Skip to content

Commit d7dbbcb

Browse files
committed
Add --rgbkbd commandline
Works like this: ``` > cargo build && sudo ./target/debug/framework_tool --rgbkbd 0 16711680 65280 255 ``` Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 42d7721 commit d7dbbcb

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

framework_lib/src/commandline/clap_std.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! as well as on the UEFI shell tool.
44
use clap::Parser;
55

6+
use crate::chromium_ec::commands::EC_RGBKBD_MAX_KEY_COUNT;
67
use crate::chromium_ec::CrosEcDriverType;
78
use crate::commandline::{
89
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, RebootEcArg,
@@ -145,6 +146,13 @@ struct ClapCli {
145146
#[arg(long)]
146147
kblight: Option<Option<u8>>,
147148

149+
/// Set the color of <key> to <RGB>. Multiple colors for adjacent keys can be set at once.
150+
/// <key> <RGB> [<RGB> ...]
151+
/// Example: 0 0xFF000 0x00FF00 0x0000FF
152+
#[clap(num_args = 2..EC_RGBKBD_MAX_KEY_COUNT)]
153+
#[arg(long)]
154+
rgbkbd: Vec<u64>,
155+
148156
/// Set tablet mode override
149157
#[clap(value_enum)]
150158
#[arg(long)]
@@ -269,6 +277,7 @@ pub fn parse(args: &[String]) -> Cli {
269277
get_gpio: args.get_gpio,
270278
fp_brightness: args.fp_brightness,
271279
kblight: args.kblight,
280+
rgbkbd: args.rgbkbd,
272281
tablet_mode: args.tablet_mode,
273282
console: args.console,
274283
reboot_ec: args.reboot_ec,

framework_lib/src/commandline/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::chromium_ec;
3535
use crate::chromium_ec::commands::DeckStateMode;
3636
use crate::chromium_ec::commands::FpLedBrightnessLevel;
3737
use crate::chromium_ec::commands::RebootEcCmd;
38+
use crate::chromium_ec::commands::RgbS;
3839
use crate::chromium_ec::commands::TabletModeOverride;
3940
use crate::chromium_ec::EcResponseStatus;
4041
use crate::chromium_ec::{print_err, EcFlashType};
@@ -161,6 +162,7 @@ pub struct Cli {
161162
pub get_gpio: Option<String>,
162163
pub fp_brightness: Option<Option<FpBrightnessArg>>,
163164
pub kblight: Option<Option<u8>>,
165+
pub rgbkbd: Vec<u64>,
164166
pub tablet_mode: Option<TabletModeArg>,
165167
pub console: Option<ConsoleArg>,
166168
pub reboot_ec: Option<RebootEcArg>,
@@ -746,6 +748,21 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
746748
} else if let Some(Some(kblight)) = args.kblight {
747749
assert!(kblight <= 100);
748750
ec.set_keyboard_backlight(kblight);
751+
} else if !args.rgbkbd.is_empty() {
752+
if args.rgbkbd.len() < 2 {
753+
println!(
754+
"Must provide at least 2 arguments. Provided only: {}",
755+
args.rgbkbd.len()
756+
);
757+
} else {
758+
let start_key = args.rgbkbd[0] as u8;
759+
let colors = args.rgbkbd[1..].iter().map(|color| RgbS {
760+
r: ((color & 0x00FF0000) >> 16) as u8,
761+
g: ((color & 0x0000FF00) >> 8) as u8,
762+
b: (color & 0x000000FF) as u8,
763+
});
764+
ec.rgbkbd_set_color(start_key, colors.collect()).unwrap();
765+
}
749766
} else if let Some(None) = args.kblight {
750767
print!("Keyboard backlight: ");
751768
if let Some(percentage) = print_err(ec.get_keyboard_backlight()) {

framework_lib/src/commandline/uefi.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub fn parse(args: &[String]) -> Cli {
8686
get_gpio: None,
8787
fp_brightness: None,
8888
kblight: None,
89+
rgbkbd: Vec<64>,
8990
tablet_mode: None,
9091
console: None,
9192
reboot_ec: None,
@@ -215,6 +216,18 @@ pub fn parse(args: &[String]) -> Cli {
215216
Some(None)
216217
};
217218
found_an_option = true;
219+
} else if arg == "--rgbkbd" {
220+
cli.rgbkbd = if args.len() > i + 2 {
221+
let colors = Vec::<u64>::new();
222+
for color_i in i + 1..args.len() {
223+
// TODO: Fail parsing instead of unwrap()
224+
colors.push(args[color_i].parse::<u64>().unwrap());
225+
}
226+
colors
227+
} else {
228+
println!("--rgbkbd requires at least arguments, the start key and an RGB value");
229+
Vec::new()
230+
}
218231
} else if arg == "--tablet-mode" {
219232
cli.tablet_mode = if args.len() > i + 1 {
220233
let tablet_mode_arg = &args[i + 1];

0 commit comments

Comments
 (0)