Prusa MINI Firmware overview
eeprom.c File Reference
#include "eeprom.h"
#include <stdio.h>
#include "st25dv64k.h"
#include "dbg.h"
#include <string.h>

Macros

#define EE_VERSION   0x0002
 
#define EE_VAR_CNT   sizeof(eeprom_map_v1)
 
#define EE_ADDRESS   0x0500
 

Functions

uint16_t eeprom_var_size (uint8_t id)
 
uint16_t eeprom_var_addr (uint8_t id)
 
variant8_t eeprom_var_default (uint8_t id)
 
void eeprom_dump (void)
 
void eeprom_print_vars (void)
 
void eeprom_clear (void)
 
uint8_t eeprom_init (void)
 
void eeprom_defaults (void)
 
variant8_t eeprom_get_var (uint8_t id)
 
void eeprom_set_var (uint8_t id, variant8_t var)
 
int eeprom_var_sprintf (char *str, uint8_t id, variant8_t var)
 
int8_t eeprom_test_PUT (const unsigned int bytes)
 

Variables

const uint8_t eeprom_map_v1 []
 
const char * eeprom_var_name []
 
uint16_t eeprom_crc_value = 0
 
uint8_t eeprom_crc_index = 0
 

Macro Definition Documentation

◆ EE_VERSION

#define EE_VERSION   0x0002

◆ EE_VAR_CNT

#define EE_VAR_CNT   sizeof(eeprom_map_v1)

◆ EE_ADDRESS

#define EE_ADDRESS   0x0500

Function Documentation

◆ eeprom_var_size()

uint16_t eeprom_var_size ( uint8_t  id)
103  {
104  if (id < EE_VAR_CNT)
105  switch (eeprom_map_v1[id]) {
106  case VARIANT8_I8:
107  case VARIANT8_UI8:
108  return 1;
109  case VARIANT8_I16:
110  case VARIANT8_UI16:
111  return 2;
112  case VARIANT8_I32:
113  case VARIANT8_UI32:
114  case VARIANT8_FLT:
115  return 4;
116  }
117  return 0;
118 }
Here is the caller graph for this function:

◆ eeprom_var_addr()

uint16_t eeprom_var_addr ( uint8_t  id)
120  {
121  uint16_t addr = EE_ADDRESS;
122  while (id)
123  addr += eeprom_var_size(--id);
124  return addr;
125 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_var_default()

variant8_t eeprom_var_default ( uint8_t  id)
127  {
128  switch (id) {
129  case EEVAR_VERSION:
130  return variant8_ui16(EE_VERSION);
131  case EEVAR_FILAMENT_TYPE:
132  return variant8_ui8(0);
134  return variant8_ui32(0);
135  case EEVAR_UNUSED_1:
136  return variant8_flt(0.0100);
137  case EEVAR_UNUSED_2:
138  return variant8_flt(-40);
139  case EEVAR_UNUSED_3:
140  return variant8_flt(20);
141  case EEVAR_RUN_SELFTEST:
142  return variant8_ui8(1);
143  case EEVAR_RUN_XYZCALIB:
144  return variant8_ui8(1);
145  case EEVAR_RUN_FIRSTLAY:
146  return variant8_ui8(1);
148  return variant8_ui8(0);
149  }
150  return variant8_empty();
151 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_dump()

void eeprom_dump ( void  )
153  {
154  int i;
155  int j;
156  uint8_t b;
157  char line[64];
158  for (i = 0; i < 128; i++) // 128 lines = 2048 bytes
159  {
160  sprintf(line, "%04x", i * 16);
161  for (j = 0; j < 16; j++) {
162  b = st25dv64k_user_read(j + i * 16);
163  sprintf(line + 4 + j * 3, " %02x", b);
164  }
165  _dbg("%s", line);
166  }
167 }
Here is the call graph for this function:

◆ eeprom_print_vars()

void eeprom_print_vars ( void  )
192  {
193  uint8_t id;
194  char text[16];
195  for (id = 0; id < EE_VAR_CNT; id++) {
196  eeprom_var_sprintf(text, id, eeprom_get_var(id));
197  _dbg("%s=%s", eeprom_var_name[id], text);
198  }
199 }
Here is the call graph for this function:

◆ eeprom_clear()

void eeprom_clear ( void  )
201  {
202  uint16_t a;
203  uint32_t data = 0xffffffff;
204  for (a = 0x0000; a < 0x0800; a += 4)
206 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_init()

uint8_t eeprom_init ( void  )
53  {
54  uint8_t ret = 0;
56  //eeprom_clear();
57  //eeprom_dump();
58  uint16_t version = eeprom_get_var(EEVAR_VERSION).ui16;
59  if (version != EE_VERSION) {
61  ret = 1;
62  }
63  //eeprom_print_vars();
64  //eeprom_dump();
65  return ret;
66 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_defaults()

void eeprom_defaults ( void  )
69  {
70  uint8_t id;
71  for (id = 0; id < EE_VAR_CNT; id++)
73 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_get_var()

variant8_t eeprom_get_var ( uint8_t  id)
75  {
76  uint16_t addr;
77  uint16_t size;
78  variant8_t var = variant8_empty();
79  if (id < EE_VAR_CNT) {
80  var.type = eeprom_map_v1[id];
81  addr = eeprom_var_addr(id);
82  size = eeprom_var_size(id);
83  st25dv64k_user_read_bytes(addr, &(var.ui32), size);
84  }
85  return var;
86 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_set_var()

void eeprom_set_var ( uint8_t  id,
variant8_t  var 
)
88  {
89  uint16_t addr;
90  uint16_t size;
91  if (id < EE_VAR_CNT) {
92  if (var.type == eeprom_map_v1[id]) {
93  addr = eeprom_var_addr(id);
94  size = eeprom_var_size(id);
95  st25dv64k_user_write_bytes(addr, &(var.ui32), size);
96  // osDelay(5);
97  }
98  }
99 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_var_sprintf()

int eeprom_var_sprintf ( char *  str,
uint8_t  id,
variant8_t  var 
)
169  {
170  switch (id) {
171  case EEVAR_VERSION:
172  return sprintf(str, "%u", (unsigned int)var.ui16);
173  case EEVAR_FILAMENT_TYPE:
174  return sprintf(str, "%u", (unsigned int)var.ui8);
176  return sprintf(str, "0x%08lx", (unsigned long)var.ui32);
177  case EEVAR_UNUSED_1:
178  return sprintf(str, "%.4f", (double)var.flt);
179  case EEVAR_UNUSED_2:
180  return sprintf(str, "%.1f", (double)var.flt);
181  case EEVAR_UNUSED_3:
182  return sprintf(str, "%.1f", (double)var.flt);
183  case EEVAR_RUN_SELFTEST:
184  case EEVAR_RUN_XYZCALIB:
185  case EEVAR_RUN_FIRSTLAY:
187  return sprintf(str, "%u", (unsigned int)var.ui8);
188  }
189  return 0;
190 }
Here is the caller graph for this function:

◆ eeprom_test_PUT()

int8_t eeprom_test_PUT ( const unsigned int  bytes)
208  {
209 
210  unsigned int i;
211  char line[16] = "abcdefghijklmno";
212  char line2[16];
213  uint8_t size = sizeof(line);
214  unsigned int count = bytes / 16;
215 
216  for (i = 0; i < count; i++) {
218  }
219 
220  int8_t res_flag = 1;
221 
222  for (i = 0; i < count; i++) {
224  if (strcmp(line2, line))
225  res_flag = 0;
226  }
227  return res_flag;
228 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ eeprom_map_v1

◆ eeprom_var_name

const char* eeprom_var_name[]
Initial value:
= {
"VERSION",
"FILAMENT_TYPE",
"FILAMENT_COLOR",
"UNUSED_1",
"UNUSED_2",
"UNUSED_3",
"RUN_SELFTEST",
"RUN_XYZCALIB",
"RUN_FIRSTLAY",
"FSENSOR_ENABLED",
}

◆ eeprom_crc_value

uint16_t eeprom_crc_value = 0

◆ eeprom_crc_index

uint8_t eeprom_crc_index = 0
VARIANT8_UI8
#define VARIANT8_UI8
Definition: variant8.h:10
EEVAR_UNUSED_1
#define EEVAR_UNUSED_1
Definition: eeprom.h:11
EE_ADDRESS
#define EE_ADDRESS
Definition: eeprom.c:11
variant8_ui8
variant8_t variant8_ui8(uint8_t ui8)
Definition: variant8.c:18
eeprom_var_name
const char * eeprom_var_name[]
Definition: eeprom.c:26
EEVAR_FSENSOR_ENABLED
#define EEVAR_FSENSOR_ENABLED
Definition: eeprom.h:17
st25dv64k_user_read_bytes
void st25dv64k_user_read_bytes(uint16_t address, void *pdata, uint8_t size)
Definition: st25dv64k.c:111
eeprom_var_default
variant8_t eeprom_var_default(uint8_t id)
Definition: eeprom.c:127
eeprom_map_v1
const uint8_t eeprom_map_v1[]
Definition: eeprom.c:13
_variant8_t::ui16
uint16_t ui16
Definition: variant8.h:34
VARIANT8_I16
#define VARIANT8_I16
Definition: variant8.h:11
st25dv64k_init
void st25dv64k_init(void)
Definition: st25dv64k.c:73
eeprom_get_var
variant8_t eeprom_get_var(uint8_t id)
Definition: eeprom.c:75
_variant8_t::ui8
uint8_t ui8
Definition: variant8.h:36
VARIANT8_I8
#define VARIANT8_I8
Definition: variant8.h:9
data
uint8_t data[8]
Definition: masstorage.h:49
EEVAR_RUN_FIRSTLAY
#define EEVAR_RUN_FIRSTLAY
Definition: eeprom.h:16
i
uint8_t i
Definition: screen_test_graph.c:72
_variant8_t::type
uint8_t type
Definition: variant8.h:25
eeprom_set_var
void eeprom_set_var(uint8_t id, variant8_t var)
Definition: eeprom.c:88
variant8_ui16
variant8_t variant8_ui16(uint16_t ui16)
Definition: variant8.c:30
_variant8_t
Definition: variant8.h:24
EE_VERSION
#define EE_VERSION
Definition: eeprom.c:9
EEVAR_RUN_XYZCALIB
#define EEVAR_RUN_XYZCALIB
Definition: eeprom.h:15
_variant8_t::flt
float flt
Definition: variant8.h:31
EEVAR_VERSION
#define EEVAR_VERSION
Definition: eeprom.h:8
EEVAR_RUN_SELFTEST
#define EEVAR_RUN_SELFTEST
Definition: eeprom.h:14
st25dv64k_user_write_bytes
void st25dv64k_user_write_bytes(uint16_t address, void *pdata, uint8_t size)
Definition: st25dv64k.c:119
eeprom_defaults
void eeprom_defaults(void)
Definition: eeprom.c:69
createSpeedLookupTable.a
list a
Definition: createSpeedLookupTable.py:29
EEVAR_FILAMENT_COLOR
#define EEVAR_FILAMENT_COLOR
Definition: eeprom.h:10
variant8_empty
variant8_t variant8_empty(void)
Definition: variant8.c:10
uint8_t
const uint8_t[]
Definition: 404_html.c:3
EEVAR_UNUSED_2
#define EEVAR_UNUSED_2
Definition: eeprom.h:12
_dbg
#define _dbg(...)
Definition: dbg.h:50
EE_VAR_CNT
#define EE_VAR_CNT
Definition: eeprom.c:10
variant8_ui32
variant8_t variant8_ui32(uint32_t ui32)
Definition: variant8.c:42
VARIANT8_UI16
#define VARIANT8_UI16
Definition: variant8.h:12
VARIANT8_FLT
#define VARIANT8_FLT
Definition: variant8.h:15
eeprom_var_sprintf
int eeprom_var_sprintf(char *str, uint8_t id, variant8_t var)
Definition: eeprom.c:169
VARIANT8_UI32
#define VARIANT8_UI32
Definition: variant8.h:14
eeprom_var_addr
uint16_t eeprom_var_addr(uint8_t id)
Definition: eeprom.c:120
_variant8_t::ui32
uint32_t ui32
Definition: variant8.h:32
st25dv64k_user_read
uint8_t st25dv64k_user_read(uint16_t address)
Definition: st25dv64k.c:93
VARIANT8_I32
#define VARIANT8_I32
Definition: variant8.h:13
eeprom_var_size
uint16_t eeprom_var_size(uint8_t id)
Definition: eeprom.c:103
variant8_flt
variant8_t variant8_flt(float flt)
Definition: variant8.c:48
createSpeedLookupTable.b
list b
Definition: createSpeedLookupTable.py:30
EEVAR_UNUSED_3
#define EEVAR_UNUSED_3
Definition: eeprom.h:13
EEVAR_FILAMENT_TYPE
#define EEVAR_FILAMENT_TYPE
Definition: eeprom.h:9
size
static png_bytep size_t size
Definition: pngwrite.c:2170