Skip to content

Commit 006a8ed

Browse files
committed
Allow inverting comparator on the fly
1 parent f51452f commit 006a8ed

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/comparator.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,35 @@ impl Config {
9393
self
9494
}
9595

96+
/// Invert the comparator output
97+
///
98+
/// NOTE: This does NOT affect the value read by [Comparator::output]
99+
///
100+
/// The following observers are affected by this setting
101+
/// * Pin output
102+
/// * EXTI interrupt/wakeup
103+
/// * TIMx
104+
///
105+
/// The following observers are NOT affected by this setting
106+
/// * HRTIM
107+
/// * Software using [Comparator::output]
96108
pub fn output_inverted(mut self) -> Self {
97109
self.inverted = true;
98110
self
99111
}
100112

113+
/// Invert the comparator output
114+
///
115+
/// NOTE: This does NOT affect the value read by [Comparator::output]
116+
///
117+
/// The following observers are affected by this setting
118+
/// * Pin output
119+
/// * EXTI interrupt/wakeup
120+
/// * TIMx
121+
///
122+
/// The following observers are NOT affected by this setting
123+
/// * HRTIM
124+
/// * Software using [Comparator::output]
101125
pub fn output_polarity(mut self, inverted: bool) -> Self {
102126
self.inverted = inverted;
103127
self
@@ -451,7 +475,25 @@ macro_rules! impl_comparator {
451475
}
452476

453477
impl<ED: EnabledState> Comparator<$COMP, ED> {
478+
/// Invert the comparator output
479+
///
480+
/// NOTE: This does NOT affect the value read by [Comparator::output]
481+
///
482+
/// The following observers are affected by this setting
483+
/// * Pin output
484+
/// * EXTI interrupt/wakeup
485+
/// * TIMx
486+
///
487+
/// The following observers are NOT affected by this setting
488+
/// * HRTIM
489+
/// * Software using [Comparator::output]
490+
pub fn set_inverted(&mut self, inverted: bool) {
491+
self.regs.csr().modify(|_, w| w.pol().bit(inverted));
492+
}
493+
454494
/// Returns the value of the output of the comparator
495+
///
496+
/// NOTE: This is taken before any potential inversion
455497
pub fn output(&self) -> bool {
456498
self.regs.csr().read().value().bit_is_set()
457499
}

0 commit comments

Comments
 (0)