/** Event handler for the library USB Configuration Changed event. */ void EVENT_USB_Device_ConfigurationChanged(void) { bool ConfigSuccess = true; /* Configure the device endpoints according to the selected mode */ if (CurrentFirmwareMode == MODE_USART_BRIDGE) { ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface); /* Configure the UART flush timer - run at Fcpu/1024 for maximum interval before overflow */ TCCR0B = ((1 << CS02) | (1 << CS00)); /* Initialize ring buffers used to hold serial data between USB and software UART interfaces */ RingBuffer_InitBuffer(&USBtoUART_Buffer, USBtoUART_Buffer_Data, sizeof(USBtoUART_Buffer_Data)); RingBuffer_InitBuffer(&UARTtoUSB_Buffer, UARTtoUSB_Buffer_Data, sizeof(UARTtoUSB_Buffer_Data)); /* Start the software USART */ SoftUART_Init(); } else { ConfigSuccess &= Endpoint_ConfigureEndpoint(AVRISP_DATA_OUT_EPADDR, EP_TYPE_BULK, AVRISP_DATA_EPSIZE, 1); if ((AVRISP_DATA_IN_EPADDR & ENDPOINT_EPNUM_MASK) != (AVRISP_DATA_OUT_EPADDR & ENDPOINT_EPNUM_MASK)) ConfigSuccess &= Endpoint_ConfigureEndpoint(AVRISP_DATA_IN_EPADDR, EP_TYPE_BULK, AVRISP_DATA_EPSIZE, 1); /* Configure the V2 protocol packet handler */ V2Protocol_Init(); } LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); }
/** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ int main(void) { SetupHardware(); V2Protocol_Init(); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); sei(); for (;;) { #if (BOARD == BOARD_USBTINYMKII) /* On the USBTINY-MKII target, there is a secondary LED which indicates the current selected power mode - either VBUS, or sourced from the VTARGET pin of the programming connectors */ LEDs_ChangeLEDs(LEDMASK_VBUSPOWER, (PIND & (1 << 0)) ? 0 : LEDMASK_VBUSPOWER); #endif AVRISP_Task(); USB_USBTask(); } }