From c51f5cea0bd4a8c3d7b80544dc6577ddacf947b6 Mon Sep 17 00:00:00 2001 From: sago35 Date: Mon, 3 Jul 2023 22:54:14 +0900 Subject: [PATCH] machine/usb/hid: add RxHandler interface --- src/machine/usb/hid/hid.go | 12 ++++++++++++ src/machine/usb/hid/keyboard/keyboard.go | 4 ++++ src/machine/usb/hid/mouse/mouse.go | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/src/machine/usb/hid/hid.go b/src/machine/usb/hid/hid.go index e73c7a4a..e3948dc4 100644 --- a/src/machine/usb/hid/hid.go +++ b/src/machine/usb/hid/hid.go @@ -24,6 +24,7 @@ const ( type hidDevicer interface { Handler() bool + RxHandler([]byte) bool } var devices [5]hidDevicer @@ -65,6 +66,17 @@ func handler() { } } +func rxHandler(b []byte) { + for _, d := range devices { + if d == nil { + continue + } + if done := d.RxHandler(b); done { + return + } + } +} + var DefaultSetupHandler = setupHandler func setupHandler(setup usb.Setup) bool { diff --git a/src/machine/usb/hid/keyboard/keyboard.go b/src/machine/usb/hid/keyboard/keyboard.go index 6a5bad64..d3932141 100644 --- a/src/machine/usb/hid/keyboard/keyboard.go +++ b/src/machine/usb/hid/keyboard/keyboard.go @@ -91,6 +91,10 @@ func (kb *keyboard) Handler() bool { return false } +func (kb *keyboard) RxHandler(b []byte) bool { + return false +} + func (kb *keyboard) tx(b []byte) { if machine.USBDev.InitEndpointComplete { if kb.waitTxc { diff --git a/src/machine/usb/hid/mouse/mouse.go b/src/machine/usb/hid/mouse/mouse.go index d778fd20..024c1e9c 100644 --- a/src/machine/usb/hid/mouse/mouse.go +++ b/src/machine/usb/hid/mouse/mouse.go @@ -57,6 +57,10 @@ func (m *mouse) Handler() bool { return false } +func (m *mouse) RxHandler(b []byte) bool { + return false +} + func (m *mouse) tx(b []byte) { if machine.USBDev.InitEndpointComplete { if m.waitTxc {