-
Notifications
You must be signed in to change notification settings - Fork 0
/
eepromi2c.h
32 lines (28 loc) · 1.01 KB
/
eepromi2c.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
#include <Arduino.h>
#include <I2C_DMAC.h>
#define DEVICE 0x50 //this is the device ID from the datasheet of the 24LC256
//in the normal write anything the eeaddress is incrimented after the writing of each byte. The Wire library does this behind the scenes.
template <class T> int eeWrite(int ee, const T& value)
{
uint8_t* p = (uint8_t*)(void*)&value;
I2C.writeBytes(DEVICE, ee, p, sizeof(value));
// unsigned int i;
//
// Wire.beginTransmission(DEVICE);
// Wire.write((int)(ee >> 8)); // MSB
// Wire.write((int)(ee & 0xFF)); // LSB
// for (i = 0; i < sizeof(value); i++)
// Wire.write(*p++);
// Wire.endTransmission();
// return i;
return sizeof(value);//to not break original eepromi2c
}
template <class T> int eeRead(int ee, T& value)
{
uint8_t* p = (uint8_t*)(void*)&value;
I2C.initWriteRegAddr(DEVICE, ee); // Set-up DMAC to write to MPU6050 register pointer
I2C.write();
I2C.initReadBytes(DEVICE, p, sizeof(value));
I2C.read();
return sizeof(value);//to not break original eepromi2c
}