2018-01-20 06:14:52 +01:00
|
|
|
# AD5206 digipot code
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
2018-11-18 23:35:30 +01:00
|
|
|
import bus
|
2018-01-20 06:14:52 +01:00
|
|
|
|
|
|
|
class ad5206:
|
|
|
|
def __init__(self, config):
|
2018-11-18 23:35:30 +01:00
|
|
|
self.spi = bus.MCU_SPI_from_config(
|
|
|
|
config, 0, pin_option="enable_pin", default_speed=25000000)
|
2018-01-20 06:14:52 +01:00
|
|
|
scale = config.getfloat('scale', 1., above=0.)
|
2018-11-18 23:35:30 +01:00
|
|
|
for i in range(6):
|
2018-01-20 06:14:52 +01:00
|
|
|
val = config.getfloat('channel_%d' % (i+1,), None,
|
|
|
|
minval=0., maxval=scale)
|
|
|
|
if val is not None:
|
2018-11-18 23:35:30 +01:00
|
|
|
self.set_register(i, int(val * 256. / scale + .5))
|
|
|
|
def set_register(self, reg, value):
|
|
|
|
self.spi.spi_send([reg, value])
|
2018-01-20 06:14:52 +01:00
|
|
|
|
2018-02-03 18:53:11 +01:00
|
|
|
def load_config_prefix(config):
|
2018-01-20 06:14:52 +01:00
|
|
|
return ad5206(config)
|