Backport eeprom functions from 3.13
This commit is contained in:
parent
b23476aaf3
commit
1445c2eecc
|
|
@ -11,57 +11,22 @@
|
||||||
|
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
|
|
||||||
#if 0
|
|
||||||
template <typename T>
|
|
||||||
static T eeprom_read(T *address);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
char eeprom_read<char>(char *address)
|
|
||||||
{
|
|
||||||
return eeprom_read_byte(reinterpret_cast<uint8_t*>(address));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static void eeprom_write(T *address, T value);
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void eeprom_write<char>(char *addres, char value)
|
|
||||||
{
|
|
||||||
eeprom_write_byte(reinterpret_cast<uint8_t*>(addres), static_cast<uint8_t>(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static bool eeprom_is_uninitialized(T *address);
|
|
||||||
|
|
||||||
template <>
|
|
||||||
bool eeprom_is_uninitialized<char>(char *address)
|
|
||||||
{
|
|
||||||
return (0xff == eeprom_read_byte(reinterpret_cast<uint8_t*>(address)));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool eeprom_is_sheet_initialized(uint8_t sheet_num)
|
|
||||||
{
|
|
||||||
return (0xffff != eeprom_read_word(reinterpret_cast<uint16_t*>(&(EEPROM_Sheets_base->
|
|
||||||
s[sheet_num].z_offset))));
|
|
||||||
}
|
|
||||||
|
|
||||||
void eeprom_init()
|
void eeprom_init()
|
||||||
{
|
{
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_POWER_COUNT, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_POWER_COUNT, 0);
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_CRASH_COUNT_X, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_CRASH_COUNT_X, 0);
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_CRASH_COUNT_Y, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_CRASH_COUNT_Y, 0);
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_FERROR_COUNT, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_FERROR_COUNT, 0);
|
||||||
if (eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_POWER_COUNT_TOT, 0);
|
eeprom_init_default_word((uint16_t*)EEPROM_POWER_COUNT_TOT, 0);
|
||||||
if (eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT, 0);
|
eeprom_init_default_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT, 0);
|
||||||
if (eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT, 0);
|
eeprom_init_default_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT, 0);
|
||||||
if (eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, 0);
|
eeprom_init_default_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, 0);
|
||||||
|
|
||||||
if (eeprom_read_word((uint16_t*)EEPROM_MMU_FAIL_TOT) == 0xffff) eeprom_update_word((uint16_t *)EEPROM_MMU_FAIL_TOT, 0);
|
eeprom_init_default_word((uint16_t*)EEPROM_MMU_FAIL_TOT, 0);
|
||||||
if (eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) == 0xffff) eeprom_update_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT, 0);
|
eeprom_init_default_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT, 0);
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_FAIL, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_MMU_FAIL, 0);
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL, 0);
|
||||||
|
eeprom_init_default_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT, 0);
|
||||||
if (eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)) == EEPROM_EMPTY_VALUE)
|
if (eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)) == EEPROM_EMPTY_VALUE)
|
||||||
{
|
{
|
||||||
eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), 0);
|
eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), 0);
|
||||||
|
|
@ -71,23 +36,13 @@ void eeprom_init()
|
||||||
eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[0].z_offset)), last_babystep);
|
eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[0].z_offset)), last_babystep);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint_least8_t i = 0; i < (sizeof(Sheets::s)/sizeof(Sheets::s[0])); ++i)
|
// initialize the sheet names in eeprom
|
||||||
{
|
for (uint_least8_t i = 0; i < (sizeof(Sheets::s)/sizeof(Sheets::s[0])); i++) {
|
||||||
bool is_uninitialized = true;
|
SheetName sheetName;
|
||||||
for (uint_least8_t j = 0; j < (sizeof(Sheet::name)/sizeof(Sheet::name[0])); ++j)
|
eeprom_default_sheet_name(i, sheetName);
|
||||||
{
|
eeprom_init_default_block(EEPROM_Sheets_base->s[i].name, (sizeof(Sheet::name)/sizeof(Sheet::name[0])), sheetName.c);
|
||||||
if (!eeprom_is_uninitialized(&(EEPROM_Sheets_base->s[i].name[j]))) is_uninitialized = false;
|
|
||||||
}
|
|
||||||
if(is_uninitialized)
|
|
||||||
{
|
|
||||||
SheetName sheetName;
|
|
||||||
eeprom_default_sheet_name(i,sheetName);
|
|
||||||
|
|
||||||
for (uint_least8_t a = 0; a < sizeof(Sheet::name); ++a){
|
|
||||||
eeprom_write(&(EEPROM_Sheets_base->s[i].name[a]), sheetName.c[a]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))))
|
if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))))
|
||||||
{
|
{
|
||||||
eeprom_switch_to_next_sheet();
|
eeprom_switch_to_next_sheet();
|
||||||
|
|
@ -95,16 +50,16 @@ void eeprom_init()
|
||||||
check_babystep();
|
check_babystep();
|
||||||
|
|
||||||
#ifdef PINDA_TEMP_COMP
|
#ifdef PINDA_TEMP_COMP
|
||||||
if (eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_PINDA_TEMP_COMPENSATION, 0);
|
eeprom_init_default_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, 0);
|
||||||
#endif //PINDA_TEMP_COMP
|
#endif //PINDA_TEMP_COMP
|
||||||
|
|
||||||
if (eeprom_read_dword((uint32_t*)EEPROM_JOB_ID) == EEPROM_EMPTY_VALUE32)
|
eeprom_init_default_dword((uint32_t*)EEPROM_JOB_ID, 0);
|
||||||
eeprom_update_dword((uint32_t*)EEPROM_JOB_ID, 0);
|
eeprom_init_default_dword((uint32_t*)EEPROM_TOTALTIME, 0);
|
||||||
|
eeprom_init_default_dword((uint32_t*)EEPROM_FILAMENTUSED, 0);
|
||||||
|
eeprom_init_default_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
|
||||||
|
|
||||||
|
eeprom_init_default_byte((uint8_t*)EEPROM_HEAT_BED_ON_LOAD_FILAMENT, 1);
|
||||||
|
|
||||||
if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255) {
|
|
||||||
eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
|
|
||||||
eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! @brief Get default sheet name for index
|
//! @brief Get default sheet name for index
|
||||||
|
|
@ -178,3 +133,97 @@ void eeprom_switch_to_next_sheet()
|
||||||
sheet = eeprom_next_initialized_sheet(sheet);
|
sheet = eeprom_next_initialized_sheet(sheet);
|
||||||
if (sheet >= 0) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), sheet);
|
if (sheet >= 0) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool __attribute__((noinline)) eeprom_is_sheet_initialized(uint8_t sheet_num) {
|
||||||
|
return (eeprom_read_word(reinterpret_cast<uint16_t*>(&(EEPROM_Sheets_base->s[sheet_num].z_offset))) != EEPROM_EMPTY_VALUE16);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool __attribute__((noinline)) eeprom_is_initialized_block(const void *__p, size_t __n) {
|
||||||
|
const uint8_t *p = (const uint8_t*)__p;
|
||||||
|
while (__n--) {
|
||||||
|
if (eeprom_read_byte(p++) != EEPROM_EMPTY_VALUE)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void eeprom_update_block_P(const void *__src, void *__dst, size_t __n) {
|
||||||
|
const uint8_t *src = (const uint8_t*)__src;
|
||||||
|
uint8_t *dst = (uint8_t*)__dst;
|
||||||
|
while (__n--) {
|
||||||
|
eeprom_update_byte(dst++, pgm_read_byte(src++));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void eeprom_toggle(uint8_t *__p) {
|
||||||
|
eeprom_write_byte(__p, !eeprom_read_byte(__p));
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_increment_byte(uint8_t *__p) {
|
||||||
|
eeprom_write_byte(__p, eeprom_read_byte(__p) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_increment_word(uint16_t *__p) {
|
||||||
|
eeprom_write_word(__p, eeprom_read_word(__p) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_increment_dword(uint32_t *__p) {
|
||||||
|
eeprom_write_dword(__p, eeprom_read_dword(__p) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_add_byte(uint8_t *__p, uint8_t add) {
|
||||||
|
eeprom_write_byte(__p, eeprom_read_byte(__p) + add);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_add_word(uint16_t *__p, uint16_t add) {
|
||||||
|
eeprom_write_word(__p, eeprom_read_word(__p) + add);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_add_dword(uint32_t *__p, uint32_t add) {
|
||||||
|
eeprom_write_dword(__p, eeprom_read_dword(__p) + add);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t __attribute__((noinline)) eeprom_init_default_byte(uint8_t *__p, uint8_t def) {
|
||||||
|
uint8_t val = eeprom_read_byte(__p);
|
||||||
|
if (val == EEPROM_EMPTY_VALUE) {
|
||||||
|
eeprom_write_byte(__p, def);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t __attribute__((noinline)) eeprom_init_default_word(uint16_t *__p, uint16_t def) {
|
||||||
|
uint16_t val = eeprom_read_word(__p);
|
||||||
|
if (val == EEPROM_EMPTY_VALUE16) {
|
||||||
|
eeprom_write_word(__p, def);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t __attribute__((noinline)) eeprom_init_default_dword(uint32_t *__p, uint32_t def) {
|
||||||
|
uint32_t val = eeprom_read_dword(__p);
|
||||||
|
if (val == EEPROM_EMPTY_VALUE32) {
|
||||||
|
eeprom_write_dword(__p, def);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_init_default_float(float *__p, float def) {
|
||||||
|
if (eeprom_read_dword((uint32_t*)__p) == EEPROM_EMPTY_VALUE32)
|
||||||
|
eeprom_write_float(__p, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_init_default_block(void *__p, size_t __n, const void *def) {
|
||||||
|
if (!eeprom_is_initialized_block(__p, __n))
|
||||||
|
eeprom_update_block(def, __p, __n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __attribute__((noinline)) eeprom_init_default_block_P(void *__p, size_t __n, const void *def) {
|
||||||
|
if (!eeprom_is_initialized_block(__p, __n))
|
||||||
|
eeprom_update_block_P(def, __p, __n);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -620,7 +620,6 @@ enum
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
void eeprom_init();
|
void eeprom_init();
|
||||||
bool eeprom_is_sheet_initialized(uint8_t sheet_num);
|
|
||||||
struct SheetName
|
struct SheetName
|
||||||
{
|
{
|
||||||
char c[sizeof(Sheet::name) + 1];
|
char c[sizeof(Sheet::name) + 1];
|
||||||
|
|
@ -628,6 +627,26 @@ struct SheetName
|
||||||
void eeprom_default_sheet_name(uint8_t index, SheetName &sheetName);
|
void eeprom_default_sheet_name(uint8_t index, SheetName &sheetName);
|
||||||
int8_t eeprom_next_initialized_sheet(int8_t sheet);
|
int8_t eeprom_next_initialized_sheet(int8_t sheet);
|
||||||
void eeprom_switch_to_next_sheet();
|
void eeprom_switch_to_next_sheet();
|
||||||
|
bool eeprom_is_sheet_initialized(uint8_t sheet_num);
|
||||||
|
|
||||||
|
bool eeprom_is_initialized_block(const void *__p, size_t __n);
|
||||||
|
void eeprom_update_block_P(const void *__src, void *__dst, size_t __n);
|
||||||
|
void eeprom_toggle(uint8_t *__p);
|
||||||
|
|
||||||
|
void eeprom_increment_byte(uint8_t *__p);
|
||||||
|
void eeprom_increment_word(uint16_t *__p);
|
||||||
|
void eeprom_increment_dword(uint32_t *__p);
|
||||||
|
|
||||||
|
void eeprom_add_byte(uint8_t *__p, uint8_t add);
|
||||||
|
void eeprom_add_word(uint16_t *__p, uint16_t add);
|
||||||
|
void eeprom_add_dword(uint32_t *__p, uint32_t add);
|
||||||
|
|
||||||
|
uint8_t eeprom_init_default_byte(uint8_t *__p, uint8_t def);
|
||||||
|
uint16_t eeprom_init_default_word(uint16_t *__p, uint16_t def);
|
||||||
|
uint32_t eeprom_init_default_dword(uint32_t *__p, uint32_t def);
|
||||||
|
void eeprom_init_default_float(float *__p, float def);
|
||||||
|
void eeprom_init_default_block(void *__p, size_t __n, const void *def);
|
||||||
|
void eeprom_init_default_block_P(void *__p, size_t __n, const void *def);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // EEPROM_H
|
#endif // EEPROM_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue