mirror of
https://github.com/grymoire/i2c_puppet-Linux.git
synced 2025-07-13 14:34:29 +02:00
Added support for Control characters and the characters <escape> and "<>{}[]^&%=\"
This commit is contained in:
6
app/Makefile
Normal file
6
app/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
# Make it useful for Linux
|
||||
all: keyboard.c keyboard.h usb.c
|
||||
cd ../build;make
|
||||
install: ../build/app/i2c_puppet.uf2
|
||||
cp ../build/app/i2c_puppet.uf2 /media/${USER}/RPI-RP2
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "fifo.h"
|
||||
#include "keyboard.h"
|
||||
#include "reg.h"
|
||||
#include <stdio.h> // BGB
|
||||
|
||||
#include <pico/stdlib.h>
|
||||
|
||||
@ -114,12 +115,76 @@ static void transition_to(struct list_item * const p_item, const enum key_state
|
||||
if (reg_is_bit_set(REG_ID_CFG, CFG_USE_MODS)) {
|
||||
const bool shift = (self.mods[KEY_MOD_ID_SHL] || self.mods[KEY_MOD_ID_SHR]) | self.capslock;
|
||||
const bool alt = self.mods[KEY_MOD_ID_ALT] | self.numlock;
|
||||
const bool is_button = (key <= KEY_BTN_RIGHT1) || ((key >= KEY_BTN_LEFT2) && (key <= KEY_BTN_RIGHT2));
|
||||
// const bool is_button = (key <= KEY_BTN_RIGHT1) || ((key >= KEY_BTN_LEFT2) && (key <= KEY_BTN_RIGHT2));
|
||||
const bool is_button = ((key == KEY_BTN_RIGHT1)
|
||||
|| (key == KEY_BTN_RIGHT2)
|
||||
|| (key == KEY_BTN_LEFT1)
|
||||
|| (key == KEY_BTN_LEFT2));
|
||||
const bool control = self.mods[KEY_MOD_ID_SYM];
|
||||
|
||||
|
||||
if (alt && !is_button) {
|
||||
if (is_button) {
|
||||
switch (key) {
|
||||
case KEY_BTN_LEFT1:
|
||||
if (alt) {
|
||||
key = '>';
|
||||
} else if (shift) {
|
||||
key = '<';
|
||||
} else if (control) {
|
||||
key = 'x';
|
||||
} else {
|
||||
key =0x1B; // ESC
|
||||
}
|
||||
break;
|
||||
case KEY_BTN_LEFT2:
|
||||
if (alt) {
|
||||
key = ']';
|
||||
} else if (shift) {
|
||||
key = '[';
|
||||
} else if (control) {
|
||||
key ='x';
|
||||
} else {
|
||||
key = '%';
|
||||
}
|
||||
break;
|
||||
case KEY_BTN_RIGHT1:
|
||||
if (alt) {
|
||||
key = '}';
|
||||
} else if (shift) {
|
||||
key = '{';
|
||||
} else if (control) {
|
||||
key = 'x';
|
||||
} else {
|
||||
key = '=';
|
||||
}
|
||||
break;
|
||||
case KEY_BTN_RIGHT2:
|
||||
if (alt) {
|
||||
key = '&';
|
||||
} else if (shift) {
|
||||
key = '^';
|
||||
} else if (control) {
|
||||
key = 'x'; // TODO
|
||||
} else {
|
||||
key = '\\';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// printf(" ERROR: Illegal key: %d\n", key);
|
||||
;
|
||||
}
|
||||
} else if (alt) {
|
||||
printf(" alt \n");
|
||||
key = p_entry->alt;
|
||||
} else if (!shift && (key >= 'A' && key <= 'Z')) {
|
||||
} else if (key >= 'A' && key <= 'Z') {
|
||||
printf(" letter\n");
|
||||
if (control) { // If the SYM key is held down, it's a control key
|
||||
key = key - 0x40;
|
||||
} else if (!shift) { // lower case letter
|
||||
key = (key + ' ');
|
||||
} else {
|
||||
// it's an uppercase letter - do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,24 +22,24 @@ enum key_mod
|
||||
KEY_MOD_ID_LAST,
|
||||
};
|
||||
|
||||
#define KEY_JOY_UP 0x01
|
||||
#define KEY_JOY_DOWN 0x02
|
||||
#define KEY_JOY_LEFT 0x03
|
||||
#define KEY_JOY_RIGHT 0x04
|
||||
#define KEY_JOY_CENTER 0x05
|
||||
#define KEY_BTN_LEFT1 0x06
|
||||
#define KEY_BTN_RIGHT1 0x07
|
||||
#define KEY_JOY_UP 0x81
|
||||
#define KEY_JOY_DOWN 0x82
|
||||
#define KEY_JOY_LEFT 0x83
|
||||
#define KEY_JOY_RIGHT 0x84
|
||||
#define KEY_JOY_CENTER 0x85
|
||||
#define KEY_BTN_LEFT1 0x86
|
||||
#define KEY_BTN_RIGHT1 0x87
|
||||
// 0x08 - BACKSPACE
|
||||
// 0x09 - TAB
|
||||
// 0x0A - NEW LINE
|
||||
// 0x0D - CARRIAGE RETURN
|
||||
#define KEY_BTN_LEFT2 0x11
|
||||
#define KEY_BTN_RIGHT2 0x12
|
||||
#define KEY_BTN_LEFT2 0x91
|
||||
#define KEY_BTN_RIGHT2 0x92
|
||||
|
||||
#define KEY_MOD_ALT 0x1A
|
||||
#define KEY_MOD_SHL 0x1B // Left Shift
|
||||
#define KEY_MOD_SHR 0x1C // Right Shift
|
||||
#define KEY_MOD_SYM 0x1D
|
||||
#define KEY_MOD_ALT 0x9A
|
||||
#define KEY_MOD_SHL 0x9B // Left Shift
|
||||
#define KEY_MOD_SHR 0x9C // Right Shift
|
||||
#define KEY_MOD_SYM 0x9D
|
||||
|
||||
struct key_callback
|
||||
{
|
||||
|
19
app/usb.c
19
app/usb.c
@ -55,8 +55,10 @@ static void key_cb(char key, enum key_state state)
|
||||
return;
|
||||
|
||||
if (tud_hid_n_ready(USB_ITF_KEYBOARD) && reg_is_bit_set(REG_ID_CF2, CF2_USB_KEYB_ON)) {
|
||||
uint8_t conv_table[128][2] = { HID_ASCII_TO_KEYCODE };
|
||||
// conv_table needs to be 256 entries long because the special keys are in range 128-256 (0x80 - 0xFF)
|
||||
uint8_t conv_table[256][2] = { HID_ASCII_TO_KEYCODE };
|
||||
conv_table['\n'][1] = HID_KEY_ENTER; // Fixup: Enter instead of Return
|
||||
conv_table['\b'][1] = HID_KEY_BACKSPACE; // Fixup: HID backspace (0x2A) instead of \b (0x08)
|
||||
conv_table[KEY_JOY_UP][1] = HID_KEY_ARROW_UP;
|
||||
conv_table[KEY_JOY_DOWN][1] = HID_KEY_ARROW_DOWN;
|
||||
conv_table[KEY_JOY_LEFT][1] = HID_KEY_ARROW_LEFT;
|
||||
@ -66,10 +68,21 @@ static void key_cb(char key, enum key_state state)
|
||||
uint8_t modifier = 0;
|
||||
|
||||
if (state == KEY_STATE_PRESSED) {
|
||||
if (conv_table[(int)key][0])
|
||||
printf(" conv_table[%d][0,1]=%d,%d ",key, conv_table[(int)key][0], conv_table[(int)key][1]); // bgb
|
||||
if (conv_table[(int)key][0]) {
|
||||
modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
|
||||
} else if (key < 0x20) { // it's a control key
|
||||
if ((key == '\n') || (key == '\b')) {
|
||||
// leave alone - this is necessary because the Linux graphical login processes the HID equivalent
|
||||
// which is done using conv_table[] below
|
||||
} else {
|
||||
// convert control key, i.e. [Control-A] converts to [modifier=control, key=A]
|
||||
modifier=KEYBOARD_MODIFIER_RIGHTCTRL;
|
||||
key=key + 0x40;
|
||||
}
|
||||
|
||||
keycode[0] = conv_table[(int)key][1];
|
||||
}
|
||||
keycode[0] = conv_table[(int)key][1];
|
||||
}
|
||||
|
||||
if (state != KEY_STATE_HOLD)
|
||||
|
Reference in New Issue
Block a user