aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorsago35 <[email protected]>2023-07-02 11:30:35 +0900
committerRon Evans <[email protected]>2023-08-01 15:24:42 +0200
commitd1eb642d45191218c95ab261183a6004785420ec (patch)
tree0ca7fbbdb70e43df6c8ac39968c8e54ad8530388
parent5f2e72f3716b4c3a1dde059d0c4471fc2c7adac9 (diff)
downloadtinygo-d1eb642d45191218c95ab261183a6004785420ec.tar.gz
tinygo-d1eb642d45191218c95ab261183a6004785420ec.zip
machine/usb: remove usbDescriptorConfig
-rw-r--r--src/machine/usb.go27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/machine/usb.go b/src/machine/usb.go
index a90fab177..34c13a5c7 100644
--- a/src/machine/usb.go
+++ b/src/machine/usb.go
@@ -29,9 +29,7 @@ type Serialer interface {
RTS() bool
}
-var usbDescriptor = descriptor.CDC
-
-var usbDescriptorConfig uint8 = usb.DescriptorConfigCDC
+var usbDescriptor descriptor.Descriptor
func usbVendorID() uint16 {
if usb.VendorID != 0 {
@@ -138,18 +136,6 @@ func sendDescriptor(setup usb.Setup) {
sendUSBPacket(0, usbDescriptor.Configuration, setup.WLength)
return
case descriptor.TypeDevice:
- // composite descriptor
- switch {
- case (usbDescriptorConfig & usb.DescriptorConfigHID) > 0:
- usbDescriptor = descriptor.CDCHID
- case (usbDescriptorConfig & usb.DescriptorConfigMIDI) > 0:
- usbDescriptor = descriptor.CDCMIDI
- case (usbDescriptorConfig & usb.DescriptorConfigJoystick) > 0:
- usbDescriptor = descriptor.CDCJoystick
- default:
- usbDescriptor = descriptor.CDC
- }
-
usbDescriptor.Configure(usbVendorID(), usbProductID())
sendUSBPacket(0, usbDescriptor.Device, setup.WLength)
return
@@ -273,7 +259,10 @@ func handleStandardSetup(setup usb.Setup) bool {
}
func EnableCDC(txHandler func(), rxHandler func([]byte), setupHandler func(usb.Setup) bool) {
- usbDescriptorConfig |= usb.DescriptorConfigCDC
+ if len(usbDescriptor.Device) == 0 {
+ usbDescriptor = descriptor.CDC
+ }
+ // Initialization of endpoints is required even for non-CDC
endPoints[usb.CDC_ENDPOINT_ACM] = (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn)
endPoints[usb.CDC_ENDPOINT_OUT] = (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut)
endPoints[usb.CDC_ENDPOINT_IN] = (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn)
@@ -285,7 +274,7 @@ func EnableCDC(txHandler func(), rxHandler func([]byte), setupHandler func(usb.S
// EnableHID enables HID. This function must be executed from the init().
func EnableHID(txHandler func(), rxHandler func([]byte), setupHandler func(usb.Setup) bool) {
- usbDescriptorConfig |= usb.DescriptorConfigHID
+ usbDescriptor = descriptor.CDCHID
endPoints[usb.HID_ENDPOINT_IN] = (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn)
usbTxHandler[usb.HID_ENDPOINT_IN] = txHandler
usbSetupHandler[usb.HID_INTERFACE] = setupHandler // 0x03 (HID - Human Interface Device)
@@ -293,7 +282,7 @@ func EnableHID(txHandler func(), rxHandler func([]byte), setupHandler func(usb.S
// EnableMIDI enables MIDI. This function must be executed from the init().
func EnableMIDI(txHandler func(), rxHandler func([]byte), setupHandler func(usb.Setup) bool) {
- usbDescriptorConfig |= usb.DescriptorConfigMIDI
+ usbDescriptor = descriptor.CDCMIDI
endPoints[usb.MIDI_ENDPOINT_OUT] = (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut)
endPoints[usb.MIDI_ENDPOINT_IN] = (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn)
usbRxHandler[usb.MIDI_ENDPOINT_OUT] = rxHandler
@@ -311,7 +300,7 @@ func EnableJoystick(txHandler func(), rxHandler func([]byte), setupHandler func(
class.ClassLength(uint16(len(hidDesc)))
descriptor.CDCJoystick.HID[2] = hidDesc
- usbDescriptorConfig |= usb.DescriptorConfigJoystick
+ usbDescriptor = descriptor.CDCJoystick
endPoints[usb.HID_ENDPOINT_OUT] = (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointOut)
usbRxHandler[usb.HID_ENDPOINT_OUT] = rxHandler
endPoints[usb.HID_ENDPOINT_IN] = (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn)