Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

| Mode | Description |
|------|-------------|
| **I2C** (default) | I2C slave reports characters / key data to the host. |
| **I2C** (default) | I2C slave reports characters / key data to the host. Enter sends CardKB CR (`0x0D`). Fn+D/X/Z/C emit CardKB navigation codes (`0xB5`/`0xB6`/`0xB4`/`0xB7`) for host UI navigation (e.g. Meshtastic). |
| **UART** | Custom frames with key index and press / release over UART. |
| **ESP-NOW** | Broadcasts key frames (similar framing to UART). |
| **BLE HID** | Bluetooth HID keyboard, including arrow keys via Fn combos. |
Expand Down
31 changes: 22 additions & 9 deletions src/main/app/app_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,37 +700,45 @@ static void app_process_key_event(key_event_t *key_event)
if (is_press && fn_pressed) {
switch (key_event->button_index) {
case KEY_UP: // Fn+D = 上方向键
if (g_mode == MODE_BLEHID) {
if (g_mode == MODE_I2C) {
bsp_i2c_add_key(KEYCODE_ARROW_UP);
} else if (g_mode == MODE_BLEHID) {
if (bsp_blehid_is_connected()) {
bsp_blehid_send_keycode(0, USB_HID_KEY_UP);
}
}
return;

case KEY_LEFT: // Fn+Z = 左方向键
if (g_mode == MODE_BLEHID) {
if (g_mode == MODE_I2C) {
bsp_i2c_add_key(KEYCODE_ARROW_LEFT);
} else if (g_mode == MODE_BLEHID) {
if (bsp_blehid_is_connected()) {
bsp_blehid_send_keycode(0, USB_HID_KEY_LEFT);
}
}
return;

case KEY_DOWN: // Fn+X = 下方向键
if (g_mode == MODE_BLEHID) {
if (g_mode == MODE_I2C) {
bsp_i2c_add_key(KEYCODE_ARROW_DOWN);
} else if (g_mode == MODE_BLEHID) {
if (bsp_blehid_is_connected()) {
bsp_blehid_send_keycode(0, USB_HID_KEY_DOWN);
}
}
return;

case KEY_RIGHT: // Fn+C = 右方向键
if (g_mode == MODE_BLEHID) {
if (g_mode == MODE_I2C) {
bsp_i2c_add_key(KEYCODE_ARROW_RIGHT);
} else if (g_mode == MODE_BLEHID) {
if (bsp_blehid_is_connected()) {
bsp_blehid_send_keycode(0, USB_HID_KEY_RIGHT);
}
}
return;

default:
break;
}
Expand Down Expand Up @@ -760,7 +768,12 @@ static void app_process_key_event(key_event_t *key_event)
char key_char = 0;
if (app_get_key_char(key_event->button_index, &key_char)) {
if (g_mode == MODE_I2C) {
bsp_i2c_add_key((uint8_t)key_char);
uint8_t i2c_key = (uint8_t)key_char;
// CardKB hosts (e.g. Meshtastic) expect CR for Enter, not LF from keymap
if (i2c_key == 0x0A || key_event->button_index == KEY_ENTER) {
i2c_key = KEYCODE_ENTER;
}
bsp_i2c_add_key(i2c_key);
} else if (g_mode == MODE_BLEHID) {
if (bsp_blehid_is_connected()) {
bsp_blehid_send_key(key_char);
Expand Down
7 changes: 7 additions & 0 deletions src/main/app/app_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ typedef struct {
#define KEY_DOWN 36 // 下方向键 (行3, 列3) = 3*11+3 = 36 (Fn+X)
#define KEY_RIGHT 37 // 右方向键 (行3, 列4) = 3*11+4 = 37 (Fn+C)

// Original M5Stack CardKB I2C navigation key codes (used by Meshtastic and other hosts)
#define KEYCODE_ENTER 0x0D
#define KEYCODE_ARROW_LEFT 0xB4
#define KEYCODE_ARROW_UP 0xB5
#define KEYCODE_ARROW_DOWN 0xB6
#define KEYCODE_ARROW_RIGHT 0xB7

// 输出模式选择:1=DEBUG模式(输出index), 0=正常模式(输出ASCII)
#define KEYBOARD_DEBUG_MODE 0

Expand Down