GT9x Touch Screen Controller Driver
no_std driver for the GT9x series of capacitive touch screen controllers.
This crate provides a no_std driver for the GT9x series of capacitive touch screen controllers. It supports both asynchronous (embedded-hal-async) and blocking (embedded-hal) I2C communication. It also provides support for cache maintenance, which is useful for MCUs with data caches (like ARM Cortex-M7).
English
Supported Chips
- GT911 (5 points)
- GT928 (10 points)
- GT9147 (5 points)
Features
async: (Default) Enables the asynchronous driver based onembedded-hal-async.blocking: Enables the blocking driver based onembedded-hal.defmt: Enables logging withdefmt.
Usage
Asynchronous Driver
The asynchronous driver can be used with or without an interrupt pin.
Polling Mode
In polling mode, the driver will check the status register for new touch data in a loop.
// From example/src/bin/common.rs
use ;
let mut gt9x = new;
gt9x.init.await.unwrap;
loop
Interrupt Mode
In interrupt mode, the driver will wait for a rising edge on the interrupt pin before reading touch data. This is more efficient than polling.
// From example/src/bin/int.rs
use ;
let mut gt9x_int = new_int;
gt9x_int.init.await.unwrap;
loop
Blocking Driver
The blocking driver polls the status register to get touch data.
// From example/src/bin/blocking.rs
use ;
let mut gt9x = new;
gt9x.init.unwrap;
loop
Cache Maintenance
The buffer must be aligned to the cache line size, and its length must be a multiple of the alignment.
// From example/src/bin/int_cache.rs
use ;
;
// Buffer needs to be aligned
;
static mut BUF: = Aligned32;
let mut gt9x = new_int_cache;
See the examples folder for more complete usage.
中文说明
支持的芯片
- GT911 (5点触摸)
- GT928 (10点触摸)
- GT9147 (5点触摸)
功能特性 (Features)
async: (默认) 启用基于embedded-hal-async的异步驱动。blocking: 启用基于embedded-hal的阻塞驱动。defmt: 启用defmt日志。
使用方法
异步驱动
异步驱动支持中断模式和轮询模式。
轮询模式
在轮询模式下,驱动会循环查询状态寄存器以获取新的触摸数据。
// 来自 example/src/bin/common.rs
use ;
let mut gt9x = new;
gt9x.init.await.unwrap;
loop
中断模式
在中断模式下,驱动会等待中断引脚的上升沿信号,然后再读取触摸数据。这种方式比轮询更高效。
// 来自 example/src/bin/int.rs
use ;
let mut gt9x_int = new_int;
gt9x_int.init.await.unwrap;
loop
阻塞驱动
阻塞驱动通过轮询状态寄存器来获取触摸数据。
// 来自 example/src/bin/blocking.rs
use ;
let mut gt9x = new;
gt9x.init.unwrap;
loop
缓存维护 (Cache Maintenance)
对于带有数据缓存(Data Cache)的 MCU,提供给驱动所使用的缓冲区位于由缓存管理的内存区域时,可以实现 CacheMaintenance trait 来处理缓存失效操作。
缓冲区必须按缓存行大小对齐,并且其长度必须是该对齐值的倍数。
// 来自 example/src/bin/int_cache.rs
use ;
;
// 缓冲区地址需要对齐
;
static mut BUF: = Aligned32;// 缓冲区大小要对齐
// let i2c = ...;
// let int_pin = ...;
let mut gt9x = new_int_cache;
请参阅 examples 目录以获取更完整的使用示例。