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.
This commit is contained in:
parent
e36caf5997
commit
262d93c76c
5 changed files with 92 additions and 0 deletions
5
Makefile
5
Makefile
|
@ -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
|
||||
|
||||
|
|
54
wasp/boards/simulator/machine.py
Normal file
54
wasp/boards/simulator/machine.py
Normal 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))
|
5
wasp/boards/simulator/micropython.py
Normal file
5
wasp/boards/simulator/micropython.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
def const(x):
|
||||
return x
|
||||
|
||||
def native(x):
|
||||
return x
|
26
wasp/boards/simulator/watch.py
Normal file
26
wasp/boards/simulator/watch.py
Normal 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)
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue