T114Board.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. // built-ins
  5. #define PIN_VBAT_READ 4
  6. #define PIN_BAT_CTL 6
  7. #define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
  8. class T114Board : public mesh::MainBoard {
  9. protected:
  10. uint8_t startup_reason;
  11. public:
  12. void begin();
  13. uint8_t getStartupReason() const override { return startup_reason; }
  14. #if defined(P_LORA_TX_LED)
  15. void onBeforeTransmit() override {
  16. digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
  17. }
  18. void onAfterTransmit() override {
  19. digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
  20. }
  21. #endif
  22. uint16_t getBattMilliVolts() override {
  23. int adcvalue = 0;
  24. NRF_SAADC->ENABLE = 1;
  25. analogReadResolution(12);
  26. analogReference(AR_INTERNAL_3_0);
  27. pinMode(PIN_BAT_CTL, OUTPUT); // battery adc can be read only ctrl pin 6 set to high
  28. digitalWrite(PIN_BAT_CTL, 1);
  29. delay(10);
  30. adcvalue = analogRead(PIN_VBAT_READ);
  31. digitalWrite(6, 0);
  32. NRF_SAADC->ENABLE = 0;
  33. return (uint16_t)((float)adcvalue * MV_LSB * 4.9);
  34. }
  35. const char* getManufacturerName() const override {
  36. return "Heltec T114";
  37. }
  38. void reboot() override {
  39. NVIC_SystemReset();
  40. }
  41. void powerOff() override {
  42. sd_power_system_off();
  43. }
  44. bool startOTAUpdate(const char* id, char reply[]) override;
  45. };