diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-11-14 10:23:56 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-11-14 10:23:56 -0500 |
commit | f3c4deb1abedc38ff91d9c77e0b7e086d2246329 (patch) | |
tree | 730b606678bd6066d66561bf0a46d7e2509e08b7 /klippy/extras/mcp4451.py | |
parent | f973886dacdbd516845d48fc5a434f113c16e84b (diff) | |
download | kutter-f3c4deb1abedc38ff91d9c77e0b7e086d2246329.tar.gz kutter-f3c4deb1abedc38ff91d9c77e0b7e086d2246329.tar.xz kutter-f3c4deb1abedc38ff91d9c77e0b7e086d2246329.zip |
lpc176x: Convert i2c code to use standard i2ccmds.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/mcp4451.py')
-rw-r--r-- | klippy/extras/mcp4451.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/klippy/extras/mcp4451.py b/klippy/extras/mcp4451.py index a7eda9aa..9a79671b 100644 --- a/klippy/extras/mcp4451.py +++ b/klippy/extras/mcp4451.py @@ -10,8 +10,9 @@ WiperRegisters = [0x00, 0x01, 0x06, 0x07] class mcp4451: def __init__(self, config): printer = config.get_printer() + # Read config parameters self.mcu = mcu.get_printer_mcu(printer, config.get('mcu', 'mcu')) - self.i2c_addr = config.getint('i2c_address') + i2c_addr = config.getint('i2c_address') scale = config.getfloat('scale', 1., above=0.) wipers = [None]*4 for i in range(len(wipers)): @@ -19,14 +20,20 @@ class mcp4451: minval=0., maxval=scale) if val is not None: wipers[i] = int(val * 255. / scale + .5) + # Setup i2c + self.oid = self.mcu.create_oid() + self.mcu.add_config_cmd( + "config_i2c oid=%d bus=0 rate=100000 addr=%d" % ( + self.oid, i2c_addr)) + # Configure registers self.add_config_cmd(0x04, 0xff) self.add_config_cmd(0x0a, 0xff) for reg, val in zip(WiperRegisters, wipers): if val is not None: self.add_config_cmd(reg, val) def add_config_cmd(self, reg, val): - self.mcu.add_config_cmd("i2c_send data=%02x%02x%02x" % ( - self.i2c_addr, (reg << 4) | ((val >> 8) & 0x03), val), is_init=True) + self.mcu.add_config_cmd("i2c_write oid=%d data=%02x%02x" % ( + self.oid, (reg << 4) | ((val >> 8) & 0x03), val), is_init=True) def load_config_prefix(config): return mcp4451(config) |