control.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Koen Zandberg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef USB_USBUS_CONTROL_H
22 #define USB_USBUS_CONTROL_H
23 
27 #define USBUS_CONTROL_EP_IN_REQUIRED_NUMOF 1
28 
32 #define USBUS_CONTROL_EP_OUT_REQUIRED_NUMOF 1
33 
34 #include "usb/usbus.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 typedef struct {
44  size_t start;
45  size_t cur;
46  size_t len;
47  size_t transferred;
48  size_t reqlen;
50 
54 typedef struct {
55 
60 
65 
70 
75 
79  size_t received_len;
80 
85 
90 
95 
101 
109 
119 size_t usbus_control_slicer_put_bytes(usbus_t *usbus, const uint8_t *buf,
120  size_t len);
121 
132 
139 
149 
160 uint8_t *usbus_control_get_out_data(usbus_t *usbus, size_t *len);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 #endif /* USB_USBUS_CONTROL_H */
void usbus_control_slicer_ready(usbus_t *usbus)
Helper function to signal the end of the control message.
size_t usbus_control_slicer_put_char(usbus_t *usbus, char c)
Helper function for adding single bytes to the current control message part.
uint8_t * usbus_control_get_out_data(usbus_t *usbus, size_t *len)
Retrieve the data from the OUT pipe of the control endpoint.
int usbus_control_slicer_nextslice(usbus_t *usbus)
Initialize the next slice of the control message.
void usbus_control_init(usbus_t *usbus, usbus_control_handler_t *handler)
Initialize the control endpoint handler.
size_t usbus_control_slicer_put_bytes(usbus_t *usbus, const uint8_t *buf, size_t len)
Helper function for adding bytes to the current control message part.
#define usbdev_ep_buf_t
Instantiation type for usbdev endpoint buffers.
Definition: usbdev.h:126
#define CONFIG_USBUS_EP0_SIZE
USBUS endpoint 0 buffer size.
Definition: usbus.h:105
usbus_control_request_state_t
USBUS control request state machine.
Definition: usbus.h:196
USB setup packet (USB 2.0 spec table 9-2)
Definition: descriptor.h:207
usbdev endpoint descriptor
Definition: usbdev.h:259
Endpoint zero event handler.
Definition: control.h:54
size_t received_len
Received bytes for set requests.
Definition: control.h:79
usbus_handler_t handler
inherited generic handler
Definition: control.h:59
usbus_control_slicer_t slicer
Slicer state for multipart control request messages.
Definition: control.h:74
usb_setup_t setup
Last received setup packet.
Definition: control.h:64
usbdev_ep_t * out
EP0 OUT endpoint reference.
Definition: control.h:84
usbdev_ep_t * in
EP0 IN endpoint reference.
Definition: control.h:89
usbus_control_request_state_t control_request_state
Control request state machine state.
Definition: control.h:69
helper struct to divide control messages in multiple parts
Definition: control.h:43
size_t len
Length of the full message
Definition: control.h:46
size_t reqlen
Maximum length of the request
Definition: control.h:48
size_t start
Start offset of the current part.
Definition: control.h:44
size_t transferred
Number of bytes transferred
Definition: control.h:47
size_t cur
Current position in the message
Definition: control.h:45
USBUS handler struct.
Definition: usbus.h:436
USBUS context struct.
Definition: usbus.h:448
USBUS basic interface.