Skip to content

Commit

Permalink
eeprom - fw_version and fw_build
Browse files Browse the repository at this point in the history
  • Loading branch information
XPila committed Mar 20, 2020
1 parent 536edb1 commit 1dcd8fe
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/common/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "cmsis_os.h"
#include "ff.h"
#include "crc32.h"
#include "version.h"

#define EEPROM_VARCOUNT (sizeof(eeprom_map) / sizeof(eeprom_entry_t))
#define EEPROM_DATASIZE sizeof(eeprom_vars_t)
Expand Down Expand Up @@ -110,8 +111,8 @@ static const eeprom_vars_t eeprom_var_defaults = {
EEPROM_VERSION, // EEVAR_VERSION
EEPROM_FEATURES, // EEVAR_FEATURES
EEPROM_DATASIZE, // EEVAR_DATASIZE
0, // EEVAR_FW_VERSION TODO: default value
0, // EEVAR_FW_BUILD TODO: default value
0, // EEVAR_FW_VERSION
0, // EEVAR_FW_BUILD
0, // EEVAR_FILAMENT_TYPE
0, // EEVAR_FILAMENT_COLOR
1, // EEVAR_RUN_SELFTEST
Expand Down Expand Up @@ -163,6 +164,8 @@ static int eeprom_convert_from(uint16_t version, uint16_t features);
static int eeprom_check_crc32(void);
static void eeprom_update_crc32(uint16_t addr, uint16_t size);

static uint16_t eeprom_fwversion_ui16(void);

// public functions - described in header

uint8_t eeprom_init(void) {
Expand Down Expand Up @@ -196,6 +199,8 @@ uint8_t eeprom_init(void) {

void eeprom_defaults(void) {
eeprom_vars_t vars = eeprom_var_defaults;
vars.FWBUILD = project_build_number;
vars.FWVERSION = eeprom_fwversion_ui16();
eeprom_lock();
// calculate crc32
vars.CRC32 = crc32_calc((uint32_t *)(&vars), (EEPROM_DATASIZE - 4) / 4);
Expand Down Expand Up @@ -344,6 +349,8 @@ static void eeprom_print_vars(void) {
// conversion function for old version 2 format (marlin eeprom)
static int eeprom_convert_from_v2(void) {
eeprom_vars_t vars = eeprom_var_defaults;
vars.FWBUILD = project_build_number;
vars.FWVERSION = eeprom_fwversion_ui16();
// read FILAMENT_TYPE (uint8_t)
st25dv64k_user_read_bytes(ADDR_V2_FILAMENT_TYPE, &(vars.FILAMENT_TYPE), sizeof(uint8_t));
// initialize to zero, maybe not necessary
Expand Down Expand Up @@ -414,6 +421,15 @@ static void eeprom_update_crc32(uint16_t addr, uint16_t size) {
#endif
}

static uint16_t eeprom_fwversion_ui16(void) {
int maj = 0;
int min = 0;
int sub = 0;
if (sscanf(project_version, "%d.%d.%d", &maj, &min, &sub) == 3)
return sub + 10 * (min + 10 * maj);
return 0;
}

int8_t eeprom_test_PUT(const unsigned int bytes) {
unsigned int i;
char line[16] = "abcdefghijklmno";
Expand Down

0 comments on commit 1dcd8fe

Please sign in to comment.