Merge pull request #3619 from nieldk/master

pm5: fix antenna RGB staying dark on battery cold boot
This commit is contained in:
Iceman authored and GitHub committed 2026-09-12 16:01:11 +07:00
commit 780081a2e9
3 files changed
+20 -10

No files matched your search

+9 -5
View File
@@ -67,12 +67,16 @@ void rgb_indicator_update(void) {
if (on_battery == last_state) {
return; // edge-triggered: only write RGB when the state changes
}
last_state = on_battery;
if (on_battery) {
RgbLedSet(0, 8, 0); // dim green: alive, on battery
} else {
RgbLedSet(0, 0, 0); // on USB: off (cable already signals power)
// Commit last_state only if the controller actually ACKed. On a cold boot the
// I2C RGB controller can still be powering up when the first write fires; if we
// latched last_state regardless, a NAK here would leave the LED dark until the
// next state change (which never comes on battery). Retrying next cycle costs
// one I2C poke and self-heals once the controller is ready.
bool ok = on_battery ? RgbLedSet(0, 8, 0) // dim green: alive, on battery
: RgbLedSet(0, 0, 0); // on USB: off (cable already signals power)
if (ok) {
last_state = on_battery;
}
}
+1 -1
View File
@@ -10,6 +10,6 @@
// driven by an I2C RGB controller). Other platforms don't build this module, so
// callers must guard usage accordingly (e.g. the CMD_PM5_RGB_SET handler).
//-----------------------------------------------------------------------------
void RgbLedSet(uint8_t r, uint8_t g, uint8_t b);
bool RgbLedSet(uint8_t r, uint8_t g, uint8_t b);
#endif // RGB_APIS_H_
+10 -4
View File
@@ -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;
}