wasp: simulator: Add interupt support for CST816S
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
parent
61931c3637
commit
acf318c122
3 changed files with 31 additions and 9 deletions
|
@ -89,7 +89,16 @@ class CST816SSim():
|
||||||
else:
|
else:
|
||||||
self.regs[1] = 0
|
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.
|
"""Use key presses to provoke different touchscreen events.
|
||||||
|
|
||||||
Note: The Down key provokes an upward swipe and vice versa.
|
Note: The Down key provokes an upward swipe and vice versa.
|
||||||
|
@ -107,16 +116,16 @@ class CST816SSim():
|
||||||
elif key.keysym.sym == sdl2.SDLK_RIGHT:
|
elif key.keysym.sym == sdl2.SDLK_RIGHT:
|
||||||
self.regs[1] = 3
|
self.regs[1] = 3
|
||||||
self.regs[3] = 0x80
|
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[1] = 5
|
||||||
self.regs[4] = button.x
|
self.regs[4] = button.x
|
||||||
self.regs[6] = button.y
|
self.regs[6] = button.y
|
||||||
self.raise_interrupt()
|
self.raise_interrupt(pins)
|
||||||
|
|
||||||
def raise_interrupt(self):
|
def raise_interrupt(self, pins):
|
||||||
pass
|
pins['TP_INT'].raise_irq()
|
||||||
|
|
||||||
sdl2.ext.init()
|
sdl2.ext.init()
|
||||||
window = sdl2.ext.Window("ST7789", size=(WIDTH, HEIGHT))
|
window = sdl2.ext.Window("ST7789", size=(WIDTH, HEIGHT))
|
||||||
|
@ -134,12 +143,12 @@ def tick(pins):
|
||||||
sdl2.ext.quit()
|
sdl2.ext.quit()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif event.type == sdl2.SDL_MOUSEBUTTONDOWN:
|
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:
|
elif event.type == sdl2.SDL_KEYDOWN:
|
||||||
if event.key.keysym.sym == sdl2.SDLK_TAB:
|
if event.key.keysym.sym == sdl2.SDLK_TAB:
|
||||||
pins['BUTTON'].value(0)
|
pins['BUTTON'].value(0)
|
||||||
else:
|
else:
|
||||||
i2c_cst816s_sim.handle_key(event.key)
|
i2c_cst816s_sim.handle_key(event.key, pins)
|
||||||
elif event.type == sdl2.SDL_KEYUP:
|
elif event.type == sdl2.SDL_KEYUP:
|
||||||
if event.key.keysym.sym == sdl2.SDLK_TAB:
|
if event.key.keysym.sym == sdl2.SDLK_TAB:
|
||||||
pins['BUTTON'].value(1)
|
pins['BUTTON'].value(1)
|
||||||
|
|
|
@ -19,6 +19,7 @@ class ADC(Tracer):
|
||||||
class Pin(object):
|
class Pin(object):
|
||||||
IN = 'IN'
|
IN = 'IN'
|
||||||
OUT = 'OUT'
|
OUT = 'OUT'
|
||||||
|
IRQ_FALLING = 'IRQ_FALLING'
|
||||||
|
|
||||||
pins = {}
|
pins = {}
|
||||||
|
|
||||||
|
@ -30,6 +31,9 @@ class Pin(object):
|
||||||
# Update the pin registry
|
# Update the pin registry
|
||||||
self.pins[id] = self
|
self.pins[id] = self
|
||||||
|
|
||||||
|
def irq(self, trigger, handler):
|
||||||
|
self._handler = handler
|
||||||
|
|
||||||
def init(self, d, value):
|
def init(self, d, value):
|
||||||
self.value(value)
|
self.value(value)
|
||||||
|
|
||||||
|
@ -39,6 +43,9 @@ class Pin(object):
|
||||||
def off(self):
|
def off(self):
|
||||||
self.value(0)
|
self.value(0)
|
||||||
|
|
||||||
|
def raise_irq(self):
|
||||||
|
self._handler(self)
|
||||||
|
|
||||||
def value(self, v=None):
|
def value(self, v=None):
|
||||||
if v is None:
|
if v is None:
|
||||||
if not self._quiet:
|
if not self._quiet:
|
||||||
|
@ -90,6 +97,12 @@ class I2C():
|
||||||
else:
|
else:
|
||||||
raise OSError
|
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():
|
class Timer():
|
||||||
def __init__(self, id, period=1000000):
|
def __init__(self, id, period=1000000):
|
||||||
self.then = None
|
self.then = None
|
||||||
|
|
|
@ -131,6 +131,6 @@ accel = Accelerometer()
|
||||||
battery = Battery()
|
battery = Battery()
|
||||||
button = Pin('BUTTON', Pin.IN, quiet=True)
|
button = Pin('BUTTON', Pin.IN, quiet=True)
|
||||||
rtc = RTC()
|
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)
|
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue