Skip to content

Commit 42d7721

Browse files
committed
framework_lib: Add support for RgbKbdSetColor HC
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent a656e19 commit 42d7721

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
@@ -893,6 +893,21 @@ impl CrosEc {
893893
let res = request.send_command(self)?;
894894
Ok(res.val == 1)
895895
}
896+
897+
pub fn rgbkbd_set_color(&self, start_key: u8, colors: Vec<RgbS>) -> EcResult<()> {
898+
let mut request = EcRequestRgbKbdSetColor {
899+
start_key,
900+
length: colors.len() as u8,
901+
color: [(); EC_RGBKBD_MAX_KEY_COUNT].map(|()| Default::default()),
902+
};
903+
904+
for (i, color) in colors.iter().enumerate() {
905+
request.color[i] = *color;
906+
}
907+
908+
let _res = request.send_command(self)?;
909+
Ok(())
910+
}
896911
}
897912

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

0 commit comments

Comments
 (0)