-
Notifications
You must be signed in to change notification settings - Fork 9
/
Eeprom24C04_16.h
211 lines (193 loc) · 6.88 KB
/
Eeprom24C04_16.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**************************************************************************//**
* \brief EEPROM 24C04 / 24C16 library for Arduino
* \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com
* \version 1.0
* \date 20120218
*
* This file is part of the EEPROM 24C04 / 24C16 library for Arduino.
*
* 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 3 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
******************************************************************************/
/**************************************************************************//**
* \headerfile Eeprom24C04_16.h
******************************************************************************/
#ifndef Eeprom24C04_16_h
#define Eeprom24C04_16_h
/******************************************************************************
* Header file inclusion.
******************************************************************************/
#include <Arduino.h>
/**************************************************************************//**
* \class Eeprom24C04_16
*
* \brief EEPROM 24C04 / 24C16 memory driver.
*
* This driver is mainly designed for 24C04 and 24C16 EEPROM memories.
******************************************************************************/
class Eeprom24C04_16
{
public:
/******************************************************************//**
* \fn Eeprom24C04_16(byte deviceAddress)
*
* \brief Constructor.
*
* \param deviceAddress EEPROM address on TWI bus.
**********************************************************************/
Eeprom24C04_16
(
byte deviceAddress
);
/******************************************************************//**
* \fn void initialize()
*
* \brief Initialize library abnd TWI bus.
*
* If several devices are connected to TWI bus, this method mustn't be
* called. TWI bus must be initialized out of this library using
* Wire.begin() method.
**********************************************************************/
void
initialize();
/******************************************************************//**
* \fn void writeByte(
* word address,
* byte data)
*
* \brief Write a byte in EEPROM memory.
*
* \remarks A delay of 10 ms is required after write cycle.
*
* \param address Address.
* \param data Byte to write.
**********************************************************************/
void
writeByte
(
word address,
byte data
);
/******************************************************************//**
* \fn void writeBytes(
* word address,
* word length,
* byte* p_data)
*
* \brief Write bytes in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes to write.
* \param[in] p_data Bytes to write.
**********************************************************************/
void
writeBytes
(
word address,
word length,
byte* p_data
);
/******************************************************************//**
* \fn byte readByte(word address)
*
* \brief Read a byte in EEPROM memory.
*
* \param address Address.
*
* \return Read byte.
**********************************************************************/
byte
readByte
(
word address
);
/******************************************************************//**
* \fn void readBytes(
* word address,
* word length,
* byte* p_data)
*
* \brief Read bytes in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes to read.
* \patam[in] p_data Byte array to fill with read bytes.
**********************************************************************/
void
readBytes
(
word address,
word length,
byte* p_buffer
);
private:
byte m_deviceAddress;
/******************************************************************//**
* \fn void writePage(
* word address,
* byte length,
* byte* p_data)
*
* \brief Write page in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes (64 bytes max).
* \param[in] p_data Data.
**********************************************************************/
void
writePage
(
word address,
byte length,
byte* p_data
);
/******************************************************************//**
* \fn void writeBuffer(
* word address,
* byte length,
* byte* p_data)
*
* \brief Write bytes into memory.
*
* \param address Start address.
* \param length Number of bytes (30 bytes max).
* \param[in] p_date Data.
**********************************************************************/
void
writeBuffer
(
word address,
byte length,
byte* p_data
);
/******************************************************************//**
* \fn void readBuffer(
* word address,
* byte length,
* byte* p_data)
*
* \brief Read bytes in memory.
*
* \param address Start address.
* \param length Number of bytes to read (32 bytes max).
* \param[in] p_data Buffer to fill with read bytes.
**********************************************************************/
void
readBuffer
(
word address,
byte length,
byte* p_data
);
};
#endif // Eeprom24C04_16_h