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 
9 #pragma once
10 
26 #define USBUS_CONTROL_EP_IN_REQUIRED_NUMOF 1
27 
31 #define USBUS_CONTROL_EP_OUT_REQUIRED_NUMOF 1
32 
33 #include "usb/usbus.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
42 typedef struct {
43  size_t start;
44  size_t cur;
45  size_t len;
46  size_t transferred;
47  size_t reqlen;
49 
53 typedef struct {
54 
59 
64 
69 
74 
78  size_t received_len;
79 
84 
89 
94 
100 
108 
118 size_t usbus_control_slicer_put_bytes(usbus_t *usbus, const uint8_t *buf,
119  size_t len);
120 
131 
138 
148 
159 uint8_t *usbus_control_get_out_data(usbus_t *usbus, size_t *len);
160 
161 #ifdef __cplusplus
162 }
163 #endif
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:104
usbus_control_request_state_t
USBUS control request state machine.
Definition: usbus.h:195
USB setup packet (USB 2.0 spec table 9-2)
Definition: descriptor.h:208
usbdev endpoint descriptor
Definition: usbdev.h:259
Endpoint zero event handler.
Definition: control.h:53
size_t received_len
Received bytes for set requests.
Definition: control.h:78
usbus_handler_t handler
inherited generic handler
Definition: control.h:58
usbus_control_slicer_t slicer
Slicer state for multipart control request messages.
Definition: control.h:73
usb_setup_t setup
Last received setup packet.
Definition: control.h:63
usbdev_ep_t * out
EP0 OUT endpoint reference.
Definition: control.h:83
usbdev_ep_t * in
EP0 IN endpoint reference.
Definition: control.h:88
usbus_control_request_state_t control_request_state
Control request state machine state.
Definition: control.h:68
helper struct to divide control messages in multiple parts
Definition: control.h:42
size_t len
Length of the full message
Definition: control.h:45
size_t reqlen
Maximum length of the request
Definition: control.h:47
size_t start
Start offset of the current part.
Definition: control.h:43
size_t transferred
Number of bytes transferred
Definition: control.h:46
size_t cur
Current position in the message
Definition: control.h:44
USBUS handler struct.
Definition: usbus.h:435
USBUS context struct.
Definition: usbus.h:447
USBUS basic interface.