Fix M261, i2c EEPROM, i2c Encoder for LPC (#17678)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
parent
307c48fe0a
commit
b700b3cde6
4 changed files with 11 additions and 15 deletions
|
@ -39,7 +39,7 @@
|
||||||
// Private Variables
|
// Private Variables
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
||||||
static uint8_t eeprom_device_address = 0x50;
|
static constexpr uint8_t eeprom_device_address = I2C_ADDRESS(0x50);
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Public functions
|
// Public functions
|
||||||
|
@ -54,7 +54,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
|
||||||
|
|
||||||
eeprom_init();
|
eeprom_init();
|
||||||
|
|
||||||
Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
|
Wire.beginTransmission(eeprom_device_address);
|
||||||
Wire.write((int)(eeprom_address >> 8)); // MSB
|
Wire.write((int)(eeprom_address >> 8)); // MSB
|
||||||
Wire.write((int)(eeprom_address & 0xFF)); // LSB
|
Wire.write((int)(eeprom_address & 0xFF)); // LSB
|
||||||
Wire.write(value);
|
Wire.write(value);
|
||||||
|
@ -70,7 +70,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
|
||||||
void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
|
void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
|
||||||
eeprom_init();
|
eeprom_init();
|
||||||
|
|
||||||
Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
|
Wire.beginTransmission(eeprom_device_address);
|
||||||
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
|
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
|
||||||
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
|
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
@ -82,7 +82,7 @@ void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
|
||||||
flag |= Wire.read() ^ ptr[c];
|
flag |= Wire.read() ^ ptr[c];
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
|
Wire.beginTransmission(eeprom_device_address);
|
||||||
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
|
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
|
||||||
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
|
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
|
||||||
Wire.write((uint8_t*)pos, n);
|
Wire.write((uint8_t*)pos, n);
|
||||||
|
@ -99,7 +99,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
|
||||||
|
|
||||||
eeprom_init();
|
eeprom_init();
|
||||||
|
|
||||||
Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
|
Wire.beginTransmission(eeprom_device_address);
|
||||||
Wire.write((int)(eeprom_address >> 8)); // MSB
|
Wire.write((int)(eeprom_address >> 8)); // MSB
|
||||||
Wire.write((int)(eeprom_address & 0xFF)); // LSB
|
Wire.write((int)(eeprom_address & 0xFF)); // LSB
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
@ -111,7 +111,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
|
||||||
void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
|
void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
|
||||||
eeprom_init();
|
eeprom_init();
|
||||||
|
|
||||||
Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
|
Wire.beginTransmission(eeprom_device_address);
|
||||||
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
|
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
|
||||||
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
|
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
|
|
@ -292,11 +292,7 @@
|
||||||
#define FMOD(x, y) fmodf(x, y)
|
#define FMOD(x, y) fmodf(x, y)
|
||||||
#define HYPOT(x,y) SQRT(HYPOT2(x,y))
|
#define HYPOT(x,y) SQRT(HYPOT2(x,y))
|
||||||
|
|
||||||
#ifdef TARGET_LPC1768
|
#define I2C_ADDRESS(A) (TERN(TARGET_LPC1768, (A) << 1, A))
|
||||||
#define I2C_ADDRESS(A) ((A) << 1)
|
|
||||||
#else
|
|
||||||
#define I2C_ADDRESS(A) A
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
|
// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
|
||||||
#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
|
#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
|
||||||
|
|
|
@ -305,7 +305,7 @@ int32_t I2CPositionEncoder::get_raw_count() {
|
||||||
|
|
||||||
encoderCount.val = 0x00;
|
encoderCount.val = 0x00;
|
||||||
|
|
||||||
if (Wire.requestFrom((int)i2cAddress, 3) != 3) {
|
if (Wire.requestFrom(I2C_ADDRESS(i2cAddress), 3) != 3) {
|
||||||
//houston, we have a problem...
|
//houston, we have a problem...
|
||||||
H = I2CPE_MAG_SIG_NF;
|
H = I2CPE_MAG_SIG_NF;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -744,7 +744,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
|
||||||
// Read value
|
// Read value
|
||||||
if (Wire.requestFrom((int)address, 32)) {
|
if (Wire.requestFrom(I2C_ADDRESS(address), 32)) {
|
||||||
char c;
|
char c;
|
||||||
while (Wire.available() > 0 && (c = (char)Wire.read()) > 0)
|
while (Wire.available() > 0 && (c = (char)Wire.read()) > 0)
|
||||||
SERIAL_ECHO(c);
|
SERIAL_ECHO(c);
|
||||||
|
|
|
@ -104,8 +104,8 @@ bool TWIBus::request(const uint8_t bytes) {
|
||||||
debug(PSTR("request"), bytes);
|
debug(PSTR("request"), bytes);
|
||||||
|
|
||||||
// requestFrom() is a blocking function
|
// requestFrom() is a blocking function
|
||||||
if (Wire.requestFrom(addr, bytes) == 0) {
|
if (Wire.requestFrom(I2C_ADDRESS(addr), bytes) == 0) {
|
||||||
debug("request fail", addr);
|
debug("request fail", I2C_ADDRESS(addr));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue