Skip to content

Commit 3ad2530

Browse files
sago35deadprogram
authored andcommitted
atsamd21, atsamd51: add support for USB INTERRUPT OUT
1 parent c4de195 commit 3ad2530

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

builder/sizes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestBinarySize(t *testing.T) {
4343
// microcontrollers
4444
{"hifive1b", "examples/echo", 4612, 280, 0, 2252},
4545
{"microbit", "examples/serial", 2724, 388, 8, 2256},
46-
{"wioterminal", "examples/pininterrupt", 6039, 1485, 116, 6816},
46+
{"wioterminal", "examples/pininterrupt", 6063, 1485, 116, 6816},
4747

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

src/machine/machine_atsamd21_usb.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,23 @@ func initEndpoint(ep, config uint32) {
225225
setEPSTATUSCLR(ep, sam.USB_DEVICE_EPSTATUSCLR_BK0RDY)
226226

227227
case usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointOut:
228-
// TODO: not really anything, seems like...
228+
// set packet size
229+
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.SetBits(epPacketSize(64) << usb_DEVICE_PCKSIZE_SIZE_Pos)
230+
231+
// set data buffer address
232+
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
233+
234+
// set endpoint type
235+
setEPCFG(ep, ((usb.ENDPOINT_TYPE_INTERRUPT + 1) << sam.USB_DEVICE_EPCFG_EPTYPE0_Pos))
236+
237+
// receive interrupts when current transfer complete
238+
setEPINTENSET(ep, sam.USB_DEVICE_EPINTENSET_TRCPT0)
239+
240+
// set byte count to zero, we have not received anything yet
241+
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos)
242+
243+
// ready for next transfer
244+
setEPSTATUSCLR(ep, sam.USB_DEVICE_EPSTATUSCLR_BK0RDY)
229245

230246
case usb.ENDPOINT_TYPE_BULK | usb.EndpointIn:
231247
// set packet size

src/machine/machine_atsamd51_usb.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,23 @@ func initEndpoint(ep, config uint32) {
228228
setEPSTATUSCLR(ep, sam.USB_DEVICE_ENDPOINT_EPSTATUSCLR_BK0RDY)
229229

230230
case usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointOut:
231-
// TODO: not really anything, seems like...
231+
// set packet size
232+
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.SetBits(epPacketSize(64) << usb_DEVICE_PCKSIZE_SIZE_Pos)
233+
234+
// set data buffer address
235+
usbEndpointDescriptors[ep].DeviceDescBank[0].ADDR.Set(uint32(uintptr(unsafe.Pointer(&udd_ep_out_cache_buffer[ep]))))
236+
237+
// set endpoint type
238+
setEPCFG(ep, ((usb.ENDPOINT_TYPE_INTERRUPT + 1) << sam.USB_DEVICE_ENDPOINT_EPCFG_EPTYPE0_Pos))
239+
240+
// receive interrupts when current transfer complete
241+
setEPINTENSET(ep, sam.USB_DEVICE_ENDPOINT_EPINTENSET_TRCPT0)
242+
243+
// set byte count to zero, we have not received anything yet
244+
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos)
245+
246+
// ready for next transfer
247+
setEPSTATUSCLR(ep, sam.USB_DEVICE_ENDPOINT_EPSTATUSCLR_BK0RDY)
232248

233249
case usb.ENDPOINT_TYPE_BULK | usb.EndpointIn:
234250
// set packet size

0 commit comments

Comments
 (0)