diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-06 21:09:43 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-06 21:09:43 (GMT) |
| commit | 948454a33b267e47e064675211849f9526cbeaa9 (patch) | |
| tree | c9c8fedc99e46e90a273ba8e47a4db1c3677a7a5 /wasp/drivers | |
| parent | 1bfe748505040acf1514dbc9e3caa07e7d03b24e (diff) | |
wasp: cst816s: Initial PoC driver
Diffstat (limited to 'wasp/drivers')
| -rw-r--r-- | wasp/drivers/cst816s.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/wasp/drivers/cst816s.py b/wasp/drivers/cst816s.py new file mode 100644 index 0000000..5157650 --- /dev/null +++ b/wasp/drivers/cst816s.py @@ -0,0 +1,30 @@ +"""Hynitron CST816S touch contoller driver for MicroPython.""" + +import watch + +class CST816S: + """Hynitron CST816S I2C touch controller driver.""" + + def __init__(self): + self.dbuf = bytearray(6) + pass + + def get_event(self, queue): + """Receive a touch event. + + Check for a pending touch event and, if an event is pending, + prepare it ready to go in the event queue. + + :return: True if an event is received, False otherwise. + """ + dbuf = self.dbuf + + try: + watch.i2c.readfrom_mem_into(21, 1, dbuf) + except OSError: + return False + + queue[0] = dbuf[0] + queue[1] = ((dbuf[2] & 0xf) << 8) + dbuf[3] + queue[2] = ((dbuf[4] & 0xf) << 8) + dbuf[5] + return True |
