diff --git a/Utilities.h b/Utilities.h index fa45296..705b676 100644 --- a/Utilities.h +++ b/Utilities.h @@ -1,16 +1,21 @@ #include #include +#include "Config.h" #include "LoRa.h" #include "ROM.h" -#include "Config.h" #include "Framing.h" #include "MD5.h" +#if MCU_VARIANT == MCU_ESP32 + #include "soc/rtc_wdt.h" + #define ISR_VECT IRAM_ATTR +#else + #define ISR_VECT +#endif + #if MCU_VARIANT == MCU_1284P || MCU_VARIANT == MCU_2560 #include #include -#elif MCU_VARIANT == MCU_ESP32 - // TODO: Hard reset on ESP32 #endif uint8_t boot_vector = 0x00; @@ -799,3 +804,82 @@ inline void fifo16_init(FIFOBuffer16 *f, uint16_t *buffer, uint16_t size) { inline uint16_t fifo16_len(FIFOBuffer16 *f) { return (f->end - f->begin); } + +#if BOARD_MODEL == BOARD_TBEAM + #include + AXP20X_Class PMU; + + bool initPMU() + { + if (PMU.begin(Wire, AXP192_SLAVE_ADDRESS) == AXP_FAIL) { + return false; + } + /* + * The charging indicator can be turned on or off + * * * */ + PMU.setChgLEDMode(AXP20X_LED_OFF); + + /* + * The default ESP32 power supply has been turned on, + * no need to set, please do not set it, if it is turned off, + * it will not be able to program + * + * PMU.setDCDC3Voltage(3300); + * PMU.setPowerOutPut(AXP192_DCDC3, AXP202_ON); + * + * * * */ + + /* + * Turn off unused power sources to save power + * **/ + + PMU.setPowerOutPut(AXP192_DCDC1, AXP202_OFF); + PMU.setPowerOutPut(AXP192_DCDC2, AXP202_OFF); + PMU.setPowerOutPut(AXP192_LDO2, AXP202_OFF); + PMU.setPowerOutPut(AXP192_LDO3, AXP202_OFF); + PMU.setPowerOutPut(AXP192_EXTEN, AXP202_OFF); + + /* + * Set the power of LoRa and GPS module to 3.3V + **/ + PMU.setLDO2Voltage(3300); //LoRa VDD + PMU.setLDO3Voltage(3300); //GPS VDD + PMU.setDCDC1Voltage(3300); //3.3V Pin next to 21 and 22 is controlled by DCDC1 + + PMU.setPowerOutPut(AXP192_DCDC1, AXP202_ON); + + // Turn on SX1276 + PMU.setPowerOutPut(AXP192_LDO2, AXP202_ON); + + // Turn off GPS + PMU.setPowerOutPut(AXP192_LDO3, AXP202_OFF); + + pinMode(PMU_IRQ, INPUT_PULLUP); + attachInterrupt(PMU_IRQ, [] { + // pmu_irq = true; + }, FALLING); + + PMU.adc1Enable(AXP202_VBUS_VOL_ADC1 | + AXP202_VBUS_CUR_ADC1 | + AXP202_BATT_CUR_ADC1 | + AXP202_BATT_VOL_ADC1, + AXP202_ON); + + PMU.enableIRQ(AXP202_VBUS_REMOVED_IRQ | + AXP202_VBUS_CONNECT_IRQ | + AXP202_BATT_REMOVED_IRQ | + AXP202_BATT_CONNECT_IRQ, + AXP202_ON); + PMU.clearIRQ(); + + return true; + } + + void disablePeripherals() + { + PMU.setPowerOutPut(AXP192_DCDC1, AXP202_OFF); + PMU.setPowerOutPut(AXP192_LDO2, AXP202_OFF); + PMU.setPowerOutPut(AXP192_LDO3, AXP202_OFF); + } + +#endif \ No newline at end of file