Skip to content

Latest commit

 

History

125 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Linux Kernel Driver for CST816x Touchscreen Controller

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.


Documentation

Raspberry Pi 4B to Display Pinout

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.

Input Device Capabilities

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)

Kernel Driver Setup

Enable In-Tree Kernel Driver

  1. Open the kernel configuration menu:
    make menuconfig
  2. Navigate to the touchscreen section:
    Device Drivers
      └─> Input device support
            └─> Touchscreens
                  └─> Hynitron CST816X touchscreen support (<M> or <*> )
    
  3. Alternatively, enable it directly in your .config:
    CONFIG_TOUCHSCREEN_CST816X=m
  4. Rebuild and install kernel modules:
    make modules
    sudo make modules_install

Device Tree Setup

DTS Snippet

#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>;
    };
};

Compile & Apply Overlay (Raspberry Pi 4B)

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 reboot

Verification

Verify that the input device is recognized and registering events:

evtest /dev/input/eventN

Expected 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)

About

Linux Kernel module for CST816x Touchscreen

Resources

Stars

7 stars

Watchers

0 watching

Forks

Contributors