@@ -20,19 +20,24 @@ const (
20
20
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
21
21
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
22
22
23
- NumberOfUSBEndpoints = 8
23
+ NumberOfUSBEndpoints = 6
24
24
)
25
25
26
26
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 {
28
36
usb .CONTROL_ENDPOINT : usb .ENDPOINT_TYPE_CONTROL ,
29
- usb .CDC_ENDPOINT_ACM : (usb .ENDPOINT_TYPE_INTERRUPT | usb .EndpointIn ),
30
37
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
38
usb .HID_ENDPOINT_OUT : (usb .ENDPOINT_TYPE_DISABLE ), // Interrupt Out
34
- usb .MIDI_ENDPOINT_IN : (usb .ENDPOINT_TYPE_DISABLE ), // Bulk In
35
39
usb .MIDI_ENDPOINT_OUT : (usb .ENDPOINT_TYPE_DISABLE ), // Bulk Out
40
+ usb .MSC_ENDPOINT_OUT : (usb .ENDPOINT_TYPE_DISABLE ), // Bulk Out
36
41
}
37
42
)
38
43
@@ -188,7 +193,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
188
193
189
194
// Now the actual transfer handlers, ignore endpoint number 0 (setup)
190
195
var i uint32
191
- for i = 1 ; i < uint32 ( len ( endPoints )) ; i ++ {
196
+ for i = 1 ; i < NumberOfUSBEndpoints ; i ++ {
192
197
// Check if endpoint has a pending interrupt
193
198
epFlags := getEPINTFLAG (i )
194
199
setEPINTFLAG (i , epFlags )
@@ -197,7 +202,8 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
197
202
if usbRxHandler [i ] == nil || usbRxHandler [i ](buf ) {
198
203
AckUsbOutTransfer (i )
199
204
}
200
- } else if (epFlags & sam .USB_DEVICE_EPINTFLAG_TRCPT1 ) > 0 {
205
+ }
206
+ if (epFlags & sam .USB_DEVICE_EPINTFLAG_TRCPT1 ) > 0 {
201
207
if usbTxHandler [i ] != nil {
202
208
usbTxHandler [i ]()
203
209
}
@@ -215,8 +221,9 @@ func initEndpoint(ep, config uint32) {
215
221
usbEndpointDescriptors [ep ].DeviceDescBank [1 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_in_cache_buffer [ep ]))))
216
222
217
223
// 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 ))
219
225
226
+ // Set interrupt enable
220
227
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
221
228
222
229
case usb .ENDPOINT_TYPE_BULK | usb .EndpointOut :
@@ -227,7 +234,7 @@ func initEndpoint(ep, config uint32) {
227
234
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_out_cache_buffer [ep ]))))
228
235
229
236
// 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 ))
231
238
232
239
// receive interrupts when current transfer complete
233
240
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
@@ -246,7 +253,7 @@ func initEndpoint(ep, config uint32) {
246
253
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_out_cache_buffer [ep ]))))
247
254
248
255
// 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 ))
250
257
251
258
// receive interrupts when current transfer complete
252
259
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
@@ -265,11 +272,12 @@ func initEndpoint(ep, config uint32) {
265
272
usbEndpointDescriptors [ep ].DeviceDescBank [1 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_in_cache_buffer [ep ]))))
266
273
267
274
// 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 ))
269
276
270
277
// NAK on endpoint IN, the bank is not yet filled in.
271
278
setEPSTATUSCLR (ep , sam .USB_DEVICE_EPSTATUSCLR_BK1RDY )
272
279
280
+ // Set interrupt enable
273
281
setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
274
282
275
283
case usb .ENDPOINT_TYPE_CONTROL :
@@ -281,7 +289,7 @@ func initEndpoint(ep, config uint32) {
281
289
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_out_cache_buffer [ep ]))))
282
290
283
291
// 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 ))
285
293
286
294
// Control IN
287
295
// set packet size
@@ -291,7 +299,7 @@ func initEndpoint(ep, config uint32) {
291
299
usbEndpointDescriptors [ep ].DeviceDescBank [1 ].ADDR .Set (uint32 (uintptr (unsafe .Pointer (& udd_ep_in_cache_buffer [ep ]))))
292
300
293
301
// 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 ))
295
303
296
304
// Prepare OUT endpoint for receive
297
305
// set multi packet size for expected number of receive bytes on control OUT
@@ -426,7 +434,6 @@ func AckUsbOutTransfer(ep uint32) {
426
434
427
435
// set ready for next data
428
436
setEPSTATUSCLR (ep , sam .USB_DEVICE_EPSTATUSCLR_BK0RDY )
429
-
430
437
}
431
438
432
439
func SendZlp () {
@@ -479,24 +486,49 @@ func getEPCFG(ep uint32) uint8 {
479
486
}
480
487
}
481
488
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 ) {
483
515
switch ep {
484
516
case 0 :
485
- sam .USB_DEVICE .EPCFG0 . Set (val )
517
+ sam .USB_DEVICE .SetEPCFG0_EPTYPE1 (val )
486
518
case 1 :
487
- sam .USB_DEVICE .EPCFG1 . Set (val )
519
+ sam .USB_DEVICE .SetEPCFG1_EPTYPE1 (val )
488
520
case 2 :
489
- sam .USB_DEVICE .EPCFG2 . Set (val )
521
+ sam .USB_DEVICE .SetEPCFG2_EPTYPE1 (val )
490
522
case 3 :
491
- sam .USB_DEVICE .EPCFG3 . Set (val )
523
+ sam .USB_DEVICE .SetEPCFG3_EPTYPE1 (val )
492
524
case 4 :
493
- sam .USB_DEVICE .EPCFG4 . Set (val )
525
+ sam .USB_DEVICE .SetEPCFG4_EPTYPE1 (val )
494
526
case 5 :
495
- sam .USB_DEVICE .EPCFG5 . Set (val )
527
+ sam .USB_DEVICE .SetEPCFG5_EPTYPE1 (val )
496
528
case 6 :
497
- sam .USB_DEVICE .EPCFG6 . Set (val )
529
+ sam .USB_DEVICE .SetEPCFG6_EPTYPE1 (val )
498
530
case 7 :
499
- sam .USB_DEVICE .EPCFG7 . Set (val )
531
+ sam .USB_DEVICE .SetEPCFG7_EPTYPE1 (val )
500
532
default :
501
533
return
502
534
}
0 commit comments