3 Copyright (C) Dean Camera, 2012.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11 Copyright 2012 Simon Foster (simon.foster [at] inbox [dot] com)
13 Permission to use, copy, modify, distribute, and sell this
14 software and its documentation for any purpose is hereby granted
15 without fee, provided that the above copyright notice appear in
16 all copies and that both that the copyright notice and this
17 permission notice and warranty disclaimer appear in supporting
18 documentation, and that the name of the author not be used in
19 advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
22 The author disclaim all warranties with regard to this
23 software, including all implied warranties of merchantability
24 and fitness. In no event shall the author be liable for any
25 special, indirect or consequential damages or any damages
26 whatsoever resulting from loss of use, data or profits, whether
27 in an action of contract, negligence or other tortious action,
28 arising out of or in connection with the use or performance of
34 * Main source file for the SerialToLCD program. This file contains the main tasks of
35 * the project and is responsible for the initial application hardware configuration.
37 * \section Hardware Information
39 * LCD Datasheet: See http://www.sparkfun.com/datasheets/LCD/HD44780.pdf
41 * Also see the two articles from EPE which are linked from here:
42 * http://en.wikipedia.org/wiki/HD44780_Character_LCD
44 * Connections from the Minimus to the HD44780 as shown below.
46 * ========================================================= \n
47 * Minimus HD44780 Pin \n
48 * ========================================================= \n
63 #include "SerialToLCD.h"
65 /** Circular buffer to hold data from the host before it is sent to the LCD */
66 static RingBuffer_t FromHost_Buffer
;
68 /** Underlying data buffer for \ref FromHost_Buffer, where the stored bytes are located. */
69 static uint8_t FromHost_Buffer_Data
[128];
71 /** LUFA CDC Class driver interface configuration and state information. This structure is
72 * passed to all CDC Class driver functions, so that multiple instances of the same class
73 * within a device can be differentiated from one another.
75 USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface
=
79 .ControlInterfaceNumber
= 0,
82 .Address
= CDC_TX_EPADDR
,
83 .Size
= CDC_TXRX_EPSIZE
,
88 .Address
= CDC_RX_EPADDR
,
89 .Size
= CDC_TXRX_EPSIZE
,
92 .NotificationEndpoint
=
94 .Address
= CDC_NOTIFICATION_EPADDR
,
95 .Size
= CDC_NOTIFICATION_EPSIZE
,
102 /** Main program entry point. This routine contains the overall program flow, including initial
103 * setup of all components and the main program loop.
109 RingBuffer_InitBuffer(&FromHost_Buffer
, FromHost_Buffer_Data
, sizeof(FromHost_Buffer_Data
));
115 /* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
116 if (!(RingBuffer_IsFull(&FromHost_Buffer
)))
118 int16_t ReceivedByte
= CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface
);
120 /* Read bytes from the USB OUT endpoint into the USART transmit buffer */
121 if (!(ReceivedByte
< 0))
122 RingBuffer_Insert(&FromHost_Buffer
, ReceivedByte
);
125 while (RingBuffer_GetCount(&FromHost_Buffer
) > 0)
127 static uint8_t escape_pending
= 0;
128 int16_t HD44780Byte
= RingBuffer_Remove(&FromHost_Buffer
);
130 if (HD44780Byte
== COMMAND_ESCAPE
)
134 HD44780_WriteData(HD44780Byte
);
146 HD44780_WriteCommand(HD44780Byte
);
151 HD44780_WriteData(HD44780Byte
);
156 CDC_Device_USBTask(&VirtualSerial_CDC_Interface
);
161 /** Configures the board hardware and chip peripherals for the application's functionality. */
162 void SetupHardware(void)
164 /* Disable watchdog if enabled by bootloader/fuses */
165 MCUSR
&= ~(1 << WDRF
);
168 /* Disable clock division */
169 clock_prescale_set(clock_div_1
);
171 /* Hardware Initialization */
174 /* Power up the HD44780 Interface */
175 HD44780_Initialise();
176 HD44780_WriteCommand(CMD_DISPLAY_ON
);
178 /* Start the flush timer so that overflows occur rapidly to push received bytes to the USB interface */
179 TCCR0B
= (1 << CS02
);
182 /** Event handler for the library USB Configuration Changed event. */
183 void EVENT_USB_Device_ConfigurationChanged(void)
185 bool ConfigSuccess
= true;
187 ConfigSuccess
&= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface
);
190 /** Event handler for the library USB Control Request reception event. */
191 void EVENT_USB_Device_ControlRequest(void)
193 CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface
);