SLS AVR Lib 0.1a
 
Loading...
Searching...
No Matches
eeprom.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------------+
2// This file is part of SLS AVR Library
3// https://github.com/SimonLitt/sls-avr-lib
4// ---------------------------------------------------------------------------+
5// Copyright (C) 2025 Simon Litt <simon@1itt.net> https://coding.1itt.net,
6// https://github.com/SimonLitt
7//
8// This program is free software: you can redistribute it and/or modify it
9// under the terms of the GNU General Public License as published by the Free
10// Software Foundation, version 3.
11//
12// This program is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15// more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program. If not, see <https://www.gnu.org/licenses/>.
19// ---------------------------------------------------------------------------+
30
31#ifndef SLS_AVR_EEPROM_H_
32#define SLS_AVR_EEPROM_H_
33
34#include <avr/eeprom.h>
35//#include <sls-avr/avr.h>
36
37typedef void * eeprom_adr_t;
38
46static inline void eeprom_read_str(char str[], const eeprom_adr_t adr, const size_t sz) {
47 for (size_t sz_counter = 0; sz_counter < sz; ++sz_counter) {
48 str[sz_counter] = eeprom_read_byte(adr + sz_counter);
49 if (!str[sz_counter]) {
50 break;
51 }
52 }
53 str[sz] = '\0'; //Always - it's faster then check
54}
55
63static inline void eeprom_read(void *const data, const eeprom_adr_t adr, const size_t sz) {
64 eeprom_read_block(data, adr, sz);
65}
66
74static inline void eeprom_write_str(const char str[], eeprom_adr_t adr, const size_t sz) {
75 for (size_t sz_counter = 0; sz_counter < sz; ++sz_counter) {
76 eeprom_update_byte(adr + sz_counter, str[sz_counter]);
77 if (!str[sz_counter]) {
78 break;
79 }
80 }
81}
82
90static inline void eeprom_write(const void *const data, eeprom_adr_t adr, const size_t sz) {
91 eeprom_update_block(data, adr, sz);
92}
93
94#endif // SLS_AVR_EEPROM_H_
AVR EEPROM helper.
static void eeprom_write(const void *const data, eeprom_adr_t adr, const size_t sz)
eeprom_update_block wrapper
Definition eeprom.h:90
static void eeprom_write_str(const char str[], eeprom_adr_t adr, const size_t sz)
Writes a string to EEPROM.
Definition eeprom.h:74
void * eeprom_adr_t
Definition eeprom.h:37
static void eeprom_read(void *const data, const eeprom_adr_t adr, const size_t sz)
eeprom_read_block wrapper
Definition eeprom.h:63
static void eeprom_read_str(char str[], const eeprom_adr_t adr, const size_t sz)
Reads a string from EEPROM.
Definition eeprom.h:46