2022-04-14 22:48:11 +02:00
|
|
|
#ifndef _CONFIG_H_
|
|
|
|
#define _CONFIG_H_
|
|
|
|
|
|
|
|
#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"
|
2022-04-14 22:48:11 +02:00
|
|
|
|
2022-05-15 16:37:34 +02:00
|
|
|
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC01
|
|
|
|
#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;
|
|
|
|
|
2022-05-15 16:37:34 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
BATTERY_UNDEFINED,
|
|
|
|
BATTERY_LIPO_2S,
|
|
|
|
BATTERY_LIPO_3S
|
|
|
|
} batteryType_t;
|
|
|
|
|
|
|
|
const char BatteryString[][10]{
|
|
|
|
"Undefined",
|
|
|
|
"LiPo 2S",
|
|
|
|
"LiPo 3S"
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
{
|
2022-05-15 16:37:34 +02:00
|
|
|
uint8_t EEPROM_Version = 1;
|
|
|
|
batteryType_t batteryType = BATTERY_UNDEFINED;
|
2022-04-14 22:48:11 +02:00
|
|
|
uint32_t checksum = 0;
|
|
|
|
} configData_t;
|
|
|
|
|
2023-02-20 13:51:54 +01:00
|
|
|
const configData_t ConfigData_defaults = {
|
|
|
|
0, BATTERY_LIPO_3S, 0
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
extern configData_t ConfigData;
|
|
|
|
extern persistenceData_t PersistenceData;
|
|
|
|
#endif // _CONFIG_H_
|