2020-01-03 10:32:31 -05:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-13 16:08:35 -04:00
|
|
|
#include "drivers/TwiMaster.h"
|
2020-01-03 10:32:31 -05:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Drivers {
|
|
|
|
class Cst816S {
|
2021-04-24 05:00:45 -04:00
|
|
|
public:
|
2021-04-18 13:28:14 -04:00
|
|
|
enum class Gestures : uint8_t {
|
|
|
|
None = 0x00,
|
|
|
|
SlideDown = 0x01,
|
|
|
|
SlideUp = 0x02,
|
|
|
|
SlideLeft = 0x03,
|
|
|
|
SlideRight = 0x04,
|
|
|
|
SingleTap = 0x05,
|
|
|
|
DoubleTap = 0x0B,
|
|
|
|
LongPress = 0x0C
|
|
|
|
};
|
|
|
|
struct TouchInfos {
|
|
|
|
uint16_t x = 0;
|
|
|
|
uint16_t y = 0;
|
|
|
|
Gestures gesture = Gestures::None;
|
2021-07-15 17:07:55 -04:00
|
|
|
bool touching = false;
|
2021-11-06 14:01:19 -04:00
|
|
|
bool isValid = false;
|
2021-04-18 13:28:14 -04:00
|
|
|
};
|
2020-01-03 10:32:31 -05:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
|
|
|
|
Cst816S(const Cst816S&) = delete;
|
|
|
|
Cst816S& operator=(const Cst816S&) = delete;
|
|
|
|
Cst816S(Cst816S&&) = delete;
|
|
|
|
Cst816S& operator=(Cst816S&&) = delete;
|
2020-03-08 16:38:11 -04:00
|
|
|
|
2021-08-18 08:23:30 -04:00
|
|
|
bool Init();
|
2021-04-18 13:28:14 -04:00
|
|
|
TouchInfos GetTouchInfo();
|
|
|
|
void Sleep();
|
|
|
|
void Wakeup();
|
2020-01-03 10:32:31 -05:00
|
|
|
|
2021-07-14 10:11:16 -04:00
|
|
|
uint8_t GetChipId() const {
|
|
|
|
return chipId;
|
|
|
|
}
|
|
|
|
uint8_t GetVendorId() const {
|
|
|
|
return vendorId;
|
|
|
|
}
|
|
|
|
uint8_t GetFwVersion() const {
|
|
|
|
return fwVersion;
|
|
|
|
}
|
2021-04-24 05:00:45 -04:00
|
|
|
private:
|
2021-11-06 14:01:19 -04:00
|
|
|
bool CheckDeviceIds();
|
|
|
|
|
2021-07-14 10:11:16 -04:00
|
|
|
// Unused/Unavailable commented out
|
|
|
|
static constexpr uint8_t gestureIndex = 1;
|
2021-04-18 13:28:14 -04:00
|
|
|
static constexpr uint8_t touchPointNumIndex = 2;
|
2021-07-15 17:07:55 -04:00
|
|
|
//static constexpr uint8_t touchEventIndex = 3;
|
2021-04-18 13:28:14 -04:00
|
|
|
static constexpr uint8_t touchXHighIndex = 3;
|
|
|
|
static constexpr uint8_t touchXLowIndex = 4;
|
2021-07-14 10:11:16 -04:00
|
|
|
//static constexpr uint8_t touchIdIndex = 5;
|
2021-04-18 13:28:14 -04:00
|
|
|
static constexpr uint8_t touchYHighIndex = 5;
|
|
|
|
static constexpr uint8_t touchYLowIndex = 6;
|
2021-07-14 10:11:16 -04:00
|
|
|
//static constexpr uint8_t touchStep = 6;
|
|
|
|
//static constexpr uint8_t touchXYIndex = 7;
|
|
|
|
//static constexpr uint8_t touchMiscIndex = 8;
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2021-11-06 14:01:19 -04:00
|
|
|
static constexpr uint8_t maxX = 240;
|
|
|
|
static constexpr uint8_t maxY = 240;
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
TwiMaster& twiMaster;
|
|
|
|
uint8_t twiAddress;
|
2021-07-14 10:11:16 -04:00
|
|
|
|
|
|
|
uint8_t chipId;
|
|
|
|
uint8_t vendorId;
|
|
|
|
uint8_t fwVersion;
|
2020-01-03 10:32:31 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2021-07-14 10:11:16 -04:00
|
|
|
}
|