46 const size_t size = 32,
47 const uint16_t page_max = 32) :
49 TWI::Device(twi, 0x50 | (subaddr & 0x07)),
64 if (!acquire())
return (
false);
65 int res =
write(NULL);
66 if (!release())
return (
false);
79 virtual int read(
void* dst, uint32_t src,
size_t count)
82 uint16_t addr = __builtin_bswap16(src);
84 if (!acquire())
return (-1);
85 int res =
write(&addr,
sizeof(addr));
86 if (res ==
sizeof(addr)) {
87 res =
read(dst, count);
88 if (!release())
break;
89 if (res == (
int) count)
return (res);
91 if (!release())
return (-1);
106 virtual int write(uint32_t dst,
const void* src,
size_t count)
108 uint8_t* p = (uint8_t*) src;
114 uint16_t addr = __builtin_bswap16(dst);
118 iovec_arg(vp, &addr,
sizeof(addr));
122 if (!acquire())
continue;
124 if (!release())
continue;
128 if (res < 0)
return (-1);
130 if (s == 0)
return (count);
147 using TWI::Device::read;
148 using TWI::Device::write;
222 AT24CXX(twi, subaddr, 512, 128)
AT24C32(TWI &twi, uint8_t subaddr=0)
Software::TWI< BOARD::D18, BOARD::D19 > twi
AT24CXX(TWI &twi, uint8_t subaddr=0, const size_t size=32, const uint16_t page_max=32)
AT24C128(TWI &twi, uint8_t subaddr=0)
AT24C512(TWI &twi, uint8_t subaddr=0)
virtual int read(void *dst, uint32_t src, size_t count)
static const uint8_t RETRY_MAX
virtual int write(uint32_t dst, const void *src, size_t count)
static const uint8_t RETRY_DELAY_MS
AT24C256(TWI &twi, uint8_t subaddr=0)
AT24C64(TWI &twi, uint8_t subaddr=0)