@@ -19,21 +19,6 @@ const (
19
19
20
20
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
21
21
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
22
-
23
- NumberOfUSBEndpoints = 8
24
- )
25
-
26
- var (
27
- endPoints = []uint32 {
28
- usb .CONTROL_ENDPOINT : usb .ENDPOINT_TYPE_CONTROL ,
29
- usb .CDC_ENDPOINT_ACM : (usb .ENDPOINT_TYPE_INTERRUPT | usb .EndpointIn ),
30
- 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
33
- usb .HID_ENDPOINT_OUT : (usb .ENDPOINT_TYPE_DISABLE ), // Interrupt Out
34
- usb .MIDI_ENDPOINT_IN : (usb .ENDPOINT_TYPE_DISABLE ), // Bulk In
35
- usb .MIDI_ENDPOINT_OUT : (usb .ENDPOINT_TYPE_DISABLE ), // Bulk Out
36
- }
37
22
)
38
23
39
24
// Configure the USB peripheral. The config is here for compatibility with the UART interface.
@@ -188,7 +173,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
188
173
189
174
// Now the actual transfer handlers, ignore endpoint number 0 (setup)
190
175
var i uint32
191
- for i = 1 ; i < uint32 (len ( endPoints ) ); i ++ {
176
+ for i = 1 ; i < uint32 (NumberOfUSBEndpoints ); i ++ {
192
177
// Check if endpoint has a pending interrupt
193
178
epFlags := getEPINTFLAG (i )
194
179
setEPINTFLAG (i , epFlags )
@@ -197,7 +182,8 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
197
182
if usbRxHandler [i ] == nil || usbRxHandler [i ](buf ) {
198
183
AckUsbOutTransfer (i )
199
184
}
200
- } else if (epFlags & sam .USB_DEVICE_EPINTFLAG_TRCPT1 ) > 0 {
185
+ }
186
+ if (epFlags & sam .USB_DEVICE_EPINTFLAG_TRCPT1 ) > 0 {
201
187
if usbTxHandler [i ] != nil {
202
188
usbTxHandler [i ]()
203
189
}
@@ -215,8 +201,9 @@ func initEndpoint(ep, config uint32) {
215
201
usbEndpointDescriptors [ep ].DeviceDescBank [1 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_in_cache_buffer [ep ]))))
216
202
217
203
// set endpoint type
218
- setEPCFG (ep , (( usb .ENDPOINT_TYPE_INTERRUPT + 1 ) << sam . USB_DEVICE_EPCFG_EPTYPE1_Pos ))
204
+ setEPCFGEPType1 (ep , (usb .ENDPOINT_TYPE_INTERRUPT + 1 ))
219
205
206
+ // Set interrupt enable
220
207
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
221
208
222
209
case usb .ENDPOINT_TYPE_BULK | usb .EndpointOut :
@@ -227,7 +214,7 @@ func initEndpoint(ep, config uint32) {
227
214
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_out_cache_buffer [ep ]))))
228
215
229
216
// set endpoint type
230
- setEPCFG (ep , (( usb .ENDPOINT_TYPE_BULK + 1 ) << sam . USB_DEVICE_EPCFG_EPTYPE0_Pos ))
217
+ setEPCFGEPType0 (ep , (usb .ENDPOINT_TYPE_BULK + 1 ))
231
218
232
219
// receive interrupts when current transfer complete
233
220
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
@@ -246,7 +233,7 @@ func initEndpoint(ep, config uint32) {
246
233
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_out_cache_buffer [ep ]))))
247
234
248
235
// set endpoint type
249
- setEPCFG (ep , (( usb .ENDPOINT_TYPE_INTERRUPT + 1 ) << sam . USB_DEVICE_EPCFG_EPTYPE0_Pos ))
236
+ setEPCFGEPType0 (ep , (usb .ENDPOINT_TYPE_INTERRUPT + 1 ))
250
237
251
238
// receive interrupts when current transfer complete
252
239
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
@@ -265,11 +252,12 @@ func initEndpoint(ep, config uint32) {
265
252
usbEndpointDescriptors [ep ].DeviceDescBank [1 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_in_cache_buffer [ep ]))))
266
253
267
254
// set endpoint type
268
- setEPCFG (ep , (( usb .ENDPOINT_TYPE_BULK + 1 ) << sam . USB_DEVICE_EPCFG_EPTYPE1_Pos ))
255
+ setEPCFGEPType1 (ep , (usb .ENDPOINT_TYPE_BULK + 1 ))
269
256
270
257
// NAK on endpoint IN, the bank is not yet filled in.
271
258
setEPSTATUSCLR (ep , sam .USB_DEVICE_EPSTATUSCLR_BK1RDY )
272
259
260
+ // Set interrupt enable
273
261
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
274
262
275
263
case usb .ENDPOINT_TYPE_CONTROL :
@@ -281,7 +269,7 @@ func initEndpoint(ep, config uint32) {
281
269
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_out_cache_buffer [ep ]))))
282
270
283
271
// set endpoint type
284
- setEPCFG (ep , getEPCFG ( ep ) | (( usb .ENDPOINT_TYPE_CONTROL + 1 ) << sam . USB_DEVICE_EPCFG_EPTYPE0_Pos ))
272
+ setEPCFGEPType0 (ep , ( usb .ENDPOINT_TYPE_CONTROL + 1 ))
285
273
286
274
// Control IN
287
275
// set packet size
@@ -291,7 +279,7 @@ func initEndpoint(ep, config uint32) {
291
279
usbEndpointDescriptors [ep ].DeviceDescBank [1 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_in_cache_buffer [ep ]))))
292
280
293
281
// set endpoint type
294
- setEPCFG (ep , getEPCFG ( ep ) | (( usb .ENDPOINT_TYPE_CONTROL + 1 ) << sam . USB_DEVICE_EPCFG_EPTYPE1_Pos ))
282
+ setEPCFGEPType1 (ep , ( usb .ENDPOINT_TYPE_CONTROL + 1 ))
295
283
296
284
// Prepare OUT endpoint for receive
297
285
// set multi packet size for expected number of receive bytes on control OUT
@@ -426,7 +414,6 @@ func AckUsbOutTransfer(ep uint32) {
426
414
427
415
// set ready for next data
428
416
setEPSTATUSCLR (ep , sam .USB_DEVICE_EPSTATUSCLR_BK0RDY )
429
-
430
417
}
431
418
432
419
func SendZlp () {
@@ -479,24 +466,49 @@ func getEPCFG(ep uint32) uint8 {
479
466
}
480
467
}
481
468
482
- func setEPCFG (ep uint32 , val uint8 ) {
469
+ // Configure output endpoint in EPCFG
470
+ func setEPCFGEPType0 (ep uint32 , val uint8 ) {
471
+ switch ep {
472
+ case 0 :
473
+ sam .USB_DEVICE .SetEPCFG0_EPTYPE0 (val )
474
+ case 1 :
475
+ sam .USB_DEVICE .SetEPCFG1_EPTYPE0 (val )
476
+ case 2 :
477
+ sam .USB_DEVICE .SetEPCFG2_EPTYPE0 (val )
478
+ case 3 :
479
+ sam .USB_DEVICE .SetEPCFG3_EPTYPE0 (val )
480
+ case 4 :
481
+ sam .USB_DEVICE .SetEPCFG4_EPTYPE0 (val )
482
+ case 5 :
483
+ sam .USB_DEVICE .SetEPCFG5_EPTYPE0 (val )
484
+ case 6 :
485
+ sam .USB_DEVICE .SetEPCFG6_EPTYPE0 (val )
486
+ case 7 :
487
+ sam .USB_DEVICE .SetEPCFG7_EPTYPE0 (val )
488
+ default :
489
+ return
490
+ }
491
+ }
492
+
493
+ // Configure input endpoint in EPCFG
494
+ func setEPCFGEPType1 (ep uint32 , val uint8 ) {
483
495
switch ep {
484
496
case 0 :
485
- sam .USB_DEVICE .EPCFG0 . Set (val )
497
+ sam .USB_DEVICE .SetEPCFG0_EPTYPE1 (val )
486
498
case 1 :
487
- sam .USB_DEVICE .EPCFG1 . Set (val )
499
+ sam .USB_DEVICE .SetEPCFG1_EPTYPE1 (val )
488
500
case 2 :
489
- sam .USB_DEVICE .EPCFG2 . Set (val )
501
+ sam .USB_DEVICE .SetEPCFG2_EPTYPE1 (val )
490
502
case 3 :
491
- sam .USB_DEVICE .EPCFG3 . Set (val )
503
+ sam .USB_DEVICE .SetEPCFG3_EPTYPE1 (val )
492
504
case 4 :
493
- sam .USB_DEVICE .EPCFG4 . Set (val )
505
+ sam .USB_DEVICE .SetEPCFG4_EPTYPE1 (val )
494
506
case 5 :
495
- sam .USB_DEVICE .EPCFG5 . Set (val )
507
+ sam .USB_DEVICE .SetEPCFG5_EPTYPE1 (val )
496
508
case 6 :
497
- sam .USB_DEVICE .EPCFG6 . Set (val )
509
+ sam .USB_DEVICE .SetEPCFG6_EPTYPE1 (val )
498
510
case 7 :
499
- sam .USB_DEVICE .EPCFG7 . Set (val )
511
+ sam .USB_DEVICE .SetEPCFG7_EPTYPE1 (val )
500
512
default :
501
513
return
502
514
}
0 commit comments