acm.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Mesotic SAS
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for
6  * more details.
7  */
8 
9 #pragma once
10 
43 #include <stdint.h>
44 #include <unistd.h>
45 
46 #include "usb/cdc.h"
47 #include "usb/usbus.h"
48 #include "tsrb.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
63 #ifdef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP
64 #define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (1<<CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP)
65 #endif
66 #ifndef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE
67 #define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (128)
68 #endif
69 
73 #if IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_8)
74 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (8)
75 #elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_16)
76 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (16)
77 #elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_32)
78 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (32)
79 #elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_64)
80 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (64)
81 #endif
82 
83 #ifndef CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE
84 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (64)
85 #endif
91 #define USBUS_CDC_ACM_INT_EP_SIZE (8)
92 
96 #define USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF 2
97 
101 #define USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF 1
102 
106 typedef enum {
111 
117 
122 
132 typedef void (*usbus_cdcacm_cb_t)(usbus_cdcacm_device_t *cdcacm,
133  uint8_t *data, size_t len);
134 
150  uint32_t baud, uint8_t bits,
151  uint8_t parity, uint8_t stop);
152 
165  size_t occupied;
174 
179 };
180 
193  usbus_cdcacm_coding_cb_t coding_cb,
194  uint8_t *buf, size_t len);
195 
207  const uint8_t *buf, size_t len);
208 
215 
225  usbus_cdcacm_coding_cb_t coding_cb);
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
Definition for USB CDC interfaces.
#define usbdev_ep_buf_t
Instantiation type for usbdev endpoint buffers.
Definition: usbdev.h:126
#define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE
USB CDC ACM bulk endpoint size.
Definition: acm.h:84
#define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE
Buffer size for STDIN and STDOUT data to and from USB when using the USBUS_CDC_ACM_STDIO module.
Definition: acm.h:67
usbus_cdcacm_line_state_t
CDC ACM line state as reported by the host computer.
Definition: acm.h:106
ssize_t usbus_cdc_acm_submit(usbus_cdcacm_device_t *cdcacm, const uint8_t *buf, size_t len)
Submit bytes to the CDC ACM handler.
void(* usbus_cdcacm_cb_t)(usbus_cdcacm_device_t *cdcacm, uint8_t *data, size_t len)
CDC ACM data callback.
Definition: acm.h:132
void usbus_cdc_acm_init(usbus_t *usbus, usbus_cdcacm_device_t *cdcacm, usbus_cdcacm_cb_t cb, usbus_cdcacm_coding_cb_t coding_cb, uint8_t *buf, size_t len)
Initialize an USBUS CDC ACM interface.
void usbus_cdc_acm_set_coding_cb(usbus_cdcacm_device_t *cdcacm, usbus_cdcacm_coding_cb_t coding_cb)
Set the callback for control settings.
void usbus_cdc_acm_flush(usbus_cdcacm_device_t *cdcacm)
Flush the buffer to the USB host.
int(* usbus_cdcacm_coding_cb_t)(usbus_cdcacm_device_t *cdcacm, uint32_t baud, uint8_t bits, uint8_t parity, uint8_t stop)
CDC ACM line coding callback.
Definition: acm.h:149
@ USBUS_CDC_ACM_LINE_STATE_DISCONNECTED
No DTE connected.
Definition: acm.h:110
@ USBUS_CDC_ACM_LINE_STATE_DTE
DTE (e.g.
Definition: acm.h:115
event structure
Definition: event.h:145
thread-safe ringbuffer struct
Definition: tsrb.h:38
USB CDC ACM line coding setup content.
Definition: cdc.h:281
USBUS CDC ACM context struct.
Definition: acm.h:156
usbus_cdcacm_coding_cb_t coding_cb
Callback for ACM coding changes.
Definition: acm.h:162
tsrb_t tsrb
TSRB for data to the host
Definition: acm.h:163
usbus_t * usbus
USBUS reference
Definition: acm.h:164
event_t flush
device2host forced flush event
Definition: acm.h:167
usbus_cdcacm_line_state_t state
Current line state
Definition: acm.h:166
usbus_handler_t handler_ctrl
control handler
Definition: acm.h:157
usb_req_cdcacm_coding_t coding
Current coding configuration
Definition: acm.h:168
usbus_interface_t iface_ctrl
CDC control interface
Definition: acm.h:158
size_t occupied
Number of bytes for the host
Definition: acm.h:165
usbus_interface_t iface_data
CDC data interface
Definition: acm.h:159
usbdev_ep_buf_t out_buf[CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE]
Host to device data buffer.
Definition: acm.h:173
usbus_cdcacm_cb_t cb
Callback for data handlers
Definition: acm.h:161
usbus_descr_gen_t cdcacm_descr
CDC descriptor generator
Definition: acm.h:160
usbdev_ep_buf_t in_buf[CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE]
Device to host data buffer.
Definition: acm.h:178
USBUS descriptor generator.
Definition: usbus.h:297
USBUS handler struct.
Definition: usbus.h:435
USBUS interface.
Definition: usbus.h:352
USBUS context struct.
Definition: usbus.h:447
Thread-safe ringbuffer interface definition.
USBUS basic interface.