123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- #include "AVRISP-MKII.h"
- #if (BOARD != BOARD_NONE)
-
- #warning Board specific drivers have been selected; make sure the board LED driver does not conflict with the programmer ISP/PDI/TPI interfaces.
- #endif
- int main(void)
- {
- SetupHardware();
- V2Protocol_Init();
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
- GlobalInterruptEnable();
- for (;;)
- {
- #if (BOARD == BOARD_USBTINYMKII)
-
- LEDs_ChangeLEDs(LEDMASK_VBUSPOWER, (PIND & (1 << 0)) ? 0 : LEDMASK_VBUSPOWER);
- #endif
- AVRISP_Task();
- USB_USBTask();
- }
- }
- void SetupHardware(void)
- {
- #if (ARCH == ARCH_AVR8)
-
- MCUSR &= ~(1 << WDRF);
- wdt_disable();
-
- clock_prescale_set(clock_div_1);
- #endif
-
- LEDs_Init();
- #if defined(RESET_TOGGLES_LIBUSB_COMPAT)
- UpdateCurrentCompatibilityMode();
- #endif
-
- USB_Init();
- }
- void EVENT_USB_Device_Connect(void)
- {
- LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
- }
- void EVENT_USB_Device_Disconnect(void)
- {
- LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
- }
- void EVENT_USB_Device_ConfigurationChanged(void)
- {
- bool ConfigSuccess = true;
-
- 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);
-
- LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
- }
- void AVRISP_Task(void)
- {
-
- if (USB_DeviceState != DEVICE_STATE_Configured)
- return;
- V2Params_UpdateParamValues();
- Endpoint_SelectEndpoint(AVRISP_DATA_OUT_EPADDR);
-
- if (Endpoint_IsOUTReceived())
- {
- LEDs_SetAllLEDs(LEDMASK_BUSY);
-
- V2Protocol_ProcessCommand();
- LEDs_SetAllLEDs(LEDMASK_USB_READY);
- }
- }
- uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
- const uint16_t wIndex,
- const void** const DescriptorAddress)
- {
- return AVRISP_GetDescriptor(wValue, wIndex, DescriptorAddress);
- }
|