Converted Host mode demos to schedulerless. Fixed host mode broken due to earlier...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 8 Jun 2009 07:34:16 +0000 (07:34 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 8 Jun 2009 07:34:16 +0000 (07:34 +0000)
39 files changed:
Bootloaders/CDC/BootloaderCDC.c
Bootloaders/DFU/BootloaderDFU.c
Demos/Host/ClassDriver/MassStorageHost/Lib/MassStoreCommands.c
Demos/Host/ClassDriver/StillImageHost/Lib/StillImageCommands.c
Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
Demos/Host/LowLevel/CDCHost/CDCHost.c
Demos/Host/LowLevel/CDCHost/CDCHost.h
Demos/Host/LowLevel/CDCHost/makefile
Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c
Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.h
Demos/Host/LowLevel/GenericHIDHost/makefile
Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c
Demos/Host/LowLevel/KeyboardHost/KeyboardHost.h
Demos/Host/LowLevel/KeyboardHost/makefile
Demos/Host/LowLevel/KeyboardHostWithParser/HIDReport.h
Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.h
Demos/Host/LowLevel/KeyboardHostWithParser/makefile
Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c
Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c
Demos/Host/LowLevel/MassStorageHost/MassStorageHost.h
Demos/Host/LowLevel/MassStorageHost/makefile
Demos/Host/LowLevel/MouseHost/MouseHost.c
Demos/Host/LowLevel/MouseHost/MouseHost.h
Demos/Host/LowLevel/MouseHost/makefile
Demos/Host/LowLevel/MouseHostWithParser/HIDReport.h
Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c
Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.h
Demos/Host/LowLevel/MouseHostWithParser/makefile
Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c
Demos/Host/LowLevel/StillImageHost/StillImageHost.c
Demos/Host/LowLevel/StillImageHost/StillImageHost.h
Demos/Host/LowLevel/StillImageHost/makefile
LUFA/ChangeLog.txt
LUFA/Drivers/USB/LowLevel/Endpoint.c
LUFA/Drivers/USB/LowLevel/Host.c
LUFA/Drivers/USB/LowLevel/LowLevel.c
LUFA/Drivers/USB/LowLevel/LowLevel.h
LUFA/Drivers/USB/LowLevel/Pipe.c

index 265e90f..d797915 100644 (file)
@@ -248,7 +248,7 @@ static void ReadWriteMemoryBlock(const uint8_t Command)
                        else\r
                        {\r
                                /* Read the next FLASH byte from the current FLASH page */\r
-                               #if defined(RAMPZ)\r
+                               #if (FLASHEND > 0xFFFF)\r
                                WriteNextResponseByte(pgm_read_byte_far(CurrAddress | HighByte));\r
                                #else\r
                                WriteNextResponseByte(pgm_read_byte(CurrAddress | HighByte));                                   \r
@@ -513,7 +513,7 @@ TASK(CDC_Task)
                }\r
                else if (Command == 'R')\r
                {\r
-                       #if defined(RAMPZ)\r
+                       #if (FLASHEND > 0xFFFF)\r
                        uint16_t ProgramWord = pgm_read_word_far(CurrAddress);\r
                        #else\r
                        uint16_t ProgramWord = pgm_read_word(CurrAddress);                      \r
index 11177c5..1850803 100644 (file)
@@ -342,7 +342,7 @@ void EVENT_USB_UnhandledControlPacket(void)
                                                }\r
 \r
                                                /* Read the flash word and send it via USB to the host */\r
-                                               #if defined(RAMPZ)\r
+                                               #if (FLASHEND > 0xFFFF)\r
                                                        Endpoint_Write_Word_LE(pgm_read_word_far(CurrFlashAddress.Long));\r
                                                #else\r
                                                        Endpoint_Write_Word_LE(pgm_read_word(CurrFlashAddress.Long));                                                   \r
@@ -585,7 +585,7 @@ static void ProcessMemReadCommand(void)
                while (CurrFlashAddress < BOOT_START_ADDR)\r
                {\r
                        /* Check if the current byte is not blank */\r
-                       #if defined(RAMPZ)\r
+                       #if (FLASHEND > 0xFFFF)\r
                        if (pgm_read_byte_far(CurrFlashAddress) != 0xFF)\r
                        #else\r
                        if (pgm_read_byte(CurrFlashAddress) != 0xFF)\r
index f47e9f5..95aafca 100644 (file)
@@ -119,10 +119,10 @@ static uint8_t MassStore_WaitForDataReceived(void)
        while (!(Pipe_IsINReceived()))\r
        {\r
                /* Check to see if a new frame has been issued (1ms elapsed) */\r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
                        /* Clear the flag and decrement the timeout period counter */\r
-                       FrameElapsed = false;\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
                        TimeoutMSRem--;\r
 \r
                        /* Check to see if the timeout period for the command has elapsed */\r
index f2f666b..8f05e48 100644 (file)
@@ -109,10 +109,10 @@ uint8_t SImage_RecieveBlockHeader(void)
        while (!(Pipe_IsReadWriteAllowed()))\r
        {\r
                /* Check to see if a new frame has been issued (1ms elapsed) */\r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
                        /* Clear the flag and decrement the timeout period counter */\r
-                       FrameElapsed = false;\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
                        TimeoutMSRem--;\r
 \r
                        /* Check to see if the timeout period for the command has elapsed */\r
index b855456..b7d49f6 100644 (file)
@@ -58,6 +58,7 @@ int main(void)
        {\r
                Bluetooth_Stack_Task();\r
                Bluetooth_Management_Task();\r
+               USB_USBTask();\r
        }\r
 }\r
 \r
index b834731..9a5e81a 100644 (file)
  \r
 #include "CDCHost.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_CDC_Host         , .TaskStatus = TASK_STOP },\r
-};\r
-\r
-\r
 /** Main program entry point. This routine configures the hardware required by the application, then\r
  *  starts the scheduler to run the application tasks.\r
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "CDC Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               CDC_Host_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -59,22 +68,7 @@ int main(void)
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-       \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
        USB_Init();\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "CDC Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Scheduling - routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -83,10 +77,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-\r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -94,12 +85,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop keyboard and USB management task */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_CDC_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -107,11 +94,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Start CDC Host task */\r
-       Scheduler_SetTaskMode(USB_CDC_Host, TASK_RUN);\r
-\r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -122,7 +105,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -136,44 +119,13 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
        \r
-       UpdateStatus(Status_EnumerationError);\r
-}\r
-\r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the CDCHost_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Task to set the configuration of the attached device after it has been enumerated, and to read in\r
  *  data received from the attached CDC device and print it to the serial port.\r
  */\r
-TASK(USB_CDC_Host)\r
+void CDC_Host_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -200,7 +152,7 @@ TASK(USB_CDC_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -223,7 +175,7 @@ TASK(USB_CDC_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
index afec780..5dcbc8e 100644 (file)
                #include <avr/power.h>\r
                #include <stdio.h>\r
 \r
-               #include <LUFA/Version.h>                                // Library Version Information\r
-               #include <LUFA/Drivers/Misc/TerminalCodes.h>             // ANSI Terminal Escape Codes\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
-               #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
-               #include <LUFA/Drivers/Board/LEDs.h>                     // LEDs driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
+               #include <LUFA/Version.h>\r
+               #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+               #include <LUFA/Drivers/Board/LEDs.h>\r
                \r
                #include "ConfigDescriptor.h"\r
                \r
                /** Pipe number for the CDC notification pipe */\r
                #define CDC_NOTIFICATIONPIPE           3\r
 \r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum CDCHost_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-               };\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
 \r
-       /* Task Definitions: */\r
-               TASK(USB_CDC_Host);\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
 \r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
+\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
+               \r
        /* Function Prototypes: */\r
+               void SetupHardware(void);\r
+               void CDC_Host_Task(void);\r
+       \r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
                void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);\r
                void EVENT_USB_DeviceEnumerationComplete(void);\r
-\r
-               void UpdateStatus(uint8_t CurrentStatus);\r
                \r
 #endif\r
index f1255aa..dfbefbb 100644 (file)
@@ -119,13 +119,12 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
@@ -138,7 +137,6 @@ SRC = $(TARGET).c                                                 \
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c      \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \\r
-         $(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c             \\r
 \r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
index e731f90..ac764fa 100644 (file)
  \r
 #include "GenericHIDHost.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_HID_Host         , .TaskStatus = TASK_STOP },\r
-};\r
-\r
-\r
 /** Main program entry point. This routine configures the hardware required by the application, then\r
  *  starts the scheduler to run the application tasks.\r
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "Generic HID Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               HID_Host_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
 \r
        /* Disable clock division */\r
        clock_prescale_set(clock_div_1);\r
-       \r
+\r
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-       \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
        USB_Init();\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "Generic HID Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Scheduling - routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -83,10 +77,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-\r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -94,12 +85,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop HID and USB management task */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_HID_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("Device Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -107,11 +94,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Start HID Host task */\r
-       Scheduler_SetTaskMode(USB_HID_Host, TASK_RUN);\r
-\r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -122,7 +105,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -136,38 +119,7 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
 \r
-       UpdateStatus(Status_EnumerationError);\r
-}\r
-\r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the GenericHIDHost_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Reads in and processes the next report from the attached device, displaying the report\r
@@ -273,7 +225,7 @@ void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t Report
 /** Task to set the configuration of the attached device after it has been enumerated, and to read and process\r
  *  HID reports from the device and to send reports if desired.\r
  */\r
-TASK(USB_HID_Host)\r
+void HID_Host_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -301,7 +253,7 @@ TASK(USB_HID_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -324,7 +276,7 @@ TASK(USB_HID_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
index 7e2f8b8..415dae0 100644 (file)
                #include <avr/power.h>\r
                #include <stdio.h>\r
 \r
-               #include <LUFA/Version.h>                                // Library Version Information\r
-               #include <LUFA/Drivers/Misc/TerminalCodes.h>             // ANSI Terminal Escape Codes\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
-               #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
-               #include <LUFA/Drivers/Board/LEDs.h>                     // LEDs driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
+               #include <LUFA/Version.h>\r
+               #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+               #include <LUFA/Drivers/Board/LEDs.h>\r
                \r
                #include "ConfigDescriptor.h"\r
                \r
                /** HID Report type specifier, for feature reports to a device */\r
                #define HID_REPORTTYPE_FEATURE           0x03\r
 \r
-       /* Task Definitions: */\r
-               TASK(USB_HID_Host);\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
 \r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum GenricHIDHost_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-               };\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
 \r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
+\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
+               \r
        /* Function Prototypes: */\r
+               void SetupHardware(void);\r
+               void HID_Host_Task(void);\r
+       \r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
                void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);\r
                void EVENT_USB_DeviceEnumerationComplete(void);\r
 \r
-               void UpdateStatus(uint8_t CurrentStatus);\r
                void ReadNextReport(void);\r
                void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t ReportType, uint16_t ReportLength);\r
                \r
index b912b2f..a07acb4 100644 (file)
@@ -119,13 +119,12 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
index 2b9bb2b..64bcf09 100644 (file)
  \r
 #include "KeyboardHost.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_Keyboard_Host    , .TaskStatus = TASK_STOP },\r
-};\r
-\r
-\r
 /** Main program entry point. This routine configures the hardware required by the application, then\r
  *  starts the scheduler to run the application tasks.\r
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "Keyboard HID Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               Keyboard_HID_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -59,22 +68,7 @@ int main(void)
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-       \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
        USB_Init();\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "Keyboard Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Scheduling - routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -83,10 +77,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-\r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -94,12 +85,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop Keyboard and USB management task */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_Keyboard_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("Device Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -107,11 +94,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Start Keyboard Host task */\r
-       Scheduler_SetTaskMode(USB_Keyboard_Host, TASK_RUN);\r
-       \r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -122,7 +105,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -136,38 +119,7 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
 \r
-       UpdateStatus(Status_EnumerationError);\r
-}\r
-\r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the KeyboardHost_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Reads in and processes the next report from the attached device, displaying the report\r
@@ -238,7 +190,7 @@ void ReadNextReport(void)
 /** Task to set the configuration of the attached device after it has been enumerated, and to read and process\r
  *  HID reports from the device and display the results onto the board LEDs.\r
  */\r
-TASK(USB_Keyboard_Host)\r
+void Keyboard_HID_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -265,7 +217,7 @@ TASK(USB_Keyboard_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -288,7 +240,7 @@ TASK(USB_Keyboard_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -315,7 +267,7 @@ TASK(USB_Keyboard_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
index d00b76a..4aa09e1 100644 (file)
                #include <avr/interrupt.h>\r
                #include <stdio.h>\r
 \r
-               #include <LUFA/Version.h>                                // Library Version Information\r
-               #include <LUFA/Drivers/Misc/TerminalCodes.h>             // ANSI Terminal Escape Codes\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
-               #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
-               #include <LUFA/Drivers/Board/LEDs.h>                     // LEDs driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
+               #include <LUFA/Version.h>\r
+               #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+               #include <LUFA/Drivers/Board/LEDs.h>\r
                \r
                #include "ConfigDescriptor.h"\r
                \r
                /** HID Class Specific request to set the report protocol mode */\r
                #define REQ_SetProtocol             0x0B\r
 \r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
+\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
+\r
        /* Type Defines: */\r
                /** Type define for a standard Boot Protocol Keyboard report */\r
                typedef struct\r
                        uint8_t KeyCode; /**< Key code of the currently pressed key */\r
                } USB_KeyboardReport_Data_t;\r
 \r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum KeyboardHost_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-               };\r
-       \r
-       /* Task Definitions: */\r
-               TASK(USB_Keyboard_Host);\r
-\r
        /* Function Prototypes: */\r
+               void Keyboard_HID_Task(void);\r
+       \r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
                void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);\r
                void EVENT_USB_DeviceEnumerationComplete(void);\r
 \r
-               void UpdateStatus(uint8_t CurrentStatus);\r
                void ReadNextReport(void);\r
                \r
 #endif\r
index b8cb79c..6e005da 100644 (file)
@@ -119,13 +119,12 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
@@ -138,7 +137,6 @@ SRC = $(TARGET).c                                                 \
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c      \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \\r
-         $(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c             \\r
 \r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
index 2096887..a141ffb 100644 (file)
@@ -37,7 +37,8 @@
 #define _HID_REPORT_H_\r
 \r
        /* Includes: */\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/USB/Class/Host/HIDParser.h>\r
                \r
                #include "KeyboardHostWithParser.h"\r
 \r
index 840cb90..620f158 100644 (file)
  \r
 #include "KeyboardHostWithParser.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_Keyboard_Host    , .TaskStatus = TASK_STOP },\r
-};\r
-\r
-\r
 /** Main program entry point. This routine configures the hardware required by the application, then\r
  *  starts the scheduler to run the application tasks.\r
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "Keyboard HID Parser Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               Keyboard_HID_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -59,22 +68,7 @@ int main(void)
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-       \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
        USB_Init();\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "Keyboard Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Scheduling - routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -83,10 +77,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-\r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -94,12 +85,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop keyboard and USB management task */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_Keyboard_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -107,11 +94,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Start Keyboard Host task */\r
-       Scheduler_SetTaskMode(USB_Keyboard_Host, TASK_RUN);\r
-       \r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -122,7 +105,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -136,47 +119,13 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
        \r
-       UpdateStatus(Status_EnumerationError);\r
-}\r
-\r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the KeyboardHostWithParser_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-               case Status_Busy:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED4);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Task to set the configuration of the attached device after it has been enumerated, and to read and process\r
  *  the HID report descriptor and HID reports from the device and display the results onto the board LEDs.\r
  */\r
-TASK(USB_Keyboard_Host)\r
+void Keyboard_HID_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -203,7 +152,7 @@ TASK(USB_Keyboard_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -226,7 +175,7 @@ TASK(USB_Keyboard_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -235,9 +184,6 @@ TASK(USB_Keyboard_Host)
                                        \r
                        puts_P(PSTR("Processing HID Report.\r\n"));\r
 \r
-                       /* LEDs one and two on to indicate busy processing */\r
-                       UpdateStatus(Status_Busy);\r
-\r
                        /* Get and process the device's first HID report descriptor */\r
                        if ((ErrorCode = GetHIDReportData()) != ParseSuccessful)\r
                        {\r
@@ -245,15 +191,12 @@ TASK(USB_Keyboard_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                        \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
                                break;  \r
                        }\r
-                       \r
-                       /* All LEDs off - ready to indicate key presses */\r
-                       UpdateStatus(Status_USBReady);\r
 \r
                        puts_P(PSTR("Keyboard Enumerated.\r\n"));\r
 \r
index acb5b8b..90db94a 100644 (file)
                #include <avr/power.h>\r
                #include <stdio.h>\r
 \r
-               #include <LUFA/Version.h>                                // Library Version Information\r
-               #include <LUFA/Drivers/Misc/TerminalCodes.h>             // ANSI Terminal Escape Codes\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
-               #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
-               #include <LUFA/Drivers/Board/LEDs.h>                     // LEDs driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
+               #include <LUFA/Version.h>\r
+               #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+               #include <LUFA/Drivers/Board/LEDs.h>
                \r
                #include "ConfigDescriptor.h"\r
                #include "HIDReport.h"\r
                /** Pipe number for the keyboard report data pipe */\r
                #define KEYBOARD_DATAPIPE              1\r
 \r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum KeyboardHostWithParser_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-                       Status_Busy             = 5, /**< Busy dumping HID report items to the serial port */\r
-               };\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
 \r
-       /* Task Definitions: */\r
-               TASK(USB_Keyboard_Host);\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
 \r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
+\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
+               \r
        /* Function Prototypes: */\r
+               void Keyboard_HID_Task(void);\r
+               void SetupHardware(void);\r
+\r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
                void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);\r
                void EVENT_USB_DeviceEnumerationComplete(void);\r
 \r
-               void UpdateStatus(uint8_t CurrentStatus);\r
                void ProcessKeyboardReport(uint8_t* KeyboardReport);\r
                \r
 #endif\r
index 0d09178..3935512 100644 (file)
@@ -119,14 +119,13 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
          HIDReport.c                                                 \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
@@ -139,7 +138,7 @@ SRC = $(TARGET).c                                                 \
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c      \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \\r
-         $(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c             \\r
+         $(LUFA_PATH)/LUFA/Drivers/USB/Class/Host/HIDParser.c        \\r
 \r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
index f47e9f5..95aafca 100644 (file)
@@ -119,10 +119,10 @@ static uint8_t MassStore_WaitForDataReceived(void)
        while (!(Pipe_IsINReceived()))\r
        {\r
                /* Check to see if a new frame has been issued (1ms elapsed) */\r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
                        /* Clear the flag and decrement the timeout period counter */\r
-                       FrameElapsed = false;\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
                        TimeoutMSRem--;\r
 \r
                        /* Check to see if the timeout period for the command has elapsed */\r
index a2e6631..6810320 100644 (file)
 \r
 #include "MassStorageHost.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_MassStore_Host   , .TaskStatus = TASK_STOP },\r
-};\r
-\r
 /* Globals */\r
 /** Index of the highest available LUN (Logical Unit) in the attached Mass Storage Device */\r
 uint8_t MassStore_MaxLUNIndex;\r
@@ -53,6 +46,23 @@ uint8_t MassStore_MaxLUNIndex;
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "Mass Storage Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               MassStorage_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -64,22 +74,6 @@ int main(void)
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
        Buttons_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "MassStore Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
-       USB_Init();\r
-       \r
-       /* Scheduling routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -88,10 +82,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-       \r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -99,12 +90,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop USB management and Mass Storage tasks */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_MassStore_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -112,11 +99,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Once device is fully enumerated, start the Mass Storage Host task */\r
-       Scheduler_SetTaskMode(USB_MassStore_Host, TASK_RUN);\r
-       \r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -127,7 +110,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -141,13 +124,13 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
        \r
-       UpdateStatus(Status_EnumerationError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Task to set the configuration of the attached device after it has been enumerated, and to read in blocks from\r
  *  the device and print them to the serial port.\r
  */\r
-TASK(USB_MassStore_Host)\r
+void MassStorage_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -174,7 +157,7 @@ TASK(USB_MassStore_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -197,7 +180,7 @@ TASK(USB_MassStore_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -210,7 +193,7 @@ TASK(USB_MassStore_Host)
                        break;\r
                case HOST_STATE_Ready:\r
                        /* Indicate device busy via the status LEDs */\r
-                       UpdateStatus(Status_Busy);\r
+                       LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
                        \r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = MassStore_GetMaxLUN(&MassStore_MaxLUNIndex)) != HOST_SENDCONTROL_Successful)\r
@@ -354,7 +337,7 @@ TASK(USB_MassStore_Host)
                        }\r
                        \r
                        /* Indicate device no longer busy */\r
-                       UpdateStatus(Status_USBReady);\r
+                       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
                        \r
                        /* Wait until USB device disconnected */\r
                        while (USB_IsConnected);\r
@@ -363,41 +346,6 @@ TASK(USB_MassStore_Host)
        }\r
 }\r
 \r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the MassStorageHost_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-               case Status_SCSICommandError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-               case Status_Busy:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED4);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
-}\r
-\r
 /** Indicates that a communication error has occurred with the attached Mass Storage Device,\r
  *  printing error codes to the serial port and waiting until the device is removed before\r
  *  continuing.\r
@@ -424,7 +372,7 @@ void ShowDiskReadError(char* CommandString, bool FailedAtSCSILayer, uint8_t Erro
        Pipe_Freeze();\r
 \r
        /* Indicate device error via the status LEDs */\r
-       UpdateStatus(Status_SCSICommandError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
        /* Wait until USB device disconnected */\r
        while (USB_IsConnected);\r
index 6e1e5cd..a299b70 100644 (file)
                #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
                #include <LUFA/Drivers/Board/LEDs.h>                     // LEDs driver\r
                #include <LUFA/Drivers/Board/Buttons.h>                  // Board Buttons driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
 \r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum MassStorageHost_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-                       Status_Busy             = 5, /**< Busy reading or writing to the attached Mass Storage device */\r
-                       Status_SCSICommandError = 6, /**< Error sending or receiving a command to or from the attached SCSI device */\r
-               };\r
+       /* Macros: */\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
 \r
-       /* Task Definitions: */\r
-               TASK(USB_MassStore_Host);\r
-                               \r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
+\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is busy. */\r
+               #define LEDMASK_USB_BUSY         (LEDS_LED2)\r
+               \r
        /* Function Prototypes: */\r
+               void MassStorage_Task(void);\r
+               void SetupHardware(void);\r
+       \r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
@@ -80,6 +82,5 @@
                void EVENT_USB_DeviceEnumerationComplete(void);\r
 \r
                void ShowDiskReadError(char* CommandString, bool FailedAtSCSILayer, uint8_t ErrorCode);\r
-               void UpdateStatus(uint8_t CurrentStatus);               \r
 \r
 #endif\r
index f50f598..709f42f 100644 (file)
@@ -119,14 +119,13 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
          Lib/MassStoreCommands.c                                     \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
@@ -139,7 +138,6 @@ SRC = $(TARGET).c                                                 \
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c      \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \\r
-         $(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c             \\r
 \r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
index 7db9580..9b4db30 100644 (file)
  \r
 #include "MouseHost.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_Mouse_Host       , .TaskStatus = TASK_STOP },\r
-};\r
-\r
-\r
 /** Main program entry point. This routine configures the hardware required by the application, then\r
  *  starts the scheduler to run the application tasks.\r
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "Mouse HID Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               Mouse_HID_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -59,22 +68,7 @@ int main(void)
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-       \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
        USB_Init();\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "Mouse Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Scheduling - routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -83,10 +77,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-\r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -94,12 +85,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop mouse and USB management task */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_Mouse_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("Device Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -107,11 +94,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Start Mouse Host task */\r
-       Scheduler_SetTaskMode(USB_Mouse_Host, TASK_RUN);\r
-\r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -122,7 +105,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -136,38 +119,7 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
 \r
-       UpdateStatus(Status_EnumerationError);\r
-}\r
-\r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the MouseHost_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Reads in and processes the next report from the attached device, displaying the report\r
@@ -233,7 +185,7 @@ void ReadNextReport(void)
 /** Task to set the configuration of the attached device after it has been enumerated, and to read and process\r
  *  HID reports from the device and display the results onto the board LEDs.\r
  */\r
-TASK(USB_Mouse_Host)\r
+void Mouse_HID_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -261,7 +213,7 @@ TASK(USB_Mouse_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -284,7 +236,7 @@ TASK(USB_Mouse_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -311,7 +263,7 @@ TASK(USB_Mouse_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error status */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
index 7111218..1abd560 100644 (file)
                #include <avr/power.h>\r
                #include <stdio.h>\r
 \r
-               #include <LUFA/Version.h>                                // Library Version Information\r
-               #include <LUFA/Drivers/Misc/TerminalCodes.h>             // ANSI Terminal Escape Codes\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
-               #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
-               #include <LUFA/Drivers/Board/LEDs.h>                     // LEDs driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
+               #include <LUFA/Version.h>\r
+               #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+               #include <LUFA/Drivers/Board/LEDs.h>\r
                \r
                #include "ConfigDescriptor.h"\r
                \r
                /** HID Class Specific request to set the report protocol mode */\r
                #define REQ_SetProtocol             0x0B\r
 \r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
+\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
+\r
        /* Type Defines: */\r
                /** Type define for a standard Boot Protocol Mouse report */\r
                typedef struct\r
                        int8_t  Y; /**< Current delta Y movement on the mouse */\r
                } USB_MouseReport_Data_t;\r
 \r
-       /* Task Definitions: */\r
-               TASK(USB_Mouse_Host);\r
-\r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum MouseHost_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-               };\r
-               \r
        /* Function Prototypes: */\r
+               void Mouse_HID_Task(void);\r
+               void SetupHardware(void);\r
+               \r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
                void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);\r
                void EVENT_USB_DeviceEnumerationComplete(void);\r
 \r
-               void UpdateStatus(uint8_t CurrentStatus);\r
                void ReadNextReport(void);\r
                \r
 #endif\r
index b7bad94..67e05a6 100644 (file)
@@ -119,13 +119,12 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
@@ -138,7 +137,6 @@ SRC = $(TARGET).c                                                 \
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c      \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \\r
-         $(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c             \\r
 \r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
index b248855..f5429f0 100644 (file)
@@ -37,7 +37,8 @@
 #define _HID_REPORT_H_\r
 \r
        /* Includes: */\r
-               #include <LUFA/Drivers/USB/USB.h>            // USB Functionality\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/USB/Class/Host/HIDParser.h>\r
                \r
                #include "MouseHostWithParser.h"\r
 \r
index f26e9e2..3ef5503 100644 (file)
  \r
 #include "MouseHostWithParser.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_Mouse_Host       , .TaskStatus = TASK_STOP },\r
-};\r
-\r
-\r
 /** Main program entry point. This routine configures the hardware required by the application, then\r
  *  starts the scheduler to run the application tasks.\r
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "Mouse HID Parser Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               Mouse_HID_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -59,22 +68,7 @@ int main(void)
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-       \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
        USB_Init();\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "Mouse Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Scheduling - routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -83,10 +77,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-\r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -94,12 +85,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop mouse and USB management task */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_Mouse_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("Device Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -107,11 +94,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Start Mouse Host task */\r
-       Scheduler_SetTaskMode(USB_Mouse_Host, TASK_RUN);\r
-       \r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -122,7 +105,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -136,47 +119,13 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
        \r
-       UpdateStatus(Status_EnumerationError);\r
-}\r
-\r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the MouseHostWithParser_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-               case Status_Busy:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED4);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Task to set the configuration of the attached device after it has been enumerated, and to read and process\r
  *  the HID report descriptor and HID reports from the device and display the results onto the board LEDs.\r
  */\r
-TASK(USB_Mouse_Host)\r
+void Mouse_HID_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -204,8 +153,8 @@ TASK(USB_Mouse_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
-\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+                               \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
                                break;\r
@@ -227,7 +176,7 @@ TASK(USB_Mouse_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -236,9 +185,6 @@ TASK(USB_Mouse_Host)
                \r
                        puts_P(PSTR("Processing HID Report.\r\n"));\r
 \r
-                       /* LEDs one and two on to indicate busy processing */\r
-                       UpdateStatus(Status_Busy);\r
-\r
                        /* Get and process the device's first HID report descriptor */\r
                        if ((ErrorCode = GetHIDReportData()) != ParseSuccessful)\r
                        {\r
@@ -246,15 +192,12 @@ TASK(USB_Mouse_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                        \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
                                break;                  \r
                        }\r
-                       \r
-                       /* All LEDs off - ready to indicate key presses */\r
-                       UpdateStatus(Status_USBReady);\r
 \r
                        puts_P(PSTR("Mouse Enumerated.\r\n"));\r
                                \r
index f2cc2fd..b91d6d1 100644 (file)
                #include <avr/power.h>\r
                #include <stdio.h>\r
 \r
-               #include <LUFA/Version.h>                                // Library Version Information\r
-               #include <LUFA/Drivers/Misc/TerminalCodes.h>             // ANSI Terminal Escape Codes\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
-               #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
-               #include <LUFA/Drivers/Board/LEDs.h>                     // LEDs driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
+               #include <LUFA/Version.h>\r
+               #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+               #include <LUFA/Drivers/Board/LEDs.h>\r
                \r
                #include "ConfigDescriptor.h"\r
                #include "HIDReport.h"\r
                /** Pipe number for the mouse report data pipe */\r
                #define MOUSE_DATAPIPE              1\r
 \r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum MouseHostWithParser_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-                       Status_Busy             = 5, /**< Busy dumping HID report items to the serial port */\r
-               };\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
 \r
-       /* Task Definitions: */\r
-               TASK(USB_Mouse_Host);\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
+\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
 \r
        /* Function Prototypes: */\r
+               void Mouse_HID_Task(void);\r
+               void SetupHardware(void);\r
+       \r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
                void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode);\r
                void EVENT_USB_DeviceEnumerationComplete(void);\r
 \r
-               void UpdateStatus(uint8_t CurrentStatus);\r
                void ProcessMouseReport(uint8_t* MouseReport);\r
 \r
 #endif\r
index a6aeb6d..30e40ad 100644 (file)
@@ -119,14 +119,13 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
          HIDReport.c                                                 \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
@@ -139,7 +138,7 @@ SRC = $(TARGET).c                                                 \
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c      \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \\r
-         $(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c             \\r
+         $(LUFA_PATH)/LUFA/Drivers/USB/Class/Host/HIDParser.c        \\r
 \r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
index f2f666b..8f05e48 100644 (file)
@@ -109,10 +109,10 @@ uint8_t SImage_RecieveBlockHeader(void)
        while (!(Pipe_IsReadWriteAllowed()))\r
        {\r
                /* Check to see if a new frame has been issued (1ms elapsed) */\r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
                        /* Clear the flag and decrement the timeout period counter */\r
-                       FrameElapsed = false;\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
                        TimeoutMSRem--;\r
 \r
                        /* Check to see if the timeout period for the command has elapsed */\r
index 197e832..318e257 100644 (file)
 \r
 #include "StillImageHost.h"\r
 \r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
-       { .Task = USB_USBTask          , .TaskStatus = TASK_STOP },\r
-       { .Task = USB_SImage_Host      , .TaskStatus = TASK_STOP },\r
-};\r
-\r
-\r
 /** Main program entry point. This routine configures the hardware required by the application, then\r
  *  starts the scheduler to run the application tasks.\r
  */\r
 int main(void)\r
 {\r
+       SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
+              "Still Image Host Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
+       for (;;)\r
+       {\r
+               StillImage_Task();\r
+               USB_USBTask();\r
+       }\r
+}\r
+\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -60,22 +69,7 @@ int main(void)
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
        LEDs_Init();\r
-       \r
-       /* Indicate USB not ready */\r
-       UpdateStatus(Status_USBNotReady);\r
-       \r
-       /* Initialize Scheduler so that it can be used */\r
-       Scheduler_Init();\r
-\r
-       /* Initialize USB Subsystem */\r
        USB_Init();\r
-\r
-       /* Start-up message */\r
-       puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
-              "Still Image Host Demo running.\r\n" ESC_INVERSE_OFF));\r
-                  \r
-       /* Scheduling - routine never returns, so put this last in the main function */\r
-       Scheduler_Start();\r
 }\r
 \r
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
@@ -84,10 +78,7 @@ int main(void)
 void EVENT_USB_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
-       UpdateStatus(Status_USBEnumerating);\r
-       \r
-       /* Start USB management task to enumerate the device */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
@@ -95,12 +86,8 @@ void EVENT_USB_DeviceAttached(void)
  */\r
 void EVENT_USB_DeviceUnattached(void)\r
 {\r
-       /* Stop USB management and Still Image tasks */\r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-       Scheduler_SetTaskMode(USB_SImage_Host, TASK_STOP);\r
-\r
        puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
-       UpdateStatus(Status_USBNotReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
@@ -108,11 +95,7 @@ void EVENT_USB_DeviceUnattached(void)
  */\r
 void EVENT_USB_DeviceEnumerationComplete(void)\r
 {\r
-       /* Once device is fully enumerated, start the Still Image Host task */\r
-       Scheduler_SetTaskMode(USB_SImage_Host, TASK_RUN);\r
-\r
-       /* Indicate device enumeration complete */\r
-       UpdateStatus(Status_USBReady);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
@@ -123,7 +106,7 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
        puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
 \r
-       UpdateStatus(Status_HardwareError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
 }\r
 \r
@@ -137,13 +120,13 @@ void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t Su
        printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
        printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
        \r
-       UpdateStatus(Status_EnumerationError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
 /** Task to set the configuration of the attached device after it has been enumerated, and to print device information\r
  *  through the serial port.\r
  */\r
-TASK(USB_SImage_Host)\r
+void StillImage_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -169,7 +152,7 @@ TASK(USB_SImage_Host)
                                puts_P(PSTR("Control error.\r\n"));\r
 \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -192,7 +175,7 @@ TASK(USB_SImage_Host)
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
                                \r
                                /* Indicate error via status LEDs */\r
-                               UpdateStatus(Status_EnumerationError);\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
                                /* Wait until USB device disconnected */\r
                                while (USB_IsConnected);\r
@@ -205,8 +188,8 @@ TASK(USB_SImage_Host)
                        break;\r
                case HOST_STATE_Ready:\r
                        /* Indicate device busy via the status LEDs */\r
-                       UpdateStatus(Status_Busy);\r
-\r
+                       LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
+                       \r
                        puts_P(PSTR("Retrieving Device Info...\r\n"));\r
                        \r
                        PIMA_SendBlock = (PIMA_Container_t)\r
@@ -345,7 +328,7 @@ TASK(USB_SImage_Host)
                        puts_P(PSTR("Done.\r\n"));\r
 \r
                        /* Indicate device no longer busy */\r
-                       UpdateStatus(Status_USBReady);\r
+                       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
                        \r
                        /* Wait until USB device disconnected */\r
                        while (USB_IsConnected);\r
@@ -379,41 +362,6 @@ void UnicodeToASCII(uint8_t* UnicodeString, char* Buffer)
        *Buffer = 0;\r
 }\r
 \r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- *  log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- *  \param CurrentStatus  Current status of the system, from the StillImageHost_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
-       uint8_t LEDMask = LEDS_NO_LEDS;\r
-       \r
-       /* Set the LED mask to the appropriate LED mask based on the given status code */\r
-       switch (CurrentStatus)\r
-       {\r
-               case Status_USBNotReady:\r
-                       LEDMask = (LEDS_LED1);\r
-                       break;\r
-               case Status_USBEnumerating:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED2);\r
-                       break;\r
-               case Status_USBReady:\r
-                       LEDMask = (LEDS_LED2);\r
-                       break;\r
-               case Status_EnumerationError:\r
-               case Status_HardwareError:\r
-               case Status_PIMACommandError:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3);\r
-                       break;\r
-               case Status_Busy:\r
-                       LEDMask = (LEDS_LED1 | LEDS_LED3 | LEDS_LED4);\r
-                       break;\r
-       }\r
-       \r
-       /* Set the board LEDs to the new LED mask */\r
-       LEDs_SetAllLEDs(LEDMask);\r
-}\r
-\r
 /** Displays a PIMA command error via the device's serial port.\r
  *\r
  *  \param ErrorCode          Error code of the function which failed to complete successfully\r
@@ -427,7 +375,7 @@ void ShowCommandError(uint8_t ErrorCode, bool ResponseCodeError)
        printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
                        \r
        /* Indicate error via status LEDs */\r
-       UpdateStatus(Status_PIMACommandError);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                \r
        /* Wait until USB device disconnected */\r
        while (USB_IsConnected);\r
index b563767..1896b8f 100644 (file)
                #include "Lib/PIMACodes.h"\r
                #include "Lib/StillImageCommands.h"\r
 \r
-               #include <LUFA/Drivers/Misc/TerminalCodes.h>             // ANSI Terminal Escape Codes\r
-               #include <LUFA/Drivers/USB/USB.h>                        // USB Functionality\r
-               #include <LUFA/Drivers/Peripheral/SerialStream.h>        // Serial stream driver\r
-               #include <LUFA/Drivers/Board/LEDs.h>                     // LED driver\r
-               #include <LUFA/Scheduler/Scheduler.h>                    // Simple scheduler for task management\r
+               #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+               #include <LUFA/Drivers/USB/USB.h>\r
+               #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+               #include <LUFA/Drivers/Board/LEDs.h>\r
+               \r
+       /* Macros: */\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
+               #define LEDMASK_USB_NOTREADY      LEDS_LED1\r
+\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */\r
+               #define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)\r
 \r
-       /* Enums: */\r
-               /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
-               enum StillImageHost_StatusCodes_t\r
-               {\r
-                       Status_USBNotReady      = 0, /**< USB is not ready (disconnected from a USB device) */\r
-                       Status_USBEnumerating   = 1, /**< USB interface is enumerating */\r
-                       Status_USBReady         = 2, /**< USB interface is connected and ready */\r
-                       Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
-                       Status_HardwareError    = 4, /**< Hardware error while enumerating the attached USB device */\r
-                       Status_Busy             = 5, /**< Busy reading or writing to the attached Still Image device */\r
-                       Status_PIMACommandError = 6, /**< Error while sending or receiving a PIM command to the attached device */\r
-               };\r
+               /** LED mask for the library LED driver, to indicate that the USB interface is ready. */\r
+               #define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)\r
 \r
-       /* Task Definitions: */\r
-               TASK(USB_SImage_Host);\r
+               /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
+               #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
 \r
+               /** LED mask for the library LED driver, to indicate that the USB interface is busy. */\r
+               #define LEDMASK_USB_BUSY         (LEDS_LED2)\r
+               \r
        /* Function Prototypes: */\r
+               void StillImage_Task(void);\r
+               void SetupHardware(void);\r
+       \r
                void EVENT_USB_HostError(const uint8_t ErrorCode);\r
                void EVENT_USB_DeviceAttached(void);\r
                void EVENT_USB_DeviceUnattached(void);\r
@@ -78,6 +80,5 @@
 \r
                void UnicodeToASCII(uint8_t* restrict UnicodeString, char* restrict Buffer);\r
                void ShowCommandError(uint8_t ErrorCode, bool ResponseCodeError);\r
-               void UpdateStatus(uint8_t CurrentStatus);\r
                \r
 #endif\r
index 8c1ca0b..a4428c5 100644 (file)
@@ -118,14 +118,13 @@ OBJDIR = .
 \r
 \r
 # Path to the LUFA library\r
-LUFA_PATH = ../../..\r
+LUFA_PATH = ../../../..\r
 \r
 \r
 # List C source files here. (C dependencies are automatically generated.)\r
 SRC = $(TARGET).c                                                 \\r
          ConfigDescriptor.c                                          \\r
          Lib/StillImageCommands.c                                    \\r
-         $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c                     \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c         \\r
          $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c               \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \\r
@@ -138,7 +137,6 @@ SRC = $(TARGET).c                                                 \
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBInterrupt.c      \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \\r
          $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \\r
-         $(LUFA_PATH)/LUFA/Drivers/USB/Class/HIDParser.c             \\r
 \r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
index 94e8da0..f65c62a 100644 (file)
@@ -5,13 +5,14 @@
  */\r
    \r
 ========== TODO: ===========\r
-       - Fix bootloaders - make compatible with smaller USB AVRS (USB_IsConnected, RAMPZ)\r
+       - Fix bootloaders - make compatible with smaller USB AVRS (USB_IsConnected)\r
        - Document new device class drivers\r
        - Made new host class drivers\r
        - Document new host class drivers\r
        - Convert Host mode demos to class drivers\r
        - Convert Host mode demos to schedulerless\r
        - Add standardized descriptor names to class driver structures, controlled by USE_NONSTANDARD_DESCRIPTOR_NAMES\r
+       - Device demos error if endpoint config fail\r
 ============================\r
 \r
  /** \page Page_ChangeLog Project Changelog\r
@@ -20,6 +21,8 @@
   *\r
   *  - Removed psuedo-scheduler, dynamic memory block allocator from the library (no longer needed and not used respectively)\r
   *  - Added new class drivers and matching demos to the library for rapid application development\r
+  *  - Added incomplete device and host mode demos for later enhancement\r
+  *  - Changed bootloaders to use FLASHEND rather than the existence of RAMPZ to determine if far FLASH pointers are needed\r
   *\r
   *\r
   *  \section Sec_ChangeLog090605 Version 090605\r
index d02071b..fd97b75 100644 (file)
@@ -98,9 +98,9 @@ uint8_t Endpoint_WaitUntilReady(void)
                else if (Endpoint_IsStalled())\r
                  return ENDPOINT_READYWAIT_EndpointStalled;\r
                          \r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
-                       FrameElapsed = false;\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
 \r
                        if (!(TimeoutMSRem--))\r
                          return ENDPOINT_READYWAIT_Timeout;\r
index 02a1c21..5f3eeb8 100644 (file)
@@ -214,9 +214,9 @@ uint8_t USB_Host_WaitMS(uint8_t MS)
 \r
        while (MS)\r
        {\r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
-                       FrameElapsed = false;\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
                        MS--;\r
                }\r
                                        \r
@@ -259,9 +259,9 @@ static void USB_Host_ResetDevice(void)
        USB_Host_ResetBus();\r
        while (!(USB_Host_IsBusResetComplete()));\r
 \r
-       USB_Host_ResumeBus();   \r
-       \r
-       FrameElapsed = false;\r
+       USB_Host_ResumeBus();\r
+\r
+       USB_INT_Clear(USB_INT_HSOFI);\r
 \r
        for (uint8_t MSRem = 10; MSRem != 0; MSRem--)\r
        {\r
@@ -270,10 +270,9 @@ static void USB_Host_ResetDevice(void)
                   looked for - if it is found within 10ms, the device is still\r
                   present.                                                        */\r
 \r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
-                       FrameElapsed = false;\r
-                       \r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
                        USB_INT_Clear(USB_INT_DDISCI);\r
                        break;\r
                }\r
index 82705db..16a50ac 100644 (file)
@@ -38,8 +38,6 @@ volatile uint8_t USB_CurrentMode = USB_MODE_NONE;
 volatile uint8_t USB_Options;\r
 #endif\r
 \r
-volatile bool FrameElapsed;\r
-\r
 void USB_Init(\r
                #if defined(USB_CAN_BE_BOTH)\r
                const uint8_t Mode\r
@@ -152,8 +150,6 @@ void USB_ResetInterface(void)
        USB_INT_DisableAllInterrupts();\r
        USB_INT_ClearAllInterrupts();\r
 \r
-       FrameElapsed = false;\r
-\r
        USB_IsConnected = false;\r
 \r
        #if defined(USB_CAN_BE_HOST)\r
index 4279ca3..41b0ff5 100644 (file)
                                  return USB_MODE_HOST;\r
                        }\r
                        #endif\r
-               \r
-               /* External Variables: */\r
-                       extern volatile bool FrameElapsed;\r
                        \r
        #endif\r
        \r
index 720da17..3c493fe 100644 (file)
@@ -94,9 +94,9 @@ uint8_t Pipe_WaitUntilReady(void)
                else if (!(USB_IsConnected))\r
                  return PIPE_READYWAIT_DeviceDisconnected;\r
                          \r
-               if (FrameElapsed)\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
                {\r
-                       FrameElapsed = false;\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
 \r
                        if (!(TimeoutMSRem--))\r
                          return PIPE_READYWAIT_Timeout;\r