Translate fx-9860G Slim keyboard scancodes to standard scancodes

The Slim has two keys that the standard 9860G doesn't: HELP and LIGHT.
Those are mapped to virtual scancodes, resulting in virtual keycodes.
This commit is contained in:
calamari 2022-09-25 01:34:40 -07:00
parent a4adc5e1bd
commit 98fea4f2ec
5 changed files with 58 additions and 7 deletions

View file

@ -135,9 +135,9 @@ typedef struct {
is useful for demo/replays that input events without the physical keyboard,
and a couple of corner uses like control over USB.
The keyboard device has built-in event transformations, which modifty the
The keyboard device has built-in event transformations, which modify the
stream of events by adding information, combining modifiers, and removing
undesired events. Because the event transformation reky on the current state
undesired events. Because the event transformation rely on the current state
of the keyboard, they must be run by the driver whenever events are read, so
they are tied to the device.
@ -173,7 +173,7 @@ typedef struct {
/* Candidate key for repeats (or 0 if no key is candidate yet) */
int rep_key;
/* Number of repeats alreay sent */
/* Number of repeats already sent */
int rep_count;
/* Time since key was first pressed (us) */
int rep_time;
@ -181,7 +181,7 @@ typedef struct {
int rep_delay;
/* Latest state of keys we are aware of. At every processing step, the
different between this and the fresh information is queued and this
difference between this and the fresh information is queued and this
is updated. state_now is identical to the real state obtained from
the device unless earlier events failed to be queued, in which case
a difference is maintained so they will be reconsidered later. */

View file

@ -207,7 +207,7 @@ enum {
/* Enable modifiers keys */
GETKEY_MOD_SHIFT = 0x01,
GETKEY_MOD_ALPHA = 0x02,
/* SHIFT + OPTN toggles backlight (requires GETKEY_MOD_SHIFT) */
/* SHIFT + OPTN (requires GETKEY_MOD_SHIFT) or LIGHT toggles backlight */
GETKEY_BACKLIGHT = 0x04,
/* MENU triggers a task switch and displays the main menu */
GETKEY_MENU = 0x08,

View file

@ -75,6 +75,10 @@ enum {
of the matrix one could use a ghosting effect to boot the calc. */
KEY_ACON = 0x07,
/* Virtual key codes */
KEY_HELP = 0x20, /* fx-9860G Slim: 0x75 */
KEY_LIGHT = 0x10, /* fx-9860G Slim: 0x76 */
/* Key aliases (handle with care =D) */
KEY_X2 = KEY_SQUARE,
KEY_CARET = KEY_POWER,

View file

@ -51,7 +51,8 @@ key_event_t getkey_opt(int opt, volatile int *timeout)
#ifdef FX9860G
/* Backlight toggle */
if((opt & GETKEY_BACKLIGHT) && e.type == KEYEV_DOWN &&
e.key == KEY_OPTN && e.shift && !e.alpha)
((e.key == KEY_LIGHT) ||
(e.key == KEY_OPTN && e.shift && !e.alpha)))
{
t6k11_backlight(-1);
continue;

View file

@ -4,6 +4,7 @@
#include <gint/defs/types.h>
#include <gint/mpu/pfc.h>
#include <gint/hardware.h>
/* This file is SH7705-only. */
#ifdef FX9860G
@ -111,12 +112,57 @@ uint8_t iokbd_row(int row)
return input;
}
static const uint16_t SLIM_SC[] = {
0x0940, 0x0920, 0x0910, 0x0908, 0x0904, 0x0902,
0x0840, 0x0820, 0x0810, 0x0808,
0x0740, 0x0720, 0x0710, 0x0708, 0x0704, 0x0702,
0x0640, 0x0620, 0x0610, 0x0608, 0x0604, 0x0602,
0x0540, 0x0520, 0x0510, 0x0508, 0x0504, 0x0502,
0x0440, 0x0420, 0x0410, 0x0408, 0x0404, 0x0402,
0x0340, 0x0320, 0x0310, 0x0308, 0x0304, 0x0302,
0x0240, 0x0220, 0x0210, 0x0208, 0x0204, 0x0202,
0x0101,
0x0020, 0x0010, 0x0008, 0x0004, 0x0002
};
#define SCANCODE_COUNT (sizeof(SLIM_SC) / sizeof(uint16_t))
static const uint16_t SLIM_TR[] = {
0x0940, 0x0620, 0x0720, 0x0710, 0x0804, 0x0802,
0x0808, 0x0640, 0x0840, 0x0740,
0x0910, 0x0608, 0x0502, 0x0810, 0x0280, 0x0180,
0x0920, 0x0610, 0x0504, 0x0820, 0x0704, 0x0702,
0x0904, 0x0602, 0x0420, 0x0320, 0x0220, 0x0120,
0x0908, 0x0604, 0x0440, 0x0340, 0x0240, 0x0140,
0x0708, 0x0520, 0x0408, 0x0308, 0x0208, 0x0108,
0x0902, 0x0540, 0x0410, 0x0310, 0x0210, 0x0110,
0x0001,
0x0510, 0x0508, 0x0304, 0x0104, 0x0204
};
/* iokbd_scan() - scan ports A/B/M to generate 12 rows of key data */
void iokbd_scan(uint8_t *scan)
{
/* Scan each row independently; the gain from scanning them altogether
/* Scan each row independently; the gain from scanning them all together
is probably not worth it */
for(int i = 0; i < 12; i++) scan[i] = iokbd_row(i);
/* Translate fx-9860G Slim scancodes to standard scancodes */
if (gint[HWCALC] == HWCALC_FX9860G_SLIM)
{
uint8_t slim_scan[12];
for (uint i = 0; i < 10; i++)
{
slim_scan[i] = scan[i];
scan[i] = 0x00;
}
for (uint i = 0; i < SCANCODE_COUNT; ++i)
{
if (slim_scan[SLIM_SC[i] >> 8] & (SLIM_SC[i] & 0xFF))
scan[SLIM_TR[i] >> 8] |= (SLIM_TR[i] & 0xFF);
}
}
}
#endif /* FX9860G */