From e26d1a356708b3702c91a86ff37f3c5c615941c9 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 27 Dec 2018 19:11:46 -0500 Subject: i2ccmds: Pass the i2c address as a 7-bit number (0-127) The sam3 i2c code and the linux code use a 7-bit i2c address, while the avr, lpc176x, and samd21 i2c code uses an 8-bit address with the least significant bit always zero. A similar issue occurred in the host code (sx1509.py and replicape.py use 7-bit addresses while uc1701.py and mcp4451.py use 8-bit addresses). Consistently use 7-bit addresses in all the code. This breaks compatibility between host and mcu software, so make a change to the config_i2c command to force users to synchronize software updates. This also breaks common Smoothieboard configs, so update the mcp4451 code to validate the i2c_address. Signed-off-by: Kevin O'Connor --- src/avr/i2c.c | 2 +- src/i2ccmds.c | 6 ++---- src/lpc176x/i2c.c | 2 +- src/samd21/i2c.c | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/avr/i2c.c b/src/avr/i2c.c index b4c0ad75..d068a2fa 100644 --- a/src/avr/i2c.c +++ b/src/avr/i2c.c @@ -45,7 +45,7 @@ i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr) if (bus) shutdown("Unsupported i2c bus"); i2c_init(); - return (struct i2c_config){ .addr=addr }; + return (struct i2c_config){ .addr=addr<<1 }; } static void diff --git a/src/i2ccmds.c b/src/i2ccmds.c index d880b46f..01f7b36f 100644 --- a/src/i2ccmds.c +++ b/src/i2ccmds.c @@ -16,15 +16,13 @@ struct i2cdev_s { void command_config_i2c(uint32_t *args) { - uint8_t addr = args[3]; - if (addr & 1) - shutdown("Invalid I2C address"); + uint8_t addr = args[3] & 0x7f; struct i2cdev_s *i2c = oid_alloc(args[0], command_config_i2c , sizeof(*i2c)); i2c->i2c_config = i2c_setup(args[1], args[2], addr); } DECL_COMMAND(command_config_i2c, - "config_i2c oid=%c bus=%u rate=%u addr=%u"); + "config_i2c oid=%c bus=%u rate=%u address=%u"); void command_i2c_write(uint32_t *args) diff --git a/src/lpc176x/i2c.c b/src/lpc176x/i2c.c index bc367ba7..420bef95 100644 --- a/src/lpc176x/i2c.c +++ b/src/lpc176x/i2c.c @@ -45,7 +45,7 @@ i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr) if (bus) shutdown("Unsupported i2c bus"); i2c_init(); - return (struct i2c_config){ .addr=addr }; + return (struct i2c_config){ .addr=addr<<1 }; } static void diff --git a/src/samd21/i2c.c b/src/samd21/i2c.c index 696cba8a..801c0e32 100644 --- a/src/samd21/i2c.c +++ b/src/samd21/i2c.c @@ -57,7 +57,7 @@ i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr) if (bus) shutdown("Unsupported i2c bus"); i2c_init(); - return (struct i2c_config){ .addr=addr }; + return (struct i2c_config){ .addr=addr<<1 }; } static void -- cgit v1.2.3-70-g09d2