@@ -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,9 +221,10 @@ 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
220
- setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
226
+ // Set interrupt enable
227
+ setEPINTENSETTRCPT1 (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
221
228
222
229
case usb .ENDPOINT_TYPE_BULK | usb .EndpointOut :
223
230
// set packet size
@@ -227,10 +234,10 @@ 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
- setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
240
+ setEPINTENSETTRCPT0 (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
234
241
235
242
// set byte count to zero, we have not received anything yet
236
243
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].PCKSIZE .ClearBits (usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos )
@@ -246,10 +253,10 @@ 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
- setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
259
+ setEPINTENSETTRCPT0 (ep , sam .USB_DEVICE_EPINTENSET_TRCPT0 )
253
260
254
261
// set byte count to zero, we have not received anything yet
255
262
usbEndpointDescriptors [ep ].DeviceDescBank [0 ].PCKSIZE .ClearBits (usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos )
@@ -265,12 +272,13 @@ 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
273
- setEPINTENSET (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
280
+ // Set interrupt enable
281
+ setEPINTENSETTRCPT1 (ep , sam .USB_DEVICE_EPINTENSET_TRCPT1 )
274
282
275
283
case usb .ENDPOINT_TYPE_CONTROL :
276
284
// Control OUT
@@ -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
@@ -304,7 +312,7 @@ func initEndpoint(ep, config uint32) {
304
312
setEPSTATUSSET (ep , sam .USB_DEVICE_EPSTATUSSET_BK0RDY )
305
313
306
314
// Enable Setup-Received interrupt
307
- setEPINTENSET (0 , sam .USB_DEVICE_EPINTENSET_RXSTP )
315
+ setEPINTENSETRXSTP (0 , sam .USB_DEVICE_EPINTENSET_RXSTP )
308
316
}
309
317
}
310
318
@@ -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,47 @@ func getEPCFG(ep uint32) uint8 {
479
486
}
480
487
}
481
488
482
- func setEPCFG (ep uint32 , val uint8 ) {
489
+ func setEPCFGEPType0 (ep uint32 , val uint8 ) {
483
490
switch ep {
484
491
case 0 :
485
- sam .USB_DEVICE .EPCFG0 . Set (val )
492
+ sam .USB_DEVICE .SetEPCFG0_EPTYPE0 (val )
486
493
case 1 :
487
- sam .USB_DEVICE .EPCFG1 . Set (val )
494
+ sam .USB_DEVICE .SetEPCFG1_EPTYPE0 (val )
488
495
case 2 :
489
- sam .USB_DEVICE .EPCFG2 . Set (val )
496
+ sam .USB_DEVICE .SetEPCFG2_EPTYPE0 (val )
490
497
case 3 :
491
- sam .USB_DEVICE .EPCFG3 . Set (val )
498
+ sam .USB_DEVICE .SetEPCFG3_EPTYPE0 (val )
492
499
case 4 :
493
- sam .USB_DEVICE .EPCFG4 . Set (val )
500
+ sam .USB_DEVICE .SetEPCFG4_EPTYPE0 (val )
494
501
case 5 :
495
- sam .USB_DEVICE .EPCFG5 . Set (val )
502
+ sam .USB_DEVICE .SetEPCFG5_EPTYPE0 (val )
496
503
case 6 :
497
- sam .USB_DEVICE .EPCFG6 . Set (val )
504
+ sam .USB_DEVICE .SetEPCFG6_EPTYPE0 (val )
498
505
case 7 :
499
- sam .USB_DEVICE .EPCFG7 .Set (val )
506
+ sam .USB_DEVICE .SetEPCFG7_EPTYPE0 (val )
507
+ default :
508
+ return
509
+ }
510
+ }
511
+
512
+ func setEPCFGEPType1 (ep uint32 , val uint8 ) {
513
+ switch ep {
514
+ case 0 :
515
+ sam .USB_DEVICE .SetEPCFG0_EPTYPE1 (val )
516
+ case 1 :
517
+ sam .USB_DEVICE .SetEPCFG1_EPTYPE1 (val )
518
+ case 2 :
519
+ sam .USB_DEVICE .SetEPCFG2_EPTYPE1 (val )
520
+ case 3 :
521
+ sam .USB_DEVICE .SetEPCFG3_EPTYPE1 (val )
522
+ case 4 :
523
+ sam .USB_DEVICE .SetEPCFG4_EPTYPE1 (val )
524
+ case 5 :
525
+ sam .USB_DEVICE .SetEPCFG5_EPTYPE1 (val )
526
+ case 6 :
527
+ sam .USB_DEVICE .SetEPCFG6_EPTYPE1 (val )
528
+ case 7 :
529
+ sam .USB_DEVICE .SetEPCFG7_EPTYPE1 (val )
500
530
default :
501
531
return
502
532
}
@@ -640,25 +670,67 @@ func setEPINTENCLR(ep uint32, val uint8) {
640
670
}
641
671
}
642
672
643
- func setEPINTENSET (ep uint32 , val uint8 ) {
673
+ func setEPINTENSETRXSTP (ep uint32 , val uint8 ) {
644
674
switch ep {
645
675
case 0 :
646
- sam .USB_DEVICE .EPINTENSET0 . Set (val )
676
+ sam .USB_DEVICE .SetEPINTENSET0_RXSTP (val )
647
677
case 1 :
648
- sam .USB_DEVICE .EPINTENSET1 . Set (val )
678
+ sam .USB_DEVICE .SetEPINTENSET1_RXSTP (val )
649
679
case 2 :
650
- sam .USB_DEVICE .EPINTENSET2 . Set (val )
680
+ sam .USB_DEVICE .SetEPINTENSET2_RXSTP (val )
651
681
case 3 :
652
- sam .USB_DEVICE .EPINTENSET3 . Set (val )
682
+ sam .USB_DEVICE .SetEPINTENSET3_RXSTP (val )
653
683
case 4 :
654
- sam .USB_DEVICE .EPINTENSET4 . Set (val )
684
+ sam .USB_DEVICE .SetEPINTENSET4_RXSTP (val )
655
685
case 5 :
656
- sam .USB_DEVICE .EPINTENSET5 . Set (val )
686
+ sam .USB_DEVICE .SetEPINTENSET5_RXSTP (val )
657
687
case 6 :
658
- sam .USB_DEVICE .EPINTENSET6 . Set (val )
688
+ sam .USB_DEVICE .SetEPINTENSET6_RXSTP (val )
659
689
case 7 :
660
- sam .USB_DEVICE .EPINTENSET7 . Set (val )
690
+ sam .USB_DEVICE .SetEPINTENSET7_RXSTP (val )
661
691
default :
662
692
return
663
693
}
664
694
}
695
+
696
+ func setEPINTENSETTRCPT0 (ep uint32 , val uint8 ) {
697
+ switch ep {
698
+ case 0 :
699
+ sam .USB_DEVICE .SetEPINTENSET0_TRCPT0 (val )
700
+ case 1 :
701
+ sam .USB_DEVICE .SetEPINTENSET1_TRCPT0 (val )
702
+ case 2 :
703
+ sam .USB_DEVICE .SetEPINTENSET2_TRCPT0 (val )
704
+ case 3 :
705
+ sam .USB_DEVICE .SetEPINTENSET3_TRCPT0 (val )
706
+ case 4 :
707
+ sam .USB_DEVICE .SetEPINTENSET4_TRCPT0 (val )
708
+ case 5 :
709
+ sam .USB_DEVICE .SetEPINTENSET5_TRCPT0 (val )
710
+ case 6 :
711
+ sam .USB_DEVICE .SetEPINTENSET6_TRCPT0 (val )
712
+ case 7 :
713
+ sam .USB_DEVICE .SetEPINTENSET7_TRCPT0 (val )
714
+ }
715
+ }
716
+
717
+ func setEPINTENSETTRCPT1 (ep uint32 , val uint8 ) {
718
+ switch ep {
719
+ case 0 :
720
+ sam .USB_DEVICE .SetEPINTENSET0_TRCPT1 (val )
721
+ case 1 :
722
+ sam .USB_DEVICE .SetEPINTENSET1_TRCPT1 (val )
723
+ case 2 :
724
+ sam .USB_DEVICE .SetEPINTENSET2_TRCPT1 (val )
725
+ case 3 :
726
+ sam .USB_DEVICE .SetEPINTENSET3_TRCPT1 (val )
727
+ case 4 :
728
+ sam .USB_DEVICE .SetEPINTENSET4_TRCPT1 (val )
729
+ case 5 :
730
+ sam .USB_DEVICE .SetEPINTENSET5_TRCPT1 (val )
731
+ case 6 :
732
+ sam .USB_DEVICE .SetEPINTENSET6_TRCPT1 (val )
733
+ case 7 :
734
+ sam .USB_DEVICE .SetEPINTENSET7_TRCPT1 (val )
735
+ }
736
+ }
0 commit comments