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

Commit f20e8b3

Browse files
authored
v1.2.2 to add support to Seeeduino nRF52
### Releases v1.2.2 1. Add support to Seeeduino nRF52840-based boards such as **Seeed_XIAO_NRF52840 and Seeed_XIAO_NRF52840_SENSE**, etc. using Seeeduino `nRF52` core 2. Add astyle using `allman` style. Restyle the library 3. Update all examples 4. Update `Packages' Patches` to add Seeeduino `nRF52` core
1 parent 4ffb6ad commit f20e8b3

22 files changed

+882
-626
lines changed

CONTRIBUTING.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ 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-
* `NRF52` Core Version (e.g. Adafruit NRF52 core v1.3.0)
18+
* `NRF52` Core Version (e.g. Adafruit NRF52 core v1.3.0, Seeed nRF52 core v1.0.0)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -27,25 +27,47 @@ Please ensure to specify the following:
2727

2828
```
2929
Arduino IDE version: 1.8.19
30-
Arduino NRF52 Core Version 1.3.0
30+
Adafruit NRF52 Core Version 1.3.0
31+
NRF52840_ITSYBITSY
3132
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
33+
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
3334
3435
Context:
35-
I encountered a crash while trying to use the Timer Interrupt.
36+
I encountered a crash while using this library
3637
3738
Steps to reproduce:
3839
1. ...
3940
2. ...
4041
3. ...
4142
4. ...
4243
```
44+
45+
---
46+
4347
### Sending Feature Requests
4448

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

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

53+
---
54+
4955
### Sending Pull Requests
5056

5157
Pull Requests with changes and fixes are also welcome!
58+
59+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
60+
61+
1. Change directory to the library GitHub
62+
63+
```
64+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/nRF52_Slow_PWM_GitHub/
65+
xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_Slow_PWM_GitHub$
66+
```
67+
68+
2. Issue astyle command
69+
70+
```
71+
xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_Slow_PWM_GitHub$ bash utils/restyle.sh
72+
```
73+

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.2.2](#releases-v122)
1516
* [Releases v1.2.1](#releases-v121)
1617
* [Releases v1.2.0](#releases-v120)
1718
* [Releases v1.1.0](#releases-v110)
@@ -22,6 +23,13 @@
2223

2324
## Changelog
2425

26+
### Releases v1.2.2
27+
28+
1. Add support to Seeeduino nRF52840-based boards such as **Seeed_XIAO_NRF52840 and Seeed_XIAO_NRF52840_SENSE**, etc. using Seeeduino `nRF52` core
29+
2. Add astyle using `allman` style. Restyle the library
30+
3. Update all examples
31+
4. Update `Packages' Patches` to add Seeeduino `nRF52` core
32+
2533
### Releases v1.2.1
2634

2735
1. Fix `DutyCycle` bug. Check [float precisison of DutyCycle only sometimes working #3](https://github.com/khoih-prog/SAMD_Slow_PWM/issues/3)

examples/ISR_16_PWMs_Array/ISR_16_PWMs_Array.ino

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
*****************************************************************************************************************************/
1515

16-
#if !(defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \
17-
defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || \
18-
defined(NRF52840_CLUE) || defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || \
19-
defined(MDBT50Q_RX) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) )
20-
#error This code is designed to run on nRF52 platform! Please check your Tools->Board setting.
21-
#endif
22-
2316
// These define's must be placed at the beginning before #include "ESP32_PWM.h"
2417
// _PWM_LOGLEVEL_ from 0 to 4
2518
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
@@ -34,15 +27,23 @@
3427
#define LED_ON LOW
3528

3629
#ifndef LED_BUILTIN
37-
#define LED_BUILTIN 25
30+
#define LED_BUILTIN 25
3831
#endif
3932

40-
#ifndef LED_BLUE
41-
#define LED_BLUE 10
33+
#ifndef LED_BLUE_PIN
34+
#if defined(LED_BLUE)
35+
#define LED_BLUE_PIN LED_BLUE
36+
#else
37+
#define LED_BLUE_PIN 7
38+
#endif
4239
#endif
4340

44-
#ifndef LED_RED
45-
#define LED_RED 11
41+
#ifndef LED_GREEN_PIN
42+
#if defined(LED_GREEN)
43+
#define LED_GREEN_PIN LED_GREEN
44+
#else
45+
#define LED_GREEN_PIN 8
46+
#endif
4647
#endif
4748

4849
#define HW_TIMER_INTERVAL_US 20L
@@ -61,8 +62,8 @@ NRF52_Slow_PWM ISR_PWM;
6162
//////////////////////////////////////////////////////
6263

6364
void TimerHandler()
64-
{
65-
ISR_PWM.run();
65+
{
66+
ISR_PWM.run();
6667
}
6768

6869
//////////////////////////////////////////////////////
@@ -92,29 +93,29 @@ void TimerHandler()
9293
// You can assign pins here. Be carefull to select good pin to use or crash, e.g pin 6-11
9394
uint32_t PWM_Pin[] =
9495
{
95-
LED_BUILTIN, LED_BLUE, LED_RED, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4,
96-
PIN_D5, PIN_D6, PIN_D7, PIN_D8, PIN_D9, PIN_D10, PIN_D11, PIN_D12
96+
LED_BUILTIN, LED_BLUE_PIN, LED_GREEN_PIN, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4,
97+
PIN_D5, PIN_D6, PIN_D7, PIN_D8, PIN_D9, PIN_D10, PIN_D11, PIN_D12
9798
};
9899

99100
// You can assign any interval for any timer here, in microseconds
100101
uint32_t PWM_Period[] =
101102
{
102-
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
103-
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
103+
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
104+
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
104105
};
105106

106107
// You can assign any interval for any timer here, in Hz
107108
float PWM_Freq[] =
108109
{
109-
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
110-
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
110+
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
111+
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
111112
};
112113

113114
// You can assign any interval for any timer here, in milliseconds
114115
float PWM_DutyCycle[] =
115116
{
116-
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0,
117-
60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0
117+
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0,
118+
60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0
118119
};
119120

120121
typedef void (*irqCallback) ();
@@ -189,57 +190,61 @@ void doingSomething15()
189190

190191
irqCallback irqCallbackStartFunc[] =
191192
{
192-
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
193-
doingSomething4, doingSomething5, doingSomething6, doingSomething7,
194-
doingSomething8, doingSomething9, doingSomething10, doingSomething11,
195-
doingSomething12, doingSomething13, doingSomething14, doingSomething15
193+
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
194+
doingSomething4, doingSomething5, doingSomething6, doingSomething7,
195+
doingSomething8, doingSomething9, doingSomething10, doingSomething11,
196+
doingSomething12, doingSomething13, doingSomething14, doingSomething15
196197
};
197198

198199
////////////////////////////////////////////////
199200

200201
void setup()
201-
{
202-
Serial.begin(115200);
203-
while (!Serial);
202+
{
203+
Serial.begin(115200);
204204

205-
delay(2000);
205+
while (!Serial && millis() < 5000);
206206

207-
Serial.print(F("\nStarting ISR_16_PWMs_Array on ")); Serial.println(BOARD_NAME);
208-
Serial.println(NRF52_SLOW_PWM_VERSION);
207+
delay(2000);
209208

210-
// Interval in microsecs
211-
if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US, TimerHandler))
212-
{
213-
startMicros = micros();
214-
Serial.print(F("Starting ITimer OK, micros() = ")); Serial.println(startMicros);
215-
}
216-
else
217-
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
209+
Serial.print(F("\nStarting ISR_16_PWMs_Array on ")); Serial.println(BOARD_NAME);
210+
Serial.println(NRF52_SLOW_PWM_VERSION);
211+
212+
// Interval in microsecs
213+
if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US, TimerHandler))
214+
{
215+
startMicros = micros();
216+
Serial.print(F("Starting ITimer OK, micros() = "));
217+
Serial.println(startMicros);
218+
}
219+
else
220+
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
218221

219222
#if 1
220-
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
221-
// You can use up to 16 timer for each ISR_PWM
222-
for (uint16_t i = 0; i < NUMBER_ISR_PWMS; i++)
223-
{
224-
//void setPWM(uint32_t pin, float frequency, float dutycycle
225-
// , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr)
223+
224+
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
225+
// You can use up to 16 timer for each ISR_PWM
226+
for (uint16_t i = 0; i < NUMBER_ISR_PWMS; i++)
227+
{
228+
//void setPWM(uint32_t pin, float frequency, float dutycycle
229+
// , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr)
226230

227231
#if USING_PWM_FREQUENCY
228232

229-
// You can use this with PWM_Freq in Hz
230-
ISR_PWM.setPWM(PWM_Pin[i], PWM_Freq[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);
233+
// You can use this with PWM_Freq in Hz
234+
ISR_PWM.setPWM(PWM_Pin[i], PWM_Freq[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);
231235

232236
#else
233-
#if USING_MICROS_RESOLUTION
234-
// Or using period in microsecs resolution
235-
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);
236-
#else
237-
// Or using period in millisecs resolution
238-
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i] / 1000, PWM_DutyCycle[i], irqCallbackStartFunc[i]);
239-
#endif
237+
#if USING_MICROS_RESOLUTION
238+
// Or using period in microsecs resolution
239+
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i], PWM_DutyCycle[i], irqCallbackStartFunc[i]);
240+
#else
241+
// Or using period in millisecs resolution
242+
ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i] / 1000, PWM_DutyCycle[i], irqCallbackStartFunc[i]);
243+
#endif
244+
#endif
245+
}
246+
240247
#endif
241-
}
242-
#endif
243248
}
244249

245250
void loop()

0 commit comments

Comments
 (0)