Skip to content

Commit

Permalink
generic: simplify port macro via paste!
Browse files Browse the repository at this point in the history
  • Loading branch information
LuigiPiucco authored and Rahix committed Nov 19, 2023
1 parent aed6b9a commit 063f845
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 611 deletions.
11 changes: 7 additions & 4 deletions arduino-hal/src/port/diecimila.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
pub use atmega_hal::port::{mode, Pin, PinOps, PinMode};
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
type Pin = Pin;

/// Pins of the **Arduino Diecimila**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins from atmega_hal::Pins {
pub struct Pins {
/// `A0`
///
/// * ADC0 (ADC input channel 0)
Expand Down Expand Up @@ -125,4 +123,9 @@ avr_hal_generic::renamed_pins! {
/// * L LED on Arduino Uno
pub d13: atmega_hal::port::PB5 = pb5,
}

impl Pins {
type Pin = Pin;
type McuPins = atmega_hal::Pins;
}
}
11 changes: 7 additions & 4 deletions arduino-hal/src/port/leonardo.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
pub use atmega_hal::port::{mode, Pin, PinOps, PinMode};
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
type Pin = Pin;

/// Pins of the **Arduino Leonardo**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins from atmega_hal::Pins {
pub struct Pins {
/// `D0` / `RX`
///
/// * `RX` (UART)
Expand Down Expand Up @@ -121,4 +119,9 @@ avr_hal_generic::renamed_pins! {
/// * `ADC0` channel
pub a5: atmega_hal::port::PF0 = pf0,
}

impl Pins {
type Pin = Pin;
type McuPins = atmega_hal::Pins;
}
}
15 changes: 9 additions & 6 deletions arduino-hal/src/port/mega.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
pub use atmega_hal::port::{mode, Pin, PinOps, PinMode};
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
type Pin = Pin;

/// Pins of the **Arduino Mega 2560** and **Arduino Mega 1280**.
///
///
/// mega1280:
/// https://www.arduino.cc/en/uploads/Main/arduino-mega-schematic.pdf
/// mega2560:
/// https://www.arduino.cc/en/uploads/Main/arduino-mega2560-schematic.pdf
///
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins from atmega_hal::Pins {
pub struct Pins {
/// `D0` / `RX0`
///
/// * `RXD0` (USART0)
Expand Down Expand Up @@ -337,4 +335,9 @@ avr_hal_generic::renamed_pins! {
/// * `PCINT23`: External Interrupt (Pin Change)
pub a15: atmega_hal::port::PK7 = pk7,
}

impl Pins {
type Pin = Pin;
type McuPins = atmega_hal::Pins;
}
}
11 changes: 7 additions & 4 deletions arduino-hal/src/port/promicro.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
pub use atmega_hal::port::{mode, Pin, PinOps, PinMode};
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
type Pin = Pin;

/// Pins of the **SparkFun ProMicro**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins from atmega_hal::Pins {
pub struct Pins {
/// `RX`
///
/// `RX` (UART)
Expand Down Expand Up @@ -74,4 +72,9 @@ avr_hal_generic::renamed_pins! {
/// `ADC4` channel
pub a3: atmega_hal::port::PF4 = pf4,
}

impl Pins {
type Pin = Pin;
type McuPins = atmega_hal::Pins;
}
}
29 changes: 16 additions & 13 deletions arduino-hal/src/port/trinket.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
pub use attiny_hal::port::{mode, Pin, PinOps, PinMode};
pub use attiny_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
type Pin = Pin;
pub struct Pins {
/// `#0`: `PB0`, `DI`(SPI), `SDA`(I2C)
pub d0: attiny_hal::port::PB0 = pb0,
/// `#1`: `PB1`, `DO`(SPI), Builtin LED
pub d1: attiny_hal::port::PB1 = pb1,
/// `#2`: `PB2`, `SCK`(SPI), `SCL`(I2C)
pub d2: attiny_hal::port::PB2 = pb2,
/// `#3`: `PB3`
pub d3: attiny_hal::port::PB3 = pb3,
/// `#4`: `PB4`
pub d4: attiny_hal::port::PB4 = pb4,
}

pub struct Pins from attiny_hal::Pins {
/// `#0`: `PB0`, `DI`(SPI), `SDA`(I2C)
pub d0: attiny_hal::port::PB0 = pb0,
/// `#1`: `PB1`, `DO`(SPI), Builtin LED
pub d1: attiny_hal::port::PB1 = pb1,
/// `#2`: `PB2`, `SCK`(SPI), `SCL`(I2C)
pub d2: attiny_hal::port::PB2 = pb2,
/// `#3`: `PB3`
pub d3: attiny_hal::port::PB3 = pb3,
/// `#4`: `PB4`
pub d4: attiny_hal::port::PB4 = pb4,
impl Pins {
type Pin = Pin;
type McuPins = attiny_hal::Pins;
}
}
11 changes: 7 additions & 4 deletions arduino-hal/src/port/trinket_pro.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
pub use atmega_hal::port::{mode, Pin, PinOps, PinMode};
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
type Pin = Pin;

/// Pins of the **Trinket Pro**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins from atmega_hal::Pins {
pub struct Pins {
/// `A0`
///
/// * ADC0 (ADC input channel 0)
Expand Down Expand Up @@ -115,4 +113,9 @@ avr_hal_generic::renamed_pins! {
/// * L LED on Trinket Pro
pub d13: atmega_hal::port::PB5 = pb5,
}

impl Pins {
type Pin = Pin;
type McuPins = atmega_hal::Pins;
}
}
11 changes: 7 additions & 4 deletions arduino-hal/src/port/uno.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
pub use atmega_hal::port::{mode, Pin, PinOps, PinMode};
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
type Pin = Pin;

/// Pins of the **Arduino Uno**, **Arduino Nano**, and **SparkFun ProMini 5V (16MHz)**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins from atmega_hal::Pins {
pub struct Pins {
/// `A0`
///
/// * ADC0 (ADC input channel 0)
Expand Down Expand Up @@ -125,4 +123,9 @@ avr_hal_generic::renamed_pins! {
/// * L LED on Arduino Uno
pub d13: atmega_hal::port::PB5 = pb5,
}

impl Pins {
type Pin = Pin;
type McuPins = atmega_hal::Pins;
}
}
Loading

0 comments on commit 063f845

Please sign in to comment.