From d99e561d40f570c5a2647f89c43ef727c7336317 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:24:36 -0400 Subject: [PATCH 01/20] Update digital.cpp Add a conditional statement to check if we're on an Uno, this flips IOPORT_CFG_PMOS to _NMOS as needed. --- cores/arduino/digital.cpp | 42 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/cores/arduino/digital.cpp b/cores/arduino/digital.cpp index fceeb5d2..479a7937 100644 --- a/cores/arduino/digital.cpp +++ b/cores/arduino/digital.cpp @@ -1,29 +1,33 @@ #include "Arduino.h" void pinMode(pin_size_t pin, const PinMode mode) { - switch (mode) { - case INPUT: - case INPUT_PULLDOWN: // TODO: document the INPUT_PULLDOWN is unavailable - R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT); - break; - case INPUT_PULLUP: - R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE); - break; - case OUTPUT: - R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT); - break; - case OUTPUT_OPENDRAIN: - R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PMOS_ENABLE); - break; - } + switch (mode) { + case INPUT: + case INPUT_PULLDOWN: // TODO: document that INPUT_PULLDOWN is unavailable + R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT); + break; + case INPUT_PULLUP: + R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE); + break; + case OUTPUT: + R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT); + break; + case OUTPUT_OPENDRAIN: + #if defined(ARDUINO_UNO) + R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_NMOS_ENABLE); + #else + R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PMOS_ENABLE); + #endif + break; + } } void digitalWrite(pin_size_t pin, PinStatus val) { - R_IOPORT_PinWrite(NULL, g_pin_cfg[pin].pin, val == LOW ? BSP_IO_LEVEL_LOW : BSP_IO_LEVEL_HIGH); + R_IOPORT_PinWrite(NULL, g_pin_cfg[pin].pin, val == LOW ? BSP_IO_LEVEL_LOW : BSP_IO_LEVEL_HIGH); } PinStatus digitalRead(pin_size_t pin) { - bsp_io_level_t ret; - R_IOPORT_PinRead(NULL, g_pin_cfg[pin].pin, &ret); - return (ret == BSP_IO_LEVEL_LOW ? LOW : HIGH); + bsp_io_level_t ret; + R_IOPORT_PinRead(NULL, g_pin_cfg[pin].pin, &ret); + return (ret == BSP_IO_LEVEL_LOW ? LOW : HIGH); } From 6f331bdb90f93786def8729fafe85d22181896dc Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:40:07 -0400 Subject: [PATCH 02/20] Update RTC.cpp Add a condition to ensure we're within the 2000-2099 year range. --- libraries/RTC/src/RTC.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 843af650..546bbe83 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -295,6 +295,9 @@ bool RTCTime::setYear(int _y) { if (_y >= TM_YEAR_OFFSET) { _y -= TM_YEAR_OFFSET; } + if (_y < 0 || _y > 99) { // Valid range for RTC is 2000-2099 + return false; + } year = _y; stime.tm_year = _y; //stime.tm_yday = day + yday(year, Month2tm(month)); From 20319d86b7598065a15f5f3d21bb44c0115f3eec Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:44:39 -0400 Subject: [PATCH 03/20] Update RTC.cpp Adds a check to RTCTime::setUnixTime(time_t time) to make sure we're in a valid year range (2000-2099) --- libraries/RTC/src/RTC.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 546bbe83..c806f1bf 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -348,6 +348,8 @@ bool RTCTime::setSaveLight(SaveLight sl) { bool RTCTime::setUnixTime(time_t time) { struct tm *t; t = localtime(&time); + if (t->tm_year < 100 || t->tm_year > 199) { + return false; setTM(*t); return true; } From 405e04bcf4ba26f883b7f04610463e198f98af30 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:55:58 -0400 Subject: [PATCH 04/20] Update WiFiTypes.h Per issue #294, imported the header definitions from wl_definitions.h --- libraries/WiFiS3/src/WiFiTypes.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/WiFiS3/src/WiFiTypes.h b/libraries/WiFiS3/src/WiFiTypes.h index 70be019a..b1e39605 100644 --- a/libraries/WiFiS3/src/WiFiTypes.h +++ b/libraries/WiFiS3/src/WiFiTypes.h @@ -1,6 +1,17 @@ #ifndef WIFI_S3_TYPES_H #define WIFI_S3_TYPES_H +#define WL_SSID_MAX_LENGTH 32 +#define WL_WPA_KEY_MAX_LENGTH 63 +#define WL_WEP_KEY_MAX_LENGTH 13 +#define WL_MAC_ADDR_LENGTH 6 +#define WL_IPV4_LENGTH 4 +#define WL_NETWORKS_LIST_MAXNUM 10 +#define MAX_SOCK_NUM 4 +#define SOCK_NOT_AVAIL 255 +#define NA_STATE -1 +#define WL_MAX_ATTEMPT_CONNECTION 10 + typedef enum { WL_NO_SHIELD = 255, WL_NO_MODULE = WL_NO_SHIELD, @@ -31,4 +42,4 @@ enum wl_enc_type { ENC_TYPE_UNKNOWN = 255 }; -#endif \ No newline at end of file +#endif From 4d6cd7b904c82d407269a918c1bb5a39fab4426e Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:12:00 -0400 Subject: [PATCH 05/20] Update RTC.cpp Fix forgotten closing brace --- libraries/RTC/src/RTC.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index c806f1bf..8ef72341 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -350,6 +350,7 @@ bool RTCTime::setUnixTime(time_t time) { t = localtime(&time); if (t->tm_year < 100 || t->tm_year > 199) { return false; + } setTM(*t); return true; } From a7cb79caa7af614cbedabb7754036e6a47ca39b6 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:17:33 -0400 Subject: [PATCH 06/20] Update RTC.cpp Remove unnecessary `RTClock::` in an effort to get rid of the *qualified-id in declaration before* compiler warnings. --- libraries/RTC/src/RTC.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 8ef72341..40e1860c 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -605,12 +605,12 @@ bool setRtcAlarm(rtc_alarm_time_t alarm_time) { return false; } -RTClock::RTClock() : is_initialized{false} { +RTClock() : is_initialized{false} { } -RTClock::~RTClock() { } +~RTClock() { } -bool RTClock::begin() { +bool begin() { if(openRtc()) { is_initialized = true; } @@ -620,7 +620,7 @@ bool RTClock::begin() { return is_initialized; } -bool RTClock::getTime(RTCTime &t) { +bool getTime(RTCTime &t) { struct tm present; if(is_initialized) { if( getRtcTime(present) ) { @@ -631,7 +631,7 @@ bool RTClock::getTime(RTCTime &t) { return false; } -bool RTClock::setPeriodicCallback(rtc_cbk_t fnc, Period p) { +bool setPeriodicCallback(rtc_cbk_t fnc, Period p) { RTCIrqCfg_t rtc_irq_cfg; @@ -649,7 +649,7 @@ bool RTClock::setPeriodicCallback(rtc_cbk_t fnc, Period p) { return false; } -bool RTClock::setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m) { +bool setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m) { RTCIrqCfg_t rtc_irq_cfg; rtc_irq_cfg.req = RTC_ALARM; @@ -693,15 +693,15 @@ bool RTClock::setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m) { return false; } -bool RTClock::setAlarm(RTCTime &t, AlarmMatch &m) { +bool setAlarm(RTCTime &t, AlarmMatch &m) { return this->setAlarmCallback(nullptr, t, m); } -bool RTClock::isRunning() { +bool isRunning() { return isRtcRunning(); } -bool RTClock::setTime(RTCTime &t) { +bool setTime(RTCTime &t) { if(is_initialized) { if(setRtcTime((rtc_time_t)t.getTmTime())) { return true; @@ -710,7 +710,7 @@ bool RTClock::setTime(RTCTime &t) { return false; } -bool RTClock::setTimeIfNotRunning(RTCTime &t) { +bool setTimeIfNotRunning(RTCTime &t) { if(!isRunning()) { return setTime(t); } From 6d5f3c8c33af11cdc6d2e65d295eb4dfb00b2976 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:27:35 -0400 Subject: [PATCH 07/20] Update RTC.h Revising the class definition for RTClock to both inline some items and trace down compiler warnings. --- libraries/RTC/src/RTC.h | 54 ++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index c0b3f431..6fd1dde4 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -168,27 +168,59 @@ class AlarmMatch { }; class RTClock { - private: +private: bool is_initialized; - public: - RTClock(); - ~RTClock(); - - bool begin(); - - bool getTime(RTCTime &t); +public: + inline RTClock() : is_initialized(false) {} + inline ~RTClock() {} + + inline bool begin() { + if(openRtc()) { + is_initialized = true; + } else { + is_initialized = false; + } + return is_initialized; + } + + inline bool getTime(RTCTime &t) { + struct tm present; + if(is_initialized) { + if( getRtcTime(present) ) { + t.setTM(present); + return true; + } + } + return false; + } bool setPeriodicCallback(rtc_cbk_t fnc, Period p); bool setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m); - bool setAlarm(RTCTime &t, AlarmMatch &m); + + inline bool setAlarm(RTCTime &t, AlarmMatch &m) { + return setAlarmCallback(nullptr, t, m); + } + + inline bool isRunning() { + return isRtcRunning(); + } - bool isRunning(); bool setTime(RTCTime &t); - bool setTimeIfNotRunning(RTCTime &t); + inline bool setTimeIfNotRunning(RTCTime &t) { + if(!isRunning()) { + return setTime(t); + } + return false; + } }; + +#if RTC_HOWMANY > 0 +extern RTClock RTC; +#endif + extern RTClock RTC; #endif From e134df5e1cd75b5a970f1bfd1456e4b2466bd3e3 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:03:21 -0400 Subject: [PATCH 08/20] Update RTC.h Roll back due to incompatibility. --- libraries/RTC/src/RTC.h | 54 +++++++++-------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index 6fd1dde4..c0b3f431 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -168,59 +168,27 @@ class AlarmMatch { }; class RTClock { -private: + private: bool is_initialized; -public: - inline RTClock() : is_initialized(false) {} - inline ~RTClock() {} - - inline bool begin() { - if(openRtc()) { - is_initialized = true; - } else { - is_initialized = false; - } - return is_initialized; - } - - inline bool getTime(RTCTime &t) { - struct tm present; - if(is_initialized) { - if( getRtcTime(present) ) { - t.setTM(present); - return true; - } - } - return false; - } + public: + RTClock(); + ~RTClock(); + + bool begin(); + + bool getTime(RTCTime &t); bool setPeriodicCallback(rtc_cbk_t fnc, Period p); bool setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m); - - inline bool setAlarm(RTCTime &t, AlarmMatch &m) { - return setAlarmCallback(nullptr, t, m); - } - - inline bool isRunning() { - return isRtcRunning(); - } + bool setAlarm(RTCTime &t, AlarmMatch &m); + bool isRunning(); bool setTime(RTCTime &t); + bool setTimeIfNotRunning(RTCTime &t); - inline bool setTimeIfNotRunning(RTCTime &t) { - if(!isRunning()) { - return setTime(t); - } - return false; - } }; - -#if RTC_HOWMANY > 0 -extern RTClock RTC; -#endif - extern RTClock RTC; #endif From 36e46b0f2c0daf5019cc7eeea67a37bb7302ad55 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:04:22 -0400 Subject: [PATCH 09/20] Update RTC.cpp Rollback - keeping domain qualifiers for now. --- libraries/RTC/src/RTC.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 40e1860c..9d947e03 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -605,12 +605,12 @@ bool setRtcAlarm(rtc_alarm_time_t alarm_time) { return false; } -RTClock() : is_initialized{false} { +RTClock::RTClock() : is_initialized{false} { } -~RTClock() { } +RTClock::~RTClock() { } -bool begin() { +bool RTClock::begin() { if(openRtc()) { is_initialized = true; } @@ -620,7 +620,7 @@ bool begin() { return is_initialized; } -bool getTime(RTCTime &t) { +bool RTClock::getTime(RTCTime &t) { struct tm present; if(is_initialized) { if( getRtcTime(present) ) { @@ -631,7 +631,7 @@ bool getTime(RTCTime &t) { return false; } -bool setPeriodicCallback(rtc_cbk_t fnc, Period p) { +bool RTClock::setPeriodicCallback(rtc_cbk_t fnc, Period p) { RTCIrqCfg_t rtc_irq_cfg; @@ -649,7 +649,7 @@ bool setPeriodicCallback(rtc_cbk_t fnc, Period p) { return false; } -bool setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m) { +bool RTClock::setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m) { RTCIrqCfg_t rtc_irq_cfg; rtc_irq_cfg.req = RTC_ALARM; @@ -693,15 +693,15 @@ bool setAlarmCallback(rtc_cbk_t fnc, RTCTime &t, AlarmMatch &m) { return false; } -bool setAlarm(RTCTime &t, AlarmMatch &m) { +bool RTClock::setAlarm(RTCTime &t, AlarmMatch &m) { return this->setAlarmCallback(nullptr, t, m); } -bool isRunning() { +bool RTClock::isRunning() { return isRtcRunning(); } -bool setTime(RTCTime &t) { +bool RTClock::setTime(RTCTime &t) { if(is_initialized) { if(setRtcTime((rtc_time_t)t.getTmTime())) { return true; @@ -710,7 +710,7 @@ bool setTime(RTCTime &t) { return false; } -bool setTimeIfNotRunning(RTCTime &t) { +bool RTClock::setTimeIfNotRunning(RTCTime &t) { if(!isRunning()) { return setTime(t); } @@ -721,4 +721,3 @@ bool setTimeIfNotRunning(RTCTime &t) { RTClock RTC; #endif - From a38a62983a0b04ab2191728146de684fb5762b15 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:22:30 -0400 Subject: [PATCH 10/20] Fix status = !!!status to status = !status --- cores/arduino/Tone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/Tone.cpp b/cores/arduino/Tone.cpp index b866046b..291b29ed 100644 --- a/cores/arduino/Tone.cpp +++ b/cores/arduino/Tone.cpp @@ -37,7 +37,7 @@ class Tone { void toggle() { digitalWrite(pin, status); - status = !!!status; + status = !status; if (millis() > limit) { stop(); } From eebf436a572bda38d91fa90d7b7efeab50c991ae Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:25:42 -0400 Subject: [PATCH 11/20] Clean up redundant paranthesis. --- cores/arduino/Tone.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/Tone.cpp b/cores/arduino/Tone.cpp index 291b29ed..4171ed21 100644 --- a/cores/arduino/Tone.cpp +++ b/cores/arduino/Tone.cpp @@ -27,7 +27,7 @@ class Tone { } void start(void) { - if ((frequency != 0) && (channel != -1)) { + if (frequency != 0 && channel != -1) { tone_timer.start(); } if (duration != 0) { @@ -44,7 +44,7 @@ class Tone { } void stop(void) { - if ((frequency != 0) && (channel != -1)) { + if (frequency != 0 && channel != -1) { tone_timer.stop(); } digitalWrite(pin, LOW); From 0d542aeeda24048cab5ebc80b408abddc444cce4 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:26:28 -0400 Subject: [PATCH 12/20] Update NULL to nullptr --- cores/arduino/Tone.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/Tone.cpp b/cores/arduino/Tone.cpp index 4171ed21..e3c093aa 100644 --- a/cores/arduino/Tone.cpp +++ b/cores/arduino/Tone.cpp @@ -70,7 +70,7 @@ class Tone { FspTimer Tone::tone_timer; int Tone::channel = -1; -static Tone* active_tone = NULL; +static Tone* active_tone = nullptr; void tone_timer_callback(timer_callback_args_t __attribute__((unused)) *args) { active_tone->toggle(); @@ -93,6 +93,6 @@ void noTone(pin_size_t __attribute__((unused)) pin) { if (active_tone) { active_tone->stop(); delete active_tone; - active_tone = NULL; + active_tone = nullptr; } }; From 77ee8c56cc348c48a3579ff9c62759ffb7db8698 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:28:01 -0400 Subject: [PATCH 13/20] Add a default value of 0 to the tone() function. --- cores/arduino/Tone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/Tone.cpp b/cores/arduino/Tone.cpp index e3c093aa..ed9675c3 100644 --- a/cores/arduino/Tone.cpp +++ b/cores/arduino/Tone.cpp @@ -76,7 +76,7 @@ void tone_timer_callback(timer_callback_args_t __attribute__((unused)) *args) { active_tone->toggle(); } -void tone(pin_size_t pin, unsigned int frequency, unsigned long duration) { +void tone(pin_size_t pin, unsigned int frequency, unsigned long duration = 0) { if (active_tone) { if (active_tone->pin == pin && active_tone->frequency == frequency && active_tone->duration == 0) { // infinite duration notes do not need to be restarted From b9ab2f11a018de534473f66f121abca33e1d3ab1 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:30:07 -0400 Subject: [PATCH 14/20] Add a nullcheck to the tone_timer_callback function --- cores/arduino/Tone.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cores/arduino/Tone.cpp b/cores/arduino/Tone.cpp index ed9675c3..14945071 100644 --- a/cores/arduino/Tone.cpp +++ b/cores/arduino/Tone.cpp @@ -73,7 +73,9 @@ int Tone::channel = -1; static Tone* active_tone = nullptr; void tone_timer_callback(timer_callback_args_t __attribute__((unused)) *args) { - active_tone->toggle(); + if (active_tone) { + active_tone->toggle(); + } } void tone(pin_size_t pin, unsigned int frequency, unsigned long duration = 0) { From 4472cb7db234e6e92204f280a6f4d494e349450f Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:30:45 -0400 Subject: [PATCH 15/20] Clean up stylistic, unncecessary semicolons. --- cores/arduino/Tone.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/arduino/Tone.cpp b/cores/arduino/Tone.cpp index 14945071..9e70e136 100644 --- a/cores/arduino/Tone.cpp +++ b/cores/arduino/Tone.cpp @@ -66,7 +66,7 @@ class Tone { } } } -}; +} FspTimer Tone::tone_timer; int Tone::channel = -1; @@ -89,7 +89,7 @@ void tone(pin_size_t pin, unsigned int frequency, unsigned long duration = 0) { Tone* t = new Tone(pin, frequency, duration); active_tone = t; t->start(); -}; +} void noTone(pin_size_t __attribute__((unused)) pin) { if (active_tone) { @@ -97,4 +97,4 @@ void noTone(pin_size_t __attribute__((unused)) pin) { delete active_tone; active_tone = nullptr; } -}; +} From 7900baf96947b8a49849221f11e3b4d2e808943b Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:35:51 -0400 Subject: [PATCH 16/20] Update one instance of NULL to nullptr for consistency. --- cores/arduino/Interrupts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/Interrupts.cpp b/cores/arduino/Interrupts.cpp index a01b79fa..8b220a09 100644 --- a/cores/arduino/Interrupts.cpp +++ b/cores/arduino/Interrupts.cpp @@ -190,7 +190,7 @@ void attachInterruptParam(pin_size_t pinNumber, voidFuncPtrParam func, PinStatus } void attachInterrupt(pin_size_t pinNumber, voidFuncPtr func, PinStatus mode) { - attachInterruptParam(pinNumber, (voidFuncPtrParam)func, mode, NULL); + attachInterruptParam(pinNumber, (voidFuncPtrParam)func, mode, nullptr); } int attachIrq2Link(uint32_t pinNumber, PinStatus mode) { From ee2ead82700bcf12b63f0e1d47529a1bc899a81e Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:38:16 -0400 Subject: [PATCH 17/20] Set constant the IRQChannel for the pin as it should never change. --- cores/arduino/Interrupts.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/arduino/Interrupts.cpp b/cores/arduino/Interrupts.cpp index 8b220a09..726701ab 100644 --- a/cores/arduino/Interrupts.cpp +++ b/cores/arduino/Interrupts.cpp @@ -119,7 +119,7 @@ void detachInterrupt(pin_size_t pinNumber) { /* -------------------------------------------------------------------------- */ CIrq *irq_context = nullptr; - int ch = pin2IrqChannel(pinNumber); + const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { irq_context = IrqChannel.get(ch,false); @@ -138,7 +138,7 @@ void attachInterruptParam(pin_size_t pinNumber, voidFuncPtrParam func, PinStatus /* -------------------------------------------------------------------------- */ CIrq *irq_context = nullptr; - int ch = pin2IrqChannel(pinNumber); + const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { irq_context = IrqChannel.get(ch,true); @@ -195,7 +195,7 @@ void attachInterrupt(pin_size_t pinNumber, voidFuncPtr func, PinStatus mode) { int attachIrq2Link(uint32_t pinNumber, PinStatus mode) { CIrq *irq_context = nullptr; - int ch = pin2IrqChannel(pinNumber); + const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { irq_context = IrqChannel.get(ch,true); @@ -249,7 +249,7 @@ int detachIrq2Link(pin_size_t pinNumber) { /* -------------------------------------------------------------------------- */ CIrq *irq_context = nullptr; - int ch = pin2IrqChannel(pinNumber); + const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { irq_context = IrqChannel.get(ch,false); From e15c5625bf09f583c6289eee9f9875aa6f97f21b Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:40:19 -0400 Subject: [PATCH 18/20] Employ auto for variables where the type is obvious from the right-hand side. --- cores/arduino/Interrupts.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cores/arduino/Interrupts.cpp b/cores/arduino/Interrupts.cpp index 726701ab..f36ec5ec 100644 --- a/cores/arduino/Interrupts.cpp +++ b/cores/arduino/Interrupts.cpp @@ -95,7 +95,7 @@ static void IrqCallback(external_irq_callback_args_t * p_args) { void * param = (void *)p_args->p_context; uint32_t ch = p_args->channel; - CIrq *irq_context = nullptr; + auto *irq_context = nullptr; if(ch < MAX_IRQ_CHANNEL) { irq_context = IrqChannel.get(ch,false); @@ -118,7 +118,7 @@ static void IrqCallback(external_irq_callback_args_t * p_args) { void detachInterrupt(pin_size_t pinNumber) { /* -------------------------------------------------------------------------- */ - CIrq *irq_context = nullptr; + auto *irq_context = nullptr; const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { @@ -137,7 +137,7 @@ void detachInterrupt(pin_size_t pinNumber) { void attachInterruptParam(pin_size_t pinNumber, voidFuncPtrParam func, PinStatus mode, void* param) { /* -------------------------------------------------------------------------- */ - CIrq *irq_context = nullptr; + auto *irq_context = nullptr; const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { @@ -194,7 +194,7 @@ void attachInterrupt(pin_size_t pinNumber, voidFuncPtr func, PinStatus mode) { } int attachIrq2Link(uint32_t pinNumber, PinStatus mode) { - CIrq *irq_context = nullptr; + auto *irq_context = nullptr; const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { @@ -248,7 +248,7 @@ int attachIrq2Link(uint32_t pinNumber, PinStatus mode) { int detachIrq2Link(pin_size_t pinNumber) { /* -------------------------------------------------------------------------- */ - CIrq *irq_context = nullptr; + auto *irq_context = nullptr; const int ch = pin2IrqChannel(pinNumber); if(ch >= 0 && ch < MAX_IRQ_CHANNEL) { From 1db420d24847969e5a41bc67c147f038a9a0b7a8 Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:44:15 -0400 Subject: [PATCH 19/20] Update the IrqPool to use a range based for-loop for optimization and safety. --- cores/arduino/Interrupts.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cores/arduino/Interrupts.cpp b/cores/arduino/Interrupts.cpp index f36ec5ec..cee5fdf3 100644 --- a/cores/arduino/Interrupts.cpp +++ b/cores/arduino/Interrupts.cpp @@ -43,13 +43,11 @@ class IrqPool { public: IrqPool() {} ~IrqPool() { - for(int i = 0; i < MAX_IRQ_CHANNEL; i++) { - if(irqs[i] != nullptr){ - delete irqs[i]; - irqs[i] = nullptr; - } + for (auto& irq : irqs) { + delete irq; + irq = nullptr; } - } + } CIrq *get(int index, bool make) { if(index < MAX_IRQ_CHANNEL) { if(irqs[index] == nullptr && make) { From b2e8e7e8821ad806fd46a5cb9333865e22b14f0e Mon Sep 17 00:00:00 2001 From: Benjamin Cance <49796265+rowingdude@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:48:23 -0400 Subject: [PATCH 20/20] Update MAX_IRQ_CHANNEL to a constexpr --- cores/arduino/Interrupts.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cores/arduino/Interrupts.cpp b/cores/arduino/Interrupts.cpp index cee5fdf3..8b462984 100644 --- a/cores/arduino/Interrupts.cpp +++ b/cores/arduino/Interrupts.cpp @@ -24,8 +24,7 @@ #if EXT_INTERRUPTS_HOWMANY > 0 extern const PinMuxCfg_t g_pin_cfg[]; - -#define MAX_IRQ_CHANNEL (15) +constexpr int MAX_IRQ_CHANNEL = 15; using IrqFuncVoid_f = void (*)(); using IrqFuncParam_f = void (*)(void *);