Update Studio Integration DLL, to include package logging.
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / V2ProtocolParams.c
index 7a2c986..99d41b1 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2011.
+     Copyright (C) Dean Camera, 2015.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2015  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
@@ -18,7 +18,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
 #include "V2ProtocolParams.h"
 
 /* Non-Volatile Parameter Values for EEPROM storage */
-uint8_t EEMEM EEPROM_Rest_Polarity = 0x00;
+static uint8_t EEMEM EEPROM_Reset_Polarity = 0x01;
+
+/* Non-Volatile Parameter Values for EEPROM storage */
+static uint8_t EEMEM EEPROM_SCK_Duration   = 0x06;
 
 /* Volatile Parameter Values for RAM storage */
 static ParameterItem_t ParameterTable[] =
@@ -60,18 +63,18 @@ static ParameterItem_t ParameterTable[] =
 
                { .ParamID          = PARAM_SW_MINOR,
                  .ParamPrivileges  = PARAM_PRIV_READ,
-                 .ParamValue       = 0x0D                               },
+                 .ParamValue       = FIRMWARE_VERSION_MINOR             },
 
                { .ParamID          = PARAM_VTARGET,
                  .ParamPrivileges  = PARAM_PRIV_READ,
-                 .ParamValue       = 0x32                               },
+                 .ParamValue       = (uint8_t)(3.3 * 10)                },
 
                { .ParamID          = PARAM_SCK_DURATION,
                  .ParamPrivileges  = PARAM_PRIV_READ | PARAM_PRIV_WRITE,
                  .ParamValue       = 6                                  },
 
                { .ParamID          = PARAM_RESET_POLARITY,
-                 .ParamPrivileges  = PARAM_PRIV_WRITE,
+                 .ParamPrivileges  = PARAM_PRIV_READ | PARAM_PRIV_WRITE,
                  .ParamValue       = 0x01                               },
 
                { .ParamID          = PARAM_STATUS_TGT_CONN,
@@ -79,7 +82,7 @@ static ParameterItem_t ParameterTable[] =
                  .ParamValue       = STATUS_ISP_READY                   },
 
                { .ParamID          = PARAM_DISCHARGEDELAY,
-                 .ParamPrivileges  = PARAM_PRIV_WRITE,
+                 .ParamPrivileges  = PARAM_PRIV_READ | PARAM_PRIV_WRITE,
                  .ParamValue       = 0x00                               },
        };
 
@@ -87,8 +90,17 @@ static ParameterItem_t ParameterTable[] =
 /** Loads saved non-volatile parameter values from the EEPROM into the parameter table, as needed. */
 void V2Params_LoadNonVolatileParamValues(void)
 {
-       /* Target RESET line polarity is a non-volatile value, retrieve current parameter value from EEPROM */
-       V2Params_GetParamFromTable(PARAM_RESET_POLARITY)->ParamValue = eeprom_read_byte(&EEPROM_Rest_Polarity);
+       /* Read parameter values that are stored in non-volatile EEPROM */
+       uint8_t ResetPolarity = eeprom_read_byte(&EEPROM_Reset_Polarity);
+       uint8_t SCKDuration   = eeprom_read_byte(&EEPROM_SCK_Duration);
+
+       /* Update current parameter table if the EEPROM contents was not blank */
+       if (ResetPolarity != 0xFF)
+         V2Params_GetParamFromTable(PARAM_RESET_POLARITY)->ParamValue = ResetPolarity;
+
+       /* Update current parameter table if the EEPROM contents was not blank */
+       if (SCKDuration != 0xFF)
+         V2Params_GetParamFromTable(PARAM_SCK_DURATION)->ParamValue   = SCKDuration;
 }
 
 /** Updates any parameter values that are sourced from hardware rather than explicitly set by the host, such as
@@ -108,11 +120,11 @@ void V2Params_UpdateParamValues(void)
  *
  *  \param[in] ParamID  Parameter ID whose privileges are to be retrieved from the table
  *
- *  \return Privileges for the requested parameter, as a mask of PARAM_PRIV_* masks
+ *  \return Privileges for the requested parameter, as a mask of \c PARAM_PRIV_* masks
  */
 uint8_t V2Params_GetParameterPrivileges(const uint8_t ParamID)
 {
-       ParameterItem_t* ParamInfo = V2Params_GetParamFromTable(ParamID);
+       ParameterItem_t* const ParamInfo = V2Params_GetParamFromTable(ParamID);
 
        if (ParamInfo == NULL)
          return 0;
@@ -132,7 +144,7 @@ uint8_t V2Params_GetParameterPrivileges(const uint8_t ParamID)
  */
 uint8_t V2Params_GetParameterValue(const uint8_t ParamID)
 {
-       ParameterItem_t* ParamInfo = V2Params_GetParamFromTable(ParamID);
+       ParameterItem_t* const ParamInfo = V2Params_GetParamFromTable(ParamID);
 
        if (ParamInfo == NULL)
          return 0;
@@ -154,7 +166,7 @@ uint8_t V2Params_GetParameterValue(const uint8_t ParamID)
 void V2Params_SetParameterValue(const uint8_t ParamID,
                                 const uint8_t Value)
 {
-       ParameterItem_t* ParamInfo = V2Params_GetParamFromTable(ParamID);
+       ParameterItem_t* const ParamInfo = V2Params_GetParamFromTable(ParamID);
 
        if (ParamInfo == NULL)
          return;
@@ -163,7 +175,11 @@ void V2Params_SetParameterValue(const uint8_t ParamID,
 
        /* The target RESET line polarity is a non-volatile parameter, save to EEPROM when changed */
        if (ParamID == PARAM_RESET_POLARITY)
-         eeprom_update_byte(&EEPROM_Rest_Polarity, Value);
+         eeprom_update_byte(&EEPROM_Reset_Polarity, Value);
+
+       /* The target SCK line period is a non-volatile parameter, save to EEPROM when changed */
+       if (ParamID == PARAM_SCK_DURATION)
+         eeprom_update_byte(&EEPROM_SCK_Duration, Value);
 }
 
 /** Retrieves a parameter entry (including ID, value and privileges) from the parameter table that matches the given
@@ -173,7 +189,7 @@ void V2Params_SetParameterValue(const uint8_t ParamID,
  *
  *  \return Pointer to the associated parameter information from the parameter table if found, NULL otherwise
  */
-static ParameterItem_t* V2Params_GetParamFromTable(const uint8_t ParamID)
+static ParameterItem_t* const V2Params_GetParamFromTable(const uint8_t ParamID)
 {
        ParameterItem_t* CurrTableItem = ParameterTable;