40#include "usb_private.h"
50 usbd_dev->control_state.state = IDLE;
62static bool needs_zlp(uint16_t len, uint16_t wLength, uint8_t ep_size)
65 if (len && (len % ep_size == 0)) {
79 for (i = 0; i < MAX_USER_CONTROL_CALLBACK; i++) {
80 if (
usbd_dev->user_control_callback[i].cb) {
84 usbd_dev->user_control_callback[i].type = type;
85 usbd_dev->user_control_callback[i].type_mask = type_mask;
86 usbd_dev->user_control_callback[i].cb = callback;
95 if (
usbd_dev->desc->bMaxPacketSize0 <
101 usbd_dev->control_state.state = DATA_IN;
114 DATA_IN : LAST_DATA_IN;
115 usbd_dev->control_state.needs_zlp =
false;
116 usbd_dev->control_state.ctrl_len = 0;
117 usbd_dev->control_state.ctrl_buf = NULL;
123 uint16_t packetsize = MIN(
usbd_dev->desc->bMaxPacketSize0,
124 usbd_dev->control_state.req.wLength -
131 if (size != packetsize) {
136 usbd_dev->control_state.ctrl_len += size;
146 struct user_control_callback *cb =
usbd_dev->user_control_callback;
149 for (i = 0; i < MAX_USER_CONTROL_CALLBACK; i++) {
150 if (cb[i].cb == NULL) {
156 &(
usbd_dev->control_state.ctrl_buf),
157 &(
usbd_dev->control_state.ctrl_len),
158 &(
usbd_dev->control_state.complete));
168 &(
usbd_dev->control_state.ctrl_buf),
169 &(
usbd_dev->control_state.ctrl_len));
190 usbd_dev->control_state.state = STATUS_IN;
208 usbd_dev->control_state.ctrl_len = 0;
211 usbd_dev->control_state.state = DATA_OUT;
213 usbd_dev->control_state.state = LAST_DATA_OUT;
227 usbd_dev->control_state.complete = NULL;
244 switch (
usbd_dev->control_state.state) {
249 if ((
usbd_dev->control_state.req.wLength -
250 usbd_dev->control_state.ctrl_len) <=
252 usbd_dev->control_state.state = LAST_DATA_OUT;
267 usbd_dev->control_state.state = STATUS_IN;
274 usbd_dev->control_state.state = IDLE;
275 if (
usbd_dev->control_state.complete) {
279 usbd_dev->control_state.complete = NULL;
291 switch (
usbd_dev->control_state.state) {
296 usbd_dev->control_state.state = STATUS_OUT;
300 if (
usbd_dev->control_state.complete) {
310 usbd_dev->control_state.state = IDLE;
static void usb_control_setup_read(usbd_device *usbd_dev, struct usb_setup_data *req)
static bool needs_zlp(uint16_t len, uint16_t wLength, uint8_t ep_size)
If we're replying with some data, but less than the host is expecting, then we normally just do a sho...
static void usb_control_send_chunk(usbd_device *usbd_dev)
int usbd_register_control_callback(usbd_device *usbd_dev, uint8_t type, uint8_t type_mask, usbd_control_callback callback)
Registers a control callback.
static void usb_control_setup_write(usbd_device *usbd_dev, struct usb_setup_data *req)
static enum usbd_request_return_codes usb_control_request_dispatch(usbd_device *usbd_dev, struct usb_setup_data *req)
static int usb_control_recv_chunk(usbd_device *usbd_dev)
static void stall_transaction(usbd_device *usbd_dev)
void usbd_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak)
Set an Out endpoint to NAK.
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.
uint16_t usbd_ep_write_packet(usbd_device *usbd_dev, uint8_t addr, const void *buf, uint16_t len)
Write a packet.
uint16_t usbd_ep_read_packet(usbd_device *usbd_dev, uint8_t addr, void *buf, uint16_t len)
Read a packet.
enum usbd_request_return_codes(* usbd_control_callback)(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete)
usbd_request_return_codes
#define USB_REQ_SET_ADDRESS
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)
static struct _usbd_device usbd_dev
enum usbd_request_return_codes _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len)