Fix M261, i2c EEPROM, i2c Encoder for LPC (#17678)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
randellhodges 2020-04-25 11:35:35 -05:00 committed by GitHub
parent 307c48fe0a
commit b700b3cde6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 15 deletions

View File

@ -39,7 +39,7 @@
// Private Variables
// ------------------------
static uint8_t eeprom_device_address = 0x50;
static constexpr uint8_t eeprom_device_address = I2C_ADDRESS(0x50);
// ------------------------
// Public functions
@ -54,7 +54,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
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 & 0xFF)); // LSB
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) {
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 & 0xFF)); // LSB
Wire.endTransmission();
@ -82,7 +82,7 @@ void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
flag |= Wire.read() ^ ptr[c];
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 & 0xFF)); // LSB
Wire.write((uint8_t*)pos, n);
@ -99,7 +99,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
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 & 0xFF)); // LSB
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) {
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 & 0xFF)); // LSB
Wire.endTransmission();

View File

@ -292,11 +292,7 @@
#define FMOD(x, y) fmodf(x, y)
#define HYPOT(x,y) SQRT(HYPOT2(x,y))
#ifdef TARGET_LPC1768
#define I2C_ADDRESS(A) ((A) << 1)
#else
#define I2C_ADDRESS(A) A
#endif
#define I2C_ADDRESS(A) (TERN(TARGET_LPC1768, (A) << 1, A))
// 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

View File

@ -305,7 +305,7 @@ int32_t I2CPositionEncoder::get_raw_count() {
encoderCount.val = 0x00;
if (Wire.requestFrom((int)i2cAddress, 3) != 3) {
if (Wire.requestFrom(I2C_ADDRESS(i2cAddress), 3) != 3) {
//houston, we have a problem...
H = I2CPE_MAG_SIG_NF;
return 0;
@ -744,7 +744,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
Wire.endTransmission();
// Read value
if (Wire.requestFrom((int)address, 32)) {
if (Wire.requestFrom(I2C_ADDRESS(address), 32)) {
char c;
while (Wire.available() > 0 && (c = (char)Wire.read()) > 0)
SERIAL_ECHO(c);

View File

@ -104,8 +104,8 @@ bool TWIBus::request(const uint8_t bytes) {
debug(PSTR("request"), bytes);
// requestFrom() is a blocking function
if (Wire.requestFrom(addr, bytes) == 0) {
debug("request fail", addr);
if (Wire.requestFrom(I2C_ADDRESS(addr), bytes) == 0) {
debug("request fail", I2C_ADDRESS(addr));
return false;
}