Browse Source

Merge pull request #135 from recrof/dev

LilyGo T-ECHO: report correct battery voltage
pull/145/head
ripplebiz 1 year ago
committed by GitHub
parent
commit
02edc645bb
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 31
      src/helpers/nrf52/TechoBoard.cpp
  2. 28
      src/helpers/nrf52/TechoBoard.h
  3. 14
      variants/techo/variant.h

31
src/helpers/nrf52/TechoBoard.cpp

@ -22,11 +22,18 @@ void TechoBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin() // for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL; startup_reason = BD_STARTUP_NORMAL;
pinMode(PIN_VBAT_READ, INPUT); delay(200);
pinMode(PIN_PWR_EN, OUTPUT);
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL) digitalWrite(PIN_PWR_EN, HIGH);
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL) pinMode(PIN_BUTTON1, INPUT_PULLUP);
#endif pinMode(PIN_BUTTON2, INPUT_PULLUP);
pinMode(LED_RED, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
delay(200);
pinMode(PIN_TXCO, OUTPUT);
digitalWrite(PIN_TXCO, HIGH);
Wire.begin(); Wire.begin();
@ -35,6 +42,20 @@ void TechoBoard::begin() {
delay(10); // give sx1262 some time to power up delay(10); // give sx1262 some time to power up
} }
uint16_t TechoBoard::getBattMilliVolts() {
int adcvalue = 0;
analogReference(AR_INTERNAL_3_0);
analogReadResolution(12);
delay(10);
// ADC range is 0..3000mV and resolution is 12-bit (0..4095)
adcvalue = analogRead(PIN_VBAT_READ);
// Convert the raw value to compensated mv, taking the resistor-
// divider into account (providing the actual LIPO voltage)
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
}
bool TechoBoard::startOTAUpdate(const char* id, char reply[]) { bool TechoBoard::startOTAUpdate(const char* id, char reply[]) {
// Config the peripheral connection with maximum bandwidth // Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice // more SRAM required by SoftDevice

28
src/helpers/nrf52/TechoBoard.h

@ -17,28 +17,26 @@
#define SX126X_DIO3_TCXO_VOLTAGE 1.8 #define SX126X_DIO3_TCXO_VOLTAGE 1.8
// built-ins // built-ins
#define PIN_VBAT_READ 4 #define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
#define ADC_MULTIPLIER (2.0)
#define VBAT_DIVIDER (0.5F) // 150K + 150K voltage divider on VBAT
#define VBAT_DIVIDER_COMP (2.0F) // Compensation factor for the VBAT divider
#define PIN_VBAT_READ (4)
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
class TechoBoard : public mesh::MainBoard { class TechoBoard : public mesh::MainBoard {
protected: protected:
uint8_t startup_reason; uint8_t startup_reason;
public: public:
void begin();
uint8_t getStartupReason() const override { return startup_reason; }
#define BATTERY_SAMPLES 8
uint16_t getBattMilliVolts() override { void begin();
analogReadResolution(12); uint16_t getBattMilliVolts() override;
uint32_t raw = 0; bool startOTAUpdate(const char* id, char reply[]) override;
for (int i = 0; i < BATTERY_SAMPLES; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / BATTERY_SAMPLES;
return (ADC_MULTIPLIER * raw) / 4096; uint8_t getStartupReason() const override {
return startup_reason;
} }
const char* getManufacturerName() const override { const char* getManufacturerName() const override {
@ -48,6 +46,4 @@ public:
void reboot() override { void reboot() override {
NVIC_SystemReset(); NVIC_SystemReset();
} }
bool startOTAUpdate(const char* id, char reply[]) override;
}; };

14
variants/techo/variant.h

@ -14,12 +14,12 @@
#define USE_LFXO // 32.768 kHz crystal oscillator #define USE_LFXO // 32.768 kHz crystal oscillator
#define VARIANT_MCK (64000000ul) #define VARIANT_MCK (64000000ul)
#define WIRE_INTERFACES_COUNT (1) #define WIRE_INTERFACES_COUNT (1)
#define PIN_TXCO (21)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Power // Power
#define PIN_PWR_EN (6) #define PIN_PWR_EN (12)
#define BATTERY_PIN (4) #define BATTERY_PIN (4)
#define ADC_MULTIPLIER (4.90F) #define ADC_MULTIPLIER (4.90F)
@ -62,11 +62,11 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Builtin LEDs // Builtin LEDs
#define LED_RED (13) #define LED_RED (34)
#define LED_GREEN (33)
#define LED_BLUE (14) #define LED_BLUE (14)
#define LED_GREEN (15)
#define LED_BUILTIN (15) #define LED_BUILTIN LED_GREEN
#define PIN_LED LED_BUILTIN #define PIN_LED LED_BUILTIN
#define LED_PIN LED_BUILTIN #define LED_PIN LED_BUILTIN
#define LED_STATE_ON LOW #define LED_STATE_ON LOW
@ -80,7 +80,7 @@
#define PIN_BUTTON1 (42) #define PIN_BUTTON1 (42)
#define BUTTON_PIN PIN_BUTTON1 #define BUTTON_PIN PIN_BUTTON1
#define PIN_BUTTON2 (18) #define PIN_BUTTON2 (11)
#define BUTTON_PIN2 PIN_BUTTON2 #define BUTTON_PIN2 PIN_BUTTON2
#define EXTERNAL_FLASH_DEVICES MX25R1635F #define EXTERNAL_FLASH_DEVICES MX25R1635F

Loading…
Cancel
Save