mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-16 11:17:52 -06:00
chipmisc: Add support for configuring ad5206 digipots
Support an "ad5206" config section so that one can configure the digipots found on Reprap "RAMBo" boards. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
9d75c3b0ca
commit
931811ab59
4 changed files with 80 additions and 14 deletions
|
@ -32,6 +32,31 @@ class PrinterStaticPWM:
|
|||
mcu_pwm.setup_static_pwm(value / scale)
|
||||
|
||||
|
||||
######################################################################
|
||||
# AD5206 digipot
|
||||
######################################################################
|
||||
|
||||
class ad5206:
|
||||
def __init__(self, printer, config):
|
||||
enable_pin_params = pins.get_printer_pins(printer).parse_pin_desc(
|
||||
config.get('enable_pin'))
|
||||
self.mcu = enable_pin_params['chip']
|
||||
self.pin = enable_pin_params['pin']
|
||||
self.mcu.add_config_object(self)
|
||||
scale = config.getfloat('scale', 1., above=0.)
|
||||
self.channels = [None] * 6
|
||||
for i in range(len(self.channels)):
|
||||
val = config.getfloat('channel_%d' % (i+1,), None,
|
||||
minval=0., maxval=scale)
|
||||
if val is not None:
|
||||
self.channels[i] = int(val * 256. / scale + .5)
|
||||
def build_config(self):
|
||||
for i, val in enumerate(self.channels):
|
||||
if val is not None:
|
||||
self.mcu.add_config_cmd(
|
||||
"send_spi_message pin=%s msg=%02x%02x" % (self.pin, i, val))
|
||||
|
||||
|
||||
######################################################################
|
||||
# Setup
|
||||
######################################################################
|
||||
|
@ -41,3 +66,5 @@ def add_printer_objects(printer, config):
|
|||
printer.add_object(s.section, PrinterStaticDigitalOut(printer, s))
|
||||
for s in config.get_prefix_sections('static_pwm_output '):
|
||||
printer.add_object(s.section, PrinterStaticPWM(printer, s))
|
||||
for s in config.get_prefix_sections('ad5206 '):
|
||||
printer.add_object(s.section, ad5206(printer, s))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue