40#include "usb_private.h"
47 for (i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
48 if (
usbd_dev->user_callback_set_config[i]) {
49 if (
usbd_dev->user_callback_set_config[i] == callback) {
55 usbd_dev->user_callback_set_config[i] = callback;
65 usbd_dev->user_callback_set_altsetting = callback;
69 uint8_t index, uint8_t *buf, uint16_t len)
71 uint8_t *tmpbuf = buf;
73 uint16_t count, total = 0, totallen = 0;
76 memcpy(buf, cfg, count = MIN(len, cfg->
bLength));
88 memcpy(buf, assoc, count = MIN(len, assoc->
bLength));
99 memcpy(buf, iface, count = MIN(len, iface->
bLength));
106 memcpy(buf, iface->
extra,
117 memcpy(buf, ep, count = MIN(len, ep->
bLength));
124 memcpy(buf, ep->
extra,
137 memcpy((tmpbuf + 2), &totallen,
sizeof(uint16_t));
149 return wValue & 0xFF;
155 uint8_t **buf, uint16_t *len)
157 int i, array_idx, descr_idx;
165 *len = MIN(*len,
usbd_dev->desc->bLength);
174 if (descr_idx == 0) {
179 sizeof(sd->
wData[0]);
182 }
else if (descr_idx ==
usbd_dev->extra_string_idx) {
192 for (i = 0; i < (*len / 2) - 1; i++) {
197 array_idx = descr_idx - 1;
205 if (array_idx >=
usbd_dev->num_strings) {
224 for (i = 0; i < (*len / 2) - 1; i++) {
231 *buf = (uint8_t *)sd;
258 if (
usbd_dev->driver->set_address_before_status) {
268 uint8_t **buf, uint16_t *len)
271 int found_index = -1;
279 for (i = 0; i <
usbd_dev->desc->bNumConfigurations; i++) {
281 ==
usbd_dev->config[i].bConfigurationValue) {
286 if (found_index < 0) {
291 usbd_dev->current_config = found_index + 1;
307 if (
usbd_dev->user_callback_set_config[0]) {
312 for (i = 0; i < MAX_USER_CONTROL_CALLBACK; i++) {
313 usbd_dev->user_control_callback[i].cb = NULL;
316 for (i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
317 if (
usbd_dev->user_callback_set_config[i]) {
330 uint8_t **buf, uint16_t *len)
351 uint8_t **buf, uint16_t *len)
371 }
else if (req->
wValue > 0) {
375 if (
usbd_dev->user_callback_set_altsetting) {
389 uint8_t **buf, uint16_t *len)
401 (*buf)[0] = (cur_altsetting) ? *cur_altsetting : 0;
409 uint8_t **buf, uint16_t *len)
428 uint8_t **buf, uint16_t *len)
446 uint8_t **buf, uint16_t *len)
462 uint8_t **buf, uint16_t *len)
475 uint8_t **buf, uint16_t *len)
495 uint8_t **buf, uint16_t *len) = NULL;
541 return command(
usbd_dev, req, buf, len);
551 uint8_t **buf, uint16_t *len) = NULL;
573 return command(
usbd_dev, req, buf, len);
583 uint8_t **buf, uint16_t *len) = NULL;
612 return command(
usbd_dev, req, buf, len);
617 uint8_t **buf, uint16_t *len)
uint8_t usbd_ep_stall_get(usbd_device *usbd_dev, uint8_t addr)
Get STALL status of an endpoint.
struct _usbd_device usbd_device
void usbd_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall)
Set/clear STALL condition on an endpoint.
usbd_request_return_codes
void(* usbd_set_config_callback)(usbd_device *usbd_dev, uint16_t wValue)
void(* usbd_set_altsetting_callback)(usbd_device *usbd_dev, uint16_t wIndex, uint16_t wValue)
static enum usbd_request_return_codes usb_standard_interface_get_status(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_get_configuration(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_get_descriptor(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static int usb_descriptor_type(uint16_t wValue)
static enum usbd_request_return_codes usb_standard_get_interface(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_endpoint_get_status(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_set_configuration(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_device_get_status(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_set_interface(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_set_address(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes usb_standard_endpoint_unstall(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
int usbd_register_set_config_callback(usbd_device *usbd_dev, usbd_set_config_callback callback)
Registers a "Set Config" callback.
void usbd_register_set_altsetting_callback(usbd_device *usbd_dev, usbd_set_altsetting_callback callback)
Registers a "Set Interface" (alternate setting) callback.
static enum usbd_request_return_codes usb_standard_endpoint_stall(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
static int usb_descriptor_index(uint16_t wValue)
static uint16_t build_config_descriptor(usbd_device *usbd_dev, uint8_t index, uint8_t *buf, uint16_t len)
#define USB_FEAT_TEST_MODE
#define USB_REQ_GET_INTERFACE
#define USB_DT_CONFIGURATION
#define USB_REQ_SET_INTERFACE
#define USB_REQ_SET_FEATURE
#define USB_REQ_TYPE_STANDARD
#define USB_REQ_TYPE_DEVICE
#define USB_REQ_CLEAR_FEATURE
#define USB_REQ_SET_SYNCH_FRAME
#define USB_REQ_TYPE_RECIPIENT
#define USB_REQ_SET_CONFIGURATION
#define USB_REQ_TYPE_TYPE
#define USB_REQ_TYPE_INTERFACE
#define USB_REQ_GET_STATUS
#define USB_FEAT_ENDPOINT_HALT
#define USB_REQ_TYPE_ENDPOINT
#define USB_FEAT_DEVICE_REMOTE_WAKEUP
#define USB_REQ_SET_ADDRESS
#define USB_REQ_GET_DESCRIPTOR
#define USB_REQ_GET_CONFIGURATION
#define USB_REQ_SET_DESCRIPTOR
const struct usb_interface * interface
uint8_t bConfigurationValue
const struct usb_endpoint_descriptor * endpoint
const struct usb_iface_assoc_descriptor * iface_assoc
const struct usb_interface_descriptor * altsetting
static struct _usbd_device usbd_dev
enum usbd_request_return_codes _usbd_standard_request_interface(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
enum usbd_request_return_codes _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
enum usbd_request_return_codes _usbd_standard_request_device(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)
enum usbd_request_return_codes _usbd_standard_request_endpoint(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)