Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

machine/usb/hid: add RxHandler interface #3851

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/machine/usb/hid/hid.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (
)

type hidDevicer interface {
Handler() bool
TxHandler() bool
RxHandler([]byte) bool
}

var devices [5]hidDevicer
Expand All @@ -39,7 +40,7 @@ func SetHandler(d hidDevicer) {
Index: usb.HID_ENDPOINT_IN,
IsIn: true,
Type: usb.ENDPOINT_TYPE_INTERRUPT,
TxHandler: handler,
TxHandler: txHandler,
},
},
[]usb.SetupConfig{
Expand All @@ -54,12 +55,23 @@ func SetHandler(d hidDevicer) {
size++
}

func handler() {
func txHandler() {
for _, d := range devices {
if d == nil {
continue
}
if done := d.Handler(); done {
if done := d.TxHandler(); done {
return
}
}
}

func rxHandler(b []byte) {
for _, d := range devices {
if d == nil {
continue
}
if done := d.RxHandler(b); done {
return
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/machine/usb/hid/keyboard/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newKeyboard() *keyboard {
}
}

func (kb *keyboard) Handler() bool {
func (kb *keyboard) TxHandler() bool {
kb.waitTxc = false
if b, ok := kb.buf.Get(); ok {
kb.waitTxc = true
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion src/machine/usb/hid/mouse/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newMouse() *mouse {
}
}

func (m *mouse) Handler() bool {
func (m *mouse) TxHandler() bool {
m.waitTxc = false
if b, ok := m.buf.Get(); ok {
m.waitTxc = true
Expand All @@ -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 {
Expand Down
Loading