1
0
Fork 0

wasp: simulator: Add interupt support for CST816S

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-06-11 21:13:58 +01:00
parent 61931c3637
commit acf318c122
3 changed files with 31 additions and 9 deletions

View file

@ -89,7 +89,16 @@ class CST816SSim():
else:
self.regs[1] = 0
def handle_key(self, key):
def writeto_mem(self, addr, reg, buf, pins):
tick(pins)
if reg == 0xa5:
# This will be a sleep command... which we can ignore
return
raise OSError
def handle_key(self, key, pins):
"""Use key presses to provoke different touchscreen events.
Note: The Down key provokes an upward swipe and vice versa.
@ -107,16 +116,16 @@ class CST816SSim():
elif key.keysym.sym == sdl2.SDLK_RIGHT:
self.regs[1] = 3
self.regs[3] = 0x80
self.raise_interrupt()
self.raise_interrupt(pins)
def handle_mousebutton(self, button):
def handle_mousebutton(self, button, pins):
self.regs[1] = 5
self.regs[4] = button.x
self.regs[6] = button.y
self.raise_interrupt()
self.raise_interrupt(pins)
def raise_interrupt(self):
pass
def raise_interrupt(self, pins):
pins['TP_INT'].raise_irq()
sdl2.ext.init()
window = sdl2.ext.Window("ST7789", size=(WIDTH, HEIGHT))
@ -134,12 +143,12 @@ def tick(pins):
sdl2.ext.quit()
sys.exit(0)
elif event.type == sdl2.SDL_MOUSEBUTTONDOWN:
i2c_cst816s_sim.handle_mousebutton(event.button)
i2c_cst816s_sim.handle_mousebutton(event.button, pins)
elif event.type == sdl2.SDL_KEYDOWN:
if event.key.keysym.sym == sdl2.SDLK_TAB:
pins['BUTTON'].value(0)
else:
i2c_cst816s_sim.handle_key(event.key)
i2c_cst816s_sim.handle_key(event.key, pins)
elif event.type == sdl2.SDL_KEYUP:
if event.key.keysym.sym == sdl2.SDLK_TAB:
pins['BUTTON'].value(1)

View file

@ -19,6 +19,7 @@ class ADC(Tracer):
class Pin(object):
IN = 'IN'
OUT = 'OUT'
IRQ_FALLING = 'IRQ_FALLING'
pins = {}
@ -30,6 +31,9 @@ class Pin(object):
# Update the pin registry
self.pins[id] = self
def irq(self, trigger, handler):
self._handler = handler
def init(self, d, value):
self.value(value)
@ -39,6 +43,9 @@ class Pin(object):
def off(self):
self.value(0)
def raise_irq(self):
self._handler(self)
def value(self, v=None):
if v is None:
if not self._quiet:
@ -90,6 +97,12 @@ class I2C():
else:
raise OSError
def writeto_mem(self, addr, reg, dbuf):
if self.sim:
self.sim.writeto_mem(addr, reg, dbuf, Pin.pins)
else:
raise OSError
class Timer():
def __init__(self, id, period=1000000):
self.then = None

View file

@ -131,6 +131,6 @@ accel = Accelerometer()
battery = Battery()
button = Pin('BUTTON', Pin.IN, quiet=True)
rtc = RTC()
touch = CST816S(I2C(0))
touch = CST816S(I2C(0), Pin('TP_INT', Pin.IN, quiet=True), Pin('TP_RST', Pin.OUT, quiet=True))
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)