machine/usb: change to not send before endpoint initialization

This commit is contained in:
sago35
2023-01-08 11:59:26 +09:00
committed by Ron Evans
parent a7ff2731b9
commit 5f3534fe72
5 changed files with 33 additions and 21 deletions
+3 -1
View File
@@ -10,7 +10,8 @@ import (
) )
type USBDevice struct { type USBDevice struct {
initcomplete bool initcomplete bool
InitEndpointComplete bool
} }
var ( var (
@@ -215,6 +216,7 @@ func handleStandardSetup(setup usb.Setup) bool {
} }
usbConfiguration = setup.WValueL usbConfiguration = setup.WValueL
USBDev.InitEndpointComplete = true
SendZlp() SendZlp()
return true return true
+8 -5
View File
@@ -2,6 +2,7 @@ package keyboard
import ( import (
"errors" "errors"
"machine"
"machine/usb/hid" "machine/usb/hid"
) )
@@ -91,11 +92,13 @@ func (kb *keyboard) Handler() bool {
} }
func (kb *keyboard) tx(b []byte) { func (kb *keyboard) tx(b []byte) {
if kb.waitTxc { if machine.USBDev.InitEndpointComplete {
kb.buf.Put(b) if kb.waitTxc {
} else { kb.buf.Put(b)
kb.waitTxc = true } else {
hid.SendUSBPacket(b) kb.waitTxc = true
hid.SendUSBPacket(b)
}
} }
} }
+8 -5
View File
@@ -1,6 +1,7 @@
package mouse package mouse
import ( import (
"machine"
"machine/usb/hid" "machine/usb/hid"
) )
@@ -55,11 +56,13 @@ func (m *mouse) Handler() bool {
} }
func (m *mouse) tx(b []byte) { func (m *mouse) tx(b []byte) {
if m.waitTxc { if machine.USBDev.InitEndpointComplete {
m.buf.Put(b) if m.waitTxc {
} else { m.buf.Put(b)
m.waitTxc = true } else {
hid.SendUSBPacket(b) m.waitTxc = true
hid.SendUSBPacket(b)
}
} }
} }
+7 -5
View File
@@ -76,11 +76,13 @@ func (m *Joystick) rxHandler(b []byte) {
} }
func (m *Joystick) tx(b []byte) { func (m *Joystick) tx(b []byte) {
if m.waitTxc { if machine.USBDev.InitEndpointComplete {
m.buf.Put(b) if m.waitTxc {
} else { m.buf.Put(b)
m.waitTxc = true } else {
m.sendUSBPacket(b) m.waitTxc = true
m.sendUSBPacket(b)
}
} }
} }
+7 -5
View File
@@ -71,11 +71,13 @@ func (m *midi) Handler() {
} }
func (m *midi) tx(b []byte) { func (m *midi) tx(b []byte) {
if m.waitTxc { if machine.USBDev.InitEndpointComplete {
m.buf.Put(b) if m.waitTxc {
} else { m.buf.Put(b)
m.waitTxc = true } else {
m.sendUSBPacket(b) m.waitTxc = true
m.sendUSBPacket(b)
}
} }
} }