12#ifndef ZEPHYR_INCLUDE_UDC_H
13#define ZEPHYR_INCLUDE_UDC_H
245 const uint8_t mode,
const bool dryrun);
258#define UDC_STATUS_INITIALIZED 0
263#define UDC_STATUS_ENABLED 1
265#define UDC_STATUS_SUSPENDED 2
469 const uint8_t mode,
const bool dryrun)
685 __ASSERT_NO_MSG(buf);
701 __ASSERT_NO_MSG(buf);
long atomic_t
Definition atomic_types.h:15
static bool atomic_test_bit(const atomic_t *target, int bit)
Atomically test a bit.
Definition atomic.h:127
static void * net_buf_user_data(const struct net_buf *buf)
Get a pointer to the user data of a buffer.
Definition buf.h:1582
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define EPERM
Not owner.
Definition errno.h:39
static struct udc_buf_info * udc_get_buf_info(const struct net_buf *const buf)
Get requests metadata.
Definition udc.h:699
static int udc_host_wakeup(const struct device *dev)
Initiate host wakeup procedure.
Definition udc.h:499
int udc_ep_set_halt(const struct device *dev, const uint8_t ep)
Halt endpoint.
static bool udc_is_enabled(const struct device *dev)
Checks whether the controller is enabled.
Definition udc.h:320
static struct udc_device_caps udc_caps(const struct device *dev)
Get USB device controller capabilities.
Definition udc.h:407
static bool udc_is_initialized(const struct device *dev)
Checks whether the controller is initialized.
Definition udc.h:306
static void udc_ep_buf_set_zlp(struct net_buf *const buf)
Set ZLP flag in requests metadata.
Definition udc.h:681
int udc_ep_disable(const struct device *dev, const uint8_t ep)
Disable endpoint.
int udc_shutdown(const struct device *dev)
Poweroff USB device controller.
int udc_ep_dequeue(const struct device *dev, const uint8_t ep)
Remove all USB device controller requests from endpoint queue.
static int udc_set_address(const struct device *dev, const uint8_t addr)
Set USB device address.
Definition udc.h:437
static int udc_test_mode(const struct device *dev, const uint8_t mode, const bool dryrun)
Enable Test Mode.
Definition udc.h:468
int udc_ep_try_config(const struct device *dev, const uint8_t ep, const uint8_t attributes, uint16_t *const mps, const uint8_t interval)
Try an endpoint configuration.
static bool udc_is_suspended(const struct device *dev)
Checks whether the controller is suspended.
Definition udc.h:334
int udc_disable(const struct device *dev)
Disable USB device controller.
int udc_init(const struct device *dev, udc_event_cb_t event_cb)
Initialize USB device controller.
enum udc_bus_speed udc_device_speed(const struct device *dev)
Get actual USB device speed.
int udc_ep_enqueue(const struct device *dev, struct net_buf *const buf)
Queue USB device controller request.
int udc_ep_enable(const struct device *dev, const uint8_t ep, const uint8_t attributes, const uint16_t mps, const uint8_t interval)
Configure and enable endpoint.
struct net_buf * udc_ep_buf_alloc(const struct device *dev, const uint8_t ep, const size_t size)
Allocate UDC request buffer.
int udc_ep_clear_halt(const struct device *dev, const uint8_t ep)
Clear endpoint halt.
int udc_ep_buf_free(const struct device *dev, struct net_buf *const buf)
Free UDC request buffer.
int udc_enable(const struct device *dev)
Enable USB device controller.
static ZTEST_BMEM int ret
Definition main.c:16
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
void * data
Address of the device instance private data.
Definition device.h:413
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
Mutex Structure.
Definition kernel.h:2917
Network buffer representation.
Definition buf.h:1004
uint16_t size
Amount of data that this buffer can store.
Definition buf.h:1036
UDC driver API This is the mandatory API any USB device controller driver needs to expose with except...
Definition udc.h:224
int(* init)(const struct device *dev)
Definition udc.h:248
int(* ep_dequeue)(const struct device *dev, struct udc_ep_config *const cfg)
Definition udc.h:229
int(* ep_disable)(const struct device *dev, struct udc_ep_config *const cfg)
Definition udc.h:239
int(* unlock)(const struct device *dev)
Definition udc.h:251
int(* ep_enable)(const struct device *dev, struct udc_ep_config *const cfg)
Definition udc.h:237
int(* set_address)(const struct device *dev, const uint8_t addr)
Definition udc.h:242
int(* ep_try_config)(const struct device *dev, struct udc_ep_config *const cfg)
Definition udc.h:235
int(* disable)(const struct device *dev)
Definition udc.h:247
int(* ep_clear_halt)(const struct device *dev, struct udc_ep_config *const cfg)
Definition udc.h:233
int(* ep_enqueue)(const struct device *dev, struct udc_ep_config *const cfg, struct net_buf *const buf)
Definition udc.h:226
int(* test_mode)(const struct device *dev, const uint8_t mode, const bool dryrun)
Definition udc.h:244
int(* lock)(const struct device *dev)
Definition udc.h:250
int(* shutdown)(const struct device *dev)
Definition udc.h:249
int(* ep_set_halt)(const struct device *dev, struct udc_ep_config *const cfg)
Definition udc.h:231
enum udc_bus_speed(* device_speed)(const struct device *dev)
Definition udc.h:225
int(* host_wakeup)(const struct device *dev)
Definition udc.h:241
int(* enable)(const struct device *dev)
Definition udc.h:246
UDC endpoint buffer info.
Definition udc.h:181
uint8_t ep
Endpoint to which request is associated.
Definition udc.h:183
void * owner
Transfer owner (usually pointer to a class instance)
Definition udc.h:197
unsigned int queued
Flag marks request buffer is queued (TBD)
Definition udc.h:195
unsigned int status
Flag marks status stage of setup transfer.
Definition udc.h:189
unsigned int setup
Flag marks setup transfer.
Definition udc.h:185
unsigned int claimed
Flag marks request buffer claimed by the controller (TBD)
Definition udc.h:193
unsigned int data
Flag marks data stage of setup transfer.
Definition udc.h:187
int err
Transfer result, 0 on success, other values on error.
Definition udc.h:199
unsigned int zlp
Flag marks ZLP at the end of a transfer.
Definition udc.h:191
Common UDC driver data structure.
Definition udc.h:273
struct k_mutex mutex
Driver access mutex.
Definition udc.h:279
struct net_buf * setup
Pointer to buffer containing setup packet.
Definition udc.h:287
udc_event_cb_t event_cb
Callback to submit an UDC event to upper layer.
Definition udc.h:281
atomic_t status
USB device controller status.
Definition udc.h:283
struct udc_device_caps caps
Controller capabilities.
Definition udc.h:277
int stage
Internal used Control Sequence Stage.
Definition udc.h:285
void * priv
Driver private data.
Definition udc.h:289
struct udc_ep_config * ep_lut[32]
LUT for endpoint management.
Definition udc.h:275
USB device controller capabilities.
Definition udc.h:36
uint32_t out_ack
Controller performs status OUT stage automatically.
Definition udc.h:42
enum udc_mps0 mps0
Maximum packet size for control endpoint.
Definition udc.h:48
uint32_t can_detect_vbus
Controller can detect the state change of USB supply VBUS.
Definition udc.h:46
uint32_t rwup
Controller supports USB remote wakeup.
Definition udc.h:40
uint32_t hs
USB high speed capable controller.
Definition udc.h:38
uint32_t addr_before_status
Controller expects device address to be set before status stage.
Definition udc.h:44
USB device controller endpoint capabilities.
Definition udc.h:68
uint32_t iso
ISO transfer capable endpoint.
Definition udc.h:78
uint32_t in
IN transfer capable endpoint.
Definition udc.h:80
uint32_t mps
Maximum packet size of the endpoint buffer.
Definition udc.h:70
uint32_t bulk
Bulk transfer capable endpoint.
Definition udc.h:76
uint32_t interrupt
Interrupt transfer capable endpoint.
Definition udc.h:74
uint32_t control
Control transfer capable endpoint (for completeness)
Definition udc.h:72
uint32_t out
OUT transfer capable endpoint.
Definition udc.h:82
USB device controller endpoint configuration.
Definition udc.h:108
uint8_t interval
Polling interval.
Definition udc.h:122
struct udc_ep_caps caps
Endpoint capabilities.
Definition udc.h:112
struct k_fifo fifo
Endpoint requests FIFO.
Definition udc.h:110
uint8_t addr
Endpoint address.
Definition udc.h:116
uint8_t attributes
Endpoint attributes.
Definition udc.h:118
uint16_t mps
Maximum packet size.
Definition udc.h:120
USB device controller endpoint status.
Definition udc.h:88
uint32_t odd
If double buffering is supported, last used buffer is odd.
Definition udc.h:96
uint32_t data1
Last submitted PID is DATA1.
Definition udc.h:94
uint32_t enabled
Endpoint is enabled.
Definition udc.h:90
uint32_t busy
Endpoint is busy.
Definition udc.h:98
uint32_t halted
Endpoint is halted (returning STALL PID)
Definition udc.h:92
USB device controller event.
Definition udc.h:159
int status
Event status value, if any.
Definition udc.h:166
enum udc_event_type type
Event type.
Definition udc.h:161
const struct device * dev
Pointer to device struct.
Definition udc.h:171
struct net_buf * buf
Pointer to request used only for UDC_EVT_EP_REQUEST.
Definition udc.h:168
uint32_t value
Event value.
Definition udc.h:164
static fdata_t data[2]
Definition test_fifo_contexts.c:15
int(* udc_event_cb_t)(const struct device *dev, const struct udc_event *const event)
Callback to submit UDC event to higher layer.
Definition udc.h:215
udc_event_type
USB device controller event types.
Definition udc.h:129
@ UDC_EVT_VBUS_READY
VBUS ready event.
Definition udc.h:131
@ UDC_EVT_RESUME
Device resume event.
Definition udc.h:135
@ UDC_EVT_SUSPEND
Device suspended event.
Definition udc.h:137
@ UDC_EVT_VBUS_REMOVED
VBUS removed event.
Definition udc.h:133
@ UDC_EVT_EP_REQUEST
Endpoint request result event.
Definition udc.h:143
@ UDC_EVT_ERROR
Non-correctable error event, requires attention from higher levels or application.
Definition udc.h:148
@ UDC_EVT_RESET
Port reset detected.
Definition udc.h:139
@ UDC_EVT_SOF
Start of Frame event.
Definition udc.h:141
udc_bus_speed
USB device actual speed.
Definition udc.h:54
@ UDC_BUS_SPEED_SS
Device is connected to a super speed bus.
Definition udc.h:62
@ UDC_BUS_SPEED_FS
Device is connected to a full speed bus.
Definition udc.h:58
@ UDC_BUS_UNKNOWN
Device is probably not connected.
Definition udc.h:56
@ UDC_BUS_SPEED_HS
Device is connected to a high speed bus
Definition udc.h:60
#define UDC_STATUS_INITIALIZED
Controller is initialized by udc_init() and can generate the VBUS events, if capable,...
Definition udc.h:258
udc_mps0
Maximum packet size of control endpoint supported by the controller.
Definition udc.h:24
@ UDC_MPS0_32
Definition udc.h:27
@ UDC_MPS0_16
Definition udc.h:26
@ UDC_MPS0_64
Definition udc.h:28
@ UDC_MPS0_8
Definition udc.h:25
#define UDC_STATUS_SUSPENDED
Controller is suspended by the host.
Definition udc.h:265
#define UDC_STATUS_ENABLED
Controller is enabled and all API functions are available, controller is recognizable by host.
Definition udc.h:263
USB Chapter 9 structures and definitions.
#define USB_EP_DIR_IS_IN(ep)
True if the endpoint is an IN endpoint.
Definition usb_ch9.h:313