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

Commit d3acd27

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 2b7d658 commit d3acd27

File tree

1 file changed

+24
-223
lines changed

1 file changed

+24
-223
lines changed

README.md

Lines changed: 24 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/nRF52_MBED_PWM.svg?)](https://www.ardu-badge.com/nRF52_MBED_PWM)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/nRF52_MBED_PWM.svg)](https://github.com/khoih-prog/nRF52_MBED_PWM/releases)
5-
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/nRF52_MBED_PWM/blob/master/LICENSE)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/nRF52_MBED_PWM/blob/main/LICENSE)
66
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
77
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/nRF52_MBED_PWM.svg)](http://github.com/khoih-prog/nRF52_MBED_PWM/issues)
88

9+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
10+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
11+
912
---
1013
---
1114

@@ -70,15 +73,17 @@ This non-being-blocked important feature is absolutely necessary for mission-cri
7073

7174
### Currently supported Boards
7275

73-
1. **Nano_33_BLE boards**, using [**ArduinoCore-mbed mbed_nano** core](https://github.com/arduino/ArduinoCore-mbed)
76+
1. **MBED nRF52840-based boards such as Nano_33_BLE, Nano_33_BLE_Sense**, etc. using [**Arduino-mbed mbed_nano** core](https://github.com/arduino/ArduinoCore-mbed)
77+
2. **Seeeduino nRF52840-based boards such as SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
7478

7579
---
7680
---
7781

7882
## Prerequisites
7983

80-
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest)
81-
2. [`ArduinoCore-mbed mbed_nano core 2.7.2+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino **Nano_33_BLE** boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
84+
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest)
85+
2. [`Arduino mbed_nano core 3.4.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) MBED nRF52840-based boards such as **Nano_33_BLE, Nano_33_BLE_Sense**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
86+
3. `Seeeduino mbed core 2.7.2+` for Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**
8287

8388
---
8489
---
@@ -95,9 +100,9 @@ You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/
95100
Another way to install is to:
96101

97102
1. Navigate to [**nRF52_MBED_PWM**](https://github.com/khoih-prog/nRF52_MBED_PWM) page.
98-
2. Download the latest release `nRF52_MBED_PWM-master.zip`.
99-
3. Extract the zip file to `nRF52_MBED_PWM-master` directory
100-
4. Copy whole `nRF52_MBED_PWM-master` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
103+
2. Download the latest release `nRF52_MBED_PWM-main.zip`.
104+
3. Extract the zip file to `nRF52_MBED_PWM-main` directory
105+
4. Copy whole `nRF52_MBED_PWM-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
101106

102107
### VS Code & PlatformIO
103108

@@ -116,14 +121,14 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.
116121

117122
You can include this `.hpp` file
118123

119-
```
124+
```cpp
120125
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
121126
#include "nRF52_MBED_PWM.hpp" //https://github.com/khoih-prog/nRF52_MBED_PWM
122127
```
123128

124129
in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error
125130

126-
```
131+
```cpp
127132
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
128133
#include "nRF52_MBED_PWM.h" //https://github.com/khoih-prog/nRF52_MBED_PWM
129134
```
@@ -150,7 +155,7 @@ Before using any Timer for a PWM channel, you have to make sure the Timer has no
150155

151156
### 1. Prepare PWM settings
152157

153-
```
158+
```cpp
154159
// All the digital pins on Arduino Nano 33 BLE sense are PWM-enabled pins which are numbered from D0 to D13
155160
uint32_t myPin = D2;
156161

@@ -163,7 +168,7 @@ mbed::PwmOut* pwm = NULL;
163168

164169
#### 2. Set PWM Frequency and dutycycle
165170

166-
```
171+
```cpp
167172
void setup()
168173
{
169174
....
@@ -176,7 +181,7 @@ void setup()
176181

177182
Use these functions
178183

179-
```
184+
```cpp
180185
float getFreq(mbed::PwmOut* &pwm);
181186

182187
float getDutyCycle(mbed::PwmOut* &pwm);
@@ -188,7 +193,7 @@ float getPeriod_uS(mbed::PwmOut* &pwm);
188193
189194
For example
190195
191-
```
196+
```cpp
192197
// All the digital pins on Arduino Nano 33 BLE sense are PWM-enabled pins which are numbered from D0 to D13
193198
uint32_t myPin = D2;
194199
@@ -223,214 +228,9 @@ if (pwm)
223228

224229
### Example [PWM_Multi](examples/PWM_Multi)
225230

226-
```
227-
#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
228-
#error This code is designed to run on nRF52-based Nano-33-BLE boards using mbed-RTOS platform! Please check your Tools->Board setting.
229-
#endif
230-
231-
#define _PWM_LOGLEVEL_ 1
232-
233-
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
234-
#include "nRF52_MBED_PWM.h"
235-
236-
#define LED_ON LOW
237-
#define LED_OFF HIGH
238-
239-
// All the digital pins on Arduino Nano 33 BLE sense are PWM-enabled pins which are numbered from D0 to D13
240-
uint32_t pins[] = { D2, D3, D4, D5 };
241-
242-
#define NUM_OF_PINS ( sizeof(pins) / sizeof(uint32_t) )
243-
244-
float dutyCycle[] = { 50.0f, 50.0f, 50.0f, 50.0f };
245-
246-
float freq[] = { 1000.0f, 2500.0f, 4000.0f, 5000.0f };
247-
248-
float curDutyCycle[] = { 50.0f, 50.0f, 50.0f, 50.0f };
249-
250-
float curFreq[] = { 1000.0f, 2500.0f, 4000.0f, 5000.0f };
251-
252-
mbed::PwmOut* pwm[] = { NULL, NULL, NULL, NULL };
253-
254-
void startAllPWM()
255-
{
256-
digitalWrite(LEDG, LED_ON);
257-
digitalWrite(LEDB, LED_OFF);
258-
digitalWrite(LEDR, LED_OFF);
259-
260-
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
261-
{
262-
PWM_LOGERROR7("Freq = ", freq[index], ", \tDutyCycle % = ", dutyCycle[index], ", \tDutyCycle = ", dutyCycle[index] / 100, ", \tPin = ", pins[index]);
263-
264-
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
265-
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
266-
}
267-
}
268-
269-
void restoreAllPWM()
270-
{
271-
digitalWrite(LEDG, LED_ON);
272-
digitalWrite(LEDB, LED_OFF);
273-
digitalWrite(LEDR, LED_OFF);
274-
275-
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
276-
{
277-
curFreq[index] = freq[index];
278-
curDutyCycle[index] = dutyCycle[index];
279-
280-
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
281-
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
282-
}
283-
}
284-
285-
void changeAllPWM()
286-
{
287-
digitalWrite(LEDG, LED_OFF);
288-
digitalWrite(LEDB, LED_ON);
289-
digitalWrite(LEDR, LED_OFF);
290-
291-
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
292-
{
293-
curFreq[index] = freq[index] * 2;
294-
curDutyCycle[index] = dutyCycle[index] / 2;
295-
296-
// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
297-
setPWM(pwm[index], pins[index], curFreq[index], curDutyCycle[index]);
298-
}
299-
}
231+
https://github.com/khoih-prog/nRF52_MBED_PWM/blob/2b7d658fce0807ab926cd4c317ffecbf6765b0f6/examples/PWM_Multi/PWM_Multi.ino#L1-L221
300232

301-
void stopAllPWM()
302-
{
303-
digitalWrite(LEDG, LED_OFF);
304-
digitalWrite(LEDB, LED_OFF);
305-
digitalWrite(LEDR, LED_ON);
306-
307-
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
308-
{
309-
curFreq[index] = 1000.0f;
310-
curDutyCycle[index] = 0.0f;
311-
312-
//stopPWM(mbed::PwmOut* &pwm, pin_size_t pin)
313-
stopPWM(pwm[index], pins[index]);
314-
}
315-
}
316233

317-
void printLine()
318-
{
319-
Serial.println(F("\n========================================================="));
320-
}
321-
322-
void printPulseWidth()
323-
{
324-
static uint32_t num = 0;
325-
326-
if (num++ % 50 == 0)
327-
{
328-
printLine();
329-
330-
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
331-
{
332-
Serial.print(F("PW (us) ")); Serial.print(index); Serial.print(F("\t"));
333-
}
334-
335-
printLine();
336-
}
337-
338-
if (num > 1)
339-
{
340-
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
341-
{
342-
if (pwm[index])
343-
{
344-
Serial.print(getPulseWidth_uS(pwm[index])); Serial.print(F("\t\t"));
345-
}
346-
}
347-
348-
Serial.println();
349-
}
350-
}
351-
352-
#define PRINT_INTERVAL 10000L
353-
#define CHANGE_INTERVAL 20000L
354-
355-
void check_status()
356-
{
357-
static unsigned long checkstatus_timeout = 0;
358-
static unsigned long changePWM_timeout = 0;
359-
360-
static bool PWM_orig = true;
361-
static uint32_t count = 0;
362-
363-
// Print every PRINT_INTERVAL (10) seconds.
364-
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
365-
{
366-
printPulseWidth();
367-
checkstatus_timeout = millis() + PRINT_INTERVAL;
368-
}
369-
370-
if ( (millis() > changePWM_timeout) && (millis() > CHANGE_INTERVAL) )
371-
{
372-
373-
if (PWM_orig)
374-
{
375-
if (count++ %2 == 0)
376-
{
377-
Serial.println("Stop all PWM");
378-
stopAllPWM();
379-
}
380-
else
381-
{
382-
Serial.println("Change all PWM");
383-
384-
changeAllPWM();
385-
386-
PWM_orig = !PWM_orig;
387-
}
388-
}
389-
else
390-
{
391-
Serial.println("Restore all PWM");
392-
393-
restoreAllPWM();
394-
395-
PWM_orig = !PWM_orig;
396-
}
397-
398-
changePWM_timeout = millis() + CHANGE_INTERVAL;
399-
}
400-
}
401-
402-
void setup()
403-
{
404-
pinMode(LEDG, OUTPUT);
405-
pinMode(LEDB, OUTPUT);
406-
pinMode(LEDR, OUTPUT);
407-
408-
digitalWrite(LEDG, LED_OFF);
409-
digitalWrite(LEDB, LED_OFF);
410-
digitalWrite(LEDR, LED_OFF);
411-
412-
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
413-
{
414-
pinMode(pins[index], OUTPUT);
415-
digitalWrite(pins[index], LOW);
416-
}
417-
418-
Serial.begin(115200);
419-
while (!Serial);
420-
421-
delay(100);
422-
423-
Serial.print(F("\nStarting PWM_Multi on ")); Serial.println(BOARD_NAME);
424-
Serial.println(nRF52_MBED_PWM_VERSION);
425-
426-
startAllPWM();
427-
}
428-
429-
void loop()
430-
{
431-
check_status();
432-
}
433-
```
434234
---
435235
---
436236

@@ -443,7 +243,7 @@ The following is the sample terminal output when running example [PWM_Single](ex
443243

444244
```
445245
Starting PWM_Single on Nano_33_BLE
446-
nRF52_MBED_PWM v1.0.1
246+
nRF52_MBED_PWM v1.0.2
447247
[PWM] Freq = 5000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 2
448248
449249
============================================
@@ -475,7 +275,7 @@ The following is the sample terminal output when running example [**PWM_Multi**]
475275

476276
```
477277
Starting PWM_Multi on Nano_33_BLE
478-
nRF52_MBED_PWM v1.0.1
278+
nRF52_MBED_PWM v1.0.2
479279
[PWM] Freq = 1000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 2
480280
[PWM] Freq = 2500.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 3
481281
[PWM] Freq = 4000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 4
@@ -554,7 +354,8 @@ Submit issues to: [nRF52_MBED_PWM issues](https://github.com/khoih-prog/nRF52_MB
554354
4. Optimize library code by using `reference-passing` instead of `value-passing`
555355
5. Use `h-only` style
556356
6. Add functions to read PWM parameters.
557-
357+
7. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
358+
8. Add astyle using `allman` style. Restyle the library
558359

559360
---
560361
---
@@ -578,7 +379,7 @@ If you want to contribute to this project:
578379

579380
### License
580381

581-
- The library is licensed under [MIT](https://github.com/khoih-prog/nRF52_MBED_PWM/blob/master/LICENSE)
382+
- The library is licensed under [MIT](https://github.com/khoih-prog/nRF52_MBED_PWM/blob/main/LICENSE)
582383

583384
---
584385

0 commit comments

Comments
 (0)