Browse Source

Add AW32001E init to disable WDT

pull/1117/head
Ashley 7 months ago
parent
commit
24385e84d9
  1. 1
      variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp
  2. 56
      variants/arduino_nesso_n1/expander.cpp
  3. 18
      variants/arduino_nesso_n1/pins_arduino.h

1
variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp

@ -15,6 +15,7 @@ void ArduinoNessoN1Board::begin() {
digitalWrite(P_LORA_TX_LED, HIGH); digitalWrite(P_LORA_TX_LED, HIGH);
#endif #endif
battery.begin();
battery.enableCharge(); battery.enableCharge();
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): set Nesso N1 pin modes and default states..."); MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): set Nesso N1 pin modes and default states...");

56
variants/arduino_nesso_n1/expander.cpp

@ -94,20 +94,64 @@ int digitalRead(ExpanderPin pin) {
return readBitRegister(pin.address, 0xF, pin.pin); return readBitRegister(pin.address, 0xF, pin.pin);
} }
void NessoBattery::enableCharge() { void NessoBattery::begin() {
// AW32001E - address 0x49 // AW32001E - address 0x49
// set CEB bit low (charge enable) // Spec: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/core/LLM630%20Computer%20Kit/AW32001E.pdf
if (!wireInitialized) { if (!wireInitialized) {
Wire.begin(SDA, SCL); Wire.begin(SDA, SCL);
wireInitialized = true; wireInitialized = true;
} }
uint8_t val = 0;
val = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHIP_ID);
// coarsely check if chip is actually the right chip
auto res = (val == AW32001_I2C_CHIP_ADDR);
if (res) {
val = readRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHR_TMR);
#ifdef MESH_DEBUG
// Debug output the WatchDog Timer (wdt) state
MESH_DEBUG_PRINTLN("NessoBattery.begin(): CHR_TMR full register; bits 5,6 are for WDT = %#02x", val);
#endif
// disable WatchDog Timer (wdt)
// take existing register value AND with 00011111
val = val & 0x1f;
writeRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_CHR_TMR, val);
}
#ifdef MESH_DEBUG
else {
MESH_DEBUG_PRINTLN("NessoBattery.begin(): Register of chip ADDR = %u != I2C of chip %u", AW32001_REG_CHIP_ID, AW32001_I2C_CHIP_ADDR);
}
#endif
// store if chip is initiated by whether it passed above checks and had watchdog disabled
_power_mgmt_init = res;
}
void NessoBattery::enableCharge() {
// AW32001E - address 0x49
// set CEB (charge enable) bit (3) low (0) in AW32001_REG_PWR_CFG (0x01)
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge()"); MESH_DEBUG_PRINTLN("NessoBattery::enableCharge()");
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge level %u %%", NessoBattery::getChargeLevel());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %f V", NessoBattery::getVoltage());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %u mV", NessoBattery::getMilliVoltage());
writeBitRegister(0x49, 0x1, 3, false); if (_power_mgmt_init) {
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): _power_mgmt_init = true");
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
bool charge_enable_bit = readBitRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_PWR_CFG, 3);
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge setting (low is on): %u", charge_enable_bit);
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge level %u %%", NessoBattery::getChargeLevel());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %f V", NessoBattery::getVoltage());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %u mV", NessoBattery::getMilliVoltage());
writeBitRegister(AW32001_I2C_CHIP_ADDR, AW32001_REG_PWR_CFG, 3, false);
}
#ifdef MESH_DEBUG
else {
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): _power_mgmt_init is false, won't enable charge");
}
#endif
} }
float NessoBattery::getVoltage() { float NessoBattery::getVoltage() {

18
variants/arduino_nesso_n1/pins_arduino.h

@ -41,6 +41,19 @@ static const uint8_t SYS_IRQ = 3;
static const uint8_t LCD_CS = 17; static const uint8_t LCD_CS = 17;
static const uint8_t LCD_RS = 16; static const uint8_t LCD_RS = 16;
// AW32001 registers
static constexpr const uint8_t AW32001_REG_PWR_CFG = 0x01; // Power Configuration
static constexpr const uint8_t AW32001_REG_CHR_CUR = 0x02; // Charging current
static constexpr const uint8_t AW32001_REG_CHR_VOL = 0x04; // Charge voltage
static constexpr const uint8_t AW32001_REG_CHR_TMR = 0x05; // Charge timer
static constexpr const uint8_t AW32001_REG_SYS_STA = 0x08; // System status
static constexpr const uint8_t AW32001_REG_CHIP_ID = 0x0A; // ChipID
static constexpr const uint8_t AW32001_I2C_CHIP_ADDR = 0x49; // ChipID
#if !defined(MAIN_ESP32_HAL_GPIO_H_) && defined(__cplusplus) #if !defined(MAIN_ESP32_HAL_GPIO_H_) && defined(__cplusplus)
/* address: 0x43/0x44 */ /* address: 0x43/0x44 */
class ExpanderPin { class ExpanderPin {
@ -51,9 +64,12 @@ public:
}; };
class NessoBattery { class NessoBattery {
private:
bool _power_mgmt_init = false;
public: public:
NessoBattery(){}; NessoBattery(){};
void enableCharge(); // enable charging void begin(){}; // setup and check power management chip
void enableCharge(); // enable charging via power management chip
float getVoltage(); // get battery voltage in Volts float getVoltage(); // get battery voltage in Volts
uint16_t getMilliVoltage(); // get battery voltage in millivolts uint16_t getMilliVoltage(); // get battery voltage in millivolts
uint16_t getChargeLevel(); // get battery charge level in percents uint16_t getChargeLevel(); // get battery charge level in percents

Loading…
Cancel
Save