diff --git a/klippy/extras/mcp4018.py b/klippy/extras/mcp4018.py index f53024b9..fd04aa66 100644 --- a/klippy/extras/mcp4018.py +++ b/klippy/extras/mcp4018.py @@ -31,18 +31,20 @@ class SoftwareI2C: self.mcu.add_config_cmd("config_digital_out oid=%d pin=%s" " value=%d default_value=%d max_duration=%d" % ( self.sda_oid, sda_params['pin'], 1, 1, 0)) + def get_mcu(self): + return self.mcu def build_config(self): self.mcu.add_config_cmd("config_digital_out oid=%d pin=%s value=%d" " default_value=%d max_duration=%d" % ( self.scl_oid, self.scl_pin, 1, 1, 0)) self.update_pin_cmd = self.mcu.lookup_command( "update_digital_out oid=%c value=%c", cq=self.cmd_queue) - def i2c_write(self, msg): + def i2c_write(self, msg, minclock=0, reqclock=0): msg = [self.addr] + msg send = self.scl_main.update_pin_cmd.send # Send ack - send([self.sda_oid, 0]) - send([self.scl_oid, 0]) + send([self.sda_oid, 0], minclock=minclock, reqclock=reqclock) + send([self.scl_oid, 0], minclock=minclock, reqclock=reqclock) # Send bytes sda_last = 0 for data in msg: @@ -51,17 +53,18 @@ class SoftwareI2C: sda_next = not not (data & (0x80 >> i)) if sda_last != sda_next: sda_last = sda_next - send([self.sda_oid, sda_last]) - send([self.scl_oid, 1]) - send([self.scl_oid, 0]) + send([self.sda_oid, sda_last], + minclock=minclock, reqclock=reqclock) + send([self.scl_oid, 1], minclock=minclock, reqclock=reqclock) + send([self.scl_oid, 0], minclock=minclock, reqclock=reqclock) # Transmit clock for ack - send([self.scl_oid, 1]) - send([self.scl_oid, 0]) + send([self.scl_oid, 1], minclock=minclock, reqclock=reqclock) + send([self.scl_oid, 0], minclock=minclock, reqclock=reqclock) # Send stop if sda_last: - send([self.sda_oid, 0]) - send([self.scl_oid, 1]) - send([self.sda_oid, 1]) + send([self.sda_oid, 0], minclock=minclock, reqclock=reqclock) + send([self.scl_oid, 1], minclock=minclock, reqclock=reqclock) + send([self.sda_oid, 1], minclock=minclock, reqclock=reqclock) class mcp4018: def __init__(self, config):