Skip to content

Commit

Permalink
Merge pull request #424 from BartMassey-upstream/high-drive
Browse files Browse the repository at this point in the history
Add method for controlling GPIO push-pull output drive
  • Loading branch information
qwandor authored Feb 21, 2024
2 parents 5afbbab + ec8380f commit b05db68
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions nrf-hal-common/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ impl<MODE> Pin<MODE> {
}
}

/// Convert the pin to be a push-pull output with normal drive.
pub fn into_push_pull_output(self, initial_output: Level) -> Pin<Output<PushPull>> {
/// Convert the pin to be a push-pull output with specified drive.
pub fn into_push_pull_output_drive(self, initial_output: Level, drive: DriveConfig) ->
Pin<Output<PushPull>>
{
let mut pin = Pin {
_mode: PhantomData,
pin_port: self.pin_port,
Expand All @@ -247,14 +249,24 @@ impl<MODE> Pin<MODE> {
w.dir().output();
w.input().connect(); // AJM - hack for SPI
w.pull().disabled();
w.drive().s0s1();
match drive {
DriveConfig::Standard0Standard1 => w.drive().s0s1(),
DriveConfig::Standard0HighDrive1 => w.drive().s0h1(),
DriveConfig::HighDrive0Standard1 => w.drive().h0s1(),
DriveConfig::HighDrive0HighDrive1 => w.drive().h0h1(),
};
w.sense().disabled();
w
});

pin
}

/// Convert the pin to be a push-pull output with specified initial output level.
pub fn into_push_pull_output(self, initial_output: Level) -> Pin<Output<PushPull>> {
self.into_push_pull_output_drive(initial_output, DriveConfig::Standard0Standard1)
}

/// Convert the pin to be an open-drain output.
///
/// This method currently does not support configuring an internal pull-up or pull-down
Expand Down Expand Up @@ -406,6 +418,14 @@ pub enum OpenDrainConfig {
HighDrive0Disconnect1,
}

/// Pin configuration for output drive.
pub enum DriveConfig {
Standard0Standard1,
Standard0HighDrive1,
HighDrive0Standard1,
HighDrive0HighDrive1,
}

#[cfg(feature = "51")]
use crate::pac::gpio::pin_cnf;

Expand Down Expand Up @@ -447,6 +467,7 @@ macro_rules! gpio {

Floating,
Disconnected,
DriveConfig,
Input,
Level,
OpenDrain,
Expand Down Expand Up @@ -544,8 +565,8 @@ macro_rules! gpio {
}
}

/// Convert the pin to bepin a push-pull output with normal drive
pub fn into_push_pull_output(self, initial_output: Level)
/// Convert the pin to bepin a push-pull output with specified drive
pub fn into_push_pull_output_drive(self, initial_output: Level, drive: DriveConfig)
-> $PXi<Output<PushPull>>
{
let mut pin = $PXi {
Expand All @@ -561,14 +582,26 @@ macro_rules! gpio {
w.dir().output();
w.input().disconnect();
w.pull().disabled();
w.drive().s0s1();
match drive {
DriveConfig::Standard0Standard1 => w.drive().s0s1(),
DriveConfig::Standard0HighDrive1 => w.drive().s0h1(),
DriveConfig::HighDrive0Standard1 => w.drive().h0s1(),
DriveConfig::HighDrive0HighDrive1 => w.drive().h0h1(),
};
w.sense().disabled();
w
});

pin
}

/// Convert the pin to bepin a push-pull output with normal drive
pub fn into_push_pull_output(self, initial_output: Level)
-> $PXi<Output<PushPull>>
{
self.into_push_pull_output_drive(initial_output, DriveConfig::Standard0Standard1)
}

/// Convert the pin to be an open-drain output
///
/// This method currently does not support configuring an
Expand Down

0 comments on commit b05db68

Please sign in to comment.