3 releases
Uses old Rust 2015
0.1.2 | Apr 20, 2020 |
---|---|
0.1.1 | Nov 24, 2019 |
0.1.0 | Nov 24, 2019 |
#808 in Embedded development
62 downloads per month
16KB
152 lines
AT42QT2120 Rust driver
Platform agnostic Rust driver for the AT42QT2120
The AT42QT2120
The AT42QT2120 is a touch driver with 12 channels, of which 3 can be used as a slider or a wheel. It has an I2C interface. Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/doc9634.pdf
Status
Basic support works and is tested on hardware:
- Support reading keys
- Support reading raw key values
- Support reading slider
- Configurable slider/wheel
- Configurable key threshold
- Enable/disable keys
- Configurable detection integrator
Most advanced configuration is not supported:
- Configurable drift compensation
- Configurable touch recal delay
- Low power mode
- Using Change pin as input
- Configurable key oversampling
I am new to Rust, so the code quality is probably not great.
License
Licensed under GNU Lesser General Public License v3.0. All contributions intentionally submitted shall be licensed under the same license.
lib.rs
:
A platform agnostic driver for the AT42QT2120 touch sensor IC in Rust.
It is based on the embedded-hal
traits
The device
The AT42QT2120 is a 12 channel QTouch touch sensor that also supports a touch sliders
Usage
Import this crate and an embedded_hal implementation, for example, on an stm32f103 device:
extern crate stm32f1xx_hal as hal;
extern crate AT42QT2120;
The AT42QT2120 only has one address option, so to instantiate a device:
let i2c2 = BlockingI2c::i2c2(..);
let mut touch_sensor = At42qt2120::new(i2c2);
The AT42QT2120, on reset, has all 12 channels setup as touch input with sane settings. If only touch buttons are needed, no extra setup is needed.
To enable a slider:
let use_wheel = false;
let enable_slider = true;
touch_sensor.setup_slider(use_wheel, enable_slider);
If a key needs to be disabled, or the threshold changed:
let key_to_setup = 3;
let key_threshold = 20; //must be 1 or more!
let enable_key = true;
setup_key(key_to_setup, key_threshold, enable_key);
Reading keys and the slider:
if touch_sensor.keys_pressed()? {
let keys_pressed = touch_sensor.read_keys()?;
}
if touch_sensor.slider_pressed()? {
let keys_pressed = touch_sensor.read_slider()?;
}
individual keys can also be read using:
let key_to_read = 3;
touch_sensor.read_key(key_to_read)?;
supported features
Basic features are supported: setting up and reading the slider/wheel setting up and reading keys. Calibration.
Not supported is: setting power mode, changing drift compensation and other advanced settings Grouping keys Setting oversampling on keys
This driver is tested on an stm32f103 and made by someone who is new to rust, ymmv :)
Dependencies
~71KB