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 
28 #ifndef USB_USBUS_CDC_ACM_H
29 #define USB_USBUS_CDC_ACM_H
30 
31 #include <stdint.h>
32 #include "usb/cdc.h"
33 #include "usb/usbus.h"
34 #include "tsrb.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
49 #ifdef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP
50 #define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (1<<CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE_EXP)
51 #endif
52 #ifndef CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE
53 #define CONFIG_USBUS_CDC_ACM_STDIO_BUF_SIZE (128)
54 #endif
55 
59 #if IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_8)
60 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (8)
61 #elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_16)
62 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (16)
63 #elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_32)
64 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (32)
65 #elif IS_ACTIVE(CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE_64)
66 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (64)
67 #endif
68 
69 #ifndef CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE
70 #define CONFIG_USBUS_CDC_ACM_BULK_EP_SIZE (64)
71 #endif
72 
77 #define USBUS_CDC_ACM_INT_EP_SIZE (8)
78 
82 typedef enum {
87 
93 
98 
108 typedef void (*usbus_cdcacm_cb_t)(usbus_cdcacm_device_t *cdcacm,
109  uint8_t *data, size_t len);
110 
126  uint32_t baud, uint8_t bits,
127  uint8_t parity, uint8_t stop);
128 
141  size_t occupied;
145 };
146 
159  usbus_cdcacm_coding_cb_t coding_cb,
160  uint8_t *buf, size_t len);
161 
172  const uint8_t *buf, size_t len);
173 
180 
190  usbus_cdcacm_coding_cb_t coding_cb);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* USB_USBUS_CDC_ACM_H */
197 
usbus.h
USBUS basic interface.
usbus_cdcacm_device::state
usbus_cdcacm_line_state_t state
Current line state
Definition: acm.h:142
usbus_cdcacm_device::iface_ctrl
usbus_interface_t iface_ctrl
CDC control interface
Definition: acm.h:134
usbus_cdcacm_device::tsrb
tsrb_t tsrb
TSRB for data to the host
Definition: acm.h:139
usbus_cdcacm_device::usbus
usbus_t * usbus
USBUS reference
Definition: acm.h:140
usb_req_cdcacm_coding_t
USB CDC ACM line coding setup content.
Definition: cdc.h:281
event
event structure
Definition: event.h:142
usbus_cdcacm_device::cdcacm_descr
usbus_descr_gen_t cdcacm_descr
CDC descriptor generator
Definition: acm.h:136
usbus_cdcacm_coding_cb_t
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:125
usbus_cdcacm_device::handler_ctrl
usbus_handler_t handler_ctrl
control handler
Definition: acm.h:133
usbus_cdcacm_device::iface_data
usbus_interface_t iface_data
CDC data interface
Definition: acm.h:135
usbus_cdcacm_device::coding
usb_req_cdcacm_coding_t coding
Current coding configuration
Definition: acm.h:144
usbus_cdc_acm_submit
size_t usbus_cdc_acm_submit(usbus_cdcacm_device_t *cdcacm, const uint8_t *buf, size_t len)
Submit bytes to the CDC ACM handler.
USBUS_CDC_ACM_LINE_STATE_DISCONNECTED
@ USBUS_CDC_ACM_LINE_STATE_DISCONNECTED
No DTE connected.
Definition: acm.h:86
usbus_handler
USBUS handler struct.
Definition: usbus.h:385
usbus_cdc_acm_flush
void usbus_cdc_acm_flush(usbus_cdcacm_device_t *cdcacm)
Flush the buffer to the USB host.
usbus_cdc_acm_set_coding_cb
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.
usbus_cdcacm_line_state_t
usbus_cdcacm_line_state_t
CDC ACM line state as reported by the host computer.
Definition: acm.h:82
usbus_cdcacm_device::occupied
size_t occupied
Number of bytes for the host
Definition: acm.h:141
usbus_descr_gen
USBUS descriptor generator.
Definition: usbus.h:263
usbus_interface
USBUS interface.
Definition: usbus.h:302
usbus_cdcacm_device
USBUS CDC ACM context struct.
Definition: acm.h:132
cdc.h
Definition for USB CDC interfaces.
usbus_cdcacm_device::cb
usbus_cdcacm_cb_t cb
Callback for data handlers
Definition: acm.h:137
usbus_cdc_acm_init
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.
tsrb
thread-safe ringbuffer struct
Definition: tsrb.h:39
usbus_cdcacm_device::flush
event_t flush
device2host forced flush event
Definition: acm.h:143
usbus_cdcacm_cb_t
void(* usbus_cdcacm_cb_t)(usbus_cdcacm_device_t *cdcacm, uint8_t *data, size_t len)
CDC ACM data callback.
Definition: acm.h:108
USBUS_CDC_ACM_LINE_STATE_DTE
@ USBUS_CDC_ACM_LINE_STATE_DTE
DTE (e.g.
Definition: acm.h:91
tsrb.h
Thread-safe ringbuffer interface definition.
usbus_cdcacm_device::coding_cb
usbus_cdcacm_coding_cb_t coding_cb
Callback for ACM coding changes.
Definition: acm.h:138
usbus
USBUS context struct.
Definition: usbus.h:397