1 #ifndef LIBPROPELLER_EEPROM_H_
2 #define LIBPROPELLER_EEPROM_H_
4 #include "libpropeller/i2c/i2c_base.h"
29 void Init(
const int scl = 28,
const int sda = 29) {
39 bool Put(
const unsigned short address,
const char byte) {
40 char bytes[] = {
byte};
41 return Put(address, bytes, 1);
53 bool Put(
unsigned short address,
char bytes [],
int size) {
58 while (bytesWritten < size) {
59 if (PollForAcknowledge() ==
false) {
62 base_.
SendByte((address >> 8) & 0xFF);
68 }
while ((address & 0b1111111) != 0 && bytesWritten < size);
85 bool PutNumber(
const unsigned short address,
const int bytes,
const int length) {
89 temp[3] = (((unsigned) bytes) & 0xFF000000) >> 24;
90 temp[2] = (((unsigned) bytes) & 0xFF0000) >> 16;
91 temp[1] = (((unsigned) bytes) & 0xFF00) >> 8;
92 temp[0] = (((unsigned) bytes) & 0xFF) >> 0;
93 return Put(address, temp, length);
101 int Get(
unsigned short address) {
103 int result =
Get(address,
byte, 1);
120 int Get(
unsigned short address,
char bytes [],
const int length) {
122 while (bytesRead < length) {
123 if (PollForAcknowledge() ==
false) {
126 base_.
SendByte((address >> 8) & 0xFF);
132 while (((address + 1) & 0b1111111) != 0
133 && bytesRead + 1 < length) {
134 bytes[bytesRead] = base_.
ReadByte(
true);
139 bytes[bytesRead] = base_.
ReadByte(
false);
160 Get(address, temp, length);
171 result = (result << 8) | temp[3];
174 result = (result << 8) | temp[2];
177 result = (result << 8) | temp[1];
180 result = (result << 8) | temp[0];
188 bool PollForAcknowledge() {
191 while (base_.
SendByte(kI2CAddress) ==
false) {
192 if (++counter == 100) {
202 static const unsigned char kI2CAddress = 0b10100000;
208 #endif // LIBPROPELLER_EEPROM_H_