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

Commit eb0da82

Browse files
authored
v1.8.0 fixes doubling time bug
### Releases v1.8.0 1. Fix doubled time for `ESP32_S2`. Check [Error in the value defined by TIMER0_INTERVAL_MS #28](https://github.com/khoih-prog/ESP32_C3_TimerInterrupt/issues/28) 2. Modify examples to avoid using `LED_BUILTIN` / `GPIO2`, `GPIO1` as it can cause crash in some boards, such as `ESP32_C3` 3. Use `allman astyle` and add `utils`
1 parent 08fb361 commit eb0da82

19 files changed

+1050
-753
lines changed

CONTRIBUTING.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `ESP32` Core Version (e.g. ESP32 core v2.0.4)
18+
* `ESP32` Core Version (e.g. ESP32 core v2.0.5)
1919
* `ESP32-S2` Board type (e.g. ESP32S2_DEV Module, ESP32_S2_Saola, etc.)
2020
* Contextual information (e.g. what you were trying to achieve)
2121
* Simplest possible steps to reproduce
@@ -28,28 +28,51 @@ Please ensure to specify the following:
2828

2929
```
3030
Arduino IDE version: 1.8.19
31-
ESP32 core v2.0.4
32-
ESP32S2_DEV Module
31+
ESP32 core v2.0.5
32+
ESP32S3_DEV Module
3333
OS: Ubuntu 20.04 LTS
34-
Linux xy-Inspiron-3593 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
34+
Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3535
3636
Context:
37-
I encountered a crash while using TimerInterrupt.
38-
37+
I encountered a crash while using this library
3938
Steps to reproduce:
4039
1. ...
4140
2. ...
4241
3. ...
4342
4. ...
4443
```
4544

45+
### Additional context
46+
47+
Add any other context about the problem here.
48+
49+
---
50+
4651
### Sending Feature Requests
4752

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

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

57+
---
58+
5259
### Sending Pull Requests
5360

5461
Pull Requests with changes and fixes are also welcome!
5562

63+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
64+
65+
1. Change directory to the library GitHub
66+
67+
```
68+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/ESP32_S2_TimerInterrupt_GitHub/
69+
xy@xy-Inspiron-3593:~/Arduino/xy/ESP32_S2_TimerInterrupt_GitHub$
70+
```
71+
72+
2. Issue astyle command
73+
74+
```
75+
xy@xy-Inspiron-3593:~/Arduino/xy/ESP32_S2_TimerInterrupt_GitHub$ bash utils/restyle.sh
76+
```
77+
78+

changelog.md

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

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP32_S2_TimerInterrupt.svg?)](https://www.ardu-badge.com/ESP32_S2_TimerInterrupt)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ESP32_S2_TimerInterrupt.svg)](https://github.com/khoih-prog/ESP32_S2_TimerInterrupt/releases)
5-
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP32_S2_TimerInterrupt/blob/master/LICENSE)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP32_S2_TimerInterrupt/blob/main/LICENSE)
66
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
77
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP32_S2_TimerInterrupt.svg)](http://github.com/khoih-prog/ESP32_S2_TimerInterrupt/issues)
88

9+
10+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
11+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
12+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
13+
<a href="https://profile-counter.glitch.me/khoih-prog-ESP32_S2_TimerInterrupt/count.svg" title="ESP32_S2_TimerInterrupt Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-ESP32_S2_TimerInterrupt/count.svg" style="height: 30px;width: 200px;"></a>
14+
915
---
1016
---
1117

1218
## Table of Contents
1319

1420
* [Changelog](#changelog)
21+
* [Releases v1.8.0](#releases-v180)
1522
* [Releases v1.7.0](#releases-v170)
1623
* [Releases v1.6.0](#releases-v160)
1724
* [Releases v1.5.1](#releases-v151)
@@ -24,6 +31,12 @@
2431

2532
## Changelog
2633

34+
### Releases v1.8.0
35+
36+
1. Fix doubled time for `ESP32_S2`. Check [Error in the value defined by TIMER0_INTERVAL_MS #28](https://github.com/khoih-prog/ESP32_C3_TimerInterrupt/issues/28)
37+
2. Modify examples to avoid using `LED_BUILTIN` / `GPIO2`, `GPIO1` as it can cause crash in some boards, such as `ESP32_C3`
38+
3. Use `allman astyle` and add `utils`
39+
2740
### Releases v1.7.0
2841

2942
1. Add support to
@@ -56,5 +69,5 @@
5669
### Releases v1.3.0
5770

5871
1. Initial coding to support ESP32-S2
59-
2. Sync with [ESP32TimerInterrupt library v1.3.0](https://github.com/khoih-prog/ESP32TimerInterrupt)
72+
2. Sync with [ESP32_S2_TimerInterrupt library v1.3.0](https://github.com/khoih-prog/ESP32_S2_TimerInterrupt)
6073

examples/Argument_None/Argument_None.ino

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,34 @@
3838

3939
#include "ESP32_S2_TimerInterrupt.h"
4040

41-
#ifndef LED_BUILTIN
42-
#define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
43-
#endif
41+
// Don't use PIN_D3 in core v2.0.0 and v2.0.1. Check https://github.com/espressif/arduino-esp32/issues/5868
42+
// Don't use PIN_D2 with ESP32_C3 (crash)
43+
#define PIN_D19 19 // Pin D19 mapped to pin GPIO9 of ESP32
44+
#define PIN_D3 3 // Pin D3 mapped to pin GPIO3/RX0 of ESP32
4445

45-
#define PIN_D1 1 // Pin D1 mapped to pin GPIO1 of ESP32-S2
46+
bool IRAM_ATTR TimerHandler0(void * timerNo)
47+
{
48+
static bool toggle0 = false;
4649

50+
//timer interrupt toggles pin PIN_D19
51+
digitalWrite(PIN_D19, toggle0);
52+
toggle0 = !toggle0;
4753

48-
bool IRAM_ATTR TimerHandler0(void * timerNo)
49-
{
50-
static bool toggle0 = false;
51-
52-
//timer interrupt toggles pin LED_BUILTIN
53-
digitalWrite(LED_BUILTIN, toggle0);
54-
toggle0 = !toggle0;
55-
56-
return true;
54+
return true;
5755
}
5856

5957
bool IRAM_ATTR TimerHandler1(void * timerNo)
6058
{
61-
static bool toggle1 = false;
59+
static bool toggle1 = false;
6260

63-
//timer interrupt toggles outputPin
64-
digitalWrite(PIN_D1, toggle1);
65-
toggle1 = !toggle1;
61+
//timer interrupt toggles outputPin
62+
digitalWrite(PIN_D3, toggle1);
63+
toggle1 = !toggle1;
6664

67-
return true;
65+
return true;
6866
}
6967

70-
#define TIMER0_INTERVAL_MS 1000
68+
#define TIMER0_INTERVAL_MS 100
7169

7270
#define TIMER1_INTERVAL_MS 5000
7371

@@ -77,40 +75,46 @@ ESP32Timer ITimer1(1);
7775

7876
void setup()
7977
{
80-
pinMode(LED_BUILTIN, OUTPUT);
81-
pinMode(PIN_D1, OUTPUT);
82-
83-
Serial.begin(115200);
84-
while (!Serial);
85-
86-
delay(100);
87-
88-
Serial.print(F("\nStarting Argument_None on ")); Serial.println(ARDUINO_BOARD);
89-
Serial.println(ESP32_S2_TIMER_INTERRUPT_VERSION);
90-
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
91-
92-
// Using ESP32 => 80 / 160 / 240MHz CPU clock ,
93-
// For 64-bit timer counter
94-
// For 16-bit timer prescaler up to 1024
95-
96-
// Interval in microsecs
97-
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
98-
//if (ITimer0.attachInterrupt(1, TimerHandler0))
99-
{
100-
Serial.print(F("Starting ITimer0 OK, millis() = ")); Serial.println(millis());
101-
}
102-
else
103-
Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer"));
104-
105-
106-
// Interval in microsecs
107-
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
108-
//if (ITimer1.attachInterrupt(2, TimerHandler1))
109-
{
110-
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
111-
}
112-
else
113-
Serial.println(F("Can't set ITimer1. Select another Timer, freq. or timer"));
78+
pinMode(PIN_D19, OUTPUT);
79+
pinMode(PIN_D3, OUTPUT);
80+
81+
Serial.begin(115200);
82+
83+
while (!Serial && millis() < 5000);
84+
85+
delay(500);
86+
87+
Serial.print(F("\nStarting Argument_None on "));
88+
Serial.println(ARDUINO_BOARD);
89+
Serial.println(ESP32_S2_TIMER_INTERRUPT_VERSION);
90+
Serial.print(F("CPU Frequency = "));
91+
Serial.print(F_CPU / 1000000);
92+
Serial.println(F(" MHz"));
93+
94+
// Using ESP32 => 80 / 160 / 240MHz CPU clock ,
95+
// For 64-bit timer counter
96+
// For 16-bit timer prescaler up to 1024
97+
98+
// Interval in microsecs
99+
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
100+
//if (ITimer0.attachInterrupt(1, TimerHandler0))
101+
{
102+
Serial.print(F("Starting ITimer0 OK, millis() = "));
103+
Serial.println(millis());
104+
}
105+
else
106+
Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer"));
107+
108+
109+
// Interval in microsecs
110+
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
111+
//if (ITimer1.attachInterrupt(2, TimerHandler1))
112+
{
113+
Serial.print(F("Starting ITimer1 OK, millis() = "));
114+
Serial.println(millis());
115+
}
116+
else
117+
Serial.println(F("Can't set ITimer1. Select another Timer, freq. or timer"));
114118
}
115119

116120
void loop()

0 commit comments

Comments
 (0)