COSA
An Object-Oriented Platform for Arduino Programming
EEPROM.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_EEPROM_HH
22 #define COSA_EEPROM_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/Power.hh"
26 
33 class EEPROM {
34 public:
40  class Device {
41  public:
48  virtual bool is_ready();
49 
59  virtual int read(void* dest, const void* src, size_t size);
60 
70  virtual int write(void* dest, const void* src, size_t size);
71 
75  static Device eeprom;
76  };
77 
78 public:
84  EEPROM(Device* dev = &Device::eeprom) : m_dev(dev) {}
85 
91  bool is_ready()
92  __attribute__((always_inline))
93  {
94  return (m_dev->is_ready());
95  }
96 
101  void write_await()
102  __attribute__((always_inline))
103  {
104  while (!is_ready()) yield();
105  }
106 
115  int read(void* dest, const void* src, size_t size)
116  __attribute__((always_inline))
117  {
118  return (m_dev->read(dest, src, size));
119  }
120 
128  template<class T> int read(T* dest, const T* src)
129  {
130  return (m_dev->read(dest, src, sizeof(T)));
131  }
132 
133  int read(unsigned char* dest, const unsigned char* src)
134  __attribute__((always_inline))
135  {
136  return (m_dev->read(dest, src, sizeof(unsigned char)));
137  }
138 
139  int read(unsigned short* dest, const unsigned short* src)
140  __attribute__((always_inline))
141  {
142  return (m_dev->read(dest, src, sizeof(unsigned short)));
143  }
144 
145  int read(unsigned int* dest, const unsigned int* src)
146  __attribute__((always_inline))
147  {
148  return (m_dev->read(dest, src, sizeof(unsigned int)));
149  }
150 
151  int read(unsigned long* dest, const unsigned long* src)
152  __attribute__((always_inline))
153  {
154  return (m_dev->read(dest, src, sizeof(unsigned long)));
155  }
156 
157  int read(char* dest, const char* src)
158  __attribute__((always_inline))
159  {
160  return (m_dev->read(dest, src, sizeof(char)));
161  }
162 
163  int read(short* dest, const short* src)
164  __attribute__((always_inline))
165  {
166  return (m_dev->read(dest, src, sizeof(short)));
167  }
168 
169  int read(int* dest, const int* src)
170  __attribute__((always_inline))
171  {
172  return (m_dev->read(dest, src, sizeof(int)));
173  }
174 
175  int read(long* dest, const long* src)
176  __attribute__((always_inline))
177  {
178  return (m_dev->read(dest, src, sizeof(long)));
179  }
180 
181  int read(float* dest, const float* src)
182  __attribute__((always_inline))
183  {
184  return (m_dev->read(dest, src, sizeof(float)));
185  }
186 
195  int write(void* dest, const void* src, size_t size)
196  __attribute__((always_inline))
197  {
198  return (m_dev->write(dest, src, size));
199  }
200 
209  template<class T> int write(T* dest, const T* src)
210  {
211  return (m_dev->write(dest, src, sizeof(T)));
212  }
213 
214  int write(unsigned char* dest, unsigned char src)
215  __attribute__((always_inline))
216  {
217  return (m_dev->write(dest, &src, sizeof(unsigned char)));
218  }
219 
220  int write(unsigned short* dest, unsigned short src)
221  __attribute__((always_inline))
222  {
223  return (m_dev->write(dest, &src, sizeof(unsigned short)));
224  }
225 
226  int write(unsigned int* dest, unsigned int src)
227  __attribute__((always_inline))
228  {
229  return (m_dev->write(dest, &src, sizeof(unsigned int)));
230  }
231 
232  int write(unsigned long* dest, unsigned long src)
233  __attribute__((always_inline))
234  {
235  return (m_dev->write(dest, &src, sizeof(unsigned long)));
236  }
237 
238  int write(char* dest, char src)
239  __attribute__((always_inline))
240  {
241  return (m_dev->write(dest, &src, sizeof(char)));
242  }
243 
244  int write(short* dest, short src)
245  __attribute__((always_inline))
246  {
247  return (m_dev->write(dest, &src, sizeof(short)));
248  }
249 
250  int write(int* dest, int src)
251  __attribute__((always_inline))
252  {
253  return (m_dev->write(dest, &src, sizeof(int)));
254  }
255 
256  int write(long* dest, long src)
257  __attribute__((always_inline))
258  {
259  return (m_dev->write(dest, &src, sizeof(long)));
260  }
261 
262  int write(float* dest, float src)
263  __attribute__((always_inline))
264  {
265  return (m_dev->write(dest, &src, sizeof(float)));
266  }
267 
268 private:
269  Device* m_dev;
270 };
271 
272 #endif
bool is_ready()
Definition: EEPROM.hh:91
void write_await()
Definition: EEPROM.hh:101
static Device eeprom
Definition: EEPROM.hh:75
int write(float *dest, float src)
Definition: EEPROM.hh:262
EEPROM(Device *dev=&Device::eeprom)
Definition: EEPROM.hh:84
Definition: EEPROM.hh:33
int write(unsigned short *dest, unsigned short src)
Definition: EEPROM.hh:220
int write(char *dest, char src)
Definition: EEPROM.hh:238
int write(unsigned int *dest, unsigned int src)
Definition: EEPROM.hh:226
int read(int *dest, const int *src)
Definition: EEPROM.hh:169
int read(unsigned long *dest, const unsigned long *src)
Definition: EEPROM.hh:151
int read(unsigned short *dest, const unsigned short *src)
Definition: EEPROM.hh:139
int read(void *dest, const void *src, size_t size)
Definition: EEPROM.hh:115
int write(int *dest, int src)
Definition: EEPROM.hh:250
virtual int write(void *dest, const void *src, size_t size)
Definition: EEPROM.cpp:40
int read(T *dest, const T *src)
Definition: EEPROM.hh:128
int write(unsigned char *dest, unsigned char src)
Definition: EEPROM.hh:214
int read(long *dest, const long *src)
Definition: EEPROM.hh:175
virtual int read(void *dest, const void *src, size_t size)
Definition: EEPROM.cpp:30
void(* yield)()
virtual bool is_ready()
Definition: EEPROM.cpp:24
int write(void *dest, const void *src, size_t size)
Definition: EEPROM.hh:195
int write(long *dest, long src)
Definition: EEPROM.hh:256
int read(char *dest, const char *src)
Definition: EEPROM.hh:157
int read(float *dest, const float *src)
Definition: EEPROM.hh:181
int write(unsigned long *dest, unsigned long src)
Definition: EEPROM.hh:232
int read(short *dest, const short *src)
Definition: EEPROM.hh:163
int write(T *dest, const T *src)
Definition: EEPROM.hh:209
int read(unsigned char *dest, const unsigned char *src)
Definition: EEPROM.hh:133
int read(unsigned int *dest, const unsigned int *src)
Definition: EEPROM.hh:145
int write(short *dest, short src)
Definition: EEPROM.hh:244