Ensure new Benito Programmer project matches Don's established LED behaviour - flash...
[pub/lufa.git] / Projects / Benito / Benito.c
index 720a224..1afb74a 100644 (file)
@@ -45,6 +45,9 @@ volatile uint8_t TxPulseMSRemaining    = 0;
 /** Counter for the number of milliseconds remaining for the RX activity LED pulse being generated. */\r
 volatile uint8_t RxPulseMSRemaining    = 0;\r
 \r
+/** Counter for the number of milliseconds remaining for the enumeration LED ping-pong being generated. */\r
+volatile uint8_t PingPongMSRemaining   = 0;\r
+\r
 /** LUFA CDC Class driver interface configuration and state information. This structure is\r
  *  passed to all CDC Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
@@ -78,8 +81,6 @@ int main(void)
 {\r
        SetupHardware();\r
 \r
-       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
-\r
        for (;;)\r
        {\r
                /* Echo bytes from the host to the target via the hardware USART */\r
@@ -103,10 +104,20 @@ int main(void)
                /* Check if the millisecond timer has elapsed */\r
                if (TIFR0 & (1 << OCF0A))\r
                {\r
+                       /* Check if the LEDs should be ping-ponging (during enumeration) */\r
+                       if (PingPongMSRemaining && !(--PingPongMSRemaining))\r
+                       {\r
+                               LEDs_ChangeLEDs(LEDMASK_BUSY, (~LEDs_GetLEDs() & LEDMASK_BUSY));\r
+                               PingPongMSRemaining = PING_PONG_LED_PULSE_MS;\r
+                       }\r
+               \r
                        /* Check if the reset pulse period has elapsed, if so tristate the target reset line */\r
                        if (ResetPulseMSRemaining && !(--ResetPulseMSRemaining))\r
-                         AVR_RESET_LINE_DDR &= ~AVR_RESET_LINE_MASK;\r
-\r
+                       {\r
+                               LEDs_TurnOffLEDs(LEDMASK_BUSY);\r
+                               AVR_RESET_LINE_DDR &= ~AVR_RESET_LINE_MASK;\r
+                       }\r
+                       \r
                        /* Turn off TX LED(s) once the TX pulse period has elapsed */\r
                        if (TxPulseMSRemaining && !(--TxPulseMSRemaining))\r
                          LEDs_TurnOffLEDs(LEDMASK_TX);\r
@@ -151,22 +162,25 @@ void SetupHardware(void)
 /** Event handler for the library USB Connection event. */\r
 void EVENT_USB_Connect(void)\r
 {\r
-       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
+       PingPongMSRemaining = PING_PONG_LED_PULSE_MS;\r
+       LEDs_SetAllLEDs(LEDMASK_TX);\r
 }\r
 \r
 /** Event handler for the library USB Disconnection event. */\r
 void EVENT_USB_Disconnect(void)\r
 {\r
-       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+       PingPongMSRemaining = 0;\r
+       LEDs_TurnOffLEDs(LEDMASK_BUSY);\r
 }\r
 \r
 /** Event handler for the library USB Configuration Changed event. */\r
 void EVENT_USB_ConfigurationChanged(void)\r
 {\r
-       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
+       PingPongMSRemaining = 0;\r
+       LEDs_TurnOffLEDs(LEDMASK_BUSY);\r
 \r
        if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface)))\r
-         LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+         LEDs_TurnOnLEDs(LEDMASK_ERROR);\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Packet event. */\r
@@ -224,6 +238,8 @@ void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const C
        /* Check if the DTR line has been asserted - if so, start the target AVR's reset pulse */\r
        if (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR)\r
        {\r
+               LEDs_TurnOnLEDs(LEDMASK_BUSY);\r
+       \r
                AVR_RESET_LINE_DDR |= AVR_RESET_LINE_MASK;\r
                ResetPulseMSRemaining = AVR_RESET_PULSE_MS;\r
        }\r