Crates.io | cst226-rs |
lib.rs | cst226-rs |
version | 0.1.1 |
created_at | 2025-08-20 12:58:10.519241+00 |
updated_at | 2025-08-24 11:55:57.355087+00 |
description | A Rust driver for the CST226 touch controllers |
homepage | https://blog.theembeddedrustacean.com/ |
repository | https://github.com/theembeddedrustacean/cst226-rs |
max_upload_size | |
id | 1803364 |
size | 57,185 |
A driver for the CST226 touch controller(s), providing functionality to read touch points and manage power modes.
Note: There is limited public information available for CST226 touch controller. Much of the operational detail is not documented in datasheets.
This driver is largely based on the implementation in the LilyGo AMOLED Series repository.
This driver is embedded-hal
compatible and provides a generic interface for implementing the device reset functionality.
The reset pin can be controlled by custom interface such as a GPIO port or an I2C I/O expander.
Some drivers include an INT
pin to indicate touch events, but this driver does not use it.
If interrupts are needed, users can connect the pin to an interrupt-capable input and implement their own callback.
ResetInterface
trait for your specific reset mechanism.Cst226Driver
.// Initialize GPIO Reset Pin or I2C-controlled Reset Pin
// ResetDriver is a type that implements the `ResetInterface` trait.
let reset = ResetDriver::new(PinInstance);
// Instantiate Driver
let mut touch = Cst226Driver::new(
I2CInstance,
CST226_DEVICE_ADDRESS,
reset_pin,
);
// Initialize Touch device
touch.initialize(&mut DelayInstance).expect("Failed to initialize touch driver");
// Monitor Touch events
loop {
let touches = touch.get_touches().unwrap();
for (i, touch) in touches.iter().enumerate() {
println!("Touch {}: x={}, y={}", i + 1, touch.x, touch.y);
}
}
To run the example demonstrating touch support:
cargo run --release --example touch --all-features
Notes: If the reset pin is controlled via an I2C GPIO expander sharing the same bus with the touch driver, you should use the
embedded_hal_bus
to manage multiple instances of I2C. Refer to the examples folder to see how that looks like.