usb: sam0: Implement missing API functions

This implements three API functions that are required for
tests/subsys/usb/device to build:

 - usb_dc_ep_disable()
 - usb_dc_ep_halt()
 - usb_dc_ep_flush()

While halt and disable are trivial, flush is just a stub for now.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
This commit is contained in:
Benjamin Valentin 2019-04-23 15:05:06 +02:00 committed by Kumar Gala
commit c8208a399a

View file

@ -423,6 +423,28 @@ int usb_dc_ep_is_stalled(const u8_t ep, u8_t *stalled)
return 0; return 0;
} }
/* Halt the selected endpoint */
int usb_dc_ep_halt(u8_t ep)
{
return usb_dc_ep_set_stall(ep);
}
/* Flush the selected endpoint */
int usb_dc_ep_flush(u8_t ep)
{
u8_t ep_num = ep & ~USB_EP_DIR_MASK;
if (ep_num >= USB_NUM_ENDPOINTS) {
LOG_ERR("endpoint index/address out of range");
return -1;
}
/* TODO */
LOG_WRN("flush not implemented");
return 0;
}
/* Enable an endpoint and the endpoint interrupts */ /* Enable an endpoint and the endpoint interrupts */
int usb_dc_ep_enable(const u8_t ep) int usb_dc_ep_enable(const u8_t ep)
{ {
@ -449,6 +471,25 @@ int usb_dc_ep_enable(const u8_t ep)
return 0; return 0;
} }
/* Disable the selected endpoint */
int usb_dc_ep_disable(u8_t ep)
{
UsbDevice *regs = &REGS->DEVICE;
u8_t ep_num = ep & ~USB_EP_DIR_MASK;
UsbDeviceEndpoint *endpoint = &regs->DeviceEndpoint[ep_num];
if (ep_num >= USB_NUM_ENDPOINTS) {
LOG_ERR("endpoint index/address out of range");
return -1;
}
endpoint->EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0
| USB_DEVICE_EPINTENCLR_TRCPT1
| USB_DEVICE_EPINTENCLR_RXSTP;
return 0;
}
/* Write a single payload to the IN buffer on the endpoint */ /* Write a single payload to the IN buffer on the endpoint */
int usb_dc_ep_write(u8_t ep, const u8_t *buf, u32_t len, u32_t *ret_bytes) int usb_dc_ep_write(u8_t ep, const u8_t *buf, u32_t len, u32_t *ret_bytes)
{ {