Skip to content

Commit

Permalink
machine/usb: refactor endpoint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 committed Aug 1, 2023
1 parent d0e0204 commit 15d3160
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/machine/usb.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,26 +266,26 @@ func EnableCDC(txHandler func(), rxHandler func([]byte), setupHandler func(usb.S
ConfigureUSBEndpoint(usbDescriptor,
[]usb.EndpointConfig{
{
No: usb.CDC_ENDPOINT_ACM,
IsIn: true,
Type: usb.ENDPOINT_TYPE_INTERRUPT,
Index: usb.CDC_ENDPOINT_ACM,
IsIn: true,
Type: usb.ENDPOINT_TYPE_INTERRUPT,
},
{
No: usb.CDC_ENDPOINT_OUT,
Index: usb.CDC_ENDPOINT_OUT,
IsIn: false,
Type: usb.ENDPOINT_TYPE_BULK,
RxHandler: rxHandler,
},
{
No: usb.CDC_ENDPOINT_IN,
Index: usb.CDC_ENDPOINT_IN,
IsIn: true,
Type: usb.ENDPOINT_TYPE_BULK,
TxHandler: txHandler,
},
},
[]usb.SetupConfig{
{
No: usb.CDC_ACM_INTERFACE,
Index: usb.CDC_ACM_INTERFACE,
Handler: setupHandler,
},
})
Expand All @@ -296,19 +296,19 @@ func ConfigureUSBEndpoint(desc descriptor.Descriptor, epSettings []usb.EndpointC

for _, ep := range epSettings {
if ep.IsIn {
endPoints[ep.No] = uint32(ep.Type | usb.EndpointIn)
endPoints[ep.Index] = uint32(ep.Type | usb.EndpointIn)
if ep.TxHandler != nil {
usbTxHandler[ep.No] = ep.TxHandler
usbTxHandler[ep.Index] = ep.TxHandler
}
} else {
endPoints[ep.No] = uint32(ep.Type | usb.EndpointOut)
endPoints[ep.Index] = uint32(ep.Type | usb.EndpointOut)
if ep.RxHandler != nil {
usbRxHandler[ep.No] = ep.RxHandler
usbRxHandler[ep.Index] = ep.RxHandler
}
}
}

for _, s := range setup {
usbSetupHandler[s.No] = s.Handler
usbSetupHandler[s.Index] = s.Handler
}
}
4 changes: 2 additions & 2 deletions src/machine/usb/adc/midi/midi.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func newMidi() *midi {
machine.ConfigureUSBEndpoint(descriptor.CDCMIDI,
[]usb.EndpointConfig{
{
No: usb.MIDI_ENDPOINT_OUT,
Index: usb.MIDI_ENDPOINT_OUT,
IsIn: false,
Type: usb.ENDPOINT_TYPE_BULK,
RxHandler: m.RxHandler,
},
{
No: usb.MIDI_ENDPOINT_IN,
Index: usb.MIDI_ENDPOINT_IN,
IsIn: true,
Type: usb.ENDPOINT_TYPE_BULK,
TxHandler: m.Handler,
Expand Down
4 changes: 2 additions & 2 deletions src/machine/usb/config.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package usb

type EndpointConfig struct {
No uint8
Index uint8
IsIn bool
TxHandler func()
RxHandler func([]byte)
Type uint8
}

type SetupConfig struct {
No uint8
Index uint8
Handler func(Setup) bool
}
4 changes: 2 additions & 2 deletions src/machine/usb/hid/hid.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func SetHandler(d hidDevicer) {
machine.ConfigureUSBEndpoint(descriptor.CDCHID,
[]usb.EndpointConfig{
{
No: usb.HID_ENDPOINT_IN,
Index: usb.HID_ENDPOINT_IN,
IsIn: true,
Type: usb.ENDPOINT_TYPE_INTERRUPT,
TxHandler: handler,
},
},
[]usb.SetupConfig{
{
No: usb.HID_INTERFACE,
Index: usb.HID_INTERFACE,
Handler: setupHandler,
},
})
Expand Down
6 changes: 3 additions & 3 deletions src/machine/usb/hid/joystick/joystick.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ func UseSettings(def Definitions, rxHandlerFunc func(b []byte), setupFunc func(s
machine.ConfigureUSBEndpoint(descriptor.CDCJoystick,
[]usb.EndpointConfig{
{
No: usb.HID_ENDPOINT_OUT,
Index: usb.HID_ENDPOINT_OUT,
IsIn: false,
Type: usb.ENDPOINT_TYPE_INTERRUPT,
RxHandler: rxHandlerFunc,
},
{
No: usb.HID_ENDPOINT_IN,
Index: usb.HID_ENDPOINT_IN,
IsIn: true,
Type: usb.ENDPOINT_TYPE_INTERRUPT,
TxHandler: js.handler,
},
},
[]usb.SetupConfig{
{
No: usb.HID_INTERFACE,
Index: usb.HID_INTERFACE,
Handler: setupFunc,
},
},
Expand Down

0 comments on commit 15d3160

Please sign in to comment.