diff options
| author | Jonathan Dickinson <[email protected]> | 2023-10-01 21:47:50 -0400 |
|---|---|---|
| committer | Jonathan Dickinson <[email protected]> | 2023-10-01 21:49:14 -0400 |
| commit | f98c8886b21099072b9373e7b194e6495291008e (patch) | |
| tree | 8cb77291190f27128c5a3c1dbe576011eb9bd196 | |
| parent | a1036e111eddf82462ce3f6e50923bded89af450 (diff) | |
feat: allow schmitt, slew, and drive strength be set from Flex, Input, Output
Allows the schmitt, slew and drive strength to be set from Flex. Input and Output[OpenDrain] also expose the appropriate setters.
| -rw-r--r-- | embassy-rp/src/gpio.rs | 38 | ||||
| -rw-r--r-- | examples/rp/src/bin/usb_hid_keyboard.rs | 3 |
2 files changed, 41 insertions, 0 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index ad9d4262d..33bc58a0f 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -97,6 +97,12 @@ impl<'d, T: Pin> Input<'d, T> { | |||
| 97 | Self { pin } | 97 | Self { pin } |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | /// Set the pin's Schmitt trigger. | ||
| 101 | #[inline] | ||
| 102 | pub fn set_schmitt(&mut self, enable: bool) { | ||
| 103 | self.pin.set_schmitt(enable) | ||
| 104 | } | ||
| 105 | |||
| 100 | #[inline] | 106 | #[inline] |
| 101 | pub fn is_high(&self) -> bool { | 107 | pub fn is_high(&self) -> bool { |
| 102 | self.pin.is_high() | 108 | self.pin.is_high() |
| @@ -326,6 +332,18 @@ impl<'d, T: Pin> Output<'d, T> { | |||
| 326 | Self { pin } | 332 | Self { pin } |
| 327 | } | 333 | } |
| 328 | 334 | ||
| 335 | /// Set the pin's drive strength. | ||
| 336 | #[inline] | ||
| 337 | pub fn set_drive_strength(&mut self, strength: Drive) { | ||
| 338 | self.pin.set_drive_strength(strength) | ||
| 339 | } | ||
| 340 | |||
| 341 | // Set the pin's slew rate. | ||
| 342 | #[inline] | ||
| 343 | pub fn set_slew_rate(&mut self, slew_rate: SlewRate) { | ||
| 344 | self.pin.set_slew_rate(slew_rate) | ||
| 345 | } | ||
| 346 | |||
| 329 | /// Set the output as high. | 347 | /// Set the output as high. |
| 330 | #[inline] | 348 | #[inline] |
| 331 | pub fn set_high(&mut self) { | 349 | pub fn set_high(&mut self) { |
| @@ -386,6 +404,18 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||
| 386 | Self { pin } | 404 | Self { pin } |
| 387 | } | 405 | } |
| 388 | 406 | ||
| 407 | /// Set the pin's drive strength. | ||
| 408 | #[inline] | ||
| 409 | pub fn set_drive_strength(&mut self, strength: Drive) { | ||
| 410 | self.pin.set_drive_strength(strength) | ||
| 411 | } | ||
| 412 | |||
| 413 | // Set the pin's slew rate. | ||
| 414 | #[inline] | ||
| 415 | pub fn set_slew_rate(&mut self, slew_rate: SlewRate) { | ||
| 416 | self.pin.set_slew_rate(slew_rate) | ||
| 417 | } | ||
| 418 | |||
| 389 | /// Set the output as high. | 419 | /// Set the output as high. |
| 390 | #[inline] | 420 | #[inline] |
| 391 | pub fn set_high(&mut self) { | 421 | pub fn set_high(&mut self) { |
| @@ -541,6 +571,14 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 541 | }); | 571 | }); |
| 542 | } | 572 | } |
| 543 | 573 | ||
| 574 | /// Set the pin's Schmitt trigger. | ||
| 575 | #[inline] | ||
| 576 | pub fn set_schmitt(&mut self, enable: bool) { | ||
| 577 | self.pin.pad_ctrl().modify(|w| { | ||
| 578 | w.set_schmitt(enable); | ||
| 579 | }); | ||
| 580 | } | ||
| 581 | |||
| 544 | /// Put the pin into input mode. | 582 | /// Put the pin into input mode. |
| 545 | /// | 583 | /// |
| 546 | /// The pull setting is left unchanged. | 584 | /// The pull setting is left unchanged. |
diff --git a/examples/rp/src/bin/usb_hid_keyboard.rs b/examples/rp/src/bin/usb_hid_keyboard.rs index 99af1f02f..cc2090d22 100644 --- a/examples/rp/src/bin/usb_hid_keyboard.rs +++ b/examples/rp/src/bin/usb_hid_keyboard.rs | |||
| @@ -78,6 +78,9 @@ async fn main(_spawner: Spawner) { | |||
| 78 | // Set up the signal pin that will be used to trigger the keyboard. | 78 | // Set up the signal pin that will be used to trigger the keyboard. |
| 79 | let mut signal_pin = Input::new(p.PIN_16, Pull::None); | 79 | let mut signal_pin = Input::new(p.PIN_16, Pull::None); |
| 80 | 80 | ||
| 81 | // Enable the schmitt trigger to slightly debounce. | ||
| 82 | signal_pin.set_schmitt(true); | ||
| 83 | |||
| 81 | let (reader, mut writer) = hid.split(); | 84 | let (reader, mut writer) = hid.split(); |
| 82 | 85 | ||
| 83 | // Do stuff with the class! | 86 | // Do stuff with the class! |
