ppisa commented on issue #19527: URL: https://github.com/apache/nuttx/issues/19527#issuecomment-5110885030
The situation does not look so simple after NuttX code observation, uint32_t is used in most cases for keycodes, there are cases where 8-bits are used only: - `kbd_decode` in [nuttx/libs/libc/misc/lib_kbddecode.c](https://github.com/apache/nuttx/blob/master/libs/libc/misc/lib_kbddecode.c#L124) returns key code in the location referenced by argument `uint8_t *pch`. So there is no space for 0xff800 based keys. In this specific case ASCII code and special key code is distinguished by the function return value `KBD_PRESS`/`KBD_SPECPRESS` and `KBD_RELEASE`/`KBD_SPECREL`. The keycode is stored as uint8_t in the buffer and its special category is saved by preceedingl ASCII ESC character. - `kbd_specpress` and `kbd_specrel` in [nuttxr/libs/libc/misc/lib_kbdencode.c](https://github.com/apache/nuttx/blob/master/libs/libc/misc/lib_kbdencode.c#L108) - `lvglterm_input_poll` in [apps/examples/lvglterm/lvglterm_kbd.c](https://github.com/apache/nuttx-apps/blob/master/examples/lvglterm/lvglterm_kbd.c#L205) uses `kbd_decode` and only `uint8_t`. - above functions are used even in [nuttx/drivers/usbhost/usbhost_hidkbd.c[(https://github.com/apache/nuttx/blob/master/drivers/usbhost/usbhost_hidkbd.c#L1023) where are even used 8-bits mapping tables only to NuttX keycodes which are initialized to `KEYCODE_`xxx, so if they are out of uint8_t range, code fails. It seems that main problem is that Microwidows NuttX driver in [microwindows/src/drivers/kbd_nuttx_event.c](https://github.com/ghaerr/microwindows/blob/master/src/drivers/kbd_nuttx_event.c#L79) use only `event.type == KEYBOARD_PRESS` but in this case there should be no translation. The code should be translated only for `event.type == KEYBOARD_SPECPRESS || event.type == KEYBOARD_KBD_SPECREL` else regular ASCII code obtained from `event.code` should be returned. The condition for press/release should look as ``` int press = (event.type == KEYBOARD_PRESS) || (event.type == KEYBOARD_SPECPRESS); ``` Please, @Acfboy, try to correct this and it should work without code shift. But I expect that there are more locations where meaning is mixed even in NuttX drivers as shows initial check. - `void sim_kbdevent(uint32_t key, bool is_press)` in [nuttx/arch/sim/src/sim/sim_keyboard.c](https://github.com/apache/nuttx/blob/master/arch/sim/src/sim/sim_keyboard.c#L246) is broken, as it translates X11 keys only to `KEYBOARD_PRESS` and `KBD_RELEASE` so losing information about key category. Use of `KBD_SPECPRESS` is almost musing in the NuttX source. Matrix keyborad limits support to ASCI keys only in the mapping tables [nuttx/drivers/input/kmatrix.c](https://github.com/apache/nuttx/blob/master/drivers/input/kmatrix.c#L219) in the current state. But after review it seems that switch to single `uint32_t` value in NuttX which would encode ASCII codes as well special keys is much more intrusive than expected. So I suggest to correct Microwindows NuttX drivers and NuttX included code to be aligned with initial NuttX design choice to have overlapping ranges distinguished by event type. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
