From 2e6fe9ba6b198ffbe2250645eb70bc9607c78643 Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Wed, 1 Oct 2025 00:08:25 +0200 Subject: [PATCH] Implement AVR328 EEPROM handling --- firmware/atmega/include/eeprom.h | 10 ++++++++++ firmware/atmega/source/eeprom.c | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 firmware/atmega/include/eeprom.h create mode 100644 firmware/atmega/source/eeprom.c diff --git a/firmware/atmega/include/eeprom.h b/firmware/atmega/include/eeprom.h new file mode 100644 index 0000000..5abff7c --- /dev/null +++ b/firmware/atmega/include/eeprom.h @@ -0,0 +1,10 @@ +#ifndef EEPROM_H +#define EEPROM_H + +#include +#include +#include +#include "config.h" + +uint8_t eepromRead(uint8_t address); +void eepromWrite(uint8_t address, uint8_t data); diff --git a/firmware/atmega/source/eeprom.c b/firmware/atmega/source/eeprom.c new file mode 100644 index 0000000..47c3ef5 --- /dev/null +++ b/firmware/atmega/source/eeprom.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include "config.h" + +uint8_t eepromRead(uint8_t address) { + // wait for previous write + while (EECR & (1 << EEPE)); + + //read from address + EEAR = address; + return EECR |= (1 << EERE); +} + +void eepromWrite(uint8_t address, uint8_t data) { + // wait for previous write + while (EECR & (1 << EEPE)); + + //write to address + EEAR = address; + EEDR = data; + + EECR |= (1 << EEMPE); + EECR |= (1 << EEPE); +}