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

Commit b898f48

Browse files
authored
Update README.md and use allman astyle
1 parent 9643982 commit b898f48

File tree

5 files changed

+56
-42
lines changed

5 files changed

+56
-42
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Arduino IDE version: 1.8.19
3131
`ArduinoCore-mbed` mbed_portenta core v3.4.1
3232
Portenta_H7 Rev2 ABX00042
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:
3737
I encountered a crash while using this library

README.md

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

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/Portenta_H7_PWM.svg?)](https://www.ardu-badge.com/Portenta_H7_PWM)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/Portenta_H7_PWM.svg)](https://github.com/khoih-prog/Portenta_H7_PWM/releases)
5-
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/Portenta_H7_PWM/blob/master/LICENSE)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/Portenta_H7_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/Portenta_H7_PWM.svg)](http://github.com/khoih-prog/Portenta_H7_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: 60px !important;width: 217px !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-Portenta_H7_PWM/count.svg" title="Portenta_H7_PWM Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-Portenta_H7_PWM/count.svg" style="height: 30px;width: 200px;"></a>
14+
1015

1116
---
1217
---
@@ -90,7 +95,7 @@ This library is using the **same or similar functions** as other FastPWM librari
9095

9196
The most important feature is they're purely hardware-based PWM channels. Therefore, their executions are **not blocked by bad-behaving functions / tasks**. This important feature is absolutely necessary for mission-critical tasks.
9297

93-
This important feature is absolutely necessary for mission-critical tasks. These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.
98+
This important feature is absolutely necessary for mission-critical tasks. These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using `millis()` or `micros()`. That's necessary if you need to measure some data requiring better accuracy.
9499

95100
The [**PWM_Multi**](examples/PWM_Multi) will demonstrate the usage of multichannel PWM using multiple Hardware Timers. The 4 independent Hardware Timers are used **to control 4 different PWM outputs**, with totally independent frequencies and dutycycles. You can **start, stop, change and restore the settings of any PWM channel on-the-fly**.
96101

@@ -110,9 +115,9 @@ You'd prefer to have your function called, no matter what happening with other f
110115

111116
The correct choice is to use a Hardware Timer with **Interrupt** to call your function.
112117

113-
These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more **precise** (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.
118+
These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more **precise** (certainly depending on clock frequency accuracy) than other software timers using `millis()` or `micros()`. That's necessary if you need to measure some data requiring better accuracy.
114119

115-
Functions using normal software timers, relying on loop() and calling millis(), won't work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
120+
Functions using normal software timers, relying on `loop()` and calling `millis()`, won't work if the `loop()` or `setup()` is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
116121

117122
The catch is **your function is now part of an ISR (Interrupt Service Routine), and must be lean / mean, and follow certain rules.** More to read on:
118123

@@ -147,9 +152,9 @@ You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/
147152
Another way to install is to:
148153

149154
1. Navigate to [**Portenta_H7_PWM**](https://github.com/khoih-prog/Portenta_H7_PWM) page.
150-
2. Download the latest release `Portenta_H7_PWM-master.zip`.
151-
3. Extract the zip file to `Portenta_H7_PWM-master` directory
152-
4. Copy whole `Portenta_H7_PWM-master` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
155+
2. Download the latest release `Portenta_H7_PWM-main.zip`.
156+
3. Extract the zip file to `Portenta_H7_PWM-main` directory
157+
4. Copy whole `Portenta_H7_PWM-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
153158

154159
### VS Code & PlatformIO
155160

@@ -168,14 +173,14 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.
168173

169174
You can include this `.hpp` file
170175

171-
```
176+
```cpp
172177
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
173178
#include "Portenta_H7_PWM.hpp" //https://github.com/khoih-prog/Portenta_H7_PWM
174179
```
175180

176181
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
177182

178-
```
183+
```cpp
179184
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
180185
#include "Portenta_H7_PWM.h" //https://github.com/khoih-prog/Portenta_H7_PWM
181186
```
@@ -250,7 +255,7 @@ To be sure which Timer is available for the board you're using, check the Core P
250255

251256
The information will be as follows:
252257

253-
```
258+
```cpp
254259
typedef struct
255260
{
256261
__IO uint32_t CR1; /*!< TIM control register 1, Address offset: 0x00 */
@@ -285,7 +290,7 @@ typedef struct
285290

286291
and
287292

288-
```
293+
```cpp
289294
#define PERIPH_BASE 0x40000000UL /*!< Base address of : AHB/ABP Peripherals
290295
/*!< Peripheral memory map */
291296
#define APB1PERIPH_BASE PERIPH_BASE
@@ -378,7 +383,7 @@ To know which Timer (TIMx) is used for which pin, check [Table 7. STM32H747xI/G
378383

379384
The result for PWM-enable pins can be summarized as follows
380385

381-
```
386+
```cpp
382387
#define pinD0 D0 // PH15 / TIM8_CH3N
383388
#define pinD1 D1 // PK1 / TIM1_CH1, TIM8_CH3
384389
#define pinD2 D2 // PJ11 / TIM1_CH2, TIM8_CH2N
@@ -397,7 +402,7 @@ Before using any Timer for a PWM channel, you have to make sure the Timer has no
397402

398403
### 1. Prepare PWM settings
399404

400-
```
405+
```cpp
401406
// Can't use same TimerIndex again, e.g., the D1 and D2, using TIM1, can't be use concurrently
402407
// That's why D0, D1, D3, D4 and D6 (using TimerIndex 8, 1, HRTIM and 3) are OK together
403408

@@ -427,7 +432,7 @@ mbed::PwmOut* pwm = NULL;
427432

428433
#### 2. Set PWM Frequency and dutycycle
429434

430-
```
435+
```cpp
431436
void setup()
432437
{
433438
....
@@ -451,7 +456,7 @@ void setup()
451456

452457
### Example [PWM_Multi](examples/PWM_Multi)
453458

454-
```
459+
```cpp
455460
#if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) )
456461
#error For Portenta_H7 only
457462
#endif
@@ -697,7 +702,7 @@ void loop()
697702
The following is the sample terminal output when running example [PWM_Single](examples/PWM_Single) on **Portenta_H7** to demonstrate how to start a single PWM channel, then stop, change, restore the PWM settings on-the-fly.
698703
699704
700-
```
705+
```cpp
701706
Starting PWM_Single on PORTENTA_H7_M7
702707
Portenta_H7_PWM v2.0.2
703708
[PWM] Freq = 5000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 5
@@ -732,7 +737,7 @@ Restore PWM
732737

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

735-
```
740+
```cpp
736741

737742
Starting PWM_Multi on PORTENTA_H7_M7
738743
Portenta_H7_PWM v2.0.2
@@ -846,12 +851,12 @@ If you want to contribute to this project:
846851

847852
### License
848853

849-
- The library is licensed under [MIT](https://github.com/khoih-prog/Portenta_H7_PWM/blob/master/LICENSE)
854+
- The library is licensed under [MIT](https://github.com/khoih-prog/Portenta_H7_PWM/blob/main/LICENSE)
850855

851856
---
852857

853858
## Copyright
854859

855-
Copyright 2021- Khoi Hoang
860+
Copyright (c) 2021- Khoi Hoang
856861

857862

changelog.md

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

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/Portenta_H7_PWM.svg?)](https://www.ardu-badge.com/Portenta_H7_PWM)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/Portenta_H7_PWM.svg)](https://github.com/khoih-prog/Portenta_H7_PWM/releases)
5-
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/Portenta_H7_PWM/blob/master/LICENSE)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/Portenta_H7_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/Portenta_H7_PWM.svg)](http://github.com/khoih-prog/Portenta_H7_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-Portenta_H7_PWM/count.svg" title="Portenta_H7_PWM Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-Portenta_H7_PWM/count.svg" style="height: 30px;width: 200px;"></a>
14+
915
---
1016
---
1117

platformio/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ upload_speed = 921600
3939

4040
; Checks for the compatibility with frameworks and dev/platforms
4141
lib_compat_mode = strict
42+
lib_ldf_mode = chain+
43+
;lib_ldf_mode = deep+
4244

4345
lib_deps =
4446

src/Portenta_H7_PWM_Impl.h

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ bool isValidPWMPin(const pin_size_t& pin)
4141
{
4242
return true;
4343
}
44-
44+
4545
PWM_LOGERROR1("Not PWM pin = ", pin);
46-
46+
4747
return false;
4848
}
4949

@@ -52,7 +52,7 @@ bool isValidPWMDutyCycle(const pin_size_t& pin, const float& dutyCycle)
5252
if ( (dutyCycle < 0.0f) || (dutyCycle > 100.0f) )
5353
{
5454
PWM_LOGERROR3("Bad dutyCycle = ", dutyCycle, ", pin = ", pin);
55-
55+
5656
return false;
5757
}
5858

@@ -64,7 +64,7 @@ bool isUsingHRTIM(const pin_size_t& pin)
6464
if ( (pin == D3) || (pin == D6) )
6565
{
6666
PWM_LOGDEBUG1("Using HRTIM pin = ", pin);
67-
67+
6868
return true;
6969
}
7070

@@ -87,10 +87,10 @@ bool isValidPWMFreq(const pin_size_t& pin, const float& frequency)
8787
{
8888
PWM_LOGERROR3("Bad Freq = ", frequency, ", pin = ", pin);
8989
}
90-
90+
9191
return false;
9292
}
93-
93+
9494
return true;
9595
}
9696

@@ -106,59 +106,60 @@ bool isValidPWMSettings(const pin_size_t& pin, const float& frequency, const flo
106106
{
107107
PWM_LOGERROR3("Bad Freq = ", frequency, ", pin = ", pin);
108108
}
109-
109+
110110
return false;
111-
}
111+
}
112112
else if ( (dutyCycle < 0.0f) || (dutyCycle > 100.0f) )
113113
{
114114
PWM_LOGERROR3("Bad dutyCycle = ", dutyCycle, ", pin = ", pin);
115-
115+
116116
return false;
117117
}
118118
else if ( !( (pin == D0) || (pin == D1) || (pin == D2) || (pin == D3) || (pin == D4) || (pin == D5) || (pin == D6) ) )
119119
{
120120
return false;
121121
}
122-
122+
123123
return true;
124124
}
125125

126126
// dutyCycle from 0.0f to 100.0f
127127
mbed::PwmOut* setPWM(mbed::PwmOut* &pwm, const pin_size_t& pin, const float& frequency, const float& dutyCycle)
128128
{
129-
PWM_LOGDEBUG7("Freq = ", frequency, ", \tDutyCycle = ", dutyCycle, ", \tDutyCycle % = ", dutyCycle / 100, ", \tPin = ", pin);
130-
129+
PWM_LOGDEBUG7("Freq = ", frequency, ", \tDutyCycle = ", dutyCycle, ", \tDutyCycle % = ", dutyCycle / 100, ", \tPin = ",
130+
pin);
131+
131132
//if ( !isValidPWMPin(pin) || !isValidPWMFreq(pin, frequency) || !isValidPWMDutyCycle(pin, dutyCycle) )
132133
if ( !isValidPWMSettings(pin, frequency, dutyCycle) )
133134
{
134135
//PWM_LOGERROR("Bad pin, Freq or dutyCycle");
135-
136+
136137
return NULL;
137138
}
138139

139140
float percent = (float) dutyCycle / 100;
140-
141+
141142
if (digitalPinToPwm(pin) == NULL)
142143
{
143144
PWM_LOGDEBUG("New pwm");
144-
145+
145146
pwm = new mbed::PwmOut(digitalPinToPinName(pin));
146-
147+
147148
digitalPinToPwm(pin) = pwm;
148149

149-
pwm->period_us( 1000000.0f/frequency );
150+
pwm->period_us( 1000000.0f / frequency );
150151

151152
pwm->write(percent);
152153
}
153154
else if (pwm && (digitalPinToPwm(pin) == pwm) )
154155
{
155156
PWM_LOGDEBUG("Use existing pwm");
156-
157-
pwm->period_us( 1000000.0f/frequency );
157+
158+
pwm->period_us( 1000000.0f / frequency );
158159

159160
pwm->write(percent);
160161
}
161-
162+
162163
return pwm;
163164
}
164165

0 commit comments

Comments
 (0)