Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,26 +723,51 @@ impl CrosEc {
Ok(InputDeckStatus::from(status))
}

fn has_pwmtype_kblight(&self) -> bool {
// Returns EcError::Response(EcResponseStatus::InvalidParameter) on some early systems
EcRequestPwmGetDuty {
pwm_type: PwmType::KbLight as u8,
index: 0,
}
.send_command(self)
.is_ok()
}
Comment on lines +726 to +734

/// Change the keyboard baclight brightness
///
/// # Arguments
/// * `percent` - An integer from 0 to 100. 0 being off, 100 being full brightness
pub fn set_keyboard_backlight(&self, percent: u8) {
debug_assert!(percent <= 100);
let res = EcRequestPwmSetDuty {
duty: percent as u16 * (PWM_MAX_DUTY / 100),
pwm_type: PwmType::KbLight as u8,
index: 0,
let res = if self.has_pwmtype_kblight() {
EcRequestPwmSetDuty {
duty: percent as u16 * (PWM_MAX_DUTY / 100),
pwm_type: PwmType::KbLight as u8,
index: 0,
}
} else {
EcRequestPwmSetDuty {
duty: percent as u16 * (PWM_MAX_DUTY / 100),
Comment on lines +742 to +750
pwm_type: PwmType::Generic as u8,
index: 1,
}
Comment on lines +749 to +753
}
.send_command(self);
Comment on lines 741 to 755
debug_assert!(res.is_ok());
}

/// Check the current brightness of the keyboard backlight
pub fn get_keyboard_backlight(&self) -> EcResult<u8> {
let kblight = EcRequestPwmGetDuty {
pwm_type: PwmType::KbLight as u8,
index: 0,
let kblight = if self.has_pwmtype_kblight() {
EcRequestPwmGetDuty {
pwm_type: PwmType::KbLight as u8,
index: 0,
}
} else {
EcRequestPwmGetDuty {
pwm_type: PwmType::Generic as u8,
index: 1,
}
}
.send_command(self)?;

Expand Down
Loading