#ifndef INC_EEPROM_H_ #define INC_EEPROM_H_ #include "stm32f4xx_hal.h" #include "stm32f4xx_hal_def.h" #define EEPROM_BASE_ADDR 0b1010000 // Device address must be shifted left before being passed to the HAL #define EEPROM_DEV_ADDR (EEPROM_BASE_ADDR << 1) #define EEPROM_TIMEOUT 200 /* ms */ #define EEPROM_READ_TRIES 5 #define EEPROM_ADDR_SLAVE_ID 0x000 typedef enum { EEPROM_OFF, EEPROM_READY, EEPROM_ERROR } EEPROM_State; extern EEPROM_State eeprom_state; void eeprom_init(I2C_HandleTypeDef* handle); /** * @brief Write a byte to the EEPROM. * * @param addr 9-bit address (1 bit page select + 8 bit address) * @param data The byte to write */ HAL_StatusTypeDef eeprom_write(uint16_t addr, uint8_t data); /** * @brief Read a byte from the next address in the EEPROM. * * @param data 1-byte buffer into which the read byte is written. */ HAL_StatusTypeDef eeprom_read_curr(uint8_t* data); /** * @brief Read a byte from the EEPROM (random-access). * * @param addr 9-bit address (1 bit page select + 8 bit address) * @param data 1-byte buffer into which the read byte is written. */ HAL_StatusTypeDef eeprom_read_random(uint16_t addr, uint8_t* data); #endif // INC_EEPROM_H_