Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45c4aca9e9 | ||
|
|
fbac2f8a3b | ||
|
|
df10f8d531 | ||
|
|
f9b2692779 | ||
|
|
7db4a62cb4 | ||
|
|
1dfedfeb81 | ||
|
|
511ab8846e | ||
|
|
3414e92753 | ||
|
|
d238261964 | ||
|
|
848a1d5b7e | ||
|
|
2b37b5925d | ||
|
|
6b319e531f | ||
|
|
b7d8f4b4b7 |
@@ -0,0 +1,7 @@
|
|||||||
|
# See: https://github.com/codespell-project/codespell#using-a-config-file
|
||||||
|
[codespell]
|
||||||
|
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
|
||||||
|
ignore-words-list = ,
|
||||||
|
check-filenames =
|
||||||
|
check-hidden =
|
||||||
|
skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches
|
||||||
@@ -36,7 +36,7 @@ If applicable, add screenshots to help explain your problem.
|
|||||||
Please ensure to specify the following:
|
Please ensure to specify the following:
|
||||||
|
|
||||||
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
|
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
|
||||||
* `RP2040` Core Version (e.g. RP2040 core v2.5.4)
|
* `RP2040` Core Version (e.g. RP2040 core v2.6.3)
|
||||||
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
|
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
|
||||||
* Contextual information (e.g. what you were trying to achieve)
|
* Contextual information (e.g. what you were trying to achieve)
|
||||||
* Simplest possible steps to reproduce
|
* Simplest possible steps to reproduce
|
||||||
@@ -49,14 +49,13 @@ Please ensure to specify the following:
|
|||||||
|
|
||||||
```
|
```
|
||||||
Arduino IDE version: 1.8.19
|
Arduino IDE version: 1.8.19
|
||||||
RP2040 core v2.5.4
|
RP2040 core v2.6.3
|
||||||
RASPBERRY_PI_PICO Module
|
RASPBERRY_PI_PICO Module
|
||||||
OS: Ubuntu 20.04 LTS
|
OS: Ubuntu 20.04 LTS
|
||||||
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
||||||
|
|
||||||
Context:
|
Context:
|
||||||
I encountered a crash while using this library
|
I encountered a crash while using this library
|
||||||
|
|
||||||
Steps to reproduce:
|
Steps to reproduce:
|
||||||
1. ...
|
1. ...
|
||||||
2. ...
|
2. ...
|
||||||
@@ -67,3 +66,34 @@ Steps to reproduce:
|
|||||||
### Additional context
|
### Additional context
|
||||||
|
|
||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 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/RPI_PICO_TimerInterrupt/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/RPI_PICO_TimerInterrupt_GitHub/
|
||||||
|
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Issue astyle command
|
||||||
|
|
||||||
|
```
|
||||||
|
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$ bash utils/restyle.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
# Configure check for outdated GitHub Actions actions in workflows.
|
||||||
|
# See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: / # Check the repository's workflows under /.github/workflows/
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
+1
-1
@@ -24,7 +24,7 @@ markComment: >
|
|||||||
for your contributions.
|
for your contributions.
|
||||||
|
|
||||||
unmarkComment: >
|
unmarkComment: >
|
||||||
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.
|
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it opening the future.
|
||||||
|
|
||||||
closeComment: >
|
closeComment: >
|
||||||
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.
|
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ jobs:
|
|||||||
check-bats-version:
|
check-bats-version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
- run: npm install -g bats
|
- run: npm install -g bats
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
name: Check Arduino
|
||||||
|
|
||||||
|
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
schedule:
|
||||||
|
# Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint.
|
||||||
|
- cron: "0 8 * * TUE"
|
||||||
|
workflow_dispatch:
|
||||||
|
repository_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Arduino Lint
|
||||||
|
uses: arduino/arduino-lint-action@v1
|
||||||
|
with:
|
||||||
|
compliance: specification
|
||||||
|
library-manager: update
|
||||||
|
# Always use this setting for official repositories. Remove for 3rd party projects.
|
||||||
|
official: true
|
||||||
|
project-type: library
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
name: Report Size Deltas
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '*/5 * * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
report:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Comment size deltas reports to PRs
|
||||||
|
uses: arduino/report-size-deltas@v1
|
||||||
|
with:
|
||||||
|
# The name of the workflow artifact created by the "Compile Examples" workflow
|
||||||
|
sketches-reports-source: sketches-reports
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: Spell Check
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
schedule:
|
||||||
|
# run every Tuesday at 3 AM UTC
|
||||||
|
- cron: "0 3 * * 2"
|
||||||
|
workflow_dispatch:
|
||||||
|
repository_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
spellcheck:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# See: https://github.com/codespell-project/actions-codespell/blob/master/README.md
|
||||||
|
- name: Spell check
|
||||||
|
uses: codespell-project/actions-codespell@master
|
||||||
+29
-4
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
|
|||||||
Please ensure to specify the following:
|
Please ensure to specify the following:
|
||||||
|
|
||||||
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
|
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
|
||||||
* `RP2040` Core Version (e.g. RP2040 core v2.5.4)
|
* `RP2040` Core Version (e.g. RP2040 core v2.6.3)
|
||||||
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
|
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
|
||||||
* Contextual information (e.g. what you were trying to achieve)
|
* Contextual information (e.g. what you were trying to achieve)
|
||||||
* Simplest possible steps to reproduce
|
* Simplest possible steps to reproduce
|
||||||
@@ -28,27 +28,52 @@ Please ensure to specify the following:
|
|||||||
|
|
||||||
```
|
```
|
||||||
Arduino IDE version: 1.8.19
|
Arduino IDE version: 1.8.19
|
||||||
RP2040 core v2.5.4
|
RP2040 core v2.6.3
|
||||||
RASPBERRY_PI_PICO Module
|
RASPBERRY_PI_PICO Module
|
||||||
OS: Ubuntu 20.04 LTS
|
OS: Ubuntu 20.04 LTS
|
||||||
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
||||||
|
|
||||||
Context:
|
Context:
|
||||||
I encountered a crash while using this library
|
I encountered a crash while using this library
|
||||||
|
|
||||||
Steps to reproduce:
|
Steps to reproduce:
|
||||||
1. ...
|
1. ...
|
||||||
2. ...
|
2. ...
|
||||||
3. ...
|
3. ...
|
||||||
4. ...
|
4. ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Additional context
|
||||||
|
|
||||||
|
Add any other context about the problem here.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Sending Feature Requests
|
### Sending Feature Requests
|
||||||
|
|
||||||
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
|
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/RPI_PICO_TimerInterrupt/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
|
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Sending Pull Requests
|
### Sending Pull Requests
|
||||||
|
|
||||||
Pull Requests with changes and fixes are also welcome!
|
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/RPI_PICO_TimerInterrupt_GitHub/
|
||||||
|
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Issue astyle command
|
||||||
|
|
||||||
|
```
|
||||||
|
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$ bash utils/restyle.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,11 @@
|
|||||||
[](#Contributing)
|
[](#Contributing)
|
||||||
[](http://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues)
|
[](http://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues)
|
||||||
|
|
||||||
|
|
||||||
<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>
|
<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>
|
||||||
<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>
|
<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>
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -87,7 +89,7 @@ This library enables you to use Interrupt from Hardware Timers on on RP2040-base
|
|||||||
|
|
||||||
As **Hardware Timers are rare, and very precious assets** of any board, this library now enables you to use up to **16 ISR-based Timers, while consuming only 1 Hardware Timer**. Timers' interval is very long (**ulong millisecs**).
|
As **Hardware Timers are rare, and very precious assets** of any board, this library now enables you to use up to **16 ISR-based Timers, while consuming only 1 Hardware Timer**. Timers' interval is very long (**ulong millisecs**).
|
||||||
|
|
||||||
Now with these new **16 ISR-based timers**, the maximum interval is **practically unlimited** (limited only by unsigned long miliseconds) while **the accuracy is nearly perfect** compared to software timers.
|
Now with these new **16 ISR-based timers**, the maximum interval is **practically unlimited** (limited only by unsigned long milliseconds) while **the accuracy is nearly perfect** compared to software timers.
|
||||||
|
|
||||||
The most important feature is they're ISR-based timers. Therefore, their executions are **not blocked by bad-behaving functions / tasks**. This important feature is absolutely necessary for mission-critical tasks.
|
The most important feature is they're ISR-based timers. Therefore, their executions are **not blocked by bad-behaving functions / tasks**. This important feature is absolutely necessary for mission-critical tasks.
|
||||||
|
|
||||||
@@ -98,11 +100,11 @@ Being ISR-based timers, their executions are not blocked by bad-behaving functio
|
|||||||
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
|
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
|
||||||
|
|
||||||
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task
|
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task
|
||||||
in loop(), using delay() function as an example. The elapsed time then is very unaccurate
|
in `loop()`, using delay() function as an example. The elapsed time then is very unaccurate
|
||||||
|
|
||||||
### Why using ISR-based Hardware Timer Interrupt is better
|
### Why using ISR-based Hardware Timer Interrupt is better
|
||||||
|
|
||||||
Imagine you have a system with a **mission-critical** function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function is **blocking** the loop() or setup().
|
Imagine you have a system with a **mission-critical** function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in `loop()`. But what if another function is **blocking** the `loop()` or `setup()`.
|
||||||
|
|
||||||
So your function **might not be executed, and the result would be disastrous.**
|
So your function **might not be executed, and the result would be disastrous.**
|
||||||
|
|
||||||
@@ -110,14 +112,15 @@ You'd prefer to have your function called, no matter what happening with other f
|
|||||||
|
|
||||||
The correct choice is to use a Hardware Timer with **Interrupt** to call your function.
|
The correct choice is to use a Hardware Timer with **Interrupt** to call your function.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||
[**HOWTO Attach Interrupt**](https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/)
|
[**HOWTO Attach Interrupt**](https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/)
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Currently supported Boards
|
### Currently supported Boards
|
||||||
@@ -140,9 +143,13 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
|
|||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [](https://github.com/arduino/Arduino/releases/latest)
|
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [](https://github.com/arduino/Arduino/releases/latest)
|
||||||
2. [`Earle Philhower's arduino-pico core v2.5.4+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [](https://github.com/earlephilhower/arduino-pico/releases/latest)
|
2. [`Earle Philhower's arduino-pico core v2.6.3+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [](https://github.com/earlephilhower/arduino-pico/releases/latest)
|
||||||
3. To use with certain example
|
3. To use with certain example, depending on which Ethernet card you're using:
|
||||||
- [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) and [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) examples.
|
- [`Ethernet_Generic library v2.7.1+`](https://github.com/khoih-prog/Ethernet_Generic) for W5100, W5200 and W5500. [](https://github.com/khoih-prog/Ethernet_Generic/releases/latest)
|
||||||
|
- [`EthernetENC library v2.0.3+`](https://github.com/jandrassy/EthernetENC) for ENC28J60. [](https://github.com/jandrassy/EthernetENC/releases/latest). **New and Better**
|
||||||
|
- [`UIPEthernet library v2.0.12+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. [](https://github.com/UIPEthernet/UIPEthernet/releases/latest)
|
||||||
|
4. To use with certain example
|
||||||
|
- [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) and [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) examples.
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -220,7 +227,7 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.
|
|||||||
|
|
||||||
You can include these `.hpp` or `.h` files
|
You can include these `.hpp` or `.h` files
|
||||||
|
|
||||||
```
|
```C++
|
||||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||||
#include "RPi_Pico_TimerInterrupt.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
#include "RPi_Pico_TimerInterrupt.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||||
|
|
||||||
@@ -230,7 +237,7 @@ You can include these `.hpp` or `.h` files
|
|||||||
|
|
||||||
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
|
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
|
||||||
|
|
||||||
```
|
```C++
|
||||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||||
#include "RPi_Pico_ISR_Timer.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
#include "RPi_Pico_ISR_Timer.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||||
```
|
```
|
||||||
@@ -249,7 +256,7 @@ The RPI_PICO system timer peripheral provides a global microsecond timebase for
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Now with these new `16 ISR-based timers` (while consuming only **1 hardware timer**), the maximum interval is practically unlimited (limited only by unsigned long miliseconds). The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
Now with these new `16 ISR-based timers` (while consuming only **1 hardware timer**), the maximum interval is practically unlimited (limited only by unsigned long milliseconds). The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||||
This important feature is absolutely necessary for mission-critical tasks.
|
This important feature is absolutely necessary for mission-critical tasks.
|
||||||
|
|
||||||
The `ISR_Timer_Complex` example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs of each type of timers.
|
The `ISR_Timer_Complex` example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs of each type of timers.
|
||||||
@@ -271,7 +278,7 @@ Before using any Timer, you have to make sure the Timer has not been used by any
|
|||||||
|
|
||||||
### 1.1 Init Hardware Timer
|
### 1.1 Init Hardware Timer
|
||||||
|
|
||||||
```
|
```C++
|
||||||
// Select the timer you're using, from ITimer0(0)-ITimer3(3)
|
// Select the timer you're using, from ITimer0(0)-ITimer3(3)
|
||||||
// Init RPI_PICO_Timer
|
// Init RPI_PICO_Timer
|
||||||
RPI_PICO_Timer ITimer1(1);
|
RPI_PICO_Timer ITimer1(1);
|
||||||
@@ -281,7 +288,7 @@ RPI_PICO_Timer ITimer1(1);
|
|||||||
|
|
||||||
Use one of these functions with **interval in unsigned long microseconds**
|
Use one of these functions with **interval in unsigned long microseconds**
|
||||||
|
|
||||||
```
|
```C++
|
||||||
// interval (in us), callback is ISR
|
// interval (in us), callback is ISR
|
||||||
bool setInterval(unsigned long interval, pico_timer_callback callback);
|
bool setInterval(unsigned long interval, pico_timer_callback callback);
|
||||||
|
|
||||||
@@ -291,7 +298,7 @@ bool attachInterruptInterval(unsigned long interval, pico_timer_callback callbac
|
|||||||
|
|
||||||
as follows
|
as follows
|
||||||
|
|
||||||
```
|
```C++
|
||||||
void TimerHandler()
|
void TimerHandler()
|
||||||
{
|
{
|
||||||
// Doing something here inside ISR
|
// Doing something here inside ISR
|
||||||
@@ -318,7 +325,7 @@ void setup()
|
|||||||
|
|
||||||
Use one of these functions with **frequency in float Hz**
|
Use one of these functions with **frequency in float Hz**
|
||||||
|
|
||||||
```
|
```C++
|
||||||
// frequency (in Hz), callback is ISR
|
// frequency (in Hz), callback is ISR
|
||||||
bool setFrequency(float frequency, pico_timer_callback callback)
|
bool setFrequency(float frequency, pico_timer_callback callback)
|
||||||
|
|
||||||
@@ -328,7 +335,7 @@ bool attachInterrupt(float frequency, timer_callback callback);
|
|||||||
|
|
||||||
as follows
|
as follows
|
||||||
|
|
||||||
```
|
```C++
|
||||||
void TimerHandler()
|
void TimerHandler()
|
||||||
{
|
{
|
||||||
// Doing something here inside ISR
|
// Doing something here inside ISR
|
||||||
@@ -360,7 +367,7 @@ The 16 ISR_based Timers, designed for long timer intervals, only support using *
|
|||||||
|
|
||||||
### 2.2 Init Hardware Timer and ISR-based Timer
|
### 2.2 Init Hardware Timer and ISR-based Timer
|
||||||
|
|
||||||
```
|
```C++
|
||||||
// Init RPI_PICO_Timer
|
// Init RPI_PICO_Timer
|
||||||
RPI_PICO_Timer ITimer1(1);
|
RPI_PICO_Timer ITimer1(1);
|
||||||
|
|
||||||
@@ -371,7 +378,7 @@ RPI_PICO_ISR_Timer ISR_timer;
|
|||||||
|
|
||||||
### 2.3 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
|
### 2.3 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
|
||||||
|
|
||||||
```
|
```C++
|
||||||
void TimerHandler()
|
void TimerHandler()
|
||||||
{
|
{
|
||||||
ISR_timer.run();
|
ISR_timer.run();
|
||||||
@@ -448,7 +455,7 @@ void setup()
|
|||||||
|
|
||||||
### Example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
|
### Example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
|
||||||
|
|
||||||
https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/f2ca9ced6ef985653cb234a3268b237b0fa257f1/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino#L23-L166
|
https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/b7d8f4b4b7eabec8c140fc55d88efb82939a6ad6/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino#L23-L168
|
||||||
|
|
||||||
---
|
---
|
||||||
---
|
---
|
||||||
@@ -462,9 +469,8 @@ The following is the sample terminal output when running example [ISR_Timers_Arr
|
|||||||
While software timer, **programmed for 2s, is activated after more than 10.000s !!!**
|
While software timer, **programmed for 2s, is activated after more than 10.000s !!!**
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
|
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
|
||||||
RPi_Pico_TimerInterrupt v1.3.0
|
RPi_Pico_TimerInterrupt v1.3.1
|
||||||
CPU Frequency = 125 MHz
|
CPU Frequency = 125 MHz
|
||||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
|
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
|
||||||
[TISR] _count = 0-1000
|
[TISR] _count = 0-1000
|
||||||
@@ -489,7 +495,7 @@ The following is the sample terminal output when running example [TimerInterrupt
|
|||||||
|
|
||||||
```
|
```
|
||||||
Starting TimerInterruptTest on RASPBERRY_PI_PICO
|
Starting TimerInterruptTest on RASPBERRY_PI_PICO
|
||||||
RPi_Pico_TimerInterrupt v1.3.0
|
RPi_Pico_TimerInterrupt v1.3.1
|
||||||
CPU Frequency = 125 MHz
|
CPU Frequency = 125 MHz
|
||||||
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
|
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
|
||||||
[TISR] _count = 0-1000000
|
[TISR] _count = 0-1000000
|
||||||
@@ -533,7 +539,7 @@ The following is the sample terminal output when running example [Change_Interva
|
|||||||
|
|
||||||
```
|
```
|
||||||
Starting Change_Interval on RASPBERRY_PI_PICO
|
Starting Change_Interval on RASPBERRY_PI_PICO
|
||||||
RPi_Pico_TimerInterrupt v1.3.0
|
RPi_Pico_TimerInterrupt v1.3.1
|
||||||
CPU Frequency = 125 MHz
|
CPU Frequency = 125 MHz
|
||||||
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
|
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
|
||||||
[TISR] _count = 0-2000000
|
[TISR] _count = 0-2000000
|
||||||
@@ -614,7 +620,7 @@ The following is the sample terminal output when running example [SwitchDebounce
|
|||||||
|
|
||||||
```
|
```
|
||||||
Starting SwitchDebounce on RASPBERRY_PI_PICO
|
Starting SwitchDebounce on RASPBERRY_PI_PICO
|
||||||
RPi_Pico_TimerInterrupt v1.3.0
|
RPi_Pico_TimerInterrupt v1.3.1
|
||||||
CPU Frequency = 125 MHz
|
CPU Frequency = 125 MHz
|
||||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 50.00
|
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 50.00
|
||||||
[TISR] _count = 0-20000
|
[TISR] _count = 0-20000
|
||||||
@@ -639,7 +645,7 @@ The following is the sample terminal output when running example [ISR_Timers_Arr
|
|||||||
|
|
||||||
```
|
```
|
||||||
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
|
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
|
||||||
RPi_Pico_TimerInterrupt v1.3.0
|
RPi_Pico_TimerInterrupt v1.3.1
|
||||||
CPU Frequency = 125 MHz
|
CPU Frequency = 125 MHz
|
||||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
|
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
|
||||||
[TISR] _count = 0-1000
|
[TISR] _count = 0-1000
|
||||||
@@ -662,7 +668,7 @@ The following is the sample terminal output when running example [ISR_16_Timers_
|
|||||||
|
|
||||||
```
|
```
|
||||||
Starting ISR_16_Timers_Array_Complex on RASPBERRY_PI_PICO
|
Starting ISR_16_Timers_Array_Complex on RASPBERRY_PI_PICO
|
||||||
RPi_Pico_TimerInterrupt v1.3.0
|
RPi_Pico_TimerInterrupt v1.3.1
|
||||||
CPU Frequency = 125 MHz
|
CPU Frequency = 125 MHz
|
||||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
|
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
|
||||||
[TISR] _count = 0-10000
|
[TISR] _count = 0-10000
|
||||||
@@ -815,7 +821,7 @@ Debug is enabled by default on Serial.
|
|||||||
|
|
||||||
You can also change the debugging level (_TIMERINTERRUPT_LOGLEVEL_) from 0 to 4
|
You can also change the debugging level (_TIMERINTERRUPT_LOGLEVEL_) from 0 to 4
|
||||||
|
|
||||||
```cpp
|
```C++
|
||||||
// These define's must be placed at the beginning before #include "RPI_PICO_TimerInterrupt.h"
|
// These define's must be placed at the beginning before #include "RPI_PICO_TimerInterrupt.h"
|
||||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||||
@@ -850,15 +856,17 @@ Submit issues to: [RPI_PICO_TimerInterrupt issues](https://github.com/khoih-prog
|
|||||||
|
|
||||||
## DONE
|
## DONE
|
||||||
|
|
||||||
1. Basic hardware timers for **RP2040-based boards such as RASPBERRY_PI_PICO**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
|
1. Basic hardware timers for **RP2040-based boards such as RASPBERRY_PI_PICO**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
|
||||||
2. More hardware-initiated software-enabled timers
|
2. More hardware-initiated software-enabled timers
|
||||||
3. Longer time interval
|
3. Longer time interval
|
||||||
4. Add Version String
|
4. Add Version String
|
||||||
5. Add Table of Contents
|
5. Add Table of Contents
|
||||||
6. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, Nano_RP2040_Connect, etc.**) using the arduino-pico core
|
6. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, Nano_RP2040_Connect, etc.**) using the arduino-pico core
|
||||||
7. Fix `multiple-definitions` linker error
|
7. Fix `multiple-definitions` linker error
|
||||||
8. Optimize library code by using `reference-passing` instead of `value-passing`
|
8. Optimize library code by using `reference-passing` instead of `value-passing`
|
||||||
9. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
|
9. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
|
||||||
|
10. Using `float` instead of `ulong` for better interval accuracy
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -6,12 +6,18 @@
|
|||||||
[](#Contributing)
|
[](#Contributing)
|
||||||
[](http://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues)
|
[](http://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues)
|
||||||
|
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
* [Changelog](#changelog)
|
* [Changelog](#changelog)
|
||||||
|
* [Releases v1.3.1](#releases-v131)
|
||||||
* [Releases v1.3.0](#releases-v130)
|
* [Releases v1.3.0](#releases-v130)
|
||||||
* [Releases v1.2.0](#releases-v120)
|
* [Releases v1.2.0](#releases-v120)
|
||||||
* [Releases v1.1.1](#releases-v111)
|
* [Releases v1.1.1](#releases-v111)
|
||||||
@@ -25,6 +31,10 @@
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### Releases v1.3.1
|
||||||
|
|
||||||
|
1. Using `float` instead of `ulong` for better interval accuracy
|
||||||
|
|
||||||
### Releases v1.3.0
|
### Releases v1.3.0
|
||||||
|
|
||||||
1. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
|
1. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ volatile pinStruct myOutputPins = { LED_BUILTIN, 0, 1 };
|
|||||||
|
|
||||||
bool TimerHandler(struct repeating_timer *t)
|
bool TimerHandler(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle = false;
|
static bool toggle = false;
|
||||||
|
|
||||||
//timer interrupt toggles pins
|
//timer interrupt toggles pins
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
|
|
||||||
bool TimerHandler0(struct repeating_timer *t)
|
bool TimerHandler0(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle0 = false;
|
static bool toggle0 = false;
|
||||||
|
|
||||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||||
@@ -65,6 +67,8 @@ bool TimerHandler0(struct repeating_timer *t)
|
|||||||
|
|
||||||
bool TimerHandler1(struct repeating_timer *t)
|
bool TimerHandler1(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle1 = false;
|
static bool toggle1 = false;
|
||||||
|
|
||||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ RPI_PICO_Timer ITimer2(2);
|
|||||||
|
|
||||||
bool TimerHandler1(struct repeating_timer *t)
|
bool TimerHandler1(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle1 = false;
|
static bool toggle1 = false;
|
||||||
|
|
||||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||||
@@ -61,6 +63,8 @@ bool TimerHandler1(struct repeating_timer *t)
|
|||||||
|
|
||||||
bool TimerHandler2(struct repeating_timer *t)
|
bool TimerHandler2(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle2 = false;
|
static bool toggle2 = false;
|
||||||
|
|
||||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ volatile uint32_t Timer1Count = 0;
|
|||||||
|
|
||||||
bool TimerHandler0(struct repeating_timer *t)
|
bool TimerHandler0(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle0 = false;
|
static bool toggle0 = false;
|
||||||
|
|
||||||
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
|
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
|
||||||
@@ -70,6 +72,8 @@ bool TimerHandler0(struct repeating_timer *t)
|
|||||||
|
|
||||||
bool TimerHandler1(struct repeating_timer *t)
|
bool TimerHandler1(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle1 = false;
|
static bool toggle1 = false;
|
||||||
|
|
||||||
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
|
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ RPI_PICO_ISR_Timer ISR_Timer;
|
|||||||
// Never use Serial.print inside this ISR. Will hang the system
|
// Never use Serial.print inside this ISR. Will hang the system
|
||||||
bool TimerHandler(struct repeating_timer *t)
|
bool TimerHandler(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle = false;
|
static bool toggle = false;
|
||||||
static int timeRun = 0;
|
static int timeRun = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ volatile uint32_t previousMillis5s = 0;
|
|||||||
|
|
||||||
bool TimerHandler(struct repeating_timer *t)
|
bool TimerHandler(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle = false;
|
static bool toggle = false;
|
||||||
static int timeRun = 0;
|
static int timeRun = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ volatile int debounceCounter;
|
|||||||
|
|
||||||
bool TimerHandler0(struct repeating_timer *t)
|
bool TimerHandler0(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
if ( !digitalRead(SWPin) && (debounceCounter >= DEBOUNCING_INTERVAL_MS / TIMER0_INTERVAL_MS ) )
|
if ( !digitalRead(SWPin) && (debounceCounter >= DEBOUNCING_INTERVAL_MS / TIMER0_INTERVAL_MS ) )
|
||||||
{
|
{
|
||||||
//min time between pulses has passed
|
//min time between pulses has passed
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ volatile bool SWLongPressed = false;
|
|||||||
|
|
||||||
bool TimerHandler1(struct repeating_timer *t)
|
bool TimerHandler1(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static unsigned int debounceCountSWPressed = 0;
|
static unsigned int debounceCountSWPressed = 0;
|
||||||
static unsigned int debounceCountSWReleased = 0;
|
static unsigned int debounceCountSWReleased = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,8 @@
|
|||||||
|
|
||||||
bool TimerHandler0(struct repeating_timer *t)
|
bool TimerHandler0(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle0 = false;
|
static bool toggle0 = false;
|
||||||
static bool started = false;
|
static bool started = false;
|
||||||
|
|
||||||
@@ -70,6 +72,8 @@ bool TimerHandler0(struct repeating_timer *t)
|
|||||||
|
|
||||||
bool TimerHandler1(struct repeating_timer *t)
|
bool TimerHandler1(struct repeating_timer *t)
|
||||||
{
|
{
|
||||||
|
(void) t;
|
||||||
|
|
||||||
static bool toggle1 = false;
|
static bool toggle1 = false;
|
||||||
static bool started = false;
|
static bool started = false;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "RPI_PICO_TimerInterrupt",
|
"name": "RPI_PICO_TimerInterrupt",
|
||||||
"version": "1.3.0",
|
"version": "1.3.1",
|
||||||
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, non-blocking, raspberry-pico, rpi-pico, pico, rp2040, arduino-pico, rp2040w, raspberry-pico-w, pico-w",
|
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, non-blocking, raspberry-pico, rpi-pico, pico, rp2040, arduino-pico, rp2040w, raspberry-pico-w, pico-w",
|
||||||
"description": "This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO. It now supports 16 ISR-based timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. 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.",
|
"description": "This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO. It now supports 16 ISR-based timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. 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.",
|
||||||
"authors":
|
"authors":
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name=RPI_PICO_TimerInterrupt
|
name=RPI_PICO_TimerInterrupt
|
||||||
version=1.3.0
|
version=1.3.1
|
||||||
author=Khoi Hoang <khoih.prog@gmail.com>
|
author=Khoi Hoang <khoih.prog@gmail.com>
|
||||||
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
||||||
sentence=This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO
|
sentence=This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
;default_envs = ESP32
|
;default_envs = ESP32
|
||||||
;default_envs = SAMD
|
;default_envs = SAMD
|
||||||
default_envs = pico
|
default_envs = pico
|
||||||
|
;default_envs = mbed_pico
|
||||||
;default_envs = NRF52
|
;default_envs = NRF52
|
||||||
;default_envs = STM32
|
;default_envs = STM32
|
||||||
;default_envs = portenta_h7_m7
|
;default_envs = portenta_h7_m7
|
||||||
@@ -38,7 +39,6 @@ upload_speed = 921600
|
|||||||
;monitor_port = COM11
|
;monitor_port = COM11
|
||||||
|
|
||||||
; Checks for the compatibility with frameworks and dev/platforms
|
; Checks for the compatibility with frameworks and dev/platforms
|
||||||
; To adjust as necessary
|
|
||||||
lib_compat_mode = strict
|
lib_compat_mode = strict
|
||||||
lib_ldf_mode = chain+
|
lib_ldf_mode = chain+
|
||||||
;lib_ldf_mode = deep+
|
;lib_ldf_mode = deep+
|
||||||
@@ -49,7 +49,7 @@ lib_deps =
|
|||||||
build_flags =
|
build_flags =
|
||||||
; set your debug output (default=Serial)
|
; set your debug output (default=Serial)
|
||||||
; -D DEBUG_ESP_PORT=Serial
|
; -D DEBUG_ESP_PORT=Serial
|
||||||
; comment the folowing line to enable WiFi debugging
|
; comment the following line to enable WiFi debugging
|
||||||
; -D NDEBUG
|
; -D NDEBUG
|
||||||
|
|
||||||
[env:portenta_h7_m7]
|
[env:portenta_h7_m7]
|
||||||
@@ -64,7 +64,17 @@ framework = arduino
|
|||||||
|
|
||||||
[env:pico]
|
[env:pico]
|
||||||
; ============================================================
|
; ============================================================
|
||||||
; Just a sample
|
; Just a sample for arduino-pice core
|
||||||
|
; You have to research and fix if there is issue
|
||||||
|
; ============================================================
|
||||||
|
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||||
|
board = pico
|
||||||
|
framework = arduino
|
||||||
|
board_build.core = earlephilhower
|
||||||
|
|
||||||
|
[env:mbed_pico]
|
||||||
|
; ============================================================
|
||||||
|
; Just a sample for mbed_rp2040 and mbed_nano cores
|
||||||
; You have to research and fix if there is issue
|
; You have to research and fix if there is issue
|
||||||
; ============================================================
|
; ============================================================
|
||||||
platform = raspberrypi
|
platform = raspberrypi
|
||||||
|
|||||||
@@ -1,40 +1,41 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
RPi_Pico_ISR_Timer-Impl.h
|
RPi_Pico_ISR_Timer-Impl.h
|
||||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||||
Written by Khoi Hoang
|
Written by Khoi Hoang
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||||
interrupts based on this timebase. It supports the following features:
|
interrupts based on this timebase. It supports the following features:
|
||||||
• A single 64-bit counter, incrementing once per microsecond
|
• A single 64-bit counter, incrementing once per microsecond
|
||||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||||
|
|
||||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||||
This important feature is absolutely necessary for mission-critical tasks.
|
This important feature is absolutely necessary for mission-critical tasks.
|
||||||
|
|
||||||
Based on SimpleTimer - A timer library for Arduino.
|
Based on SimpleTimer - A timer library for Arduino.
|
||||||
Author: mromani@ottotecnica.com
|
Author: mromani@ottotecnica.com
|
||||||
Copyright (c) 2010 OTTOTECNICA Italy
|
Copyright (c) 2010 OTTOTECNICA Italy
|
||||||
|
|
||||||
Based on BlynkTimer.h
|
Based on BlynkTimer.h
|
||||||
Author: Volodymyr Shymanskyy
|
Author: Volodymyr Shymanskyy
|
||||||
|
|
||||||
Version: 1.3.0
|
Version: 1.3.1
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||||
|
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -53,11 +54,11 @@ RPI_PICO_ISR_Timer::RPI_PICO_ISR_Timer()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::init()
|
void RPI_PICO_ISR_Timer::init()
|
||||||
{
|
{
|
||||||
unsigned long current_millis = millis(); //elapsed();
|
unsigned long current_millis = millis(); //elapsed();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
memset((void*) &timer[i], 0, sizeof (timer_t));
|
memset((void*) &timer[i], 0, sizeof (timer_t));
|
||||||
timer[i].prev_millis = current_millis;
|
timer[i].prev_millis = current_millis;
|
||||||
@@ -68,7 +69,7 @@ void RPI_PICO_ISR_Timer::init()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::run()
|
void RPI_PICO_ISR_Timer::run()
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
unsigned long current_millis;
|
unsigned long current_millis;
|
||||||
@@ -78,43 +79,43 @@ void RPI_PICO_ISR_Timer::run()
|
|||||||
|
|
||||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during ISR
|
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during ISR
|
||||||
rp2040.idleOtherCore();
|
rp2040.idleOtherCore();
|
||||||
|
|
||||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_DONTRUN;
|
timer[i].toBeCalled = RPI_PICO_DEFCALL_DONTRUN;
|
||||||
|
|
||||||
// no callback == no timer, i.e. jump over empty slots
|
// no callback == no timer, i.e. jump over empty slots
|
||||||
if (timer[i].callback != NULL)
|
if (timer[i].callback != NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
// is it time to process this timer ?
|
// is it time to process this timer ?
|
||||||
// see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592
|
// see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592
|
||||||
|
|
||||||
if ((current_millis - timer[i].prev_millis) >= timer[i].delay)
|
if ((current_millis - timer[i].prev_millis) >= timer[i].delay)
|
||||||
{
|
{
|
||||||
unsigned long skipTimes = (current_millis - timer[i].prev_millis) / timer[i].delay;
|
unsigned long skipTimes = (current_millis - timer[i].prev_millis) / timer[i].delay;
|
||||||
|
|
||||||
// update time
|
// update time
|
||||||
timer[i].prev_millis += timer[i].delay * skipTimes;
|
timer[i].prev_millis += timer[i].delay * skipTimes;
|
||||||
|
|
||||||
// check if the timer callback has to be executed
|
// check if the timer callback has to be executed
|
||||||
if (timer[i].enabled)
|
if (timer[i].enabled)
|
||||||
{
|
{
|
||||||
|
|
||||||
// "run forever" timers must always be executed
|
// "run forever" timers must always be executed
|
||||||
if (timer[i].maxNumRuns == RPI_PICO_RUN_FOREVER)
|
if (timer[i].maxNumRuns == RPI_PICO_RUN_FOREVER)
|
||||||
{
|
{
|
||||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||||
}
|
}
|
||||||
// other timers get executed the specified number of times
|
// other timers get executed the specified number of times
|
||||||
else if (timer[i].numRuns < timer[i].maxNumRuns)
|
else if (timer[i].numRuns < timer[i].maxNumRuns)
|
||||||
{
|
{
|
||||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||||
timer[i].numRuns++;
|
timer[i].numRuns++;
|
||||||
|
|
||||||
// after the last run, delete the timer
|
// after the last run, delete the timer
|
||||||
if (timer[i].numRuns >= timer[i].maxNumRuns)
|
if (timer[i].numRuns >= timer[i].maxNumRuns)
|
||||||
{
|
{
|
||||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNANDDEL;
|
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNANDDEL;
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,7 @@ void RPI_PICO_ISR_Timer::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
if (timer[i].toBeCalled == RPI_PICO_DEFCALL_DONTRUN)
|
if (timer[i].toBeCalled == RPI_PICO_DEFCALL_DONTRUN)
|
||||||
continue;
|
continue;
|
||||||
@@ -147,18 +148,18 @@ void RPI_PICO_ISR_Timer::run()
|
|||||||
|
|
||||||
// find the first available slot
|
// find the first available slot
|
||||||
// return -1 if none found
|
// return -1 if none found
|
||||||
int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
||||||
{
|
{
|
||||||
// all slots are used
|
// all slots are used
|
||||||
if (numTimers >= RPI_PICO_MAX_TIMERS)
|
if (numTimers >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the first slot with no callback (i.e. free)
|
// return the first slot with no callback (i.e. free)
|
||||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
if (timer[i].callback == NULL)
|
if (timer[i].callback == NULL)
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -170,22 +171,23 @@ int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int RPI_PICO_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n)
|
int RPI_PICO_ISR_Timer::setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n)
|
||||||
{
|
{
|
||||||
int freeTimer;
|
int freeTimer;
|
||||||
|
|
||||||
if (numTimers < 0)
|
if (numTimers < 0)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
freeTimer = findFirstFreeSlot();
|
freeTimer = findFirstFreeSlot();
|
||||||
if (freeTimer < 0)
|
|
||||||
|
if (freeTimer < 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -205,57 +207,57 @@ int RPI_PICO_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p, boo
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback f, const unsigned& n)
|
int RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback f, const unsigned& n)
|
||||||
{
|
{
|
||||||
return setupTimer(d, (void *)f, NULL, false, n);
|
return setupTimer(d, (void *)f, NULL, false, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback_p f, void* p, const unsigned& n)
|
int RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n)
|
||||||
{
|
{
|
||||||
return setupTimer(d, (void *)f, p, true, n);
|
return setupTimer(d, (void *)f, p, true, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback f)
|
int RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback f)
|
||||||
{
|
{
|
||||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
|
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback_p f, void* p)
|
int RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback_p f, void* p)
|
||||||
{
|
{
|
||||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_FOREVER);
|
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback f)
|
int RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback f)
|
||||||
{
|
{
|
||||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
|
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback_p f, void* p)
|
int RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback_p f, void* p)
|
||||||
{
|
{
|
||||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_ONCE);
|
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_ONCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const unsigned long& d)
|
bool RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const float& d)
|
||||||
{
|
{
|
||||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates interval of existing specified timer
|
// Updates interval of existing specified timer
|
||||||
if (timer[numTimer].callback != NULL)
|
if (timer[numTimer].callback != NULL)
|
||||||
{
|
{
|
||||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||||
rp2040.idleOtherCore();
|
rp2040.idleOtherCore();
|
||||||
@@ -268,28 +270,28 @@ bool RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const unsigned
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// false return for non-used numTimer, no callback
|
// false return for non-used numTimer, no callback
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::deleteTimer(const unsigned& timerId)
|
void RPI_PICO_ISR_Timer::deleteTimer(const unsigned& timerId)
|
||||||
{
|
{
|
||||||
if (timerId >= RPI_PICO_MAX_TIMERS)
|
if (timerId >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nothing to delete if no timers are in use
|
// nothing to delete if no timers are in use
|
||||||
if (numTimers == 0)
|
if (numTimers == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't decrease the number of timers if the specified slot is already empty
|
// don't decrease the number of timers if the specified slot is already empty
|
||||||
if (timer[timerId].callback != NULL)
|
if (timer[timerId].callback != NULL)
|
||||||
{
|
{
|
||||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||||
rp2040.idleOtherCore();
|
rp2040.idleOtherCore();
|
||||||
@@ -309,9 +311,9 @@ void RPI_PICO_ISR_Timer::deleteTimer(const unsigned& timerId)
|
|||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// function contributed by code@rowansimms.com
|
// function contributed by code@rowansimms.com
|
||||||
void RPI_PICO_ISR_Timer::restartTimer(const unsigned& numTimer)
|
void RPI_PICO_ISR_Timer::restartTimer(const unsigned& numTimer)
|
||||||
{
|
{
|
||||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -327,9 +329,9 @@ void RPI_PICO_ISR_Timer::restartTimer(const unsigned& numTimer)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool RPI_PICO_ISR_Timer::isEnabled(const unsigned& numTimer)
|
bool RPI_PICO_ISR_Timer::isEnabled(const unsigned& numTimer)
|
||||||
{
|
{
|
||||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -339,9 +341,9 @@ bool RPI_PICO_ISR_Timer::isEnabled(const unsigned& numTimer)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::enable(const unsigned& numTimer)
|
void RPI_PICO_ISR_Timer::enable(const unsigned& numTimer)
|
||||||
{
|
{
|
||||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -351,9 +353,9 @@ void RPI_PICO_ISR_Timer::enable(const unsigned& numTimer)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::disable(const unsigned& numTimer)
|
void RPI_PICO_ISR_Timer::disable(const unsigned& numTimer)
|
||||||
{
|
{
|
||||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -363,16 +365,16 @@ void RPI_PICO_ISR_Timer::disable(const unsigned& numTimer)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::enableAll()
|
void RPI_PICO_ISR_Timer::enableAll()
|
||||||
{
|
{
|
||||||
// Enable all timers with a callback assigned (used)
|
// Enable all timers with a callback assigned (used)
|
||||||
|
|
||||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||||
rp2040.idleOtherCore();
|
rp2040.idleOtherCore();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||||
{
|
{
|
||||||
timer[i].enabled = true;
|
timer[i].enabled = true;
|
||||||
}
|
}
|
||||||
@@ -384,16 +386,16 @@ void RPI_PICO_ISR_Timer::enableAll()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::disableAll()
|
void RPI_PICO_ISR_Timer::disableAll()
|
||||||
{
|
{
|
||||||
// Disable all timers with a callback assigned (used)
|
// Disable all timers with a callback assigned (used)
|
||||||
|
|
||||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||||
rp2040.idleOtherCore();
|
rp2040.idleOtherCore();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||||
{
|
{
|
||||||
timer[i].enabled = false;
|
timer[i].enabled = false;
|
||||||
}
|
}
|
||||||
@@ -406,9 +408,9 @@ void RPI_PICO_ISR_Timer::disableAll()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RPI_PICO_ISR_Timer::toggle(const unsigned& numTimer)
|
void RPI_PICO_ISR_Timer::toggle(const unsigned& numTimer)
|
||||||
{
|
{
|
||||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -418,7 +420,7 @@ void RPI_PICO_ISR_Timer::toggle(const unsigned& numTimer)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
unsigned RPI_PICO_ISR_Timer::getNumTimers()
|
unsigned RPI_PICO_ISR_Timer::getNumTimers()
|
||||||
{
|
{
|
||||||
return numTimers;
|
return numTimers;
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-26
@@ -1,40 +1,41 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
RPi_Pico_ISR_Timer.h
|
RPi_Pico_ISR_Timer.h
|
||||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||||
Written by Khoi Hoang
|
Written by Khoi Hoang
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||||
interrupts based on this timebase. It supports the following features:
|
interrupts based on this timebase. It supports the following features:
|
||||||
• A single 64-bit counter, incrementing once per microsecond
|
• A single 64-bit counter, incrementing once per microsecond
|
||||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||||
|
|
||||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||||
This important feature is absolutely necessary for mission-critical tasks.
|
This important feature is absolutely necessary for mission-critical tasks.
|
||||||
|
|
||||||
Based on SimpleTimer - A timer library for Arduino.
|
Based on SimpleTimer - A timer library for Arduino.
|
||||||
Author: mromani@ottotecnica.com
|
Author: mromani@ottotecnica.com
|
||||||
Copyright (c) 2010 OTTOTECNICA Italy
|
Copyright (c) 2010 OTTOTECNICA Italy
|
||||||
|
|
||||||
Based on BlynkTimer.h
|
Based on BlynkTimer.h
|
||||||
Author: Volodymyr Shymanskyy
|
Author: Volodymyr Shymanskyy
|
||||||
|
|
||||||
Version: 1.3.0
|
Version: 1.3.1
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||||
|
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|||||||
+14
-13
@@ -25,7 +25,7 @@
|
|||||||
Based on BlynkTimer.h
|
Based on BlynkTimer.h
|
||||||
Author: Volodymyr Shymanskyy
|
Author: Volodymyr Shymanskyy
|
||||||
|
|
||||||
Version: 1.3.0
|
Version: 1.3.1
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||||
|
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -56,13 +57,13 @@
|
|||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.0"
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.1"
|
||||||
|
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 0
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
|
||||||
|
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003000
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003001
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
@@ -111,35 +112,35 @@ class RPI_PICO_ISR_Timer
|
|||||||
// Timer will call function 'f' every 'd' milliseconds forever
|
// Timer will call function 'f' every 'd' milliseconds forever
|
||||||
// returns the timer number (numTimer) on success or
|
// returns the timer number (numTimer) on success or
|
||||||
// -1 on failure (f == NULL) or no free timers
|
// -1 on failure (f == NULL) or no free timers
|
||||||
int setInterval(const unsigned long& d, timer_callback f);
|
int setInterval(const float& d, timer_callback f);
|
||||||
|
|
||||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
|
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
|
||||||
// returns the timer number (numTimer) on success or
|
// returns the timer number (numTimer) on success or
|
||||||
// -1 on failure (f == NULL) or no free timers
|
// -1 on failure (f == NULL) or no free timers
|
||||||
int setInterval(const unsigned long& d, timer_callback_p f, void* p);
|
int setInterval(const float& d, timer_callback_p f, void* p);
|
||||||
|
|
||||||
// Timer will call function 'f' after 'd' milliseconds one time
|
// Timer will call function 'f' after 'd' milliseconds one time
|
||||||
// returns the timer number (numTimer) on success or
|
// returns the timer number (numTimer) on success or
|
||||||
// -1 on failure (f == NULL) or no free timers
|
// -1 on failure (f == NULL) or no free timers
|
||||||
int setTimeout(const unsigned long& d, timer_callback f);
|
int setTimeout(const float& d, timer_callback f);
|
||||||
|
|
||||||
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
|
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
|
||||||
// returns the timer number (numTimer) on success or
|
// returns the timer number (numTimer) on success or
|
||||||
// -1 on failure (f == NULL) or no free timers
|
// -1 on failure (f == NULL) or no free timers
|
||||||
int setTimeout(const unsigned long& d, timer_callback_p f, void* p);
|
int setTimeout(const float& d, timer_callback_p f, void* p);
|
||||||
|
|
||||||
// Timer will call function 'f' every 'd' milliseconds 'n' times
|
// Timer will call function 'f' every 'd' milliseconds 'n' times
|
||||||
// returns the timer number (numTimer) on success or
|
// returns the timer number (numTimer) on success or
|
||||||
// -1 on failure (f == NULL) or no free timers
|
// -1 on failure (f == NULL) or no free timers
|
||||||
int setTimer(const unsigned long& d, timer_callback f, const unsigned& n);
|
int setTimer(const float& d, timer_callback f, const unsigned& n);
|
||||||
|
|
||||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
|
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
|
||||||
// returns the timer number (numTimer) on success or
|
// returns the timer number (numTimer) on success or
|
||||||
// -1 on failure (f == NULL) or no free timers
|
// -1 on failure (f == NULL) or no free timers
|
||||||
int setTimer(const unsigned long& d, timer_callback_p f, void* p, const unsigned& n);
|
int setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n);
|
||||||
|
|
||||||
// updates interval of the specified timer
|
// updates interval of the specified timer
|
||||||
bool changeInterval(const unsigned& numTimer, const unsigned long& d);
|
bool changeInterval(const unsigned& numTimer, const float& d);
|
||||||
|
|
||||||
// destroy the specified timer
|
// destroy the specified timer
|
||||||
void deleteTimer(const unsigned& numTimer);
|
void deleteTimer(const unsigned& numTimer);
|
||||||
@@ -183,7 +184,7 @@ class RPI_PICO_ISR_Timer
|
|||||||
// low level function to initialize and enable a new timer
|
// low level function to initialize and enable a new timer
|
||||||
// returns the timer number (numTimer) on success or
|
// returns the timer number (numTimer) on success or
|
||||||
// -1 on failure (f == NULL) or no free timers
|
// -1 on failure (f == NULL) or no free timers
|
||||||
int setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n);
|
int setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n);
|
||||||
|
|
||||||
// find the first available slot
|
// find the first available slot
|
||||||
int findFirstFreeSlot();
|
int findFirstFreeSlot();
|
||||||
@@ -194,7 +195,7 @@ class RPI_PICO_ISR_Timer
|
|||||||
void* callback; // pointer to the callback function
|
void* callback; // pointer to the callback function
|
||||||
void* param; // function parameter
|
void* param; // function parameter
|
||||||
bool hasParam; // true if callback takes a parameter
|
bool hasParam; // true if callback takes a parameter
|
||||||
unsigned long delay; // delay value
|
float delay; // delay value
|
||||||
unsigned maxNumRuns; // number of runs to be executed
|
unsigned maxNumRuns; // number of runs to be executed
|
||||||
unsigned numRuns; // number of executed runs
|
unsigned numRuns; // number of executed runs
|
||||||
bool enabled; // true if enabled
|
bool enabled; // true if enabled
|
||||||
|
|||||||
@@ -1,41 +1,42 @@
|
|||||||
|
|
||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
RPi_Pico_TimerInterrupt.h
|
RPi_Pico_TimerInterrupt.h
|
||||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||||
Written by Khoi Hoang
|
Written by Khoi Hoang
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||||
interrupts based on this timebase. It supports the following features:
|
interrupts based on this timebase. It supports the following features:
|
||||||
• A single 64-bit counter, incrementing once per microsecond
|
• A single 64-bit counter, incrementing once per microsecond
|
||||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||||
|
|
||||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||||
This important feature is absolutely necessary for mission-critical tasks.
|
This important feature is absolutely necessary for mission-critical tasks.
|
||||||
|
|
||||||
Based on SimpleTimer - A timer library for Arduino.
|
Based on SimpleTimer - A timer library for Arduino.
|
||||||
Author: mromani@ottotecnica.com
|
Author: mromani@ottotecnica.com
|
||||||
Copyright (c) 2010 OTTOTECNICA Italy
|
Copyright (c) 2010 OTTOTECNICA Italy
|
||||||
|
|
||||||
Based on BlynkTimer.h
|
Based on BlynkTimer.h
|
||||||
Author: Volodymyr Shymanskyy
|
Author: Volodymyr Shymanskyy
|
||||||
|
|
||||||
Version: 1.3.0
|
Version: 1.3.1
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||||
|
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -43,11 +44,11 @@
|
|||||||
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
||||||
#define RPI_PICO_TIMERINTERRUPT_H
|
#define RPI_PICO_TIMERINTERRUPT_H
|
||||||
|
|
||||||
#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED)
|
#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED)
|
||||||
#if defined(USING_RPI_PICO_TIMER_INTERRUPT)
|
#if defined(USING_RPI_PICO_TIMER_INTERRUPT)
|
||||||
#undef USING_RPI_PICO_TIMER_INTERRUPT
|
#undef USING_RPI_PICO_TIMER_INTERRUPT
|
||||||
#endif
|
#endif
|
||||||
#define USING_RPI_PICO_TIMER_INTERRUPT true
|
#define USING_RPI_PICO_TIMER_INTERRUPT true
|
||||||
#else
|
#else
|
||||||
#error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting.
|
#error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
@@ -55,13 +56,13 @@
|
|||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.0"
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.1"
|
||||||
|
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 0
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
|
||||||
|
|
||||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003000
|
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003001
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
@@ -84,13 +85,13 @@
|
|||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*
|
/*
|
||||||
To enable an alarm:
|
To enable an alarm:
|
||||||
• Enable the interrupt at the timer with a write to the appropriate alarm bit in INTE: i.e. (1 << 0) for ALARM0
|
• Enable the interrupt at the timer with a write to the appropriate alarm bit in INTE: i.e. (1 << 0) for ALARM0
|
||||||
• Enable the appropriate timer interrupt at the processor (see Section 2.3.2)
|
• Enable the appropriate timer interrupt at the processor (see Section 2.3.2)
|
||||||
• Write the time you would like the interrupt to fire to ALARM0 (i.e. the current value in TIMERAWL plus your desired
|
• Write the time you would like the interrupt to fire to ALARM0 (i.e. the current value in TIMERAWL plus your desired
|
||||||
alarm time in microseconds). Writing the time to the ALARM register sets the ARMED bit as a side effect.
|
alarm time in microseconds). Writing the time to the ALARM register sets the ARMED bit as a side effect.
|
||||||
Once the alarm has fired, the ARMED bit will be set to 0 . To clear the latched interrupt, write a 1 to the appropriate bit in
|
Once the alarm has fired, the ARMED bit will be set to 0 . To clear the latched interrupt, write a 1 to the appropriate bit in
|
||||||
INTR.
|
INTR.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -108,64 +109,64 @@ typedef bool (*pico_timer_callback) (struct repeating_timer *t);
|
|||||||
class RPI_PICO_TimerInterrupt
|
class RPI_PICO_TimerInterrupt
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
uint8_t _timerNo;
|
uint8_t _timerNo;
|
||||||
|
|
||||||
pico_timer_callback _callback; // pointer to the callback function
|
pico_timer_callback _callback; // pointer to the callback function
|
||||||
float _frequency; // Timer frequency
|
float _frequency; // Timer frequency
|
||||||
int64_t _timerCount; // count to activate timer, in us
|
int64_t _timerCount; // count to activate timer, in us
|
||||||
|
|
||||||
struct repeating_timer _timer;
|
struct repeating_timer _timer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RPI_PICO_TimerInterrupt(uint8_t timerNo)
|
RPI_PICO_TimerInterrupt(uint8_t timerNo)
|
||||||
{
|
{
|
||||||
_timerNo = timerNo;
|
_timerNo = timerNo;
|
||||||
_callback = NULL;
|
_callback = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define TIM_CLOCK_FREQ ( (float) 1000000.0f )
|
#define TIM_CLOCK_FREQ ( (float) 1000000.0f )
|
||||||
|
|
||||||
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||||
// No params and duration now. To be added in the future by adding similar functions here
|
// No params and duration now. To be added in the future by adding similar functions here
|
||||||
bool setFrequency(const float& frequency, pico_timer_callback callback)
|
bool setFrequency(const float& frequency, pico_timer_callback callback)
|
||||||
{
|
{
|
||||||
if (_timerNo < MAX_RPI_PICO_NUM_TIMERS)
|
if (_timerNo < MAX_RPI_PICO_NUM_TIMERS)
|
||||||
{
|
{
|
||||||
if ( (frequency == 0.0f) || (frequency > 100000.0f) || (callback == NULL) )
|
if ( (frequency == 0.0f) || (frequency > 100000.0f) || (callback == NULL) )
|
||||||
{
|
{
|
||||||
TISR_LOGERROR(F("Error. frequency == 0, higher than 100KHz or callback == NULL "));
|
TISR_LOGERROR(F("Error. frequency == 0, higher than 100KHz or callback == NULL "));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now.
|
// select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now.
|
||||||
// Will use later if very low frequency is needed.
|
// Will use later if very low frequency is needed.
|
||||||
_frequency = frequency;
|
_frequency = frequency;
|
||||||
_timerCount = (int64_t) (TIM_CLOCK_FREQ / frequency);
|
_timerCount = (int64_t) (TIM_CLOCK_FREQ / frequency);
|
||||||
|
|
||||||
TISR_LOGWARN5(F("_timerNo = "), _timerNo, F(", Clock (Hz) = "), TIM_CLOCK_FREQ, F(", _fre (Hz) = "), _frequency);
|
TISR_LOGWARN5(F("_timerNo = "), _timerNo, F(", Clock (Hz) = "), TIM_CLOCK_FREQ, F(", _fre (Hz) = "), _frequency);
|
||||||
TISR_LOGWARN3(F("_count = "), (uint32_t) (_timerCount >> 32) , F("-"), (uint32_t) (_timerCount));
|
TISR_LOGWARN3(F("_count = "), (uint32_t) (_timerCount >> 32), F("-"), (uint32_t) (_timerCount));
|
||||||
|
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
|
|
||||||
// static bool add_repeating_timer_us(int64_t delay_us, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
// static bool add_repeating_timer_us(int64_t delay_us, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||||
// static bool add_repeating_timer_ms(int64_t delay_ms, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
// static bool add_repeating_timer_ms(int64_t delay_ms, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||||
// bool cancel_repeating_timer (repeating_timer_t *timer);
|
// bool cancel_repeating_timer (repeating_timer_t *timer);
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// Important Notes
|
// Important Notes
|
||||||
// delay_ms the repeat delay in milliseconds; if >0 then this is the delay between one callback ending and the next
|
// delay_ms the repeat delay in milliseconds; if >0 then this is the delay between one callback ending and the next
|
||||||
// starting; if <0 then this is the negative of the time between the starts of the callbacks.
|
// starting; if <0 then this is the negative of the time between the starts of the callbacks.
|
||||||
// The value of 0 is treated as 1 microsecond
|
// The value of 0 is treated as 1 microsecond
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
cancel_repeating_timer(&_timer);
|
cancel_repeating_timer(&_timer);
|
||||||
|
|
||||||
// Use negative value to select time between the starts of the callbacks
|
// Use negative value to select time between the starts of the callbacks
|
||||||
add_repeating_timer_us(-(_timerCount), _callback, NULL, &_timer);
|
add_repeating_timer_us(-(_timerCount), _callback, NULL, &_timer);
|
||||||
|
|
||||||
TISR_LOGWARN1(F("add_repeating_timer_us between starts = "), _timerCount);
|
TISR_LOGWARN1(F("add_repeating_timer_us between starts = "), _timerCount);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -173,7 +174,7 @@ class RPI_PICO_TimerInterrupt
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
TISR_LOGERROR(F("Error. Timer must be 0-3"));
|
TISR_LOGERROR(F("Error. Timer must be 0-3"));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,7 +183,7 @@ class RPI_PICO_TimerInterrupt
|
|||||||
|
|
||||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||||
// No params and duration now. To be added in the future by adding similar functions here
|
// No params and duration now. To be added in the future by adding similar functions here
|
||||||
bool setInterval(const unsigned long& interval, pico_timer_callback callback)
|
bool setInterval(const float& interval, pico_timer_callback callback)
|
||||||
{
|
{
|
||||||
return setFrequency((float) (1000000.0f / interval), callback);
|
return setFrequency((float) (1000000.0f / interval), callback);
|
||||||
}
|
}
|
||||||
@@ -198,7 +199,7 @@ class RPI_PICO_TimerInterrupt
|
|||||||
|
|
||||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||||
// No params and duration now. To be added in the future by adding similar functions here
|
// No params and duration now. To be added in the future by adding similar functions here
|
||||||
bool attachInterruptInterval(const unsigned long& interval, pico_timer_callback callback)
|
bool attachInterruptInterval(const float& interval, pico_timer_callback callback)
|
||||||
{
|
{
|
||||||
return setFrequency( (float) ( 1000000.0f / interval), callback);
|
return setFrequency( (float) ( 1000000.0f / interval), callback);
|
||||||
}
|
}
|
||||||
@@ -258,7 +259,7 @@ class RPI_PICO_TimerInterrupt
|
|||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}; // class RPI_PICO_TimerInterrupt
|
}; // class RPI_PICO_TimerInterrupt
|
||||||
|
|
||||||
#endif // RPI_PICO_TIMERINTERRUPT_H
|
#endif // RPI_PICO_TIMERINTERRUPT_H
|
||||||
|
|||||||
@@ -1,40 +1,41 @@
|
|||||||
/****************************************************************************************************************************
|
/****************************************************************************************************************************
|
||||||
TimerInterrupt_Generic_Debug.h
|
TimerInterrupt_Generic_Debug.h
|
||||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||||
Written by Khoi Hoang
|
Written by Khoi Hoang
|
||||||
|
|
||||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||||
Licensed under MIT license
|
Licensed under MIT license
|
||||||
|
|
||||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||||
interrupts based on this timebase. It supports the following features:
|
interrupts based on this timebase. It supports the following features:
|
||||||
• A single 64-bit counter, incrementing once per microsecond
|
• A single 64-bit counter, incrementing once per microsecond
|
||||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||||
|
|
||||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||||
This important feature is absolutely necessary for mission-critical tasks.
|
This important feature is absolutely necessary for mission-critical tasks.
|
||||||
|
|
||||||
Based on SimpleTimer - A timer library for Arduino.
|
Based on SimpleTimer - A timer library for Arduino.
|
||||||
Author: mromani@ottotecnica.com
|
Author: mromani@ottotecnica.com
|
||||||
Copyright (c) 2010 OTTOTECNICA Italy
|
Copyright (c) 2010 OTTOTECNICA Italy
|
||||||
|
|
||||||
Based on BlynkTimer.h
|
Based on BlynkTimer.h
|
||||||
Author: Volodymyr Shymanskyy
|
Author: Volodymyr Shymanskyy
|
||||||
|
|
||||||
Version: 1.3.0
|
Version: 1.3.1
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||||
|
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
# Code formatting rules for Arduino libraries, modified from for KH libraries:
|
||||||
|
#
|
||||||
|
# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
|
||||||
|
#
|
||||||
|
|
||||||
|
# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino
|
||||||
|
|
||||||
|
--mode=c
|
||||||
|
--lineend=linux
|
||||||
|
--style=allman
|
||||||
|
|
||||||
|
# -r or -R
|
||||||
|
#--recursive
|
||||||
|
|
||||||
|
# -c => Converts tabs into spaces
|
||||||
|
convert-tabs
|
||||||
|
|
||||||
|
# -s2 => 2 spaces indentation
|
||||||
|
--indent=spaces=2
|
||||||
|
|
||||||
|
# -t2 => tab =2 spaces
|
||||||
|
#--indent=tab=2
|
||||||
|
|
||||||
|
# -C
|
||||||
|
--indent-classes
|
||||||
|
|
||||||
|
# -S
|
||||||
|
--indent-switches
|
||||||
|
|
||||||
|
# -xW
|
||||||
|
--indent-preproc-block
|
||||||
|
|
||||||
|
# -Y => indent classes, switches (and cases), comments starting at column 1
|
||||||
|
--indent-col1-comments
|
||||||
|
|
||||||
|
# -M120 => maximum of 120 spaces to indent a continuation line
|
||||||
|
--max-continuation-indent=120
|
||||||
|
|
||||||
|
# -xC120 => max‑code‑length will break a line if the code exceeds # characters
|
||||||
|
--max-code-length=120
|
||||||
|
|
||||||
|
# -f =>
|
||||||
|
--break-blocks
|
||||||
|
|
||||||
|
# -p => put a space around operators
|
||||||
|
--pad-oper
|
||||||
|
|
||||||
|
# -xg => Insert space padding after commas
|
||||||
|
--pad-comma
|
||||||
|
|
||||||
|
# -H => put a space after if/for/while
|
||||||
|
pad-header
|
||||||
|
|
||||||
|
# -xb => Break one line headers (e.g. if/for/while)
|
||||||
|
--break-one-line-headers
|
||||||
|
|
||||||
|
# -c => Converts tabs into spaces
|
||||||
|
#--convert-tabs
|
||||||
|
|
||||||
|
# if you like one-liners, keep them
|
||||||
|
#keep-one-line-statements
|
||||||
|
|
||||||
|
# -xV
|
||||||
|
--attach-closing-while
|
||||||
|
|
||||||
|
#unpad-paren
|
||||||
|
|
||||||
|
# -xp
|
||||||
|
remove-comment-prefix
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for dir in . ; do
|
||||||
|
find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \;
|
||||||
|
done
|
||||||
|
|
||||||
Reference in New Issue
Block a user