/** 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); }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Hardware Initialization */ SoftUART_Init(); LEDs_Init(); USB_Init(); /* Disable JTAG debugging */ MCUCR |= (1 << JTD); MCUCR |= (1 << JTD); /* Enable pull-up on the JTAG TDI pin so we can use it to select the mode */ PORTF |= (1 << 7); _delay_ms(10); /* Select the firmware mode based on the JTD pin's value */ CurrentFirmwareMode = (PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER; /* Re-enable JTAG debugging */ MCUCR &= ~(1 << JTD); MCUCR &= ~(1 << JTD); }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { #if (ARCH == ARCH_AVR8) /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); #endif /* Disable JTAG debugging */ MCUCR |= (1 << JTD); MCUCR |= (1 << JTD); /* Enable pull-up on the JTAG TDI pin so we can use it to select the mode */ PORTF |= (1 << 7); Delay_MS(10); /* Select the firmware mode based on the JTD pin's value */ CurrentFirmwareMode = (PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER; /* Re-enable JTAG debugging */ MCUCR &= ~(1 << JTD); MCUCR &= ~(1 << JTD); /* Hardware Initialization */ SoftUART_Init(); LEDs_Init(); #if defined(RESET_TOGGLES_LIBUSB_COMPAT) UpdateCurrentCompatibilityMode(); #endif /* USB Stack Initialization */ USB_Init(); }