@@ -235,7 +235,9 @@ void board_kblight_init(void)
235235#define FN_PRESSED BIT(0)
236236#define FN_LOCKED BIT(1)
237237static uint8_t Fn_key ;
238- static uint8_t keep_fn_key_code ;
238+ static uint8_t keep_fn_key_F1F12 ;
239+ static uint8_t keep_fn_key_special ;
240+ static uint8_t keep_fn_key_functional ;
239241
240242void fnkey_shutdown (void ) {
241243 uint8_t current_kb = 0 ;
@@ -264,12 +266,20 @@ void fnkey_startup(void) {
264266}
265267DECLARE_HOOK (HOOK_CHIPSET_STARTUP , fnkey_startup , HOOK_PRIO_DEFAULT );
266268
267- static void fn_keep_check (int8_t pressed )
269+ static void fn_keep_check_F1F12 (int8_t pressed )
268270{
269271 if (pressed )
270- keep_fn_key_code = 1 ;
272+ keep_fn_key_F1F12 = 1 ;
271273 else
272- keep_fn_key_code = 0 ;
274+ keep_fn_key_F1F12 = 0 ;
275+ }
276+
277+ static void fn_keep_check_special (int8_t pressed )
278+ {
279+ if (pressed )
280+ keep_fn_key_special = 1 ;
281+ else
282+ keep_fn_key_special = 0 ;
273283}
274284
275285int hotkey_F1_F12 (uint16_t * key_code , uint16_t lock , int8_t pressed )
@@ -278,12 +288,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
278288
279289 if (!(Fn_key & FN_LOCKED ) &&
280290 (lock & FN_PRESSED ) &&
281- !keep_fn_key_code )
291+ !keep_fn_key_F1F12 )
282292 return EC_SUCCESS ;
283293 else if (Fn_key & FN_LOCKED &&
284294 !(lock & FN_PRESSED ))
285295 return EC_SUCCESS ;
286- else if (!pressed && !keep_fn_key_code )
296+ else if (!pressed && !keep_fn_key_F1F12 )
287297 return EC_SUCCESS ;
288298
289299 switch (prss_key ) {
@@ -307,10 +317,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
307317 break ;
308318 case SCANCODE_F7 : /* TODO: DIM_SCREEN */
309319 update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_DN , pressed );
320+ fn_keep_check_F1F12 (pressed );
310321 return EC_ERROR_UNIMPLEMENTED ;
311322 break ;
312323 case SCANCODE_F8 : /* TODO: BRIGHTEN_SCREEN */
313324 update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_UP , pressed );
325+ fn_keep_check_F1F12 (pressed );
314326 return EC_ERROR_UNIMPLEMENTED ;
315327 break ;
316328 case SCANCODE_F9 : /* EXTERNAL_DISPLAY */
@@ -321,10 +333,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
321333 simulate_keyboard (SCANCODE_P , 0 );
322334 simulate_keyboard (SCANCODE_LEFT_WIN , 0 );
323335 }
336+ fn_keep_check_F1F12 (pressed );
324337 return EC_ERROR_UNIMPLEMENTED ;
325338 break ;
326339 case SCANCODE_F10 : /* FLIGHT_MODE */
327340 update_hid_key (HID_KEY_AIRPLANE_MODE , pressed );
341+ fn_keep_check_F1F12 (pressed );
328342 return EC_ERROR_UNIMPLEMENTED ;
329343 break ;
330344 case SCANCODE_F11 :
@@ -343,12 +357,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
343357 default :
344358 return EC_SUCCESS ;
345359 }
346- fn_keep_check (pressed );
360+ fn_keep_check_F1F12 (pressed );
347361 return EC_SUCCESS ;
348362}
349363
350364
351- int hotkey_special_key (uint16_t * key_code )
365+ int hotkey_special_key (uint16_t * key_code , int8_t pressed )
352366{
353367 const uint16_t prss_key = * key_code ;
354368
@@ -374,29 +388,36 @@ int hotkey_special_key(uint16_t *key_code)
374388 case SCANCODE_DOWN : /* PAGE_DOWN */
375389 * key_code = 0xe07a ;
376390 break ;
391+ default :
392+ return EC_SUCCESS ;
377393 }
394+ fn_keep_check_special (pressed );
378395 return EC_SUCCESS ;
379396}
380397
381- int functional_hotkey (uint16_t * key_code )
398+ int functional_hotkey (uint16_t * key_code , int8_t pressed )
382399{
383400 const uint16_t prss_key = * key_code ;
384401 uint8_t bl_brightness = 0 ;
385402
403+ /* don't send break key if last time doesn't send make key */
404+ if (!pressed && keep_fn_key_functional ) {
405+ keep_fn_key_functional = 0 ;
406+ return EC_ERROR_UNKNOWN ;
407+ }
408+
386409 switch (prss_key ) {
387410 case SCANCODE_ESC : /* TODO: FUNCTION_LOCK */
388411 if (Fn_key & FN_LOCKED )
389412 Fn_key &= ~FN_LOCKED ;
390413 else
391414 Fn_key |= FN_LOCKED ;
392- return EC_ERROR_UNIMPLEMENTED ;
393415 break ;
394416 case SCANCODE_B :
395417 /* BREAK_KEY */
396418 simulate_keyboard (0xe07e , 1 );
397419 simulate_keyboard (0xe0 , 1 );
398420 simulate_keyboard (0x7e , 0 );
399- return EC_ERROR_UNIMPLEMENTED ;
400421 break ;
401422 case SCANCODE_P :
402423 /* PAUSE_KEY */
@@ -405,7 +426,6 @@ int functional_hotkey(uint16_t *key_code)
405426 simulate_keyboard (0xe1 , 1 );
406427 simulate_keyboard (0x14 , 0 );
407428 simulate_keyboard (0x77 , 0 );
408- return EC_ERROR_UNIMPLEMENTED ;
409429 break ;
410430 case SCANCODE_SPACE : /* TODO: TOGGLE_KEYBOARD_BACKLIGHT */
411431 bl_brightness = kblight_get ();
@@ -428,10 +448,12 @@ int functional_hotkey(uint16_t *key_code)
428448 }
429449 kblight_set (bl_brightness );
430450 /* we dont want to pass the space key event to the OS */
431- return EC_ERROR_UNKNOWN ;
432451 break ;
452+ default :
453+ return EC_SUCCESS ;
433454 }
434- return EC_SUCCESS ;
455+ keep_fn_key_functional = 1 ;
456+ return EC_ERROR_UNIMPLEMENTED ;
435457}
436458
437459enum ec_error_list keyboard_scancode_callback (uint16_t * make_code ,
@@ -464,21 +486,23 @@ enum ec_error_list keyboard_scancode_callback(uint16_t *make_code,
464486 /*
465487 * If the function key is not held then
466488 * we pass through all events without modifying them
489+ * but if last time have press FN still need keep that
467490 */
468- if (!Fn_key )
491+ if (!Fn_key && ! keep_fn_key_special && ! keep_fn_key_functional )
469492 return EC_SUCCESS ;
470493
471494 if (Fn_key & FN_LOCKED && !(Fn_key & FN_PRESSED ))
472495 return EC_SUCCESS ;
473496
474- r = hotkey_special_key (make_code );
497+ r = hotkey_special_key (make_code , pressed );
475498 if (r != EC_SUCCESS )
476499 return r ;
477500
478- if (!pressed || pressed_key != * make_code )
501+ if ((!pressed && !keep_fn_key_functional ) ||
502+ pressed_key != * make_code )
479503 return EC_SUCCESS ;
480504
481- r = functional_hotkey (make_code );
505+ r = functional_hotkey (make_code , pressed );
482506 if (r != EC_SUCCESS )
483507 return r ;
484508
0 commit comments