Add support for HID Keyboard LEDs

This commit is contained in:
Unrud
2023-08-05 15:23:20 +02:00
committed by Ron Evans
parent 72270f9052
commit 0ef86e1534
4 changed files with 40 additions and 2 deletions
+6
View File
@@ -36,6 +36,12 @@ func SetHandler(d hidDevicer) {
if size == 0 {
machine.ConfigureUSBEndpoint(descriptor.CDCHID,
[]usb.EndpointConfig{
{
Index: usb.HID_ENDPOINT_OUT,
IsIn: false,
Type: usb.ENDPOINT_TYPE_INTERRUPT,
RxHandler: rxHandler,
},
{
Index: usb.HID_ENDPOINT_IN,
IsIn: true,
+15
View File
@@ -92,6 +92,9 @@ func (kb *keyboard) TxHandler() bool {
}
func (kb *keyboard) RxHandler(b []byte) bool {
if len(b) >= 2 && b[0] == 2 /* ReportID */ {
kb.led = b[1]
}
return false
}
@@ -106,6 +109,18 @@ func (kb *keyboard) tx(b []byte) {
}
}
func (kb *keyboard) NumLockLed() bool {
return kb.led&1 != 0
}
func (kb *keyboard) CapsLockLed() bool {
return kb.led&2 != 0
}
func (kb *keyboard) ScrollLockLed() bool {
return kb.led&4 != 0
}
func (kb *keyboard) ready() bool {
return true
}