Skip to content

Commit

Permalink
arduino-hal: Add support for Arduino Mega 2560
Browse files Browse the repository at this point in the history
  • Loading branch information
explicite authored Feb 17, 2021
1 parent 8cffcc8 commit 9e41a1e
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 7 deletions.
1 change: 1 addition & 0 deletions arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ board-selected = []
mcu-atmega=[]
arduino-uno = ["mcu-atmega", "atmega-hal/atmega328p", "board-selected"]
arduino-leonardo = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
arduino-mega2560 = ["mcu-atmega", "atmega-hal/atmega2560", "board-selected"]

[dependencies]
cfg-if = "1"
Expand Down
2 changes: 2 additions & 0 deletions arduino-hal/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ pub(crate) mod default {
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(feature = "arduino-leonardo")]
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(feature = "arduino-mega2560")]
pub type DefaultClock = avr_hal_generic::clock::MHz16;
}
22 changes: 16 additions & 6 deletions arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ compile_error!(
Please select one of the following
* arduino-uno
* arduino-leonardo
* arduino-mega2560
"
);

Expand Down Expand Up @@ -54,19 +56,23 @@ pub mod prelude {
}
}

pub use void::ResultVoidExt as _;
pub use void::ResultVoidErrExt as _;
pub use ufmt::uWrite as _;
pub use void::ResultVoidErrExt as _;
pub use void::ResultVoidExt as _;
}

#[allow(non_snake_case)]
#[cfg(feature = "board-selected")]
pub struct Peripherals {
pub pins: Pins,
#[cfg(feature = "arduino-uno")]
#[cfg(any(feature = "arduino-uno", feature = "arduino-mega2560"))]
pub USART0: hal::RawPeripheral<pac::USART0>,
#[cfg(feature = "arduino-leonardo")]
#[cfg(any(feature = "arduino-leonardo", feature = "arduino-mega2560"))]
pub USART1: hal::RawPeripheral<pac::USART1>,
#[cfg(feature = "arduino-mega2560")]
pub USART2: hal::RawPeripheral<pac::USART2>,
#[cfg(feature = "arduino-mega2560")]
pub USART3: hal::RawPeripheral<pac::USART3>,
}

#[cfg(feature = "board-selected")]
Expand All @@ -76,10 +82,14 @@ impl Peripherals {
#[cfg(feature = "atmega-hal")]
pins: Pins::with_mcu_pins(dp.pins),

#[cfg(feature = "arduino-uno")]
#[cfg(any(feature = "arduino-uno", feature = "arduino-mega2560"))]
USART0: dp.USART0,
#[cfg(feature = "arduino-leonardo")]
#[cfg(any(feature = "arduino-leonardo", feature = "arduino-mega2560"))]
USART1: dp.USART1,
#[cfg(feature = "arduino-mega2560")]
USART2: dp.USART2,
#[cfg(feature = "arduino-mega2560")]
USART3: dp.USART3,
}
}

Expand Down
Loading

0 comments on commit 9e41a1e

Please sign in to comment.