Skip to content

Commit 5b30acd

Browse files
committed
Revert esp32 ISR-safe timer workaround, fixed in espressif/arduino-esp32#4684
1 parent 6407868 commit 5b30acd

File tree

3 files changed

+13
-43
lines changed

3 files changed

+13
-43
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Poking around with a logic analyzer and oscilloscope revealed that the errors ca
8989
* Includes [Arduino framework support](https://github.com/esp8266/Arduino) and WiFi for ~$3USD shipped.
9090
- esp32:
9191
* Development boards: NodeMCU ESP-32S, Doit ESP32 Devkit v1, Wemos Lolin D32, etc.
92-
* Includes [Arduino framework support](https://github.com/espressif/arduino-esp32), dual cores, WiFi, and Bluetooth for ~$5USD shipped.
92+
* Includes [Arduino framework support](https://github.com/espressif/arduino-esp32) (v1.0.5-rc6 or newer required), dual cores, WiFi, and Bluetooth for ~$5USD shipped.
9393
* Possible features (PRs welcome!):
9494
- [DSC IT-100](https://cms.dsc.com/download.php?t=1&id=16238) emulation
9595
- Unlock 6-digit installer codes
@@ -103,7 +103,7 @@ Poking around with a logic analyzer and oscilloscope revealed that the errors ca
103103
- New: `TimeSyncNTP` example sketch - uses NTP to automatically set the panel time
104104
- New: [ESPHome](https://esphome.io) integration example (located in the `extras` directory) - thanks to [Dilbert66](https://github.com/Dilbert66) for this contribution!
105105
- New: `KeybusReaderIP` example sketch enables Keybus data access over IP, thanks to [aboulfad](https://github.com/aboulfad) for this contribution!
106-
- New: esp32 microcontroller support
106+
- New: esp32 microcontroller support - requires [Arduino-esp32](https://github.com/espressif/arduino-esp32) v1.0.5-rc6 or newer
107107
- New: Features for sketches:
108108
* `ready` and `disabled` track partition status
109109
* `setTime()` sets the panel date and time

Diff for: src/dscKeybusInterface.cpp

+2-36
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,7 @@ volatile byte dscKeybusInterface::moduleSubCmd;
5959
volatile unsigned long dscKeybusInterface::clockHighTime;
6060
volatile unsigned long dscKeybusInterface::keybusTime;
6161

62-
// Workaround for ESP32 hardware timer interrupt functions called from within an ISR:
63-
// https://github.com/crankyoldgit/IRremoteESP8266/pull/1351
6462
#if defined(ESP32)
65-
typedef struct {
66-
union {
67-
struct {
68-
uint32_t reserved0: 10;
69-
uint32_t alarm_en: 1;
70-
uint32_t level_int_en: 1;
71-
uint32_t edge_int_en: 1;
72-
uint32_t divider: 16;
73-
uint32_t autoreload: 1;
74-
uint32_t increase: 1;
75-
uint32_t enable: 1;
76-
};
77-
uint32_t val;
78-
} config;
79-
uint32_t cnt_low;
80-
uint32_t cnt_high;
81-
uint32_t update;
82-
uint32_t alarm_low;
83-
uint32_t alarm_high;
84-
uint32_t load_low;
85-
uint32_t load_high;
86-
uint32_t reload;
87-
} hw_timer_reg_t;
88-
89-
typedef struct hw_timer_s {
90-
hw_timer_reg_t * dev;
91-
uint8_t num;
92-
uint8_t group;
93-
uint8_t timer;
94-
portMUX_TYPE lock;
95-
} hw_timer_t;
96-
9763
hw_timer_t *timer0 = NULL;
9864
portMUX_TYPE timer0Mux = portMUX_INITIALIZER_UNLOCKED;
9965
#endif
@@ -715,7 +681,7 @@ void IRAM_ATTR dscKeybusInterface::dscClockInterrupt() {
715681

716682
// esp32 timer0 calls dscDataInterrupt() in 250us
717683
#elif defined(ESP32)
718-
timer0->dev->config.enable = 1;
684+
timerStart(timer0);
719685
portENTER_CRITICAL(&timer0Mux);
720686
#endif
721687

@@ -812,7 +778,7 @@ void dscKeybusInterface::dscDataInterrupt() {
812778
void ICACHE_RAM_ATTR dscKeybusInterface::dscDataInterrupt() {
813779
#elif defined(ESP32)
814780
void IRAM_ATTR dscKeybusInterface::dscDataInterrupt() {
815-
timer0->dev->config.enable = 0;
781+
timerStop(timer0);
816782
portENTER_CRITICAL(&timer0Mux);
817783
#endif
818784

Diff for: src/dscKeybusInterface.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
const byte dscPartitions = 4; // Maximum number of partitions - requires 19 bytes of memory per partition
2727
const byte dscZones = 4; // Maximum number of zone groups, 8 zones per group - requires 6 bytes of memory per zone group
2828
const byte dscBufferSize = 10; // Number of commands to buffer if the sketch is busy - requires dscReadSize + 2 bytes of memory per command
29-
#elif defined(ESP8266) || defined(ESP32)
29+
const byte dscReadSize = 16; // Maximum bytes of a Keybus command
30+
#elif defined(ESP8266)
3031
const byte dscPartitions = 8;
3132
const byte dscZones = 8;
3233
const byte dscBufferSize = 50;
33-
#endif
34-
35-
// Maximum bytes of a Keybus command
3634
const byte dscReadSize = 16;
35+
#elif defined(ESP32)
36+
const byte dscPartitions = 8;
37+
const byte dscZones = 8;
38+
const DRAM_ATTR byte dscBufferSize = 50;
39+
const DRAM_ATTR byte dscReadSize = 16;
40+
#endif
3741

3842
// Exit delay target states
3943
#define DSC_EXIT_STAY 1
@@ -144,7 +148,7 @@ class dscKeybusInterface {
144148
// True if dscBufferSize needs to be increased
145149
static volatile bool bufferOverflow;
146150

147-
// Timer interrupt function to capture data - declared as public for use by AVR Timer2
151+
// Timer interrupt function to capture data - declared as public for use by AVR Timer1
148152
static void dscDataInterrupt();
149153

150154
// Deprecated

0 commit comments

Comments
 (0)