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

Commit 60aa83a

Browse files
authored
v.2.0 to convert to h-only library, etc
### Releases v1.2.0 1. Add support to new `ESP32-S3` (ESP32S3_DEV, ESP32_S3_BOX, UM TINYS3, UM PROS3, UM FEATHERS3, etc.) 2. Add support to new `ESP32-S2` (ESP32S2_DEV, etc.) 3. Add support to new `ESP32-C3` (ESP32C3_DEV, etc.) 4. Convert to h-only library. 5. Optimize library code by using `reference-passing` instead of `value-passing` 6. Improve accuracy by using `float`, instead of `uint32_t` for `position` in degrees 7. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
1 parent 24a505b commit 60aa83a

File tree

9 files changed

+87
-64
lines changed

9 files changed

+87
-64
lines changed

examples/ESP32_ISR_MultiServos/ESP32_ISR_MultiServos.ino

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
2727
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2828
or the entire sequence of your code which accesses the data.
29-
30-
Version: 1.1.0
31-
32-
Version Modified By Date Comments
33-
------- ----------- ---------- -----------
34-
1.0.0 K Hoang 12/12/2019 Initial coding
35-
1.0.1 K Hoang 13/12/2019 Add more features getPosition and getPulseWidth. Optimize.
36-
1.0.2 K Hoang 20/12/2019 Add more Blynk examples.Change example names to avoid duplication.
37-
1.1.0 K Hoang 03/01/2021 Fix bug. Add TOC and Version String.
3829
*****************************************************************************************************************************/
3930

4031
/****************************************************************************************************************************
@@ -88,6 +79,7 @@
8879
// Select different ESP32 timer number (0-3) to avoid conflict
8980
#define USE_ESP32_TIMER_NO 3
9081

82+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
9183
#include "ESP32_ISR_Servo.h"
9284

9385
//See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h
@@ -157,8 +149,8 @@ void setup()
157149
//Select ESP32 timer USE_ESP32_TIMER_NO
158150
ESP32_ISR_Servos.useTimer(USE_ESP32_TIMER_NO);
159151

160-
servoIndex1 = ESP32_ISR_Servos.setupServo(PIN_D25, MIN_MICROS, MAX_MICROS);
161-
servoIndex2 = ESP32_ISR_Servos.setupServo(PIN_D26, MIN_MICROS, MAX_MICROS);
152+
servoIndex1 = ESP32_ISR_Servos.setupServo(PIN_D3, MIN_MICROS, MAX_MICROS);
153+
servoIndex2 = ESP32_ISR_Servos.setupServo(PIN_D4, MIN_MICROS, MAX_MICROS);
162154

163155
if (servoIndex1 != -1)
164156
Serial.println(F("Setup Servo1 OK"));

examples/ESP32_MultipleRandomServos/ESP32_MultipleRandomServos.ino

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
2727
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2828
or the entire sequence of your code which accesses the data.
29-
30-
Version: 1.1.0
31-
32-
Version Modified By Date Comments
33-
------- ----------- ---------- -----------
34-
1.0.0 K Hoang 12/12/2019 Initial coding
35-
1.0.1 K Hoang 13/12/2019 Add more features getPosition and getPulseWidth. Optimize.
36-
1.0.2 K Hoang 20/12/2019 Add more Blynk examples.Change example names to avoid duplication.
37-
1.1.0 K Hoang 03/01/2021 Fix bug. Add TOC and Version String.
3829
*****************************************************************************************************************************/
3930
/****************************************************************************************************************************
4031
This example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs.
@@ -86,6 +77,7 @@
8677
// Select different ESP32 timer number (0-3) to avoid conflict
8778
#define USE_ESP32_TIMER_NO 3
8879

80+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
8981
#include "ESP32_ISR_Servo.h"
9082

9183
//See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h
@@ -149,7 +141,7 @@ typedef struct
149141

150142
ISR_servo_t ISR_servo[NUM_SERVOS] =
151143
{
152-
{ -1, PIN_D21 }, { -1, PIN_D22 }, { -1, PIN_D23 }, { -1, PIN_D24 }, { -1, PIN_D25 }, { -1, PIN_D26 }
144+
{ -1, PIN_D1 }, { -1, PIN_D2 }, { -1, PIN_D3 }, { -1, PIN_D4 }, { -1, PIN_D5 }, { -1, PIN_D6 }
153145
};
154146

155147
void setup()

examples/ESP32_MultipleServos/ESP32_MultipleServos.ino

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
2727
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2828
or the entire sequence of your code which accesses the data.
29-
30-
Version: 1.1.0
31-
32-
Version Modified By Date Comments
33-
------- ----------- ---------- -----------
34-
1.0.0 K Hoang 12/12/2019 Initial coding
35-
1.0.1 K Hoang 13/12/2019 Add more features getPosition and getPulseWidth. Optimize.
36-
1.0.2 K Hoang 20/12/2019 Add more Blynk examples.Change example names to avoid duplication.
37-
1.1.0 K Hoang 03/01/2021 Fix bug. Add TOC and Version String.
3829
*****************************************************************************************************************************/
3930

4031
/****************************************************************************************************************************
@@ -78,7 +69,7 @@
7869
Experimentally, 550 and 2350 are pretty close to 0 and 180.
7970
*****************************************************************************************************************************/
8071
#ifndef ESP32
81-
#error This code is designed to run on ESP32 platform, not Arduino nor ESP8266! Please check your Tools->Board setting.
72+
#error This code is designed to run on ESP32 platform, not Arduino nor ESP8266! Please check your Tools->Board setting.
8273
#endif
8374

8475
#define TIMER_INTERRUPT_DEBUG 1
@@ -87,6 +78,7 @@
8778
// Select different ESP32 timer number (0-3) to avoid conflict
8879
#define USE_ESP32_TIMER_NO 3
8980

81+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
9082
#include "ESP32_ISR_Servo.h"
9183

9284
//See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h
@@ -150,7 +142,7 @@ typedef struct
150142

151143
ISR_servo_t ISR_servo[NUM_SERVOS] =
152144
{
153-
{ -1, PIN_D21 }, { -1, PIN_D22 }, { -1, PIN_D23 }, { -1, PIN_D24 }, { -1, PIN_D25 }, { -1, PIN_D26 }
145+
{ -1, PIN_D1 }, { -1, PIN_D2 }, { -1, PIN_D3 }, { -1, PIN_D4 }, { -1, PIN_D5 }, { -1, PIN_D6 }
154146
};
155147

156148
void setup()

examples/ISR_MultiServos/ISR_MultiServos.ino

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
2727
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2828
or the entire sequence of your code which accesses the data.
29-
30-
Version: 1.1.0
31-
32-
Version Modified By Date Comments
33-
------- ----------- ---------- -----------
34-
1.0.0 K Hoang 12/12/2019 Initial coding
35-
1.0.1 K Hoang 13/12/2019 Add more features getPosition and getPulseWidth. Optimize.
36-
1.0.2 K Hoang 20/12/2019 Add more Blynk examples.Change example names to avoid duplication.
37-
1.1.0 K Hoang 03/01/2021 Fix bug. Add TOC and Version String.
3829
*****************************************************************************************************************************/
3930

4031
/****************************************************************************************************************************
@@ -88,6 +79,7 @@
8879
// Select different ESP32 timer number (0-3) to avoid conflict
8980
#define USE_ESP32_TIMER_NO 3
9081

82+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
9183
#include "ESP32_ISR_Servo.h"
9284

9385
//See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h
@@ -157,8 +149,8 @@ void setup()
157149
//Select ESP32 timer USE_ESP32_TIMER_NO
158150
ESP32_ISR_Servos.useTimer(USE_ESP32_TIMER_NO);
159151

160-
servoIndex1 = ESP32_ISR_Servos.setupServo(PIN_D25, MIN_MICROS, MAX_MICROS);
161-
servoIndex2 = ESP32_ISR_Servos.setupServo(PIN_D26, MIN_MICROS, MAX_MICROS);
152+
servoIndex1 = ESP32_ISR_Servos.setupServo(PIN_D5, MIN_MICROS, MAX_MICROS);
153+
servoIndex2 = ESP32_ISR_Servos.setupServo(PIN_D6, MIN_MICROS, MAX_MICROS);
162154

163155
if (servoIndex1 != -1)
164156
Serial.println(F("Setup Servo1 OK"));

examples/MultipleRandomServos/MultipleRandomServos.ino

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
2727
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2828
or the entire sequence of your code which accesses the data.
29-
30-
Version: 1.1.0
31-
32-
Version Modified By Date Comments
33-
------- ----------- ---------- -----------
34-
1.0.0 K Hoang 12/12/2019 Initial coding
35-
1.0.1 K Hoang 13/12/2019 Add more features getPosition and getPulseWidth. Optimize.
36-
1.0.2 K Hoang 20/12/2019 Add more Blynk examples.Change example names to avoid duplication.
37-
1.1.0 K Hoang 03/01/2021 Fix bug. Add TOC and Version String.
3829
*****************************************************************************************************************************/
3930

4031
/****************************************************************************************************************************
@@ -87,6 +78,7 @@
8778
// Select different ESP32 timer number (0-3) to avoid conflict
8879
#define USE_ESP32_TIMER_NO 3
8980

81+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
9082
#include "ESP32_ISR_Servo.h"
9183

9284
//See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h
@@ -150,7 +142,7 @@ typedef struct
150142

151143
ISR_servo_t ISR_servo[NUM_SERVOS] =
152144
{
153-
{ -1, PIN_D21 }, { -1, PIN_D22 }, { -1, PIN_D23 }, { -1, PIN_D24 }, { -1, PIN_D25 }, { -1, PIN_D26 }
145+
{ -1, PIN_D1 }, { -1, PIN_D2 }, { -1, PIN_D3 }, { -1, PIN_D4 }, { -1, PIN_D5 }, { -1, PIN_D6 }
154146
};
155147

156148
void setup()

examples/MultipleServos/MultipleServos.ino

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
2727
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2828
or the entire sequence of your code which accesses the data.
29-
30-
Version: 1.1.0
31-
32-
Version Modified By Date Comments
33-
------- ----------- ---------- -----------
34-
1.0.0 K Hoang 12/12/2019 Initial coding
35-
1.0.1 K Hoang 13/12/2019 Add more features getPosition and getPulseWidth. Optimize.
36-
1.0.2 K Hoang 20/12/2019 Add more Blynk examples.Change example names to avoid duplication.
37-
1.1.0 K Hoang 03/01/2021 Fix bug. Add TOC and Version String.
3829
*****************************************************************************************************************************/
3930

4031
/****************************************************************************************************************************
@@ -78,7 +69,7 @@
7869
Experimentally, 550 and 2350 are pretty close to 0 and 180.
7970
*****************************************************************************************************************************/
8071
#ifndef ESP32
81-
#error This code is designed to run on ESP32 platform, not Arduino nor ESP8266! Please check your Tools->Board setting.
72+
#error This code is designed to run on ESP32 platform, not Arduino nor ESP8266! Please check your Tools->Board setting.
8273
#endif
8374

8475
#define TIMER_INTERRUPT_DEBUG 1
@@ -87,6 +78,7 @@
8778
// Select different ESP32 timer number (0-3) to avoid conflict
8879
#define USE_ESP32_TIMER_NO 3
8980

81+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
9082
#include "ESP32_ISR_Servo.h"
9183

9284
//See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h
@@ -150,7 +142,7 @@ typedef struct
150142

151143
ISR_servo_t ISR_servo[NUM_SERVOS] =
152144
{
153-
{ -1, PIN_D21 }, { -1, PIN_D22 }, { -1, PIN_D23 }, { -1, PIN_D24 }, { -1, PIN_D25 }, { -1, PIN_D26 }
145+
{ -1, PIN_D1 }, { -1, PIN_D2 }, { -1, PIN_D3 }, { -1, PIN_D4 }, { -1, PIN_D5 }, { -1, PIN_D6 }
154146
};
155147

156148
void setup()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/****************************************************************************************************************************
2+
multiFileProject.cpp
3+
For ESP32 boards
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/ESP32_ISR_Servo
7+
Licensed under MIT license
8+
*****************************************************************************************************************************/
9+
10+
// To demo how to include files in multi-file Projects
11+
12+
#include "multiFileProject.h"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/****************************************************************************************************************************
2+
multiFileProject.h
3+
For ESP32 boards
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/ESP32_ISR_Servo
7+
Licensed under MIT license
8+
*****************************************************************************************************************************/
9+
10+
// To demo how to include files in multi-file Projects
11+
12+
#pragma once
13+
14+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
15+
#include "ESP32_ISR_Servo.hpp"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/****************************************************************************************************************************
2+
multiFileProject.ino
3+
For ESP32 boards
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/ESP32_ISR_Servo
7+
Licensed under MIT license
8+
*****************************************************************************************************************************/
9+
10+
// To demo how to include files in multi-file Projects
11+
12+
#ifndef ESP32
13+
#error This code is designed to run on ESP32 platform, not Arduino nor ESP32! Please check your Tools->Board setting.
14+
#endif
15+
16+
#define ESP32_ISR_SERVO_VERSION_MIN_TARGET "ESP32_ISR_Servo v1.2.0"
17+
#define ESP32_ISR_SERVO_VERSION_MIN 1002000
18+
19+
#include "multiFileProject.h"
20+
21+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
22+
#include "ESP32_ISR_Servo.h"
23+
24+
void setup()
25+
{
26+
Serial.begin(115200);
27+
while (!Serial);
28+
29+
Serial.println("\nStart multiFileProject");
30+
Serial.println(ESP32_ISR_SERVO_VERSION);
31+
32+
#if defined(ESP32_ISR_SERVO_VERSION_MIN)
33+
if (ESP32_ISR_SERVO_VERSION_INT < ESP32_ISR_SERVO_VERSION_MIN)
34+
{
35+
Serial.print("Warning. Must use this example on Version equal or later than : ");
36+
Serial.println(ESP32_ISR_SERVO_VERSION_MIN_TARGET);
37+
}
38+
#endif
39+
}
40+
41+
void loop()
42+
{
43+
// put your main code here, to run repeatedly:
44+
}

0 commit comments

Comments
 (0)