summaryrefslogtreecommitdiff
path: root/wasp/drivers
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-08-09 19:06:45 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-08-09 19:06:45 (GMT)
commit2d1942f76a52ea748617791bc22022fb447f182c (patch)
treee297d97aefa2da426de7d57c165705cd1780d610 /wasp/drivers
parent5c30b2e0f0acdf055e820b5905cdf7ff9d9ad649 (diff)
k9: Add support for Senbono K9
The K9 is similar to the PineTime and P8 devices but does not appear to use the CST[78]16 touch screen controllers. At present the protocol is not known (readfrom yields all zeros, readfrom_mem provokes an exception) so we have a hugely limited interface consisting of the side button and the touchscreen interrupts (in other words we can treat the touchscreen like a second button). Works suprisingly well considering... Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
Diffstat (limited to 'wasp/drivers')
-rw-r--r--wasp/drivers/touch.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/wasp/drivers/touch.py b/wasp/drivers/touch.py
new file mode 100644
index 0000000..0b08653
--- /dev/null
+++ b/wasp/drivers/touch.py
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: LGPL-3.0-or-later
+# Copyright (C) 2020 Daniel Thompson
+
+"""Basic touch sensor driver
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+"""
+
+import array
+import time
+from machine import Pin
+from watch import rtc
+
+class TouchButton:
+ """Simple touch controller driver.
+
+ .. automethod:: __init__
+ """
+
+ def __init__(self, intr, rst, schedule=None):
+ """Specify the bus used by the touch controller.
+
+ :param machine.I2C bus: I2C bus for the CST816S.
+ """
+ self.tp_int = intr
+ self.tp_rst = rst
+ self.schedule = schedule
+ self.event = array.array('H', (0, 0, 0))
+
+ self._reset()
+ self.tp_int.irq(trigger=Pin.IRQ_FALLING, handler=self.get_touch_data)
+
+ def _reset(self):
+ self.tp_rst.off()
+ time.sleep_ms(5)
+ self.tp_rst.on()
+ time.sleep_ms(50)
+ self.event[0] = 0
+ self._wake_at = rtc.get_uptime_ms() + 300
+
+ def get_touch_data(self, pin_obj):
+ """Synthesize a right swipe during interrupt.
+ """
+ self.event[0] = 4
+
+ if self.schedule:
+ self.schedule(self)
+
+ def get_event(self):
+ """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: An event record if an event is received, None otherwise.
+ """
+ if rtc.get_uptime_ms() < self._wake_at:
+ self.event[0] = 0
+
+ if self.event[0] == 0:
+ return None
+
+ return self.event
+
+ def reset_touch_data(self):
+ """Reset touch data.
+
+ Reset touch data, call this function after processing an event.
+ """
+ self.event[0] = 0
+
+ def wake(self):
+ """Wake up touch controller chip.
+
+ Just reset the chip in order to wake it up
+ """
+ self._reset()
+
+ def sleep(self):
+ """Put touch controller chip on sleep mode to save power.
+ """
+ self.tp_rst.off()
+
+ # Ensure get_event() cannot return anything
+ self.event[0] = 0