@@ -770,22 +770,49 @@ 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+ if let Err ( EcError :: Response ( EcResponseStatus :: InvalidParameter ) ) = res {
785+ let res = EcRequestPwmSetDuty {
786+ duty,
787+ pwm_type : PwmType :: Generic as u8 ,
788+ index : 1 ,
789+ }
790+ . send_command ( self ) ;
791+ debug_assert ! ( res. is_ok( ) ) ;
792+ return ;
793+ }
779794 debug_assert ! ( res. is_ok( ) ) ;
780795 }
781796
782797 /// Check the current brightness of the keyboard backlight
783798 pub fn get_keyboard_backlight ( & self ) -> EcResult < u8 > {
784- let kblight = EcRequestPwmGetDuty {
799+ let res = EcRequestPwmGetDuty {
785800 pwm_type : PwmType :: KbLight as u8 ,
786801 index : 0 ,
787802 }
788- . send_command ( self ) ?;
803+ . send_command ( self ) ;
804+
805+ // Early systems (hx20/hx30) don't enable CONFIG_PWM_KBLIGHT in their EC firmware;
806+ // keyboard backlight is at generic PWM channel index 1.
807+ let kblight = if let Err ( EcError :: Response ( EcResponseStatus :: InvalidParameter ) ) = res {
808+ EcRequestPwmGetDuty {
809+ pwm_type : PwmType :: Generic as u8 ,
810+ index : 1 ,
811+ }
812+ . send_command ( self ) ?
813+ } else {
814+ res?
815+ } ;
789816
790817 Ok ( ( kblight. duty / ( PWM_MAX_DUTY / 100 ) ) as u8 )
791818 }
0 commit comments