PromicroBoard.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. #define P_LORA_NSS 13 //P1.13 45
  5. #define P_LORA_DIO_1 11 //P0.10 10
  6. #define P_LORA_RESET 10 //P0.09 9
  7. #define P_LORA_BUSY 16 //P0.29 29
  8. #define P_LORA_MISO 15 //P0.02 2
  9. #define P_LORA_SCLK 12 //P1.11 43
  10. #define P_LORA_MOSI 14 //P1.15 47
  11. #define SX126X_POWER_EN 21 //P0.13 13
  12. #define SX126X_RXEN 2 //P0.17
  13. #define SX126X_TXEN RADIOLIB_NC
  14. #define SX126X_DIO2_AS_RF_SWITCH true
  15. #define SX126X_DIO3_TCXO_VOLTAGE (1.8f)
  16. #define PIN_VBAT_READ 17
  17. #define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
  18. class PromicroBoard : public mesh::MainBoard {
  19. protected:
  20. uint8_t startup_reason;
  21. uint8_t btn_prev_state;
  22. public:
  23. void begin();
  24. uint8_t getStartupReason() const override { return startup_reason; }
  25. #define BATTERY_SAMPLES 8
  26. uint16_t getBattMilliVolts() override {
  27. analogReadResolution(12);
  28. uint32_t raw = 0;
  29. for (int i = 0; i < BATTERY_SAMPLES; i++) {
  30. raw += analogRead(PIN_VBAT_READ);
  31. }
  32. raw = raw / BATTERY_SAMPLES;
  33. return (ADC_MULTIPLIER * raw);
  34. }
  35. const char* getManufacturerName() const override {
  36. return "ProMicro DIY";
  37. }
  38. int buttonStateChanged() {
  39. #ifdef BUTTON_PIN
  40. uint8_t v = digitalRead(BUTTON_PIN);
  41. if (v != btn_prev_state) {
  42. btn_prev_state = v;
  43. return (v == LOW) ? 1 : -1;
  44. }
  45. #endif
  46. return 0;
  47. }
  48. void reboot() override {
  49. NVIC_SystemReset();
  50. }
  51. void powerOff() override {
  52. sd_power_system_off();
  53. }
  54. bool startOTAUpdate(const char* id, char reply[]) override;
  55. };