mirror of https://github.com/Desuuuu/klipper.git
uc1701: Use bus.py helper code for spi
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
5bb0bd755d
commit
1c71ea27e0
|
@ -5,7 +5,7 @@
|
|||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging
|
||||
import icons, font8x14
|
||||
import icons, font8x14, extras.bus
|
||||
|
||||
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
|
||||
|
||||
|
@ -15,42 +15,33 @@ class UC1701:
|
|||
CURRENT_BUF, OLD_BUF = 0, 1
|
||||
EMPTY_CHAR = (0, 32, 255)
|
||||
def __init__(self, config):
|
||||
printer = config.get_printer()
|
||||
# pin config
|
||||
ppins = printer.lookup_object('pins')
|
||||
pins = [ppins.lookup_pin(config.get(name + '_pin'))
|
||||
for name in ['cs','a0']]
|
||||
mcu = None
|
||||
for pin_params in pins:
|
||||
if mcu is not None and pin_params['chip'] != mcu:
|
||||
raise ppins.error("uc1701 all pins must be on same mcu")
|
||||
mcu = pin_params['chip']
|
||||
self.pins = [pin_params['pin'] for pin_params in pins]
|
||||
self.mcu = mcu
|
||||
self.spi_oid = self.mcu.create_oid()
|
||||
self.a0_oid = self.mcu.create_oid()
|
||||
self.mcu.register_config_callback(self.build_config)
|
||||
self.spi_xfer_cmd = self.set_pin_cmd = None
|
||||
self.spi = extras.bus.MCU_SPI_from_config(config, 0,
|
||||
default_speed=10000000)
|
||||
mcu = self.spi.get_mcu()
|
||||
# Create a0 pin
|
||||
ppins = config.get_printer().lookup_object('pins')
|
||||
a0_pin_params = ppins.lookup_pin(config.get('a0_pin'))
|
||||
if a0_pin_params['chip'] != mcu:
|
||||
raise ppins.error("uc1701 all pins must be on same mcu")
|
||||
self.a0_oid = mcu.create_oid()
|
||||
mcu.add_config_cmd("config_digital_out oid=%d pin=%s"
|
||||
" value=%d default_value=%d max_duration=%d" % (
|
||||
self.a0_oid, a0_pin_params['pin'], 0, 0, 0))
|
||||
mcu.register_config_callback(self.build_config)
|
||||
self.update_pin_cmd = None
|
||||
# framebuffers
|
||||
self.vram = ([bytearray(128) for i in range(8)],
|
||||
[bytearray('~'*128) for i in range(8)])
|
||||
def build_config(self):
|
||||
self.mcu.add_config_cmd(
|
||||
"config_spi oid=%d bus=%d pin=%s mode=%d rate=%d shutdown_msg=" % (
|
||||
self.spi_oid, 0, self.pins[0], 0, 10000000))
|
||||
self.mcu.add_config_cmd(
|
||||
"config_digital_out oid=%d pin=%s value=%d default_value=%d max_duration=%d" % (
|
||||
self.a0_oid, self.pins[1], 0, 0, 0))
|
||||
cmd_queue = self.mcu.alloc_command_queue()
|
||||
self.spi_send_cmd = self.mcu.lookup_command(
|
||||
"spi_send oid=%c data=%*s", cq=cmd_queue)
|
||||
self.update_pin_cmd = self.mcu.lookup_command(
|
||||
"update_digital_out oid=%c value=%c", cq=cmd_queue)
|
||||
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):
|
||||
if is_data:
|
||||
self.update_pin_cmd.send([self.a0_oid, 1], reqclock=BACKGROUND_PRIORITY_CLOCK)
|
||||
else:
|
||||
self.update_pin_cmd.send([self.a0_oid, 0], reqclock=BACKGROUND_PRIORITY_CLOCK)
|
||||
self.spi_send_cmd.send([self.spi_oid, cmds], reqclock=BACKGROUND_PRIORITY_CLOCK)
|
||||
self.spi.spi_send(cmds, reqclock=BACKGROUND_PRIORITY_CLOCK)
|
||||
def init(self):
|
||||
init_cmds = [0xE2, # System reset
|
||||
0x40, # Set display to start at line 0
|
||||
|
|
Loading…
Reference in New Issue