Prusa MINI Firmware overview
new_eeprom.cpp File Reference
#include "new_eeprom.h"
#include <inttypes.h>
#include <stddef.h>

Functions

void eeprom_initialize (EEPROM_t *ptr)
 
void eeprom_factory_reset (EEPROM_t *ptr)
 
int8_t eeprom_check_sum (EEPROM_t *ptr)
 

Function Documentation

◆ eeprom_initialize()

void eeprom_initialize ( EEPROM_t ptr)
11  { //fill up next condition if you add a variable to EEPROM
12  static bool eeprom_init_flag = false;
13  if (eeprom_init_flag == false) {
16  return;
17  }
18  if (ptr->eeprom_version == EEPROM_VER_OFFSET) {
19  ptr->filament_type = 0;
20  ptr->filament_r = 0;
21  ptr->filament_g = 0;
22  ptr->filament_b = 0;
23  }
24  /*-----------PREPARED_FOR_NEXT_VERSIONS-------------
25  if(ptr->eeprom_version <= EEPROM_VER_OFFSET + 1)
26  {
27 
28  //set variables that belong to eeprom version 2
29  }
30  if(ptr->eeprom_version <= EEPROM_VER_OFFSET + 2)
31  {
32 
33  //set variables that belong to eeprom version 3
34  }
35  */
36  int8_t check_sum_flag = eeprom_check_sum(ptr); //sets eeprom's check sum
37 
39  if (check_sum_flag == 0) //data is corrupted
41  } else
42  ptr->eeprom_version = EEPROM_VER_OFFSET + EEPROM_VER; //if you added some variable increment EEPROM_VER macro
43 
44  eeprom_init_flag = true;
45  }
46 }
Here is the call graph for this function:

◆ eeprom_factory_reset()

void eeprom_factory_reset ( EEPROM_t ptr)
48  {
49 
51  ptr->filament_type = 0;
52  ptr->filament_r = 0;
53  ptr->filament_g = 0;
54  ptr->filament_b = 0;
55 
56  eeprom_check_sum(ptr);
57 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eeprom_check_sum()

int8_t eeprom_check_sum ( EEPROM_t ptr)
59  {
60 
61  uint32_t curr_sum = ptr->check_sum;
62  ptr->check_sum = 0; //checksum is calculated from whole EEPROM structure, where check_sum var = 0
63  uint32_t tmp_sum = 0;
64  const uint8_t *p = reinterpret_cast<const uint8_t *>(ptr);
65  for (size_t count = sizeof(EEPROM_t); count; count--) {
66  tmp_sum += *p++;
67  }
68  ptr->check_sum = tmp_sum;
69  if (curr_sum != tmp_sum)
70  return 0;
71  else
72  return 1;
73 }
Here is the caller graph for this function:
eeprom_check_sum
int8_t eeprom_check_sum(EEPROM_t *ptr)
Definition: new_eeprom.cpp:59
EEPROM_t::filament_type
uint8_t filament_type
Definition: new_eeprom.h:35
EEPROM_t::check_sum
uint32_t check_sum
Definition: new_eeprom.h:34
EEPROM_t::eeprom_version
uint16_t eeprom_version
Definition: new_eeprom.h:33
EEPROM_t::filament_b
uint8_t filament_b
Definition: new_eeprom.h:38
EEPROM_t
Definition: new_eeprom.h:31
EEPROM_t::filament_r
uint8_t filament_r
Definition: new_eeprom.h:36
EEPROM_VER_OFFSET
#define EEPROM_VER_OFFSET
Definition: new_eeprom.h:28
eeprom_factory_reset
void eeprom_factory_reset(EEPROM_t *ptr)
Definition: new_eeprom.cpp:48
uint8_t
const uint8_t[]
Definition: 404_html.c:3
EEPROM_t::filament_g
uint8_t filament_g
Definition: new_eeprom.h:37
EEPROM_VER
#define EEPROM_VER
Definition: new_eeprom.h:27