summaryrefslogtreecommitdiff
path: root/src/drivers/Cst816s.h
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-07-19 18:30:44 (GMT)
committerJF <jf@codingfield.com>2020-07-19 18:30:44 (GMT)
commit6af5bbcbc87eecccf7613785a3c9540c07d2fd3b (patch)
tree77ea3c1c638321545c5d5f036134045ae112c6b3 /src/drivers/Cst816s.h
parent42d8a18fe74b060a84ea74b29aefca69f9471d5f (diff)
New implementation of the I²C/TWI driver.
Fix reset timing and add dummy reading in Cst816S to fix init error on some devices.
Diffstat (limited to 'src/drivers/Cst816s.h')
-rw-r--r--src/drivers/Cst816s.h30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h
index 4a5dda6..b115a68 100644
--- a/src/drivers/Cst816s.h
+++ b/src/drivers/Cst816s.h
@@ -1,20 +1,21 @@
#pragma once
#include <nrfx_twi.h>
+#include "TwiMaster.h"
namespace Pinetime {
namespace Drivers {
class Cst816S {
public :
enum class Gestures : uint8_t {
- None = 0x00,
- SlideDown = 0x01,
- SlideUp = 0x02,
- SlideLeft = 0x03,
- SlideRight = 0x04,
- SingleTap = 0x05,
- DoubleTap = 0x0B,
- LongPress = 0x0C
+ None = 0x00,
+ SlideDown = 0x01,
+ SlideUp = 0x02,
+ SlideLeft = 0x03,
+ SlideRight = 0x04,
+ SingleTap = 0x05,
+ DoubleTap = 0x0B,
+ LongPress = 0x0C
};
struct TouchInfos {
uint16_t x;
@@ -27,21 +28,19 @@ namespace Pinetime {
bool isTouch = false;
};
- Cst816S() = default;
+ Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
Cst816S(const Cst816S&) = delete;
Cst816S& operator=(const Cst816S&) = delete;
Cst816S(Cst816S&&) = delete;
Cst816S& operator=(Cst816S&&) = delete;
void Init();
- void Probe();
TouchInfos GetTouchInfo();
void Sleep();
void Wakeup();
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;
@@ -56,12 +55,9 @@ namespace Pinetime {
static constexpr uint8_t gestureIndex = 1;
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
+ TwiMaster& twiMaster;
+ uint8_t twiAddress;
};
}
-}
+} \ No newline at end of file