Skip to content

Commit ed09c2a

Browse files
Add unused pin functionality
1 parent 1924bb1 commit ed09c2a

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/gpio.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ pub struct PushPull;
6161

6262
use embedded_hal::digital::{toggleable, InputPin, OutputPin, StatefulOutputPin};
6363

64+
/// Unused pin
65+
///
66+
/// Usefull if you don't want to utilize some part of a peripheral,
67+
/// but a pin parameter is required
68+
pub struct Unused {
69+
data: PhantomData<()>,
70+
}
71+
impl Unused {
72+
/// Create a new unused pin
73+
pub fn new() -> Self {
74+
Self { data: PhantomData }
75+
}
76+
}
77+
6478
/// Fully erased pin
6579
pub struct Pin<MODE> {
6680
i: u8,

src/i2c.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ macro_rules! i2c {
113113
($($I2C:ident: ($i2c:ident, $i2cXen:ident, $i2cXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
114114
$(
115115
use crate::stm32::$I2C;
116+
117+
impl SclPin<$I2C> for Unused {}
118+
impl SdaPin<$I2C> for Unused {}
119+
116120
impl<SCLPIN, SDAPIN> I2c<$I2C, SCLPIN, SDAPIN> {
117121
pub fn $i2c(i2c: $I2C, pins: (SCLPIN, SDAPIN), speed: KiloHertz) -> Self
118122
where

src/serial.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ macro_rules! usart {
168168
($($USART:ident: ($usart:ident, $usartXen:ident, $apbenr:ident),)+) => {
169169
$(
170170
use crate::stm32::$USART;
171+
172+
impl RxPin<$USART> for Unused {}
173+
impl TxPin<$USART> for Unused {}
174+
171175
impl<TXPIN, RXPIN> Serial<$USART, TXPIN, RXPIN> {
172176
/// Creates a new serial instance
173177
pub fn $usart(usart: $USART, pins: (TXPIN, RXPIN), baud_rate: Bps, clocks: Clocks) -> Self

src/spi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ spi_pins! {
112112
macro_rules! spi {
113113
($($SPI:ident: ($spi:ident, $spiXen:ident, $spiXrst:ident, $apbenr:ident, $apbrstr:ident),)+) => {
114114
$(
115+
impl SckPin<$SPI> for Unused {}
116+
impl MisoPin<$SPI> for Unused {}
117+
impl MosiPin<$SPI> for Unused {}
118+
115119
impl<SCKPIN, MISOPIN, MOSIPIN> Spi<$SPI, SCKPIN, MISOPIN, MOSIPIN> {
116120
pub fn $spi<F>(
117121
spi: $SPI,

0 commit comments

Comments
 (0)