File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
framework_lib/src/chromium_ec Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,16 @@ impl EcRequest<()> for EcRequestPwmSetFanDutyV1 {
246246
247247pub const PWM_MAX_DUTY : u16 = 0xFFFF ;
248248
249+ pub fn percent_to_duty ( percent : u8 ) -> u16 {
250+ let duty = percent as u32 * PWM_MAX_DUTY as u32 ;
251+ ( duty / 100 ) as u16
252+ }
253+
254+ pub fn duty_to_percent ( duty : u16 ) -> u8 {
255+ let percent = duty as u32 * 100 ;
256+ ( percent / PWM_MAX_DUTY as u32 ) as u8
257+ }
258+
249259#[ repr( C , packed) ]
250260pub struct EcRequestPwmSetDuty {
251261 /// Duty cycle, min 0, max 0xFFFF
Original file line number Diff line number Diff line change @@ -770,7 +770,7 @@ impl CrosEc {
770770 /// * `percent` - An integer from 0 to 100. 0 being off, 100 being full brightness
771771 pub fn set_keyboard_backlight ( & self , percent : u8 ) {
772772 debug_assert ! ( percent <= 100 ) ;
773- let duty = percent as u16 * ( PWM_MAX_DUTY / 100 ) ;
773+ let duty = percent_to_duty ( percent ) ;
774774
775775 let res = EcRequestPwmSetDuty {
776776 duty,
@@ -816,7 +816,7 @@ impl CrosEc {
816816 other => other?,
817817 } ;
818818
819- Ok ( ( kblight. duty / ( PWM_MAX_DUTY / 100 ) ) as u8 )
819+ Ok ( duty_to_percent ( kblight. duty ) )
820820 }
821821
822822 pub fn ps2_emulation_enable ( & self , enable : bool ) -> EcResult < ( ) > {
You can’t perform that action at this time.
0 commit comments