Skip to content

Commit 0f3d0c3

Browse files
committed
feat: allow bidirectional usb endpoint numbers
1 parent 3869f76 commit 0f3d0c3

File tree

14 files changed

+242
-146
lines changed

14 files changed

+242
-146
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", 7387, 1489, 116, 6912},
47+
{"wioterminal", "examples/pininterrupt", 7444, 1500, 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: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ const (
2020
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
2121
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
2222

23-
NumberOfUSBEndpoints = 8
23+
NumberOfUSBEndpoints = 6
2424
)
2525

2626
var (
27-
endPoints = []uint32{
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{
2836
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
29-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
3037
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
31-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
32-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
3338
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
34-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
3539
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
40+
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
3641
}
3742
)
3843

@@ -188,7 +193,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
188193

189194
// Now the actual transfer handlers, ignore endpoint number 0 (setup)
190195
var i uint32
191-
for i = 1; i < uint32(len(endPoints)); i++ {
196+
for i = 1; i < NumberOfUSBEndpoints; i++ {
192197
// Check if endpoint has a pending interrupt
193198
epFlags := getEPINTFLAG(i)
194199
setEPINTFLAG(i, epFlags)
@@ -197,7 +202,8 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
197202
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
198203
AckUsbOutTransfer(i)
199204
}
200-
} else if (epFlags & sam.USB_DEVICE_EPINTFLAG_TRCPT1) > 0 {
205+
}
206+
if (epFlags & sam.USB_DEVICE_EPINTFLAG_TRCPT1) > 0 {
201207
if usbTxHandler[i] != nil {
202208
usbTxHandler[i]()
203209
}
@@ -215,8 +221,9 @@ func initEndpoint(ep, config uint32) {
215221
usbEndpointDescriptors[ep].DeviceDescBank[1].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_in_cache_buffer[ep]))))
216222

217223
// set endpoint type
218-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_INTERRUPT + 1) << sam.USB_DEVICE_EPCFG_EPTYPE1_Pos))
224+
setEPCFGEPType1(ep, (usb.ENDPOINT_TYPE_INTERRUPT + 1))
219225

226+
// Set interrupt enable
220227
setEPINTENSET(ep, sam.USB_DEVICE_EPINTENSET_TRCPT1)
221228

222229
case usb.ENDPOINT_TYPE_BULK | usb.EndpointOut:
@@ -227,7 +234,7 @@ func initEndpoint(ep, config uint32) {
227234
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
228235

229236
// set endpoint type
230-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_BULK + 1) << sam.USB_DEVICE_EPCFG_EPTYPE0_Pos))
237+
setEPCFGEPType0(ep, (usb.ENDPOINT_TYPE_BULK + 1))
231238

232239
// receive interrupts when current transfer complete
233240
setEPINTENSET(ep, sam.USB_DEVICE_EPINTENSET_TRCPT0)
@@ -246,7 +253,7 @@ func initEndpoint(ep, config uint32) {
246253
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
247254

248255
// set endpoint type
249-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_INTERRUPT + 1) << sam.USB_DEVICE_EPCFG_EPTYPE0_Pos))
256+
setEPCFGEPType0(ep, (usb.ENDPOINT_TYPE_INTERRUPT + 1))
250257

251258
// receive interrupts when current transfer complete
252259
setEPINTENSET(ep, sam.USB_DEVICE_EPINTENSET_TRCPT0)
@@ -265,11 +272,12 @@ func initEndpoint(ep, config uint32) {
265272
usbEndpointDescriptors[ep].DeviceDescBank[1].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_in_cache_buffer[ep]))))
266273

267274
// set endpoint type
268-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_BULK + 1) << sam.USB_DEVICE_EPCFG_EPTYPE1_Pos))
275+
setEPCFGEPType1(ep, (usb.ENDPOINT_TYPE_BULK + 1))
269276

270277
// NAK on endpoint IN, the bank is not yet filled in.
271278
setEPSTATUSCLR(ep, sam.USB_DEVICE_EPSTATUSCLR_BK1RDY)
272279

280+
// Set interrupt enable
273281
setEPINTENSET(ep, sam.USB_DEVICE_EPINTENSET_TRCPT1)
274282

275283
case usb.ENDPOINT_TYPE_CONTROL:
@@ -281,7 +289,7 @@ func initEndpoint(ep, config uint32) {
281289
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
282290

283291
// set endpoint type
284-
setEPCFG(ep, getEPCFG(ep)|((usb.ENDPOINT_TYPE_CONTROL+1)<<sam.USB_DEVICE_EPCFG_EPTYPE0_Pos))
292+
setEPCFGEPType0(ep, (usb.ENDPOINT_TYPE_CONTROL + 1))
285293

286294
// Control IN
287295
// set packet size
@@ -291,7 +299,7 @@ func initEndpoint(ep, config uint32) {
291299
usbEndpointDescriptors[ep].DeviceDescBank[1].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_in_cache_buffer[ep]))))
292300

293301
// set endpoint type
294-
setEPCFG(ep, getEPCFG(ep)|((usb.ENDPOINT_TYPE_CONTROL+1)<<sam.USB_DEVICE_EPCFG_EPTYPE1_Pos))
302+
setEPCFGEPType1(ep, (usb.ENDPOINT_TYPE_CONTROL + 1))
295303

296304
// Prepare OUT endpoint for receive
297305
// set multi packet size for expected number of receive bytes on control OUT
@@ -426,7 +434,6 @@ func AckUsbOutTransfer(ep uint32) {
426434

427435
// set ready for next data
428436
setEPSTATUSCLR(ep, sam.USB_DEVICE_EPSTATUSCLR_BK0RDY)
429-
430437
}
431438

432439
func SendZlp() {
@@ -479,24 +486,49 @@ func getEPCFG(ep uint32) uint8 {
479486
}
480487
}
481488

482-
func setEPCFG(ep uint32, val uint8) {
489+
// Configure output endpoint in EPCFG
490+
func setEPCFGEPType0(ep uint32, val uint8) {
491+
switch ep {
492+
case 0:
493+
sam.USB_DEVICE.SetEPCFG0_EPTYPE0(val)
494+
case 1:
495+
sam.USB_DEVICE.SetEPCFG1_EPTYPE0(val)
496+
case 2:
497+
sam.USB_DEVICE.SetEPCFG2_EPTYPE0(val)
498+
case 3:
499+
sam.USB_DEVICE.SetEPCFG3_EPTYPE0(val)
500+
case 4:
501+
sam.USB_DEVICE.SetEPCFG4_EPTYPE0(val)
502+
case 5:
503+
sam.USB_DEVICE.SetEPCFG5_EPTYPE0(val)
504+
case 6:
505+
sam.USB_DEVICE.SetEPCFG6_EPTYPE0(val)
506+
case 7:
507+
sam.USB_DEVICE.SetEPCFG7_EPTYPE0(val)
508+
default:
509+
return
510+
}
511+
}
512+
513+
// Configure input endpoint in EPCFG
514+
func setEPCFGEPType1(ep uint32, val uint8) {
483515
switch ep {
484516
case 0:
485-
sam.USB_DEVICE.EPCFG0.Set(val)
517+
sam.USB_DEVICE.SetEPCFG0_EPTYPE1(val)
486518
case 1:
487-
sam.USB_DEVICE.EPCFG1.Set(val)
519+
sam.USB_DEVICE.SetEPCFG1_EPTYPE1(val)
488520
case 2:
489-
sam.USB_DEVICE.EPCFG2.Set(val)
521+
sam.USB_DEVICE.SetEPCFG2_EPTYPE1(val)
490522
case 3:
491-
sam.USB_DEVICE.EPCFG3.Set(val)
523+
sam.USB_DEVICE.SetEPCFG3_EPTYPE1(val)
492524
case 4:
493-
sam.USB_DEVICE.EPCFG4.Set(val)
525+
sam.USB_DEVICE.SetEPCFG4_EPTYPE1(val)
494526
case 5:
495-
sam.USB_DEVICE.EPCFG5.Set(val)
527+
sam.USB_DEVICE.SetEPCFG5_EPTYPE1(val)
496528
case 6:
497-
sam.USB_DEVICE.EPCFG6.Set(val)
529+
sam.USB_DEVICE.SetEPCFG6_EPTYPE1(val)
498530
case 7:
499-
sam.USB_DEVICE.EPCFG7.Set(val)
531+
sam.USB_DEVICE.SetEPCFG7_EPTYPE1(val)
500532
default:
501533
return
502534
}

src/machine/machine_atsamd51_usb.go

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ const (
2020
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
2121
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
2222

23-
NumberOfUSBEndpoints = 8
23+
NumberOfUSBEndpoints = 6
2424
)
2525

2626
var (
27-
endPoints = []uint32{
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{
2836
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
29-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
3037
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
31-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
32-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
3338
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
34-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
3539
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
40+
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
3641
}
3742
)
3843

@@ -191,7 +196,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
191196

192197
// Now the actual transfer handlers, ignore endpoint number 0 (setup)
193198
var i uint32
194-
for i = 1; i < uint32(len(endPoints)); i++ {
199+
for i = 1; i < NumberOfUSBEndpoints; i++ {
195200
// Check if endpoint has a pending interrupt
196201
epFlags := getEPINTFLAG(i)
197202
setEPINTFLAG(i, epFlags)
@@ -200,7 +205,8 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
200205
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
201206
AckUsbOutTransfer(i)
202207
}
203-
} else if (epFlags & sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT1) > 0 {
208+
}
209+
if (epFlags & sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT1) > 0 {
204210
if usbTxHandler[i] != nil {
205211
usbTxHandler[i]()
206212
}
@@ -218,8 +224,9 @@ func initEndpoint(ep, config uint32) {
218224
usbEndpointDescriptors[ep].DeviceDescBank[1].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_in_cache_buffer[ep]))))
219225

220226
// set endpoint type
221-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_INTERRUPT + 1) << sam.USB_DEVICE_ENDPOINT_EPCFG_EPTYPE1_Pos))
227+
setEPCFGEPType1(ep, (usb.ENDPOINT_TYPE_INTERRUPT + 1))
222228

229+
// Set interrupt enable
223230
setEPINTENSET(ep, sam.USB_DEVICE_ENDPOINT_EPINTENSET_TRCPT1)
224231

225232
case usb.ENDPOINT_TYPE_BULK | usb.EndpointOut:
@@ -230,7 +237,7 @@ func initEndpoint(ep, config uint32) {
230237
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
231238

232239
// set endpoint type
233-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_BULK + 1) << sam.USB_DEVICE_ENDPOINT_EPCFG_EPTYPE0_Pos))
240+
setEPCFGEPType0(ep, (usb.ENDPOINT_TYPE_BULK + 1))
234241

235242
// receive interrupts when current transfer complete
236243
setEPINTENSET(ep, sam.USB_DEVICE_ENDPOINT_EPINTENSET_TRCPT0)
@@ -249,7 +256,7 @@ func initEndpoint(ep, config uint32) {
249256
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
250257

251258
// set endpoint type
252-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_INTERRUPT + 1) << sam.USB_DEVICE_ENDPOINT_EPCFG_EPTYPE0_Pos))
259+
setEPCFGEPType0(ep, (usb.ENDPOINT_TYPE_INTERRUPT + 1))
253260

254261
// receive interrupts when current transfer complete
255262
setEPINTENSET(ep, sam.USB_DEVICE_ENDPOINT_EPINTENSET_TRCPT0)
@@ -268,11 +275,12 @@ func initEndpoint(ep, config uint32) {
268275
usbEndpointDescriptors[ep].DeviceDescBank[1].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_in_cache_buffer[ep]))))
269276

270277
// set endpoint type
271-
setEPCFG(ep, ((usb.ENDPOINT_TYPE_BULK + 1) << sam.USB_DEVICE_ENDPOINT_EPCFG_EPTYPE1_Pos))
278+
setEPCFGEPType1(ep, (usb.ENDPOINT_TYPE_BULK + 1))
272279

273280
// NAK on endpoint IN, the bank is not yet filled in.
274281
setEPSTATUSCLR(ep, sam.USB_DEVICE_ENDPOINT_EPSTATUSCLR_BK1RDY)
275282

283+
// Set interrupt enable
276284
setEPINTENSET(ep, sam.USB_DEVICE_ENDPOINT_EPINTENSET_TRCPT1)
277285

278286
case usb.ENDPOINT_TYPE_CONTROL:
@@ -284,7 +292,7 @@ func initEndpoint(ep, config uint32) {
284292
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
285293

286294
// set endpoint type
287-
setEPCFG(ep, getEPCFG(ep)|((usb.ENDPOINT_TYPE_CONTROL+1)<<sam.USB_DEVICE_ENDPOINT_EPCFG_EPTYPE0_Pos))
295+
setEPCFGEPType0(ep, (usb.ENDPOINT_TYPE_CONTROL + 1))
288296

289297
// Control IN
290298
// set packet size
@@ -294,7 +302,7 @@ func initEndpoint(ep, config uint32) {
294302
usbEndpointDescriptors[ep].DeviceDescBank[1].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_in_cache_buffer[ep]))))
295303

296304
// set endpoint type
297-
setEPCFG(ep, getEPCFG(ep)|((usb.ENDPOINT_TYPE_CONTROL+1)<<sam.USB_DEVICE_ENDPOINT_EPCFG_EPTYPE1_Pos))
305+
setEPCFGEPType1(ep, (usb.ENDPOINT_TYPE_CONTROL + 1))
298306

299307
// Prepare OUT endpoint for receive
300308
// set multi packet size for expected number of receive bytes on control OUT
@@ -462,8 +470,14 @@ func getEPCFG(ep uint32) uint8 {
462470
return sam.USB_DEVICE.DEVICE_ENDPOINT[ep].EPCFG.Get()
463471
}
464472

465-
func setEPCFG(ep uint32, val uint8) {
466-
sam.USB_DEVICE.DEVICE_ENDPOINT[ep].EPCFG.Set(val)
473+
// Configure output endpoint in EPCFG
474+
func setEPCFGEPType0(ep uint32, val uint8) {
475+
sam.USB_DEVICE.DEVICE_ENDPOINT[ep].SetEPCFG_EPTYPE0(val)
476+
}
477+
478+
// Configure input endpoint in EPCFG
479+
func setEPCFGEPType1(ep uint32, val uint8) {
480+
sam.USB_DEVICE.DEVICE_ENDPOINT[ep].SetEPCFG_EPTYPE1(val)
467481
}
468482

469483
func setEPSTATUSCLR(ep uint32, val uint8) {

src/machine/machine_nrf52840_usb.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"unsafe"
1212
)
1313

14-
const NumberOfUSBEndpoints = 8
14+
const NumberOfUSBEndpoints = 6
1515

1616
var (
1717
sendOnEP0DATADONE struct {
@@ -23,15 +23,20 @@ var (
2323
epouten uint32
2424
easyDMABusy volatile.Register8
2525

26-
endPoints = []uint32{
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{
2735
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
28-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
2936
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
30-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
31-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
3237
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
33-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
3438
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
39+
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
3540
}
3641
)
3742

@@ -183,15 +188,16 @@ func handleUSBIRQ(interrupt.Interrupt) {
183188
epDataStatus := nrf.USBD.EPDATASTATUS.Get()
184189
nrf.USBD.EPDATASTATUS.Set(epDataStatus)
185190
var i uint32
186-
for i = 1; i < uint32(len(endPoints)); i++ {
191+
for i = 1; i < NumberOfUSBEndpoints; i++ {
187192
// Check if endpoint has a pending interrupt
188193
inDataDone := epDataStatus&(nrf.USBD_EPDATASTATUS_EPIN1<<(i-1)) > 0
189194
outDataDone := epDataStatus&(nrf.USBD_EPDATASTATUS_EPOUT1<<(i-1)) > 0
190195
if inDataDone {
191196
if usbTxHandler[i] != nil {
192197
usbTxHandler[i]()
193198
}
194-
} else if outDataDone {
199+
}
200+
if outDataDone {
195201
enterCriticalSection()
196202
nrf.USBD.EPOUT[i].PTR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[i]))))
197203
count := nrf.USBD.SIZE.EPOUT[i].Get()
@@ -202,7 +208,7 @@ func handleUSBIRQ(interrupt.Interrupt) {
202208
}
203209

204210
// ENDEPOUT[n] events
205-
for i := 0; i < len(endPoints); i++ {
211+
for i := 0; i < len(outEndpoints); i++ {
206212
if nrf.USBD.EVENTS_ENDEPOUT[i].Get() > 0 {
207213
nrf.USBD.EVENTS_ENDEPOUT[i].Set(0)
208214
buf := handleEndpointRx(uint32(i))

0 commit comments

Comments
 (0)