From e3b2c7bf7d7a4cc7dc2cafc28f35e30f44260a21 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 12 Dec 2020 12:32:01 +0000 Subject: [PATCH] boards: simulator: Improve spi.write() simulation Signed-off-by: Daniel Thompson --- wasp/boards/simulator/display.py | 5 +++++ wasp/drivers/st7789.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wasp/boards/simulator/display.py b/wasp/boards/simulator/display.py index 8efbb9c..379760c 100644 --- a/wasp/boards/simulator/display.py +++ b/wasp/boards/simulator/display.py @@ -37,6 +37,11 @@ class ST7789Sim(object): self.cmd = 0 def write(self, data): + # Converting data to a memoryview ensures we act more like spi.write() + # when running in a real device (e.g. data must be bytes-like object + # that implements the buffer protocol) + data = memoryview(data) + if len(data) == 1: # Assume if we get a byte at a time then it is command. # This is a simplification do we don't have to track diff --git a/wasp/drivers/st7789.py b/wasp/drivers/st7789.py index 013ee1b..be4b109 100644 --- a/wasp/drivers/st7789.py +++ b/wasp/drivers/st7789.py @@ -181,8 +181,8 @@ class ST7789_SPI(ST7789): Send data to the display as part of an optimized write sequence. - :param bytearray buf: Data, must be in a form that can be directly - consumed by the SPI bus. + :param bytes-like buf: Data, must be in a form that can be directly + consumed by the SPI bus. """ def __init__(self, width, height, spi, cs, dc, res=None, rate=8000000): """Configure the display.