summaryrefslogtreecommitdiff
path: root/wasp
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-06-11 20:13:58 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-06-11 20:15:47 (GMT)
commitacf318c122c635fef3dbe1f89806b5a4192500b6 (patch)
tree29de0ce45cdc99c170084e0bd6e930ed4af1b26a /wasp
parent61931c3637f382a696fb8af8a4f435272f383269 (diff)
wasp: simulator: Add interupt support for CST816S
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
Diffstat (limited to 'wasp')
-rw-r--r--wasp/boards/simulator/display.py25
-rw-r--r--wasp/boards/simulator/machine.py13
-rw-r--r--wasp/boards/simulator/watch.py2
3 files changed, 31 insertions, 9 deletions
diff --git a/wasp/boards/simulator/display.py b/wasp/boards/simulator/display.py
index bafb632..11b4701 100644
--- a/wasp/boards/simulator/display.py
+++ b/wasp/boards/simulator/display.py
@@ -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)
diff --git a/wasp/boards/simulator/machine.py b/wasp/boards/simulator/machine.py
index 1a5cf46..891b635 100644
--- a/wasp/boards/simulator/machine.py
+++ b/wasp/boards/simulator/machine.py
@@ -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
diff --git a/wasp/boards/simulator/watch.py b/wasp/boards/simulator/watch.py
index b9de73d..c6dafc3 100644
--- a/wasp/boards/simulator/watch.py
+++ b/wasp/boards/simulator/watch.py
@@ -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)