StationG2Board.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <Arduino.h>
  3. // LoRa radio module pins for Station G2
  4. #define P_LORA_DIO_1 48
  5. #define P_LORA_NSS 11
  6. #define P_LORA_RESET 21
  7. #define P_LORA_BUSY 47
  8. #define P_LORA_SCLK 12
  9. #define P_LORA_MISO 14
  10. #define P_LORA_MOSI 13
  11. // built-ins
  12. //#define PIN_LED_BUILTIN 35
  13. //#define PIN_VEXT_EN 36
  14. #include "ESP32Board.h"
  15. #include <driver/rtc_io.h>
  16. class StationG2Board : public ESP32Board {
  17. public:
  18. void begin() {
  19. ESP32Board::begin();
  20. esp_reset_reason_t reason = esp_reset_reason();
  21. if (reason == ESP_RST_DEEPSLEEP) {
  22. long wakeup_source = esp_sleep_get_ext1_wakeup_status();
  23. if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
  24. startup_reason = BD_STARTUP_RX_PACKET;
  25. }
  26. rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
  27. rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
  28. }
  29. }
  30. void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1) {
  31. esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
  32. // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
  33. rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
  34. rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
  35. rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
  36. if (pin_wake_btn < 0) {
  37. esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
  38. } else {
  39. esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
  40. }
  41. if (secs > 0) {
  42. esp_sleep_enable_timer_wakeup(secs * 1000000);
  43. }
  44. // Finally set ESP32 into sleep
  45. esp_deep_sleep_start(); // CPU halts here and never returns!
  46. }
  47. uint16_t getBattMilliVolts() override {
  48. return 0;
  49. }
  50. const char* getManufacturerName() const override {
  51. return "Station G2";
  52. }
  53. };