PicoWBoard.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. // built-ins
  5. #define PIN_VBAT_READ 26
  6. #define ADC_MULTIPLIER (3.1 * 3.3 * 1000) // MT Uses 3.1
  7. #define PIN_LED_BUILTIN LED_BUILTIN
  8. class PicoWBoard : 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. void onBeforeTransmit() override {
  15. digitalWrite(LED_BUILTIN, HIGH); // turn TX LED on
  16. }
  17. void onAfterTransmit() override {
  18. digitalWrite(LED_BUILTIN, LOW); // turn TX LED off
  19. }
  20. #define BATTERY_SAMPLES 8
  21. uint16_t getBattMilliVolts() override {
  22. analogReadResolution(12);
  23. uint32_t raw = 0;
  24. for (int i = 0; i < BATTERY_SAMPLES; i++) {
  25. raw += analogRead(PIN_VBAT_READ);
  26. }
  27. raw = raw / BATTERY_SAMPLES;
  28. return (ADC_MULTIPLIER * raw) / 4096;
  29. }
  30. const char* getManufacturerName() const override {
  31. return "Pico W";
  32. }
  33. void reboot() override {
  34. //NVIC_SystemReset();
  35. rp2040.reboot();
  36. }
  37. bool startOTAUpdate(const char* id, char reply[]) override;
  38. };