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: remove usbDescriptorConfig #3849

Merged
merged 1 commit into from
Aug 1, 2023
Merged
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
27 changes: 8 additions & 19 deletions src/machine/usb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -285,15 +274,15 @@ 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)
}

// 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
Expand All @@ -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)
Expand Down
Loading