Browse Source

machine/usb/hid: add MediaKey support (#3436)

machine/usb/hid: add MediaKey support
pull/3459/head
sago35 2 years ago
committed by GitHub
parent
commit
e21ab04fad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/machine/usb/descriptor.go
  2. 12
      src/machine/usb/hid/keyboard/keyboard.go
  3. 1
      src/machine/usb/hid/keyboard/keycode.go

15
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
},
},
}

12
src/machine/usb/hid/keyboard/keyboard.go

@ -238,7 +238,9 @@ func (kb *keyboard) sendKey(consumer bool, b []byte) bool {
func (kb *keyboard) keyboardSendKeys(consumer bool) bool {
var b [9]byte
b[0] = 0x02
if !consumer {
b[0] = 0x02 // REPORT_ID
b[1] = kb.mod
b[2] = 0x02
b[3] = kb.key[0]
@ -248,6 +250,14 @@ func (kb *keyboard) keyboardSendKeys(consumer bool) bool {
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.

1
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

Loading…
Cancel
Save