Merge pull request #7818 from CDarius/m5stack_stickc_fixes

M5stack Stick-C fixes
This commit is contained in:
Dan Halbert 2023-03-30 09:33:07 -04:00 committed by GitHub
commit b07de078f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 5 deletions

13
ports/espressif/boards/m5stack_stick_c/axp192.h Normal file → Executable file
View File

@ -144,21 +144,28 @@
#define AXP192_BATT_TEMP_HIGH_THRESH 0x39 #define AXP192_BATT_TEMP_HIGH_THRESH 0x39
#define AXP192_BATT_TEMP_HIGH_THRESH_DEFAULT 0b11111100 #define AXP192_BATT_TEMP_HIGH_THRESH_DEFAULT 0b11111100
#define AXP192_APS_LOW_BATT_LEVEL_1 0x3A
#define AXP192_APS_LOW_BATT_LEVEL_2 0x3B
#define AXP192_APS_LOW_BATT_VOLTAGE_3_695V 0b10010100
#define AXP192_APS_LOW_BATT_VOLTAGE_3_600V 0b10000011
#define AXP192_IRQ_1_ENABLE 0x40 #define AXP192_IRQ_1_ENABLE 0x40
#define AXP192_IRQ_2_ENABLE 0x41 #define AXP192_IRQ_2_ENABLE 0x41
#define AXP192_IRQ_3_ENABLE 0x42 #define AXP192_IRQ_3_ENABLE 0x42
#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010
#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001
#define AXP192_IRQ_4_ENABLE 0x43 #define AXP192_IRQ_4_ENABLE 0x43
#define AXP192_IRQ_4_LOW_VOLTAGE_WARNING 0b00000001
#define AXP192_IRQ_5_ENABLE 0x4a #define AXP192_IRQ_5_ENABLE 0x4a
#define AXP192_IRQ_X_DISABLE_ALL 0b00000000
#define AXP192_IRQ_1_STATUS 0x44 #define AXP192_IRQ_1_STATUS 0x44
#define AXP192_IRQ_2_STATUS 0x45 #define AXP192_IRQ_2_STATUS 0x45
#define AXP192_IRQ_3_STATUS 0x46 #define AXP192_IRQ_3_STATUS 0x46
#define AXP192_IRQ_4_STATUS 0x47 #define AXP192_IRQ_4_STATUS 0x47
#define AXP192_IRQ_5_STATUS 0x4d #define AXP192_IRQ_5_STATUS 0x4d
#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010
#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001
#define AXP192_ADC_ACIN_VOLTAGE_H 0x56 #define AXP192_ADC_ACIN_VOLTAGE_H 0x56
#define AXP192_ADC_ACIN_VOLTAGE_L 0x57 #define AXP192_ADC_ACIN_VOLTAGE_L 0x57
#define AXP192_ADC_ACIN_CURRENT_H 0x58 #define AXP192_ADC_ACIN_CURRENT_H 0x58

80
ports/espressif/boards/m5stack_stick_c/board.c Normal file → Executable file
View File

@ -127,6 +127,24 @@ static bool pmic_init(void) {
return false; return false;
} }
// Reg: 3Ah
// APS Low battery warning level 1: 3.695V
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1;
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 3Bh
// APS Low battery warning level 2: 3.600V
write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2;
write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 82h // Reg: 82h
// ADC all on // ADC all on
write_buf[0] = AXP192_ADC_ENABLE_1; write_buf[0] = AXP192_ADC_ENABLE_1;
@ -204,7 +222,7 @@ static bool pmic_init(void) {
return false; return false;
} }
// Reg: 28h // Reg: 26h
// DCDC1 (ESP32 VDD): 3.350V // DCDC1 (ESP32 VDD): 3.350V
write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE; write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE;
write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V; write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V;
@ -213,6 +231,54 @@ static bool pmic_init(void) {
return false; return false;
} }
// Reg: 40h
// IRQ enable control register 1
write_buf[0] = AXP192_IRQ_1_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 41h
// IRQ enable control register 2
write_buf[0] = AXP192_IRQ_2_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 42h
// IRQ enable control register 3
// Enable power on key short and long press interrupt
write_buf[0] = AXP192_IRQ_2_ENABLE;
write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS |
AXP192_IRQ_3_PEK_LONG_PRESS;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 43h
// IRQ enable control register 4
// Enable power on key short and long press interrupt
write_buf[0] = AXP192_IRQ_2_ENABLE;
write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
// Reg: 44h
// IRQ enable control register 5
write_buf[0] = AXP192_IRQ_2_ENABLE;
write_buf[1] = AXP192_IRQ_X_DISABLE_ALL;
rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf));
if (rc != 0) {
return false;
}
return true; return true;
} }
@ -279,7 +345,17 @@ void board_init(void) {
} }
if (!display_init()) { if (!display_init()) {
mp_printf(&mp_plat_print, "could not initialize ili9342c LCD"); mp_printf(&mp_plat_print, "could not initialize the display");
return; return;
} }
} }
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
// Set IR led gpio high to prevent power drain from the led
if (pin_number == 9) {
gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT);
gpio_set_level(pin_number, true);
return true;
}
return false;
}

View File

@ -30,6 +30,7 @@
#define MICROPY_HW_MCU_NAME "ESP32" #define MICROPY_HW_MCU_NAME "ESP32"
#define MICROPY_HW_LED_STATUS (&pin_GPIO10) #define MICROPY_HW_LED_STATUS (&pin_GPIO10)
#define MICROPY_HW_LED_STATUS_INVERTED (1)
#define CIRCUITPY_BOARD_I2C (2) #define CIRCUITPY_BOARD_I2C (2)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}, \ #define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}, \

View File

@ -37,6 +37,9 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
// internal devices interrupt // internal devices interrupt
{ MP_ROM_QSTR(MP_QSTR_SYS_INT), MP_ROM_PTR(&pin_GPIO35) }, { MP_ROM_QSTR(MP_QSTR_SYS_INT), MP_ROM_PTR(&pin_GPIO35) },
// pmu AXP192
{ MP_ROM_QSTR(MP_QSTR_PMU_N_VBUSEN), MP_ROM_PTR(&pin_GPIO27) },
// pdm microphone // pdm microphone
{ MP_ROM_QSTR(MP_QSTR_PDM_MIC_CLK), MP_ROM_PTR(&pin_GPIO0) }, { MP_ROM_QSTR(MP_QSTR_PDM_MIC_CLK), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_PDM_MIC_DATA), MP_ROM_PTR(&pin_GPIO34) }, { MP_ROM_QSTR(MP_QSTR_PDM_MIC_DATA), MP_ROM_PTR(&pin_GPIO34) },