Skip to content

Commit 26b4393

Browse files
committed
Add some modern avr support
1 parent 6807aaf commit 26b4393

File tree

19 files changed

+852
-6
lines changed

19 files changed

+852
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ members = [
1818
# MCU HAL crates
1919
"mcu/atmega-hal",
2020
"mcu/attiny-hal",
21+
"mcu/avrmodern-hal",
2122

2223
# Higher level crates
2324
"arduino-hal",
@@ -36,6 +37,7 @@ members = [
3637
"examples/sparkfun-promini-5v",
3738
"examples/trinket-pro",
3839
"examples/trinket",
40+
"examples/avrmodern",
3941
]
4042
exclude = [
4143
# The RAVEDUDE! Yeah!

arduino-hal/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ critical-section-impl = ["avr-device/critical-section-impl"]
1919
board-selected = []
2020
mcu-atmega = []
2121
mcu-attiny = []
22+
mcu-avrmodern = []
2223
arduino-diecimila = ["mcu-atmega", "atmega-hal/atmega168", "board-selected"]
2324
arduino-leonardo = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
2425
arduino-mega2560 = ["mcu-atmega", "atmega-hal/atmega2560", "board-selected"]
@@ -31,6 +32,10 @@ sparkfun-promini-3v3 = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enabl
3132
sparkfun-promini-5v = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc", "board-selected"]
3233
trinket = ["mcu-attiny", "attiny-hal/attiny85", "board-selected"]
3334
nano168 = ["mcu-atmega", "atmega-hal/atmega168", "atmega-hal/enable-extra-adc", "board-selected"]
35+
attiny402 = ["mcu-avrmodern", "avrmodern-hal/attiny402", "board-selected"]
36+
attiny1614 = ["mcu-avrmodern", "avrmodern-hal/attiny1614", "board-selected"]
37+
#attiny3224 = ["mcu-avrmodern", "avrmodern-hal/attiny3224", "board-selected"]
38+
#avr128db28 = ["mcu-avrmodern", "avrmodern-hal/avr128db28", "board-selected"]
3439

3540
# We must select a board to build on docs.rs
3641
docsrs = ["arduino-uno"]
@@ -57,6 +62,11 @@ features = ["disable-device-selection-error"]
5762
path = "../mcu/attiny-hal/"
5863
optional = true
5964

65+
[dependencies.avrmodern-hal]
66+
path = "../mcu/avrmodern-hal/"
67+
optional = true
68+
features = ["disable-device-selection-error"]
69+
6070
[dependencies.avr-device]
6171
version = "0.7"
6272

arduino-hal/src/clock.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub(crate) mod default {
2727
feature = "nano168",
2828
))]
2929
pub type DefaultClock = avr_hal_generic::clock::MHz16;
30-
#[cfg(any(feature = "trinket", feature = "sparkfun-promini-3v3"))]
30+
#[cfg(any(
31+
feature = "trinket", feature = "sparkfun-promini-3v3",
32+
feature = "attiny402", feature = "attiny1614",
33+
// feature = "attiny3224",
34+
))]
3135
pub type DefaultClock = avr_hal_generic::clock::MHz8;
3236
}

arduino-hal/src/lib.rs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#![cfg_attr(feature = "trinket-pro", doc = "**Trinket Pro**.")]
2525
#![cfg_attr(feature = "trinket", doc = "**Trinket**.")]
2626
#![cfg_attr(feature = "nano168", doc = "**Nano clone (ATmega168)**.")]
27+
#![cfg_attr(feature = "attiny402", doc = "**ATtiny402**.")]
28+
#![cfg_attr(feature = "attiny1614", doc = "**ATtiny1614**.")]
29+
// #![cfg_attr(feature = "attiny3224", doc = "**ATtiny3224**.")]
30+
// #![cfg_attr(feature = "avr128db28", doc = "**avr128db28**.")]
2731
//! This means that only items which are available for this board are visible. If you are using a
2832
//! different board, try building the documentation locally with
2933
//!
@@ -72,6 +76,8 @@ compile_error!(
7276
* trinket-pro
7377
* trinket
7478
* nano168
79+
* attiny402
80+
* attiny1614
7581
"
7682
);
7783

@@ -101,6 +107,13 @@ pub use atmega_hal as hal;
101107
#[cfg(feature = "mcu-atmega")]
102108
pub use atmega_hal::pac;
103109

110+
#[doc(no_inline)]
111+
#[cfg(feature = "mcu-avrmodern")]
112+
pub use avrmodern_hal as hal;
113+
#[doc(no_inline)]
114+
#[cfg(feature = "mcu-avrmodern")]
115+
pub use avrmodern_hal::pac;
116+
104117
#[doc(no_inline)]
105118
#[cfg(feature = "mcu-attiny")]
106119
pub use attiny_hal as hal;
@@ -165,7 +178,7 @@ pub mod spi {
165178
#[cfg(feature = "mcu-atmega")]
166179
pub use spi::Spi;
167180

168-
#[cfg(feature = "mcu-atmega")]
181+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-avrmodern"))]
169182
pub mod usart {
170183
pub use crate::hal::usart::{Baudrate, UsartOps};
171184

@@ -177,15 +190,15 @@ pub mod usart {
177190
}
178191

179192
#[doc(no_inline)]
180-
#[cfg(feature = "mcu-atmega")]
193+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-avrmodern"))]
181194
pub use usart::Usart;
182195

183-
#[cfg(feature = "board-selected")]
196+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-attiny"))]
184197
pub mod eeprom {
185198
pub use crate::hal::eeprom::{Eeprom, EepromOps, OutOfBoundsError};
186199
}
187200
#[doc(no_inline)]
188-
#[cfg(feature = "board-selected")]
201+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-attiny"))]
189202
pub use eeprom::Eeprom;
190203

191204
#[cfg(feature = "board-selected")]
@@ -197,7 +210,7 @@ pub mod simple_pwm {
197210
pub use attiny_hal::simple_pwm::*;
198211
}
199212

200-
#[cfg(feature = "mcu-atmega")]
213+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-avrmodern"))]
201214
pub mod prelude {
202215
pub use crate::hal::prelude::*;
203216

@@ -340,3 +353,37 @@ macro_rules! default_serial {
340353
)
341354
};
342355
}
356+
357+
/// Convenience macro to instantiate the [`Usart`] driver for this board.
358+
///
359+
/// # Example
360+
/// ```no_run
361+
/// let dp = arduino_hal::Peripherals::take().unwrap();
362+
/// let pins = arduino_hal::pins!(dp);
363+
/// let serial = arduino_hal::default_serial!(dp, pins, 57600);
364+
/// ```
365+
#[cfg(any(feature = "attiny402"))]
366+
#[macro_export]
367+
macro_rules! default_serial {
368+
($p:expr, $pins:expr, $baud:expr) => {
369+
$crate::Usart::new(
370+
$p.USART0,
371+
$pins.a7,
372+
$pins.a6.into_output(),
373+
$crate::hal::usart::BaudrateExt::into_baudrate($baud),
374+
)
375+
};
376+
}
377+
378+
#[cfg(any(feature = "attiny1614"))]
379+
#[macro_export]
380+
macro_rules! default_serial {
381+
($p:expr, $pins:expr, $baud:expr) => {
382+
$crate::Usart::new(
383+
$p.USART0,
384+
$pins.b3,
385+
$pins.b2.into_output(),
386+
$crate::hal::usart::BaudrateExt::into_baudrate($baud),
387+
)
388+
};
389+
}

arduino-hal/src/port/attiny1614.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pub use avrmodern_hal::port::{mode, Pin, PinMode, PinOps};
2+
3+
avr_hal_generic::renamed_pins! {
4+
pub struct Pins {
5+
pub a0: avrmodern_hal::port::PA0 = pa0,
6+
pub a1: avrmodern_hal::port::PA1 = pa1,
7+
pub a2: avrmodern_hal::port::PA2 = pa2,
8+
pub a3: avrmodern_hal::port::PA3 = pa3,
9+
pub a4: avrmodern_hal::port::PA4 = pa4,
10+
pub a5: avrmodern_hal::port::PA5 = pa5,
11+
pub a6: avrmodern_hal::port::PA6 = pa6,
12+
pub a7: avrmodern_hal::port::PA7 = pa7,
13+
14+
pub b0: avrmodern_hal::port::PB0 = pb0,
15+
pub b1: avrmodern_hal::port::PB1 = pb1,
16+
pub b2: avrmodern_hal::port::PB2 = pb2,
17+
pub b3: avrmodern_hal::port::PB3 = pb3,
18+
}
19+
20+
impl Pins {
21+
type Pin = Pin;
22+
type McuPins = avrmodern_hal::Pins;
23+
}
24+
}

arduino-hal/src/port/attiny402.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub use avrmodern_hal::port::{mode, Pin, PinMode, PinOps};
2+
3+
avr_hal_generic::renamed_pins! {
4+
pub struct Pins {
5+
pub a0: avrmodern_hal::port::PA0 = pa0,
6+
pub a1: avrmodern_hal::port::PA1 = pa1,
7+
pub a2: avrmodern_hal::port::PA2 = pa2,
8+
pub a3: avrmodern_hal::port::PA3 = pa3,
9+
pub a6: avrmodern_hal::port::PA6 = pa6,
10+
pub a7: avrmodern_hal::port::PA7 = pa7,
11+
}
12+
13+
impl Pins {
14+
type Pin = Pin;
15+
type McuPins = avrmodern_hal::Pins;
16+
}
17+
}

arduino-hal/src/port/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ pub use trinket_pro::*;
5555
mod trinket;
5656
#[cfg(feature = "trinket")]
5757
pub use trinket::*;
58+
#[cfg(feature = "attiny402")]
59+
mod attiny402;
60+
#[cfg(feature = "attiny402")]
61+
pub use attiny402::*;
62+
#[cfg(feature = "attiny1614")]
63+
mod attiny1614;
64+
#[cfg(feature = "attiny1614")]
65+
pub use attiny1614::*;

0 commit comments

Comments
 (0)