CDCDSerial.c
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------- */
2 /* Atmel Microcontroller Software Support */
3 /* SAM Software Package License */
4 /* ---------------------------------------------------------------------------- */
5 /* Copyright (c) 2015, Atmel Corporation */
6 /* */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without */
10 /* modification, are permitted provided that the following condition is met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, */
13 /* this list of conditions and the disclaimer below. */
14 /* */
15 /* Atmel's name may not be used to endorse or promote products derived from */
16 /* this software without specific prior written permission. */
17 /* */
18 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */
19 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */
21 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */
22 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
24 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
25 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
26 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 /* ---------------------------------------------------------------------------- */
29 
38 /*------------------------------------------------------------------------------
39  * Headers
40  *------------------------------------------------------------------------------*/
41 
42 #include "CDCDSerial.h"
43 
44 #include <USBLib_Trace.h>
45 #include <USBDDriver.h>
46 #include <USBD_HAL.h>
47 
48 /*------------------------------------------------------------------------------
49  * Types
50  *------------------------------------------------------------------------------*/
51 
52 /*------------------------------------------------------------------------------
53  * Internal variables
54  *------------------------------------------------------------------------------*/
55 
58 
59 /*------------------------------------------------------------------------------
60  * Internal functions
61  *------------------------------------------------------------------------------*/
62 
68 static uint32_t CDCDSerial_EventHandler(uint32_t event,
69  uint32_t param)
70 {
71  switch (event) {
75  (param & CDCControlLineState_DTR) > 0,
76  (param & CDCControlLineState_RTS) > 0);
77  }
78  }
79  break;
80 
82  if (NULL != (void *)CDCDSerial_LineCodingIsToChange) {
84  (CDCLineCoding *)param);
85 
86  if (event != USBRC_SUCCESS)
87  return event;
88  }
89  }
90  break;
91 
92  default:
93  return USBRC_SUCCESS;
94  }
95 
96  return USBRC_SUCCESS;
97 }
98 
99 /*------------------------------------------------------------------------------
100  * Exported functions
101  *------------------------------------------------------------------------------*/
102 
109  USBDDriver *pUsbd, uint8_t bInterfaceNb)
110 {
111  CDCDSerialPort *pCdcd = &cdcdSerial;
112 
113  TRACE_INFO("CDCDSerial_Initialize\n\r");
114 
115  /* Initialize serial port function */
117  pCdcd, pUsbd,
119  0,
120  bInterfaceNb, 2);
121 }
122 
129 void CDCDSerial_ConfigureFunction(USBGenericDescriptor *pDescriptors,
130  uint16_t wLength)
131 {
132  CDCDSerialPort *pCdcd = &cdcdSerial;
133 
135  (USBGenericDescriptor *)pDescriptors,
136  wLength);
137 }
138 
145 {
146  CDCDSerialPort *pCdcd = &cdcdSerial;
147 
148  TRACE_INFO_WP("Cdcf ");
149  return CDCDSerialPort_RequestHandler(pCdcd, request);
150 }
151 
163 uint32_t CDCDSerial_Read(void *data,
164  uint32_t size,
165  TransferCallback callback,
166  void *argument)
167 {
168  CDCDSerialPort *pCdcd = &cdcdSerial;
169 
170  return CDCDSerialPort_Read(pCdcd, data, size, callback, argument);
171 }
172 
184 uint32_t CDCDSerial_Write(void *data,
185  uint32_t size,
186  TransferCallback callback,
187  void *argument)
188 {
189  CDCDSerialPort *pCdcd = &cdcdSerial;
190 
191  return CDCDSerialPort_Write(pCdcd, data, size, callback, argument);
192 }
193 
198 {
199  CDCDSerialPort *pCdcd = &cdcdSerial;
200 
202 }
203 
208 void CDCDSerial_GetLineCoding(CDCLineCoding *pLineCoding)
209 {
210  CDCDSerialPort *pCdcd = &cdcdSerial;
211 
212  CDCDSerialPort_GetLineCoding(pCdcd, pLineCoding);
213 }
214 
219 {
220  CDCDSerialPort *pCdcd = &cdcdSerial;
221 
222  return CDCDSerialPort_GetSerialState(pCdcd);
223 }
224 
229 void CDCDSerial_SetSerialState(uint16_t serialState)
230 {
231  CDCDSerialPort *pCdcd = &cdcdSerial;
232 
233  CDCDSerialPort_SetSerialState(pCdcd, serialState);
234 }
235 
void CDCDSerial_GetLineCoding(CDCLineCoding *pLineCoding)
Definition: CDCDSerial.c:208
uint32_t CDCDSerialPort_Write(CDCDSerialPort *pCdcd, void *pData, uint32_t dwSize, TransferCallback fCallback, void *pArg)
uint16_t CDCDSerialPort_GetSerialState(const CDCDSerialPort *pCdcd)
void CDCDSerialPort_SetSerialState(CDCDSerialPort *pCdcd, uint16_t wSerialState)
void CDCDSerial_Initialize(USBDDriver *pUsbd, uint8_t bInterfaceNb)
Definition: CDCDSerial.c:108
uint32_t CDCDSerialPort_RequestHandler(CDCDSerialPort *pCdcd, const USBGenericRequest *request)
#define TRACE_INFO(...)
Definition: USBLib_Trace.h:166
uint32_t CDCDSerial_RequestHandler(const USBGenericRequest *request)
Definition: CDCDSerial.c:144
#define NULL
Definition: nm_bsp.h:52
uint16_t CDCDSerial_GetSerialState(void)
Definition: CDCDSerial.c:218
#define CDCControlLineState_RTS
Definition: CDCRequests.h:91
uint8_t CDCDSerialPort_GetControlLineState(const CDCDSerialPort *pCdcd)
uint32_t CDCDSerial_Write(void *data, uint32_t size, TransferCallback callback, void *argument)
Definition: CDCDSerial.c:184
static CDCDSerialPort cdcdSerial
Definition: CDCDSerial.c:57
static uint32_t CDCDSerial_EventHandler(uint32_t event, uint32_t param)
Definition: CDCDSerial.c:68
WEAK uint8_t CDCDSerial_LineCodingIsToChange(CDCLineCoding *pLineCoding)
void CDCDSerialPort_Initialize(CDCDSerialPort *pCdcd, USBDDriver *pUsbd, CDCDSerialPortEventHandler fEventHandler, void *pArg, uint8_t firstInterface, uint8_t numInterface)
WEAK void CDCDSerial_ControlLineStateChanged(uint8_t DTR, uint8_t RTS)
void(* TransferCallback)(void *pArg, uint8_t status, uint32_t transferred, uint32_t remaining)
Definition: USBD.h:200
void CDCDSerialPort_GetLineCoding(const CDCDSerialPort *pCdcd, CDCLineCoding *pLineCoding)
USBInterfaceDescriptor data
void CDCDSerial_ConfigureFunction(USBGenericDescriptor *pDescriptors, uint16_t wLength)
Definition: CDCDSerial.c:129
#define CDCControlLineState_DTR
Definition: CDCRequests.h:87
#define CDCDSerialPortEvent_SETCONTROLLINESTATE
uint32_t(* CDCDSerialPortEventHandler)(uint32_t dwEvent, uint32_t dwParam, void *pArguments)
uint32_t CDCDSerial_Read(void *data, uint32_t size, TransferCallback callback, void *argument)
Definition: CDCDSerial.c:163
USBGenericDescriptor * CDCDSerialPort_ParseInterfaces(CDCDSerialPort *pCdcd, USBGenericDescriptor *pDescriptors, uint32_t dwLength)
#define CDCDSerialPortEvent_SETLINECODING
#define TRACE_INFO_WP(...)
Definition: USBLib_Trace.h:167
uint8_t CDCDSerial_GetControlLineState(void)
Definition: CDCDSerial.c:197
void CDCDSerial_SetSerialState(uint16_t serialState)
Definition: CDCDSerial.c:229
uint32_t CDCDSerialPort_Read(const CDCDSerialPort *pCdcd, void *pData, uint32_t dwSize, TransferCallback fCallback, void *pArg)


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57