HAL eeprom cleanup
This commit is contained in:
@@ -55,12 +55,15 @@ static constexpr uint8_t eeprom_device_address = I2C_ADDRESS(EEPROM_DEVICE_ADDRE
|
||||
// Public functions
|
||||
// ------------------------
|
||||
|
||||
void eeprom_write_byte(uint8_t *pos, unsigned char value) {
|
||||
static void _eeprom_begin(uint8_t * const pos) {
|
||||
const unsigned eeprom_address = (unsigned)pos;
|
||||
|
||||
Wire.beginTransmission(eeprom_device_address);
|
||||
Wire.write(int(eeprom_address >> 8)); // MSB
|
||||
Wire.write(int(eeprom_address & 0xFF)); // LSB
|
||||
Wire.write(int(eeprom_address >> 8)); // Address High
|
||||
Wire.write(int(eeprom_address & 0xFF)); // Address Low
|
||||
}
|
||||
|
||||
void eeprom_write_byte(uint8_t *pos, uint8_t value) {
|
||||
_eeprom_begin(pos);
|
||||
Wire.write(value);
|
||||
Wire.endTransmission();
|
||||
|
||||
@@ -70,11 +73,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
|
||||
}
|
||||
|
||||
uint8_t eeprom_read_byte(uint8_t *pos) {
|
||||
const unsigned eeprom_address = (unsigned)pos;
|
||||
|
||||
Wire.beginTransmission(eeprom_device_address);
|
||||
Wire.write(int(eeprom_address >> 8)); // MSB
|
||||
Wire.write(int(eeprom_address & 0xFF)); // LSB
|
||||
_eeprom_begin(pos);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(eeprom_device_address, (byte)1);
|
||||
return Wire.available() ? Wire.read() : 0xFF;
|
||||
|
||||
Reference in New Issue
Block a user