From 716c355b216d1551bb554b0cb88e0568fdbcd6dd Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 18 Jan 2020 17:41:17 -0800 Subject: [PATCH] move axpinit and document LDO & LED usage on V1 hardware --- main/configuration.h | 2 +- main/main.ino | 107 +++++++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 45 deletions(-) diff --git a/main/configuration.h b/main/configuration.h index feb29df..b7c2789 100644 --- a/main/configuration.h +++ b/main/configuration.h @@ -91,9 +91,9 @@ void ttn_register(void (*callback)(uint8_t message)); #define I2C_SDA 21 #define I2C_SCL 22 -#define LED_PIN 14 #if defined(T_BEAM_V07) +#define LED_PIN 14 #define BUTTON_PIN 39 #elif defined(T_BEAM_V10) #define BUTTON_PIN 38 diff --git a/main/main.ino b/main/main.ino index 6e39b7c..73eac14 100644 --- a/main/main.ino +++ b/main/main.ino @@ -171,6 +171,66 @@ void scanI2Cdevice(void) Serial.println("done\n"); } +/** + * Init the power manager chip + * + * axp192 power + DCDC1 0.7-3.5V @ 1200mA max -> OLED // If you turn this off you'll lose comms to the axp192 because the OLED and the axp192 share the same i2c bus, instead use ssd1306 sleep mode + DCDC2 -> unused + DCDC3 0.7-3.5V @ 700mA max -> ESP32 (keep this on!) + LDO1 30mA -> charges GPS backup battery // turn this off during deep sleep to force the tiny J13 battery by the GPS to power the GPS ram (for a couple of days) + LDO2 200mA -> LORA + LDO3 200mA -> GPS + */ +void axp192Init() { + if (axp192_found) { + if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) { + Serial.println("AXP192 Begin PASS"); + } else { + Serial.println("AXP192 Begin FAIL"); + } + // axp.setChgLEDMode(LED_BLINK_4HZ); + Serial.printf("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE"); + Serial.println("----------------------------------------"); + + axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); + axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); + axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON); + axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON); + axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); + axp.setDCDC1Voltage(3300); // for the OLED power + + Serial.printf("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE"); + Serial.printf("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE"); + + pinMode(PMU_IRQ, INPUT_PULLUP); + attachInterrupt(PMU_IRQ, [] { + pmu_irq = true; + }, FALLING); + + axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1); + axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1); + axp.clearIRQ(); + + if (axp.isChargeing()) { + baChStatus = "Charging"; + } + } else { + Serial.println("AXP192 not found"); + } +} + + + void setup() { // Debug #ifdef DEBUG_PORT @@ -183,55 +243,14 @@ void setup() { Wire.begin(I2C_SDA, I2C_SCL); scanI2Cdevice(); axp192_found = true; - if (axp192_found) { - if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) { - Serial.println("AXP192 Begin PASS"); - } else { - Serial.println("AXP192 Begin FAIL"); - } - // axp.setChgLEDMode(LED_BLINK_4HZ); - Serial.printf("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE"); - Serial.println("----------------------------------------"); - - axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); - axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); - axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON); - axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON); - axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); - axp.setDCDC1Voltage(3300); - - Serial.printf("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE"); - Serial.printf("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE"); - - pinMode(PMU_IRQ, INPUT_PULLUP); - attachInterrupt(PMU_IRQ, [] { - pmu_irq = true; - }, FALLING); - - axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1); - axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1); - axp.clearIRQ(); - - if (axp.isChargeing()) { - baChStatus = "Charging"; - } - } else { - Serial.println("AXP192 not found"); - } + axp192Init(); #endif // Buttons & LED pinMode(BUTTON_PIN, INPUT_PULLUP); +#ifdef LED_PIN pinMode(LED_PIN, OUTPUT); +#endif // Hello DEBUG_MSG(APP_NAME " " APP_VERSION "\n");