Merge pull request #1994 from jcdickinson/pin_params

feat (rp2040): allow schmitt, slew, and drive strength be set from Flex, Input, Output
This commit is contained in:
Dario Nieuwenhuis 2023-10-02 10:44:19 +00:00 committed by GitHub
commit 5f6a915a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -97,6 +97,12 @@ impl<'d, T: Pin> Input<'d, T> {
Self { pin }
}
/// Set the pin's Schmitt trigger.
#[inline]
pub fn set_schmitt(&mut self, enable: bool) {
self.pin.set_schmitt(enable)
}
#[inline]
pub fn is_high(&self) -> bool {
self.pin.is_high()
@ -326,6 +332,18 @@ impl<'d, T: Pin> Output<'d, T> {
Self { pin }
}
/// Set the pin's drive strength.
#[inline]
pub fn set_drive_strength(&mut self, strength: Drive) {
self.pin.set_drive_strength(strength)
}
// Set the pin's slew rate.
#[inline]
pub fn set_slew_rate(&mut self, slew_rate: SlewRate) {
self.pin.set_slew_rate(slew_rate)
}
/// Set the output as high.
#[inline]
pub fn set_high(&mut self) {
@ -386,6 +404,18 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
Self { pin }
}
/// Set the pin's drive strength.
#[inline]
pub fn set_drive_strength(&mut self, strength: Drive) {
self.pin.set_drive_strength(strength)
}
// Set the pin's slew rate.
#[inline]
pub fn set_slew_rate(&mut self, slew_rate: SlewRate) {
self.pin.set_slew_rate(slew_rate)
}
/// Set the output as high.
#[inline]
pub fn set_high(&mut self) {
@ -541,6 +571,14 @@ impl<'d, T: Pin> Flex<'d, T> {
});
}
/// Set the pin's Schmitt trigger.
#[inline]
pub fn set_schmitt(&mut self, enable: bool) {
self.pin.pad_ctrl().modify(|w| {
w.set_schmitt(enable);
});
}
/// Put the pin into input mode.
///
/// The pull setting is left unchanged.

View File

@ -78,6 +78,9 @@ async fn main(_spawner: Spawner) {
// Set up the signal pin that will be used to trigger the keyboard.
let mut signal_pin = Input::new(p.PIN_16, Pull::None);
// Enable the schmitt trigger to slightly debounce.
signal_pin.set_schmitt(true);
let (reader, mut writer) = hid.split();
// Do stuff with the class!