ft6336u_driver/lib.rs
1//! # FT6336U Capacitive Touch Controller Driver
2//!
3//! A platform-agnostic driver for the FT6336U capacitive touch controller using the
4//! [`embedded-hal`](https://docs.rs/embedded-hal) I2C traits.
5//!
6//! ## Features
7//!
8//! - No `std` dependency - works in embedded environments
9//! - Uses `embedded-hal` I2C traits for portability
10//! - Support for up to 2 simultaneous touch points
11//! - Gesture detection capabilities
12//! - Configurable power modes and scan rates
13//! - Comprehensive register access
14//!
15//! ## Quick Start
16//!
17//! ```rust,no_run
18//! # use embedded_hal::i2c::I2c;
19//! # use core::convert::Infallible;
20//! # struct MockI2c;
21//! # impl embedded_hal::i2c::ErrorType for MockI2c {
22//! # type Error = Infallible;
23//! # }
24//! # impl I2c for MockI2c {
25//! # fn write(&mut self, _: u8, _: &[u8]) -> Result<(), Self::Error> { Ok(()) }
26//! # fn read(&mut self, _: u8, _: &mut [u8]) -> Result<(), Self::Error> { Ok(()) }
27//! # fn write_read(&mut self, _: u8, _: &[u8], _: &mut [u8]) -> Result<(), Self::Error> { Ok(()) }
28//! # fn transaction(&mut self, _: u8, _: &mut [embedded_hal::i2c::Operation<'_>]) -> Result<(), Self::Error> { Ok(()) }
29//! # }
30//! # let i2c = MockI2c;
31//! use ft6336u_driver::FT6336U;
32//!
33//! // Create the driver with your I2C peripheral
34//! let mut touch = FT6336U::new(i2c);
35//!
36//! // Scan for touch events
37//! let touch_data = touch.scan().unwrap();
38//!
39//! if touch_data.touch_count > 0 {
40//! let point = &touch_data.points[0];
41//! println!("Touch at ({}, {})", point.x, point.y);
42//! }
43//! ```
44//!
45//! ## Hardware Integration
46//!
47//! The FT6336U communicates over I2C at address `0x38`. It requires:
48//! - An I2C bus connection (SDA/SCL)
49//! - A reset pin (typically controlled by GPIO or GPIO expander)
50//! - An interrupt pin (optional, for event-driven operation)
51//!
52//! ### Interrupt-Driven Operation
53//!
54//! For optimal power efficiency, configure the touch controller's interrupt pin
55//! and use it to trigger touch scans only when needed:
56//!
57//! ```rust,no_run
58//! # use embedded_hal::i2c::I2c;
59//! # use core::convert::Infallible;
60//! # struct MockI2c;
61//! # impl embedded_hal::i2c::ErrorType for MockI2c {
62//! # type Error = Infallible;
63//! # }
64//! # impl I2c for MockI2c {
65//! # fn write(&mut self, _: u8, _: &[u8]) -> Result<(), Self::Error> { Ok(()) }
66//! # fn read(&mut self, _: u8, _: &mut [u8]) -> Result<(), Self::Error> { Ok(()) }
67//! # fn write_read(&mut self, _: u8, _: &[u8], _: &mut [u8]) -> Result<(), Self::Error> { Ok(()) }
68//! # fn transaction(&mut self, _: u8, _: &mut [embedded_hal::i2c::Operation<'_>]) -> Result<(), Self::Error> { Ok(()) }
69//! # }
70//! # let i2c = MockI2c;
71//! use ft6336u_driver::{FT6336U, GestureMode};
72//!
73//! let mut touch = FT6336U::new(i2c);
74//!
75//! // Enable interrupt mode
76//! touch.write_g_mode(GestureMode::Trigger).unwrap();
77//!
78//! // In your interrupt handler:
79//! // let data = touch.scan().unwrap();
80//! ```
81
82#![no_std]
83#![deny(missing_docs)]
84#![deny(unsafe_code)]
85
86mod ft6336u;
87
88// Re-export the public API
89pub use ft6336u::*;