Remove type definitions of the keyboard and mouse boot protocol report layouts from...
[pub/USBasp.git] / Projects / AVRISP / AVRISP.c
index 9c21af2..016d74c 100644 (file)
@@ -34,6 +34,9 @@
  *  the project and is responsible for the initial application hardware configuration.\r
  */\r
 \r
+// TODO: Add in software SPI for lower programming speeds below 125KHz\r
+// TODO: Add reversed/shorted target connector checks\r
+\r
 #include "AVRISP.h"\r
 \r
 /** Main program entry point. This routine contains the overall program flow, including initial\r
 int main(void)\r
 {\r
        SetupHardware();\r
-       \r
-       printf("AVRISP-MKII\r\n");\r
+\r
+       V2Params_LoadNonVolatileParamValues();\r
        \r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 \r
        for (;;)\r
        {
-               Process_AVRISP_Commands();
-\r
+               Process_AVRISP_Commands();\r
+               \r
+               V2Params_UpdateParamValues();\r
+               \r
                USB_USBTask();\r
        }\r
 }\r
@@ -66,9 +71,20 @@ void SetupHardware(void)
        clock_prescale_set(clock_div_1);\r
 \r
        /* Hardware Initialization */\r
-       SerialStream_Init(9600, false);\r
        LEDs_Init();\r
        USB_Init();\r
+\r
+       #if defined(ADC)\r
+       /* Initialize the ADC converter for VTARGET level detection on supported AVR models */\r
+       ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);\r
+       ADC_SetupChannel(VTARGET_ADC_CHANNEL);\r
+       ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);\r
+       #endif\r
+       \r
+       /* Millisecond timer initialization for timeouts and delays */\r
+       OCR0A  = ((F_CPU / 64) / 1000);\r
+       TCCR0A = (1 << WGM01);\r
+       TCCR0B = ((1 << CS01) | (1 << CS00));\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
@@ -98,11 +114,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        }\r
 }\r
 \r
-void EVENT_USB_Device_UnhandledControlRequest(void)\r
-{\r
-       printf("CONTROL REQUEST\r\n");\r
-}\r
-
+/** 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 */\r
@@ -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;\r
-         \r
-       printf("COMMAND\r\n");
+         return;
 
        /* Pass off processing of the V2 Protocol command to the V2 Protocol handler */
-       V2Protocol_ProcessCommand();
-\r
-       /* Reset Endpoint direction to OUT ready for next command */\r
-       Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);\r
+       V2Protocol_ProcessCommand();\r
 }