@@ -770,22 +770,51 @@ 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 ) ;
774+
773775 let res = EcRequestPwmSetDuty {
774- duty : percent as u16 * ( PWM_MAX_DUTY / 100 ) ,
776+ duty,
775777 pwm_type : PwmType :: KbLight as u8 ,
776778 index : 0 ,
777779 }
778780 . send_command ( self ) ;
781+
782+ // Early systems (hx20/hx30) don't enable CONFIG_PWM_KBLIGHT in their EC firmware;
783+ // keyboard backlight is at generic PWM channel index 1.
784+ let res = match res {
785+ Err ( EcError :: Response ( EcResponseStatus :: InvalidParameter ) ) => {
786+ EcRequestPwmSetDuty {
787+ duty,
788+ pwm_type : PwmType :: Generic as u8 ,
789+ index : 1 ,
790+ }
791+ . send_command ( self )
792+ }
793+ other => other,
794+ } ;
779795 debug_assert ! ( res. is_ok( ) ) ;
780796 }
781797
782798 /// Check the current brightness of the keyboard backlight
783799 pub fn get_keyboard_backlight ( & self ) -> EcResult < u8 > {
784- let kblight = EcRequestPwmGetDuty {
800+ let res = EcRequestPwmGetDuty {
785801 pwm_type : PwmType :: KbLight as u8 ,
786802 index : 0 ,
787803 }
788- . send_command ( self ) ?;
804+ . send_command ( self ) ;
805+
806+ // Early systems (hx20/hx30) don't enable CONFIG_PWM_KBLIGHT in their EC firmware;
807+ // keyboard backlight is at generic PWM channel index 1.
808+ let kblight = match res {
809+ Err ( EcError :: Response ( EcResponseStatus :: InvalidParameter ) ) => {
810+ EcRequestPwmGetDuty {
811+ pwm_type : PwmType :: Generic as u8 ,
812+ index : 1 ,
813+ }
814+ . send_command ( self ) ?
815+ }
816+ other => other?,
817+ } ;
789818
790819 Ok ( ( kblight. duty / ( PWM_MAX_DUTY / 100 ) ) as u8 )
791820 }
0 commit comments