4 * \brief USB Device Communication Device Class (CDC) interface definitions.
6 * Copyright (c) 2009-2016 Atmel Corporation. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
22 * 3. The name of Atmel may not be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * 4. This software may only be redistributed and used in connection with an
26 * Atmel microcontroller product.
28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
53 #include "usb_protocol.h"
54 #include "usb_protocol_cdc.h"
59 // Check the number of port
60 #ifndef UDI_CDC_PORT_NB
61 # define UDI_CDC_PORT_NB 1
63 #if (UDI_CDC_PORT_NB > 1)
64 # error UDI_CDC_PORT_NB must be at most 1
72 * \addtogroup udi_cdc_group_udc
76 //! Global structure which contains standard UDI API for UDC
77 extern UDC_DESC_STORAGE udi_api_t udi_api_cdc_comm;
78 extern UDC_DESC_STORAGE udi_api_t udi_api_cdc_data;
81 //#define CDC_ACM_SIZE 64 see usb_protocol_cdc.h
82 //#define CDC_RX_SIZE 64
84 //! CDC communication endpoints size for all speeds
85 #define UDI_CDC_COMM_EP_SIZE CDC_ACM_SIZE
86 //! CDC data endpoints size for FS speed (8B, 16B, 32B, 64B)
87 #define UDI_CDC_DATA_EPS_FS_SIZE CDC_RX_SIZE
93 * \defgroup udi_cdc_group USB Device Interface (UDI) for Communication Class Device (CDC)
95 * Common APIs used by high level application to use this USB class.
97 * These routines are used to transfer and control data
98 * to/from USB CDC endpoint.
100 * See \ref udi_cdc_quickstart.
105 * \name Interface for application with single CDC interface support
110 * \brief Notify a state change of DCD signal
112 * \param b_set DCD is enabled if true, else disabled
114 void udi_cdc_ctrl_signal_dcd(bool b_set);
117 * \brief Notify a state change of DSR signal
119 * \param b_set DSR is enabled if true, else disabled
121 void udi_cdc_ctrl_signal_dsr(bool b_set);
124 * \brief Notify a framing error
126 void udi_cdc_signal_framing_error(void);
129 * \brief Notify a parity error
131 void udi_cdc_signal_parity_error(void);
134 * \brief Notify a overrun
136 void udi_cdc_signal_overrun(void);
139 * \brief Gets the number of byte received
141 * \return the number of data available
143 iram_size_t udi_cdc_get_nb_received_data(void);
146 * \brief This function checks if a character has been received on the CDC line
148 * \return \c 1 if a byte is ready to be read.
150 bool udi_cdc_is_rx_ready(void);
153 * \brief Waits and gets a value on CDC line
155 * \return value read on CDC line
157 int udi_cdc_getc(void);
160 * \brief Reads a RAM buffer on CDC line
162 * \param buf Values read
163 * \param size Number of value read
165 * \return the number of data remaining
167 iram_size_t udi_cdc_read_buf(void* buf, iram_size_t size);
170 * \brief Non polling reads of a up to 'size' data from CDC line
172 * \param port Communication port number to manage
173 * \param buf Buffer where to store read data
174 * \param size Maximum number of data to read (size of buffer)
176 * \return the number of data effectively read
178 iram_size_t udi_cdc_read_no_polling(void* buf, iram_size_t size);
181 * \brief Gets the number of free byte in TX buffer
183 * \return the number of free byte in TX buffer
185 iram_size_t udi_cdc_get_free_tx_buffer(void);
188 * \brief This function checks if a new character sent is possible
189 * The type int is used to support scanf redirection from compiler LIB.
191 * \return \c 1 if a new character can be sent
193 bool udi_cdc_is_tx_ready(void);
196 * \brief Puts a byte on CDC line
197 * The type int is used to support printf redirection from compiler LIB.
199 * \param value Value to put
201 * \return \c 1 if function was successfully done, otherwise \c 0.
203 int udi_cdc_putc(int value);
206 * \brief Writes a RAM buffer on CDC line
208 * \param buf Values to write
209 * \param size Number of value to write
211 * \return the number of data remaining
213 iram_size_t udi_cdc_write_buf(const void* buf, iram_size_t size);
217 * \name Interface for application with multi CDC interfaces support
222 * \brief Notify a state change of DCD signal
224 * \param port Communication port number to manage
225 * \param b_set DCD is enabled if true, else disabled
227 void udi_cdc_multi_ctrl_signal_dcd(uint8_t port, bool b_set);
230 * \brief Notify a state change of DSR signal
232 * \param port Communication port number to manage
233 * \param b_set DSR is enabled if true, else disabled
235 void udi_cdc_multi_ctrl_signal_dsr(uint8_t port, bool b_set);
238 * \brief Notify a framing error
240 * \param port Communication port number to manage
242 void udi_cdc_multi_signal_framing_error(uint8_t port);
245 * \brief Notify a parity error
247 * \param port Communication port number to manage
249 void udi_cdc_multi_signal_parity_error(uint8_t port);
252 * \brief Notify a overrun
254 * \param port Communication port number to manage
256 void udi_cdc_multi_signal_overrun(uint8_t port);
259 * \brief Gets the number of byte received
261 * \param port Communication port number to manage
263 * \return the number of data available
265 iram_size_t udi_cdc_multi_get_nb_received_data(uint8_t port);
268 * \brief This function checks if a character has been received on the CDC line
270 * \param port Communication port number to manage
272 * \return \c 1 if a byte is ready to be read.
274 bool udi_cdc_multi_is_rx_ready(uint8_t port);
277 * \brief Waits and gets a value on CDC line
279 * \param port Communication port number to manage
281 * \return value read on CDC line
283 int udi_cdc_multi_getc(uint8_t port);
286 * \brief Reads a RAM buffer on CDC line
288 * \param port Communication port number to manage
289 * \param buf Values read
290 * \param size Number of values read
292 * \return the number of data remaining
294 iram_size_t udi_cdc_multi_read_buf(uint8_t port, void* buf, iram_size_t size);
297 * \brief Gets the number of free byte in TX buffer
299 * \param port Communication port number to manage
301 * \return the number of free byte in TX buffer
303 iram_size_t udi_cdc_multi_get_free_tx_buffer(uint8_t port);
306 * \brief This function checks if a new character sent is possible
307 * The type int is used to support scanf redirection from compiler LIB.
309 * \param port Communication port number to manage
311 * \return \c 1 if a new character can be sent
313 bool udi_cdc_multi_is_tx_ready(uint8_t port);
316 * \brief Puts a byte on CDC line
317 * The type int is used to support printf redirection from compiler LIB.
319 * \param port Communication port number to manage
320 * \param value Value to put
322 * \return \c 1 if function was successfully done, otherwise \c 0.
324 int udi_cdc_multi_putc(uint8_t port, int value);
327 * \brief Writes a RAM buffer on CDC line
329 * \param port Communication port number to manage
330 * \param buf Values to write
331 * \param size Number of value to write
333 * \return the number of data remaining
335 iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t size);
338 #define CDC_PRINTBUF_SIZE 256
339 extern char printbuf[CDC_PRINTBUF_SIZE];
341 #define CDC_INBUF_SIZE 256
346 char buf[CDC_INBUF_SIZE];
351 // keep these to accommodate calls if remaining
352 #define CDC_PRINTBUF_SIZE 1
353 extern char printbuf[CDC_PRINTBUF_SIZE];
355 #define CDC_INBUF_SIZE 1
360 char buf[CDC_INBUF_SIZE];
363 extern inbuf_t inbuf;
367 uint32_t CDC_print(char *printbuf);
368 uint32_t CDC_input(void);
375 #endif // _UDI_CDC_H_