From 39e160439b9b4e7c5238202379bd042121784f65 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Sun, 27 Feb 2022 21:40:41 -0500 Subject: [PATCH] v1.1.0 to convert to `h-only` style, etc. ### Releases v1.1.0 1. Convert to `h-only` style 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project 3. Fix setPulseWidth() bug. Check [setPulseWidth - removed wrong map #2](https://github.com/khoih-prog/RP2040_ISR_Servo/pull/2) 4. Optimize code by using passing by `reference` instead of by `value` --- .../RP2040_MultipleRandomServos.ino | 9 +-- .../RP2040_MultipleServos.ino | 9 +-- .../multiFileProject/multiFileProject.cpp | 16 +++++ examples/multiFileProject/multiFileProject.h | 19 ++++++ .../multiFileProject/multiFileProject.ino | 61 +++++++++++++++++++ 5 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 examples/multiFileProject/multiFileProject.cpp create mode 100644 examples/multiFileProject/multiFileProject.h create mode 100644 examples/multiFileProject/multiFileProject.ino diff --git a/examples/RP2040_MultipleRandomServos/RP2040_MultipleRandomServos.ino b/examples/RP2040_MultipleRandomServos/RP2040_MultipleRandomServos.ino index baa9d64..3a18ce0 100644 --- a/examples/RP2040_MultipleRandomServos/RP2040_MultipleRandomServos.ino +++ b/examples/RP2040_MultipleRandomServos/RP2040_MultipleRandomServos.ino @@ -8,13 +8,6 @@ Built by Khoi Hoang https://github.com/khoih-prog/RP2040_ISR_Servo Licensed under MIT license - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy *****************************************************************************************************************************/ /**************************************************************************************************************************** @@ -66,9 +59,9 @@ #error This code is intended to run on the mbed / non-mbed RP2040 platform! Please check your Tools->Board setting. #endif -#define TIMER_INTERRUPT_DEBUG 4 #define ISR_SERVO_DEBUG 4 +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error #include "RP2040_ISR_Servo.h" // Published values for SG90 servos; adjust if needed diff --git a/examples/RP2040_MultipleServos/RP2040_MultipleServos.ino b/examples/RP2040_MultipleServos/RP2040_MultipleServos.ino index dd01218..afe1437 100644 --- a/examples/RP2040_MultipleServos/RP2040_MultipleServos.ino +++ b/examples/RP2040_MultipleServos/RP2040_MultipleServos.ino @@ -8,13 +8,6 @@ Built by Khoi Hoang https://github.com/khoih-prog/RP2040_ISR_Servo Licensed under MIT license - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy *****************************************************************************************************************************/ /**************************************************************************************************************************** @@ -66,9 +59,9 @@ #error This code is intended to run on the mbed / non-mbed RP2040 platform! Please check your Tools->Board setting. #endif -#define TIMER_INTERRUPT_DEBUG 4 #define ISR_SERVO_DEBUG 4 +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error #include "RP2040_ISR_Servo.h" // Published values for SG90 servos; adjust if needed diff --git a/examples/multiFileProject/multiFileProject.cpp b/examples/multiFileProject/multiFileProject.cpp new file mode 100644 index 0000000..b0c8d35 --- /dev/null +++ b/examples/multiFileProject/multiFileProject.cpp @@ -0,0 +1,16 @@ +/**************************************************************************************************************************** + multiFileProject.cpp + RP2040_MultipleServos.ino + For : + - MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040. + - RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040 using arduino_pico core + + Written by Khoi Hoang + + Built by Khoi Hoang https://github.com/khoih-prog/RP2040_ISR_Servo + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#include "multiFileProject.h" diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h new file mode 100644 index 0000000..5c1fa8b --- /dev/null +++ b/examples/multiFileProject/multiFileProject.h @@ -0,0 +1,19 @@ +/**************************************************************************************************************************** + multiFileProject.h + RP2040_MultipleServos.ino + For : + - MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040. + - RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040 using arduino_pico core + + Written by Khoi Hoang + + Built by Khoi Hoang https://github.com/khoih-prog/RP2040_ISR_Servo + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#pragma once + +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "RP2040_ISR_Servo.hpp" diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino new file mode 100644 index 0000000..193a1d1 --- /dev/null +++ b/examples/multiFileProject/multiFileProject.ino @@ -0,0 +1,61 @@ +/**************************************************************************************************************************** + multiFileProject.ino + RP2040_MultipleServos.ino + For : + - MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040. + - RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040 using arduino_pico core + + Written by Khoi Hoang + + Built by Khoi Hoang https://github.com/khoih-prog/RP2040_ISR_Servo + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#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(RP2040_ISR_SERVO_USING_MBED) + #define RP2040_ISR_SERVO_USING_MBED false + #endif + +#elif ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \ + defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED) + + #if !defined(RP2040_ISR_SERVO_USING_MBED) + #define RP2040_ISR_SERVO_USING_MBED true + #endif + +#else + #error This code is intended to run on the mbed / non-mbed RP2040 platform! Please check your Tools->Board setting. +#endif + +#define RP2040_ISR_SERVO_VERSION_MIN_TARGET "RP2040_ISR_Servo v1.1.0" +#define RP2040_ISR_SERVO_VERSION_MIN 1001000 + +#include "multiFileProject.h" + +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error +#include "RP2040_ISR_Servo.h" + +void setup() +{ + Serial.begin(115200); + while (!Serial); + + Serial.println("\nStart multiFileProject"); + Serial.println(RP2040_ISR_SERVO_VERSION); + +#if defined(RP2040_ISR_SERVO_VERSION_MIN) + if (RP2040_ISR_SERVO_VERSION_INT < RP2040_ISR_SERVO_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(RP2040_ISR_SERVO_VERSION_MIN_TARGET); + } +#endif +} + +void loop() +{ + // put your main code here, to run repeatedly: +}