X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ea922c98d187eb74c31535afa3334ead5bd50526..0da99447d3e88e83f9977501bee56af5c7aa56c0:/Projects/AVRISP-MKII/AVRISP-MKII.c diff --git a/Projects/AVRISP-MKII/AVRISP-MKII.c b/Projects/AVRISP-MKII/AVRISP-MKII.c index d774b1119..c4623fd8e 100644 --- a/Projects/AVRISP-MKII/AVRISP-MKII.c +++ b/Projects/AVRISP-MKII/AVRISP-MKII.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2011. + Copyright (C) Dean Camera, 2012. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -45,14 +45,14 @@ int main(void) V2Protocol_Init(); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - GlobalInterruptEnable(); - + sei(); + for (;;) { #if (BOARD == BOARD_USBTINYMKII) - /* On the USBTINY-MKII board 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(LEDS_LED3, (PIND & (1 << 0)) ? 0 : LEDS_LED3); + /* 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(); @@ -63,37 +63,20 @@ int main(void) /** 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); - #elif (ARCH == ARCH_UC3) - /* Select slow startup, external high frequency crystal attached to OSC0 */ - AVR32_PM.OSCCTRL0.mode = 7; - AVR32_PM.OSCCTRL0.startup = 6; - AVR32_PM.MCCTRL.osc0en = true; - while (!(AVR32_PM.POSCSR.osc0rdy)); - - /* Switch CPU core to use OSC0 as the system clock */ - AVR32_PM.MCCTRL.mcsel = 1; - - /* Start PLL1 to feed into the USB generic clock module */ - AVR32_PM.PLL[1].pllmul = (F_USB / F_CPU) ? (((F_USB / F_CPU) - 1) / 2) : 0; - AVR32_PM.PLL[1].plldiv = 0; - AVR32_PM.PLL[1].pllosc = 0; - AVR32_PM.PLL[1].pllen = true; - while (!(AVR32_PM.POSCSR.lock1)); - - /* Configure interrupt management peripheral */ -// INTC_Init(); - INTC_RegisterGroupHandler(AVR32_USBB_IRQ, AVR32_INTC_INT0, USB_GEN_vect); - #endif - + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + /* Hardware Initialization */ LEDs_Init(); + #if defined(RESET_TOGGLES_LIBUSB_COMPAT) + UpdateCurrentCompatibilityMode(); + #endif + + /* USB Stack Initialization */ USB_Init(); } @@ -114,14 +97,12 @@ void EVENT_USB_Device_ConfigurationChanged(void) { bool ConfigSuccess = true; - /* Setup AVRISP Data Endpoint(s) */ - ConfigSuccess &= Endpoint_ConfigureEndpoint(AVRISP_DATA_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT, - AVRISP_DATA_EPSIZE, ENDPOINT_BANK_SINGLE); + /* Setup AVRISP Data OUT endpoint */ + ConfigSuccess &= Endpoint_ConfigureEndpoint(AVRISP_DATA_OUT_EPADDR, EP_TYPE_BULK, AVRISP_DATA_EPSIZE, 1); - #if defined(LIBUSB_DRIVER_COMPAT) - ConfigSuccess &= Endpoint_ConfigureEndpoint(AVRISP_DATA_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN, - AVRISP_DATA_EPSIZE, ENDPOINT_BANK_SINGLE); - #endif + /* Setup AVRISP Data IN endpoint if it is using a physically different endpoint */ + 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); /* Indicate endpoint configuration success or failure */ LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); @@ -136,7 +117,7 @@ void AVRISP_Task(void) V2Params_UpdateParamValues(); - Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPNUM); + Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPADDR); /* Check to see if a V2 Protocol command has been received */ if (Endpoint_IsOUTReceived()) @@ -150,3 +131,24 @@ void AVRISP_Task(void) } } +/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" + * documentation) by the application code so that the address and size of a requested descriptor can be given + * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function + * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the + * USB host. + * + * \param[in] wValue Descriptor type and index to retrieve + * \param[in] wIndex Sub-index to retrieve (such as a localized string language) + * \param[out] DescriptorAddress Address of the retrieved descriptor + * \param[out] DescriptorMemorySpace Memory space that the descriptor is stored in + * + * \return Length of the retrieved descriptor in bytes, or NO_DESCRIPTOR if the descriptor was not found + */ +uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, + const uint8_t wIndex, + const void** const DescriptorAddress, + uint8_t* DescriptorMemorySpace) +{ + return AVRISP_GetDescriptor(wValue, wIndex, DescriptorAddress, DescriptorMemorySpace); +} +