mirror of https://github.com/Desuuuu/klipper.git
ad5206: Use bus.py helper code for spi
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
be58c7f8ec
commit
ab6a8ec76e
|
@ -3,30 +3,20 @@
|
||||||
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
import bus
|
||||||
|
|
||||||
class ad5206:
|
class ad5206:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
ppins = config.get_printer().lookup_object('pins')
|
self.spi = bus.MCU_SPI_from_config(
|
||||||
enable_pin = config.get('enable_pin')
|
config, 0, pin_option="enable_pin", default_speed=25000000)
|
||||||
enable_pin_params = ppins.lookup_pin(enable_pin)
|
|
||||||
mcu = enable_pin_params['chip']
|
|
||||||
pin = enable_pin_params['pin']
|
|
||||||
scale = config.getfloat('scale', 1., above=0.)
|
scale = config.getfloat('scale', 1., above=0.)
|
||||||
channels = [None]*6
|
for i in range(6):
|
||||||
for i in range(len(channels)):
|
|
||||||
val = config.getfloat('channel_%d' % (i+1,), None,
|
val = config.getfloat('channel_%d' % (i+1,), None,
|
||||||
minval=0., maxval=scale)
|
minval=0., maxval=scale)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
channels[i] = int(val * 256. / scale + .5)
|
self.set_register(i, int(val * 256. / scale + .5))
|
||||||
oid = mcu.create_oid()
|
def set_register(self, reg, value):
|
||||||
mcu.add_config_cmd(
|
self.spi.spi_send([reg, value])
|
||||||
"config_spi oid=%d bus=%d pin=%s mode=%u rate=%u shutdown_msg=" % (
|
|
||||||
oid, 0, pin, 0, 25000000))
|
|
||||||
for i, val in enumerate(channels):
|
|
||||||
if val is not None:
|
|
||||||
mcu.add_config_cmd(
|
|
||||||
"spi_send oid=%d data=%02x%02x" % (oid, i, val),
|
|
||||||
is_init=True)
|
|
||||||
|
|
||||||
def load_config_prefix(config):
|
def load_config_prefix(config):
|
||||||
return ad5206(config)
|
return ad5206(config)
|
||||||
|
|
Loading…
Reference in New Issue