diff options
author | Lorenzo <lorenzo.franco94@gmail.com> | 2022-02-22 16:28:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-22 10:28:28 -0500 |
commit | 7c964e5fdf99c22c2f2d543a205d97ac6c3366bd (patch) | |
tree | ee7280433e444a502dda3cd8d9973a44a0f2e277 /klippy/extras/dac084S085.py | |
parent | b0a24a4458beca81e4a97a9cf505ca9d42251e8a (diff) | |
download | kutter-7c964e5fdf99c22c2f2d543a205d97ac6c3366bd.tar.gz kutter-7c964e5fdf99c22c2f2d543a205d97ac6c3366bd.tar.xz kutter-7c964e5fdf99c22c2f2d543a205d97ac6c3366bd.zip |
dac084S085: SPI DAC DAC084S085 implementation (#5134)
Alligator Board Rev2 tested config sample.
Add example configuration file for Alligator board rev.3.
Signed-off-by: Lorenzo Franco <lorenzo.franco@lorenzing.com>
Diffstat (limited to 'klippy/extras/dac084S085.py')
-rw-r--r-- | klippy/extras/dac084S085.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/klippy/extras/dac084S085.py b/klippy/extras/dac084S085.py new file mode 100644 index 00000000..bc015dd4 --- /dev/null +++ b/klippy/extras/dac084S085.py @@ -0,0 +1,25 @@ +# SPI DAC DAC084S085 implementation +# +# Copyright (C) 2021 Lorenzo Franco <lorenzo.franco@lorenzing.com> +# +# This file may be distributed under the terms of the GNU GPLv3 license. + +from . import bus + +class dac084S085: + def __init__(self, config): + self.spi = bus.MCU_SPI_from_config( + config, 1, pin_option="enable_pin", default_speed=10000000) + scale = config.getfloat('scale', 1., above=0.) + for chan, name in enumerate("ABCD"): + val = config.getfloat('channel_%s' % (name,), None, + minval=0., maxval=scale) + if val is not None: + self.set_register(chan, int(val * 255. / scale)) + def set_register(self, chan, value): + b1 = (chan << 6) | (1 << 4) | ((value >> 4) & 0x0f) + b2 = (value << 4) & 0xf0 + self.spi.spi_send([b1, b2]) + +def load_config_prefix(config): + return dac084S085(config) |