FT6336U Touch Controller Driver
A platform-agnostic Rust driver for the FT6336U capacitive touch controller, built using the embedded-hal traits.
Features
no_stdcompatible - Works in embedded environments without the standard library- Platform-agnostic - Uses
embedded-halI2C traits for maximum portability - Multi-touch support - Handles up to 2 simultaneous touch points
- Gesture detection - Built-in gesture recognition capabilities
- Power management - Configurable active and monitor modes for power efficiency
- Interrupt-driven operation - Support for both polling and interrupt modes
- Comprehensive API - Full access to all device registers and configuration options
Hardware Support
The FT6336U is a capacitive touch controller commonly found in:
- Touch screen displays
- Touch panels
- Embedded systems with touch interfaces
I2C Address: 0x38
Installation
Add this to your Cargo.toml:
[]
= "1.0"
= "1.0"
Usage
Basic Example
use FT6336U;
// Create the driver with your I2C peripheral
let mut touch = FT6336Unew;
// Scan for touch events
let touch_data = touch.scan.unwrap;
if touch_data.touch_count > 0
Polling Mode
Continuously poll for touch events:
use ;
let mut touch = FT6336Unew;
loop
Interrupt Mode
For better power efficiency, use interrupt-driven operation:
use ;
let mut touch = FT6336Unew;
// Enable interrupt mode
touch.write_g_mode.unwrap;
// In your interrupt handler:
// let data = touch.scan().unwrap();
// Process touch data...
Reading Device Information
// Read chip ID (should be 0x64)
let chip_id = touch.read_chip_id.unwrap;
// Read firmware version
let firmware_id = touch.read_firmware_id.unwrap;
// Read library version
let lib_version = touch.read_library_version.unwrap;
Hardware Integration
Connections
- SDA - I2C data line (requires pull-up resistor)
- SCL - I2C clock line (requires pull-up resistor)
- INT - Interrupt output (optional, active low)
- RST - Reset input (active low)
Typical Integration
- Connect I2C lines with appropriate pull-up resistors (typically 4.7kΩ)
- Connect reset pin to GPIO or GPIO expander
- Connect interrupt pin to GPIO with interrupt capability (optional)
- Initialize I2C at 100kHz or 400kHz
- Reset the controller by toggling the reset pin
- Create the driver and start scanning
Example with GPIO Expander (e.g., AW9523B)
On some boards like the CoreSE-S3, the touch controller's reset and interrupt pins are managed through a GPIO expander:
// Configure expander pins
// - P0_0 (TOUCH_RST): Output mode
// - P1_2 (TOUCH_INT): Input mode with interrupt
// Reset sequence
expander.set_pin_low; // Assert reset
delay.delay_ms;
expander.set_pin_high; // Release reset
delay.delay_ms;
// Create touch driver
let mut touch = FT6336Unew;
// Enable interrupt mode
touch.write_g_mode.unwrap;
Examples
The repository includes several examples:
polling.rs- Continuous polling for touch eventsinterrupt.rs- Interrupt-driven touch detectiondevice_info.rs- Reading device information and configuration
Run examples with (requires hardware):
API Documentation
For complete API documentation, visit docs.rs/ft6336u-driver.
Build documentation locally:
Register Access
The driver provides both high-level methods (like scan()) and low-level register access:
// High-level touch scanning
let data = touch.scan.unwrap;
// Low-level register access
let threshold = touch.read_touch_threshold.unwrap;
touch.write_ctrl_mode.unwrap;
Supported Platforms
This driver works on any platform that implements the embedded-hal I2C traits, including:
- ARM Cortex-M (STM32, nRF, etc.)
- RISC-V (ESP32-C3, GD32V, etc.)
- Xtensa (ESP32, ESP32-S3, etc.)
- AVR (Arduino)
- Any other platform with
embedded-halsupport
Testing
Run documentation tests:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
References
Author
Trevor Flahardy
Note: This is an unofficial driver and is not affiliated with or endorsed by FocalTech Systems Co., Ltd.
Platform-agnostic driver for the FT6336U capacitive touch controller using embedded-hal traits.