This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit baea3523742bdfc0123d6246fe6bb24d4c771623
Author: Jorge Guzman <[email protected]>
AuthorDate: Thu Jul 30 20:29:09 2026 -0300

    boards/xtensa/esp32s3/esp32s3-m5-cardputer: report the cursor keys as 
keycodes
    
    The Fn cursor cluster was reported as ordinary key presses carrying 0x80
    to 0x83, chosen to sit above the printable range so that an application
    could tell them apart from characters.  That is the collision this work
    exists to remove:  a key that produces no character is a special key, and
    the event type is what says so.
    
    Report them as KEYBOARD_SPECPRESS carrying KEYCODE_UP and friends, which
    is what every other keyboard does and what the applications now expect.
    
    The character tables are untouched, so the layout and the shift map behave
    exactly as before.  Only the four Fn cursor keys change.
    
    Not tested on hardware:  the board was not available.  It builds, and the
    change is confined to the two lines that pick the event type.
    
    Signed-off-by: Jorge Guzman <[email protected]>
---
 .../esp32s3/esp32s3-m5-cardputer/src/esp32s3_kbd.c | 47 ++++++++++++----------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/boards/xtensa/esp32s3/esp32s3-m5-cardputer/src/esp32s3_kbd.c 
b/boards/xtensa/esp32s3/esp32s3-m5-cardputer/src/esp32s3_kbd.c
index c4dfef46b13..1cb550263e8 100644
--- a/boards/xtensa/esp32s3/esp32s3-m5-cardputer/src/esp32s3_kbd.c
+++ b/boards/xtensa/esp32s3/esp32s3-m5-cardputer/src/esp32s3_kbd.c
@@ -36,6 +36,7 @@
 #include <nuttx/clock.h>
 #include <nuttx/wqueue.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/input/kbd_codec.h>
 #include <nuttx/input/keyboard.h>
 
 #include <arch/board/board.h>
@@ -79,16 +80,6 @@
 #define KBD_FN_Y        2
 #define KBD_FN_X        0
 
-/* Codes emitted for the Fn + navigation cluster (cursor keys).  They are
- * placed above the printable ASCII range so applications reading /dev/kbd0
- * can tell them apart from regular characters.
- */
-
-#define KBD_CODE_UP     0x80
-#define KBD_CODE_DOWN   0x81
-#define KBD_CODE_LEFT   0x82
-#define KBD_CODE_RIGHT  0x83
-
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -102,6 +93,7 @@ struct esp32s3_kbd_s
 
   bool pressed[KBD_NROW_PHYS][KBD_NCOL_PHYS];
   uint8_t code[KBD_NROW_PHYS][KBD_NCOL_PHYS];
+  bool special[KBD_NROW_PHYS][KBD_NCOL_PHYS];
 };
 
 /****************************************************************************
@@ -174,35 +166,42 @@ static void esp32s3_kbd_select(uint8_t row)
  ****************************************************************************/
 
 static uint8_t esp32s3_kbd_resolve(int y, int x, bool shift, bool ctrl,
-                                   bool fn)
+                                   bool fn, FAR bool *special)
 {
   char ch;
 
-  /* FN layer: the ; . , / cluster becomes the cursor (arrow) keys, reported
-   * as out-of-band codes so applications can act on them (e.g. scrolling).
+  *special = false;
+
+  /* FN layer: the ; . , / cluster becomes the cursor (arrow) keys.  They
+   * produce no character, so they are reported as special keys carrying a
+   * keycode:  the caller turns *special into a SPEC event type.
    */
 
   if (fn)
     {
+      *special = true;
+
       if (y == 2 && x == 11)
         {
-          return KBD_CODE_UP;                        /* Fn + ';' */
+          return KEYCODE_UP;                         /* Fn + ';' */
         }
 
       if (y == 3 && x == 11)
         {
-          return KBD_CODE_DOWN;                      /* Fn + '.' */
+          return KEYCODE_DOWN;                       /* Fn + '.' */
         }
 
       if (y == 3 && x == 10)
         {
-          return KBD_CODE_LEFT;                      /* Fn + ',' */
+          return KEYCODE_LEFT;                       /* Fn + ',' */
         }
 
       if (y == 3 && x == 12)
         {
-          return KBD_CODE_RIGHT;                     /* Fn + '/' */
+          return KEYCODE_RIGHT;                      /* Fn + '/' */
         }
+
+      *special = false;
     }
 
   ch = shift ? g_shift[y][x] : g_normal[y][x];
@@ -289,21 +288,27 @@ static void esp32s3_kbd_worker(FAR void *arg)
 
           if (scan[y][x])
             {
-              uint8_t code = esp32s3_kbd_resolve(y, x, shift, ctrl, fn);
+              bool special;
+              uint8_t code = esp32s3_kbd_resolve(y, x, shift, ctrl, fn,
+                                                 &special);
 #ifdef CONFIG_ESP32S3_M5_CARDPUTER_KBD_DEBUG
               syslog(LOG_INFO, "kbd: press y=%d x=%d code=0x%02x '%c'\n",
                      y, x, code, (code >= 0x20 && code < 0x7f) ? code : '.');
 #endif
               if (code != 0)
                 {
-                  priv->code[y][x] = code;
-                  keyboard_event(&priv->lower, code, KEYBOARD_PRESS);
+                  priv->code[y][x]    = code;
+                  priv->special[y][x] = special;
+                  keyboard_event(&priv->lower, code,
+                                 special ? KEYBOARD_SPECPRESS :
+                                           KEYBOARD_PRESS);
                 }
             }
           else if (priv->code[y][x] != 0)
             {
               keyboard_event(&priv->lower, priv->code[y][x],
-                             KEYBOARD_RELEASE);
+                             priv->special[y][x] ? KEYBOARD_SPECREL :
+                                                   KEYBOARD_RELEASE);
               priv->code[y][x] = 0;
             }
         }

Reply via email to