]> git.tdb.fi Git - model-railway-devices.git/blob - common/eeprom.c
Reorganize the directory structure
[model-railway-devices.git] / common / eeprom.c
1 #include <avr/io.h>
2 #include "eeprom.h"
3
4 #define BIT(n) (1<<(n))
5
6 static void eeprom_wait(void)
7 {
8         while(EECR&BIT(EEPE)) ;
9 }
10
11 void eeprom_write(uint16_t addr, uint8_t data)
12 {
13         eeprom_wait();
14         EEARH = addr>>8;
15         EEARL = addr;
16         EEDR = data;
17         EECR = BIT(EEMPE);
18         EECR |= BIT(EEPE);
19         eeprom_wait();
20 }
21
22 uint8_t eeprom_read(uint16_t addr)
23 {
24         eeprom_wait();
25         EEARH = addr>>8;
26         EEARL = addr;
27         EECR = BIT(EERE);
28         return EEDR;
29 }