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
}\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
}\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
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
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
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
{\r
Bluetooth_Stack_Task();\r
Bluetooth_Management_Task();\r
+ USB_USBTask();\r
}\r
}\r
\r
\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
/* 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
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
*/\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
*/\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
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
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
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
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
#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
\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
$(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
\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
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
*/\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
*/\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
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
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
/** 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
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
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
#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
\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
\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
/* 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
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
*/\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
*/\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
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
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
/** 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
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
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
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
#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
\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
$(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
#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
\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
/* 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
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
*/\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
*/\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
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
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
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
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
\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
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
#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
\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
$(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
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
\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
*/\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
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
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
*/\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
*/\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
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
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
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
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
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
}\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
}\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
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
#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
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
\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
$(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
\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
/* 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
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
*/\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
*/\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
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
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
/** 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
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
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
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
#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
\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
$(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
#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
\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
/* 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
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
*/\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
*/\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
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
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
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
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
\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
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
#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
\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
$(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
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
\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
/* 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
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
*/\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
*/\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
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
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
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
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
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
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
*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
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
#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
\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
\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
$(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
*/\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
*\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
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
\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
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
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
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
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
return USB_MODE_HOST;\r
}\r
#endif\r
- \r
- /* External Variables: */\r
- extern volatile bool FrameElapsed;\r
\r
#endif\r
\r
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