diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-08-17 21:46:45 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-08-17 22:14:02 -0400 |
commit | 05bb5484b43cd7e5b1f9ee235eacfec7c1f1d928 (patch) | |
tree | 770e51cc99ccc6d759ebf89dd5c914621100ddf8 /klippy/extras/bus.py | |
parent | 9c40394248259e13bc3b498e2ea849ea53c622f1 (diff) | |
download | kutter-05bb5484b43cd7e5b1f9ee235eacfec7c1f1d928.tar.gz kutter-05bb5484b43cd7e5b1f9ee235eacfec7c1f1d928.tar.xz kutter-05bb5484b43cd7e5b1f9ee235eacfec7c1f1d928.zip |
bus: Add MCU_bus_digital_out helper class
Add a helper class for tracking gpio outputs that are synchronized to
bus updates on a particular command queue.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/bus.py')
-rw-r--r-- | klippy/extras/bus.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py index d7e2be51..04795a88 100644 --- a/klippy/extras/bus.py +++ b/klippy/extras/bus.py @@ -197,3 +197,44 @@ def MCU_I2C_from_config(config, default_addr=None, default_speed=100000): addr = config.getint('i2c_address', default_addr, minval=0, maxval=127) # Create MCU_I2C object return MCU_I2C(i2c_mcu, bus, addr, speed) + + +###################################################################### +# Bus synchronized digital outputs +###################################################################### + +# Helper code for a gpio that updates on a cmd_queue +class MCU_bus_digital_out: + def __init__(self, mcu, pin_desc, cmd_queue=None, value=0): + self.mcu = mcu + self.oid = mcu.create_oid() + ppins = mcu.get_printer().lookup_object('pins') + pin_params = ppins.lookup_pin(pin_desc) + if pin_params['chip'] is not mcu: + raise ppins.error("Pin %s must be on mcu %s" % ( + pin_desc, mcu.get_name())) + mcu.add_config_cmd("config_digital_out oid=%d pin=%s value=%d" + " default_value=%d max_duration=%d" + % (self.oid, pin_params['pin'], value, value, 0)) + mcu.register_config_callback(self.build_config) + if cmd_queue is None: + cmd_queue = mcu.alloc_command_queue() + self.cmd_queue = cmd_queue + self.update_pin_cmd = None + def get_oid(self): + return self.oid + def get_mcu(self): + return self.mcu + def get_command_queue(self): + return self.cmd_queue + def build_config(self): + self.update_pin_cmd = self.mcu.lookup_command( + "update_digital_out oid=%c value=%c", cq=self.cmd_queue) + def update_digital_out(self, value, minclock=0, reqclock=0): + if self.update_pin_cmd is None: + # Send setup message via mcu initialization + self.mcu.add_config_cmd("update_digital_out oid=%c value=%c" + % (self.oid, not not value)) + return + self.update_pin_cmd.send([self.oid, not not value], + minclock=minclock, reqclock=reqclock) |