summaryrefslogtreecommitdiff
path: root/src/drivers/Cst816s.h
blob: b7876b887a33b3c4df7558813a0436611c1d0cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#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
        };
        struct TouchInfos {
          uint16_t x = 0;
          uint16_t y = 0;
          uint8_t action = 0;
          uint8_t finger = 0;
          uint8_t pressure = 0;
          uint8_t area = 0;
          Gestures gesture = Gestures::None;
          bool isTouch = false;
        };

        Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
        Cst816S(const Cst816S&) = delete;
        Cst816S& operator=(const Cst816S&) = delete;
        Cst816S(Cst816S&&) = delete;
        Cst816S& operator=(Cst816S&&) = delete;

        void Init();
        TouchInfos GetTouchInfo();
        void Sleep();
        void Wakeup();
      private:
        static constexpr uint8_t pinIrq = 28;
        static constexpr uint8_t pinReset = 10;
        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;
        static constexpr uint8_t gestureIndex = 1;

        uint8_t touchData[63];
        TwiMaster& twiMaster;
        uint8_t twiAddress;
    };

  }
}