2023-04-18 12:27:04 +02:00
|
|
|
#ifndef _EEPROM_H_
|
|
|
|
#define _EEPROM_H_
|
2022-04-14 22:48:11 +02:00
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <I2C_eeprom.h>
|
|
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
#include "dtc.h"
|
2023-02-20 13:51:54 +01:00
|
|
|
#include "common.h"
|
2023-04-18 12:27:04 +02:00
|
|
|
#include "debugger.h"
|
2022-04-14 22:48:11 +02:00
|
|
|
|
2023-04-18 20:06:57 +02:00
|
|
|
#define I2C_EE_ADDRESS 0x50
|
2023-04-17 20:23:17 +02:00
|
|
|
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC64
|
2022-05-15 16:37:34 +02:00
|
|
|
#define EEPROM_ENDURANCE 1000000
|
2022-04-14 22:48:11 +02:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
FACTION_1,
|
|
|
|
FACTION_2,
|
|
|
|
FACTION_3
|
|
|
|
} factions_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2022-05-15 16:37:34 +02:00
|
|
|
uint32_t writeCycleCounter = 0;
|
2022-04-14 22:48:11 +02:00
|
|
|
uint32_t faction_1_timer = 0;
|
|
|
|
uint32_t faction_2_timer = 0;
|
|
|
|
uint32_t faction_3_timer = 0;
|
|
|
|
factions_t activeFaction = NONE;
|
|
|
|
uint32_t checksum = 0;
|
|
|
|
} persistenceData_t;
|
|
|
|
|
2023-04-18 12:28:11 +02:00
|
|
|
extern persistenceData_t PersistenceData;
|
2022-05-15 16:37:34 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
BATTERY_UNDEFINED,
|
|
|
|
BATTERY_LIPO_2S,
|
|
|
|
BATTERY_LIPO_3S
|
|
|
|
} batteryType_t;
|
|
|
|
|
|
|
|
const char BatteryString[][10]{
|
2023-04-18 12:27:04 +02:00
|
|
|
"Undefined",
|
|
|
|
"LiPo 2S",
|
|
|
|
"LiPo 3S"};
|
2022-05-15 16:37:34 +02:00
|
|
|
|
2023-04-13 00:35:24 +02:00
|
|
|
const size_t BatteryString_Elements = sizeof(BatteryString) / sizeof(BatteryString[0]);
|
|
|
|
|
2022-04-14 22:48:11 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2023-04-18 12:27:04 +02:00
|
|
|
uint8_t EEPROM_Version;
|
|
|
|
batteryType_t batteryType;
|
|
|
|
bool active_faction_on_reboot;
|
2023-04-18 20:06:57 +02:00
|
|
|
char Faction_1_Name[33];
|
|
|
|
char Faction_2_Name[33];
|
|
|
|
char Faction_3_Name[33];
|
2023-04-18 12:27:04 +02:00
|
|
|
uint32_t checksum;
|
2022-04-14 22:48:11 +02:00
|
|
|
} configData_t;
|
|
|
|
|
2023-04-18 12:28:11 +02:00
|
|
|
extern configData_t ConfigData;
|
|
|
|
|
2023-02-20 13:51:54 +01:00
|
|
|
const configData_t ConfigData_defaults = {
|
2023-04-18 12:27:04 +02:00
|
|
|
2, // EEPROM_Version (incerease this if anything on Layout changes!)
|
|
|
|
BATTERY_LIPO_3S, // batteryType
|
|
|
|
false, // active_faction_on_reboot
|
|
|
|
"FACTION 1", // Faction_1_Name
|
|
|
|
"FACTION 2", // Faction_2_Name
|
|
|
|
"FACTION 3", // Faction_3_Name
|
|
|
|
0 // checksum
|
2023-02-20 13:51:54 +01:00
|
|
|
};
|
|
|
|
|
2023-04-18 12:27:04 +02:00
|
|
|
const uint16_t startofConfigData = 16;
|
|
|
|
const uint16_t startofPersistence = 16 + sizeof(ConfigData) + (sizeof(ConfigData) % 16);
|
|
|
|
|
2022-04-14 22:48:11 +02:00
|
|
|
void InitEEPROM();
|
|
|
|
void EEPROM_Process();
|
|
|
|
void StoreConfig_EEPROM();
|
|
|
|
void GetConfig_EEPROM();
|
|
|
|
void StorePersistence_EEPROM();
|
|
|
|
void GetPersistence_EEPROM();
|
|
|
|
void FormatConfig_EEPROM();
|
|
|
|
void FormatPersistence_EEPROM();
|
|
|
|
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
|
|
|
|
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
|
|
|
|
void MovePersistencePage_EEPROM(boolean reset);
|
2023-02-20 13:51:54 +01:00
|
|
|
uint32_t ConfigSanityCheck(bool autocorrect = false);
|
2022-04-14 22:48:11 +02:00
|
|
|
|
2023-04-18 12:27:04 +02:00
|
|
|
#endif // _EEPROM_H_
|