|
3 | 3 |
|
4 | 4 | [](https://www.arduinolibraries.info/libraries/cst816-s) |
5 | 5 |
|
| 6 | +## Auto Sleep Control |
| 7 | + |
| 8 | +Auto Sleep is referred to as Standby Mode in this [Waveshare document](https://www.waveshare.com/w/upload/5/51/CST816S_Datasheet_EN.pdf). Disabling of auto sleep or auto standby will keep the touch display in Dynamic mode. This will improve responsiveness, at the cost of about ~1.6mA. |
| 9 | + |
| 10 | +By default, auto sleep is **enabled** with a timeout of 2 seconds. The following functions allow you to manage auto sleep behavior: |
| 11 | + |
| 12 | +- **`void disable_auto_sleep();`** |
| 13 | + Disables auto sleep, keeping the device active indefinitely. |
| 14 | + |
| 15 | +- **`void enable_auto_sleep();`** |
| 16 | + Re-enables auto sleep with the current timeout (default is 2 seconds). |
| 17 | + |
| 18 | +- **`void set_auto_sleep_time(int seconds);`** |
| 19 | + Sets the auto sleep timeout in seconds (1-255). |
| 20 | + Example: `set_auto_sleep_time(10);` sets a 10-second timeout. |
| 21 | + |
| 22 | +## User-Provided Interrupt |
| 23 | + |
| 24 | +The CST816S library allows you to attach a custom interrupt function to handle touch events according to your application's needs. By providing a user-defined interrupt, you can trigger specific actions upon touch events, such as waking the device from a low-power state, checking gestures, or executing custom logic without constantly polling the device. |
| 25 | + |
| 26 | +**Feature Highlights:** |
| 27 | +- **Custom Event Handling**: Define and attach a user function that executes on each touch interrupt, allowing immediate responses to touch events. |
| 28 | +- **Power Management**: Ideal for applications needing to manage power, such as waking from sleep modes, as the interrupt triggers only on touch. |
| 29 | +- **Gesture-Based Logic**: Use the interrupt to wake, then analyze gestures to decide on further actions, enabling efficient and gesture-responsive behavior. |
| 30 | + |
| 31 | + |
| 32 | + |
6 | 33 | ## Register Information |
7 | 34 |
|
8 | 35 | The following information was extracted from [this document](https://www.waveshare.com/w/upload/c/c2/CST816S_register_declaration.pdf) provided by Waveshare. |
9 | 36 |
|
10 | 37 | | Register Name | Address | Bit Description | Default Value | Configuration Options | |
11 | 38 | |-------------------|---------|-------------------------------------------------------|---------------|----------------------------------------------------------------| |
12 | | -| GestureID | 0x01 | Gesture code for detected gestures | N/A | 0x00: None, 0x01: Slide Up, 0x02: Slide Down, 0x0B: Double Click | |
13 | | -| FingerNum | 0x02 | Number of fingers detected | N/A | 0: No finger, 1: One finger | |
| 39 | +| GestureID | 0x01 | Gesture code for detected gestures | N/A | - 0x00: None <br> - 0x01: Slide Up <br> - 0x02: Slide Down <br> - 0x03: Slide Left <br> - 0x04: Slide Right <br> - 0x05: Single Click <br> - 0x0B: Double Click <br> - 0x0C: Long Press | |
| 40 | +| FingerNum | 0x02 | Number of fingers detected | N/A | - 0: No finger <br> - 1: One finger | |
14 | 41 | | XposH | 0x03 | High 4 bits of X coordinate | N/A | - | |
15 | 42 | | XposL | 0x04 | Low 8 bits of X coordinate | N/A | - | |
16 | 43 | | YposH | 0x05 | High 4 bits of Y coordinate | N/A | - | |
|
22 | 49 | | ChipID | 0xA7 | Chip model identifier | N/A | - | |
23 | 50 | | ProjID | 0xA8 | Project number | N/A | - | |
24 | 51 | | FwVersion | 0xA9 | Firmware version number | N/A | - | |
25 | | -| MotionMask | 0xEC | Enable gesture actions like double-click | 0x00 | Bit 0: EnDClick (enable double-click), Bit 1: EnConUD | |
| 52 | +| MotionMask | 0xEC | Enable continuous gesture actions and double-click | 0x00 | - Bit 0: EnDClick (enable double-click) <br> - Bit 1: EnConUD (enable continuous up/down swipe) <br> - Bit 2: EnConLR (enable continuous left/right swipe) | |
26 | 53 | | IrqPluseWidth | 0xED | Interrupt pulse width (0.1 ms units) | 10 | 1-200 | |
27 | 54 | | NorScanPer | 0xEE | Normal scan period (10 ms units) | 1 | 1-30 | |
28 | | -| MotionSlAngle | 0xEF | Gesture detection sliding angle control | N/A | - | |
29 | | -| LpScanRaw1H | 0xF0 | High 8 bits of low-power scan channel 1 reference | N/A | - | |
30 | | -| LpScanRaw1L | 0xF1 | Low 8 bits of low-power scan channel 1 reference | N/A | - | |
31 | | -| LpScanRaw2H | 0xF2 | High 8 bits of low-power scan channel 2 reference | N/A | - | |
32 | | -| LpScanRaw2L | 0xF3 | Low 8 bits of low-power scan channel 2 reference | N/A | - | |
33 | | -| LpAutoWakeTime | 0xF4 | Auto recalibration time in low-power mode | 5 minutes | 1-5 minutes | |
34 | | -| LpScanTH | 0xF5 | Low-power scan wake threshold | 48 | 1-255 | |
35 | | -| LpScanWin | 0xF6 | Low-power scan range | 3 | 0-3 | |
36 | | -| LpScanFreq | 0xF7 | Low-power scan frequency | 7 | 1-255 | |
37 | | -| LpScanIdac | 0xF8 | Low-power scan current | N/A | 1-255 | |
38 | | -| AutoSleepTime | 0xF9 | Time in seconds before entering standby mode | 2 seconds | 1-255 seconds | |
39 | | -| IrqCtl | 0xFA | Control of interrupt behavior | N/A | EnTest, EnTouch, EnChange, EnMotion | |
40 | | -| AutoReset | 0xFB | Auto-reset time with no valid gesture detected | 5 seconds | 0-5 seconds (0 to disable) | |
41 | | -| LongPressTime | 0xFC | Time for long press to trigger reset | 10 seconds | 0-10 seconds (0 to disable) | |
42 | | -| IOCtl | 0xFD | IO control settings including soft reset | N/A | SOFT_RST, IIC_OD, En1v8 | |
43 | | -| DisAutoSleep | 0xFE | Disable auto sleep mode | 0 | Non-zero value disables auto sleep mode | |
| 55 | +| MotionSlAngle | 0xEF | Gesture detection sliding angle control (Angle = tan(c) * 10, where c is the angle relative to the positive X-axis) | N/A | - | |
| 56 | +| LpScanRaw1H | 0xF0 | High 8 bits of low-power scan channel 1 reference | N/A | - | |
| 57 | +| LpScanRaw1L | 0xF1 | Low 8 bits of low-power scan channel 1 reference | N/A | - | |
| 58 | +| LpScanRaw2H | 0xF2 | High 8 bits of low-power scan channel 2 reference | N/A | - | |
| 59 | +| LpScanRaw2L | 0xF3 | Low 8 bits of low-power scan channel 2 reference | N/A | - | |
| 60 | +| LpAutoWakeTime | 0xF4 | Low-power mode auto recalibration interval (in minutes) | 5 minutes | 1-5 minutes | |
| 61 | +| LpScanTH | 0xF5 | Low-power scan wake threshold. The smaller the value, the more sensitive it is. | 48 | 1-255 | |
| 62 | +| LpScanWin | 0xF6 | Low-power scan range. The larger the value, the more sensitive it is, but power consumption increases. | 3 | 0-3 | |
| 63 | +| LpScanFreq | 0xF7 | Low-power scan frequency. The smaller the value, the more sensitive it is. | 7 | 1-255 | |
| 64 | +| LpScanIdac | 0xF8 | Low-power scan current. The smaller the value, the more sensitive it is. | N/A | 1-255 | |
| 65 | +| AutoSleepTime | 0xF9 | Time in seconds before entering standby mode after inactivity | 2 seconds | 1-255 seconds | |
| 66 | +| IrqCtl | 0xFA | Control of interrupt behavior | N/A | - Bit 7: EnTest (Enable test, periodically sends low pulses) <br> - Bit 6: EnTouch (Sends low pulse on touch detection) <br> - Bit 5: EnChange (Sends low pulse on touch state change) <br> - Bit 4: EnMotion (Sends low pulse on gesture detection) <br> - Bit 0: OnceWLP (Sends one low pulse on long press) | |
| 67 | +| AutoReset | 0xFB | Auto-reset time after detecting touch with no valid gesture | 5 seconds | - 0: Disable <br> - 1-5: Time in seconds before auto-reset | |
| 68 | +| LongPressTime | 0xFC | Time (in seconds) for a long press to trigger reset | 10 seconds | - 0: Disable <br> - 1-10: Long press duration in seconds | |
| 69 | +| IOCtl | 0xFD | IO control settings including soft reset and power options | N/A | - Bit 2: SOFT_RST (0: Disable soft reset, 1: Enable soft reset) <br> - Bit 1: IIC_OD (0: Pull-up resistor, 1: Open-drain) <br> - Bit 0: En1v8 (0: VDD, 1: 1.8V) | |
| 70 | +| DisAutoSleep | 0xFE | Disable automatic entry into low-power mode | 0 (enabled) | - 0: Enable auto sleep <br> - Non-zero: Disable auto sleep | |
0 commit comments