bus: Add MCU_bus_digital_out helper class
Add a helper class for tracking gpio outputs that are synchronized to bus updates on a particular command queue. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
9c40394248
commit
05bb5484b4
|
@ -197,3 +197,44 @@ def MCU_I2C_from_config(config, default_addr=None, default_speed=100000):
|
||||||
addr = config.getint('i2c_address', default_addr, minval=0, maxval=127)
|
addr = config.getint('i2c_address', default_addr, minval=0, maxval=127)
|
||||||
# Create MCU_I2C object
|
# Create MCU_I2C object
|
||||||
return MCU_I2C(i2c_mcu, bus, addr, speed)
|
return MCU_I2C(i2c_mcu, bus, addr, speed)
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Bus synchronized digital outputs
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
# Helper code for a gpio that updates on a cmd_queue
|
||||||
|
class MCU_bus_digital_out:
|
||||||
|
def __init__(self, mcu, pin_desc, cmd_queue=None, value=0):
|
||||||
|
self.mcu = mcu
|
||||||
|
self.oid = mcu.create_oid()
|
||||||
|
ppins = mcu.get_printer().lookup_object('pins')
|
||||||
|
pin_params = ppins.lookup_pin(pin_desc)
|
||||||
|
if pin_params['chip'] is not mcu:
|
||||||
|
raise ppins.error("Pin %s must be on mcu %s" % (
|
||||||
|
pin_desc, mcu.get_name()))
|
||||||
|
mcu.add_config_cmd("config_digital_out oid=%d pin=%s value=%d"
|
||||||
|
" default_value=%d max_duration=%d"
|
||||||
|
% (self.oid, pin_params['pin'], value, value, 0))
|
||||||
|
mcu.register_config_callback(self.build_config)
|
||||||
|
if cmd_queue is None:
|
||||||
|
cmd_queue = mcu.alloc_command_queue()
|
||||||
|
self.cmd_queue = cmd_queue
|
||||||
|
self.update_pin_cmd = None
|
||||||
|
def get_oid(self):
|
||||||
|
return self.oid
|
||||||
|
def get_mcu(self):
|
||||||
|
return self.mcu
|
||||||
|
def get_command_queue(self):
|
||||||
|
return self.cmd_queue
|
||||||
|
def build_config(self):
|
||||||
|
self.update_pin_cmd = self.mcu.lookup_command(
|
||||||
|
"update_digital_out oid=%c value=%c", cq=self.cmd_queue)
|
||||||
|
def update_digital_out(self, value, minclock=0, reqclock=0):
|
||||||
|
if self.update_pin_cmd is None:
|
||||||
|
# Send setup message via mcu initialization
|
||||||
|
self.mcu.add_config_cmd("update_digital_out oid=%c value=%c"
|
||||||
|
% (self.oid, not not value))
|
||||||
|
return
|
||||||
|
self.update_pin_cmd.send([self.oid, not not value],
|
||||||
|
minclock=minclock, reqclock=reqclock)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Support for UC1701 (and similar) 128x64 graphics LCD displays
|
# Support for UC1701 (and similar) 128x64 graphics LCD displays
|
||||||
#
|
#
|
||||||
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
|
||||||
# Copyright (C) 2018 Eric Callahan <arksine.code@gmail.com>
|
# Copyright (C) 2018 Eric Callahan <arksine.code@gmail.com>
|
||||||
# Copyright (C) 2019 Dmitry Budaev <condemil@gmail.com>
|
# Copyright (C) 2019 Dmitry Budaev <condemil@gmail.com>
|
||||||
#
|
#
|
||||||
|
@ -110,30 +110,12 @@ class SPI4wire:
|
||||||
def __init__(self, config, data_pin_name):
|
def __init__(self, config, data_pin_name):
|
||||||
self.spi = extras.bus.MCU_SPI_from_config(config, 0,
|
self.spi = extras.bus.MCU_SPI_from_config(config, 0,
|
||||||
default_speed=10000000)
|
default_speed=10000000)
|
||||||
mcu = self.spi.get_mcu()
|
dc_pin = config.get(data_pin_name)
|
||||||
# Create data/control pin
|
self.mcu_dc = extras.bus.MCU_bus_digital_out(
|
||||||
ppins = config.get_printer().lookup_object('pins')
|
self.spi.get_mcu(), dc_pin, self.spi.get_command_queue())
|
||||||
pin_params = ppins.lookup_pin(config.get(data_pin_name))
|
|
||||||
if pin_params['chip'] != mcu:
|
|
||||||
raise ppins.error("%s: all pins must be on same mcu" % (
|
|
||||||
config.get_name()))
|
|
||||||
self.dc_oid = mcu.create_oid()
|
|
||||||
mcu.add_config_cmd("config_digital_out oid=%d pin=%s"
|
|
||||||
" value=%d default_value=%d max_duration=%d" % (
|
|
||||||
self.dc_oid, pin_params['pin'], 0, 0, 0))
|
|
||||||
mcu.register_config_callback(self.build_config)
|
|
||||||
self.update_pin_cmd = None
|
|
||||||
def build_config(self):
|
|
||||||
self.update_pin_cmd = self.spi.get_mcu().lookup_command(
|
|
||||||
"update_digital_out oid=%c value=%c",
|
|
||||||
cq=self.spi.get_command_queue())
|
|
||||||
def send(self, cmds, is_data=False):
|
def send(self, cmds, is_data=False):
|
||||||
if is_data:
|
self.mcu_dc.update_digital_out(is_data,
|
||||||
self.update_pin_cmd.send([self.dc_oid, 1],
|
reqclock=BACKGROUND_PRIORITY_CLOCK)
|
||||||
reqclock=BACKGROUND_PRIORITY_CLOCK)
|
|
||||||
else:
|
|
||||||
self.update_pin_cmd.send([self.dc_oid, 0],
|
|
||||||
reqclock=BACKGROUND_PRIORITY_CLOCK)
|
|
||||||
self.spi.spi_send(cmds, reqclock=BACKGROUND_PRIORITY_CLOCK)
|
self.spi.spi_send(cmds, reqclock=BACKGROUND_PRIORITY_CLOCK)
|
||||||
|
|
||||||
# IO wrapper for i2c bus
|
# IO wrapper for i2c bus
|
||||||
|
|
Loading…
Reference in New Issue