aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/bus.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-12-27 19:11:46 -0500
committerKevinOConnor <kevin@koconnor.net>2019-01-07 20:00:44 -0500
commite26d1a356708b3702c91a86ff37f3c5c615941c9 (patch)
tree89cbc00e3af6fe731c863da4a30b487b56a8badd /klippy/extras/bus.py
parentf2f54290e84903679bdb9548924f933a6efe311d (diff)
downloadkutter-e26d1a356708b3702c91a86ff37f3c5c615941c9.tar.gz
kutter-e26d1a356708b3702c91a86ff37f3c5c615941c9.tar.xz
kutter-e26d1a356708b3702c91a86ff37f3c5c615941c9.zip
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 <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/bus.py')
-rw-r--r--klippy/extras/bus.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py
index 6df95ee5..2808d6fe 100644
--- a/klippy/extras/bus.py
+++ b/klippy/extras/bus.py
@@ -83,9 +83,11 @@ def MCU_SPI_from_config(config, mode, pin_option="cs_pin",
class MCU_I2C:
def __init__(self, mcu, bus, addr, speed):
self.mcu = mcu
+ self.i2c_address = addr
self.oid = self.mcu.create_oid()
- self.mcu.add_config_cmd("config_i2c oid=%d bus=%d rate=%d addr=%d" % (
- self.oid, bus, speed, addr))
+ self.mcu.add_config_cmd(
+ "config_i2c oid=%d bus=%d rate=%d address=%d" % (
+ self.oid, bus, speed, addr))
self.cmd_queue = self.mcu.alloc_command_queue()
self.mcu.register_config_callback(self.build_config)
self.i2c_write_cmd = self.i2c_read_cmd = self.i2c_modify_bits_cmd = None
@@ -93,6 +95,8 @@ class MCU_I2C:
return self.oid
def get_mcu(self):
return self.mcu
+ def get_i2c_address(self):
+ return self.i2c_address
def get_command_queue(self):
return self.cmd_queue
def build_config(self):
@@ -136,8 +140,8 @@ def MCU_I2C_from_config(config, default_addr=None, default_speed=100000):
speed = config.getint('i2c_speed', default_speed, minval=100000)
bus = config.getint('i2c_bus', 0, minval=0)
if default_addr is None:
- addr = config.getint('i2c_address')
+ addr = config.getint('i2c_address', minval=0, maxval=127)
else:
- addr = config.getint('i2c_address', default_addr)
+ addr = config.getint('i2c_address', default_addr, minval=0, maxval=127)
# Create MCU_I2C object
return MCU_I2C(i2c_mcu, bus, addr, speed)