StationG3Board.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <helpers/ESP32Board.h>
  4. #include <driver/rtc_io.h>
  5. #ifndef P_PRIMARY_LNA_EN_ACTIVE
  6. #define P_PRIMARY_LNA_EN_ACTIVE LOW
  7. #endif
  8. #ifndef P_PA1_EN_ACTIVE
  9. #define P_PA1_EN_ACTIVE HIGH
  10. #endif
  11. class StationG3Board : public ESP32Board {
  12. void setPAModeHigh(bool enabled) {
  13. #ifdef P_PA1_EN
  14. // Station G3 PA PL1 mode: LOW/open is PA low, HIGH/short is PA high.
  15. digitalWrite(P_PA1_EN, enabled ? P_PA1_EN_ACTIVE : !P_PA1_EN_ACTIVE);
  16. #endif
  17. }
  18. void setPrimaryLNAControl(bool enabled) {
  19. #ifdef P_PRIMARY_LNA_EN
  20. // Station G3 primary LNA mode is active-low: LOW/open is LNA on, HIGH/short is LNA off.
  21. digitalWrite(P_PRIMARY_LNA_EN, enabled ? P_PRIMARY_LNA_EN_ACTIVE : !P_PRIMARY_LNA_EN_ACTIVE);
  22. #endif
  23. }
  24. public:
  25. void begin() {
  26. ESP32Board::begin();
  27. #ifdef P_PA1_EN
  28. rtc_gpio_hold_dis((gpio_num_t)P_PA1_EN);
  29. pinMode(P_PA1_EN, OUTPUT);
  30. setPAModeHigh(false);
  31. #endif
  32. #ifdef P_PRIMARY_LNA_EN
  33. rtc_gpio_hold_dis((gpio_num_t)P_PRIMARY_LNA_EN);
  34. pinMode(P_PRIMARY_LNA_EN, OUTPUT);
  35. setPrimaryLNAControl(true);
  36. #endif
  37. esp_reset_reason_t reason = esp_reset_reason();
  38. if (reason == ESP_RST_DEEPSLEEP) {
  39. uint64_t wakeup_source = esp_sleep_get_ext1_wakeup_status();
  40. if (wakeup_source & (1ULL << P_LORA_DIO_1)) {
  41. startup_reason = BD_STARTUP_RX_PACKET;
  42. }
  43. rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
  44. rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
  45. }
  46. }
  47. void setPrimaryLNAEnable(bool enabled) {
  48. setPrimaryLNAControl(enabled);
  49. }
  50. void setPrimaryPAHighPower(bool enabled) {
  51. setPAModeHigh(enabled);
  52. }
  53. void onBeforeTransmit() override {
  54. ESP32Board::onBeforeTransmit();
  55. setPrimaryLNAControl(false);
  56. }
  57. void onAfterTransmit() override {
  58. ESP32Board::onAfterTransmit();
  59. setPrimaryLNAControl(true);
  60. }
  61. void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1) {
  62. esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
  63. rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
  64. rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
  65. rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
  66. #ifdef P_PA1_EN
  67. setPAModeHigh(false);
  68. rtc_gpio_hold_en((gpio_num_t)P_PA1_EN);
  69. #endif
  70. #ifdef P_PRIMARY_LNA_EN
  71. setPrimaryLNAControl(true);
  72. rtc_gpio_hold_en((gpio_num_t)P_PRIMARY_LNA_EN);
  73. #endif
  74. if (pin_wake_btn < 0) {
  75. esp_sleep_enable_ext1_wakeup((1ULL << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH);
  76. } else {
  77. esp_sleep_enable_ext1_wakeup((1ULL << P_LORA_DIO_1) | (1ULL << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH);
  78. }
  79. if (secs > 0) {
  80. esp_sleep_enable_timer_wakeup(secs * 1000000);
  81. }
  82. esp_deep_sleep_start();
  83. }
  84. uint16_t getBattMilliVolts() override {
  85. return 0;
  86. }
  87. const char* getManufacturerName() const override {
  88. return "Station G3 ESP32";
  89. }
  90. };