Don't compile in ISP sources into the XPLAIN bridge project.
[pub/USBasp.git] / Projects / SerialToLCD / SerialToLCD.c
index 7a28927..85abbdb 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2012.
+     Copyright (C) Dean Camera, 2017.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)
   Copyright 2012  Simon Foster (simon.foster [at] inbox [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
@@ -19,7 +19,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
   this software.
 */
 
-/** \file 
+/** \file
  *
  *  Main source file for the SerialToLCD program. This file contains the main tasks of
  *  the project and is responsible for the initial application hardware configuration.
- *    
- *  \section Hardware Information
- *
- *    LCD Datasheet:  See http://www.sparkfun.com/datasheets/LCD/HD44780.pdf
- *   
- *   Also see the two articles from EPE which are linked from here:
- *   http://en.wikipedia.org/wiki/HD44780_Character_LCD
- *
- *   Connections from the Minimus to the HD44780 as shown below.
- *   
- *   =========================================================  \n
- *   Minimus                 HD44780     Pin                    \n
- *   =========================================================  \n
- *   PD0                     DB4         11                     \n
- *   PD1                     DB5         12                     \n
- *   PD2                     DB6         13                     \n
- *   PD3                     DB7         14                     \n
- *                                                              \n
- *   PD4                     RS          4                      \n
- *                           RW          5       GND            \n
- *   PD7                     EN          6                      \n
- *                                                              \n
- *                                       1       GND            \n
- *                                       2       USB +5V        \n
- *                                       3       2k -> GND      \n
  */
 
 #include "SerialToLCD.h"
@@ -76,7 +51,7 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
        {
                .Config =
                        {
-                               .ControlInterfaceNumber   = 0,
+                               .ControlInterfaceNumber   = INTERFACE_ID_CDC_CCI,
                                .DataINEndpoint           =
                                        {
                                                .Address          = CDC_TX_EPADDR,
@@ -108,7 +83,7 @@ int main(void)
 
        RingBuffer_InitBuffer(&FromHost_Buffer, FromHost_Buffer_Data, sizeof(FromHost_Buffer_Data));
 
-       sei();
+       GlobalInterruptEnable();
 
        for (;;)
        {
@@ -124,27 +99,28 @@ int main(void)
 
                while (RingBuffer_GetCount(&FromHost_Buffer) > 0)
                {
-                       static uint8_t escape_pending = 0;
+                       static uint8_t EscapePending = 0;
                        int16_t HD44780Byte = RingBuffer_Remove(&FromHost_Buffer);
-                       
+
                        if (HD44780Byte == COMMAND_ESCAPE)
                        {
-                               if (escape_pending)
+                               if (EscapePending)
                                {
                                        HD44780_WriteData(HD44780Byte);
-                                       escape_pending = 0;
+                                       EscapePending = 0;
                                }
                                else
                                {
-                                       escape_pending = 1;
+                                       /* Next received character is the command byte */
+                                       EscapePending = 1;
                                }
                        }
                        else
                        {
-                               if (escape_pending)
+                               if (EscapePending)
                                {
                                        HD44780_WriteCommand(HD44780Byte);
-                                       escape_pending = 0;
+                                       EscapePending = 0;
                                }
                                else
                                {
@@ -161,20 +137,22 @@ int main(void)
 /** Configures the board hardware and chip peripherals for the application's functionality. */
 void SetupHardware(void)
 {
+#if (ARCH == ARCH_AVR8)
        /* Disable watchdog if enabled by bootloader/fuses */
        MCUSR &= ~(1 << WDRF);
        wdt_disable();
 
        /* Disable clock division */
        clock_prescale_set(clock_div_1);
+#endif
 
        /* Hardware Initialization */
        USB_Init();
 
        /* Power up the HD44780 Interface */
-       HD44780_Initialise();
+       HD44780_Initialize();
        HD44780_WriteCommand(CMD_DISPLAY_ON);
-       
+
        /* Start the flush timer so that overflows occur rapidly to push received bytes to the USB interface */
        TCCR0B = (1 << CS02);
 }
@@ -182,9 +160,7 @@ void SetupHardware(void)
 /** Event handler for the library USB Configuration Changed event. */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
-       bool ConfigSuccess = true;
-
-       ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
+       CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
 }
 
 /** Event handler for the library USB Control Request reception event. */