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
89 #define CDC_PRINT_BUF_SIZE 256
90 extern char printbuf[CDC_PRINT_BUF_SIZE];
96 * \defgroup udi_cdc_group USB Device Interface (UDI) for Communication Class Device (CDC)
98 * Common APIs used by high level application to use this USB class.
100 * These routines are used to transfer and control data
101 * to/from USB CDC endpoint.
103 * See \ref udi_cdc_quickstart.
108 * \name Interface for application with single CDC interface support
113 * \brief Notify a state change of DCD signal
115 * \param b_set DCD is enabled if true, else disabled
117 void udi_cdc_ctrl_signal_dcd(bool b_set);
120 * \brief Notify a state change of DSR signal
122 * \param b_set DSR is enabled if true, else disabled
124 void udi_cdc_ctrl_signal_dsr(bool b_set);
127 * \brief Notify a framing error
129 void udi_cdc_signal_framing_error(void);
132 * \brief Notify a parity error
134 void udi_cdc_signal_parity_error(void);
137 * \brief Notify a overrun
139 void udi_cdc_signal_overrun(void);
142 * \brief Gets the number of byte received
144 * \return the number of data available
146 iram_size_t udi_cdc_get_nb_received_data(void);
149 * \brief This function checks if a character has been received on the CDC line
151 * \return \c 1 if a byte is ready to be read.
153 bool udi_cdc_is_rx_ready(void);
156 * \brief Waits and gets a value on CDC line
158 * \return value read on CDC line
160 int udi_cdc_getc(void);
163 * \brief Reads a RAM buffer on CDC line
165 * \param buf Values read
166 * \param size Number of value read
168 * \return the number of data remaining
170 iram_size_t udi_cdc_read_buf(void* buf, iram_size_t size);
173 * \brief Non polling reads of a up to 'size' data from CDC line
175 * \param port Communication port number to manage
176 * \param buf Buffer where to store read data
177 * \param size Maximum number of data to read (size of buffer)
179 * \return the number of data effectively read
181 iram_size_t udi_cdc_read_no_polling(void* buf, iram_size_t size);
184 * \brief Gets the number of free byte in TX buffer
186 * \return the number of free byte in TX buffer
188 iram_size_t udi_cdc_get_free_tx_buffer(void);
191 * \brief This function checks if a new character sent is possible
192 * The type int is used to support scanf redirection from compiler LIB.
194 * \return \c 1 if a new character can be sent
196 bool udi_cdc_is_tx_ready(void);
199 * \brief Puts a byte on CDC line
200 * The type int is used to support printf redirection from compiler LIB.
202 * \param value Value to put
204 * \return \c 1 if function was successfully done, otherwise \c 0.
206 int udi_cdc_putc(int value);
209 * \brief Writes a RAM buffer on CDC line
211 * \param buf Values to write
212 * \param size Number of value to write
214 * \return the number of data remaining
216 iram_size_t udi_cdc_write_buf(const void* buf, iram_size_t size);
220 * \name Interface for application with multi CDC interfaces support
225 * \brief Notify a state change of DCD signal
227 * \param port Communication port number to manage
228 * \param b_set DCD is enabled if true, else disabled
230 void udi_cdc_multi_ctrl_signal_dcd(uint8_t port, bool b_set);
233 * \brief Notify a state change of DSR signal
235 * \param port Communication port number to manage
236 * \param b_set DSR is enabled if true, else disabled
238 void udi_cdc_multi_ctrl_signal_dsr(uint8_t port, bool b_set);
241 * \brief Notify a framing error
243 * \param port Communication port number to manage
245 void udi_cdc_multi_signal_framing_error(uint8_t port);
248 * \brief Notify a parity error
250 * \param port Communication port number to manage
252 void udi_cdc_multi_signal_parity_error(uint8_t port);
255 * \brief Notify a overrun
257 * \param port Communication port number to manage
259 void udi_cdc_multi_signal_overrun(uint8_t port);
262 * \brief Gets the number of byte received
264 * \param port Communication port number to manage
266 * \return the number of data available
268 iram_size_t udi_cdc_multi_get_nb_received_data(uint8_t port);
271 * \brief This function checks if a character has been received on the CDC line
273 * \param port Communication port number to manage
275 * \return \c 1 if a byte is ready to be read.
277 bool udi_cdc_multi_is_rx_ready(uint8_t port);
280 * \brief Waits and gets a value on CDC line
282 * \param port Communication port number to manage
284 * \return value read on CDC line
286 int udi_cdc_multi_getc(uint8_t port);
289 * \brief Reads a RAM buffer on CDC line
291 * \param port Communication port number to manage
292 * \param buf Values read
293 * \param size Number of values read
295 * \return the number of data remaining
297 iram_size_t udi_cdc_multi_read_buf(uint8_t port, void* buf, iram_size_t size);
300 * \brief Gets the number of free byte in TX buffer
302 * \param port Communication port number to manage
304 * \return the number of free byte in TX buffer
306 iram_size_t udi_cdc_multi_get_free_tx_buffer(uint8_t port);
309 * \brief This function checks if a new character sent is possible
310 * The type int is used to support scanf redirection from compiler LIB.
312 * \param port Communication port number to manage
314 * \return \c 1 if a new character can be sent
316 bool udi_cdc_multi_is_tx_ready(uint8_t port);
319 * \brief Puts a byte on CDC line
320 * The type int is used to support printf redirection from compiler LIB.
322 * \param port Communication port number to manage
323 * \param value Value to put
325 * \return \c 1 if function was successfully done, otherwise \c 0.
327 int udi_cdc_multi_putc(uint8_t port, int value);
330 * \brief Writes a RAM buffer on CDC line
332 * \param port Communication port number to manage
333 * \param buf Values to write
334 * \param size Number of value to write
336 * \return the number of data remaining
338 iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t size);
341 #define CDC_PRINTBUF_SIZE 256
342 extern char printbuf[CDC_PRINTBUF_SIZE];
344 #define CDC_INBUF_SIZE 256
349 char buf[CDC_INBUF_SIZE];
354 // keep these to accommodate calls if remaining
355 #define CDC_PRINTBUF_SIZE 1
356 extern char printbuf[CDC_PRINTBUF_SIZE];
358 #define CDC_INBUF_SIZE 1
363 char buf[CDC_INBUF_SIZE];
366 extern inbuf_t inbuf;
370 uint32_t CDC_print(char *printbuf);
371 uint32_t CDC_input(void);
374 #define __xprintf dpf
375 int dpf(const char *_Format, ...);
381 #endif // _UDI_CDC_H_