X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/2a0c28e6e47c8a173f32fc99cd8666a2633c5c12..eb410869474e14ec5762a96b930bc200409b6915:/Projects/Benito/Benito.c diff --git a/Projects/Benito/Benito.c b/Projects/Benito/Benito.c index 720a2245d..26c566496 100644 --- a/Projects/Benito/Benito.c +++ b/Projects/Benito/Benito.c @@ -45,6 +45,9 @@ volatile uint8_t TxPulseMSRemaining = 0; /** Counter for the number of milliseconds remaining for the RX activity LED pulse being generated. */ volatile uint8_t RxPulseMSRemaining = 0; +/** Counter for the number of milliseconds remaining for the enumeration LED ping-pong being generated. */ +volatile uint8_t PingPongMSRemaining = 0; + /** LUFA CDC Class driver interface configuration and state information. This structure is * passed to all CDC Class driver functions, so that multiple instances of the same class * within a device can be differentiated from one another. @@ -64,11 +67,6 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, }, - - .State = - { - // Leave all state values to their defaults - } }; /** Main program entry point. This routine contains the overall program flow, including initial @@ -78,12 +76,10 @@ int main(void) { SetupHardware(); - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - for (;;) { /* Echo bytes from the host to the target via the hardware USART */ - if (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) + if (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface) > 0) { Serial_TxByte(CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface)); @@ -103,10 +99,20 @@ int main(void) /* Check if the millisecond timer has elapsed */ if (TIFR0 & (1 << OCF0A)) { + /* Check if the LEDs should be ping-ponging (during enumeration) */ + if (PingPongMSRemaining && !(--PingPongMSRemaining)) + { + LEDs_ToggleLEDs(LEDMASK_BUSY); + PingPongMSRemaining = PING_PONG_LED_PULSE_MS; + } + /* Check if the reset pulse period has elapsed, if so tristate the target reset line */ if (ResetPulseMSRemaining && !(--ResetPulseMSRemaining)) - AVR_RESET_LINE_DDR &= ~AVR_RESET_LINE_MASK; - + { + LEDs_TurnOffLEDs(LEDMASK_BUSY); + AVR_RESET_LINE_DDR &= ~AVR_RESET_LINE_MASK; + } + /* Turn off TX LED(s) once the TX pulse period has elapsed */ if (TxPulseMSRemaining && !(--TxPulseMSRemaining)) LEDs_TurnOffLEDs(LEDMASK_TX); @@ -151,22 +157,25 @@ void SetupHardware(void) /** Event handler for the library USB Connection event. */ void EVENT_USB_Connect(void) { - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); + PingPongMSRemaining = PING_PONG_LED_PULSE_MS; + LEDs_SetAllLEDs(LEDMASK_TX); } /** Event handler for the library USB Disconnection event. */ void EVENT_USB_Disconnect(void) { - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + PingPongMSRemaining = 0; + LEDs_TurnOffLEDs(LEDMASK_BUSY); } /** Event handler for the library USB Configuration Changed event. */ void EVENT_USB_ConfigurationChanged(void) { - LEDs_SetAllLEDs(LEDMASK_USB_READY); + PingPongMSRemaining = 0; + LEDs_TurnOffLEDs(LEDMASK_BUSY); if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface))) - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + LEDs_TurnOnLEDs(LEDMASK_ERROR); } /** Event handler for the library USB Unhandled Control Packet event. */ @@ -224,6 +233,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 */ if (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR) { + LEDs_TurnOnLEDs(LEDMASK_BUSY); + AVR_RESET_LINE_DDR |= AVR_RESET_LINE_MASK; ResetPulseMSRemaining = AVR_RESET_PULSE_MS; }