Skip to content

Commit acad29d

Browse files
committed
machine/usb: refactoring descriptors into subpackage for modularity
Signed-off-by: deadprogram <[email protected]>
1 parent 71b44e7 commit acad29d

File tree

13 files changed

+1054
-188
lines changed

13 files changed

+1054
-188
lines changed

src/machine/usb.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/binary"
88
"errors"
99
"machine/usb"
10+
"machine/usb/descriptor"
1011
)
1112

1213
type USBDevice struct {
@@ -29,7 +30,7 @@ type Serialer interface {
2930
RTS() bool
3031
}
3132

32-
var usbDescriptor = usb.DescriptorCDC
33+
var usbDescriptor = descriptor.CDC
3334

3435
var usbDescriptorConfig uint8 = usb.DescriptorConfigCDC
3536

@@ -88,7 +89,7 @@ var (
8889
)
8990

9091
var (
91-
usbEndpointDescriptors [usb.NumberOfEndpoints]usb.DeviceDescriptor
92+
usbEndpointDescriptors [usb.NumberOfEndpoints]descriptor.Device
9293

9394
isEndpointHalt = false
9495
isRemoteWakeUpEnabled = false
@@ -141,13 +142,13 @@ func sendDescriptor(setup usb.Setup) {
141142
// composite descriptor
142143
switch {
143144
case (usbDescriptorConfig & usb.DescriptorConfigHID) > 0:
144-
usbDescriptor = usb.DescriptorCDCHID
145+
usbDescriptor = descriptor.CDCHID
145146
case (usbDescriptorConfig & usb.DescriptorConfigMIDI) > 0:
146-
usbDescriptor = usb.DescriptorCDCMIDI
147+
usbDescriptor = descriptor.CDCMIDI
147148
case (usbDescriptorConfig & usb.DescriptorConfigJoystick) > 0:
148-
usbDescriptor = usb.DescriptorCDCJoystick
149+
usbDescriptor = descriptor.CDCJoystick
149150
default:
150-
usbDescriptor = usb.DescriptorCDC
151+
usbDescriptor = descriptor.CDC
151152
}
152153

153154
usbDescriptor.Configure(usbVendorID(), usbProductID())
@@ -302,11 +303,11 @@ func EnableMIDI(txHandler func(), rxHandler func([]byte), setupHandler func(usb.
302303

303304
// EnableJoystick enables HID. This function must be executed from the init().
304305
func EnableJoystick(txHandler func(), rxHandler func([]byte), setupHandler func(usb.Setup) bool, hidDesc []byte) {
305-
idx := bytes.Index(usb.DescriptorCDCJoystick.Configuration, []byte{
306+
idx := bytes.Index(descriptor.CDCJoystick.Configuration, []byte{
306307
0x09, 0x21, 0x11, 0x01, 0x00, 0x01, 0x22,
307308
})
308-
binary.LittleEndian.PutUint16(usb.DescriptorCDCJoystick.Configuration[idx+7:idx+9], uint16(len(hidDesc)))
309-
usb.DescriptorCDCJoystick.HID[2] = hidDesc
309+
binary.LittleEndian.PutUint16(descriptor.CDCJoystick.Configuration[idx+7:idx+9], uint16(len(hidDesc)))
310+
descriptor.CDCJoystick.HID[2] = hidDesc
310311
usbDescriptorConfig |= usb.DescriptorConfigJoystick
311312
endPoints[usb.HID_ENDPOINT_OUT] = (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointOut)
312313
usbRxHandler[usb.HID_ENDPOINT_OUT] = rxHandler

src/machine/usb/descriptor.go

Lines changed: 0 additions & 179 deletions
This file was deleted.

0 commit comments

Comments
 (0)