The Linux kernel provides native support for the CST816X touchscreen driver (introduced in kernel version 6.18), located at drivers/input/touchscreen/ and managed through the CONFIG_TOUCHSCREEN_CST816X configuration. This tutorial details how to enable the integrated driver and implement a Device Tree overlay to operate a 1.28-inch round LCD utilizing the CST816S controller on a Raspberry Pi.
- Driver Source Code: Available in the Linux tree under
drivers/input/touchscreen/ - DT-Binding Documentation: Available under
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816s.yaml
| Module Pin | GPIO(n) |
|---|---|
| VCC | 3.3V |
| GND | GND |
| MISO | GPIO9 |
| MOSI | GPIO10 |
| SCLK | GPIO11 |
| LCD_CS | GPIO8 |
| LCD_DC | GPIO25 |
| LCD_RST | GPIO27 |
| LCD_BL | GPIO18 |
| TP_SDA | GPIO2 |
| TP_SCL | GPIO3 |
| TP_INT | GPIO4 |
| TP_RST | GPIO17 |
Refer to the Waveshare guide for hardware connection details.
| Event Code | Description |
|---|---|
| BTN_LEFT | Gesture Left |
| BTN_RIGHT | Gesture Right |
| BTN_FORWARD | Gesture Up |
| BTN_BACK | Gesture Down |
| BTN_TOUCH | Single Touch |
| BTN_TOOL_TRIPLETAP | Long Press (Hold) |
- Open the kernel configuration menu:
make menuconfig
- Navigate to the touchscreen section:
Device Drivers └─> Input device support └─> Touchscreens └─> Hynitron CST816X touchscreen support (<M> or <*> ) - Alternatively, enable it directly in your
.config:CONFIG_TOUCHSCREEN_CST816X=m - Rebuild and install kernel modules:
make modules sudo make modules_install
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
i2c {
#address-cells = <1>;
#size-cells = <0>;
touchscreen@15 {
compatible = "hynitron,cst816s";
reg = <0x15>;
interrupt-parent = <&gpio0>;
interrupts = <4 IRQ_TYPE_EDGE_RISING>;
reset-gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
};
};
cd rpi4b/
dtc -@ -I dts -O dtb -o cst816s.dtbo hynitron-cst816s.dts
sudo cp cst816s.dtbo /boot/overlays/
echo "dtoverlay=cst816s" | sudo tee -a /boot/config.txt
sudo rebootVerify that the input device is recognized and registering events:
evtest /dev/input/eventNExpected output:
Input device name: "Hynitron CST816X Touchscreen"
Supported events:
EV_SYN
EV_KEY: BTN_LEFT, BTN_RIGHT, BTN_FORWARD, BTN_BACK, BTN_TOUCH, BTN_TOOL_TRIPLETAP
EV_ABS: ABS_X (0-240), ABS_Y (0-240)
