summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-02-26 00:29:55 +0700
committerGitHub <[email protected]>2021-02-26 00:29:55 +0700
commit1ce6f76d6e8df1fbb3c26cb5830c12491ed9b9e0 (patch)
tree13b929995dd32681c2e88c68804f71b76e7bf0fa /src
parent50a0bddd8b5f394215bdf36ac5b17a7386a77e3d (diff)
parent0632ecf556edb11081d621cbb7ef6162d76b0ef3 (diff)
Merge pull request #676 from majbthrd/rp2040device
rp2040: don't compile in host code when in device mode
Diffstat (limited to 'src')
-rw-r--r--src/portable/raspberrypi/rp2040/rp2040_usb.c10
-rw-r--r--src/portable/raspberrypi/rp2040/rp2040_usb.h12
2 files changed, 17 insertions, 5 deletions
diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c
index ecd474695..4e0850af8 100644
--- a/src/portable/raspberrypi/rp2040/rp2040_usb.c
+++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c
@@ -43,10 +43,12 @@ static inline void _hw_endpoint_lock_update(struct hw_endpoint *ep, int delta) {
// sense to have worker and IRQ on same core, however I think using critsec is about equivalent.
}
+#ifdef RP2040_USB_HOST_MODE
static inline void _hw_endpoint_update_last_buf(struct hw_endpoint *ep)
{
ep->last_buf = ep->len + ep->transfer_size == ep->total_len;
}
+#endif
void rp2040_usb_init(void)
{
@@ -67,7 +69,9 @@ void hw_endpoint_reset_transfer(struct hw_endpoint *ep)
{
ep->stalled = false;
ep->active = false;
+#ifdef RP2040_USB_HOST_MODE
ep->sent_setup = false;
+#endif
ep->total_len = 0;
ep->len = 0;
ep->transfer_size = 0;
@@ -121,6 +125,7 @@ void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep)
val |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID;
ep->next_pid ^= 1u;
+#ifdef RP2040_USB_HOST_MODE
// Is this the last buffer? Only really matters for host mode. Will trigger
// the trans complete irq but also stop it polling. We only really care about
// trans complete for setup packets being sent
@@ -129,6 +134,7 @@ void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep)
pico_trace("Last buf (%d bytes left)\n", ep->transfer_size);
val |= USB_BUF_CTRL_LAST;
}
+#endif
// Finally, write to buffer_control which will trigger the transfer
// the next time the controller polls this dpram address
@@ -155,9 +161,11 @@ void _hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t t
ep->transfer_size = tu_min16(total_len, ep->wMaxPacketSize);
ep->active = true;
ep->user_buf = buffer;
+#ifdef RP2040_USB_HOST_MODE
// Recalculate if this is the last buffer
_hw_endpoint_update_last_buf(ep);
ep->buf_sel = 0;
+#endif
_hw_endpoint_start_next_buffer(ep);
_hw_endpoint_lock_update(ep, -1);
@@ -231,7 +239,9 @@ bool _hw_endpoint_xfer_continue(struct hw_endpoint *ep)
// Now we have synced our state with the hardware. Is there more data to transfer?
uint16_t remaining_bytes = ep->total_len - ep->len;
ep->transfer_size = tu_min16(remaining_bytes, ep->wMaxPacketSize);
+#ifdef RP2040_USB_HOST_MODE
_hw_endpoint_update_last_buf(ep);
+#endif
// Can happen because of programmer error so check for it
if (ep->len > ep->total_len)
diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.h b/src/portable/raspberrypi/rp2040/rp2040_usb.h
index 522d7d701..e92b70416 100644
--- a/src/portable/raspberrypi/rp2040/rp2040_usb.h
+++ b/src/portable/raspberrypi/rp2040/rp2040_usb.h
@@ -71,11 +71,6 @@ struct hw_endpoint
uint16_t len;
// Amount of data with the hardware
uint16_t transfer_size;
- // Only needed for host mode
- bool last_buf;
- // HOST BUG. Host will incorrect write status to top half of buffer
- // control register when doing transfers > 1 packet
- uint8_t buf_sel;
// User buffer in main memory
uint8_t *user_buf;
@@ -84,11 +79,18 @@ struct hw_endpoint
// Interrupt, bulk, etc
uint8_t transfer_type;
+#ifdef RP2040_USB_HOST_MODE
+ // Only needed for host mode
+ bool last_buf;
+ // HOST BUG. Host will incorrect write status to top half of buffer
+ // control register when doing transfers > 1 packet
+ uint8_t buf_sel;
// Only needed for host
uint8_t dev_addr;
bool sent_setup;
// If interrupt endpoint
uint8_t interrupt_num;
+#endif
};
void rp2040_usb_init(void);