Skip to content

Commit

Permalink
Deduplicate handle_rtcio macros
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 12, 2024
1 parent a00c046 commit 43d06b5
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 163 deletions.
18 changes: 0 additions & 18 deletions esp-hal/src/gpio/lp_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,6 @@ macro_rules! lp_gpio {
}
}
)+

#[doc(hidden)]
#[macro_export]
macro_rules! handle_rtcio {
($this:expr, $inner:ident, $code:tt) => {
match $this {
$(
AnyPinInner::[<Gpio $gpionum >]($inner) => {
$code
},
)+

_ => panic!("Unsupported")
}
}
}
pub(crate) use handle_rtcio;
pub(crate) use handle_rtcio as handle_rtcio_with_resistors;
}
}
}
126 changes: 63 additions & 63 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,17 +873,32 @@ fn on_pin_irq(pin_nr: u8) {
#[macro_export]
macro_rules! if_output_pin {
// Base case: not an Output pin, substitute the else branch
({ $($then:tt)* } else { $($else:tt)* } ) => { $($else)* };
({ $($then:tt)* } else { $($else:tt)* }) => { $($else)* };

// First is an output pin, skip checking and substitute the then branch
(Output $(, $other:ident)* { $($then:tt)* } else { $($else:tt)* } ) => { $($then)* };
// First is an Output pin, skip checking and substitute the then branch
(Output $(, $other:ident)* { $($then:tt)* } else { $($else:tt)* }) => { $($then)* };

// First is not an output pin, check the rest
($not_output:ident $(, $other:ident)* { $($then:tt)* } else { $($else:tt)* } ) => {
// First is not an Output pin, check the rest
($not:ident $(, $other:ident)* { $($then:tt)* } else { $($else:tt)* }) => {
$crate::if_output_pin!($($other),* { $($then)* } else { $($else)* })
};
}

#[doc(hidden)]
#[macro_export]
macro_rules! if_rtcio_pin {
// Base case: not an RtcIo pin, substitute the else branch
({ $($then:tt)* } else { $($else:tt)* }) => { $($else)* };

// First is an RtcIo pin, skip checking and substitute the then branch
(RtcIo $(, $other:ident)* { $($then:tt)* } else { $($else:tt)* }) => { $($then)* };

// First is not an RtcIo pin, check the rest
($not:ident $(, $other:ident)* { $($then:tt)* } else { $($else:tt)* }) => {
$crate::if_rtcio_pin!($($other),* { $($then)* } else { $($else)* })
};
}

#[doc(hidden)]
#[macro_export]
macro_rules! io_type {
Expand Down Expand Up @@ -917,6 +932,7 @@ macro_rules! io_type {
}
}
};
(RtcIo, $gpionum:literal) => {};
}

#[doc(hidden)]
Expand Down Expand Up @@ -1059,8 +1075,50 @@ macro_rules! gpio {
}
}

#[doc(hidden)]
#[macro_export]
macro_rules! handle_rtcio {
($this:expr, $inner:ident, $code:tt) => {
match $this {
$(
AnyPinInner::[<Gpio $gpionum >]($inner) => $crate::if_rtcio_pin!($($type),* {
$code
} else {{
let _ = $inner;
panic!("Unsupported")
}}),
)+
}
}
}

#[doc(hidden)]
#[macro_export]
macro_rules! handle_rtcio_with_resistors {
($this:expr, $inner:ident, $code:tt) => {
match $this {
$(
AnyPinInner::[<Gpio $gpionum >]($inner) => $crate::if_rtcio_pin!($($type),* {
$crate::if_output_pin!($($type),* {
$code
} else {{
let _ = $inner;
panic!("Unsupported")
}})
} else {{
let _ = $inner;
panic!("Unsupported")
}}),
)+
}
}
}

pub(crate) use handle_gpio_output;
pub(crate) use handle_gpio_input;

pub(crate) use handle_rtcio;
pub(crate) use handle_rtcio_with_resistors;
}
};
}
Expand Down Expand Up @@ -1110,25 +1168,6 @@ macro_rules! rtc_pins {

( $( $pin_num:expr )+ ) => {
$( $crate::rtc_pins!($pin_num); )+

#[doc(hidden)]
#[macro_export]
macro_rules! handle_rtcio {
($this:expr, $inner:ident, $code:tt) => {
match $this {
$(
paste::paste! { AnyPinInner::[<Gpio $pin_num >]($inner) } => {
$code
},
)+

_ => panic!("Unsupported")
}
}
}

pub(crate) use handle_rtcio;
pub(crate) use handle_rtcio as handle_rtcio_with_resistors;
};
}

Expand Down Expand Up @@ -1292,45 +1331,6 @@ macro_rules! rtcio_analog {
pin.rtcio_pulldown(pull_down);
}
}

#[doc(hidden)]
#[macro_export]
macro_rules! handle_rtcio {
($this:expr, $inner:ident, $code:tt) => {
match $this {
$(
paste::paste! { AnyPinInner::[<Gpio $pin_num >]($inner) } => {
$code
},
)+

_ => panic!("Unsupported")
}
}
}

#[doc(hidden)]
#[macro_export]
macro_rules! handle_rtcio_with_resistors {
(@ignore $a:tt) => {};
($this:expr, $inner:ident, $code:tt) => {
match $this {
$(
$(
paste::paste! { AnyPinInner::[<Gpio $pin_num >]($inner) } => {
// FIXME: replace with $(ignore($rue)) once stable
handle_rtcio_with_resistors!(@ignore $rue);
$code
},
)?
)+

_ => panic!("Unsupported")
}
}
}
pub(crate) use handle_rtcio;
pub(crate) use handle_rtcio_with_resistors;
};
}

Expand Down
36 changes: 18 additions & 18 deletions esp-hal/src/soc/esp32/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,22 +528,22 @@ pub enum OutputSignal {
}

crate::gpio! {
(0, 0, [Input, Output, Analog, Touch] (5 => EMAC_TX_CLK) (1 => CLK_OUT1))
(0, 0, [Input, Output, Analog, RtcIo, Touch] (5 => EMAC_TX_CLK) (1 => CLK_OUT1))
(1, 0, [Input, Output] (5 => EMAC_RXD2) (0 => U0TXD 1 => CLK_OUT3))
(2, 0, [Input, Output, Analog, Touch] (1 => HSPIWP 3 => HS2_DATA0 4 => SD_DATA0) (3 => HS2_DATA0 4 => SD_DATA0))
(2, 0, [Input, Output, Analog, RtcIo, Touch] (1 => HSPIWP 3 => HS2_DATA0 4 => SD_DATA0) (3 => HS2_DATA0 4 => SD_DATA0))
(3, 0, [Input, Output] (0 => U0RXD) (1 => CLK_OUT2))
(4, 0, [Input, Output, Analog, Touch] (1 => HSPIHD 3 => HS2_DATA1 4 => SD_DATA1 5 => EMAC_TX_ER) (3 => HS2_DATA1 4 => SD_DATA1))
(4, 0, [Input, Output, Analog, RtcIo, Touch] (1 => HSPIHD 3 => HS2_DATA1 4 => SD_DATA1 5 => EMAC_TX_ER) (3 => HS2_DATA1 4 => SD_DATA1))
(5, 0, [Input, Output] (1 => VSPICS0 3 => HS1_DATA6 5 => EMAC_RX_CLK) (3 => HS1_DATA6))
(6, 0, [Input, Output] (4 => U1CTS) (0 => SD_CLK 1 => SPICLK 3 => HS1_CLK))
(7, 0, [Input, Output] (0 => SD_DATA0 1 => SPIQ 3 => HS1_DATA0) (0 => SD_DATA0 1 => SPIQ 3 => HS1_DATA0 4 => U2RTS))
(8, 0, [Input, Output] (0 => SD_DATA1 1 => SPID 3 => HS1_DATA1 4 => U2CTS) (0 => SD_DATA1 1 => SPID 3 => HS1_DATA1))
(9, 0, [Input, Output] (0 => SD_DATA2 1 => SPIHD 3 => HS1_DATA2 4 => U1RXD) (0 => SD_DATA2 1 => SPIHD 3 => HS1_DATA2))
(10, 0, [Input, Output] ( 0 => SD_DATA3 1 => SPIWP 3 => HS1_DATA3) (0 => SD_DATA3 1 => SPIWP 3 => HS1_DATA3 4 => U1TXD))
(11, 0, [Input, Output] ( 1 => SPICS0) (0 => SD_CMD 1 => SPICS0 3 => HS1_CMD 4 => U1RTS))
(12, 0, [Input, Output, Analog, Touch] (0 => MTDI 1 => HSPIQ 3 => HS2_DATA2 4 => SD_DATA2) (1 => HSPIQ 3 => HS2_DATA2 4 => SD_DATA2 5 => EMAC_TXD3))
(13, 0, [Input, Output, Analog, Touch] (0 => MTCK 1 => HSPID 3 => HS2_DATA3 4 => SD_DATA3) (1 => HSPID 3 => HS2_DATA3 4 => SD_DATA3 5 => EMAC_RX_ER))
(14, 0, [Input, Output, Analog, Touch] (0 => MTMS 1 => HSPICLK) (1 => HSPICLK 3 => HS2_CLK 4 => SD_CLK 5 => EMAC_TXD2))
(15, 0, [Input, Output, Analog, Touch] (1 => HSPICS0 5 => EMAC_RXD3) (0 => MTDO 1 => HSPICS0 3 => HS2_CMD 4 => SD_CMD))
(12, 0, [Input, Output, Analog, RtcIo, Touch] (0 => MTDI 1 => HSPIQ 3 => HS2_DATA2 4 => SD_DATA2) (1 => HSPIQ 3 => HS2_DATA2 4 => SD_DATA2 5 => EMAC_TXD3))
(13, 0, [Input, Output, Analog, RtcIo, Touch] (0 => MTCK 1 => HSPID 3 => HS2_DATA3 4 => SD_DATA3) (1 => HSPID 3 => HS2_DATA3 4 => SD_DATA3 5 => EMAC_RX_ER))
(14, 0, [Input, Output, Analog, RtcIo, Touch] (0 => MTMS 1 => HSPICLK) (1 => HSPICLK 3 => HS2_CLK 4 => SD_CLK 5 => EMAC_TXD2))
(15, 0, [Input, Output, Analog, RtcIo, Touch] (1 => HSPICS0 5 => EMAC_RXD3) (0 => MTDO 1 => HSPICS0 3 => HS2_CMD 4 => SD_CMD))
(16, 0, [Input, Output] (3 => HS1_DATA4 4 => U2RXD) (3 => HS1_DATA4 5 => EMAC_CLK_OUT))
(17, 0, [Input, Output] (3 => HS1_DATA5) (3 => HS1_DATA5 4 => U2TXD 5 => EMAC_CLK_180))
(18, 0, [Input, Output] (1 => VSPICLK 3 => HS1_DATA7) (1 => VSPICLK 3 => HS1_DATA7))
Expand All @@ -553,17 +553,17 @@ crate::gpio! {
(22, 0, [Input, Output] (1 => VSPIWP) (1 => VSPIWP 3 => U0RTS 5 => EMAC_TXD1))
(23, 0, [Input, Output] (1 => VSPID) (1 => VSPID 3 => HS1_STROBE))
(24, 0, [Input, Output])
(25, 0, [Input, Output, Analog] (5 => EMAC_RXD0) ())
(26, 0, [Input, Output, Analog] (5 => EMAC_RXD1) ())
(27, 0, [Input, Output, Analog, Touch] (5 => EMAC_RX_DV) ())
(32, 1, [Input, Output, Analog, Touch])
(33, 1, [Input, Output, Analog, Touch])
(34, 1, [Input, Analog])
(35, 1, [Input, Analog])
(36, 1, [Input, Analog])
(37, 1, [Input, Analog])
(38, 1, [Input, Analog])
(39, 1, [Input, Analog])
(25, 0, [Input, Output, Analog, RtcIo] (5 => EMAC_RXD0) ())
(26, 0, [Input, Output, Analog, RtcIo] (5 => EMAC_RXD1) ())
(27, 0, [Input, Output, Analog, RtcIo, Touch] (5 => EMAC_RX_DV) ())
(32, 1, [Input, Output, Analog, RtcIo, Touch])
(33, 1, [Input, Output, Analog, RtcIo, Touch])
(34, 1, [Input, Analog, RtcIo])
(35, 1, [Input, Analog, RtcIo])
(36, 1, [Input, Analog, RtcIo])
(37, 1, [Input, Analog, RtcIo])
(38, 1, [Input, Analog, RtcIo])
(39, 1, [Input, Analog, RtcIo])
}

crate::rtcio_analog! {
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/soc/esp32c2/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ pub enum OutputSignal {
}

crate::gpio! {
(0, 0, [Input, Output, Analog])
(1, 0, [Input, Output, Analog])
(2, 0, [Input, Output, Analog] (2 => FSPIQ) (2 => FSPIQ))
(3, 0, [Input, Output, Analog])
(4, 0, [Input, Output, Analog] (2 => FSPIHD) (2 => FSPIHD))
(5, 0, [Input, Output] (2 => FSPIWP) (2 => FSPIWP))
(0, 0, [Input, Output, Analog, RtcIo])
(1, 0, [Input, Output, Analog, RtcIo])
(2, 0, [Input, Output, Analog, RtcIo] (2 => FSPIQ) (2 => FSPIQ))
(3, 0, [Input, Output, Analog, RtcIo])
(4, 0, [Input, Output, Analog, RtcIo] (2 => FSPIHD) (2 => FSPIHD))
(5, 0, [Input, Output, Analog, RtcIo] (2 => FSPIWP) (2 => FSPIWP))
(6, 0, [Input, Output] (2 => FSPICLK) (2 => FSPICLK_MUX))
(7, 0, [Input, Output] (2 => FSPID) (2 => FSPID))
(8, 0, [Input, Output])
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/soc/esp32c3/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ pub enum OutputSignal {
}

crate::gpio! {
(0, 0, [Input, Output, Analog])
(1, 0, [Input, Output, Analog])
(2, 0, [Input, Output, Analog] (2 => FSPIQ) (2 => FSPIQ))
(3, 0, [Input, Output, Analog])
(4, 0, [Input, Output, Analog] (2 => FSPIHD) (0 => USB_JTAG_TMS 2 => FSPIHD))
(5, 0, [Input, Output, Analog] (2 => FSPIWP) (0 => USB_JTAG_TDI 2 => FSPIWP))
(0, 0, [Input, Output, Analog, RtcIo])
(1, 0, [Input, Output, Analog, RtcIo])
(2, 0, [Input, Output, Analog, RtcIo] (2 => FSPIQ) (2 => FSPIQ))
(3, 0, [Input, Output, Analog, RtcIo])
(4, 0, [Input, Output, Analog, RtcIo] (2 => FSPIHD) (0 => USB_JTAG_TMS 2 => FSPIHD))
(5, 0, [Input, Output, Analog, RtcIo] (2 => FSPIWP) (0 => USB_JTAG_TDI 2 => FSPIWP))
(6, 0, [Input, Output] (2 => FSPICLK) (0 => USB_JTAG_TCK 2 => FSPICLK_MUX))
(7, 0, [Input, Output] (2 => FSPID) (0 => USB_JTAG_TDO 2 => FSPID))
(8, 0, [Input, Output])
Expand Down
16 changes: 8 additions & 8 deletions esp-hal/src/soc/esp32c6/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ pub enum OutputSignal {
}

crate::gpio! {
(0, 0, [Input, Output, Analog])
(1, 0, [Input, Output, Analog])
(2, 0, [Input, Output, Analog] (2 => FSPIQ) (2 => FSPIQ))
(3, 0, [Input, Output, Analog])
(4, 0, [Input, Output, Analog] (2 => FSPIHD) (0 => USB_JTAG_TMS 2 => FSPIHD))
(5, 0, [Input, Output, Analog] (2 => FSPIWP) (0 => USB_JTAG_TDI 2 => FSPIWP))
(6, 0, [Input, Output, Analog] (2 => FSPICLK) (0 => USB_JTAG_TCK 2 => FSPICLK_MUX))
(7, 0, [Input, Output, Analog] (2 => FSPID) (0 => USB_JTAG_TDO 2 => FSPID))
(0, 0, [Input, Output, Analog, RtcIo])
(1, 0, [Input, Output, Analog, RtcIo])
(2, 0, [Input, Output, Analog, RtcIo] (2 => FSPIQ) (2 => FSPIQ))
(3, 0, [Input, Output, Analog, RtcIo])
(4, 0, [Input, Output, Analog, RtcIo] (2 => FSPIHD) (0 => USB_JTAG_TMS 2 => FSPIHD))
(5, 0, [Input, Output, Analog, RtcIo] (2 => FSPIWP) (0 => USB_JTAG_TDI 2 => FSPIWP))
(6, 0, [Input, Output, Analog, RtcIo] (2 => FSPICLK) (0 => USB_JTAG_TCK 2 => FSPICLK_MUX))
(7, 0, [Input, Output, Analog, RtcIo] (2 => FSPID) (0 => USB_JTAG_TDO 2 => FSPID))
(8, 0, [Input, Output])
(9, 0, [Input, Output])
(10, 0, [Input, Output])
Expand Down
44 changes: 22 additions & 22 deletions esp-hal/src/soc/esp32s2/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,28 +315,28 @@ pub enum OutputSignal {
}

crate::gpio! {
(0, 0, [Input, Output, Analog])
(1, 0, [Input, Output, Analog])
(2, 0, [Input, Output, Analog])
(3, 0, [Input, Output, Analog])
(4, 0, [Input, Output, Analog])
(5, 0, [Input, Output, Analog])
(6, 0, [Input, Output, Analog])
(7, 0, [Input, Output, Analog])
(8, 0, [Input, Output, Analog])
(9, 0, [Input, Output, Analog])
(10, 0, [Input, Output, Analog])
(11, 0, [Input, Output, Analog])
(12, 0, [Input, Output, Analog])
(13, 0, [Input, Output, Analog])
(14, 0, [Input, Output, Analog])
(15, 0, [Input, Output, Analog])
(16, 0, [Input, Output, Analog])
(17, 0, [Input, Output, Analog])
(18, 0, [Input, Output, Analog])
(19, 0, [Input, Output, Analog])
(20, 0, [Input, Output, Analog])
(21, 0, [Input, Output, Analog])
(0, 0, [Input, Output, Analog, RtcIo])
(1, 0, [Input, Output, Analog, RtcIo])
(2, 0, [Input, Output, Analog, RtcIo])
(3, 0, [Input, Output, Analog, RtcIo])
(4, 0, [Input, Output, Analog, RtcIo])
(5, 0, [Input, Output, Analog, RtcIo])
(6, 0, [Input, Output, Analog, RtcIo])
(7, 0, [Input, Output, Analog, RtcIo])
(8, 0, [Input, Output, Analog, RtcIo])
(9, 0, [Input, Output, Analog, RtcIo])
(10, 0, [Input, Output, Analog, RtcIo])
(11, 0, [Input, Output, Analog, RtcIo])
(12, 0, [Input, Output, Analog, RtcIo])
(13, 0, [Input, Output, Analog, RtcIo])
(14, 0, [Input, Output, Analog, RtcIo])
(15, 0, [Input, Output, Analog, RtcIo])
(16, 0, [Input, Output, Analog, RtcIo])
(17, 0, [Input, Output, Analog, RtcIo])
(18, 0, [Input, Output, Analog, RtcIo])
(19, 0, [Input, Output, Analog, RtcIo])
(20, 0, [Input, Output, Analog, RtcIo])
(21, 0, [Input, Output, Analog, RtcIo])

(26, 0, [Input, Output])
(27, 0, [Input, Output])
Expand Down
Loading

0 comments on commit 43d06b5

Please sign in to comment.