removed eeprom.h .c
This commit is contained in:
parent
c8047a9017
commit
61e455dfcd
@ -1,17 +0,0 @@
|
||||
#ifndef INC_EEPROM_H_
|
||||
#define INC_EEPROM_H_
|
||||
|
||||
#include "stm32f3xx_hal.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
__attribute__((packed)) typedef struct {
|
||||
uint8_t id;
|
||||
} EEPROMConfig;
|
||||
|
||||
extern EEPROMConfig eeprom_config;
|
||||
|
||||
void eeprom_init(I2C_HandleTypeDef* hi2c);
|
||||
void eeprom_config_save();
|
||||
|
||||
#endif // INC_EEPROM_H_
|
@ -1,55 +0,0 @@
|
||||
#include "eeprom.h"
|
||||
#include "errors.h"
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "stm32f3xx_hal_exti.h"
|
||||
#include "stm32f3xx_hal_i2c.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define EEPROM_I2C_ADDR 0xA0
|
||||
// Don't use the beginning of the EEPROM, since the testbench writes there
|
||||
#define EEPROM_CONFIG_BASE 0x0100
|
||||
#define EEPROM_CONFIG_ECC_OFFSET 0x20
|
||||
|
||||
EEPROMConfig eeprom_config;
|
||||
|
||||
static I2C_HandleTypeDef* hi2c;
|
||||
|
||||
void eeprom_init(I2C_HandleTypeDef* handle) {
|
||||
hi2c = handle;
|
||||
uint8_t buf[sizeof(EEPROMConfig) * 3];
|
||||
// Read 3 EEPROM config buffers at 32 byte offsets
|
||||
for (size_t ecc_i = 0; ecc_i < 3; ecc_i++) {
|
||||
HAL_I2C_Mem_Read(hi2c, EEPROM_I2C_ADDR,
|
||||
EEPROM_CONFIG_BASE + EEPROM_CONFIG_ECC_OFFSET * ecc_i, 2,
|
||||
buf + sizeof(EEPROMConfig) * ecc_i, sizeof(EEPROMConfig),
|
||||
100);
|
||||
}
|
||||
// ECC
|
||||
for (size_t i = 0; i < sizeof(EEPROMConfig); i++) {
|
||||
uint8_t a = buf[i + sizeof(EEPROMConfig) * 0];
|
||||
uint8_t b = buf[i + sizeof(EEPROMConfig) * 1];
|
||||
uint8_t c = buf[i + sizeof(EEPROMConfig) * 2];
|
||||
if (a == b || a == c) {
|
||||
buf[i] = a;
|
||||
} else if (b == c) {
|
||||
buf[i] = b;
|
||||
} else {
|
||||
set_error_source(ERROR_SOURCE_EEPROM);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&eeprom_config, buf, sizeof(EEPROMConfig));
|
||||
// Write back config
|
||||
eeprom_config.id = 10;
|
||||
eeprom_config_save();
|
||||
}
|
||||
|
||||
void eeprom_config_save() {
|
||||
for (size_t ecc_i = 0; ecc_i < 3; ecc_i++) {
|
||||
HAL_I2C_Mem_Write(hi2c, EEPROM_I2C_ADDR,
|
||||
EEPROM_CONFIG_BASE + EEPROM_CONFIG_ECC_OFFSET * ecc_i, 2,
|
||||
(uint8_t*)&eeprom_config, sizeof(eeprom_config), 100);
|
||||
HAL_Delay(100);
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@
|
||||
#include "AMS_HighLevel.h"
|
||||
#include "state_machine.h"
|
||||
#include "TMP1075.h"
|
||||
#include "eeprom.h"
|
||||
#include "errors.h"
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "stm32f3xx_hal_gpio.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user