Expand description
TSC Peripheral Interface
This module provides an interface for the Touch Sensing Controller (TSC) peripheral. It supports both blocking and async modes of operation, as well as different TSC versions (v1, v2, v3).
§Key Concepts
- Pin Groups: TSC pins are organized into groups, each containing up to four IOs.
- Pin Roles: Each pin in a group can have a role: Channel, Sample, or Shield.
- Acquisition Banks: Used for efficient, repeated TSC acquisitions on specific sets of pins.
§Example (stm32)
let device_config = embassy_stm32::Config::default();
let context = embassy_stm32::init(device_config);
let config = tsc::Config {
ct_pulse_high_length: ChargeTransferPulseCycle::_4,
ct_pulse_low_length: ChargeTransferPulseCycle::_4,
spread_spectrum: false,
spread_spectrum_deviation: SSDeviation::new(2).unwrap(),
spread_spectrum_prescaler: false,
pulse_generator_prescaler: PGPrescalerDivider::_16,
max_count_value: MaxCount::_255,
io_default_mode: false,
synchro_pin_polarity: false,
acquisition_mode: false,
max_count_interrupt: false,
};
let mut g2: PinGroupWithRoles<embassy_stm32::peripherals::TSC, G2> = PinGroupWithRoles::new();
g2.set_io1::<tsc_pin_roles::Sample>(context.PB4);
let sensor_pin = g2.set_io2::<tsc_pin_roles::Channel>(context.PB5);
let pin_groups = PinGroups {
g2: Some(g2.pin_group),
..Default::default()
};
let mut touch_controller = tsc::Tsc::new_blocking(
context.TSC,
pin_groups,
config,
).unwrap();
let discharge_delay = 5; // ms
loop {
touch_controller.set_active_channels_mask(sensor_pin.pin.into());
touch_controller.start();
touch_controller.poll_for_acquisition();
touch_controller.discharge_io(true);
Timer::after_millis(discharge_delay).await;
match touch_controller.group_get_status(sensor_pin.pin.group()) {
GroupStatus::Complete => {
let group_val = touch_controller.group_get_value(sensor_pin.pin.group());
// Process the touch value
// ...
}
GroupStatus::Ongoing => {
// Handle ongoing acquisition
// ...
}
}
}
§Async Usage
For async operation, use Tsc::new_async
and pend_for_acquisition
instead of polling.
Re-exports§
pub use acquisition_banks::*;
pub use config::*;
pub use errors::*;
pub use io_pin::*;
pub use pin_groups::*;
pub use tsc::*;
pub use types::*;
Modules§
- Structures and implementations for TSC acquisition banks.
- Configuration structures and enums for the TSC peripheral.
- Error types and definitions for the TSC module.
- Definitions and implementations for individual TSC I/O pins.
- Definitions and implementations for TSC pin groups.
- Core implementation of the TSC (Touch Sensing Controller) driver.
- Type definitions used throughout the TSC module.
Structs§
- TSC interrupt handler.
Enums§
- Error type defined for TSC
Traits§
- TSC instance trait