LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
usbd_cdcuser.h
Go to the documentation of this file.
1 /*
2  * @brief Definition of functions exported by ROM based CDC function driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #include "error.h"
33 #include "usbd.h"
34 #include "usbd_cdc.h"
35 
36 #ifndef __CDCUSER_H__
37 #define __CDCUSER_H__
38 
39 
51 /*----------------------------------------------------------------------------
52  We need a buffer for incomming data on USB port because USB receives
53  much faster than UART transmits
54  *---------------------------------------------------------------------------*/
55 /* Buffer masks */
56 #define CDC_BUF_SIZE (128) /* Output buffer in bytes (power 2) */
57  /* large enough for file transfer */
58 #define CDC_BUF_MASK (CDC_BUF_SIZE-1ul)
59 
67 typedef struct USBD_CDC_INIT_PARAM
68 {
69  /* memory allocation params */
70  uint32_t mem_base;
75  uint32_t mem_size;
82  uint8_t* cif_intf_desc;
87  uint8_t* dif_intf_desc;
88 
89  /* user defined functions */
90 
91  /* required functions */
116  ErrorCode_t (*CIC_GetRequest)( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* length);
117 
147  ErrorCode_t (*CIC_SetRequest)( USBD_HANDLE_T hCdc, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length);
148 
166  ErrorCode_t (*CDC_BulkIN_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
167 
185  ErrorCode_t (*CDC_BulkOUT_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
186 
187  ErrorCode_t (*SendEncpsCmd) (USBD_HANDLE_T hCDC, uint8_t* buffer, uint16_t len);
188  ErrorCode_t (*GetEncpsResp) (USBD_HANDLE_T hCDC, uint8_t** buffer, uint16_t* len);
189  ErrorCode_t (*SetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t* buffer, uint16_t len);
190  ErrorCode_t (*GetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t** pBuffer, uint16_t* len);
191  ErrorCode_t (*ClrCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature);
192  ErrorCode_t (*SetCtrlLineState) (USBD_HANDLE_T hCDC, uint16_t state);
193  ErrorCode_t (*SendBreak) (USBD_HANDLE_T hCDC, uint16_t mstime);
194  ErrorCode_t (*SetLineCode) (USBD_HANDLE_T hCDC, CDC_LINE_CODING* line_coding);
195 
213  ErrorCode_t (*CDC_InterruptEP_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
214 
234  ErrorCode_t (*CDC_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
235 
237 
244 typedef struct USBD_CDC_API
245 {
257  uint32_t (*GetMemSize)(USBD_CDC_INIT_PARAM_T* param);
258 
276 
293  ErrorCode_t (*SendNotification)(USBD_HANDLE_T hCdc, uint8_t bNotification, uint16_t data);
294 
296 
297 /*-----------------------------------------------------------------------------
298  * Private functions & structures prototypes
299  *-----------------------------------------------------------------------------*/
302 typedef struct _CDC_CTRL_T
303 {
304  USB_CORE_CTRL_T* pUsbCtrl;
305  /* notification buffer */
306  uint8_t notice_buf[12];
307  CDC_LINE_CODING line_coding;
308 
309  uint8_t cif_num; /* control interface number */
310  uint8_t dif_num; /* data interface number */
311  uint8_t epin_num; /* BULK IN endpoint number */
312  uint8_t epout_num; /* BULK OUT endpoint number */
313  uint8_t epint_num; /* Interrupt IN endpoint number */
314 
315  /* user defined functions */
316  ErrorCode_t (*SendEncpsCmd) (USBD_HANDLE_T hCDC, uint8_t* buffer, uint16_t len);
317  ErrorCode_t (*GetEncpsResp) (USBD_HANDLE_T hCDC, uint8_t** buffer, uint16_t* len);
318  ErrorCode_t (*SetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t* buffer, uint16_t len);
319  ErrorCode_t (*GetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t** pBuffer, uint16_t* len);
320  ErrorCode_t (*ClrCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature);
321  ErrorCode_t (*SetCtrlLineState) (USBD_HANDLE_T hCDC, uint16_t state);
322  ErrorCode_t (*SendBreak) (USBD_HANDLE_T hCDC, uint16_t state);
323  ErrorCode_t (*SetLineCode) (USBD_HANDLE_T hCDC, CDC_LINE_CODING* line_coding);
324 
325  /* virtual functions */
326  ErrorCode_t (*CIC_GetRequest)( USBD_HANDLE_T hCdc, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* length);
327  ErrorCode_t (*CIC_SetRequest)( USBD_HANDLE_T hCdc, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length);
328 
329 }USB_CDC_CTRL_T;
330 
331 
334 void UsbdCdc_IO_Buffer_Sync_Task(void);
335 void UsbdCdc_SendData(uint8_t* buffer, uint32_t cnt);
336 uint32_t UsbdCdc_RecvData(uint8_t* buffer, uint32_t len);
337 
338 
339 #endif /* __CDCUSER_H__ */
340