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

Commit e60827f

Browse files
authored
Update README.md and use allman astyle
1 parent d3bc24f commit e60827f

File tree

9 files changed

+121
-81
lines changed

9 files changed

+121
-81
lines changed

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/MBED_RP2040_PWM.svg?)](https://www.ardu-badge.com/MBED_RP2040_PWM)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/MBED_RP2040_PWM.svg)](https://github.com/khoih-prog/MBED_RP2040_PWM/releases)
5-
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/MBED_RP2040_PWM/blob/master/LICENSE)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/MBED_RP2040_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/MBED_RP2040_PWM.svg)](http://github.com/khoih-prog/MBED_RP2040_PWM/issues)
88

9-
<a href="https://www.buymeacoffee.com/khoihprog6" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 50px !important;width: 181px !important;" ></a>
9+
10+
<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>
11+
<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>
12+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
13+
<a href="https://profile-counter.glitch.me/khoih-prog-MBED_RP2040_PWM/count.svg" title="MBED_RP2040_PWM Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-MBED_RP2040_PWM/count.svg" style="height: 30px;width: 200px;"></a>
14+
15+
1016

1117
---
1218
---
@@ -112,9 +118,9 @@ You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/
112118
Another way to install is to:
113119

114120
1. Navigate to [**MBED_RP2040_PWM**](https://github.com/khoih-prog/MBED_RP2040_PWM) page.
115-
2. Download the latest release `MBED_RP2040_PWM-master.zip`.
116-
3. Extract the zip file to `MBED_RP2040_PWM-master` directory
117-
4. Copy whole `MBED_RP2040_PWM-master` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
121+
2. Download the latest release `MBED_RP2040_PWM-main.zip`.
122+
3. Extract the zip file to `MBED_RP2040_PWM-main` directory
123+
4. Copy whole `MBED_RP2040_PWM-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
118124

119125
### VS Code & PlatformIO
120126

@@ -133,14 +139,14 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.
133139

134140
You can include this `.hpp` file
135141

136-
```
142+
```cpp
137143
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
138144
#include "MBED_RP2040_PWM.hpp" //https://github.com/khoih-prog/MBED_RP2040_PWM
139145
```
140146

141147
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
142148

143-
```
149+
```cpp
144150
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
145151
#include "MBED_RP2040_PWM.h" //https://github.com/khoih-prog/MBED_RP2040_PWM
146152
```
@@ -156,7 +162,7 @@ Before using any Timer for a PWM channel, you have to make sure the Timer has no
156162

157163
### 1. Prepare PWM settings
158164

159-
```
165+
```cpp
160166
// Valid pins from 0-29 (GP0-GP29)
161167
uint32_t myPin = 15; // GP15
162168

@@ -169,7 +175,7 @@ mbed::PwmOut* pwm = NULL;
169175

170176
#### 2. Set PWM Frequency and dutycycle
171177

172-
```
178+
```cpp
173179
void setup()
174180
{
175181
....
@@ -182,7 +188,7 @@ void setup()
182188

183189
Use these functions
184190

185-
```
191+
```cpp
186192
float getFreq(mbed::PwmOut* &pwm);
187193

188194
float getDutyCycle(mbed::PwmOut* &pwm);
@@ -194,7 +200,7 @@ float getPeriod_uS(mbed::PwmOut* &pwm);
194200
195201
For example
196202
197-
```
203+
```cpp
198204
// Valid pins from 0-29 (GP0-GP29)
199205
uint32_t myPin = 15; // GP15
200206
@@ -229,7 +235,7 @@ if (pwm)
229235

230236
### Example [PWM_Multi](examples/PWM_Multi)
231237

232-
```
238+
```cpp
233239
#if !( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
234240
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)
235241
#error This code is intended to run on the MBED RP2040 platform! Please check your Tools->Board setting.
@@ -463,7 +469,7 @@ void loop()
463469
The following is the sample terminal output when running example [PWM_Single](examples/PWM_Single) on **RaspberryPi Pico** to demonstrate how to start a single PWM channel, then stop, change, restore the PWM settings on-the-fly.
464470
465471
466-
```
472+
```cpp
467473
Starting PWM_Single on RaspberryPi Pico
468474
MBED_RP2040_PWM v1.0.0
469475
[PWM] Freq = 5000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 15
@@ -495,7 +501,7 @@ Change PWM
495501

496502
The following is the sample terminal output when running example [**PWM_Multi**](examples/PWM_Multi) on **RaspberryPi Pico** to demonstrate how to start multiple PWM channels, then stop, change, restore the PWM settings on-the-fly.
497503

498-
```
504+
```cpp
499505
Starting PWM_Multi on RaspberryPi Pico
500506
MBED_RP2040_PWM v1.0.0
501507
[PWM] Freq = 1000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = GP12
@@ -600,12 +606,12 @@ If you want to contribute to this project:
600606

601607
### License
602608

603-
- The library is licensed under [MIT](https://github.com/khoih-prog/MBED_RP2040_PWM/blob/master/LICENSE)
609+
- The library is licensed under [MIT](https://github.com/khoih-prog/MBED_RP2040_PWM/blob/main/LICENSE)
604610

605611
---
606612

607613
## Copyright
608614

609-
Copyright 2022- Khoi Hoang
615+
Copyright (c) 2022- Khoi Hoang
610616

611617

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/MBED_RP2040_PWM.svg?)](https://www.ardu-badge.com/MBED_RP2040_PWM)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/MBED_RP2040_PWM.svg)](https://github.com/khoih-prog/MBED_RP2040_PWM/releases)
5-
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/MBED_RP2040_PWM/blob/master/LICENSE)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/MBED_RP2040_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/MBED_RP2040_PWM.svg)](http://github.com/khoih-prog/MBED_RP2040_PWM/issues)
88

9+
10+
<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>
11+
<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>
12+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
13+
<a href="https://profile-counter.glitch.me/khoih-prog-MBED_RP2040_PWM/count.svg" title="MBED_RP2040_PWM Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-MBED_RP2040_PWM/count.svg" style="height: 30px;width: 200px;"></a>
14+
15+
916
---
1017
---
1118

examples/PWM_Multi/PWM_Multi.ino

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#if !( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
1111
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)
12-
#error This code is intended to run on the MBED RP2040 platform! Please check your Tools->Board setting.
12+
#error This code is intended to run on the MBED RP2040 platform! Please check your Tools->Board setting.
1313
#endif
1414

1515
#define _PWM_LOGLEVEL_ 1
@@ -52,11 +52,12 @@ void startAllPWM()
5252
digitalWrite(LED_BUILTIN, LED_ON);
5353
digitalWrite(LED_BLUE, LED_OFF);
5454
digitalWrite(LED_RED, LED_OFF);
55-
55+
5656
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
5757
{
58-
PWM_LOGERROR7("Freq = ", freq[index], ", \tDutyCycle % = ", dutyCycle[index], ", \tDutyCycle = ", dutyCycle[index] / 100, ", \tPin = GP", pins[index]);
59-
58+
PWM_LOGERROR7("Freq = ", freq[index], ", \tDutyCycle % = ", dutyCycle[index], ", \tDutyCycle = ",
59+
dutyCycle[index] / 100, ", \tPin = GP", pins[index]);
60+
6061
// setPWM(mbed::PwmOut* &pwm, pinsize_t pin, float frequency, float dutyCycle)
6162
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
6263
}
@@ -67,12 +68,12 @@ void restoreAllPWM()
6768
digitalWrite(LED_BUILTIN, LED_ON);
6869
digitalWrite(LED_BLUE, LED_OFF);
6970
digitalWrite(LED_RED, LED_OFF);
70-
71+
7172
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
7273
{
7374
curFreq[index] = freq[index];
7475
curDutyCycle[index] = dutyCycle[index];
75-
76+
7677
// setPWM(mbed::PwmOut* &pwm, pinsize_t pin, float frequency, float dutyCycle)
7778
setPWM(pwm[index], pins[index], freq[index], dutyCycle[index]);
7879
}
@@ -83,12 +84,12 @@ void changeAllPWM()
8384
digitalWrite(LED_BUILTIN, LED_OFF);
8485
digitalWrite(LED_BLUE, LED_ON);
8586
digitalWrite(LED_RED, LED_OFF);
86-
87+
8788
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
8889
{
8990
curFreq[index] = freq[index] * 2;
9091
curDutyCycle[index] = dutyCycle[index] / 2;
91-
92+
9293
// setPWM(mbed::PwmOut* &pwm, pinsize_t pin, float frequency, float dutyCycle)
9394
setPWM(pwm[index], pins[index], curFreq[index], curDutyCycle[index]);
9495
}
@@ -99,12 +100,12 @@ void stopAllPWM()
99100
digitalWrite(LED_BUILTIN, LED_OFF);
100101
digitalWrite(LED_BLUE, LED_OFF);
101102
digitalWrite(LED_RED, LED_ON);
102-
103+
103104
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
104105
{
105106
curFreq[index] = 1000.0f;
106107
curDutyCycle[index] = 0.0f;
107-
108+
108109
//stopPWM(mbed::PwmOut* &pwm, pinsize_t pin)
109110
stopPWM(pwm[index], pins[index]);
110111
}
@@ -122,22 +123,25 @@ void printPulseWidth()
122123
if (num++ % 50 == 0)
123124
{
124125
printLine();
125-
126+
126127
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
127128
{
128-
Serial.print(F("PW (us) ")); Serial.print(index); Serial.print(F("\t"));
129+
Serial.print(F("PW (us) "));
130+
Serial.print(index);
131+
Serial.print(F("\t"));
129132
}
130133

131134
printLine();
132135
}
133-
136+
134137
if (num > 1)
135138
{
136139
for (uint8_t index = 0; index < NUM_OF_PINS; index++)
137140
{
138141
if (pwm[index])
139142
{
140-
Serial.print(getPulseWidth_uS(pwm[index])); Serial.print(F("\t\t"));
143+
Serial.print(getPulseWidth_uS(pwm[index]));
144+
Serial.print(F("\t\t"));
141145
}
142146
}
143147

@@ -165,18 +169,18 @@ void check_status()
165169

166170
if ( (millis() > changePWM_timeout) && (millis() > CHANGE_INTERVAL) )
167171
{
168-
172+
169173
if (PWM_orig)
170174
{
171-
if (count++ %2 == 0)
175+
if (count++ % 2 == 0)
172176
{
173177
Serial.println("Stop all PWM");
174178
stopAllPWM();
175179
}
176180
else
177181
{
178182
Serial.println("Change all PWM");
179-
183+
180184
changeAllPWM();
181185

182186
PWM_orig = !PWM_orig;
@@ -185,12 +189,12 @@ void check_status()
185189
else
186190
{
187191
Serial.println("Restore all PWM");
188-
192+
189193
restoreAllPWM();
190194

191195
PWM_orig = !PWM_orig;
192196
}
193-
197+
194198
changePWM_timeout = millis() + CHANGE_INTERVAL;
195199
}
196200
}
@@ -212,11 +216,13 @@ void setup()
212216
}
213217

214218
Serial.begin(115200);
219+
215220
while (!Serial);
216221

217222
delay(100);
218223

219-
Serial.print(F("\nStarting PWM_Multi on ")); Serial.println(BOARD_NAME);
224+
Serial.print(F("\nStarting PWM_Multi on "));
225+
Serial.println(BOARD_NAME);
220226
Serial.println(MBED_RP2040_PWM_VERSION);
221227

222228
// Automatically retrieve TIM instance and channel associated to pin

0 commit comments

Comments
 (0)