mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
rp2040: don't compile in host code when in device mode
This commit is contained in:
parent
99d3a32ba2
commit
e00178a1af
@ -44,10 +44,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.
|
// 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)
|
static inline void _hw_endpoint_update_last_buf(struct hw_endpoint *ep)
|
||||||
{
|
{
|
||||||
ep->last_buf = ep->len + ep->transfer_size == ep->total_len;
|
ep->last_buf = ep->len + ep->transfer_size == ep->total_len;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void rp2040_usb_init(void)
|
void rp2040_usb_init(void)
|
||||||
{
|
{
|
||||||
@ -68,7 +70,9 @@ void hw_endpoint_reset_transfer(struct hw_endpoint *ep)
|
|||||||
{
|
{
|
||||||
ep->stalled = false;
|
ep->stalled = false;
|
||||||
ep->active = false;
|
ep->active = false;
|
||||||
|
#ifdef RP2040_USB_HOST_MODE
|
||||||
ep->sent_setup = false;
|
ep->sent_setup = false;
|
||||||
|
#endif
|
||||||
ep->total_len = 0;
|
ep->total_len = 0;
|
||||||
ep->len = 0;
|
ep->len = 0;
|
||||||
ep->transfer_size = 0;
|
ep->transfer_size = 0;
|
||||||
@ -122,6 +126,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;
|
val |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID;
|
||||||
ep->next_pid ^= 1u;
|
ep->next_pid ^= 1u;
|
||||||
|
|
||||||
|
#ifdef RP2040_USB_HOST_MODE
|
||||||
// Is this the last buffer? Only really matters for host mode. Will trigger
|
// 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
|
// the trans complete irq but also stop it polling. We only really care about
|
||||||
// trans complete for setup packets being sent
|
// trans complete for setup packets being sent
|
||||||
@ -130,6 +135,7 @@ void _hw_endpoint_start_next_buffer(struct hw_endpoint *ep)
|
|||||||
pico_trace("Last buf (%d bytes left)\n", ep->transfer_size);
|
pico_trace("Last buf (%d bytes left)\n", ep->transfer_size);
|
||||||
val |= USB_BUF_CTRL_LAST;
|
val |= USB_BUF_CTRL_LAST;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Finally, write to buffer_control which will trigger the transfer
|
// Finally, write to buffer_control which will trigger the transfer
|
||||||
// the next time the controller polls this dpram address
|
// the next time the controller polls this dpram address
|
||||||
@ -156,9 +162,11 @@ void _hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t t
|
|||||||
ep->transfer_size = tu_min32(total_len, ep->wMaxPacketSize);
|
ep->transfer_size = tu_min32(total_len, ep->wMaxPacketSize);
|
||||||
ep->active = true;
|
ep->active = true;
|
||||||
ep->user_buf = buffer;
|
ep->user_buf = buffer;
|
||||||
|
#ifdef RP2040_USB_HOST_MODE
|
||||||
// Recalculate if this is the last buffer
|
// Recalculate if this is the last buffer
|
||||||
_hw_endpoint_update_last_buf(ep);
|
_hw_endpoint_update_last_buf(ep);
|
||||||
ep->buf_sel = 0;
|
ep->buf_sel = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
_hw_endpoint_start_next_buffer(ep);
|
_hw_endpoint_start_next_buffer(ep);
|
||||||
_hw_endpoint_lock_update(ep, -1);
|
_hw_endpoint_lock_update(ep, -1);
|
||||||
@ -232,7 +240,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?
|
// Now we have synced our state with the hardware. Is there more data to transfer?
|
||||||
uint remaining_bytes = ep->total_len - ep->len;
|
uint remaining_bytes = ep->total_len - ep->len;
|
||||||
ep->transfer_size = tu_min32(remaining_bytes, ep->wMaxPacketSize);
|
ep->transfer_size = tu_min32(remaining_bytes, ep->wMaxPacketSize);
|
||||||
|
#ifdef RP2040_USB_HOST_MODE
|
||||||
_hw_endpoint_update_last_buf(ep);
|
_hw_endpoint_update_last_buf(ep);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Can happen because of programmer error so check for it
|
// Can happen because of programmer error so check for it
|
||||||
if (ep->len > ep->total_len)
|
if (ep->len > ep->total_len)
|
||||||
|
@ -71,11 +71,13 @@ struct hw_endpoint
|
|||||||
uint len;
|
uint len;
|
||||||
// Amount of data with the hardware
|
// Amount of data with the hardware
|
||||||
uint transfer_size;
|
uint transfer_size;
|
||||||
|
#ifdef RP2040_USB_HOST_MODE
|
||||||
// Only needed for host mode
|
// Only needed for host mode
|
||||||
bool last_buf;
|
bool last_buf;
|
||||||
// HOST BUG. Host will incorrect write status to top half of buffer
|
// HOST BUG. Host will incorrect write status to top half of buffer
|
||||||
// control register when doing transfers > 1 packet
|
// control register when doing transfers > 1 packet
|
||||||
uint8_t buf_sel;
|
uint8_t buf_sel;
|
||||||
|
#endif
|
||||||
// User buffer in main memory
|
// User buffer in main memory
|
||||||
uint8_t *user_buf;
|
uint8_t *user_buf;
|
||||||
|
|
||||||
@ -84,11 +86,13 @@ struct hw_endpoint
|
|||||||
// Interrupt, bulk, etc
|
// Interrupt, bulk, etc
|
||||||
uint8_t transfer_type;
|
uint8_t transfer_type;
|
||||||
|
|
||||||
|
#ifdef RP2040_USB_HOST_MODE
|
||||||
// Only needed for host
|
// Only needed for host
|
||||||
uint8_t dev_addr;
|
uint8_t dev_addr;
|
||||||
bool sent_setup;
|
bool sent_setup;
|
||||||
// If interrupt endpoint
|
// If interrupt endpoint
|
||||||
uint8_t interrupt_num;
|
uint8_t interrupt_num;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void rp2040_usb_init(void);
|
void rp2040_usb_init(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user