Converted TestApp demo over to the new demo structure.
More class driver documentation improvements.
\r
#include "TestApp.h"\r
\r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
- { .Task = TestApp_CheckJoystick, .TaskStatus = TASK_RUN },\r
- { .Task = TestApp_CheckButton , .TaskStatus = TASK_RUN },\r
- { .Task = TestApp_CheckTemp , .TaskStatus = TASK_RUN },\r
- { .Task = USB_USBTask , .TaskStatus = TASK_RUN },\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
+ "LUFA Demo running.\r\n" ESC_INVERSE_OFF));\r
+\r
+ for (;;)\r
+ {\r
+ CheckJoystick();\r
+ CheckButton();\r
+ CheckTemperature();\r
+\r
+ /* Clear output-compare flag (logic 1 clears the flag) */\r
+ TIFR0 |= (1 << OCF0A);\r
+ \r
+ USB_USBTask();\r
+ }\r
+}\r
+\r
+void SetupHardware(void)\r
+{\r
/* Disable watchdog if enabled by bootloader/fuses */\r
MCUSR &= ~(1 << WDRF);\r
wdt_disable();\r
LEDs_Init();\r
Buttons_Init();\r
\r
- /* Millisecond timer initialization, with output compare interrupt enabled */\r
+ /* Millisecond timer initialization */\r
OCR0A = 0x7D;\r
TCCR0A = (1 << WGM01);\r
TCCR0B = ((1 << CS01) | (1 << CS00));\r
- TIMSK0 = (1 << OCIE0A);\r
- \r
- /* Turn on interrupts */\r
- sei();\r
-\r
- /* Start-up message via USART */\r
- puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
- "LUFA 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
-/** ISR for the timer 0 compare vector. This ISR fires once each millisecond, and increments the\r
- * scheduler tick counter.\r
- */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
-{\r
- /* Scheduler test - increment scheduler tick counter once each millisecond */\r
- Scheduler_TickCounter++;\r
}\r
\r
/** Task responsible for checking the joystick position, and displaying the joystick position onto the\r
* board LEDs.\r
*/\r
-TASK(TestApp_CheckJoystick)\r
+void CheckJoystick(void)\r
{\r
uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
- uint8_t LEDMask = 0;\r
+ uint8_t LEDMask = LEDS_NO_LEDS;\r
\r
- /* Test of the Joystick - change a mask in response to joystick */\r
if (JoyStatus_LCL & JOY_UP)\r
LEDMask |= LEDS_LED1;\r
\r
if (JoyStatus_LCL & JOY_PRESS)\r
LEDMask = LEDS_ALL_LEDS;\r
\r
- /* Test of LEDs - light up in response to joystick */\r
LEDs_SetAllLEDs(LEDMask);\r
}\r
\r
/** Task responsible for checking the current temperature via the temperature sensor mounted on the\r
* board, and displaying it through the serial USART.\r
*/\r
-TASK(TestApp_CheckTemp)\r
+void CheckTemperature(void)\r
{\r
- static SchedulerDelayCounter_t DelayCounter = 10000; // Force immediate run on start-up\r
+ static uint16_t MSElapsed = 0;\r
+\r
+ if (TIFR0 & (1 << OCF0A))\r
+ MSElapsed++;\r
\r
/* Task runs every 10000 ticks, 10 seconds for this demo */\r
- if (Scheduler_HasDelayElapsed(10000, &DelayCounter))\r
+ if (MSElapsed == 1000)\r
{\r
printf_P(PSTR("Current temperature: %d Degrees Celcius\r\n\r\n"),\r
(int8_t)Temperature_GetTemperature());\r
\r
- /* Reset the delay counter, ready to count another 10000 tick interval */\r
- Scheduler_ResetDelay(&DelayCounter);\r
+ MSElapsed = 0;\r
} \r
}\r
\r
/** Task responsible for checking the board's first button' position, and start-stopping other tasks and the USB\r
* interface in response to user joystick movements.\r
*/\r
-TASK(TestApp_CheckButton)\r
+void CheckButton(void)\r
{\r
- static SchedulerDelayCounter_t DelayCounter = 0;\r
- static bool IsPressed;\r
- static bool BlockingJoystickTask;\r
+ static uint16_t DebounceMSElapsed = 0;\r
+ static bool IsPressed;\r
\r
- /* Check if board button pressed (start USB) */\r
+ if (TIFR0 & (1 << OCF0A))\r
+ DebounceMSElapsed++;\r
+\r
if (Buttons_GetStatus() & BUTTONS_BUTTON1)\r
{\r
- /* Debounce - check 100 ticks later to see if button is still being pressed */\r
- if ((IsPressed == false) && (Scheduler_HasDelayElapsed(100, &DelayCounter)))\r
+ if (!(IsPressed) && (DebounceMSElapsed == 100))\r
{\r
- /* Set flag, indicating that current pressed state has been handled */\r
IsPressed = true;\r
- \r
- /* First start of the USB interface permanently blocks the joystick task */\r
- if (BlockingJoystickTask == false)\r
- {\r
- Scheduler_SetTaskMode(TestApp_CheckJoystick, TASK_STOP);\r
- BlockingJoystickTask = true;\r
- }\r
\r
- /* Toggle USB interface */\r
if (USB_IsInitialized == true)\r
{\r
USB_ShutDown();\r
-\r
- LEDs_SetAllLEDs(LEDS_LED1);\r
puts_P(PSTR(ESC_BG_WHITE "USB Power Off.\r\n"));\r
- \r
- Scheduler_SetTaskMode(TestApp_CheckTemp, TASK_RUN);\r
}\r
else\r
{\r
- Scheduler_SetTaskMode(TestApp_CheckTemp, TASK_STOP);\r
-\r
- LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3);\r
- puts_P(PSTR(ESC_BG_YELLOW "USB Power On.\r\n"));\r
- \r
+ puts_P(PSTR(ESC_BG_YELLOW "USB Power On.\r\n")); \r
USB_Init(USB_MODE_UID, USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL);\r
}\r
}\r
}\r
else\r
{\r
- /* Board button not pressed - reset debounce interval counter and press handled flag */\r
- Scheduler_ResetDelay(&DelayCounter);\r
+ DebounceMSElapsed = 0;\r
IsPressed = false;\r
}\r
}\r
#include <avr/wdt.h>\r
#include <avr/power.h>\r
\r
- #include <LUFA/Version.h> // Library Version Information\r
- #include <LUFA/Drivers/USB/USB.h> // USB Functionality\r
- #include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management\r
- #include <LUFA/Drivers/Misc/TerminalCodes.h> // ANSI Terminal Escape Codes\r
- #include <LUFA/Drivers/Peripheral/ADC.h> // ADC driver\r
- #include <LUFA/Drivers/Peripheral/SerialStream.h> // USART Stream driver\r
- #include <LUFA/Drivers/Board/Joystick.h> // Joystick driver\r
- #include <LUFA/Drivers/Board/LEDs.h> // LED driver\r
- #include <LUFA/Drivers/Board/Buttons.h> // Board Buttons driver\r
- #include <LUFA/Drivers/Board/Temperature.h> // Temperature sensor driver\r
+ #include <LUFA/Version.h>\r
+ #include <LUFA/Drivers/USB/USB.h>\r
+ #include <LUFA/Drivers/Misc/TerminalCodes.h>\r
+ #include <LUFA/Drivers/Peripheral/ADC.h>\r
+ #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+ #include <LUFA/Drivers/Board/Joystick.h>\r
+ #include <LUFA/Drivers/Board/LEDs.h>\r
+ #include <LUFA/Drivers/Board/Buttons.h>\r
+ #include <LUFA/Drivers/Board/Temperature.h>\r
\r
- /* Task Definitions: */\r
- TASK(TestApp_CheckJoystick);\r
- TASK(TestApp_CheckButton);\r
- TASK(TestApp_CheckTemp);\r
+ /* Function Prototypes: */\r
+ void SetupHardware(void);\r
+ \r
+ void CheckJoystick(void);\r
+ void CheckButton(void);\r
+ void CheckTemperature(void);\r
\r
#endif\r
* Pressing the HWB will initiate the USB subsystem, enumerating\r
* the device (which has <b>no actual functionality beyond\r
* enumeration as a device or as a host in this demo</b>, and serves\r
- * only to demonstrate the USB portion of the library). It will\r
- * also suspend the joystick and temperature monitoring tasks.\r
+ * only to demonstrate the USB portion of the library).\r
* \r
- * Pressing the HWB a second time will turn off the USB system\r
- * and resume the temperature printing task (but not the joystick\r
- * monitoring task).\r
+ * Pressing the HWB a second time will turn off the USB system.\r
*\r
* When activated, the USB events will be printed through the\r
* serial USART.\r
*\r
- * When the USB subsystem is activated, the board LEDs will show\r
- * the current USB status.\r
- *\r
* \section SSec_Options Project Options\r
*\r
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.\r
void EVENT_USB_Connect(void)\r
{\r
puts_P(PSTR(EVENT_PREFIX "USB +\r\n"));\r
- LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3 | LEDS_LED4);\r
- \r
- Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
}\r
\r
/**\r
*/\r
void EVENT_USB_Disconnect(void)\r
{\r
- Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
-\r
puts_P(PSTR(EVENT_PREFIX "USB -\r\n"));\r
- LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3 | LEDS_LED3);\r
}\r
\r
/** Event handler for the USB_Suspend event. When fired, the event is logged to the USART. */\r
void EVENT_USB_Suspend(void)\r
{\r
puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW "USB Sleep\r\n"));\r
- LEDs_SetAllLEDs(LEDS_ALL_LEDS);\r
}\r
\r
/** Event handler for the USB_WakeUp event. When fired, the event is logged to the USART. */\r
void EVENT_USB_WakeUp(void)\r
{\r
puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "USB Wakeup\r\n"));\r
- LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4);\r
}\r
\r
/** Event handler for the USB_Reset event. When fired, the event is logged to the USART. */\r
ModeStrPtr = PSTR("DEVICE");\r
else\r
ModeStrPtr = PSTR("N/A");\r
- \r
- LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3);\r
\r
printf_P(PSTR(" -- New Mode %S\r\n"), ModeStrPtr);\r
}\r
void EVENT_USB_ConfigurationChanged(void)\r
{\r
puts_P(PSTR(EVENT_PREFIX "Configuration Number Changed\r\n"));\r
-\r
- LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4);\r
}\r
\r
/** Event handler for the USB_DeviceAttached event. When fired, the event is logged to the USART. */\r
void EVENT_USB_DeviceAttached(void)\r
{\r
puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "Device +\r\n"));\r
-\r
- Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
}\r
\r
/** Event handler for the USB_DeviceUnattached event. When fired, the event is logged to the USART. */\r
/* Includes: */\r
#include <avr/io.h>\r
\r
- #include <LUFA/Common/Common.h> // Commonly used macros\r
- #include <LUFA/Drivers/USB/USB.h> // USB Functionality\r
- #include <LUFA/Drivers/Board/LEDs.h> // LED driver\r
- #include <LUFA/Drivers/Peripheral/SerialStream.h> // USART Stream driver\r
- #include <LUFA/Drivers/Misc/TerminalCodes.h> // ANSI Terminal Escape Codes\r
- #include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management\r
+ #include <LUFA/Common/Common.h>\r
+ #include <LUFA/Drivers/USB/USB.h>\r
+ #include <LUFA/Drivers/Board/LEDs.h>\r
+ #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+ #include <LUFA/Drivers/Misc/TerminalCodes.h>
\r
/* Macros: */\r
/** Prefix sent through the USART when an even fires before the actual event message. */\r
SRC = $(TARGET).c \\r
TestEvents.c \\r
Descriptors.c \\r
- $(LUFA_PATH)/LUFA/Scheduler/Scheduler.c \\r
$(LUFA_PATH)/LUFA/Drivers/Board/Temperature.c \\r
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \\r
$(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \\r
*\r
* \return Boolean true if the endpoints were sucessfully configured, false otherwise\r
*/\r
- bool USB_Audio_ConfigureEndpoints(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
+ bool USB_Audio_ConfigureEndpoints(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
\r
/** Processes incomming control requests from the host, that are directed to the given Audio class interface. This should be\r
* linked to the library \ref EVENT_USB_UnhandledControlPacket() event.\r
*\r
* \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.\r
*/\r
- void USB_Audio_ProcessControlPacket(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
+ void USB_Audio_ProcessControlPacket(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
\r
/** General management task for a given Audio class interface, required for the correct operation of the interface. This should\r
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().\r
*\r
* \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.\r
*/\r
- void USB_Audio_USBTask(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
+ void USB_Audio_USBTask(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
\r
/** Reads the next 8-bit audio sample from the current audio interface.\r
*\r
*\r
* \return Signed 8-bit audio sample from the audio interface\r
*/\r
- int8_t USB_Audio_ReadSample8(void);\r
+ int8_t USB_Audio_ReadSample8(void);\r
\r
/** Reads the next 16-bit audio sample from the current audio interface.\r
*\r
*\r
* \return Signed 16-bit audio sample from the audio interface\r
*/\r
- int16_t USB_Audio_ReadSample16(void);\r
+ int16_t USB_Audio_ReadSample16(void);\r
\r
/** Reads the next 24-bit audio sample from the current audio interface.\r
*\r
*\r
* \return Signed 24-bit audio sample from the audio interface\r
*/\r
- int32_t USB_Audio_ReadSample24(void);\r
+ int32_t USB_Audio_ReadSample24(void);\r
\r
/** Writes the next 8-bit audio sample to the current audio interface.\r
*\r
*\r
* \param Sample Signed 8-bit audio sample\r
*/\r
- void USB_Audio_WriteSample8(int8_t Sample);\r
+ void USB_Audio_WriteSample8(int8_t Sample);\r
\r
/** Writes the next 16-bit audio sample to the current audio interface.\r
*\r
*\r
* \param Sample Signed 16-bit audio sample\r
*/\r
- void USB_Audio_WriteSample16(int16_t Sample);\r
+ void USB_Audio_WriteSample16(int16_t Sample);\r
\r
/** Writes the next 24-bit audio sample to the current audio interface.\r
*\r
*\r
* \param Sample Signed 24-bit audio sample\r
*/\r
- void USB_Audio_WriteSample24(int32_t Sample);\r
+ void USB_Audio_WriteSample24(int32_t Sample);\r
\r
/** Determines if the given audio interface is ready for a sample to be read from it.\r
*\r
*\r
* \return Boolean true if the given Audio interface has a sample to be read, false otherwise\r
*/\r
- bool USB_Audio_IsSampleReceived(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
+ bool USB_Audio_IsSampleReceived(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
\r
/** Determines if the given audio interface is ready to accept the next sample to be written to it.\r
*\r
*\r
* \return Boolean true if the given Audio interface is ready to accept the next sample, false otherwise\r
*/\r
- bool USB_Audio_IsReadyForNextSample(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
+ bool USB_Audio_IsReadyForNextSample(USB_ClassInfo_Audio_t* AudioInterfaceInfo);\r
\r
/* Disable C linkage for C++ Compilers: */\r
#if defined(__cplusplus)\r
\r
CDCInterfaceInfo->ControlLineState = USB_ControlRequest.wValue;\r
\r
- EVENT_USB_CDC_ControLineStateChanged();\r
+ EVENT_USB_CDC_ControLineStateChanged(CDCInterfaceInfo);\r
\r
while (!(Endpoint_IsINReady()));\r
Endpoint_ClearIN();\r
uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */\r
uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */\r
\r
- uint8_t ControlLineState;\r
+ uint8_t ControlLineState; /**< Current control line state, as set by the host */\r
\r
struct\r
{\r
void USB_CDC_Event_Stub(void);\r
void EVENT_USB_CDC_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
ATTR_WEAK ATTR_ALIAS(USB_CDC_Event_Stub);\r
- void EVENT_USB_CDC_ControLineStateChanged(void) ATTR_WEAK ATTR_ALIAS(USB_CDC_Event_Stub);; \r
+ void EVENT_USB_CDC_ControLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo)\r
+ ATTR_WEAK ATTR_ALIAS(USB_CDC_Event_Stub);\r
#endif\r
\r
- bool USB_CDC_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
- void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
- void USB_CDC_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
+ /** Configures the endpoints of a given CDC interface, ready for use. This should be linked to the library\r
+ * \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration containing the\r
+ * given CDC interface is selected.\r
+ *\r
+ * \param CDCInterfaceInfo Pointer to a structure containing an CDC Class configuration and state.\r
+ *\r
+ * \return Boolean true if the endpoints were sucessfully configured, false otherwise\r
+ */\r
+ bool USB_CDC_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
+\r
+ /** Processes incomming control requests from the host, that are directed to the given CDC class interface. This should be\r
+ * linked to the library \ref EVENT_USB_UnhandledControlPacket() event.\r
+ *\r
+ * \param CDCInterfaceInfo Pointer to a structure containing an CDC Class configuration and state.\r
+ */\r
+ void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
+\r
+ /** General management task for a given CDC class interface, required for the correct operation of the interface. This should\r
+ * be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().\r
+ *\r
+ * \param CDCInterfaceInfo Pointer to a structure containing an CDC Class configuration and state.\r
+ */\r
+ void USB_CDC_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
\r
void EVENT_USB_CDC_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
- void EVENT_USB_CDC_ControLineStateChanged(void);\r
+ void EVENT_USB_CDC_ControLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);\r
\r
void USB_CDC_SendString(USB_ClassInfo_CDC_t* CDCInterfaceInfo, char* Data, uint16_t Length);\r
void USB_CDC_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data);\r