Skip to content

Commit 05c92e4

Browse files
committed
chore: move endpoints and NumberOfUSBEndpoints to usb.go
1 parent 0f3d0c3 commit 05c92e4

File tree

6 files changed

+24
-83
lines changed

6 files changed

+24
-83
lines changed

builder/sizes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestBinarySize(t *testing.T) {
4444
// microcontrollers
4545
{"hifive1b", "examples/echo", 4580, 280, 0, 2264},
4646
{"microbit", "examples/serial", 2928, 388, 8, 2272},
47-
{"wioterminal", "examples/pininterrupt", 7444, 1500, 116, 6592},
47+
{"wioterminal", "examples/pininterrupt", 7442, 1502, 116, 6592},
4848

4949
// TODO: also check wasm. Right now this is difficult, because
5050
// wasm binaries are run through wasm-opt and therefore the

src/machine/machine_atsamd21_usb.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@ const (
1919

2020
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
2121
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
22-
23-
NumberOfUSBEndpoints = 6
24-
)
25-
26-
var (
27-
inEndpoints = []uint32{
28-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
29-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
30-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
31-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
32-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
33-
usb.MSC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
34-
}
35-
outEndpoints = []uint32{
36-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
37-
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
38-
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
39-
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
40-
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
41-
}
4222
)
4323

4424
// Configure the USB peripheral. The config is here for compatibility with the UART interface.
@@ -193,7 +173,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
193173

194174
// Now the actual transfer handlers, ignore endpoint number 0 (setup)
195175
var i uint32
196-
for i = 1; i < NumberOfUSBEndpoints; i++ {
176+
for i = 1; i < uint32(NumberOfUSBEndpoints); i++ {
197177
// Check if endpoint has a pending interrupt
198178
epFlags := getEPINTFLAG(i)
199179
setEPINTFLAG(i, epFlags)

src/machine/machine_atsamd51_usb.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@ const (
1919

2020
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
2121
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
22-
23-
NumberOfUSBEndpoints = 6
24-
)
25-
26-
var (
27-
inEndpoints = []uint32{
28-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
29-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
30-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
31-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
32-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
33-
usb.MSC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
34-
}
35-
outEndpoints = []uint32{
36-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
37-
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
38-
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
39-
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
40-
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
41-
}
4222
)
4323

4424
// Configure the USB peripheral. The config is here for compatibility with the UART interface.
@@ -196,7 +176,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
196176

197177
// Now the actual transfer handlers, ignore endpoint number 0 (setup)
198178
var i uint32
199-
for i = 1; i < NumberOfUSBEndpoints; i++ {
179+
for i = 1; i < uint32(NumberOfUSBEndpoints); i++ {
200180
// Check if endpoint has a pending interrupt
201181
epFlags := getEPINTFLAG(i)
202182
setEPINTFLAG(i, epFlags)

src/machine/machine_nrf52840_usb.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
const NumberOfUSBEndpoints = 6
15-
1614
var (
1715
sendOnEP0DATADONE struct {
1816
ptr *byte
@@ -22,22 +20,6 @@ var (
2220
epinen uint32
2321
epouten uint32
2422
easyDMABusy volatile.Register8
25-
26-
inEndpoints = []uint32{
27-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
28-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
29-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
30-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
31-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
32-
usb.MSC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
33-
}
34-
outEndpoints = []uint32{
35-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
36-
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
37-
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
38-
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
39-
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
40-
}
4123
)
4224

4325
// enterCriticalSection is used to protect access to easyDMA - only one thing
@@ -188,7 +170,7 @@ func handleUSBIRQ(interrupt.Interrupt) {
188170
epDataStatus := nrf.USBD.EPDATASTATUS.Get()
189171
nrf.USBD.EPDATASTATUS.Set(epDataStatus)
190172
var i uint32
191-
for i = 1; i < NumberOfUSBEndpoints; i++ {
173+
for i = 1; i < uint32(NumberOfUSBEndpoints); i++ {
192174
// Check if endpoint has a pending interrupt
193175
inDataDone := epDataStatus&(nrf.USBD_EPDATASTATUS_EPIN1<<(i-1)) > 0
194176
outDataDone := epDataStatus&(nrf.USBD_EPDATASTATUS_EPOUT1<<(i-1)) > 0

src/machine/machine_rp2_usb.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,12 @@ import (
88
"unsafe"
99
)
1010

11-
// If inEndpoints or outEndpoints is added to, this must be updated.
12-
const NumberOfUSBEndpoints = 6
13-
1411
var (
1512
sendOnEP0DATADONE struct {
1613
offset int
1714
data []byte
1815
pid uint32
1916
}
20-
21-
inEndpoints = []uint32{
22-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
23-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
24-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
25-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
26-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
27-
usb.MSC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
28-
}
29-
outEndpoints = []uint32{
30-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
31-
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
32-
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
33-
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
34-
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
35-
}
3617
)
3718

3819
func initEndpoint(ep, config uint32) {

src/machine/usb.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,29 @@ var udd_ep_out_cache_buffer [NumberOfUSBEndpoints][64]uint8
119119
// must be revisited.
120120
var usb_trans_buffer [255]uint8
121121

122+
const NumberOfUSBEndpoints = max(len(inEndpoints), len(outEndpoints))
123+
122124
var (
123125
usbTxHandler [NumberOfUSBEndpoints]func()
124126
usbRxHandler [NumberOfUSBEndpoints]func([]byte) bool
125127
usbSetupHandler [usb.NumberOfInterfaces]func(usb.Setup) bool
126128
usbStallHandler [NumberOfUSBEndpoints]func(usb.Setup) bool
129+
130+
inEndpoints = [...]uint32{
131+
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
132+
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
133+
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
134+
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
135+
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
136+
usb.MSC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
137+
}
138+
outEndpoints = [...]uint32{
139+
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
140+
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
141+
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
142+
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
143+
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
144+
}
127145
)
128146

129147
// sendDescriptor creates and sends the various USB descriptor types that
@@ -202,7 +220,7 @@ func handleStandardSetup(setup usb.Setup) bool {
202220
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
203221
isRemoteWakeUpEnabled = false
204222
} else if setup.WValueL == 0 { // ENDPOINTHALT
205-
if idx := setup.WIndex & 0x7F; idx < NumberOfUSBEndpoints && usbStallHandler[idx] != nil {
223+
if idx := setup.WIndex & 0x7F; idx < uint16(NumberOfUSBEndpoints) && usbStallHandler[idx] != nil {
206224
// Host has requested to clear an endpoint stall. If the request is addressed to
207225
// an endpoint with a configured StallHandler, forward the message on.
208226
// The 0x7F mask is used to clear the direction bit from the endpoint number
@@ -217,7 +235,7 @@ func handleStandardSetup(setup usb.Setup) bool {
217235
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
218236
isRemoteWakeUpEnabled = true
219237
} else if setup.WValueL == 0 { // ENDPOINTHALT
220-
if idx := setup.WIndex & 0x7F; idx < NumberOfUSBEndpoints && usbStallHandler[idx] != nil {
238+
if idx := setup.WIndex & 0x7F; idx < uint16(NumberOfUSBEndpoints) && usbStallHandler[idx] != nil {
221239
// Host has requested to stall an endpoint. If the request is addressed to
222240
// an endpoint with a configured StallHandler, forward the message on.
223241
// The 0x7F mask is used to clear the direction bit from the endpoint number

0 commit comments

Comments
 (0)