diff options
author | sago35 <[email protected]> | 2023-02-18 09:27:15 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2023-02-18 01:27:15 +0100 |
commit | e21ab04fad5e273b8f4c933f3e96133b90797314 (patch) | |
tree | 38db85eb1dd18cd08eedfce8b37f0e1c11316b8d | |
parent | 4e8453167f42976aad87099ffdb3746fc540d6a6 (diff) | |
download | tinygo-e21ab04fad5e273b8f4c933f3e96133b90797314.tar.gz tinygo-e21ab04fad5e273b8f4c933f3e96133b90797314.zip |
machine/usb/hid: add MediaKey support (#3436)
machine/usb/hid: add MediaKey support
-rw-r--r-- | src/machine/usb/descriptor.go | 15 | ||||
-rw-r--r-- | src/machine/usb/hid/keyboard/keyboard.go | 30 | ||||
-rw-r--r-- | src/machine/usb/hid/keyboard/keycode.go | 1 |
3 files changed, 35 insertions, 11 deletions
diff --git a/src/machine/usb/descriptor.go b/src/machine/usb/descriptor.go index 3acb2e9a7..d57d0bd8a 100644 --- a/src/machine/usb/descriptor.go +++ b/src/machine/usb/descriptor.go @@ -67,7 +67,7 @@ var DescriptorCDCHID = Descriptor{ 0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00, 0x07, 0x05, 0x83, 0x02, 0x40, 0x00, 0x00, 0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, - 0x09, 0x21, 0x01, 0x01, 0x00, 0x01, 0x22, 0x65, 0x00, + 0x09, 0x21, 0x01, 0x01, 0x00, 0x01, 0x22, 0x7E, 0x00, 0x07, 0x05, 0x84, 0x03, 0x40, 0x00, 0x01, }, HID: map[uint16][]byte{ @@ -80,6 +80,19 @@ var DescriptorCDCHID = Descriptor{ 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x03, 0x81, 0x06, 0xc0, 0xc0, + + 0x05, 0x0C, // Usage Page (Consumer) + 0x09, 0x01, // Usage (Consumer Control) + 0xA1, 0x01, // Collection (Application) + 0x85, 0x03, // Report ID (3) + 0x15, 0x00, // Logical Minimum (0) + 0x26, 0xFF, 0x1F, // Logical Maximum (8191) + 0x19, 0x00, // Usage Minimum (Unassigned) + 0x2A, 0xFF, 0x1F, // Usage Maximum (0x1FFF) + 0x75, 0x10, // Report Size (16) + 0x95, 0x01, // Report Count (1) + 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0xC0, // End Collection }, }, } diff --git a/src/machine/usb/hid/keyboard/keyboard.go b/src/machine/usb/hid/keyboard/keyboard.go index ce6993998..6a5bad647 100644 --- a/src/machine/usb/hid/keyboard/keyboard.go +++ b/src/machine/usb/hid/keyboard/keyboard.go @@ -238,16 +238,26 @@ func (kb *keyboard) sendKey(consumer bool, b []byte) bool { func (kb *keyboard) keyboardSendKeys(consumer bool) bool { var b [9]byte - b[0] = 0x02 - b[1] = kb.mod - b[2] = 0x02 - b[3] = kb.key[0] - b[4] = kb.key[1] - b[5] = kb.key[2] - b[6] = kb.key[3] - b[7] = kb.key[4] - b[8] = kb.key[5] - return kb.sendKey(consumer, b[:]) + + if !consumer { + b[0] = 0x02 // REPORT_ID + b[1] = kb.mod + b[2] = 0x02 + b[3] = kb.key[0] + b[4] = kb.key[1] + b[5] = kb.key[2] + b[6] = kb.key[3] + b[7] = kb.key[4] + b[8] = kb.key[5] + return kb.sendKey(consumer, b[:]) + + } else { + b[0] = 0x03 // REPORT_ID + b[1] = uint8(kb.con[0]) + b[2] = uint8((kb.con[0] & 0x0300) >> 8) + + return kb.sendKey(consumer, b[:3]) + } } // Down transmits a key-down event for the given Keycode. diff --git a/src/machine/usb/hid/keyboard/keycode.go b/src/machine/usb/hid/keyboard/keycode.go index 8b26eaccd..762f65b9c 100644 --- a/src/machine/usb/hid/keyboard/keycode.go +++ b/src/machine/usb/hid/keyboard/keycode.go @@ -77,6 +77,7 @@ const ( KeyModifierRightAlt Keycode = 0x40 | 0xE000 KeyModifierRightGUI Keycode = 0x80 | 0xE000 + // KeySystemXXX is not supported now KeySystemPowerDown Keycode = 0x81 | 0xE200 KeySystemSleep Keycode = 0x82 | 0xE200 KeySystemWakeUp Keycode = 0x83 | 0xE200 |