Move ADC VTARGET sampling to a new V2Params_UpdateParamValues() in the AVRISP project...
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 30 Aug 2009 03:51:44 +0000 (03:51 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 30 Aug 2009 03:51:44 +0000 (03:51 +0000)
Projects/AVRISP/AVRISP.c
Projects/AVRISP/Lib/V2ProtocolParams.c
Projects/AVRISP/Lib/V2ProtocolParams.h

index ce16aeb..e4d467f 100644 (file)
@@ -46,7 +46,7 @@ int main(void)
 {\r
        SetupHardware();\r
 \r
-       V2Params_LoadEEPROMParamValues();\r
+       V2Params_LoadNonVolatileParamValues();\r
        \r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 \r
@@ -54,11 +54,8 @@ int main(void)
        {
                Process_AVRISP_Commands();\r
                \r
-               #if defined(ADC)\r
-               /* Update VTARGET parameter with the latest ADC conversion of VTARGET on supported AVR models */\r
-               V2Params_SetParameterValue(PARAM_VTARGET, ((5 * 10 * ADC_GetResult()) / 1024));\r
-               #endif
-\r
+               V2Params_UpdateParamValues();\r
+               \r
                USB_USBTask();\r
        }\r
 }\r
index 9914c08..2d646a9 100644 (file)
@@ -85,12 +85,25 @@ static ParameterItem_t ParameterTable[] =
 \r
 \r
 /** Loads saved non-volatile parameter values from the EEPROM into the parameter table, as needed. */\r
-void V2Params_LoadEEPROMParamValues(void)\r
+void V2Params_LoadNonVolatileParamValues(void)\r
 {\r
-       /* Target RESET line polarity is a non-volatile value, retrieve current parameter value from EEPROM */\r
+       /* Target RESET line polarity is a non-volatile value, retrieve current parameter value from EEPROM -\r
+        *   NB: Cannot call V2Protocol_SetParameterValue() here, as that will cause another EEPROM write!\r
+        */\r
        V2Params_GetParamFromTable(PARAM_RESET_POLARITY)->ParamValue = eeprom_read_byte(&EEPROM_Rest_Polarity);\r
 }\r
 \r
+/** Updates any parameter values that are sourced from hardware rather than explicitly set by the host, such as\r
+ *  VTARGET levels from the ADC on supported AVR models.\r
+ */\r
+void V2Params_UpdateParamValues(void)\r
+{\r
+       #if defined(ADC)\r
+       /* Update VTARGET parameter with the latest ADC conversion of VTARGET on supported AVR models */\r
+       V2Params_GetParamFromTable(PARAM_VTARGET)->ParamValue = ((5 * 10 * ADC_GetResult()) / 1024);\r
+       #endif\r
+}\r
+\r
 /** Retrieves the host PC read/write privellages for a given parameter in the parameter table. This should\r
  *  be called before calls to \ref V2Params_GetParameterValue() or \ref V2Params_SetParameterValue() when\r
  *  getting or setting parameter values in response to requests from the host.\r
index 9c0f044..9ad84e7 100644 (file)
 \r
                #include <LUFA/Version.h>
 \r
+               #if defined(ADC)\r
+                       #include <LUFA/Drivers/Peripheral/ADC.h>\r
+               #endif\r
+               \r
                #include "V2Protocol.h"\r
                #include "V2ProtocolConstants.h"\r
 \r
@@ -62,7 +66,8 @@
                } ParameterItem_t;
 
        /* Function Prototypes: */\r
-               void    V2Params_LoadEEPROMParamValues(void);\r
+               void    V2Params_LoadNonVolatileParamValues(void);\r
+               void    V2Params_UpdateParamValues(void);\r
        \r
                uint8_t V2Params_GetParameterPrivellages(uint8_t ParamID);\r
                uint8_t V2Params_GetParameterValue(uint8_t ParamID);\r