aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-11-24 19:46:28 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-01-02 18:17:56 -0500
commitc2086796bf1ccd755e6bd3d47168031c67bf0780 (patch)
tree1ec9a2e71f15c746e86716bceafba5061703ce44 /klippy/extras
parent0da064ccd94efec0966bf1569b6487ece74c9569 (diff)
downloadkutter-c2086796bf1ccd755e6bd3d47168031c67bf0780.tar.gz
kutter-c2086796bf1ccd755e6bd3d47168031c67bf0780.tar.xz
kutter-c2086796bf1ccd755e6bd3d47168031c67bf0780.zip
mcp4728: Add initial support for the mcp4728 i2c dac chip
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras')
-rw-r--r--klippy/extras/mcp4728.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/klippy/extras/mcp4728.py b/klippy/extras/mcp4728.py
new file mode 100644
index 00000000..6f2eeb29
--- /dev/null
+++ b/klippy/extras/mcp4728.py
@@ -0,0 +1,23 @@
+# MCP4728 dac code
+#
+# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+import bus
+
+class mcp4728:
+ def __init__(self, config):
+ self.i2c = bus.MCU_I2C_from_config(config, default_addr=0)
+ scale = config.getfloat('scale', 1., above=0.)
+ # Configure registers
+ for i, name in enumerate('abcd'):
+ val = config.getfloat('channel_%s' % (name,), None,
+ minval=0., maxval=scale)
+ if val is not None:
+ self.set_dac(i, int(val * 4095. / scale + .5))
+ def set_dac(self, dac, value):
+ self.i2c.i2c_write([0x40 | (dac << 1),
+ (value >> 8) & 0x0f, value & 0xff])
+
+def load_config_prefix(config):
+ return mcp4728(config)