Ryan Malloy 9a8eae1d2f Add HID (Human Interface Device) profile support
Implements Classic Bluetooth HID Device profile for keyboard/mouse emulation:

Firmware:
- bt_hid.c/h: HID device driver with combo keyboard/mouse HID descriptor
- cmd_hid_{enable,disable,connect,disconnect}: HID lifecycle management
- cmd_hid_send_keyboard: Send keyboard reports (modifier + up to 6 keys)
- cmd_hid_send_mouse: Send mouse reports (buttons + relative X/Y)
- cmd_hid_status: Query HID state (enabled, registered, connected)

Python MCP tools:
- esp32_hid_enable/disable: Control HID device mode
- esp32_hid_connect/disconnect: Manage HID host connections
- esp32_hid_send_keyboard/send_mouse: Send HID reports
- esp32_hid_status: Get connection state

Config:
- Enable BT_HID_ENABLED + BT_HID_DEVICE_ENABLED in sdkconfig.defaults
- Add bt_hid.c to CMakeLists.txt

Tested E2E: Linux (hci1) connects to ESP32 HID device, keyboard and
mouse reports sent successfully.
2026-02-03 14:07:35 -07:00

92 lines
2.9 KiB
C

#pragma once
#include "driver/uart.h"
/* UART configuration */
#define PROTO_UART_NUM UART_NUM_0
#define PROTO_BAUD_RATE 115200
#define PROTO_TX_BUF_SIZE 4096
#define PROTO_RX_BUF_SIZE 4096
#define PROTO_MAX_LINE 2048
/* Message types */
#define MSG_TYPE_CMD "cmd"
#define MSG_TYPE_RESP "resp"
#define MSG_TYPE_EVENT "event"
/* Response status */
#define STATUS_OK "ok"
#define STATUS_ERROR "error"
/* System commands */
#define CMD_PING "ping"
#define CMD_RESET "reset"
#define CMD_GET_INFO "get_info"
#define CMD_GET_STATUS "get_status"
/* Configuration commands */
#define CMD_CONFIGURE "configure"
#define CMD_LOAD_PERSONA "load_persona"
#define CMD_LIST_PERSONAS "list_personas"
#define CMD_CLASSIC_SET_SSP_MODE "classic_set_ssp_mode"
/* Classic BT commands */
#define CMD_CLASSIC_ENABLE "classic_enable"
#define CMD_CLASSIC_DISABLE "classic_disable"
#define CMD_CLASSIC_SET_DISCOVERABLE "classic_set_discoverable"
#define CMD_CLASSIC_PAIR_RESPOND "classic_pair_respond"
/* SPP commands */
#define CMD_SPP_SEND "spp_send"
#define CMD_SPP_DISCONNECT "spp_disconnect"
#define CMD_SPP_STATUS "spp_status"
/* HID commands */
#define CMD_HID_ENABLE "hid_enable"
#define CMD_HID_DISABLE "hid_disable"
#define CMD_HID_CONNECT "hid_connect"
#define CMD_HID_DISCONNECT "hid_disconnect"
#define CMD_HID_SEND_KEYBOARD "hid_send_keyboard"
#define CMD_HID_SEND_MOUSE "hid_send_mouse"
#define CMD_HID_STATUS "hid_status"
/* BLE commands */
#define CMD_BLE_ENABLE "ble_enable"
#define CMD_BLE_DISABLE "ble_disable"
#define CMD_BLE_ADVERTISE "ble_advertise"
#define CMD_BLE_SET_ADV_DATA "ble_set_adv_data"
/* GATT commands */
#define CMD_GATT_ADD_SERVICE "gatt_add_service"
#define CMD_GATT_ADD_CHARACTERISTIC "gatt_add_characteristic"
#define CMD_GATT_SET_VALUE "gatt_set_value"
#define CMD_GATT_NOTIFY "gatt_notify"
#define CMD_GATT_CLEAR "gatt_clear"
/* Events */
#define EVT_BOOT "boot"
#define EVT_PAIR_REQUEST "pair_request"
#define EVT_PAIR_COMPLETE "pair_complete"
#define EVT_CONNECT "connect"
#define EVT_DISCONNECT "disconnect"
#define EVT_GATT_READ "gatt_read"
#define EVT_GATT_WRITE "gatt_write"
#define EVT_GATT_SUBSCRIBE "gatt_subscribe"
/* SPP events */
#define EVT_SPP_DATA "spp_data"
#define EVT_SPP_CONNECT "spp_connect"
#define EVT_SPP_DISCONNECT "spp_disconnect"
/* HID events */
#define EVT_HID_CONNECT "hid_connect"
#define EVT_HID_DISCONNECT "hid_disconnect"
#define EVT_HID_DATA "hid_data"
/* SSP IO capabilities */
#define IO_CAP_DISPLAY_ONLY "display_only"
#define IO_CAP_DISPLAY_YESNO "display_yesno"
#define IO_CAP_KEYBOARD_ONLY "keyboard_only"
#define IO_CAP_NO_IO "no_io"
#define IO_CAP_KEYBOARD_DISPLAY "keyboard_display"