From b90670827306b1ce24912be69ec39b776cad62cb Mon Sep 17 00:00:00 2001 From: cskzoli <73739705+cskzoli@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:12:25 +0200 Subject: [PATCH] Add compatibility to Arduino Core 3.0.x and ESP-IDF 5.xx --- src/dscClassic.cpp | 10 ++++++++++ src/dscClassicKeypad.cpp | 9 +++++++++ src/dscKeybusInterface.cpp | 9 +++++++++ src/dscKeybusReader.cpp | 9 +++++++++ src/dscKeypad.cpp | 7 +++++++ 5 files changed, 44 insertions(+) diff --git a/src/dscClassic.cpp b/src/dscClassic.cpp index f74b38d..ad44550 100644 --- a/src/dscClassic.cpp +++ b/src/dscClassic.cpp @@ -64,13 +64,21 @@ void dscClassicInterface::begin(Stream &_stream) { timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE); // esp32 timer1 calls dscDataInterrupt() from dscClockInterrupt() + #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR >= 5 + timer1 = timerBegin(1000000); + timerStop(timer1); + timerAttachInterrupt(timer1, &dscDataInterrupt); + timerAlarm(timer1, 250, true, 0); + #elif timer1 = timerBegin(1, 80, true); timerStop(timer1); timerAttachInterrupt(timer1, &dscDataInterrupt, true); timerAlarmWrite(timer1, 250, true); timerAlarmEnable(timer1); #endif + #endif // Generates an interrupt when the Keybus clock rises or falls - requires a hardware interrupt pin on Arduino/AVR attachInterrupt(digitalPinToInterrupt(dscClockPin), dscClockInterrupt, CHANGE); @@ -90,7 +98,9 @@ void dscClassicInterface::stop() { // Disables esp32 timer1 #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR < 5 timerAlarmDisable(timer1); + #endif timerEnd(timer1); #endif diff --git a/src/dscClassicKeypad.cpp b/src/dscClassicKeypad.cpp index c7d8293..2cd3252 100644 --- a/src/dscClassicKeypad.cpp +++ b/src/dscClassicKeypad.cpp @@ -61,13 +61,22 @@ void dscClassicKeypadInterface::begin(Stream &_stream) { timer1_write(5000); // esp32 timer1 calls dscClockInterrupt() + + #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR >= 5 + timer1 = timerBegin(1000000); + timerStop(timer1); + timerAttachInterrupt(timer1, &dscClockInterrupt); + timerAlarm(timer1, 1000, true, 0); + #elif timer1 = timerBegin(1, 80, true); timerStop(timer1); timerAttachInterrupt(timer1, &dscClockInterrupt, true); timerAlarmWrite(timer1, 1000, true); timerAlarmEnable(timer1); #endif + #endif intervalStart = millis(); diff --git a/src/dscKeybusInterface.cpp b/src/dscKeybusInterface.cpp index 45f5c28..5b158c7 100644 --- a/src/dscKeybusInterface.cpp +++ b/src/dscKeybusInterface.cpp @@ -59,12 +59,19 @@ void dscKeybusInterface::begin(Stream &_stream) { // esp32 timer1 calls dscDataInterrupt() from dscClockInterrupt() #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR >= 5 + timer1 = timerBegin(1000000); + timerStop(timer1); + timerAttachInterrupt(timer1, &dscDataInterrupt); + timerAlarm(timer1, 250, true, 0); + #elif timer1 = timerBegin(1, 80, true); timerStop(timer1); timerAttachInterrupt(timer1, &dscDataInterrupt, true); timerAlarmWrite(timer1, 250, true); timerAlarmEnable(timer1); #endif + #endif // Generates an interrupt when the Keybus clock rises or falls - requires a hardware interrupt pin on Arduino/AVR attachInterrupt(digitalPinToInterrupt(dscClockPin), dscClockInterrupt, CHANGE); @@ -84,7 +91,9 @@ void dscKeybusInterface::stop() { // Disables esp32 timer1 #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR < 5 timerAlarmDisable(timer1); + #endif timerEnd(timer1); #endif diff --git a/src/dscKeybusReader.cpp b/src/dscKeybusReader.cpp index 2578c27..0ea3215 100644 --- a/src/dscKeybusReader.cpp +++ b/src/dscKeybusReader.cpp @@ -59,12 +59,19 @@ void dscKeybusReaderInterface::begin(Stream &_stream) { // esp32 timer1 calls dscDataInterrupt() from dscClockInterrupt() #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR >= 5 + timer1 = timerBegin(1000000); + timerStop(timer1); + timerAttachInterrupt(timer1, &dscDataInterrupt); + timerAlarm(timer1, 250, true, 0); + #elif timer1 = timerBegin(1, 80, true); timerStop(timer1); timerAttachInterrupt(timer1, &dscDataInterrupt, true); timerAlarmWrite(timer1, 250, true); timerAlarmEnable(timer1); #endif + #endif // Generates an interrupt when the Keybus clock rises or falls - requires a hardware interrupt pin on Arduino/AVR attachInterrupt(digitalPinToInterrupt(dscClockPin), dscClockInterrupt, CHANGE); @@ -84,7 +91,9 @@ void dscKeybusReaderInterface::stop() { // Disables esp32 timer1 #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR < 5 timerAlarmDisable(timer1); + #endif timerEnd(timer1); #endif diff --git a/src/dscKeypad.cpp b/src/dscKeypad.cpp index 9de7b09..fbf0e9d 100644 --- a/src/dscKeypad.cpp +++ b/src/dscKeypad.cpp @@ -62,12 +62,19 @@ void dscKeypadInterface::begin(Stream &_stream) { // esp32 timer1 calls dscClockInterrupt() #elif defined(ESP32) + #if ESP_IDF_VERSION_MAJOR >= 5 + timer1 = timerBegin(1000000); + timerStop(timer1); + timerAttachInterrupt(timer1, &dscClockInterrupt); + timerAlarm(timer1, 500, true, 0); + #elif timer1 = timerBegin(1, 80, true); timerStop(timer1); timerAttachInterrupt(timer1, &dscClockInterrupt, true); timerAlarmWrite(timer1, 500, true); timerAlarmEnable(timer1); #endif + #endif intervalStart = millis();