From ee530baaa05faeb246392cd2ac0ee66e79af49db Mon Sep 17 00:00:00 2001 From: JF Date: Fri, 3 Jan 2020 16:32:31 +0100 Subject: Add basic touch panel driver. Handle touch event in display app : draw a big square at the touch point coordinates. --- src/drivers/Cst816s.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/drivers/Cst816s.h (limited to 'src/drivers/Cst816s.h') diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h new file mode 100644 index 00000000..fea33f40 --- /dev/null +++ b/src/drivers/Cst816s.h @@ -0,0 +1,47 @@ +#pragma once + +#include + +namespace Pinetime { + namespace Drivers { + class Cst816S { + public : + struct TouchInfos { + uint16_t x; + uint16_t y; + uint8_t action; + uint8_t finger; + uint8_t pressure; + uint8_t area; + bool isTouch = false; + }; + + void Init(); + void Probe(); + TouchInfos GetTouchInfo(); + private: + static constexpr uint8_t pinIrq = 28; + static constexpr uint8_t pinReset = 10; + static constexpr uint8_t address = 0x15; + static constexpr uint8_t lastTouchId = 0x0f; + static constexpr uint8_t touchPointNumIndex = 2; + static constexpr uint8_t touchMiscIndex = 8; + static constexpr uint8_t touchXYIndex = 7; + static constexpr uint8_t touchEventIndex = 3; + static constexpr uint8_t touchXHighIndex = 3; + static constexpr uint8_t touchXLowIndex = 4; + static constexpr uint8_t touchYHighIndex = 5; + static constexpr uint8_t touchYLowIndex = 6; + static constexpr uint8_t touchIdIndex = 5; + static constexpr uint8_t touchStep = 6; + + uint8_t touchData[63]; + + // TODO TWI (i²C) should be created outside and injected into this class + // It will be needed when implementing other I²C devices + // (0x15 = touch, 0x18 = accelerometer, 0x44 = HR sensor) + nrfx_twi_t twi = NRFX_TWI_INSTANCE(1); // Use instance 1, because instance 0 is already used by SPI + }; + + } +} -- cgit v1.2.3-70-g09d2