Skip to content

Commit a718e63

Browse files
committed
framework_lib: Add support for RgbKbdSetColor HC
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent f31af68 commit a718e63

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub enum EcCommands {
4646
RebootEc = 0x00D2,
4747
/// Get information about PD controller power
4848
UsbPdPowerInfo = 0x0103,
49+
RgbKbdSetColor = 0x013A,
50+
RgbKbd = 0x013B,
4951

5052
// Framework specific commands
5153
/// Configure the behavior of the flash notify

framework_lib/src/chromium_ec/commands.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,37 @@ impl EcRequest<EcResponseUsbPdPowerInfo> for EcRequestUsbPdPowerInfo {
518518
}
519519
}
520520

521+
// TODO: Actually 128, but if we go above ~80 EC returns REQUEST_TRUNCATED
522+
// At least when I use the portio driver
523+
pub const EC_RGBKBD_MAX_KEY_COUNT: usize = 64;
524+
525+
#[repr(C, packed)]
526+
#[derive(Default, Clone, Copy, Debug)]
527+
pub struct RgbS {
528+
pub r: u8,
529+
pub g: u8,
530+
pub b: u8,
531+
}
532+
533+
#[repr(C, packed)]
534+
pub struct EcRequestRgbKbdSetColor {
535+
/// Specifies the starting key ID whose color is being changed
536+
pub start_key: u8,
537+
/// Specifies # of elements in color
538+
pub length: u8,
539+
/// RGB color data array of length up to MAX_KEY_COUNT
540+
pub color: [RgbS; EC_RGBKBD_MAX_KEY_COUNT],
541+
}
542+
543+
#[repr(C, packed)]
544+
pub struct EcResponseRgbKbdSetColor {}
545+
546+
impl EcRequest<EcResponseRgbKbdSetColor> for EcRequestRgbKbdSetColor {
547+
fn command_id() -> EcCommands {
548+
EcCommands::RgbKbdSetColor
549+
}
550+
}
551+
521552
// --- Framework Specific commands ---
522553

523554
#[repr(C, packed)]

framework_lib/src/chromium_ec/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,21 @@ impl CrosEc {
921921
let res = request.send_command(self)?;
922922
Ok(res.val == 1)
923923
}
924+
925+
pub fn rgbkbd_set_color(&self, start_key: u8, colors: Vec<RgbS>) -> EcResult<()> {
926+
let mut request = EcRequestRgbKbdSetColor {
927+
start_key,
928+
length: colors.len() as u8,
929+
color: [(); EC_RGBKBD_MAX_KEY_COUNT].map(|()| Default::default()),
930+
};
931+
932+
for (i, color) in colors.iter().enumerate() {
933+
request.color[i] = *color;
934+
}
935+
936+
let _res = request.send_command(self)?;
937+
Ok(())
938+
}
924939
}
925940

926941
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]

0 commit comments

Comments
 (0)