mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 07:10:17 +00:00
151 lines
4.0 KiB
C
151 lines
4.0 KiB
C
#include "stm32f1xx_hal.h"
|
|
|
|
#ifndef INC_EEPROM_H_
|
|
#define INC_EEPROM_H_
|
|
|
|
#include <assert.h>
|
|
|
|
#define AT24C_ADRESS 0x50 // i2c slave adress EEPROM
|
|
|
|
#define START_ADR_STAT 0x0000 //00000
|
|
|
|
#define STAT_BLOCKSIZE 128
|
|
|
|
#define START_ADR_SHOT (START_ADR_STAT+STAT_BLOCKSIZE)
|
|
#define SHOT_BLOCKSIZE 10
|
|
#define MAX_SHOT_COUNT 256
|
|
|
|
#define START_ADR_PROGRAM (START_ADR_SHOT + (SHOT_BLOCKSIZE*MAX_SHOT_COUNT))
|
|
#define PROGRAM_BLOCKSIZE 67
|
|
#define MAX_PROGRAM_COUNT 256
|
|
#define MAX_SHOT_COUNT_IN_PROGRAMS \
|
|
(PROGRAM_BLOCKSIZE-sizeof(ProgramHeader)) /sizeof(ProgramShot) //
|
|
|
|
#define START_ADR_MACRO (START_ADR_PROGRAM + (PROGRAM_BLOCKSIZE*MAX_PROGRAM_COUNT))
|
|
#define MACRO_BLOCKSIZE 129
|
|
#define MAX_MACRO_COUNT 100
|
|
#define MAX_PROGRAM_COUNT_IN_MACRO \
|
|
(MACRO_BLOCKSIZE-sizeof(MacroHeader)) /sizeof(MacroProgram) //
|
|
|
|
#define MEMORY_END (START_ADR_MACRO + (MACRO_BLOCKSIZE*MAX_MACRO_COUNT))
|
|
|
|
typedef enum MemoryStatus {
|
|
EEPROM_FAIL,
|
|
EEPROM_MISSING_ELEMENT,
|
|
EEPROM_OUT_OF_RANGE,
|
|
EEPROM_WRONG_STARTADDR,
|
|
EEPROM_OK
|
|
} MemoryStatus;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
unsigned char isExist;
|
|
unsigned char countRepeatShot; // 0 = inf
|
|
unsigned char speedRollerTop; // 0 .. 100 .. 200
|
|
unsigned char speedRollerBottom; // 0 .. 100 .. 200
|
|
unsigned char speedScrew; // 0 .. 100
|
|
unsigned char rotationAxial; // 0 .. 90 .. 180
|
|
unsigned char rotationHorizontal; // 0 .. 90 .. 180
|
|
unsigned char rotationVertical; // 0 .. 90 .. 180
|
|
} Shot;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
unsigned char shotCount; //isExist
|
|
unsigned char countRepeat;
|
|
unsigned char options;
|
|
} ProgramHeader;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
unsigned char id;
|
|
unsigned char speedScrew;
|
|
} ProgramShot;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
ProgramHeader header;
|
|
ProgramShot shots[MAX_SHOT_COUNT_IN_PROGRAMS];
|
|
} Program;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
unsigned char programmCount; //isExist
|
|
} MacroHeader;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
unsigned char id;
|
|
unsigned char speedScrew;
|
|
unsigned char countRepeat;
|
|
unsigned char options;
|
|
} MacroProgram;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
MacroHeader header;
|
|
MacroProgram programs[MAX_PROGRAM_COUNT_IN_MACRO];
|
|
} Macro;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
uint8_t invert;
|
|
uint16_t min;
|
|
uint16_t def;
|
|
uint16_t max;
|
|
} ServoSetting;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
uint16_t preRun;
|
|
} DelayTimes;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
uint16_t speed_Rollers_min;
|
|
// uint16_t speed_Rollers_max;
|
|
|
|
uint16_t speed_Screw_min;
|
|
// uint16_t speed_Screw_max;
|
|
} Motors;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
DelayTimes timings;
|
|
ServoSetting servos[3];
|
|
Motors motors;
|
|
} HardwareInit_t;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
uint32_t shotsInShot;
|
|
uint32_t shotsInProgram;
|
|
uint32_t shotInMacro;
|
|
} Statistics;
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
char init_uid[11];
|
|
HardwareInit_t hwInfo;
|
|
Statistics statInfo;
|
|
} InfoBlock;
|
|
_Static_assert(sizeof(InfoBlock) <= STAT_BLOCKSIZE, "Error: InfoBlock size exceeds 128 bytes.");
|
|
|
|
extern InfoBlock infoBlock;
|
|
|
|
// read from EEPROM infoBlock
|
|
// or write to EEPROM default infoBlock
|
|
MemoryStatus EEPROM_INIT();
|
|
MemoryStatus EEPROM_EARSE();
|
|
|
|
MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number,
|
|
uint8_t *writeData, uint16_t dataSize, uint16_t blockSize);
|
|
MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number,
|
|
uint8_t *readData, uint16_t dataSize);
|
|
MemoryStatus FLASH_DelBlock(uint16_t startAddr, uint8_t number,
|
|
uint16_t dataSize);
|
|
|
|
MemoryStatus saveShot(unsigned char number, Shot *shot);
|
|
MemoryStatus getShot(unsigned char number, Shot *shot);
|
|
MemoryStatus delShot(unsigned char number);
|
|
|
|
MemoryStatus saveProg(unsigned char number, Program *prog);
|
|
MemoryStatus getProg(unsigned char number, Program *prog);
|
|
MemoryStatus delProg(unsigned char number);
|
|
|
|
MemoryStatus saveMacro(unsigned char number, Macro *macro);
|
|
MemoryStatus getMacro(unsigned char number, Macro *macro);
|
|
MemoryStatus delMacro(unsigned char number);
|
|
|
|
MemoryStatus saveInfoBlock();
|
|
MemoryStatus getInfoBlock();
|
|
|
|
#endif /* INC_EEPROM_H_ */
|