\r
#include "TestApp.h"\r
\r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
- { Task: TestApp_CheckJoystick, TaskStatus: TASK_RUN },\r
- { Task: TestApp_CheckHWB , 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_FG_CYAN "LUFA Demo running.\r\n" ESC_FG_WHITE));\r
+\r
+ for (;;)\r
+ {\r
+ CheckJoystick();\r
+ CheckButton();\r
+ CheckTemperature();\r
+\r
+ /* Clear millisecond timer's 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
Temperature_Init();\r
Joystick_Init();\r
LEDs_Init();\r
- HWB_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
+ /* Timer 0's compare flag is set every millisecond */\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 == 10000)\r
{\r
printf_P(PSTR("Current temperature: %d Degrees Celcius\r\n\r\n"),\r
- (int)Temperature_GetTemperature());\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 HWB button position, and start-stopping other tasks and the USB\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_CheckHWB)\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 HWB pressed (start USB) */\r
- if (HWB_GetStatus() == true)\r
+ /* Timer 0's compare flag is set every millisecond */\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
+ puts_P(PSTR(ESC_FG_YELLOW "USB Power Off.\r\n" ESC_FG_WHITE));\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_FG_YELLOW "USB Power On.\r\n" ESC_FG_WHITE)); \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
- /* HWB not pressed - reset debounce interval counter and press handled flag */\r
- Scheduler_ResetDelay(&DelayCounter);\r
+ DebounceMSElapsed = 0;\r
IsPressed = false;\r
}\r
}\r