diff --git a/src/dscClassic.cpp b/src/dscClassic.cpp index c674ba9..25944fe 100644 --- a/src/dscClassic.cpp +++ b/src/dscClassic.cpp @@ -64,11 +64,15 @@ void dscClassicInterface::begin(Stream &_stream) { // esp32 timer1 calls dscDataInterrupt() from dscClockInterrupt() #elif defined(ESP32) - timer1 = timerBegin(1, 80, true); + //timer1 = timerBegin(1, 80, true); + //timerStop(timer1); + //timerAttachInterrupt(timer1, &dscDataInterrupt, true); + //timerAlarmWrite(timer1, 250, true); + //timerAlarmEnable(timer1); + timer1 = timerBegin(1000000); // 1 MHz = 1 µs per tick timerStop(timer1); - timerAttachInterrupt(timer1, &dscDataInterrupt, true); - timerAlarmWrite(timer1, 250, true); - timerAlarmEnable(timer1); + timerAttachInterrupt(timer1, &dscDataInterrupt); + timerAlarm(timer1, 250, true, 0); // 1000 ticks = 1 ms interval #endif // Generates an interrupt when the Keybus clock rises or falls - requires a hardware interrupt pin on Arduino/AVR @@ -89,8 +93,11 @@ void dscClassicInterface::stop() { // Disables esp32 timer1 #elif defined(ESP32) - timerAlarmDisable(timer1); - timerEnd(timer1); + //timerAlarmDisable(timer1); + //timerEnd(timer1); + timerDetachInterrupt(timer1); // Detach the interrupt handler + timerStop(timer1); // Stop counting + timerEnd(timer1); // Free the timer resource #endif // Disables the Keybus clock pin interrupt diff --git a/src/dscClassicKeypad.cpp b/src/dscClassicKeypad.cpp index bde8357..b5be5d2 100644 --- a/src/dscClassicKeypad.cpp +++ b/src/dscClassicKeypad.cpp @@ -62,11 +62,15 @@ void dscClassicKeypadInterface::begin(Stream &_stream) { // esp32 timer1 calls dscClockInterrupt() #elif defined(ESP32) - timer1 = timerBegin(1, 80, true); + //timer1 = timerBegin(1, 80, true); + //timerStop(timer1); + //timerAttachInterrupt(timer1, &dscClockInterrupt, true); + //timerAlarmWrite(timer1, 1000, true); + //timerAlarmEnable(timer1); + timer1 = timerBegin(1000000); // 1 MHz = 1 µs per tick timerStop(timer1); - timerAttachInterrupt(timer1, &dscClockInterrupt, true); - timerAlarmWrite(timer1, 1000, true); - timerAlarmEnable(timer1); + timerAttachInterrupt(timer1, &dscClockInterrupt); + timerAlarm(timer1, 1000, true, 0); // 1000 ticks = 1 ms interval #endif intervalStart = millis(); diff --git a/src/dscKeybusInterface.cpp b/src/dscKeybusInterface.cpp index e694851..4a4a0f5 100644 --- a/src/dscKeybusInterface.cpp +++ b/src/dscKeybusInterface.cpp @@ -62,11 +62,15 @@ void dscKeybusInterface::begin(Stream &_stream) { // esp32 timer1 calls dscDataInterrupt() from dscClockInterrupt() #elif defined(ESP32) - timer1 = timerBegin(1, 80, true); + //timer1 = timerBegin(1, 80, true); + //timerStop(timer1); + //timerAttachInterrupt(timer1, &dscDataInterrupt, true); + //timerAlarmWrite(timer1, 250, true); + //timerAlarmEnable(timer1); + timer1 = timerBegin(1000000); // 1 MHz = 1 µs per tick timerStop(timer1); - timerAttachInterrupt(timer1, &dscDataInterrupt, true); - timerAlarmWrite(timer1, 250, true); - timerAlarmEnable(timer1); + timerAttachInterrupt(timer1, &dscDataInterrupt); + timerAlarm(timer1, 250, true, 0); // 1000 ticks = 1 ms interval #endif // Generates an interrupt when the Keybus clock rises or falls - requires a hardware interrupt pin on Arduino/AVR @@ -87,8 +91,11 @@ void dscKeybusInterface::stop() { // Disables esp32 timer1 #elif defined(ESP32) - timerAlarmDisable(timer1); - timerEnd(timer1); + //timerAlarmDisable(timer1); + //timerEnd(timer1); + timerDetachInterrupt(timer1); // Detach the interrupt handler + timerStop(timer1); // Stop counting + timerEnd(timer1); // Free the timer resource #endif // Disables the Keybus clock pin interrupt diff --git a/src/dscKeypad.cpp b/src/dscKeypad.cpp index cd946a0..a63c5b1 100644 --- a/src/dscKeypad.cpp +++ b/src/dscKeypad.cpp @@ -62,11 +62,15 @@ void dscKeypadInterface::begin(Stream &_stream) { // esp32 timer1 calls dscClockInterrupt() #elif defined(ESP32) - timer1 = timerBegin(1, 80, true); + //timer1 = timerBegin(1, 80, true); + //timerStop(timer1); + //timerAttachInterrupt(timer1, &dscClockInterrupt, true); + //timerAlarmWrite(timer1, 500, true); + //timerAlarmEnable(timer1); + timer1 = timerBegin(1000000); // 1 MHz = 1 µs per tick timerStop(timer1); - timerAttachInterrupt(timer1, &dscClockInterrupt, true); - timerAlarmWrite(timer1, 500, true); - timerAlarmEnable(timer1); + timerAttachInterrupt(timer1, &dscClockInterrupt); + timerAlarm(timer1, 500, true, 0); // 1000 ticks = 1 ms interval #endif intervalStart = millis();