1 /*----------------------------------------------------------------------------
3 * Purpose: USB virtual COM port Demo
5 *----------------------------------------------------------------------------
6 * This software is supplied "AS IS" without any warranties, express,
7 * implied or statutory, including but not limited to the implied
8 * warranties of fitness for purpose, satisfactory quality and
9 * noninfringement. Keil extends you a royalty-free right to reproduce
10 * and distribute executable files created using this software for use
11 * on NXP Semiconductors LPC microcontroller devices only. Nothing else
12 * gives you the right to use this software.
14 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
15 *---------------------------------------------------------------------------*/
18 #include "lpc_types.h"
29 /* Example group ----------------------------------------------------------- */
30 /** @defgroup USBDEV_USBCDC USBCDC
31 * @ingroup USBDEV_Examples
35 /*----------------------------------------------------------------------------
36 Initialises the VCOM port.
37 Call this function before using VCOM_putchar or VCOM_getchar
38 *---------------------------------------------------------------------------*/
39 void VCOM_Init(void) {
48 /*----------------------------------------------------------------------------
49 Reads character from serial port buffer and writes to USB buffer
50 *---------------------------------------------------------------------------*/
51 void VCOM_Serial2Usb(void) {
52 static char serBuf [USB_CDC_BUFSIZE];
53 int numBytesRead, numAvailByte;
55 ser_AvailChar (&numAvailByte);
56 if (numAvailByte > 0) {
58 numBytesRead = ser_Read (&serBuf[0], &numAvailByte);
61 USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], numBytesRead);
67 /*----------------------------------------------------------------------------
68 Reads character from USB buffer and writes to serial port buffer
69 *---------------------------------------------------------------------------*/
70 void VCOM_Usb2Serial(void) {
71 static char serBuf [32];
72 int numBytesToRead, numBytesRead, numAvailByte;
74 CDC_OutBufAvailChar (&numAvailByte);
75 if (numAvailByte > 0) {
76 numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte;
77 numBytesRead = CDC_RdOutBuf (&serBuf[0], &numBytesToRead);
79 ser_Write (1, &serBuf[0], &numBytesRead);
81 ser_Write (0, &serBuf[0], &numBytesRead);
88 /*----------------------------------------------------------------------------
89 checks the serial state and initiates notification
90 *---------------------------------------------------------------------------*/
91 void VCOM_CheckSerialState (void) {
93 static unsigned short serialState;
95 temp = CDC_GetSerialState();
96 if (serialState != temp) {
98 CDC_NotificationIn(); // send SERIAL_STATE notification