Add IOConfig struct and pub fn io_config()

The STM32 TSC needs to do successive acquisitions when using multiple channels in a group. To do this the IOs must be configured for each acquisition. This change reflects the implementations in the STM32 HAL.

See:
* https://community.st.com/t5/stm32-mcus-products/tsc-channel-selection/td-p/164783

Specifically, see the HAL solution provided. It shows that only one acquisition channel must enabled in a group during an acquisition cycle, then the next channel in the next acquisition cycle, and so on.


* https://www.st.com/content/ccc/resource/technical/document/user_manual/group0/d6/4c/20/0d/a1/c1/4c/99/DM00210526/files/DM00210526.pdf/jcr:content/translations/en.DM00210526.pdf

While this is about the STM Touch Library, table 8 (and others) show the acquisition timings required for multiple channels in a group.
This commit is contained in:
Chris Yates 2024-08-20 20:05:56 +01:00 committed by GitHub
parent 1c466b81e6
commit ebfbcc40be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -227,6 +227,15 @@ impl Default for Config {
}
}
pub struct IOConfig {
/// Channel IO mask
pub channel_ios: u32,
/// Shield IO mask
pub shield_ios: u32,
/// Sampling IO mask
pub sampling_ios: u32,
}
/// Pin struct that maintains usage
#[allow(missing_docs)]
pub struct TscPin<'d, T, C> {
@ -761,6 +770,27 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
groups
}
pub fn io_config(&mut self, config: &IOConfig) {
// Disable Schmitt trigger hysteresis on all used TSC IOs
T::regs()
.iohcr()
.write(|w| w.0 = !(config.channel_ios | config.shield_ios | config.sampling_ios));
// Set channel and shield IOs
T::regs()
.ioccr()
.write(|w| w.0 = config.channel_ios | config.shield_ios);
// Set sampling IOs
T::regs().ioscr().write(|w| w.0 = config.sampling_ios);
// Set the groups to be acquired
T::regs()
.iogcsr()
.write(|w| w.0 = Self::extract_groups(config.channel_ios));
}
fn new_inner(
peri: impl Peripheral<P = T> + 'd,
g1: Option<PinGroup<'d, T, G1>>,
@ -804,6 +834,15 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
});
// Set IO configuration
let io_config = IOConfig {
channel_ios: config.channel_ios,
sampling_ios: config.sampling_ios,
shield_ios: config.shield_ios,
};
Self.io_config(&io_config);
/*
// Disable Schmitt trigger hysteresis on all used TSC IOs
T::regs()
.iohcr()
@ -822,6 +861,8 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> {
.iogcsr()
.write(|w| w.0 = Self::extract_groups(config.channel_ios));
*/
// Disable interrupts
T::regs().ier().modify(|w| {
w.set_eoaie(false);