X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ecd82778cf9a53e34f13d9ce6dcd7e1a4cf76b70..0d5e30e69fdd10cc75f62e550c32ab4baf9b0005:/Projects/AVRISP/AVRISP.c?ds=sidebyside diff --git a/Projects/AVRISP/AVRISP.c b/Projects/AVRISP/AVRISP.c index 9c21af2cb..016d74ce8 100644 --- a/Projects/AVRISP/AVRISP.c +++ b/Projects/AVRISP/AVRISP.c @@ -34,6 +34,9 @@ * the project and is responsible for the initial application hardware configuration. */ +// TODO: Add in software SPI for lower programming speeds below 125KHz +// TODO: Add reversed/shorted target connector checks + #include "AVRISP.h" /** Main program entry point. This routine contains the overall program flow, including initial @@ -42,15 +45,17 @@ int main(void) { SetupHardware(); - - printf("AVRISP-MKII\r\n"); + + V2Params_LoadNonVolatileParamValues(); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); for (;;) { - Process_AVRISP_Commands(); - + Process_AVRISP_Commands(); + + V2Params_UpdateParamValues(); + USB_USBTask(); } } @@ -66,9 +71,20 @@ void SetupHardware(void) clock_prescale_set(clock_div_1); /* Hardware Initialization */ - SerialStream_Init(9600, false); LEDs_Init(); USB_Init(); + + #if defined(ADC) + /* Initialize the ADC converter for VTARGET level detection on supported AVR models */ + ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128); + ADC_SetupChannel(VTARGET_ADC_CHANNEL); + ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC); + #endif + + /* Millisecond timer initialization for timeouts and delays */ + OCR0A = ((F_CPU / 64) / 1000); + TCCR0A = (1 << WGM01); + TCCR0B = ((1 << CS01) | (1 << CS00)); } /** Event handler for the library USB Connection event. */ @@ -98,11 +114,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) } } -void EVENT_USB_Device_UnhandledControlRequest(void) -{ - printf("CONTROL REQUEST\r\n"); -} - +/** Processes incomming V2 Protocol commands from the host, returning a response when required. */ void Process_AVRISP_Commands(void) { /* Device must be connected and configured for the task to run */ @@ -113,14 +125,9 @@ void Process_AVRISP_Commands(void) /* Check to see if a V2 Protocol command has been received - if not, abort */ if (!(Endpoint_IsOUTReceived())) - return; - - printf("COMMAND\r\n"); + return; /* Pass off processing of the V2 Protocol command to the V2 Protocol handler */ - V2Protocol_ProcessCommand(); - - /* Reset Endpoint direction to OUT ready for next command */ - Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT); + V2Protocol_ProcessCommand(); }