Skip to content

Commit f988eb3

Browse files
committed
To implement light sleep for ESP32 without changing setFlag
To put back missing code board->onAfterTransmit();
1 parent 67a4398 commit f988eb3

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/helpers/ESP32Board.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,31 @@ class ESP32Board : public mesh::MainBoard {
6565
return; // Not supported
6666
#endif
6767

68-
gpio_intr_disable((gpio_num_t) wakeupPin); // To disable ISR for LoRa
68+
// To configure GPIO wakeup
6969
esp_sleep_enable_gpio_wakeup();
7070
gpio_wakeup_enable((gpio_num_t) wakeupPin, GPIO_INTR_HIGH_LEVEL); // To wake up when receiving a LoRa packet
7171

72+
// To configure timer wakeup
7273
if (secs > 0) {
73-
esp_sleep_enable_timer_wakeup(secs * 1000000); // To wake up periodically to do scheduled jobs
74+
esp_sleep_enable_timer_wakeup(secs * 1000000ULL); // To wake up periodically to do scheduled jobs
7475
}
7576

76-
esp_light_sleep_start(); // CPU enters light sleep
77-
gpio_intr_enable((gpio_num_t) wakeupPin); // Wakeup. Let ISR to handle LoRa packet as normal
77+
// To disable CPU interrupt servicing
78+
noInterrupts();
79+
80+
// MCU to enter light sleep
81+
esp_light_sleep_start();
82+
Serial.println(esp_sleep_get_wakeup_cause());
83+
84+
// To avoid ISR flood during wakeup due to HIGH LEVEL interrupt
85+
#if defined(ESP32) && defined(RADIO_SX1276) && defined(P_LORA_DIO_0) // SX1276
86+
gpio_set_intr_type((gpio_num_t)P_LORA_DIO_0, GPIO_INTR_POSEDGE);
87+
#elif defined(ESP32) && defined(P_LORA_DIO_1) // SX1262
88+
gpio_set_intr_type((gpio_num_t)P_LORA_DIO_1, GPIO_INTR_POSEDGE);
89+
#endif
90+
91+
// To disable CPU interrupt servicing
92+
interrupts();
7893
}
7994

8095
void sleep(uint32_t secs) override {

src/helpers/radiolib/RadioLibWrappers.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ static
2222
void setFlag(void) {
2323
// we sent a packet, set the flag
2424
state |= STATE_INT_READY;
25-
26-
// To avoid ISR flood during wakeup due to HIGH LEVEL interrupt
27-
#if defined(ESP32) && defined(RADIO_SX1276) && defined(P_LORA_DIO_0) // SX1276
28-
gpio_set_intr_type((gpio_num_t)P_LORA_DIO_0, GPIO_INTR_POSEDGE);
29-
#elif defined(ESP32) && defined(P_LORA_DIO_1) // SX1262
30-
gpio_set_intr_type((gpio_num_t)P_LORA_DIO_1, GPIO_INTR_POSEDGE);
31-
#endif
3225
}
3326

3427
void RadioLibWrapper::begin() {
@@ -144,6 +137,7 @@ bool RadioLibWrapper::startSendRaw(const uint8_t* bytes, int len) {
144137
}
145138
MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startTransmit(%d)", err);
146139
idle(); // trigger another startRecv()
140+
_board->onAfterTransmit();
147141
return false;
148142
}
149143

0 commit comments

Comments
 (0)