|
| 1 | +#pragma once |
| 2 | + |
| 3 | +// CST816(S) / CST716 High-performance self-capacitive touch chip |
| 4 | +// Hynitron, www.hynitron.com |
| 5 | + |
| 6 | +// Manually assembled from auto-translated incomplete datasheets and documents. |
| 7 | + |
| 8 | +// The device contains an embedded firmware, behaviour may differ. |
| 9 | +// Code fragments on how to update the internal firmware exist, but not much is know about |
| 10 | +// the internal architecture. No verified compatible binary firmware has been found yet. |
| 11 | + |
| 12 | +// The "S" suffix stands for speed, i.e. double the sample rate (>100 Hz instead of ~50 Hz (?)). |
| 13 | + |
| 14 | +// The CST816S has an auto-sleep low-power mode, from which it can wake via a touch event. |
| 15 | +// In low-power sleep, the I2C interface is inactive. |
| 16 | +// It sends a gesture event while the gesture is still being performed. |
| 17 | + |
| 18 | +// The CST716 has no auto-sleep functionality, and sends a gesture event after the gesture has been completed. |
| 19 | +// Its I2C interface is always active, as it stays in normal mode. |
| 20 | + |
| 21 | +// Both chips are able to enter a deep-sleep mode, from which they can only wake via a signal on the reset pin. |
| 22 | + |
| 23 | +// Registers |
| 24 | + |
| 25 | +// * = Works only on chips which have not been preconfigured (fused) in the factory. |
| 26 | +// CST716 are probably always fused, default: reporting mode. |
| 27 | +// CST816S can be reconfigureable, but can be fused as well. Some fused ones report with a CST716 chip ID. |
| 28 | + |
| 29 | +// ** = Auto-sleep related registers. Only on the CST816S. |
| 30 | + |
| 31 | +#define DEV_MODE 0x00 // readonly. Always 0. |
| 32 | +#define GESTURE_ID 0x01 // readonly. Which gesture was detected. |
| 33 | +#define TD_STATUS 0x02 // readonly. Number of touch points. (0 - 2). |
| 34 | + |
| 35 | +#define P1_X_POS_H 0x03 // readonly. Point 1: X touch event flag + X touch coordinate MSB. |
| 36 | +#define P1_X_POS_L 0x04 // readonly. Point 1: X touch coordinate LSB. |
| 37 | +#define P1_Y_POS_H 0x05 // readonly. Point 1: Y touch event flag + Y touch coordinate MSB. |
| 38 | +#define P1_Y_POS_L 0x06 // readonly. Point 1: Y touch coordinate LSB. |
| 39 | +#define P1_WEIGHT 0x07 // readonly. Point 1: Touch weight. |
| 40 | +#define P1_MISC 0x08 // readonly. Point 1: Touch area. |
| 41 | + |
| 42 | +#define P2_X_POS_H 0x09 // readonly. Point 2: X touch event flag + X touch coordinate MSB. |
| 43 | +#define P2_X_POS_L 0x0A // readonly. Point 2: X touch coordinate LSB. |
| 44 | +#define P2_Y_POS_H 0x0B // readonly. Point 2: Y touch event flag + Y touch coordinate MSB. |
| 45 | +#define P2_Y_POS_L 0x0C // readonly. Point 2: Y touch coordinate LSB. |
| 46 | +#define P2_WEIGHT 0x0D // readonly. Point 2: Touch weight. |
| 47 | +#define P2_MISC 0x0E // readonly. Point 2: Touch area. |
| 48 | + |
| 49 | +#define BPC0_H 0xB0 // unknown. BPC0 value MSB. |
| 50 | +#define BPC0_L 0xB1 // unknown. BPC0 value LSB. |
| 51 | +#define BPC1_H 0xB2 // unknown. BPC1 value MSB. |
| 52 | +#define BPC1_L 0xB3 // unknown. BPC1 value LSB. |
| 53 | + |
| 54 | +#define CHIP_ID 0xA7 // readonly. Chip / firmware type ID. |
| 55 | +#define PROJ_ID 0xA8 // readonly. Vendor / project ID. |
| 56 | +#define FW_VERSION 0xA9 // readonly. Firmware version. |
| 57 | + |
| 58 | +#define MOTION_MASK 0xEC // read-write*. Motion configuration. |
| 59 | +#define IRQ_PULSE_WIDTH 0xED // read-write. Interrupt low pulse output width. Unit 0.1ms, possible value: 1~200. The default value is 10. |
| 60 | +// read-write. Normal fast detection cycle. This value affects LpAutoWakeTime and AutoSleepTime. Unit 10ms, possible value: 1~30. The |
| 61 | +// default value is 1. |
| 62 | +#define NOR_SCAN_PER 0xEE |
| 63 | +// read-write. Gesture detection sliding partition angle control. Angle=tan(c)*10. c is the angle based on the positive direction of |
| 64 | +// the x-axis. |
| 65 | +#define MOTION_S1_ANGLE 0xEF |
| 66 | + |
| 67 | +#define LP_SCAN_RAW1_H 0xF0 // readonly**. Low power scan, MSB of the reference value of channel 1. |
| 68 | +#define LP_SCAN_RAW1_L 0xF1 // readonly**. Low power scan, LSB of the reference value of channel 1. |
| 69 | +#define LP_SCAN_RAW2_H 0xF2 // readonly**. Low power scan, MSB of the reference value of channel 2. |
| 70 | +#define LP_SCAN_RAW2_L 0xF3 // readonly**. Low power scan, LSB of the reference value of channel 2. |
| 71 | +// read-write**. Automatic recalibration cycle in low power mode. The unit is 1 minute, and the possible value is 1 to 5. The default |
| 72 | +// value is 5. |
| 73 | +#define LP_AUTO_WAKE_TIME 0xF4 |
| 74 | +// read-write**. Low-power scan wake-up threshold. The smaller the more sensitive. Possible values: 1 to 255. The default value |
| 75 | +// is 48. |
| 76 | +#define LP_SCAN_TH 0xF5 |
| 77 | +// read-write**. Low power scan range. The larger the more sensitive, the higher the power consumption. Possible values: 0, 1, 2, 3. |
| 78 | +// The default value is 3. |
| 79 | +#define LP_SCAN_WIN 0xF6 |
| 80 | +// read-write**. Low power scan frequency. The smaller the more sensitive. Possible values: 1 to 255. The default value is 7. |
| 81 | +#define LP_SCAN_FREQ 0xF7 |
| 82 | +#define LP_SCAN_I_DAC 0xF8 // read-write**. Low power scan current. The smaller the more sensitive. Possible values: 1 to 255. |
| 83 | +// read-write**. Automatically enter low power mode when there is no touch for x seconds. The unit is 1s, the default value is 2. |
| 84 | +#define AUTO_SLEEP_TIME 0xF9 |
| 85 | +// read-write*. Interrupt configuration. 0x60 = report mode, 0x11 = gesture mode, 0x71 = both. |
| 86 | +#define IRQ_CTL 0xFA |
| 87 | +// read-write. Automatic reset (cancel) when there is a touch but no valid gesture within x seconds. The unit is 1s. When it is 0, |
| 88 | +// this function is not enabled. Default is 5. |
| 89 | +#define AUTO_RESET 0xFB |
| 90 | +// read-write. Automatic reset (cancel) after long press for x seconds. The unit is 1s. When it is 0, this function is not enabled. |
| 91 | +// Default is 10. |
| 92 | +#define LONG_PRESS_TIME 0xFC |
| 93 | +// read-write. Pin IO configuration. |
| 94 | +#define IO_CTL 0xFD |
| 95 | +// read-write**. The default is 0, enabling automatic entry into low power mode. When it is a non-zero value, automatic entry into |
| 96 | +// low power mode is disabled. |
| 97 | +#define DIS_AUTO_SLEEP 0xFE |
| 98 | + |
| 99 | +#define PWR_MODE_CST816S 0xE5 // read-write. Power state for the CST816S. |
| 100 | +#define PWR_MODE_CST716 0xA5 // read-write. Power state for the CST716. |
| 101 | + |
| 102 | +// Data fields |
| 103 | + |
| 104 | +// GESTURE_ID |
| 105 | + |
| 106 | +#define GESTURE_ID_NONE 0x00 |
| 107 | +#define GESTURE_ID_SLIDE_DOWN 0x01 |
| 108 | +#define GESTURE_ID_SLIDE_UP 0x02 |
| 109 | +#define GESTURE_ID_SLIDE_LEFT 0x03 |
| 110 | +#define GESTURE_ID_SLIDE_RIGHT 0x04 |
| 111 | +#define GESTURE_ID_SINGLE_TAP 0x05 |
| 112 | +#define GESTURE_ID_DOUBLE_TAP 0x0B |
| 113 | +#define GESTURE_ID_LONG_PRESS 0x0C |
| 114 | + |
| 115 | +// TD_STATUS |
| 116 | + |
| 117 | +#define TD_STATUS_MASK 0x0F |
| 118 | + |
| 119 | +// *_POS_H |
| 120 | + |
| 121 | +#define POS_H_POS_MASK 0x0F |
| 122 | + |
| 123 | +#define POS_H_EVENT_MASK 0xC0 |
| 124 | +#define POS_H_EVENT0 (1 << 6) |
| 125 | +#define POS_H_EVENT1 (1 << 7) |
| 126 | + |
| 127 | +#define POS_H_EVENT_DOWN (0 << 6) |
| 128 | +#define POS_H_EVENT_UP (1 << 6) |
| 129 | +#define POS_H_EVENT_CONTACT (2 << 6) |
| 130 | +#define POS_H_EVENT_NONE (3 << 6) |
| 131 | + |
| 132 | +// CHIP_ID |
| 133 | + |
| 134 | +#define CHIP_ID_CST816S 0xB4 |
| 135 | +#define CHIP_ID_CST716 0x20 |
| 136 | + |
| 137 | +// Control register configurations |
| 138 | + |
| 139 | +// MOTION_MASK |
| 140 | + |
| 141 | +#define MOTION_MASK_EN_DCLICK (1 << 0) // Enable double click action |
| 142 | +#define MOTION_MASK_EN_CON_UD (1 << 1) // Enable continuous up-down sliding action |
| 143 | +#define MOTION_MASK_EN_CON_LR (1 << 2) // Enable continuous left-right sliding action |
| 144 | + |
| 145 | +// IRQ_CTL |
| 146 | + |
| 147 | +#define IRQ_CTL_ONCE_WLP (1 << 0) // The long press gesture only emits a low pulse signal. |
| 148 | +#define IRQ_CTL_EN_MOTION (1 << 4) // When a gesture is detected, a low pulse is emitted. |
| 149 | +#define IRQ_CTL_EN_CHANGE (1 << 5) // A low pulse is emitted when a touch state change is detected. |
| 150 | +#define IRQ_CTL_EN_TOUCH (1 << 6) // Periodically emit low pulses when a touch is detected. |
| 151 | +#define IRQ_CTL_EN_TEST (1 << 7) // Interrupt pin test, automatically and periodically send low pulses after enabling. |
| 152 | + |
| 153 | +// IO_CTL |
| 154 | + |
| 155 | +#define IO_CTL_EN_1V8 (1 << 0) // I2C and IRQ pin voltage level selection, the default is VDD level. 0: VDD, 1: 1.8V. |
| 156 | +#define IO_CTL_IIC_OD (1 << 1) // I2C pin drive mode, the default is resistor pull-up. 0: Resistor pull-up 1: OD. |
| 157 | +#define IO_CTL_SOFT_RST (1 << 2) // Enable soft reset by pulling down the IRQ pin. 0: Soft reset is disabled. 1: Enable soft reset. |
| 158 | + |
| 159 | +// PWR_MODE_* |
| 160 | + |
| 161 | +#define PWR_MODE_ACTIVE 0x00 // Normal state of execution |
| 162 | +#define PWR_MODE_DEEP_SLEEP 0x03 // Deep-sleep mode. Touch to wakeup and I2C are disabled. |
0 commit comments