00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2014, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 00028 */ 00029 00030 /** \file 00031 * Definition of a class for implementing a USB device 00032 * CDC serial port function. 00033 */ 00034 00035 #ifndef _CDCDSERIALPORT_H_ 00036 #define _CDCDSERIALPORT_H_ 00037 00038 /*------------------------------------------------------------------------------ 00039 * Headers 00040 *------------------------------------------------------------------------------*/ 00041 00042 /* These headers were introduced in C99 00043 by working group ISO/IEC JTC1/SC22/WG14. */ 00044 #include <stdint.h> 00045 00046 #include <USBRequests.h> 00047 #include <CDCRequests.h> 00048 #include <CDCNotifications.h> 00049 #include "USBD.h" 00050 #include <USBDDriver.h> 00051 /** \addtogroup usbd_cdc 00052 *@{ 00053 */ 00054 00055 /*------------------------------------------------------------------------------ 00056 * Defines 00057 *------------------------------------------------------------------------------*/ 00058 00059 /** \addtogroup usbd_cdc_serial_desc USB Device Serial Port Descriptor Values 00060 * @{ 00061 */ 00062 /** Default CDC interrupt endpoints max packat size (8). */ 00063 #define CDCDSerialPort_INTERRUPT_MAXPACKETSIZE 8 00064 /** Default CDC interrupt endpoint polling rate of High Speed (16ms). */ 00065 #define CDCDSerialPort_INTERRUPT_INTERVAL_HS 8 00066 /** Default CDC interrupt endpoint polling rate of Full Speed (16ms). */ 00067 #define CDCDSerialPort_INTERRUPT_INTERVAL_FS 16 00068 /** Default CDC bulk endpoints max packat size (512, for HS actually). */ 00069 #define CDCDSerialPort_BULK_MAXPACKETSIZE_HS 512 00070 /** Default CDC bulk endpoints max packat size (64, for FS actually). */ 00071 #define CDCDSerialPort_BULK_MAXPACKETSIZE_FS 64 00072 /** @}*/ 00073 00074 /** \addtogroup usbd_cdc_serial_events USB Device Serial Port Events 00075 * @{ 00076 */ 00077 /** SetControlLineState event, value is changed */ 00078 #define CDCDSerialPortEvent_SETCONTROLLINESTATE 0 00079 /** SetLineCoding event, value is to changed according to return value */ 00080 #define CDCDSerialPortEvent_SETLINECODING 1 00081 /** @}*/ 00082 00083 /*------------------------------------------------------------------------------ 00084 * Types 00085 *------------------------------------------------------------------------------*/ 00086 00087 /** Callback function for serial port events */ 00088 typedef uint32_t (*CDCDSerialPortEventHandler)(uint32_t dwEvent, 00089 uint32_t dwParam, 00090 void * pArguments); 00091 00092 /** 00093 * Struct for USB CDC virtual COM serial port function. 00094 */ 00095 typedef struct _CDCDSerialPort { 00096 /** USB Driver for the %device */ 00097 USBDDriver *pUsbd; 00098 /** Callback for serial port events */ 00099 CDCDSerialPortEventHandler fEventHandler; 00100 /** Callback arguments */ 00101 void *pArg; 00102 /** USB starting interface index */ 00103 uint8_t bInterfaceNdx; 00104 /** USB number of interfaces */ 00105 uint8_t bNumInterface; 00106 /** USB interrupt IN endpoint address */ 00107 uint8_t bIntInPIPE; 00108 /** USB bulk IN endpoint address */ 00109 uint8_t bBulkInPIPE; 00110 /** USB bulk OUT endpoint address */ 00111 uint8_t bBulkOutPIPE; 00112 00113 /** Serial port ControlLineState */ 00114 uint8_t bControlLineState; 00115 /** Serial port SerialState */ 00116 uint16_t wSerialState; 00117 /** Serial port linecoding */ 00118 CDCLineCoding lineCoding; 00119 00120 uint8_t bReserved; 00121 } CDCDSerialPort; 00122 00123 /*------------------------------------------------------------------------------ 00124 * Functions 00125 *------------------------------------------------------------------------------*/ 00126 00127 extern void CDCDSerialPort_Initialize(CDCDSerialPort *pCdcd, 00128 USBDDriver *pUsbd, 00129 CDCDSerialPortEventHandler fCallback, 00130 void *pArg, 00131 uint8_t firstInterface, 00132 uint8_t numInterface); 00133 00134 extern USBGenericDescriptor * CDCDSerialPort_ParseInterfaces( 00135 CDCDSerialPort * pCdcd, 00136 USBGenericDescriptor * pDescriptors, uint32_t dwLength); 00137 00138 extern uint32_t CDCDSerialPort_RequestHandler( 00139 CDCDSerialPort *pCdcd, 00140 const USBGenericRequest *pRequest); 00141 00142 extern uint32_t CDCDSerialPort_Write( 00143 const CDCDSerialPort *pCdcd, 00144 void *pData, uint32_t dwSize, 00145 TransferCallback fCallback, void* pArg); 00146 00147 extern uint32_t CDCDSerialPort_Read( 00148 const CDCDSerialPort *pCdcd, 00149 void *pData, uint32_t dwSize, 00150 TransferCallback fCallback, void* pArg); 00151 00152 extern uint16_t CDCDSerialPort_GetSerialState( 00153 const CDCDSerialPort *pCdcd); 00154 00155 extern void CDCDSerialPort_SetSerialState( 00156 CDCDSerialPort *pCdcd, 00157 uint16_t wSerialState); 00158 00159 extern uint8_t CDCDSerialPort_GetControlLineState( 00160 const CDCDSerialPort * pCdcd); 00161 00162 extern void CDCDSerialPort_GetLineCoding( 00163 const CDCDSerialPort * pCdcd, 00164 CDCLineCoding * pLineCoding); 00165 00166 /**@}*/ 00167 #endif /* #ifndef _CDCDSERIALPORT_H_ */