@@ -235,6 +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_F1F12 ;
239+ static uint8_t keep_fn_key_special ;
240+ static uint8_t keep_fn_key_functional ;
238241
239242void fnkey_shutdown (void ) {
240243 uint8_t current_kb = 0 ;
@@ -263,13 +266,34 @@ void fnkey_startup(void) {
263266}
264267DECLARE_HOOK (HOOK_CHIPSET_STARTUP , fnkey_startup , HOOK_PRIO_DEFAULT );
265268
269+ static void fn_keep_check_F1F12 (int8_t pressed )
270+ {
271+ if (pressed )
272+ keep_fn_key_F1F12 = 1 ;
273+ else
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 ;
283+ }
284+
266285int hotkey_F1_F12 (uint16_t * key_code , uint16_t lock , int8_t pressed )
267286{
268287 const uint16_t prss_key = * key_code ;
269288
270- if (!(Fn_key & FN_LOCKED ) && lock & FN_PRESSED )
289+ if (!(Fn_key & FN_LOCKED ) &&
290+ (lock & FN_PRESSED ) &&
291+ !keep_fn_key_F1F12 )
271292 return EC_SUCCESS ;
272- else if (Fn_key & FN_LOCKED && !(Fn_key & FN_PRESSED ))
293+ else if (Fn_key & FN_LOCKED &&
294+ !(lock & FN_PRESSED ))
295+ return EC_SUCCESS ;
296+ else if (!pressed && !keep_fn_key_F1F12 )
273297 return EC_SUCCESS ;
274298
275299 switch (prss_key ) {
@@ -278,33 +302,28 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
278302 break ;
279303 case SCANCODE_F2 : /* VOLUME_DOWN */
280304 * key_code = SCANCODE_VOLUME_DOWN ;
281-
282305 break ;
283306 case SCANCODE_F3 : /* VOLUME_UP */
284307 * key_code = SCANCODE_VOLUME_UP ;
285-
286308 break ;
287309 case SCANCODE_F4 : /* PREVIOUS_TRACK */
288310 * key_code = SCANCODE_PREV_TRACK ;
289-
290311 break ;
291312 case SCANCODE_F5 : /* PLAY_PAUSE */
292313 * key_code = 0xe034 ;
293-
294314 break ;
295315 case SCANCODE_F6 : /* NEXT_TRACK */
296316 * key_code = SCANCODE_NEXT_TRACK ;
297-
298317 break ;
299318 case SCANCODE_F7 : /* TODO: DIM_SCREEN */
300319 update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_DN , pressed );
320+ fn_keep_check_F1F12 (pressed );
301321 return EC_ERROR_UNIMPLEMENTED ;
302-
303322 break ;
304323 case SCANCODE_F8 : /* TODO: BRIGHTEN_SCREEN */
305324 update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_UP , pressed );
325+ fn_keep_check_F1F12 (pressed );
306326 return EC_ERROR_UNIMPLEMENTED ;
307-
308327 break ;
309328 case SCANCODE_F9 : /* EXTERNAL_DISPLAY */
310329 if (pressed ) {
@@ -314,12 +333,13 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
314333 simulate_keyboard (SCANCODE_P , 0 );
315334 simulate_keyboard (SCANCODE_LEFT_WIN , 0 );
316335 }
336+ fn_keep_check_F1F12 (pressed );
317337 return EC_ERROR_UNIMPLEMENTED ;
318338 break ;
319339 case SCANCODE_F10 : /* FLIGHT_MODE */
320340 update_hid_key (HID_KEY_AIRPLANE_MODE , pressed );
341+ fn_keep_check_F1F12 (pressed );
321342 return EC_ERROR_UNIMPLEMENTED ;
322-
323343 break ;
324344 case SCANCODE_F11 :
325345 /*
@@ -333,14 +353,16 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
333353 case SCANCODE_F12 : /* TODO: FRAMEWORK */
334354 /* Media Select scan code */
335355 * key_code = 0xE050 ;
336-
337356 break ;
357+ default :
358+ return EC_SUCCESS ;
338359 }
360+ fn_keep_check_F1F12 (pressed );
339361 return EC_SUCCESS ;
340362}
341363
342364
343- int hotkey_special_key (uint16_t * key_code )
365+ int hotkey_special_key (uint16_t * key_code , int8_t pressed )
344366{
345367 const uint16_t prss_key = * key_code ;
346368
@@ -366,29 +388,36 @@ int hotkey_special_key(uint16_t *key_code)
366388 case SCANCODE_DOWN : /* PAGE_DOWN */
367389 * key_code = 0xe07a ;
368390 break ;
391+ default :
392+ return EC_SUCCESS ;
369393 }
394+ fn_keep_check_special (pressed );
370395 return EC_SUCCESS ;
371396}
372397
373- int functional_hotkey (uint16_t * key_code )
398+ int functional_hotkey (uint16_t * key_code , int8_t pressed )
374399{
375400 const uint16_t prss_key = * key_code ;
376401 uint8_t bl_brightness = 0 ;
377402
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+
378409 switch (prss_key ) {
379410 case SCANCODE_ESC : /* TODO: FUNCTION_LOCK */
380411 if (Fn_key & FN_LOCKED )
381412 Fn_key &= ~FN_LOCKED ;
382413 else
383414 Fn_key |= FN_LOCKED ;
384- return EC_ERROR_UNIMPLEMENTED ;
385415 break ;
386416 case SCANCODE_B :
387417 /* BREAK_KEY */
388418 simulate_keyboard (0xe07e , 1 );
389419 simulate_keyboard (0xe0 , 1 );
390420 simulate_keyboard (0x7e , 0 );
391- return EC_ERROR_UNIMPLEMENTED ;
392421 break ;
393422 case SCANCODE_P :
394423 /* PAUSE_KEY */
@@ -397,7 +426,6 @@ int functional_hotkey(uint16_t *key_code)
397426 simulate_keyboard (0xe1 , 1 );
398427 simulate_keyboard (0x14 , 0 );
399428 simulate_keyboard (0x77 , 0 );
400- return EC_ERROR_UNIMPLEMENTED ;
401429 break ;
402430 case SCANCODE_SPACE : /* TODO: TOGGLE_KEYBOARD_BACKLIGHT */
403431 bl_brightness = kblight_get ();
@@ -420,10 +448,12 @@ int functional_hotkey(uint16_t *key_code)
420448 }
421449 kblight_set (bl_brightness );
422450 /* we dont want to pass the space key event to the OS */
423- return EC_ERROR_UNKNOWN ;
424451 break ;
452+ default :
453+ return EC_SUCCESS ;
425454 }
426- return EC_SUCCESS ;
455+ keep_fn_key_functional = 1 ;
456+ return EC_ERROR_UNIMPLEMENTED ;
427457}
428458
429459enum ec_error_list keyboard_scancode_callback (uint16_t * make_code ,
@@ -456,21 +486,23 @@ enum ec_error_list keyboard_scancode_callback(uint16_t *make_code,
456486 /*
457487 * If the function key is not held then
458488 * we pass through all events without modifying them
489+ * but if last time have press FN still need keep that
459490 */
460- if (!Fn_key )
491+ if (!Fn_key && ! keep_fn_key_special && ! keep_fn_key_functional )
461492 return EC_SUCCESS ;
462493
463494 if (Fn_key & FN_LOCKED && !(Fn_key & FN_PRESSED ))
464495 return EC_SUCCESS ;
465496
466- r = hotkey_special_key (make_code );
497+ r = hotkey_special_key (make_code , pressed );
467498 if (r != EC_SUCCESS )
468499 return r ;
469500
470- if (!pressed || pressed_key != * make_code )
501+ if ((!pressed && !keep_fn_key_functional ) ||
502+ pressed_key != * make_code )
471503 return EC_SUCCESS ;
472504
473- r = functional_hotkey (make_code );
505+ r = functional_hotkey (make_code , pressed );
474506 if (r != EC_SUCCESS )
475507 return r ;
476508
0 commit comments