PromicroBoard.h 1.8 KB

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