From 3ddcf740c692e91ede4f89ba18a3b6e8a43219c4 Mon Sep 17 00:00:00 2001 From: Julian Arevalo Date: Mon, 9 Dec 2024 13:19:39 +0100 Subject: [PATCH 1/2] Fix nano backspace key behavior Stay on backspace key until there is a PIN entry to delete --- lib_nbgl/src/nbgl_layout_keypad_nanos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_nbgl/src/nbgl_layout_keypad_nanos.c b/lib_nbgl/src/nbgl_layout_keypad_nanos.c index 877a00b3f..ecc680b88 100644 --- a/lib_nbgl/src/nbgl_layout_keypad_nanos.c +++ b/lib_nbgl/src/nbgl_layout_keypad_nanos.c @@ -136,8 +136,8 @@ int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout, // if validate key is enabled and was not, select it directly keypad->selectedKey = 11; } - else { - // otherwise let the draw function pick a new selected + // Shuffle if selected key was not backspace or if the last pin entry has been deleted + else if ((keypad->selectedKey != 0) || (keypad->enableBackspace && !enableBackspace)) { keypad->selectedKey = 0xFF; } keypad->enableValidate = enableValidate; From 823c5ca75aeb06209886392b9b6562d788d46c42 Mon Sep 17 00:00:00 2001 From: Julian Arevalo Date: Mon, 9 Dec 2024 13:22:26 +0100 Subject: [PATCH 2/2] Fix nano keypad shuffling Only shuffle digits, backspace and validate keys must not be selected --- lib_nbgl/src/nbgl_obj_keypad_nanos.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/lib_nbgl/src/nbgl_obj_keypad_nanos.c b/lib_nbgl/src/nbgl_obj_keypad_nanos.c index 75dd229d8..20f98414e 100644 --- a/lib_nbgl/src/nbgl_obj_keypad_nanos.c +++ b/lib_nbgl/src/nbgl_obj_keypad_nanos.c @@ -165,24 +165,8 @@ static void keypadInitSelected(nbgl_keypad_t *keypad) keypad->selectedKey = 1 + INIT_DIGIT_VALUE; } else { - uint8_t nbChoices = 10; - uint8_t random; - if (keypad->enableBackspace) { - nbChoices++; - } - if (keypad->enableValidate) { - nbChoices++; - } - random = cx_rng_u32_range(0, nbChoices); - if (random < 10) { - keypad->selectedKey = 1 + random; - } - else if (random == 10) { - keypad->selectedKey = 0; - } - else if (random == 11) { - keypad->selectedKey = 11; - } + // Exclude backspace and validate keys ([0,11]), shuffle only digits + keypad->selectedKey = cx_rng_u32_range(1, 11); } }