From 50c189ed0aa532ab88b842cdcc3622ad25fb5e32 Mon Sep 17 00:00:00 2001 From: Niel Nielsen Date: Sat, 12 Sep 2026 10:35:00 +0200 Subject: [PATCH] Change RgbLedSet to return bool for success status Modify RgbLedSet to return success status and handle cold boot NAK. Signed-off-by: Niel Nielsen --- common_arm/rgb/rgb_hw_at32.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common_arm/rgb/rgb_hw_at32.c b/common_arm/rgb/rgb_hw_at32.c index e851d6b72..30e9e6739 100644 --- a/common_arm/rgb/rgb_hw_at32.c +++ b/common_arm/rgb/rgb_hw_at32.c @@ -12,11 +12,17 @@ #define RGB_REG_INDEX 0x02 #define RGB_REG_DATA 0x03 -void RgbLedSet(uint8_t r, uint8_t g, uint8_t b) { +bool RgbLedSet(uint8_t r, uint8_t g, uint8_t b) { uint8_t rgb[3] = { r, g, b }; StartTicks(); I2C_init(true); - I2C_WriteByte(0, RGB_REG_INDEX, RGB_I2C_ADDR); // address LED index 0 - I2C_WriteByte(1, RGB_REG_COUNT, RGB_I2C_ADDR); // 1 LED on the string - I2C_BufferWrite(rgb, sizeof(rgb), RGB_REG_DATA, RGB_I2C_ADDR); + // Report NAK: on a cold boot the controller may still be powering up when the + // first write fires. The caller uses this to retry instead of latching a failed + // write (which previously left the LED dark until the next state change - i.e. + // "worked once after flash, dark on every cold boot" on battery). + bool ok = true; + ok &= I2C_WriteByte(0, RGB_REG_INDEX, RGB_I2C_ADDR); // address LED index 0 + ok &= I2C_WriteByte(1, RGB_REG_COUNT, RGB_I2C_ADDR); // 1 LED on the string + ok &= I2C_BufferWrite(rgb, sizeof(rgb), RGB_REG_DATA, RGB_I2C_ADDR); + return ok; }