boards: simulator: Add basic mute simulation

Currently the simulator shows redraw artifacts that are concealed
on the real device by using display on/off. We can improve this by
avoiding the refresh when the display is off. This does not match
the behaviour of the real hardware (which goes dark during transitions)
but does make the simulator feel much more comfortable to use.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2021-01-10 10:43:50 +00:00
parent 637f5d6e8a
commit 61c56598de

View file

@ -13,6 +13,8 @@ import numpy as np
from PIL import Image from PIL import Image
import wasp import wasp
DISPOFF = 0x28
DISPON = 0x29
CASET = 0x2a CASET = 0x2a
RASET = 0x2b RASET = 0x2b
RAMWR = 0x2c RAMWR = 0x2c
@ -35,6 +37,7 @@ class ST7789Sim(object):
self.colclip = [0, WIDTH-1] self.colclip = [0, WIDTH-1]
self.rowclip = [0, HEIGHT-1] self.rowclip = [0, HEIGHT-1]
self.cmd = 0 self.cmd = 0
self.mute = False
def write(self, data): def write(self, data):
# Converting data to a memoryview ensures we act more like spi.write() # Converting data to a memoryview ensures we act more like spi.write()
@ -46,7 +49,14 @@ class ST7789Sim(object):
# Assume if we get a byte at a time then it is command. # Assume if we get a byte at a time then it is command.
# This is a simplification do we don't have to track # This is a simplification do we don't have to track
# the D/C pin from within the simulator. # the D/C pin from within the simulator.
self.cmd = data[0] cmd = data[0]
if cmd == DISPOFF:
self.mute = True
elif cmd == DISPON:
self.mute = False
window.refresh()
else:
self.cmd = data[0]
elif self.cmd == CASET: elif self.cmd == CASET:
self.colclip[0] = (data[0] << 8) + data[1] self.colclip[0] = (data[0] << 8) + data[1]
@ -91,7 +101,8 @@ class ST7789Sim(object):
# Forcibly release the surface to ensure it is unlocked # Forcibly release the surface to ensure it is unlocked
del pixelview del pixelview
window.refresh() if not self.mute:
window.refresh()
class CST816SSim(): class CST816SSim():
def __init__(self): def __init__(self):
@ -268,4 +279,3 @@ def tick(pins):
else: else:
#print(event) #print(event)
pass pass
window.refresh()