embassy-stm32

Crates

git

Versions

stm32wba52ke

Flavors

embassy_stm32::tsc::tsc

Struct Tsc

Source
pub struct Tsc<'d, T: Instance, K: PeriMode> { /* private fields */ }
Expand description

TSC driver

Implementations§

Source§

impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K>

Source

pub fn get_acquisition_bank_status( &self, bank: &AcquisitionBank, ) -> AcquisitionBankStatus

Get the status of all groups involved in a AcquisitionBank

Source

pub fn get_acquisition_bank_values( &self, bank: &AcquisitionBank, ) -> AcquisitionBankReadings

Get the values for all channels involved in a AcquisitionBank

Source

pub fn create_acquisition_bank( &self, acquisition_bank_pins: AcquisitionBankPins, ) -> AcquisitionBank

Creates a new TSC acquisition bank from the provided pin configuration.

This method creates a AcquisitionBank that can be used for efficient, repeated TSC acquisitions. It automatically generates the appropriate mask for the provided pins.

§Note on TSC Hardware Limitation

The TSC hardware can only read one channel pin from each TSC group per acquisition.

§Arguments
  • acquisition_bank_pins - The pin configuration for the acquisition bank.
§Returns

A new AcquisitionBank instance.

§Example
let tsc = // ... initialize TSC
let tsc_sensor1: tsc::IOPinWithRole<G1, tsc_pin_roles::Channel> = ...;
let tsc_sensor2: tsc::IOPinWithRole<G2, tsc_pin_roles::Channel> = ...;

let bank = tsc.create_acquisition_bank(AcquisitionBankPins {
    g1_pin: Some(tsc_sensor1),
    g2_pin: Some(tsc_sensor2),
    ..Default::default()
});

// Use the bank for acquisitions
tsc.set_active_channels_bank(&bank);
tsc.start();
// ... perform acquisition ...
Source

pub fn set_active_channels_mask(&mut self, mask: u32)

Sets the active channels for the next TSC acquisition.

This is a low-level method that directly sets the channel mask. For most use cases, consider using set_active_channels_bank with a AcquisitionBank instead, which provides a higher-level interface and additional safety checks.

This method configures which sensor channels will be read during the next touch sensing acquisition cycle. It should be called before starting a new acquisition with the start() method.

§Arguments
  • mask - A 32-bit mask where each bit represents a channel. Set bits indicate active channels.
§Note

Only one pin from each TSC group can be read for each acquisition. This method does not perform checks to ensure this limitation is met. Incorrect masks may lead to unexpected behavior.

§Safety

This method doesn’t perform extensive checks on the provided mask. Ensure that the mask is valid and adheres to hardware limitations to avoid undefined behavior.

Source

pub fn set_active_channels( &mut self, channels: &[IOPin], ) -> Result<(), AcquisitionBankError>

Convenience method for setting active channels directly from a slice of tsc::IOPin. This method performs safety checks but is less efficient for repeated use.

Source

pub fn set_active_channels_bank(&mut self, bank: &AcquisitionBank)

Sets the active channels for the next TSC acquisition using a pre-configured acquisition bank.

This method efficiently configures the TSC peripheral to read the channels specified in the provided AcquisitionBank. It’s the recommended way to set up channel configurations for acquisition, especially when using the same set of channels repeatedly.

§Arguments
  • bank - A reference to a AcquisitionBank containing the pre-configured TSC channel mask.
§Example
let tsc_sensor1: tsc::IOPinWithRole<G1, Channel> = ...;
let tsc_sensor2: tsc::IOPinWithRole<G5, Channel> = ...;
let mut touch_controller: Tsc<'_, TSC, Async> = ...;
let bank = touch_controller.create_acquisition_bank(AcquisitionBankPins {
    g1_pin: Some(tsc_sensor1),
    g2_pin: Some(tsc_sensor2),
    ..Default::default()
});

touch_controller.set_active_channels_bank(&bank);
touch_controller.start();
// ... perform acquisition ...

This method should be called before starting a new acquisition with the start() method.

Source

pub fn start(&mut self)

Start charge transfer acquisition

Source

pub fn stop(&mut self)

Stop charge transfer acquisition

Source

pub fn get_state(&mut self) -> State

Get current state of acquisition

Source

pub fn group_get_status(&self, index: Group) -> GroupStatus

Get the individual group status to check acquisition complete

Source

pub fn group_get_value(&self, index: Group) -> u16

Get the count for the acquisiton, valid once group status is set

Source

pub fn discharge_io(&mut self, status: bool)

Discharge the IOs for subsequent acquisition

Source§

impl<'d, T: Instance> Tsc<'d, T, Async>

Source

pub fn new_async( peri: impl Peripheral<P = T> + 'd, pin_groups: PinGroups<'d, T>, config: Config, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, ) -> Result<Self, GroupError>

Create a Tsc instance that can be awaited for completion

Source

pub async fn pend_for_acquisition(&mut self)

Asyncronously wait for the end of an acquisition

Source§

impl<'d, T: Instance> Tsc<'d, T, Blocking>

Source

pub fn new_blocking( peri: impl Peripheral<P = T> + 'd, pin_groups: PinGroups<'d, T>, config: Config, ) -> Result<Self, GroupError>

Create a Tsc instance that must be polled for completion

Source

pub fn poll_for_acquisition(&mut self)

Wait for end of acquisition

Trait Implementations§

Source§

impl<'d, T: Instance, K: PeriMode> Drop for Tsc<'d, T, K>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'d, T, K> Freeze for Tsc<'d, T, K>
where T: Freeze,

§

impl<'d, T, K> RefUnwindSafe for Tsc<'d, T, K>

§

impl<'d, T, K> Send for Tsc<'d, T, K>
where T: Send, K: Send,

§

impl<'d, T, K> Sync for Tsc<'d, T, K>
where T: Sync, K: Sync,

§

impl<'d, T, K> Unpin for Tsc<'d, T, K>
where T: Unpin, K: Unpin,

§

impl<'d, T, K> !UnwindSafe for Tsc<'d, T, K>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.