I2C improvements and fixes (#201)

- Show I2C device name in I2C Scanner app
- Register various I2C devices from board implementations
- Fix M5Stack Core2 power status
- Fix pre-allocation issue in `hal::Device`
This commit is contained in:
Ken Van Hoeylandt
2025-02-02 17:54:36 +01:00
committed by GitHub
parent 2e61aea93c
commit c0f4738abe
13 changed files with 133 additions and 59 deletions
+15 -11
View File
@@ -14,6 +14,9 @@
#define CORES3_SPI2_PIN_MOSI GPIO_NUM_37
#define CORES3_SPI2_PIN_MISO GPIO_NUM_35
std::shared_ptr<Axp2101> axp2101;
std::shared_ptr<Aw9523> aw9523;
/**
* For details see https://github.com/espressif/esp-bsp/blob/master/bsp/m5stack_core_s3/m5stack_core_s3.c
*/
@@ -92,22 +95,19 @@ bool initGpioExpander() {
// Boost enable
p1_state |= (1U << 7U);
Aw9523 aw(I2C_NUM_0);
if (!aw.writeP0(p0_state)) {
if (!aw9523->writeP0(p0_state)) {
TT_LOG_E(TAG, "AW9523: Failed to set P0");
return false;
}
if (!aw.writeP1(p1_state)) {
if (!aw9523->writeP1(p1_state)) {
TT_LOG_E(TAG, "AW9523: Failed to set P1");
return false;
}
Axp2101 axp(I2C_NUM_0);
if (axp.isVBus()) {
if (axp2101->isVBus()) {
float voltage = 0.0f;
axp.getVBusVoltage(voltage);
axp2101->getVBusVoltage(voltage);
TT_LOG_I(TAG, "AXP2101: VBus at %.2f", voltage);
} else {
TT_LOG_W(TAG, "AXP2101: VBus disabled");
@@ -119,9 +119,8 @@ bool initGpioExpander() {
bool initPowerControl() {
TT_LOG_I(TAG, "Init power control (AXP2101)");
Aw9523 aw(I2C_NUM_0);
// Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L61
aw.bitOnP1(0b10000000); // SY7088 boost enable
aw9523->bitOnP1(0b10000000); // SY7088 boost enable
/** AXP2101 usage
Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/README.md?plain=1#L223
@@ -168,8 +167,7 @@ bool initPowerControl() {
0x30, 0x0F // ADC enabled (for voltage measurement)
};
Axp2101 axp(I2C_NUM_0);
if (axp.setRegisters((uint8_t*)reg_data_array, sizeof(reg_data_array))) {
if (axp2101->setRegisters((uint8_t*)reg_data_array, sizeof(reg_data_array))) {
TT_LOG_I(TAG, "AXP2101 initialized with %d registers", sizeof(reg_data_array) / 2);
return true;
} else {
@@ -180,6 +178,12 @@ bool initPowerControl() {
bool initBoot() {
TT_LOG_I(TAG, "initBoot()");
axp2101 = std::make_shared<Axp2101>(I2C_NUM_0);
tt::hal::registerDevice(axp2101);
aw9523 = std::make_shared<Aw9523>(I2C_NUM_0);
tt::hal::registerDevice(aw9523);
return initPowerControl() &&
initGpioExpander() &&
initSpi3();