40#include "usb_private.h"
45 const char *
const *strings,
int num_strings,
46 uint8_t *control_buffer, uint16_t control_buffer_size)
50 usbd_dev = driver->init();
52 usbd_dev->driver = driver;
54 usbd_dev->config = conf;
55 usbd_dev->strings = strings;
56 usbd_dev->num_strings = num_strings;
57 usbd_dev->extra_string_idx = 0;
58 usbd_dev->extra_string = NULL;
59 usbd_dev->ctrl_buf = control_buffer;
60 usbd_dev->ctrl_buf_len = control_buffer_size;
62 usbd_dev->user_callback_ctr[0][USB_TRANSACTION_SETUP] =
64 usbd_dev->user_callback_ctr[0][USB_TRANSACTION_OUT] =
66 usbd_dev->user_callback_ctr[0][USB_TRANSACTION_IN] =
70 for (i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
71 usbd_dev->user_callback_set_config[i] = NULL;
79 usbd_dev->user_callback_reset = callback;
83 void (*callback)(
void))
85 usbd_dev->user_callback_suspend = callback;
89 void (*callback)(
void))
91 usbd_dev->user_callback_resume = callback;
96 usbd_dev->user_callback_sof = callback;
105 if (
string != NULL && index > 0) {
106 usbd_dev->extra_string_idx = index;
107 usbd_dev->extra_string = string;
109 usbd_dev->extra_string_idx = 0;
115 usbd_dev->current_address = 0;
116 usbd_dev->current_config = 0;
118 usbd_dev->driver->set_address(usbd_dev, 0);
120 if (usbd_dev->user_callback_reset) {
121 usbd_dev->user_callback_reset();
128 usbd_dev->driver->poll(usbd_dev);
135 if (usbd_dev->driver->disconnect) {
136 usbd_dev->driver->disconnect(usbd_dev, disconnected);
143 usbd_dev->driver->ep_setup(usbd_dev, addr, type, max_size, callback);
147 const void *buf, uint16_t len)
149 return usbd_dev->driver->ep_write_packet(usbd_dev, addr, buf, len);
155 return usbd_dev->driver->ep_read_packet(usbd_dev, addr, buf, len);
160 usbd_dev->driver->ep_stall_set(usbd_dev, addr, stall);
165 return usbd_dev->driver->ep_stall_get(usbd_dev, addr);
170 usbd_dev->driver->ep_nak_set(usbd_dev, addr, nak);
struct _usbd_device usbd_device
void(* usbd_endpoint_callback)(usbd_device *usbd_dev, uint8_t ep)
struct _usbd_driver usbd_driver
void usbd_register_resume_callback(usbd_device *usbd_dev, void(*callback)(void))
Registers a resume callback.
void usbd_register_suspend_callback(usbd_device *usbd_dev, void(*callback)(void))
Registers a suspend callback.
void usbd_register_reset_callback(usbd_device *usbd_dev, void(*callback)(void))
Registers a reset callback.
void usbd_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak)
Set an Out endpoint to NAK.
uint8_t usbd_ep_stall_get(usbd_device *usbd_dev, uint8_t addr)
Get STALL status of an endpoint.
void _usbd_reset(usbd_device *usbd_dev)
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.
void usbd_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall)
Set/clear STALL condition on an endpoint.
void usbd_poll(usbd_device *usbd_dev)
uint16_t usbd_ep_write_packet(usbd_device *usbd_dev, uint8_t addr, const void *buf, uint16_t len)
Write a packet.
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.
uint16_t usbd_ep_read_packet(usbd_device *usbd_dev, uint8_t addr, void *buf, uint16_t len)
Read a packet.
void usbd_register_sof_callback(usbd_device *usbd_dev, void(*callback)(void))
Registers a SOF callback.
void usbd_register_extra_string(usbd_device *usbd_dev, int index, const char *string)
Registers a non-contiguous string descriptor.
void usbd_disconnect(usbd_device *usbd_dev, bool disconnected)
Disconnect, if supported by the driver.
#define USB_ENDPOINT_ATTR_CONTROL
void _usbd_control_out(usbd_device *usbd_dev, uint8_t ea)
void _usbd_control_in(usbd_device *usbd_dev, uint8_t ea)
void _usbd_control_setup(usbd_device *usbd_dev, uint8_t ea)