Unverified Commit 1dfd9eba authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Add HID consumer (aka media) keys for USB, BT (#1309)

Allow sending thigns like KEY_MUTE or KEY_SCAN_NEXT from the USB and
Bluetooth Classic keyboard libraries.

BLE requires some add'l magic, not yet discovered.

Pull in latest upstream Keyboard library changes
parent 3dbe5cf9
...@@ -157,7 +157,7 @@ void __SetupDescHIDReport() { ...@@ -157,7 +157,7 @@ void __SetupDescHIDReport() {
//allocate memory for the HID report descriptors. We don't use them, but need the size here. //allocate memory for the HID report descriptors. We don't use them, but need the size here.
uint8_t desc_hid_report_mouse[] = { TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(1)) }; uint8_t desc_hid_report_mouse[] = { TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(1)) };
uint8_t desc_hid_report_joystick[] = { TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(1)) }; uint8_t desc_hid_report_joystick[] = { TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(1)) };
uint8_t desc_hid_report_keyboard[] = { TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(1)) }; uint8_t desc_hid_report_keyboard[] = { TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(1)), TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(2)) };
int size = 0; int size = 0;
//accumulate the size of all used HID report descriptors //accumulate the size of all used HID report descriptors
...@@ -194,7 +194,7 @@ void __SetupDescHIDReport() { ...@@ -194,7 +194,7 @@ void __SetupDescHIDReport() {
if (__USBInstallMouse) { if (__USBInstallMouse) {
//determine if we need an offset (USB keyboard is installed) //determine if we need an offset (USB keyboard is installed)
if (__USBInstallKeyboard) { if (__USBInstallKeyboard) {
uint8_t desc_local[] = { TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(2)) }; uint8_t desc_local[] = { TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(3)) };
memcpy(__hid_report + sizeof(desc_hid_report_keyboard), desc_local, sizeof(desc_local)); memcpy(__hid_report + sizeof(desc_hid_report_keyboard), desc_local, sizeof(desc_local));
} else { } else {
memcpy(__hid_report, desc_hid_report_mouse, sizeof(desc_hid_report_mouse)); memcpy(__hid_report, desc_hid_report_mouse, sizeof(desc_hid_report_mouse));
...@@ -206,7 +206,7 @@ void __SetupDescHIDReport() { ...@@ -206,7 +206,7 @@ void __SetupDescHIDReport() {
uint8_t reportid = 1; uint8_t reportid = 1;
int offset = 0; int offset = 0;
if (__USBInstallKeyboard) { if (__USBInstallKeyboard) {
reportid++; reportid += 2;
offset += sizeof(desc_hid_report_keyboard); offset += sizeof(desc_hid_report_keyboard);
} }
if (__USBInstallMouse) { if (__USBInstallMouse) {
......
Subproject commit 68d4702949cf373be251de6936d71aff7dc9f5a4 Subproject commit c0f474695f83d63209fe4ad73ec5d90f27cd9e64
...@@ -26,7 +26,19 @@ void setup() { ...@@ -26,7 +26,19 @@ void setup() {
void loop() { void loop() {
if (BOOTSEL) { if (BOOTSEL) {
Serial.println("Typing password for you...shhhh...."); Serial.println("Typing password for you...shhhh....");
Serial.println("First, mute the computer to be extra quiet");
Keyboard.consumerPress(KEY_MUTE);
delay(100);
Keyboard.consumerRelease();
Keyboard.print("ThisPasswordIsWeakLikeABaby"); Keyboard.print("ThisPasswordIsWeakLikeABaby");
Serial.println("OK, unmute the computer since our secret is done");
Keyboard.consumerPress(KEY_MUTE);
delay(100);
Keyboard.consumerRelease();
while (BOOTSEL); while (BOOTSEL);
} }
} }
...@@ -46,6 +46,16 @@ void Keyboard_::sendReport(KeyReport* keys) { ...@@ -46,6 +46,16 @@ void Keyboard_::sendReport(KeyReport* keys) {
tud_task(); tud_task();
} }
void Keyboard_::sendConsumerReport(uint16_t key) {
CoreMutex m(&__usb_mutex);
tud_task();
if (tud_hid_ready()) {
tud_hid_report(__USBGetKeyboardReportID() + 1, &key, sizeof(key));
}
tud_task();
}
extern "C" void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { extern "C" void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
(void) report_id; (void) report_id;
(void) instance; (void) instance;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
class Keyboard_ : public HID_Keyboard { class Keyboard_ : public HID_Keyboard {
protected: protected:
virtual void sendReport(KeyReport* keys) override; virtual void sendReport(KeyReport* keys) override;
virtual void sendConsumerReport(uint16_t key) override;
public: public:
Keyboard_(void); Keyboard_(void);
......
...@@ -63,4 +63,9 @@ void KeyboardBLE_::sendReport(KeyReport* keys) { ...@@ -63,4 +63,9 @@ void KeyboardBLE_::sendReport(KeyReport* keys) {
PicoBluetoothBLEHID.send(&data, sizeof(data)); PicoBluetoothBLEHID.send(&data, sizeof(data));
} }
void KeyboardBLE_::sendConsumerReport(uint16_t key) {
(void) key;
// TODO - Need some BLE-specific code to send 2nd report
}
KeyboardBLE_ KeyboardBLE; KeyboardBLE_ KeyboardBLE;
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
class KeyboardBLE_ : public HID_Keyboard { class KeyboardBLE_ : public HID_Keyboard {
private: private:
virtual void sendReport(KeyReport* keys) override; virtual void sendReport(KeyReport* keys) override;
virtual void sendConsumerReport(uint16_t key) override;
public: public:
KeyboardBLE_(void); KeyboardBLE_(void);
void begin(const char *localName = nullptr, const char *hidName = nullptr, const uint8_t *layout = KeyboardLayout_en_US); void begin(const char *localName = nullptr, const char *hidName = nullptr, const uint8_t *layout = KeyboardLayout_en_US);
......
...@@ -34,7 +34,7 @@ KeyboardBT_::KeyboardBT_(void) { ...@@ -34,7 +34,7 @@ KeyboardBT_::KeyboardBT_(void) {
#define REPORT_ID 0x01 #define REPORT_ID 0x01
static const uint8_t desc_keyboard[] = {TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID))}; static const uint8_t desc_keyboard[] = {TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID)), TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(REPORT_ID + 1))};
static void _hidReportCB(uint16_t cid, hid_report_type_t report_type, uint16_t report_id, int report_size, uint8_t *report) { static void _hidReportCB(uint16_t cid, hid_report_type_t report_type, uint16_t report_id, int report_size, uint8_t *report) {
(void) cid; (void) cid;
...@@ -71,4 +71,8 @@ void KeyboardBT_::sendReport(KeyReport* keys) { ...@@ -71,4 +71,8 @@ void KeyboardBT_::sendReport(KeyReport* keys) {
PicoBluetoothHID.send(REPORT_ID, &data, sizeof(data)); PicoBluetoothHID.send(REPORT_ID, &data, sizeof(data));
} }
void KeyboardBT_::sendConsumerReport(uint16_t key) {
PicoBluetoothHID.send(REPORT_ID + 1, &key, sizeof(key));
}
KeyboardBT_ KeyboardBT; KeyboardBT_ KeyboardBT;
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
class KeyboardBT_ : public HID_Keyboard { class KeyboardBT_ : public HID_Keyboard {
protected: protected:
virtual void sendReport(KeyReport* keys) override; virtual void sendReport(KeyReport* keys) override;
virtual void sendConsumerReport(uint16_t key) override;
public: public:
KeyboardBT_(void); KeyboardBT_(void);
void begin(const char *localName = nullptr, const char *hidName = nullptr, const uint8_t *layout = KeyboardLayout_en_US); void begin(const char *localName = nullptr, const char *hidName = nullptr, const uint8_t *layout = KeyboardLayout_en_US);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment