Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 2b7d658

Browse files
authored
v1.0.2 to add support to Seeeduino nRF52
### Releases v1.0.2 1. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core 2. Add astyle using `allman` style. Restyle the library
1 parent 6d5b89f commit 2b7d658

15 files changed

+205
-79
lines changed

CONTRIBUTING.md

+25-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* Board type
19-
* Arduino `mbed` Core Version (e.g. Arduino `mbed` core v1.3.2 or Arduino `mbed_nano` core v2.7.2 )
18+
* `nRF52840 mbed` Core Version (e.g. Arduino mbed_nano core v3.4.1, Seeeduino mbed core v2.7.2)
19+
* `nRF52840-based Nano_33_BLE` Board type (e.g. Nano_33_BLE, Nano_33_BLE_Sense, SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE, etc.)
2020
* Contextual information (e.g. what you were trying to achieve)
2121
* Simplest possible steps to reproduce
2222
* Anything that might be relevant in your opinion, such as:
@@ -28,13 +28,13 @@ Please ensure to specify the following:
2828

2929
```
3030
Arduino IDE version: 1.8.19
31+
Arduino mbed_nano core v3.4.1
3132
Nano_33_BLE board
32-
Arduino mbed_nano` core v2.7.2
3333
OS: Ubuntu 20.04 LTS
34-
Linux xy-Inspiron-3593 5.4.0-99-generic #112-Ubuntu SMP Thu Feb 3 13:50:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
34+
Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3535
3636
Context:
37-
I encountered a crash while using PWM.
37+
I encountered a crash while using this library
3838
3939
Steps to reproduce:
4040
1. ...
@@ -43,13 +43,33 @@ Steps to reproduce:
4343
4. ...
4444
```
4545

46+
---
47+
4648
### Sending Feature Requests
4749

4850
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
4951

5052
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/nRF52_MBED_PWM/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
5153

54+
---
55+
5256
### Sending Pull Requests
5357

5458
Pull Requests with changes and fixes are also welcome!
5559

60+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
61+
62+
1. Change directory to the library GitHub
63+
64+
```
65+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/nRF52_MBED_PWM_GitHub/
66+
xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_MBED_PWM_GitHub$
67+
```
68+
69+
2. Issue astyle command
70+
71+
```
72+
xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_MBED_PWM_GitHub$ bash utils/restyle.sh
73+
```
74+
75+

changelog.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.0.2](#Releases-v102)
1516
* [Releases v1.0.1](#Releases-v101)
1617
* [Initial Releases v1.0.0](#Initial-Releases-v100)
1718

@@ -20,12 +21,16 @@
2021

2122
## Changelog
2223

24+
### Releases v1.0.2
25+
26+
1. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
27+
2. Add astyle using `allman` style. Restyle the library
28+
2329
### Releases v1.0.1
2430

2531
1. Add functions to read PWM parameters
2632
2. Update examples
2733

28-
2934
### Initial Releases v1.0.0
3035

3136
1. Initial coding to support **Nano_33_BLE boards**, using [**ArduinoCore-mbed mbed_nano** core](https://github.com/arduino/ArduinoCore-mbed)

examples/PWM_Multi/PWM_Multi.ino

+26-20
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ void startAllPWM()
3939
digitalWrite(LEDG, LED_ON);
4040
digitalWrite(LEDB, LED_OFF);
4141
digitalWrite(LEDR, LED_OFF);
42-
42+
4343
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
4444
{
45-
PWM_LOGERROR7("Freq = ", freq[index], ", \tDutyCycle % = ", dutyCycle[index], ", \tDutyCycle = ", dutyCycle[index] / 100, ", \tPin = ", pins[index]);
46-
45+
PWM_LOGERROR7("Freq = ", freq[index], ", \tDutyCycle % = ", dutyCycle[index], ", \tDutyCycle = ",
46+
dutyCycle[index] / 100, ", \tPin = ", pins[index]);
47+
4748
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
4849
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
4950
}
@@ -54,12 +55,12 @@ void restoreAllPWM()
5455
digitalWrite(LEDG, LED_ON);
5556
digitalWrite(LEDB, LED_OFF);
5657
digitalWrite(LEDR, LED_OFF);
57-
58+
5859
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
5960
{
6061
curFreq[index] = freq[index];
6162
curDutyCycle[index] = dutyCycle[index];
62-
63+
6364
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
6465
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
6566
}
@@ -70,12 +71,12 @@ void changeAllPWM()
7071
digitalWrite(LEDG, LED_OFF);
7172
digitalWrite(LEDB, LED_ON);
7273
digitalWrite(LEDR, LED_OFF);
73-
74+
7475
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
7576
{
7677
curFreq[index] = freq[index] * 2;
7778
curDutyCycle[index] = dutyCycle[index] / 2;
78-
79+
7980
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
8081
setPWM(pwm[index], pins[index], curFreq[index], curDutyCycle[index]);
8182
}
@@ -86,12 +87,12 @@ void stopAllPWM()
8687
digitalWrite(LEDG, LED_OFF);
8788
digitalWrite(LEDB, LED_OFF);
8889
digitalWrite(LEDR, LED_ON);
89-
90+
9091
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
9192
{
9293
curFreq[index] = 1000.0f;
9394
curDutyCycle[index] = 0.0f;
94-
95+
9596
//stopPWM(mbed::PwmOut* &pwm, pin_size_t pin)
9697
stopPWM(pwm[index], pins[index]);
9798
}
@@ -109,22 +110,25 @@ void printPulseWidth()
109110
if (num++ % 50 == 0)
110111
{
111112
printLine();
112-
113+
113114
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
114115
{
115-
Serial.print(F("PW (us) ")); Serial.print(index); Serial.print(F("\t"));
116+
Serial.print(F("PW (us) "));
117+
Serial.print(index);
118+
Serial.print(F("\t"));
116119
}
117120

118121
printLine();
119122
}
120-
123+
121124
if (num > 1)
122125
{
123126
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
124127
{
125128
if (pwm[index])
126129
{
127-
Serial.print(getPulseWidth_uS(pwm[index])); Serial.print(F("\t\t"));
130+
Serial.print(getPulseWidth_uS(pwm[index]));
131+
Serial.print(F("\t\t"));
128132
}
129133
}
130134

@@ -152,18 +156,18 @@ void check_status()
152156

153157
if ( (millis() > changePWM_timeout) && (millis() > CHANGE_INTERVAL) )
154158
{
155-
159+
156160
if (PWM_orig)
157161
{
158-
if (count++ %2 == 0)
162+
if (count++ % 2 == 0)
159163
{
160164
Serial.println("Stop all PWM");
161165
stopAllPWM();
162166
}
163167
else
164168
{
165169
Serial.println("Change all PWM");
166-
170+
167171
changeAllPWM();
168172

169173
PWM_orig = !PWM_orig;
@@ -172,12 +176,12 @@ void check_status()
172176
else
173177
{
174178
Serial.println("Restore all PWM");
175-
179+
176180
restoreAllPWM();
177181

178182
PWM_orig = !PWM_orig;
179183
}
180-
184+
181185
changePWM_timeout = millis() + CHANGE_INTERVAL;
182186
}
183187
}
@@ -199,11 +203,13 @@ void setup()
199203
}
200204

201205
Serial.begin(115200);
202-
while (!Serial);
206+
207+
while (!Serial && millis() < 5000);
203208

204209
delay(100);
205210

206-
Serial.print(F("\nStarting PWM_Multi on ")); Serial.println(BOARD_NAME);
211+
Serial.print(F("\nStarting PWM_Multi on "));
212+
Serial.println(BOARD_NAME);
207213
Serial.println(nRF52_MBED_PWM_VERSION);
208214

209215
startAllPWM();

examples/PWM_Single/PWM_Single.ino

+21-17
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ void restorePWM()
4747
digitalWrite(LEDG, LED_ON);
4848
digitalWrite(LEDB, LED_OFF);
4949
digitalWrite(LEDR, LED_OFF);
50-
50+
5151
curFreq = freq;
5252
curDutyCycle = dutyCycle;
53-
53+
5454
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
5555
setPWM(pwm, myPin, freq, dutyCycle);
5656
}
@@ -60,10 +60,10 @@ void changePWM()
6060
digitalWrite(LEDG, LED_OFF);
6161
digitalWrite(LEDB, LED_ON);
6262
digitalWrite(LEDR, LED_OFF);
63-
63+
6464
curFreq = freq * 2;
6565
curDutyCycle = dutyCycle / 2;
66-
66+
6767
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
6868
setPWM(pwm, myPin, curFreq, curDutyCycle);
6969
}
@@ -73,10 +73,10 @@ void stopMyPWM()
7373
digitalWrite(LEDG, LED_OFF);
7474
digitalWrite(LEDB, LED_OFF);
7575
digitalWrite(LEDR, LED_ON);
76-
76+
7777
curFreq = 1000.0f;
7878
curDutyCycle = 0.0f;
79-
79+
8080
//stopPWM(mbed::PwmOut* &pwm, pin_size_t pin)
8181
stopPWM(pwm, myPin);
8282
}
@@ -93,18 +93,20 @@ void printPulseWidth()
9393
if (num++ % 50 == 0)
9494
{
9595
printLine();
96-
96+
9797
Serial.print(F("PW (us)\t\tDutyCycle\tPeriod (uS)"));
9898

9999
printLine();
100100
}
101-
101+
102102
if (num > 1)
103103
{
104104
if (pwm)
105105
{
106-
Serial.print(getPulseWidth_uS(pwm)); Serial.print(F("\t\t"));
107-
Serial.print(getDutyCycle(pwm)); Serial.print(F("\t\t"));
106+
Serial.print(getPulseWidth_uS(pwm));
107+
Serial.print(F("\t\t"));
108+
Serial.print(getDutyCycle(pwm));
109+
Serial.print(F("\t\t"));
108110
Serial.print(getPeriod_uS(pwm));
109111
}
110112

@@ -132,18 +134,18 @@ void check_status()
132134

133135
if ( (millis() > changePWM_timeout) && (millis() > CHANGE_INTERVAL) )
134136
{
135-
137+
136138
if (PWM_orig)
137139
{
138-
if (count++ %2 == 0)
140+
if (count++ % 2 == 0)
139141
{
140142
Serial.println("Stop PWM");
141143
stopMyPWM();
142144
}
143145
else
144146
{
145147
Serial.println("Change PWM");
146-
148+
147149
changePWM();
148150

149151
PWM_orig = !PWM_orig;
@@ -152,12 +154,12 @@ void check_status()
152154
else
153155
{
154156
Serial.println("Restore PWM");
155-
157+
156158
restorePWM();
157159

158160
PWM_orig = !PWM_orig;
159161
}
160-
162+
161163
changePWM_timeout = millis() + CHANGE_INTERVAL;
162164
}
163165
}
@@ -176,11 +178,13 @@ void setup()
176178
digitalWrite(myPin, LOW);
177179

178180
Serial.begin(115200);
179-
while (!Serial);
181+
182+
while (!Serial && millis() < 5000);
180183

181184
delay(100);
182185

183-
Serial.print(F("\nStarting PWM_Single on ")); Serial.println(BOARD_NAME);
186+
Serial.print(F("\nStarting PWM_Single on "));
187+
Serial.println(BOARD_NAME);
184188
Serial.println(nRF52_MBED_PWM_VERSION);
185189

186190
startPWM();

examples/multiFileProject/multiFileProject.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************************************************************
22
multiFileProject.cpp
3-
3+
44
For Nano_33_BLE or Nano_33_BLE_Sense boards
55
Written by Khoi Hoang
66

examples/multiFileProject/multiFileProject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************************************************************
22
multiFileProject.h
3-
3+
44
For Nano_33_BLE or Nano_33_BLE_Sense boards
55
Written by Khoi Hoang
66

0 commit comments

Comments
 (0)