COSA
An Object-Oriented Platform for Arduino Programming
AT24CXX.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_AT24CXX_HH
22 #define COSA_AT24CXX_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/TWI.hh"
26 #include "Cosa/EEPROM.hh"
27 
48 class AT24CXX : private TWI::Driver, public EEPROM::Device {
49 public:
53  const size_t SIZE;
54 
58  const uint16_t PAGE_MAX;
59 
67  AT24CXX(uint8_t subaddr = 0,
68  const size_t size = 32,
69  const uint16_t page_max = 32) :
70  TWI::Driver(0x50 | (subaddr & 0x07)),
71  EEPROM::Device(),
72  SIZE((size / CHARBITS) * 1024),
73  PAGE_MAX(page_max),
74  WRITE_MAX(page_max),
75  WRITE_MASK(page_max - 1)
76  {}
77 
84  virtual bool is_ready();
85 
95  virtual int read(void* dest, const void* src, size_t size);
96 
106  virtual int write(void* dest, const void* src, size_t size);
107 
108 private:
109  static const uint8_t POLL_MAX = 3;
110  const uint16_t WRITE_MAX;
111  const uint16_t WRITE_MASK;
112 
124  bool poll(const void* addr, const void* buf = NULL, size_t size = 0);
125 };
126 
135 class AT24C32 : public AT24CXX {
136 public:
137  AT24C32(uint8_t addr = 0) : AT24CXX(addr, 32, 32) {}
138 };
139 
148 class AT24C64 : public AT24CXX {
149 public:
150  AT24C64(uint8_t addr = 0) : AT24CXX(addr, 64, 32) {}
151 };
152 
161 class AT24C128 : public AT24CXX {
162 public:
163  AT24C128(uint8_t addr = 0) : AT24CXX(addr, 128, 64) {}
164 };
165 
174 class AT24C256 : public AT24CXX {
175 public:
176  AT24C256(uint8_t addr = 0) : AT24CXX(addr, 256, 64) {}
177 };
178 
187 class AT24C512 : public AT24CXX {
188 public:
189  AT24C512(uint8_t addr = 0) : AT24CXX(addr, 512, 128) {}
190 };
191 #endif
AT24C128(uint8_t addr=0)
Definition: AT24CXX.hh:163
AT24C512(uint8_t addr=0)
Definition: AT24CXX.hh:189
Definition: TWI.hh:51
AT24C64(uint8_t addr=0)
Definition: AT24CXX.hh:150
#define NULL
Definition: Types.h:101
Definition: EEPROM.hh:33
const size_t SIZE
Definition: AT24CXX.hh:53
const uint16_t PAGE_MAX
Definition: AT24CXX.hh:58
AT24C32(uint8_t addr=0)
Definition: AT24CXX.hh:137
virtual bool is_ready()
Definition: AT24CXX.cpp:47
#define CHARBITS
Definition: Types.h:57
AT24C256(uint8_t addr=0)
Definition: AT24CXX.hh:176
Driver(uint8_t addr)
Definition: TWI.hh:70
virtual int write(void *dest, const void *src, size_t size)
Definition: AT24CXX.cpp:66
AT24CXX(uint8_t subaddr=0, const size_t size=32, const uint16_t page_max=32)
Definition: AT24CXX.hh:67
virtual int read(void *dest, const void *src, size_t size)
Definition: AT24CXX.cpp:57