Skip to content

Commit

Permalink
Merge pull request #768 from ithinuel/add-getters-to-gpio-pads
Browse files Browse the repository at this point in the history
gpio: Add getters to the various pad overrides (not type tracked)
  • Loading branch information
jannic authored Feb 12, 2024
2 parents 099e34f + c99bf2a commit 9296ebc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions rp2040-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,18 @@ impl<I: PinId, F: func::Function, P: PullType> Pin<I, F, P> {
// =======================
// IO related methods

/// Get the input override.
#[inline]
pub fn get_input_override(&self) -> InputOverride {
use pac::io_bank0::gpio::gpio_ctrl::INOVER_A;
match self.id.io_ctrl().read().inover().variant() {
INOVER_A::NORMAL => InputOverride::Normal,
INOVER_A::INVERT => InputOverride::Invert,
INOVER_A::LOW => InputOverride::AlwaysLow,
INOVER_A::HIGH => InputOverride::AlwaysHigh,
}
}

/// Set the input override.
#[inline]
pub fn set_input_override(&mut self, override_value: InputOverride) {
Expand All @@ -535,6 +547,18 @@ impl<I: PinId, F: func::Function, P: PullType> Pin<I, F, P> {
self.id.io_ctrl().modify(|_, w| w.inover().variant(variant));
}

/// Get the output enable override.
#[inline]
pub fn get_output_enable_override(&self) -> OutputEnableOverride {
use pac::io_bank0::gpio::gpio_ctrl::OEOVER_A;
match self.id.io_ctrl().read().oeover().variant() {
OEOVER_A::NORMAL => OutputEnableOverride::Normal,
OEOVER_A::INVERT => OutputEnableOverride::Invert,
OEOVER_A::DISABLE => OutputEnableOverride::Disable,
OEOVER_A::ENABLE => OutputEnableOverride::Enable,
}
}

/// Set the output enable override.
#[inline]
pub fn set_output_enable_override(&mut self, override_value: OutputEnableOverride) {
Expand All @@ -548,6 +572,18 @@ impl<I: PinId, F: func::Function, P: PullType> Pin<I, F, P> {
self.id.io_ctrl().modify(|_, w| w.oeover().variant(variant));
}

/// Get the output override.
#[inline]
pub fn get_output_override(&self) -> OutputOverride {
use pac::io_bank0::gpio::gpio_ctrl::OUTOVER_A;
match self.id.io_ctrl().read().outover().variant() {
OUTOVER_A::NORMAL => OutputOverride::DontInvert,
OUTOVER_A::INVERT => OutputOverride::Invert,
OUTOVER_A::LOW => OutputOverride::AlwaysLow,
OUTOVER_A::HIGH => OutputOverride::AlwaysHigh,
}
}

/// Set the output override.
#[inline]
pub fn set_output_override(&mut self, override_value: OutputOverride) {
Expand All @@ -563,6 +599,18 @@ impl<I: PinId, F: func::Function, P: PullType> Pin<I, F, P> {
.modify(|_, w| w.outover().variant(variant));
}

/// Get the interrupt override.
#[inline]
pub fn get_interrupt_override(&self) -> InterruptOverride {
use pac::io_bank0::gpio::gpio_ctrl::IRQOVER_A;
match self.id.io_ctrl().read().irqover().variant() {
IRQOVER_A::NORMAL => InterruptOverride::Normal,
IRQOVER_A::INVERT => InterruptOverride::Invert,
IRQOVER_A::LOW => InterruptOverride::AlwaysLow,
IRQOVER_A::HIGH => InterruptOverride::AlwaysHigh,
}
}

/// Set the interrupt override.
#[inline]
pub fn set_interrupt_override(&mut self, override_value: InterruptOverride) {
Expand Down

0 comments on commit 9296ebc

Please sign in to comment.