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.
25 lines
697 B
C
25 lines
697 B
C
/*
|
|
* bt_hid.h -- Classic Bluetooth HID Device (keyboard/mouse emulation)
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include "cJSON.h"
|
|
|
|
void bt_hid_init(void);
|
|
|
|
/* Command handlers (dispatched from cmd_dispatcher) */
|
|
void cmd_hid_enable(const char *id, cJSON *params);
|
|
void cmd_hid_disable(const char *id, cJSON *params);
|
|
void cmd_hid_connect(const char *id, cJSON *params);
|
|
void cmd_hid_disconnect(const char *id, cJSON *params);
|
|
void cmd_hid_send_keyboard(const char *id, cJSON *params);
|
|
void cmd_hid_send_mouse(const char *id, cJSON *params);
|
|
void cmd_hid_status(const char *id, cJSON *params);
|
|
|
|
/* State query */
|
|
bool bt_hid_is_enabled(void);
|
|
bool bt_hid_is_connected(void);
|