libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
Generic USB Drivers More...
Functions | |
usbd_device * | usbd_init (const usbd_driver *driver, const struct usb_device_descriptor *dev, const struct usb_config_descriptor *conf, const char *const *strings, int num_strings, uint8_t *control_buffer, uint16_t control_buffer_size) |
Main initialization entry point. More... | |
void | usbd_register_reset_callback (usbd_device *usbd_dev, void(*callback)(void)) |
Registers a reset callback. More... | |
void | usbd_register_suspend_callback (usbd_device *usbd_dev, void(*callback)(void)) |
Registers a suspend callback. More... | |
void | usbd_register_resume_callback (usbd_device *usbd_dev, void(*callback)(void)) |
Registers a resume callback. More... | |
void | usbd_register_sof_callback (usbd_device *usbd_dev, void(*callback)(void)) |
Registers a SOF callback. More... | |
void | usbd_register_extra_string (usbd_device *usbd_dev, int index, const char *string) |
Registers a non-contiguous string descriptor. More... | |
void | _usbd_reset (usbd_device *usbd_dev) |
void | usbd_poll (usbd_device *usbd_dev) |
void | usbd_disconnect (usbd_device *usbd_dev, bool disconnected) |
Disconnect, if supported by the driver. More... | |
void | usbd_ep_setup (usbd_device *usbd_dev, uint8_t addr, uint8_t type, uint16_t max_size, usbd_endpoint_callback callback) |
Setup an endpoint. More... | |
uint16_t | usbd_ep_write_packet (usbd_device *usbd_dev, uint8_t addr, const void *buf, uint16_t len) |
Write a packet. More... | |
uint16_t | usbd_ep_read_packet (usbd_device *usbd_dev, uint8_t addr, void *buf, uint16_t len) |
Read a packet. More... | |
void | usbd_ep_stall_set (usbd_device *usbd_dev, uint8_t addr, uint8_t stall) |
Set/clear STALL condition on an endpoint. More... | |
uint8_t | usbd_ep_stall_get (usbd_device *usbd_dev, uint8_t addr) |
Get STALL status of an endpoint. More... | |
void | usbd_ep_nak_set (usbd_device *usbd_dev, uint8_t addr, uint8_t nak) |
Set an Out endpoint to NAK. More... | |
Generic USB Drivers
LGPL License Terms libopencm3 License
void _usbd_reset | ( | usbd_device * | usbd_dev | ) |
Definition at line 113 of file usb.c.
References USB_ENDPOINT_ATTR_CONTROL, and usbd_ep_setup().
Referenced by st_usbfs_poll().
void usbd_disconnect | ( | usbd_device * | usbd_dev, |
bool | disconnected | ||
) |
Disconnect, if supported by the driver.
This function is implemented as weak function and can be replaced by an application specific version to handle chips that don't have built-in handling for this (e.g. STM32F1.)
usbd_dev | the usb device handle returned from usbd_init |
disconnected | true to request a disconnect |
void usbd_ep_nak_set | ( | usbd_device * | usbd_dev, |
uint8_t | addr, | ||
uint8_t | nak | ||
) |
Set an Out endpoint to NAK.
usbd_dev | the usb device handle returned from usbd_init |
addr | EP address |
nak | if nonzero, set NAK |
Definition at line 168 of file usb.c.
Referenced by _usbd_control_in(), _usbd_control_setup(), and usb_control_setup_write().
uint16_t usbd_ep_read_packet | ( | usbd_device * | usbd_dev, |
uint8_t | addr, | ||
void * | buf, | ||
uint16_t | len | ||
) |
Read a packet.
usbd_dev | the usb device handle returned from usbd_init |
addr | EP address |
buf | user buffer that will receive data |
len | # of bytes |
Definition at line 152 of file usb.c.
Referenced by _usbd_control_out(), msc_data_rx_cb(), and usb_control_recv_chunk().
void usbd_ep_setup | ( | usbd_device * | usbd_dev, |
uint8_t | addr, | ||
uint8_t | type, | ||
uint16_t | max_size, | ||
usbd_endpoint_callback | callback | ||
) |
Setup an endpoint.
usbd_dev | the usb device handle returned from usbd_init |
addr | Full EP address including direction (e.g. 0x01 or 0x81) |
type | Value for bmAttributes (USB_ENDPOINT_ATTR_*) |
max_size | Endpoint max size |
callback | your desired callback function |
Definition at line 140 of file usb.c.
Referenced by _usbd_reset(), and msc_set_config().
uint8_t usbd_ep_stall_get | ( | usbd_device * | usbd_dev, |
uint8_t | addr | ||
) |
Get STALL status of an endpoint.
usbd_dev | the usb device handle returned from usbd_init |
addr | Full EP address (with direction bit) |
Definition at line 163 of file usb.c.
Referenced by usb_standard_endpoint_get_status().
void usbd_ep_stall_set | ( | usbd_device * | usbd_dev, |
uint8_t | addr, | ||
uint8_t | stall | ||
) |
Set/clear STALL condition on an endpoint.
usbd_dev | the usb device handle returned from usbd_init |
addr | Full EP address (with direction bit) |
stall | if 0, clear STALL, else set stall. |
Definition at line 158 of file usb.c.
Referenced by stall_transaction(), usb_standard_endpoint_stall(), and usb_standard_endpoint_unstall().
uint16_t usbd_ep_write_packet | ( | usbd_device * | usbd_dev, |
uint8_t | addr, | ||
const void * | buf, | ||
uint16_t | len | ||
) |
Write a packet.
usbd_dev | the usb device handle returned from usbd_init |
addr | EP address (direction is ignored) |
buf | pointer to user data to write |
len | # of bytes |
Definition at line 146 of file usb.c.
Referenced by _usbd_control_out(), msc_data_rx_cb(), msc_data_tx_cb(), usb_control_send_chunk(), and usb_control_setup_read().
usbd_device * usbd_init | ( | const usbd_driver * | driver, |
const struct usb_device_descriptor * | dev, | ||
const struct usb_config_descriptor * | conf, | ||
const char *const * | strings, | ||
int | num_strings, | ||
uint8_t * | control_buffer, | ||
uint16_t | control_buffer_size | ||
) |
Main initialization entry point.
Initialize the USB firmware library to implement the USB device described by the descriptors provided.
It is required that the 48MHz USB clock is already available.
driver | TODO |
dev | Pointer to USB device descriptor. This must not be changed while the device is in use. |
conf | Pointer to array of USB configuration descriptors. These must not be changed while the device is in use. The length of this array is determined by the bNumConfigurations field in the device descriptor. |
strings | Pointer to an array of strings for USB string descriptors. Referenced in iSomething fields, e.g. iManufacturer. Since a zero index means "no string", an iSomething value of 1 refers strings[0]. |
num_strings | Number of items in strings array. |
control_buffer | Pointer to array that would hold the data received during control requests with DATA stage |
control_buffer_size | Size of control_buffer |
To place strings entirely into Flash/read-only memory, use
(note the double const.) The first const refers to the strings while the second const refers to the array.
Definition at line 42 of file usb.c.
References _usbd_control_in(), _usbd_control_out(), and _usbd_control_setup().
void usbd_poll | ( | usbd_device * | usbd_dev | ) |
void usbd_register_extra_string | ( | usbd_device * | usbd_dev, |
int | index, | ||
const char * | string | ||
) |
void usbd_register_reset_callback | ( | usbd_device * | usbd_dev, |
void(*)(void) | callback | ||
) |
void usbd_register_resume_callback | ( | usbd_device * | usbd_dev, |
void(*)(void) | callback | ||
) |
void usbd_register_sof_callback | ( | usbd_device * | usbd_dev, |
void(*)(void) | callback | ||
) |
void usbd_register_suspend_callback | ( | usbd_device * | usbd_dev, |
void(*)(void) | callback | ||
) |