Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- impl embedded_hal_1::spi::SpiBus for SPI
- impl embedded_hal_1::digital traits for Pins
- Enable AF1 on GPIOE for pins [13, 14, 15] to support SPI communication
- Allow creating open-drain output pins with pull-up or pull-down

### Fixed

Expand Down
40 changes: 40 additions & 0 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,46 @@ macro_rules! gpio {
$PXi { _mode: PhantomData }
}

/// Configures the pin to operate as a pulled up open drain output pin
pub fn into_pullup_open_drain_output(
self, _cs: &CriticalSection
) -> $PXi<Output<OpenDrain>> {
let offset = 2 * $i;
unsafe {
let reg = &(*$GPIOX::ptr());
reg.pupdr.modify(|r, w| {
w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))
});
reg.otyper.modify(|r, w| {
w.bits(r.bits() | (0b1 << $i))
});
reg.moder.modify(|r, w| {
w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))
});
}
$PXi { _mode: PhantomData }
}

/// Configures the pin to operate as a pulled down open drain output pin
pub fn into_pulldown_open_drain_output(
self, _cs: &CriticalSection
) -> $PXi<Output<OpenDrain>> {
let offset = 2 * $i;
unsafe {
let reg = &(*$GPIOX::ptr());
reg.pupdr.modify(|r, w| {
w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))
});
reg.otyper.modify(|r, w| {
w.bits(r.bits() | (0b1 << $i))
});
reg.moder.modify(|r, w| {
w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))
});
}
$PXi { _mode: PhantomData }
}

/// Configures the pin to operate as an push pull output pin
pub fn into_push_pull_output(
self, _cs: &CriticalSection
Expand Down
Loading