8000 Updatate PMU initializaiton. Increased low battery waring levels and … · megacoder/circuitpython@1ea6d7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ea6d7b

Browse files
committed
Updatate PMU initializaiton. Increased low battery waring levels and disabled some interrupts
1 parent 808df20 commit 1ea6d7b

File tree

2 files changed

+88
-5
lines changed

2 files changed

+88
-5
lines changed

ports/espressif/boards/m5stack_stick_c/axp192.h

100644100755
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,28 @@
144144
#define AXP192_BATT_TEMP_HIGH_THRESH 0x39
145145
#define AXP192_BATT_TEMP_HIGH_THRESH_DEFAULT 0b11111100
146146

147+
#define AXP192_APS_LOW_BATT_LEVEL_1 0x3A
148+
#define AXP192_APS_LOW_BATT_LEVEL_2 0x3B
149+
#define AXP192_APS_LOW_BATT_VOLTAGE_3_695V 0b10010100
150+
#define AXP192_APS_LOW_BATT_VOLTAGE_3_600V 0b10000011
151+
147152
#define AXP192_IRQ_1_ENABLE 0x40
148153
#define AXP192_IRQ_2_ENABLE 0x41
149154
#define AXP192_IRQ_3_ENABLE 0x42
155+
#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010
156+
#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001
150157
#define AXP192_IRQ_4_ENABLE 0x43
158+
#define AXP192_IRQ_4_LOW_VOLTAGE_WARNING 0b00000001
151159
#define AXP192_IRQ_5_ENABLE 0x4a
152160

161+
#define AXP192_IRQ_X_DISABLE_ALL 0b00000000
162+
153163
#define AXP192_IRQ_1_STATUS 0x44
154164
#define AXP192_IRQ_2_STATUS 0x45
155165
#define AXP192_IRQ_3_STATUS 0x46
156166
#define AXP192_IRQ_4_STATUS 0x47
157167
#define AXP192_IRQ_5_STATUS 0x4d
158168

159-
#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010
160-
#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001
161-
162169
#define AXP192_ADC_ACIN_VOLTAGE_H 0x56
163170
#define AXP192_ADC_ACIN_VOLTAGE_L 0x57
164171
#define AXP192_ADC_ACIN_CURRENT_H 0x58

ports/espressif/boards/m5stack_stick_c/board.c

100644100755
Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ static bool pmic_init(void) {
127127
return false;
128128
}
129129

130+
// Reg: 3Ah
131+
// APS Low battery warning level 1: 3.695V
132+
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1;
133+
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V;
134+
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
135+
if (rc != 0) {
136+
return false;
137+
}
138+
139+
// Reg: 3Bh
140+
// APS Low battery warning level 2: 3.600V
141+
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2;
142+
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V;
143+
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
144+
if (rc != 0) {
145+
return false;
146+
}
147+
130148
// Reg: 82h
131149
// ADC all on
132150
write_buf[0] = AXP192_ADC_ENABLE_1;
@@ -204,7 +222,7 @@ static bool pmic_init(void) {
204222
return false;
205223
}
206224

207-
// Reg: 28h
225+
// Reg: 26h
208226
// DCDC1 (ESP32 VDD): 3.350V
209227
write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE;
210228
write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V;
@@ -213,6 +231,54 @@ static bool pmic_init(void) {
213231
return false;
214232
}
215233

234+
// Reg: 40h
235+
// IRQ enable control register 1
236+
write_buf[0] = AXP192_IRQ_1_ENABLE;
237+
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
238+
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
239+
if (rc != 0) {
240+
return false;
241+
}
242+
243+
// Reg: 41h
244+
// IRQ enable control register 2
245+
write_buf[0] = AXP192_IRQ_2_ENABLE;
246+
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
247+
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
248+
if (rc != 0) {
249+
return false;
250+
}
251+
252+
// Reg: 42h
253+
// IRQ enable control register 3
254+
// Enable power on key short and long press interrupt
255+
write_buf[0] = AXP192_IRQ_2_ENABLE;
256+
write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS |
257+
AXP192_IRQ_3_PEK_LONG_PRESS;
258+
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
259+
if (rc != 0) {
260+
return false;
261+
}
262+
263+
// Reg: 43h
264+
// IRQ enable control register 4
265+
// Enable power on key short and long press interrupt
266+
write_buf[0] = AXP192_IRQ_2_ENABLE;
267+
write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING;
268+
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
269+
if (rc != 0) {
270+
return false;
271+
}
272+
273+
// Reg: 44h
274+
// IRQ enable control register 5
275+
write_buf[0] = AXP192_IRQ_2_ENABLE;
276+
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
277+
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
278+
if (rc != 0) {
279+
return false;
280+
}
281+
216282
return true;
217283
}
218284

@@ -279,7 +345,17 @@ void board_init(void) {
279345
}
280346

281347
if (!display_init()) {
282-
mp_printf(&mp_plat_print, "could not initialize ili9342c LCD");
348+
mp_printf(&mp_plat_print, "could not initialize the display");
283349
return;
284350
}
285351
}
352+
353+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
354+
// Set IR led gpio high to prevent power drain from the led
355+
if (pin_number == 9) {
356+
gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT);
357+
gpio_set_level(pin_number, true);
358+
return true;
359+
}
360+
return false;
361+
}

0 commit comments

Comments
 (0)
0