-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathEEPROM.h
66 lines (61 loc) · 1.91 KB
/
EEPROM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @file EEPROM.h
* @version 1.0
*
* @section License
* Copyright (C) 2017, Mikael Patel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#ifndef EEPROM_H
#define EEPROM_H
#include "Storage.h"
/**
* Storage device driver for the AVR internal EEPROM.
*/
class EEPROM : public Storage {
public:
/**
* Construct EEPROM device driver with storage size.
*/
EEPROM() : Storage(E2END + 1) {}
/**
* @override{Storage}
* Read eeprom block with the given size into the buffer from the
* source address. Return number of bytes read or negative error
* code.
* @param[in] dst buffer to read from eeprom.
* @param[in] src address in eeprom to read from.
* @param[in] count number of bytes to read.
* @return number of bytes or negative error code.
*/
virtual int read(void* dst, uint32_t src, size_t count)
{
eeprom_read_block(dst, (const void*) src, count);
return (count);
}
/**
* @override{Storage}
* Write eeprom block at given destination address with the contents
* from the buffer. Return number of bytes written or negative error
* code.
* @param[in] dst address in eeprom to read write to.
* @param[in] src buffer to write to eeprom.
* @param[in] count number of bytes to write.
* @return number of bytes or negative error code.
*/
virtual int write(uint32_t dst, const void* src, size_t count)
{
eeprom_update_block(src, (void*) dst, count);
return (count);
}
};
#endif