mirror of
https://github.com/m5stack/M5IOE1.git
synced 2026-05-20 11:49:24 -07:00
1.Added M5IOE1_I2C_WRITE_DELAY_US and M5IOE1_I2C_READ_DELAY_US macros (default 500μs) in I2C operations
2.Implemented clearLedRam() API to zero all 64 bytes of LED RAM registers 3.update 1.0.6
This commit is contained in:
+1
-1
@@ -13,4 +13,4 @@ dependencies:
|
||||
espressif/i2c_bus:
|
||||
version: "^1.0.0"
|
||||
public: true
|
||||
version: 1.0.5
|
||||
version: 1.0.6
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "M5IOE1",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "Library for M5Stack M5IOE1",
|
||||
"keywords": [
|
||||
"m5stack",
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=M5IOE1
|
||||
version=1.0.5
|
||||
version=1.0.6
|
||||
author=M5Stack
|
||||
maintainer=M5Stack
|
||||
sentence=Library for M5Stack M5IOE1
|
||||
|
||||
+33
-3
@@ -2383,6 +2383,36 @@ m5ioe1_err_t M5IOE1::disableLeds()
|
||||
return M5IOE1_OK;
|
||||
}
|
||||
|
||||
m5ioe1_err_t M5IOE1::clearLedRam()
|
||||
{
|
||||
if (!_initialized) {
|
||||
M5IOE1_LOG_E(TAG, "Device not initialized");
|
||||
return M5IOE1_ERR_NOT_INIT;
|
||||
}
|
||||
|
||||
// 清除所有 LED RAM (0x30 - 0x6F, 共 64 字节,支持 32 个 LED)
|
||||
// Clear all LED RAM (0x30 - 0x6F, 64 bytes total, supports 32 LEDs)
|
||||
uint8_t zeroData[64] = {0};
|
||||
|
||||
M5IOE1_LOG_I(TAG, "Clearing LED RAM...");
|
||||
|
||||
// 分块写入,每次写入 8 字节,避免 I2C 缓冲区溢出
|
||||
// Write in chunks of 8 bytes to avoid I2C buffer overflow
|
||||
for (uint8_t offset = 0; offset < 64; offset += 8) {
|
||||
uint8_t regAddr = M5IOE1_REG_LED_RAM_START + offset;
|
||||
if (!_writeBytes(regAddr, zeroData, 8)) {
|
||||
M5IOE1_LOG_E(TAG, "Failed to clear LED RAM at offset %d", offset);
|
||||
return M5IOE1_ERR_I2C_COMM;
|
||||
}
|
||||
// 每次写入后增加延迟,确保设备有时间处理
|
||||
// Add delay after each write to ensure device has time to process
|
||||
M5IOE1_DELAY_MS(2);
|
||||
}
|
||||
|
||||
M5IOE1_LOG_I(TAG, "LED RAM cleared successfully");
|
||||
return M5IOE1_OK;
|
||||
}
|
||||
|
||||
m5ioe1_err_t M5IOE1::setLeds(const m5ioe1_rgb_t* colors, uint8_t count, uint8_t arraySize, bool autoRefresh)
|
||||
{
|
||||
// 步骤 1: 参数验证
|
||||
@@ -3300,9 +3330,9 @@ m5ioe1_err_t M5IOE1::updateSnapshot()
|
||||
{
|
||||
if (!_initialized) return M5IOE1_ERR_NOT_INIT;
|
||||
|
||||
bool gpio = _snapshotPinStates();
|
||||
bool pwm = _snapshotPwmStates();
|
||||
bool adc = _snapshotAdcState();
|
||||
bool gpio = _snapshotPinStates();
|
||||
bool pwm = _snapshotPwmStates();
|
||||
bool adc = _snapshotAdcState();
|
||||
bool aw8737a = _snapshotAw8737a();
|
||||
|
||||
return (gpio && pwm && adc && aw8737a) ? M5IOE1_OK : M5IOE1_ERR_I2C_COMM;
|
||||
|
||||
@@ -1087,6 +1087,15 @@ public:
|
||||
*/
|
||||
m5ioe1_err_t disableLeds();
|
||||
|
||||
/**
|
||||
* @brief 清除 LED RAM 寄存器(将所有 LED 数据设置为 0)
|
||||
* Clear LED RAM registers (set all LED data to 0)
|
||||
* @return M5IOE1_OK if successful, error code otherwise
|
||||
* @note 此函数会清除所有 32 个 LED 的颜色数据,建议在 begin() 后调用
|
||||
* This function clears color data for all 32 LEDs, recommended to call after begin()
|
||||
*/
|
||||
m5ioe1_err_t clearLedRam();
|
||||
|
||||
// ========================
|
||||
// AW8737A 脉冲功能
|
||||
// AW8737A Pulse Functions
|
||||
|
||||
@@ -15,6 +15,18 @@
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
// ============================
|
||||
// I2C 延迟配置 (可调整以解决总线冲突)
|
||||
// I2C Delay Configuration (adjustable to resolve bus conflicts)
|
||||
// ============================
|
||||
#ifndef M5IOE1_I2C_WRITE_DELAY_US
|
||||
#define M5IOE1_I2C_WRITE_DELAY_US 500 // 写操作后延迟(微秒) / Delay after write (microseconds)
|
||||
#endif
|
||||
|
||||
#ifndef M5IOE1_I2C_READ_DELAY_US
|
||||
#define M5IOE1_I2C_READ_DELAY_US 500 // 读操作前延迟(微秒) / Delay before read (microseconds)
|
||||
#endif
|
||||
|
||||
// ============================
|
||||
// Arduino I2C 功能
|
||||
// Arduino I2C Functions
|
||||
@@ -28,6 +40,7 @@ static inline bool M5IOE1_I2C_READ_BYTE(TwoWire *wire, uint8_t addr, uint8_t reg
|
||||
if (wire->endTransmission(false) != 0) {
|
||||
return false;
|
||||
}
|
||||
delayMicroseconds(M5IOE1_I2C_READ_DELAY_US); // 增加延迟避免 I2C 总线冲突
|
||||
if (wire->requestFrom(addr, (uint8_t)1) != 1) {
|
||||
return false;
|
||||
}
|
||||
@@ -44,6 +57,7 @@ static inline bool M5IOE1_I2C_READ_BYTES(TwoWire *wire, uint8_t addr, uint8_t st
|
||||
if (wire->endTransmission(false) != 0) {
|
||||
return false;
|
||||
}
|
||||
delayMicroseconds(M5IOE1_I2C_READ_DELAY_US); // 增加延迟避免 I2C 总线冲突
|
||||
if (wire->requestFrom(addr, (uint8_t)len) != len) {
|
||||
return false;
|
||||
}
|
||||
@@ -77,6 +91,7 @@ static inline bool M5IOE1_I2C_WRITE_BYTE(TwoWire *wire, uint8_t addr, uint8_t re
|
||||
if (wire->endTransmission() != 0) {
|
||||
return false;
|
||||
}
|
||||
delayMicroseconds(M5IOE1_I2C_WRITE_DELAY_US); // 增加延迟给设备处理时间
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -93,6 +108,7 @@ static inline bool M5IOE1_I2C_WRITE_BYTES(TwoWire *wire, uint8_t addr, uint8_t s
|
||||
if (wire->endTransmission() != 0) {
|
||||
return false;
|
||||
}
|
||||
delayMicroseconds(M5IOE1_I2C_WRITE_DELAY_US); // 增加延迟给设备处理时间
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user