1 /** 2 * \file 3 * 4 * \brief USB Standard I/O Serial Management. 5 * 6 * This file defines a useful set of functions for the Stdio Serial 7 * interface on AVR devices. 8 * 9 * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved. 10 * 11 * \asf_license_start 12 * 13 * \page License 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions are met: 17 * 18 * 1. Redistributions of source code must retain the above copyright notice, 19 * this list of conditions and the following disclaimer. 20 * 21 * 2. Redistributions in binary form must reproduce the above copyright notice, 22 * this list of conditions and the following disclaimer in the documentation 23 * and/or other materials provided with the distribution. 24 * 25 * 3. The name of Atmel may not be used to endorse or promote products derived 26 * from this software without specific prior written permission. 27 * 28 * 4. This software may only be redistributed and used in connection with an 29 * Atmel microcontroller product. 30 * 31 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 32 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 34 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 35 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 40 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGE. 42 * 43 * \asf_license_stop 44 * 45 */ 46 /* 47 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> 48 */ 49 50 #ifndef _stdio_usb_h_ 51 #define _stdio_usb_h_ 52 53 /** 54 * \defgroup group_common_utils_stdio_stdio_usb USB/CDC Standard I/O (stdio) 55 * \ingroup group_common_utils_stdio 56 * 57 * Standard I/O (stdio) management component that implements a stdio 58 * USB CDC interface on AVR devices. 59 * 60 * \{ 61 */ 62 63 #include <compiler.h> 64 65 #include <stdio.h> 66 67 #include <udc.h> 68 #include <udi_cdc.h> 69 70 extern int _write (char c, int *f); 71 extern int _read (int *f); 72 73 74 //! Pointer to the base of the USART module instance to use for stdio. 75 extern volatile void *volatile stdio_base; 76 //! Pointer to the external low level write function. 77 extern int (*ptr_put)(void volatile*, char); 78 //! Pointer to the external low level read function. 79 extern void (*ptr_get)(void volatile*, char*); 80 81 /*! \brief Sends a character with the USART. 82 * 83 * \param usart Base address of the USART instance. 84 * \param data Character to write. 85 * 86 * \return Status. 87 * \retval 0 The character was written. 88 * \retval -1 The function timed out before the transmitter became ready. 89 */ 90 int stdio_usb_putchar (volatile void * usart, char data); 91 92 /*! \brief Waits until a character is received, and returns it. 93 * 94 * \param usart Base address of the USART instance. 95 * \param data Data to read 96 * 97 * \return Nothing. 98 */ 99 void stdio_usb_getchar (void volatile * usart, char * data); 100 101 /*! \brief Enables the stdio in USB Serial Mode. 102 * 103 * \return \c 1 if function was successfully done, otherwise \c 0. 104 */ 105 bool stdio_usb_enable(void); 106 107 /*! \brief Disables the stdio in USB Serial Mode. 108 * 109 * \return Nothing. 110 */ 111 void stdio_usb_disable(void); 112 113 /*! \brief Initializes the stdio in USB Serial Mode. 114 * 115 * \return Nothing. 116 */ 117 void stdio_usb_init(void); 118 119 /** 120 * \} 121 */ 122 123 #endif // _stdio_usb_h_ 124