diff --git a/CMakeLists.txt b/CMakeLists.txt index bf15769..5210ca5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,5 +5,5 @@ idf_component_register( "src" REQUIRES "driver" - "espressif__i2c_bus" + # NOTE: espressif__i2c_bus dependency removed to avoid conflict with M5GFX ) diff --git a/idf_component.yml b/idf_component.yml index e0124b8..0188ac4 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,15 +1,13 @@ -description: "M5Stack M5PM1 Power Management IC Library" -url: "https://github.com/m5stack/M5PM1" +description: "M5Stack M5PM1 Power Management IC Library (i2c_master only)" +url: "https://github.com/LOVECHEN/M5PM1" maintainers: - "M5Stack" + - "LOVECHEN" license: MIT tags: - "m5stack" - "power-management" dependencies: idf: - version: ">=4.4" - espressif/i2c_bus: - version: "^1.0.0" - public: true -version: "1.0.4" \ No newline at end of file + version: ">=5.0" +version: "1.0.5" \ No newline at end of file diff --git a/src/M5PM1.cpp b/src/M5PM1.cpp index ea33e1a..a0969a5 100644 --- a/src/M5PM1.cpp +++ b/src/M5PM1.cpp @@ -162,12 +162,11 @@ M5PM1::M5PM1() _i2cDriverType = M5PM1_I2C_DRIVER_NONE; _i2c_master_bus = nullptr; _i2c_master_dev = nullptr; - _i2c_bus = nullptr; - _i2c_device = nullptr; - _busExternal = false; - _sda = -1; - _scl = -1; - _port = I2C_NUM_0; + // NOTE: _i2c_bus and _i2c_device removed (i2c_bus support removed) + _busExternal = false; + _sda = -1; + _scl = -1; + _port = I2C_NUM_0; #endif } @@ -194,12 +193,7 @@ M5PM1::~M5PM1() } break; - case M5PM1_I2C_DRIVER_BUS: - if (_i2c_device) { - i2c_bus_device_delete(&_i2c_device); - _i2c_device = nullptr; - } - break; + // NOTE: M5PM1_I2C_DRIVER_BUS case removed (i2c_bus support removed) default: break; @@ -582,109 +576,8 @@ m5pm1_err_t M5PM1::begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t spe return M5PM1_OK; } -m5pm1_err_t M5PM1::begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed) -{ - _addr = addr; - _busExternal = true; - _i2cDriverType = M5PM1_I2C_DRIVER_BUS; - _i2c_bus = bus; - - // 步骤1:校验用户频率并记录 - // Step 1: Validate requested speed and store it - if (!_isValidI2cFrequency(speed)) { - M5PM1_LOG_W(TAG, "Invalid I2C frequency: %lu Hz. PM1 only supports 100KHz or 400KHz. Falling back to 100KHz.", - (unsigned long)speed); - _requestedSpeed = M5PM1_I2C_FREQ_100K; - } else { - _requestedSpeed = speed; - } - - // 步骤2:以100KHz创建设备句柄 - // Step 2: Create device handle at 100KHz - _i2c_device = i2c_bus_device_create(bus, addr, M5PM1_I2C_FREQ_100K); - if (_i2c_device == nullptr) { - M5PM1_LOG_E(TAG, "Failed to create I2C device"); - return M5PM1_ERR_I2C_CONFIG; - } - - // 尝试唤醒设备 - // Try to wake up the device - M5PM1_I2C_SEND_WAKE(_i2c_device, M5PM1_REG_HW_REV); - M5PM1_DELAY_MS(10); - - // 步骤3:验证设备通信(失败则等待800ms重试一次) - // Step 3: Verify device communication (retry once after 800ms if failed) - if (!_initDevice()) { - M5PM1_LOG_W(TAG, "Device init failed, retrying after 800ms..."); - M5PM1_DELAY_MS(800); - // 重试前再次发送唤醒信号 - // Send wake signal again before retry - M5PM1_I2C_SEND_WAKE(_i2c_device, M5PM1_REG_HW_REV); - M5PM1_DELAY_MS(10); - if (!_initDevice()) { - // 100K 再次失败,尝试 400K - // 100K failed again, try 400K - M5PM1_LOG_W(TAG, "Device init failed at 100KHz (retry), trying 400KHz..."); - - // 删除当前100K设备句柄 - // Remove current 100K device handle - i2c_bus_device_delete(&_i2c_device); - _i2c_device = nullptr; - - // 以400K重新创建设备句柄 - // Recreate device handle at 400K - _i2c_device = i2c_bus_device_create(bus, addr, M5PM1_I2C_FREQ_400K); - if (_i2c_device == nullptr) { - M5PM1_LOG_E(TAG, "Failed to create I2C device at 400KHz"); - return M5PM1_ERR_I2C_CONFIG; - } - - // 尝试唤醒设备 - // Try to wake up the device - M5PM1_I2C_SEND_WAKE(_i2c_device, M5PM1_REG_HW_REV); - M5PM1_DELAY_MS(10); - - if (!_initDevice()) { - M5PM1_LOG_E(TAG, "Failed at 100KHz (twice) and 400KHz"); - i2c_bus_device_delete(&_i2c_device); - _i2c_device = nullptr; - return M5PM1_ERR_I2C_COMM; - } - } - } - _initialized = true; - - // 步骤4:配置设备I2C参数(关闭睡眠 + 目标频率) - // Step 4: Configure device I2C (sleep off + target speed) - m5pm1_i2c_speed_t targetSpeed = - (_requestedSpeed == M5PM1_I2C_FREQ_400K) ? M5PM1_I2C_SPEED_400K : M5PM1_I2C_SPEED_100K; - if (setI2cConfig(0, targetSpeed) != M5PM1_OK) { - M5PM1_LOG_W(TAG, "Failed to set I2C config"); - } - - // 步骤5:重建设备句柄到目标频率 - // Step 5: Recreate device handle at target speed - i2c_bus_device_delete(&_i2c_device); - _i2c_device = nullptr; - - _i2c_device = i2c_bus_device_create(bus, addr, _requestedSpeed); - if (_i2c_device == nullptr) { - M5PM1_LOG_E(TAG, "Failed to switch device to %lu Hz", (unsigned long)_requestedSpeed); - _initialized = false; - return M5PM1_ERR_I2C_CONFIG; - } - - // 步骤6:刷新快照并完成初始化 - // Step 6: Refresh snapshot and finish initialization - _lastCommTime = M5PM1_GET_TIME_MS(); - if (!_snapshotAll()) { - _clearAll(); - } - - _initialized = true; - M5PM1_LOG_I(TAG, "M5PM1 initialized at address 0x%02X (I2C: %lu Hz)", _addr, (unsigned long)_requestedSpeed); - return M5PM1_OK; -} +// NOTE: begin(i2c_bus_handle_t) implementation removed to avoid conflict with M5GFX's i2c_master driver +// Use begin(i2c_master_bus_handle_t) instead #endif // ARDUINO @@ -854,9 +747,9 @@ bool M5PM1::_snapshotAw8737a() // 解析寄存器值(不含 REFRESH 位) // Parse register value (without REFRESH bit) - _aw8737aRegValue = regValue & 0x7F; - _aw8737aPin = (m5pm1_gpio_num_t)(regValue & 0x1F); - _aw8737aPulseNum = (m5pm1_aw8737a_pulse_t)((regValue >> 5) & 0x03); + _aw8737aRegValue = regValue & 0x7F; + _aw8737aPin = (m5pm1_gpio_num_t)(regValue & 0x1F); + _aw8737aPulseNum = (m5pm1_aw8737a_pulse_t)((regValue >> 5) & 0x03); _aw8737aStateValid = true; return true; @@ -1244,9 +1137,6 @@ bool M5PM1::_writeReg(uint8_t reg, uint8_t value) case M5PM1_I2C_DRIVER_MASTER: success = M5PM1_I2C_MASTER_WRITE_BYTE(_i2c_master_dev, reg, value) == ESP_OK; break; - case M5PM1_I2C_DRIVER_BUS: - success = M5PM1_I2C_WRITE_BYTE(_i2c_device, reg, value) == ESP_OK; - break; default: success = false; break; @@ -1276,9 +1166,6 @@ bool M5PM1::_writeReg16(uint8_t reg, uint16_t value) case M5PM1_I2C_DRIVER_MASTER: success = M5PM1_I2C_MASTER_WRITE_REG16(_i2c_master_dev, reg, value) == ESP_OK; break; - case M5PM1_I2C_DRIVER_BUS: - success = M5PM1_I2C_WRITE_REG16(_i2c_device, reg, value) == ESP_OK; - break; default: success = false; break; @@ -1308,9 +1195,6 @@ bool M5PM1::_readReg(uint8_t reg, uint8_t* value) case M5PM1_I2C_DRIVER_MASTER: success = M5PM1_I2C_MASTER_READ_BYTE(_i2c_master_dev, reg, value) == ESP_OK; break; - case M5PM1_I2C_DRIVER_BUS: - success = M5PM1_I2C_READ_BYTE(_i2c_device, reg, value) == ESP_OK; - break; default: success = false; break; @@ -1340,9 +1224,6 @@ bool M5PM1::_readReg16(uint8_t reg, uint16_t* value) case M5PM1_I2C_DRIVER_MASTER: success = M5PM1_I2C_MASTER_READ_REG16(_i2c_master_dev, reg, value) == ESP_OK; break; - case M5PM1_I2C_DRIVER_BUS: - success = M5PM1_I2C_READ_REG16(_i2c_device, reg, value) == ESP_OK; - break; default: success = false; break; @@ -1372,9 +1253,6 @@ bool M5PM1::_writeBytes(uint8_t reg, const uint8_t* data, uint8_t len) case M5PM1_I2C_DRIVER_MASTER: success = M5PM1_I2C_MASTER_WRITE_BYTES(_i2c_master_dev, reg, len, data) == ESP_OK; break; - case M5PM1_I2C_DRIVER_BUS: - success = M5PM1_I2C_WRITE_BYTES(_i2c_device, reg, len, data) == ESP_OK; - break; default: success = false; break; @@ -1404,9 +1282,6 @@ bool M5PM1::_readBytes(uint8_t reg, uint8_t* data, uint8_t len) case M5PM1_I2C_DRIVER_MASTER: success = M5PM1_I2C_MASTER_READ_BYTES(_i2c_master_dev, reg, len, data) == ESP_OK; break; - case M5PM1_I2C_DRIVER_BUS: - success = M5PM1_I2C_READ_BYTES(_i2c_device, reg, len, data) == ESP_OK; - break; default: success = false; break; @@ -4060,8 +3935,8 @@ m5pm1_err_t M5PM1::refreshAw8737aPulse() // 输出详细日志 // Output detailed log const char* driveStr = (_pinStatus[_aw8737aPin].drive == M5PM1_GPIO_DRIVE_PUSHPULL) ? "PUSH-PULL" : "OPEN-DRAIN"; - M5PM1_LOG_I(TAG, "AW8737A pulse refresh: pin=%d, pulseNum=%d, mode=OUTPUT, drive=%s", - _aw8737aPin, _aw8737aPulseNum, driveStr); + M5PM1_LOG_I(TAG, "AW8737A pulse refresh: pin=%d, pulseNum=%d, mode=OUTPUT, drive=%s", _aw8737aPin, _aw8737aPulseNum, + driveStr); M5PM1_DELAY_MS(20); _autoSnapshotUpdate(M5PM1_SNAPSHOT_DOMAIN_AW8737A); @@ -4387,22 +4262,7 @@ m5pm1_err_t M5PM1::switchI2cSpeed(m5pm1_i2c_speed_t speed) } break; } - case M5PM1_I2C_DRIVER_BUS: - if (_i2c_device != nullptr) { - ret = i2c_bus_device_delete(&_i2c_device); - if (ret != ESP_OK) { - M5PM1_LOG_E(TAG, "Failed to delete I2C device: %s", esp_err_to_name(ret)); - return M5PM1_ERR_I2C_CONFIG; - } - _i2c_device = i2c_bus_device_create(_i2c_bus, _addr, targetFreq); - if (_i2c_device == nullptr) { - M5PM1_LOG_E(TAG, "Failed to create I2C device at %lu Hz", (unsigned long)targetFreq); - _i2c_device = i2c_bus_device_create(_i2c_bus, _addr, originalFreq); - _writeReg(M5PM1_REG_I2C_CFG, originalCfg); - return M5PM1_ERR_I2C_CONFIG; - } - } - break; + // NOTE: M5PM1_I2C_DRIVER_BUS case removed (i2c_bus support removed) default: M5PM1_LOG_E(TAG, "Unknown I2C driver type"); return M5PM1_ERR_INTERNAL; @@ -4435,12 +4295,7 @@ m5pm1_err_t M5PM1::switchI2cSpeed(m5pm1_i2c_speed_t speed) } break; } - case M5PM1_I2C_DRIVER_BUS: - if (_i2c_device != nullptr) { - i2c_bus_device_delete(&_i2c_device); - _i2c_device = i2c_bus_device_create(_i2c_bus, _addr, originalFreq); - } - break; + // NOTE: M5PM1_I2C_DRIVER_BUS case removed default: break; } @@ -4487,8 +4342,7 @@ m5pm1_err_t M5PM1::sendWakeSignal() case M5PM1_I2C_DRIVER_SELF_CREATED: case M5PM1_I2C_DRIVER_MASTER: return M5PM1_I2C_MASTER_SEND_WAKE(_i2c_master_bus, _addr) == ESP_OK ? M5PM1_OK : M5PM1_ERR_I2C_COMM; - case M5PM1_I2C_DRIVER_BUS: - return M5PM1_I2C_SEND_WAKE(_i2c_device, M5PM1_REG_HW_REV) == ESP_OK ? M5PM1_OK : M5PM1_ERR_I2C_COMM; + // NOTE: M5PM1_I2C_DRIVER_BUS case removed (i2c_bus support removed) default: return M5PM1_ERR_INTERNAL; } @@ -4524,7 +4378,7 @@ m5pm1_err_t M5PM1::updateSnapshot() m5pm1_snapshot_verify_t M5PM1::verifySnapshot() { m5pm1_snapshot_verify_t result = {0}; - result.consistent = true; + result.consistent = true; if (!_initialized) { result.consistent = false; diff --git a/src/M5PM1.h b/src/M5PM1.h index dc65622..893d4df 100644 --- a/src/M5PM1.h +++ b/src/M5PM1.h @@ -265,11 +265,11 @@ typedef enum { 0x3B // R/W 定时器计数字节3(bit 6:0,最大31位) / Timer counter byte 3 (bit 6:0, max 31 bits) // 定时器,单位秒,最大214748364秒(约6.8年) / Timer in seconds, max 214748364 (~6.8 years) #define M5PM1_REG_TIM_CFG \ - 0x3C // R/W 定时器配置 / Timer configuration - // [7-4] 保留 / Reserved - // [3] ARM - 自动重装: 0=单次 1=自动重装 / ARM - auto reload: 0=one-shot, 1=auto - // [2:0] ACTION - 超时动作: 000=停止 001=标志 010=复位 011=开机 100=关机 - // ACTION: 000=stop, 001=flag, 010=reboot, 011=power on, 100=shutdown + 0x3C // R/W 定时器配置 / Timer configuration + // [7-4] 保留 / Reserved + // [3] ARM - 自动重装: 0=单次 1=自动重装 / ARM - auto reload: 0=one-shot, 1=auto + // [2:0] ACTION - 超时动作: 000=停止 001=标志 010=复位 011=开机 100=关机 + // ACTION: 000=stop, 001=flag, 010=reboot, 011=power on, 100=shutdown #define M5PM1_REG_TIM_KEY 0x3D // W 写入0xA5重载定时器 / Write 0xA5 to reload timer // ---- 中断寄存器 ---- @@ -1060,16 +1060,7 @@ class M5PM1 { */ m5pm1_err_t begin(i2c_master_bus_handle_t bus, uint8_t addr = M5PM1_DEFAULT_ADDR, uint32_t speed = M5PM1_I2C_FREQ_100K); - - /** - * @brief Initialize with existing i2c_bus handle (esp-idf-lib) - * @param bus Existing i2c_bus_handle_t - * @param addr I2C address (default 0x6E) - * @param speed I2C speed in Hz - * @return 成功返回 M5PM1_OK,否则返回错误码 - * Return M5PM1_OK on success, error code otherwise - */ - m5pm1_err_t begin(i2c_bus_handle_t bus, uint8_t addr = M5PM1_DEFAULT_ADDR, uint32_t speed = M5PM1_I2C_FREQ_100K); + // NOTE: i2c_bus_handle_t overload removed to avoid conflict with M5GFX's i2c_master driver #endif /** @@ -2436,7 +2427,8 @@ class M5PM1 { * @return 成功返回 M5PM1_OK,否则返回错误码 * Return M5PM1_OK on success, error code otherwise * @note 如果引脚不是输出模式,会自动配置为推挽输出;如果已是输出模式则保持原有配置 - * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current config + * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current + * config * @note 如果使用开漏输出,需要外部上拉电阻 * If using open-drain output, external pull-up is required * @note 当 refresh=NOW 时,执行后会有 20ms 延迟 @@ -2452,7 +2444,8 @@ class M5PM1 { * @note 需要先调用 setAw8737aPulse 并设置 refresh=WAIT,然后调用此函数触发 * Call setAw8737aPulse with refresh=WAIT first, then call this to trigger * @note 如果引脚不是输出模式,会自动配置为推挽输出;如果已是输出模式则保持原有配置 - * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current config + * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current + * config * @note 如果使用开漏输出,需要外部上拉电阻 * If using open-drain output, external pull-up is required * @note 执行后会有 20ms 延迟 @@ -2472,7 +2465,8 @@ class M5PM1 { * @return 成功返回 M5PM1_OK,否则返回错误码 * Return M5PM1_OK on success, error code otherwise * @note 如果引脚不是输出模式,会自动配置为推挽输出;如果已是输出模式则保持原有配置 - * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current config + * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current + * config * @note 如果使用开漏输出,需要外部上拉电阻 * If using open-drain output, external pull-up is required * @note 当 refresh=NOW 时,执行后会有 20ms 延迟 @@ -2489,7 +2483,8 @@ class M5PM1 { * @note 需要先调用 setAw8737aMode 并设置 refresh=WAIT,然后调用此函数触发 * Call setAw8737aMode with refresh=WAIT first, then call this to trigger * @note 如果引脚不是输出模式,会自动配置为推挽输出;如果已是输出模式则保持原有配置 - * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current config + * If pin is not output mode, it will be auto-configured as push-pull output; if already output, keeps current + * config * @note 如果使用开漏输出,需要外部上拉电阻 * If using open-drain output, external pull-up is required * @note 执行后会有 20ms 延迟 @@ -2841,16 +2836,16 @@ class M5PM1 { // AW8737A 配置状态缓存 // AW8737A configuration state cache - bool _aw8737aConfigured; // 是否已调用 setAw8737aPulse 配置 - // Whether setAw8737aPulse has been called - m5pm1_gpio_num_t _aw8737aPin; // 配置的引脚号 - // Configured pin number - m5pm1_aw8737a_pulse_t _aw8737aPulseNum; // 配置的脉冲数 - // Configured pulse count - uint8_t _aw8737aRegValue; // 缓存的寄存器值(不含 REFRESH 位) - // Cached register value (without REFRESH bit) - bool _aw8737aStateValid; // 缓存有效性标志 - // Cache validity flag + bool _aw8737aConfigured; // 是否已调用 setAw8737aPulse 配置 + // Whether setAw8737aPulse has been called + m5pm1_gpio_num_t _aw8737aPin; // 配置的引脚号 + // Configured pin number + m5pm1_aw8737a_pulse_t _aw8737aPulseNum; // 配置的脉冲数 + // Configured pulse count + uint8_t _aw8737aRegValue; // 缓存的寄存器值(不含 REFRESH 位) + // Cached register value (without REFRESH bit) + bool _aw8737aStateValid; // 缓存有效性标志 + // Cache validity flag // Pin 状态缓存 // Pin status cache @@ -2866,12 +2861,11 @@ class M5PM1 { // I2C driver type selection m5pm1_i2c_driver_t _i2cDriverType; - // I2C 句柄 - // I2C handles + // I2C 句柄 (only i2c_master driver supported) + // I2C handles (only i2c_master driver supported) i2c_master_bus_handle_t _i2c_master_bus; i2c_master_dev_handle_t _i2c_master_dev; - i2c_bus_handle_t _i2c_bus; - i2c_bus_device_handle_t _i2c_device; + // NOTE: i2c_bus handles removed to avoid conflict with M5GFX // I2C 管理标志 // I2C management flags diff --git a/src/M5PM1_i2c_compat.h b/src/M5PM1_i2c_compat.h index 62857be..86d2f5e 100644 --- a/src/M5PM1_i2c_compat.h +++ b/src/M5PM1_i2c_compat.h @@ -2,6 +2,8 @@ * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD * * SPDX-License-Identifier: MIT + * + * Modified by LOVECHEN: Removed i2c_bus dependency, only use ESP-IDF native i2c_master driver */ #ifndef __M5PM1_I2C_COMPAT_H__ @@ -124,8 +126,7 @@ static inline void M5PM1_I2C_SEND_WAKE(TwoWire *wire, uint8_t addr) #else // ESP-IDF #include -#include // ESP-IDF native i2c_master driver -#include // esp-idf-lib i2c_bus component +#include // ESP-IDF native i2c_master driver ONLY #ifdef __cplusplus extern "C" { @@ -134,74 +135,15 @@ extern "C" { // ============================ // I2C 驱动类型选择 // I2C Driver Type Selection +// NOTE: i2c_bus support removed to avoid driver conflict with M5GFX // ============================ typedef enum { M5PM1_I2C_DRIVER_NONE = 0, // 未初始化 / Not initialized M5PM1_I2C_DRIVER_SELF_CREATED, // 使用 i2c_port_t 自创建 / Self-created using i2c_port_t - M5PM1_I2C_DRIVER_MASTER, // ESP-IDF 原生 i2c_master 驱动 / ESP-IDF native i2c_master driver - M5PM1_I2C_DRIVER_BUS // esp-idf-lib i2c_bus 组件 / esp-idf-lib i2c_bus component + M5PM1_I2C_DRIVER_MASTER // ESP-IDF 原生 i2c_master 驱动 / ESP-IDF native i2c_master driver + // M5PM1_I2C_DRIVER_BUS removed - causes conflict with M5GFX's i2c_master driver } m5pm1_i2c_driver_t; -// ============================ -// ESP-IDF I2C 函数 (i2c_bus) -// ESP-IDF I2C Functions (i2c_bus) -// ============================ - -#ifndef M5PM1_I2C_READ_BYTE -static inline esp_err_t M5PM1_I2C_READ_BYTE(i2c_bus_device_handle_t dev, uint8_t reg, uint8_t *data) -{ - return i2c_bus_read_byte(dev, reg, data); -} -#endif - -#ifndef M5PM1_I2C_READ_BYTES -static inline esp_err_t M5PM1_I2C_READ_BYTES(i2c_bus_device_handle_t dev, uint8_t start_reg, size_t len, uint8_t *data) -{ - return i2c_bus_read_bytes(dev, start_reg, len, data); -} -#endif - -#ifndef M5PM1_I2C_READ_REG16 -static inline esp_err_t M5PM1_I2C_READ_REG16(i2c_bus_device_handle_t dev, uint8_t reg, uint16_t *data) -{ - uint8_t buf[2]; - esp_err_t ret = i2c_bus_read_bytes(dev, reg, 2, buf); - if (ret == ESP_OK) { - // 小端模式:低字节在前 - // Little-endian: low byte first - *data = (uint16_t)buf[0] | ((uint16_t)buf[1] << 8); - } - return ret; -} -#endif - -#ifndef M5PM1_I2C_WRITE_BYTE -static inline esp_err_t M5PM1_I2C_WRITE_BYTE(i2c_bus_device_handle_t dev, uint8_t reg, uint8_t data) -{ - return i2c_bus_write_byte(dev, reg, data); -} -#endif - -#ifndef M5PM1_I2C_WRITE_BYTES -static inline esp_err_t M5PM1_I2C_WRITE_BYTES(i2c_bus_device_handle_t dev, uint8_t start_reg, size_t len, - const uint8_t *data) -{ - return i2c_bus_write_bytes(dev, start_reg, len, (uint8_t *)data); -} -#endif - -#ifndef M5PM1_I2C_WRITE_REG16 -static inline esp_err_t M5PM1_I2C_WRITE_REG16(i2c_bus_device_handle_t dev, uint8_t reg, uint16_t data) -{ - uint8_t buf[2]; - // 小端模式:低字节在前 - // Little-endian: low byte first - buf[0] = (uint8_t)(data & 0xFF); - buf[1] = (uint8_t)((data >> 8) & 0xFF); - return i2c_bus_write_bytes(dev, reg, 2, buf); -} -#endif - // ============================ // ESP-IDF I2C 函数 (i2c_master - 原生驱动) // ESP-IDF I2C Functions (i2c_master - native driver) @@ -273,17 +215,6 @@ static inline esp_err_t M5PM1_I2C_MASTER_WRITE_REG16(i2c_master_dev_handle_t dev } #endif -// 使用i2c_bus的PM1睡眠模式唤醒信号 -// Wake signal for PM1 sleep mode using i2c_bus -#ifndef M5PM1_I2C_SEND_WAKE -static inline esp_err_t M5PM1_I2C_SEND_WAKE(i2c_bus_device_handle_t dev, uint8_t reg) -{ - // Read any register to generate I2C start signal for wake - uint8_t dummy; - return i2c_bus_read_byte(dev, reg, &dummy); -} -#endif - // 使用i2c_master的PM1睡眠模式唤醒信号 // Wake signal for PM1 sleep mode using i2c_master #ifndef M5PM1_I2C_MASTER_SEND_WAKE