1
0
Fork 0

wasp: simulator: First steps towards a simulator

Currently this just traces SPI activity from the ST7789 driver but its
a good baseline to start building up test functions from.
pull/5/head
Daniel Thompson 2020-01-31 19:36:55 +00:00
parent e36caf5997
commit 262d93c76c
5 changed files with 92 additions and 0 deletions

View File

@ -53,5 +53,10 @@ debug:
-ex "attach 1" \
-ex "load"
sim:
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=$(PWD)/wasp/boards/simulator:$(PWD)/wasp \
python3 -i wasp/boot.py
.PHONY: bootloader micropython

View File

@ -0,0 +1,54 @@
class Tracer(object):
def __init__(self, *args, **kwargs):
print(f'{self.__class__.__name__}.__init__{args} {kwargs}')
def __getattr__(self, name):
if name.upper() == name:
return name
return lambda *args, **kwargs: print(f'{self.__class__.__name__}.{name}{args} {kwargs}')
class ADC(Tracer):
pass
class Pin(object):
IN = 'IN'
OUT = 'OUT'
def __init__(self, id, direction, value=1):
self._id = id
self._value = 0
def init(self, d, value):
self.value(value)
def on(self):
self.value(1)
def off(self):
self.value(0)
def value(self, v=None):
if v is None:
return self._value
if v:
print(self._id + ": on")
self._value = False
else:
print(self._id + ": off")
self._value = True
def __call__(self, v=None):
self.value(v)
class PWM(Tracer):
FREQ_16MHZ = 'FREQ_16MHZ'
class SPI(object):
def __init__(self, id):
self._id = id
def init(self, baudrate=1000000, polarity=0, phase=0, bits=8, sck=None, mosi=None, miso=None):
pass
def write(self, buf):
print("Sending data: " + str(buf))

View File

@ -0,0 +1,5 @@
def const(x):
return x
def native(x):
return x

View File

@ -0,0 +1,26 @@
import time
def sleep_ms(ms):
time.sleep(ms / 1000)
time.sleep_ms = sleep_ms
from machine import Pin
from machine import SPI
from drivers.st7789 import ST7789_SPI
from drivers.vibrator import Vibrator
class Display(ST7789_SPI):
def __init__(self):
spi = SPI(0)
# Mode 3, maximum clock speed!
spi.init(polarity=1, phase=1, baudrate=8000000)
# Configure the display
cs = Pin("DISP_CS", Pin.OUT)
dc = Pin("DISP_DC", Pin.OUT)
rst = Pin("DISP_RST", Pin.OUT)
super().__init__(240, 240, spi, cs=cs, dc=dc, res=rst)
display = Display()
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)

View File

@ -1,5 +1,7 @@
# MicroPython ST7789 display driver, currently only has an SPI interface
import micropython
from micropython import const
from time import sleep_ms