2021-01-20 02:52:07 +01:00
|
|
|
#ifndef RP2040_COMMON_H_
|
|
|
|
#define RP2040_COMMON_H_
|
|
|
|
|
|
|
|
#if defined(RP2040_USB_HOST_MODE) && defined(RP2040_USB_DEVICE_MODE)
|
|
|
|
#error TinyUSB device and host mode not supported at the same time
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common/tusb_common.h"
|
|
|
|
|
|
|
|
#include "pico.h"
|
|
|
|
#include "hardware/structs/usb.h"
|
|
|
|
#include "hardware/irq.h"
|
|
|
|
#include "hardware/resets.h"
|
|
|
|
|
|
|
|
#if defined(PICO_RP2040_USB_DEVICE_ENUMERATION_FIX) && !defined(TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX)
|
|
|
|
#define TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX PICO_RP2040_USB_DEVICE_ENUMERATION_FIX
|
|
|
|
#endif
|
|
|
|
|
2022-06-16 18:03:53 +02:00
|
|
|
#ifndef PICO_RP2040_USB_FAST_IRQ
|
|
|
|
#define PICO_RP2040_USB_FAST_IRQ 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PICO_RP2040_USB_FAST_IRQ
|
|
|
|
#define __tusb_irq_path_func(x) __no_inline_not_in_flash_func(x)
|
|
|
|
#else
|
|
|
|
#define __tusb_irq_path_func(x) x
|
|
|
|
#endif
|
2021-01-20 02:52:07 +01:00
|
|
|
|
2021-06-11 13:44:08 +02:00
|
|
|
#define pico_info(...) TU_LOG(2, __VA_ARGS__)
|
|
|
|
#define pico_trace(...) TU_LOG(3, __VA_ARGS__)
|
2021-01-20 02:52:07 +01:00
|
|
|
|
|
|
|
// Hardware information per endpoint
|
2021-09-01 14:42:40 +02:00
|
|
|
typedef struct hw_endpoint
|
2021-01-20 02:52:07 +01:00
|
|
|
{
|
|
|
|
// Is this a valid struct
|
|
|
|
bool configured;
|
|
|
|
|
|
|
|
// Transfer direction (i.e. IN is rx for host but tx for device)
|
|
|
|
// allows us to common up transfer functions
|
|
|
|
bool rx;
|
|
|
|
|
|
|
|
uint8_t ep_addr;
|
|
|
|
uint8_t next_pid;
|
|
|
|
|
|
|
|
// Endpoint control register
|
|
|
|
io_rw_32 *endpoint_control;
|
2021-06-11 12:05:49 +02:00
|
|
|
|
2021-01-20 02:52:07 +01:00
|
|
|
// Buffer control register
|
|
|
|
io_rw_32 *buffer_control;
|
|
|
|
|
|
|
|
// Buffer pointer in usb dpram
|
|
|
|
uint8_t *hw_data_buf;
|
|
|
|
|
|
|
|
// Current transfer information
|
|
|
|
bool active;
|
2021-06-11 12:58:29 +02:00
|
|
|
uint16_t remaining_len;
|
|
|
|
uint16_t xferred_len;
|
2021-06-11 12:05:49 +02:00
|
|
|
|
2021-01-20 02:52:07 +01:00
|
|
|
// User buffer in main memory
|
|
|
|
uint8_t *user_buf;
|
|
|
|
|
|
|
|
// Data needed from EP descriptor
|
2021-02-23 03:53:16 +01:00
|
|
|
uint16_t wMaxPacketSize;
|
2021-06-13 10:27:20 +02:00
|
|
|
|
2021-01-20 02:52:07 +01:00
|
|
|
// Interrupt, bulk, etc
|
|
|
|
uint8_t transfer_type;
|
|
|
|
|
2022-02-23 15:49:11 +01:00
|
|
|
#if CFG_TUH_ENABLED
|
2021-01-20 02:52:07 +01:00
|
|
|
// Only needed for host
|
|
|
|
uint8_t dev_addr;
|
2021-06-13 10:27:20 +02:00
|
|
|
|
2021-01-20 02:52:07 +01:00
|
|
|
// If interrupt endpoint
|
|
|
|
uint8_t interrupt_num;
|
2021-02-23 21:04:56 +01:00
|
|
|
#endif
|
2021-09-01 14:42:40 +02:00
|
|
|
} hw_endpoint_t;
|
2021-01-20 02:52:07 +01:00
|
|
|
|
|
|
|
void rp2040_usb_init(void);
|
|
|
|
|
2021-06-11 12:34:51 +02:00
|
|
|
void hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t total_len);
|
|
|
|
bool hw_endpoint_xfer_continue(struct hw_endpoint *ep);
|
2021-01-20 02:52:07 +01:00
|
|
|
void hw_endpoint_reset_transfer(struct hw_endpoint *ep);
|
2021-06-11 12:05:49 +02:00
|
|
|
|
2021-01-20 02:52:07 +01:00
|
|
|
void _hw_endpoint_buffer_control_update32(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask);
|
2022-06-08 11:08:27 +02:00
|
|
|
|
|
|
|
TU_ATTR_ALWAYS_INLINE static inline uint32_t _hw_endpoint_buffer_control_get_value32(struct hw_endpoint *ep) {
|
2021-01-20 02:52:07 +01:00
|
|
|
return *ep->buffer_control;
|
|
|
|
}
|
2022-06-08 11:08:27 +02:00
|
|
|
|
|
|
|
TU_ATTR_ALWAYS_INLINE static inline void _hw_endpoint_buffer_control_set_value32(struct hw_endpoint *ep, uint32_t value) {
|
2021-01-20 02:52:07 +01:00
|
|
|
return _hw_endpoint_buffer_control_update32(ep, 0, value);
|
|
|
|
}
|
2022-06-08 11:08:27 +02:00
|
|
|
|
|
|
|
TU_ATTR_ALWAYS_INLINE static inline void _hw_endpoint_buffer_control_set_mask32(struct hw_endpoint *ep, uint32_t value) {
|
2021-01-20 02:52:07 +01:00
|
|
|
return _hw_endpoint_buffer_control_update32(ep, ~value, value);
|
|
|
|
}
|
2022-06-08 11:08:27 +02:00
|
|
|
|
|
|
|
TU_ATTR_ALWAYS_INLINE static inline void _hw_endpoint_buffer_control_clear_mask32(struct hw_endpoint *ep, uint32_t value) {
|
2021-01-20 02:52:07 +01:00
|
|
|
return _hw_endpoint_buffer_control_update32(ep, ~value, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uintptr_t hw_data_offset(uint8_t *buf)
|
|
|
|
{
|
|
|
|
// Remove usb base from buffer pointer
|
|
|
|
return (uintptr_t)buf ^ (uintptr_t)usb_dpram;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern const char *ep_dir_string[];
|
|
|
|
|
|
|
|
#endif
|