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

Commit

Permalink
v1.0.2 to add support to Seeeduino nRF52
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
khoih-prog authored Oct 26, 2022
1 parent 6d5b89f commit 2b7d658
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 79 deletions.
30 changes: 25 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* Board type
* Arduino `mbed` Core Version (e.g. Arduino `mbed` core v1.3.2 or Arduino `mbed_nano` core v2.7.2 )
* `nRF52840 mbed` Core Version (e.g. Arduino mbed_nano core v3.4.1, Seeeduino mbed core v2.7.2)
* `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.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
Expand All @@ -28,13 +28,13 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.19
Arduino mbed_nano core v3.4.1
Nano_33_BLE board
Arduino mbed_nano` core v2.7.2
OS: Ubuntu 20.04 LTS
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
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
Context:
I encountered a crash while using PWM.
I encountered a crash while using this library
Steps to reproduce:
1. ...
Expand All @@ -43,13 +43,33 @@ Steps to reproduce:
4. ...
```

---

### Sending Feature Requests

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

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.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/nRF52_MBED_PWM_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_MBED_PWM_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_MBED_PWM_GitHub$ bash utils/restyle.sh
```


7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.0.2](#Releases-v102)
* [Releases v1.0.1](#Releases-v101)
* [Initial Releases v1.0.0](#Initial-Releases-v100)

Expand All @@ -20,12 +21,16 @@

## Changelog

### 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

### Releases v1.0.1

1. Add functions to read PWM parameters
2. Update examples


### Initial Releases v1.0.0

1. Initial coding to support **Nano_33_BLE boards**, using [**ArduinoCore-mbed mbed_nano** core](https://github.com/arduino/ArduinoCore-mbed)
Expand Down
46 changes: 26 additions & 20 deletions examples/PWM_Multi/PWM_Multi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ void startAllPWM()
digitalWrite(LEDG, LED_ON);
digitalWrite(LEDB, LED_OFF);
digitalWrite(LEDR, LED_OFF);

for (uint8_t index = 0; index < NUM_OF_PINS; index++)
{
PWM_LOGERROR7("Freq = ", freq[index], ", \tDutyCycle % = ", dutyCycle[index], ", \tDutyCycle = ", dutyCycle[index] / 100, ", \tPin = ", pins[index]);

PWM_LOGERROR7("Freq = ", freq[index], ", \tDutyCycle % = ", dutyCycle[index], ", \tDutyCycle = ",
dutyCycle[index] / 100, ", \tPin = ", pins[index]);

// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
}
Expand All @@ -54,12 +55,12 @@ void restoreAllPWM()
digitalWrite(LEDG, LED_ON);
digitalWrite(LEDB, LED_OFF);
digitalWrite(LEDR, LED_OFF);

for (uint8_t index = 0; index < NUM_OF_PINS; index++)
{
curFreq[index] = freq[index];
curDutyCycle[index] = dutyCycle[index];

// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
}
Expand All @@ -70,12 +71,12 @@ void changeAllPWM()
digitalWrite(LEDG, LED_OFF);
digitalWrite(LEDB, LED_ON);
digitalWrite(LEDR, LED_OFF);

for (uint8_t index = 0; index < NUM_OF_PINS; index++)
{
curFreq[index] = freq[index] * 2;
curDutyCycle[index] = dutyCycle[index] / 2;

// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
setPWM(pwm[index], pins[index], curFreq[index], curDutyCycle[index]);
}
Expand All @@ -86,12 +87,12 @@ void stopAllPWM()
digitalWrite(LEDG, LED_OFF);
digitalWrite(LEDB, LED_OFF);
digitalWrite(LEDR, LED_ON);

for (uint8_t index = 0; index < NUM_OF_PINS; index++)
{
curFreq[index] = 1000.0f;
curDutyCycle[index] = 0.0f;

//stopPWM(mbed::PwmOut* &pwm, pin_size_t pin)
stopPWM(pwm[index], pins[index]);
}
Expand All @@ -109,22 +110,25 @@ void printPulseWidth()
if (num++ % 50 == 0)
{
printLine();

for (uint8_t index = 0; index < NUM_OF_PINS; index++)
{
Serial.print(F("PW (us) ")); Serial.print(index); Serial.print(F("\t"));
Serial.print(F("PW (us) "));
Serial.print(index);
Serial.print(F("\t"));
}

printLine();
}

if (num > 1)
{
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
{
if (pwm[index])
{
Serial.print(getPulseWidth_uS(pwm[index])); Serial.print(F("\t\t"));
Serial.print(getPulseWidth_uS(pwm[index]));
Serial.print(F("\t\t"));
}
}

Expand Down Expand Up @@ -152,18 +156,18 @@ void check_status()

if ( (millis() > changePWM_timeout) && (millis() > CHANGE_INTERVAL) )
{

if (PWM_orig)
{
if (count++ %2 == 0)
if (count++ % 2 == 0)
{
Serial.println("Stop all PWM");
stopAllPWM();
}
else
{
Serial.println("Change all PWM");

changeAllPWM();

PWM_orig = !PWM_orig;
Expand All @@ -172,12 +176,12 @@ void check_status()
else
{
Serial.println("Restore all PWM");

restoreAllPWM();

PWM_orig = !PWM_orig;
}

changePWM_timeout = millis() + CHANGE_INTERVAL;
}
}
Expand All @@ -199,11 +203,13 @@ void setup()
}

Serial.begin(115200);
while (!Serial);

while (!Serial && millis() < 5000);

delay(100);

Serial.print(F("\nStarting PWM_Multi on ")); Serial.println(BOARD_NAME);
Serial.print(F("\nStarting PWM_Multi on "));
Serial.println(BOARD_NAME);
Serial.println(nRF52_MBED_PWM_VERSION);

startAllPWM();
Expand Down
38 changes: 21 additions & 17 deletions examples/PWM_Single/PWM_Single.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ void restorePWM()
digitalWrite(LEDG, LED_ON);
digitalWrite(LEDB, LED_OFF);
digitalWrite(LEDR, LED_OFF);

curFreq = freq;
curDutyCycle = dutyCycle;

// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
setPWM(pwm, myPin, freq, dutyCycle);
}
Expand All @@ -60,10 +60,10 @@ void changePWM()
digitalWrite(LEDG, LED_OFF);
digitalWrite(LEDB, LED_ON);
digitalWrite(LEDR, LED_OFF);

curFreq = freq * 2;
curDutyCycle = dutyCycle / 2;

// setPWM(mbed::PwmOut* &pwm, pin_size_t pin, float frequency, float dutyCycle)
setPWM(pwm, myPin, curFreq, curDutyCycle);
}
Expand All @@ -73,10 +73,10 @@ void stopMyPWM()
digitalWrite(LEDG, LED_OFF);
digitalWrite(LEDB, LED_OFF);
digitalWrite(LEDR, LED_ON);

curFreq = 1000.0f;
curDutyCycle = 0.0f;

//stopPWM(mbed::PwmOut* &pwm, pin_size_t pin)
stopPWM(pwm, myPin);
}
Expand All @@ -93,18 +93,20 @@ void printPulseWidth()
if (num++ % 50 == 0)
{
printLine();

Serial.print(F("PW (us)\t\tDutyCycle\tPeriod (uS)"));

printLine();
}

if (num > 1)
{
if (pwm)
{
Serial.print(getPulseWidth_uS(pwm)); Serial.print(F("\t\t"));
Serial.print(getDutyCycle(pwm)); Serial.print(F("\t\t"));
Serial.print(getPulseWidth_uS(pwm));
Serial.print(F("\t\t"));
Serial.print(getDutyCycle(pwm));
Serial.print(F("\t\t"));
Serial.print(getPeriod_uS(pwm));
}

Expand Down Expand Up @@ -132,18 +134,18 @@ void check_status()

if ( (millis() > changePWM_timeout) && (millis() > CHANGE_INTERVAL) )
{

if (PWM_orig)
{
if (count++ %2 == 0)
if (count++ % 2 == 0)
{
Serial.println("Stop PWM");
stopMyPWM();
}
else
{
Serial.println("Change PWM");

changePWM();

PWM_orig = !PWM_orig;
Expand All @@ -152,12 +154,12 @@ void check_status()
else
{
Serial.println("Restore PWM");

restorePWM();

PWM_orig = !PWM_orig;
}

changePWM_timeout = millis() + CHANGE_INTERVAL;
}
}
Expand All @@ -176,11 +178,13 @@ void setup()
digitalWrite(myPin, LOW);

Serial.begin(115200);
while (!Serial);

while (!Serial && millis() < 5000);

delay(100);

Serial.print(F("\nStarting PWM_Single on ")); Serial.println(BOARD_NAME);
Serial.print(F("\nStarting PWM_Single on "));
Serial.println(BOARD_NAME);
Serial.println(nRF52_MBED_PWM_VERSION);

startPWM();
Expand Down
2 changes: 1 addition & 1 deletion examples/multiFileProject/multiFileProject.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************************************************************
multiFileProject.cpp
For Nano_33_BLE or Nano_33_BLE_Sense boards
Written by Khoi Hoang
Expand Down
2 changes: 1 addition & 1 deletion examples/multiFileProject/multiFileProject.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************************************************************
multiFileProject.h
For Nano_33_BLE or Nano_33_BLE_Sense boards
Written by Khoi Hoang
Expand Down
Loading

0 comments on commit 2b7d658

Please sign in to comment.