LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
VirtualSerial.c
Go to the documentation of this file.
1 /*
2  * @brief Virtual Serial Device and KeyBoard Host
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * Copyright(C) Dean Camera, 2011, 2012
7  * All rights reserved.
8  *
9  * @par
10  * Software that is described herein is for illustrative purposes only
11  * which provides customers with programming information regarding the
12  * LPC products. This software is supplied "AS IS" without any warranties of
13  * any kind, and NXP Semiconductors and its licensor disclaim any and
14  * all warranties, express or implied, including all implied warranties of
15  * merchantability, fitness for a particular purpose and non-infringement of
16  * intellectual property rights. NXP Semiconductors assumes no responsibility
17  * or liability for the use of the software, conveys no license or rights under any
18  * patent, copyright, mask work right, or any other intellectual property rights in
19  * or to any products. NXP Semiconductors reserves the right to make changes
20  * in the software without notification. NXP Semiconductors also makes no
21  * representation or warranty that such application will be suitable for the
22  * specified use without further testing or modification.
23  *
24  * @par
25  * Permission to use, copy, modify, and distribute this software and its
26  * documentation is hereby granted, under NXP Semiconductors' and its
27  * licensor's relevant copyrights in the software, without fee, provided that it
28  * is used in conjunction with NXP Semiconductors microcontrollers. This
29  * copyright, permission, and disclaimer notice must appear in all copies of
30  * this code.
31  */
32 
33 #include "VirtualSerial.h"
34 #include "KeyboardHost.h"
35 
41  .Config = {
43 
44  .DataINEndpointNumber = CDC_TX_EPNUM,
45  .DataINEndpointSize = CDC_TXRX_EPSIZE,
46  .DataINEndpointDoubleBank = false,
47 
48  .DataOUTEndpointNumber = CDC_RX_EPNUM,
49  .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
50  .DataOUTEndpointDoubleBank = false,
51 
52  .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
53  .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
54  .NotificationEndpointDoubleBank = false,
55  },
56 };
57 
61 // static FILE USBSerialStream;
62 
65 #define CDC_TASK_SELECT ECHO_CHARACTER_TASK
66 
71 int main(void)
72 {
73  volatile char tecla;
74  SetupHardware();
75  tecla = 'g';
76  for (;; ) {
77  USB_Disable();
79  USB_Init();
80  while (tecla != 'h') {
81  tecla = EchoCharater();
82  USB_USBTask();
83  }
84  tecla = keyboard();
85  }
86 }
87 
89 void SetupHardware(void)
90 {
91  Board_Init();
92  // USB_Init();
93 }
94 
95 #if (CDC_TASK_SELECT == ECHO_CHARACTER_TASK)
96 
97 char EchoCharater(void)
98 {
99  /* Echo back character */
100  uint8_t recv_byte[CDC_TXRX_EPSIZE];
101 
102  if (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) {
103  recv_byte[0] = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
104  CDC_Device_SendData(&VirtualSerial_CDC_Interface, (char *) recv_byte, 1);
105  }
106 
107  return recv_byte[0];
108 }
109 
110 #else
111 
112 void CDC_Bridge_Task(void)
113 {
114  /* Echo back character */
115  uint8_t out_buff[CDC_TXRX_EPSIZE], in_buff[CDC_TXRX_EPSIZE];
116  uint32_t recv_count;
117 
118  recv_count = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface);
119  while (recv_count--) {
120  out_buff[0] = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
121  Serial_Send((uint8_t *) out_buff, 1, BLOCKING);
122  }
123 
124  recv_count = Serial_Revc(in_buff, CDC_TXRX_EPSIZE, NONE_BLOCKING);
125  if (recv_count) {
126  CDC_Device_SendData(&VirtualSerial_CDC_Interface, (char *) in_buff, recv_count);
127  }
128 }
129 
130 #endif
131 
134 {}
135 
138 {}
139 
142 {
143  bool ConfigSuccess = true;
144 
145  ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
146 
147  // LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
148 }
149 
152 {
153  CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
154 }
155 
157 {
158  /*TODO: add LineEncoding processing here
159  * this is just a simple statement, only Baud rate is set */
160  // Serial_Init(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS, false);
161 }
162 
163 #if defined(USB_DEVICE_ROM_DRIVER)
164  #error This demo is not supposed to run under ROM STACK mode
165 #endif