Skip to content

Conversation

@LOVECHEN
Copy link

Problem

M5PM1 depends on espressif/i2c_bus which uses the legacy I2C driver (i2c_bus.h).
M5GFX and M5Unified use the native ESP-IDF I2C driver (driver/i2c_master.h).

ESP-IDF 5.x does not allow both drivers to coexist on the same I2C port, causing:

  • Display blackout on M5StickS3
  • I2C communication failures
  • System instability

Solution

Remove the espressif/i2c_bus dependency completely. M5PM1 now only uses the native driver/i2c_master.h driver.

Commits

  • 398ca72: Remove espressif/i2c_bus from idf_component.yml, rewrite M5PM1_i2c_compat.h, remove begin(i2c_bus_handle_t) API
  • b5aec61: Remove espressif__i2c_bus from CMakeLists.txt REQUIRES

Changes Summary

File Change
idf_component.yml Removed espressif/i2c_bus dependency
CMakeLists.txt Removed espressif__i2c_bus from REQUIRES
M5PM1_i2c_compat.h Removed #include "i2c_bus.h" and all i2c_bus macros
M5PM1.h Removed begin(i2c_bus_handle_t) declaration and _i2c_bus/_i2c_device members
M5PM1.cpp Removed begin(i2c_bus_handle_t) implementation and all M5PM1_I2C_DRIVER_BUS cases

API Changes

  • Removed: pm1.begin(i2c_bus_handle_t bus, ...)
  • Kept: pm1.begin(i2c_master_bus_handle_t bus, ...) (ESP-IDF native)
  • Kept: pm1.begin(TwoWire* wire, ...) (Arduino)

Tested

✅ M5StickS3 with M5PM1 + M5Unified + M5GFX working correctly.
✅ Display shows normally, no I2C conflicts.
✅ This enables M5PM1, M5Unified, and M5GFX to coexist without I2C driver conflicts on ESP-IDF 5.x.

@ricker-go This PR resolves the I2C driver conflict issue that prevents M5PM1, M5Unified, and M5GFX from working together. The legacy i2c_bus driver has been completely removed in favor of the native i2c_master driver.

LOVE added 3 commits January 31, 2026 01:19
## 问题背景
- M5PM1 原本依赖 espressif/i2c_bus 库(旧版 I2C 驱动)
- M5GFX/M5Unified 使用 ESP-IDF native driver/i2c_master.h(新版驱动)
- ESP-IDF 5.x 不允许同一个 I2C port 同时使用两种驱动
- 导致 M5StickS3 屏幕黑屏或 I2C 通信失败

## 解决方案
### idf_component.yml
- 删除 espressif/i2c_bus 依赖

### M5PM1_i2c_compat.h
- 移除 #include "i2c_bus.h"
- 移除所有 M5PM1_I2C_*() i2c_bus 版本的宏
- 保留 M5PM1_I2C_MASTER_*() i2c_master 版本的宏
- 移除 M5PM1_I2C_DRIVER_BUS 枚举值

### M5PM1.h
- 删除 begin(i2c_bus_handle_t bus, ...) 函数声明
- 删除 _i2c_bus 成员变量 (i2c_bus_handle_t)
- 删除 _i2c_device 成员变量 (i2c_bus_device_handle_t)

### M5PM1.cpp
- 删除 begin(i2c_bus_handle_t) 实现(约100行)
- 删除构造函数中的 _i2c_bus = nullptr / _i2c_device = nullptr
- 删除析构函数中的 M5PM1_I2C_DRIVER_BUS case
- 删除 _writeReg() 中的 M5PM1_I2C_DRIVER_BUS case
- 删除 _writeReg16() 中的 M5PM1_I2C_DRIVER_BUS case
- 删除 _readReg() 中的 M5PM1_I2C_DRIVER_BUS case
- 删除 _readReg16() 中的 M5PM1_I2C_DRIVER_BUS case
- 删除 _writeBytes() 中的 M5PM1_I2C_DRIVER_BUS case
- 删除 _readBytes() 中的 M5PM1_I2C_DRIVER_BUS case
- 删除 setI2cConfig() 中的两处 M5PM1_I2C_DRIVER_BUS case
- 删除 sendWakeSignal() 中的 M5PM1_I2C_DRIVER_BUS case

## API 变更
- 旧 API: pm1.begin(i2c_bus_handle_t) [已删除]
- 新 API: pm1.begin(i2c_master_bus_handle_t) [保留]
- Arduino API: pm1.begin(TwoWire*) [保留,不受影响]

## 兼容性
- ESP-IDF 5.x: 完全支持(使用 i2c_master 驱动)
- Arduino: 完全支持(使用 TwoWire)
- 与 M5Unified/M5GFX: 现在可以共存,无驱动冲突

## 测试状态
待验证:M5StickS3 + M5PM1 + M5Unified 共存
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant