Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
ci:
name: "${{ matrix.m.type }}: ${{ matrix.m.name }}"
strategy:
fail-fast: true
fail-fast: false
matrix:
m:
- type: board
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
# MCU HAL crates
"mcu/atmega-hal",
"mcu/attiny-hal",
"mcu/avrmodern-hal",

# Higher level crates
"arduino-hal",
Expand All @@ -36,9 +37,13 @@ members = [
"examples/sparkfun-promini-5v",
"examples/trinket-pro",
"examples/trinket",
"examples/avrmodern",
]
exclude = [
# The RAVEDUDE! Yeah!
"ravedude",
]
resolver = "2"

[patch.crates-io]
avr-device = { git = "https://github.com/rahix/avr-device", rev = "330cdf1fb1a7301b9d6cf62491c16e69d6aa7312" }
12 changes: 10 additions & 2 deletions arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ categories = ["no-std", "embedded", "hardware-support"]
default = ["rt"]
rt = ["avr-device/rt"]

critical-section-impl = ["avr-device/critical-section-impl"]

board-selected = []
mcu-atmega = []
mcu-attiny = []
mcu-avrmodern = []
arduino-diecimila = ["mcu-atmega", "atmega-hal/atmega168", "board-selected"]
arduino-leonardo = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
arduino-mega2560 = ["mcu-atmega", "atmega-hal/atmega2560", "board-selected"]
Expand All @@ -31,6 +30,10 @@ sparkfun-promini-3v3 = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enabl
sparkfun-promini-5v = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc", "board-selected"]
trinket = ["mcu-attiny", "attiny-hal/attiny85", "board-selected"]
nano168 = ["mcu-atmega", "atmega-hal/atmega168", "atmega-hal/enable-extra-adc", "board-selected"]
attiny402 = ["mcu-avrmodern", "avrmodern-hal/attiny402", "board-selected"]
attiny1614 = ["mcu-avrmodern", "avrmodern-hal/attiny1614", "board-selected"]
#attiny3224 = ["mcu-avrmodern", "avrmodern-hal/attiny3224", "board-selected"]
#avr128db28 = ["mcu-avrmodern", "avrmodern-hal/avr128db28", "board-selected"]

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

[dependencies.avrmodern-hal]
path = "../mcu/avrmodern-hal/"
optional = true
features = ["disable-device-selection-error"]

[dependencies.avr-device]
version = "0.7"

Expand Down
6 changes: 5 additions & 1 deletion arduino-hal/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub(crate) mod default {
feature = "nano168",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(any(feature = "trinket", feature = "sparkfun-promini-3v3"))]
#[cfg(any(
feature = "trinket", feature = "sparkfun-promini-3v3",
feature = "attiny402", feature = "attiny1614",
// feature = "attiny3224",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz8;
}
57 changes: 52 additions & 5 deletions arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#![cfg_attr(feature = "trinket-pro", doc = "**Trinket Pro**.")]
#![cfg_attr(feature = "trinket", doc = "**Trinket**.")]
#![cfg_attr(feature = "nano168", doc = "**Nano clone (ATmega168)**.")]
#![cfg_attr(feature = "attiny402", doc = "**ATtiny402**.")]
#![cfg_attr(feature = "attiny1614", doc = "**ATtiny1614**.")]
// #![cfg_attr(feature = "attiny3224", doc = "**ATtiny3224**.")]
// #![cfg_attr(feature = "avr128db28", doc = "**avr128db28**.")]
//! This means that only items which are available for this board are visible. If you are using a
//! different board, try building the documentation locally with
//!
Expand Down Expand Up @@ -72,6 +76,8 @@ compile_error!(
* trinket-pro
* trinket
* nano168
* attiny402
* attiny1614
"
);

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

#[doc(no_inline)]
#[cfg(feature = "mcu-avrmodern")]
pub use avrmodern_hal as hal;
#[doc(no_inline)]
#[cfg(feature = "mcu-avrmodern")]
pub use avrmodern_hal::pac;

#[doc(no_inline)]
#[cfg(feature = "mcu-attiny")]
pub use attiny_hal as hal;
Expand Down Expand Up @@ -165,7 +178,7 @@ pub mod spi {
#[cfg(feature = "mcu-atmega")]
pub use spi::Spi;

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

Expand All @@ -177,15 +190,15 @@ pub mod usart {
}

#[doc(no_inline)]
#[cfg(feature = "mcu-atmega")]
#[cfg(any(feature = "mcu-atmega", feature = "mcu-avrmodern"))]
pub use usart::Usart;

#[cfg(feature = "board-selected")]
#[cfg(any(feature = "mcu-atmega", feature = "mcu-attiny"))]
pub mod eeprom {
pub use crate::hal::eeprom::{Eeprom, EepromOps, OutOfBoundsError};
}
#[doc(no_inline)]
#[cfg(feature = "board-selected")]
#[cfg(any(feature = "mcu-atmega", feature = "mcu-attiny"))]
pub use eeprom::Eeprom;

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

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

Expand Down Expand Up @@ -340,3 +353,37 @@ macro_rules! default_serial {
)
};
}

/// Convenience macro to instantiate the [`Usart`] driver for this board.
///
/// # Example
/// ```no_run
/// let dp = arduino_hal::Peripherals::take().unwrap();
/// let pins = arduino_hal::pins!(dp);
/// let serial = arduino_hal::default_serial!(dp, pins, 57600);
/// ```
#[cfg(any(feature = "attiny402"))]
#[macro_export]
macro_rules! default_serial {
($p:expr, $pins:expr, $baud:expr) => {
$crate::Usart::new(
$p.USART0,
$pins.a7,
$pins.a6.into_output(),
$crate::hal::usart::BaudrateExt::into_baudrate($baud),
)
};
}

#[cfg(any(feature = "attiny1614"))]
#[macro_export]
macro_rules! default_serial {
($p:expr, $pins:expr, $baud:expr) => {
$crate::Usart::new(
$p.USART0,
$pins.b3,
$pins.b2.into_output(),
$crate::hal::usart::BaudrateExt::into_baudrate($baud),
)
};
}
24 changes: 24 additions & 0 deletions arduino-hal/src/port/attiny1614.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pub use avrmodern_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
pub struct Pins {
pub a0: avrmodern_hal::port::PA0 = pa0,
pub a1: avrmodern_hal::port::PA1 = pa1,
pub a2: avrmodern_hal::port::PA2 = pa2,
pub a3: avrmodern_hal::port::PA3 = pa3,
pub a4: avrmodern_hal::port::PA4 = pa4,
pub a5: avrmodern_hal::port::PA5 = pa5,
pub a6: avrmodern_hal::port::PA6 = pa6,
pub a7: avrmodern_hal::port::PA7 = pa7,

pub b0: avrmodern_hal::port::PB0 = pb0,
pub b1: avrmodern_hal::port::PB1 = pb1,
pub b2: avrmodern_hal::port::PB2 = pb2,
pub b3: avrmodern_hal::port::PB3 = pb3,
}

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

avr_hal_generic::renamed_pins! {
pub struct Pins {
pub a0: avrmodern_hal::port::PA0 = pa0,
pub a1: avrmodern_hal::port::PA1 = pa1,
pub a2: avrmodern_hal::port::PA2 = pa2,
pub a3: avrmodern_hal::port::PA3 = pa3,
pub a6: avrmodern_hal::port::PA6 = pa6,
pub a7: avrmodern_hal::port::PA7 = pa7,
}

impl Pins {
type Pin = Pin;
type McuPins = avrmodern_hal::Pins;
}
}
8 changes: 8 additions & 0 deletions arduino-hal/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ pub use trinket_pro::*;
mod trinket;
#[cfg(feature = "trinket")]
pub use trinket::*;
#[cfg(feature = "attiny402")]
mod attiny402;
#[cfg(feature = "attiny402")]
pub use attiny402::*;
#[cfg(feature = "attiny1614")]
mod attiny1614;
#[cfg(feature = "attiny1614")]
pub use attiny1614::*;
10 changes: 5 additions & 5 deletions avr-hal-generic/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,17 @@ macro_rules! impl_adc {

#[inline]
fn raw_read_adc(&self) -> u16 {
self.adc.read().bits()
self.adc().read().bits()
}

#[inline]
fn raw_is_converting(&self) -> bool {
self.adcsra.read().adsc().bit_is_set()
self.adcsra().read().adsc().bit_is_set()
}

#[inline]
fn raw_start_conversion(&mut self) {
self.adcsra.modify(|_, w| w.adsc().set_bit());
self.adcsra().modify(|_, w| w.adsc().set_bit());
}

#[inline]
Expand All @@ -276,7 +276,7 @@ macro_rules! impl_adc {
match channel {
$(
x if x == $pin_channel => {
$(self.$didr.modify(|_, w| w.$didr_method().set_bit());)?
$(self.$didr().modify(|_, w| w.$didr_method().set_bit());)?
}
)+
_ => unreachable!(),
Expand All @@ -288,7 +288,7 @@ macro_rules! impl_adc {
match channel {
$(
x if x == $pin_channel => {
$(self.$didr.modify(|_, w| w.$didr_method().clear_bit());)?
$(self.$didr().modify(|_, w| w.$didr_method().clear_bit());)?
}
)+
_ => unreachable!(),
Expand Down
Loading