From d72516070644bbe7876ae002121913fc9e2b64ed Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 29 May 2018 20:59:17 -0400 Subject: mcp4451: Add initial support for programming the mcp4451 on lpc176x Add support for programming smoothieboard current. Signed-off-by: Kevin O'Connor --- klippy/extras/mcp4451.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 klippy/extras/mcp4451.py (limited to 'klippy/extras/mcp4451.py') diff --git a/klippy/extras/mcp4451.py b/klippy/extras/mcp4451.py new file mode 100644 index 00000000..a7eda9aa --- /dev/null +++ b/klippy/extras/mcp4451.py @@ -0,0 +1,32 @@ +# MCP4451 digipot code +# +# Copyright (C) 2018 Kevin O'Connor +# +# This file may be distributed under the terms of the GNU GPLv3 license. +import mcu + +WiperRegisters = [0x00, 0x01, 0x06, 0x07] + +class mcp4451: + def __init__(self, config): + printer = config.get_printer() + self.mcu = mcu.get_printer_mcu(printer, config.get('mcu', 'mcu')) + self.i2c_addr = config.getint('i2c_address') + scale = config.getfloat('scale', 1., above=0.) + wipers = [None]*4 + for i in range(len(wipers)): + val = config.getfloat('wiper_%d' % (i,), None, + minval=0., maxval=scale) + if val is not None: + wipers[i] = int(val * 255. / scale + .5) + 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) + +def load_config_prefix(config): + return mcp4451(config) -- cgit v1.2.3-70-g09d2