summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-07-04 18:45:10 +0700
committerhathach <[email protected]>2019-07-04 18:45:10 +0700
commitf16ebd512bbaed3971a6e5a28168413279abf4c4 (patch)
tree5787a43f3beea1c6151aa1a9f1bc8c1827b3ce6b /src
parent3ec279b424ea463577420e75db54deebf409be2b (diff)
indent clean up
Diffstat (limited to 'src')
-rw-r--r--src/portable/microchip/samd21/dcd_samd21.c81
-rw-r--r--src/portable/microchip/samd51/dcd_samd51.c78
2 files changed, 81 insertions, 78 deletions
diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c
index 7f3c34959..231abc7d0 100644
--- a/src/portable/microchip/samd21/dcd_samd21.c
+++ b/src/portable/microchip/samd21/dcd_samd21.c
@@ -232,60 +232,63 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
/*------------------------------------------------------------------*/
static bool maybe_handle_setup_packet(void) {
- if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
- {
- USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
+ if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
+ {
+ USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
- // This copies the data elsewhere so we can reuse the buffer.
- dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
- return true;
- }
- return false;
+ // This copies the data elsewhere so we can reuse the buffer.
+ dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
+ return true;
+ }
+ return false;
}
void maybe_transfer_complete(void) {
- uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
- for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
- if ((epints & (1 << epnum)) == 0) {
- continue;
- }
+ uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
+
+ for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
+ if ((epints & (1 << epnum)) == 0) {
+ continue;
+ }
- if (maybe_handle_setup_packet()) {
- continue;
- }
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
+ if (maybe_handle_setup_packet()) {
+ continue;
+ }
- uint32_t epintflag = ep->EPINTFLAG.reg;
+ UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
- uint16_t total_transfer_size = 0;
+ uint32_t epintflag = ep->EPINTFLAG.reg;
- // Handle IN completions
- if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
- ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
+ uint16_t total_transfer_size = 0;
- UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_IN];
- total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
+ // Handle IN completions
+ if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
+ ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
- uint8_t ep_addr = epnum | TUSB_DIR_IN_MASK;
- dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
- }
+ UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_IN];
+ total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
- // Handle OUT completions
- if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT0) != 0) {
- ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
+ uint8_t ep_addr = epnum | TUSB_DIR_IN_MASK;
+ dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
+ }
- UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_OUT];
- total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
+ // Handle OUT completions
+ if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT0) != 0) {
+ ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
- uint8_t ep_addr = epnum;
- dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
- }
+ UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_OUT];
+ total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
- // just finished status stage (total size = 0), prepare for next setup packet
- if (epnum == 0 && total_transfer_size == 0) {
- dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
- }
+ uint8_t ep_addr = epnum;
+ dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
}
+
+ // Just finished status stage (total size = 0), prepare for next setup packet
+ // TODO could cause issue with actual zero length data used by class such as DFU
+ if (epnum == 0 && total_transfer_size == 0) {
+ dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
+ }
+ }
}
void USB_Handler(void)
diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c
index f2aff857c..f58e7cbc7 100644
--- a/src/portable/microchip/samd51/dcd_samd51.c
+++ b/src/portable/microchip/samd51/dcd_samd51.c
@@ -213,9 +213,9 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
- ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
+ ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
} else {
- ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
+ ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
}
}
@@ -236,15 +236,15 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
/*------------------------------------------------------------------*/
static bool maybe_handle_setup_packet(void) {
- if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
- {
- USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
+ if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP)
+ {
+ USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
- // This copies the data elsewhere so we can reuse the buffer.
- dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
- return true;
- }
- return false;
+ // This copies the data elsewhere so we can reuse the buffer.
+ dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
+ return true;
+ }
+ return false;
}
/*
*------------------------------------------------------------------*/
@@ -309,42 +309,42 @@ void USB_0_Handler(void) {
/* USB_SOF_HSOF */
void USB_1_Handler(void) {
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
+ USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
+ dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
}
void transfer_complete(uint8_t direction) {
- uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
- for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
- if ((epints & (1 << epnum)) == 0) {
- continue;
- }
+ uint32_t epints = USB->DEVICE.EPINTSMRY.reg;
+ for (uint8_t epnum = 0; epnum < USB_EPT_NUM; epnum++) {
+ if ((epints & (1 << epnum)) == 0) {
+ continue;
+ }
- if (direction == TUSB_DIR_OUT && maybe_handle_setup_packet()) {
- continue;
- }
- UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
+ if (direction == TUSB_DIR_OUT && maybe_handle_setup_packet()) {
+ continue;
+ }
+ UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
- UsbDeviceDescBank* bank = &sram_registers[epnum][direction];
- uint16_t total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
+ UsbDeviceDescBank* bank = &sram_registers[epnum][direction];
+ uint16_t total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
- uint8_t ep_addr = epnum;
- if (direction == TUSB_DIR_IN) {
- ep_addr |= TUSB_DIR_IN_MASK;
- }
- dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
+ uint8_t ep_addr = epnum;
+ if (direction == TUSB_DIR_IN) {
+ ep_addr |= TUSB_DIR_IN_MASK;
+ }
+ dcd_event_xfer_complete(0, ep_addr, total_transfer_size, XFER_RESULT_SUCCESS, true);
- // just finished status stage (total size = 0), prepare for next setup packet
- if (epnum == 0 && total_transfer_size == 0) {
- dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
- }
+ // just finished status stage (total size = 0), prepare for next setup packet
+ if (epnum == 0 && total_transfer_size == 0) {
+ dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
+ }
- if (direction == TUSB_DIR_IN) {
- ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
- } else {
- ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
- }
+ if (direction == TUSB_DIR_IN) {
+ ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
+ } else {
+ ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
}
+ }
}
// Bank zero is for OUT and SETUP transactions.
@@ -352,7 +352,7 @@ void transfer_complete(uint8_t direction) {
USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5,
USB_TRCPT0_6, USB_TRCPT0_7 */
void USB_2_Handler(void) {
- transfer_complete(TUSB_DIR_OUT);
+ transfer_complete(TUSB_DIR_OUT);
}
// Bank one is used for IN transactions.
@@ -360,7 +360,7 @@ void USB_2_Handler(void) {
USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5,
USB_TRCPT1_6, USB_TRCPT1_7 */
void USB_3_Handler(void) {
- transfer_complete(TUSB_DIR_IN);
+ transfer_complete(TUSB_DIR_IN);
}
#endif