Skip to content

Commit

Permalink
feat: add nano every support
Browse files Browse the repository at this point in the history
  • Loading branch information
flobz committed Jan 7, 2025
1 parent 5079e1e commit c4fee5f
Show file tree
Hide file tree
Showing 21 changed files with 771 additions and 53 deletions.
7 changes: 6 additions & 1 deletion arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ critical-section-impl = ["avr-device/critical-section-impl"]
board-selected = []
mcu-atmega = []
mcu-attiny = []
mcu-atxmega = []
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"]
arduino-mega1280 = ["mcu-atmega", "atmega-hal/atmega1280", "board-selected"]
arduino-nano = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc", "board-selected"]
arduino-uno = ["mcu-atmega", "atmega-hal/atmega328p", "board-selected"]
nano-every = ["mcu-atxmega", "atxmega-hal/atmega4809", "atxmega-hal/enable-extra-adc","board-selected"]
trinket-pro = ["mcu-atmega", "atmega-hal/atmega328p", "board-selected"]
sparkfun-promicro = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
sparkfun-promini-3v3 = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc", "board-selected"]
Expand All @@ -51,6 +53,9 @@ path = "../avr-hal-generic/"
path = "../mcu/atmega-hal/"
optional = true

[dependencies.atxmega-hal]
path = "../mcu/atxmega-hal/"
optional = true
# Because this crate has its own check that at least one device is selected, we
# can safely "circumvent" the check in `atmega-hal`. Due to compile order,
# this allows us to show our error instead of the one from `atmega-hal` (which
Expand All @@ -62,7 +67,7 @@ path = "../mcu/attiny-hal/"
optional = true

[dependencies.avr-device]
version = "0.5.4"
version = "0.7.0"

# Because this crate has its own check that at least one device is selected, we
# can safely "circumvent" the check in `avr-device`.
Expand Down
1 change: 1 addition & 0 deletions arduino-hal/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub(crate) mod default {
feature = "arduino-mega1280",
feature = "arduino-nano",
feature = "arduino-uno",
feature = "nano-every",
feature = "sparkfun-promicro",
feature = "sparkfun-promini-5v",
feature = "trinket-pro",
Expand Down
36 changes: 29 additions & 7 deletions arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#![cfg_attr(feature = "arduino-mega1280", doc = "**Arduino Mega 1280**.")]
#![cfg_attr(feature = "arduino-nano", doc = "**Arduino Nano**.")]
#![cfg_attr(feature = "arduino-uno", doc = "**Arduino Uno**.")]
#![cfg_attr(feature = "nano-every", doc = "**Nano Every**.")]
#![cfg_attr(feature = "sparkfun-promicro", doc = "**SparkFun ProMicro**.")]
#![cfg_attr(
feature = "sparkfun-promini-3v3",
Expand Down Expand Up @@ -66,6 +67,7 @@ compile_error!(
* arduino-mega1280
* arduino-nano
* arduino-uno
* nano-every
* sparkfun-promicro
* sparkfun-promini-3v3
* sparkfun-promini-5v
Expand Down Expand Up @@ -101,6 +103,13 @@ pub use atmega_hal as hal;
#[cfg(feature = "mcu-atmega")]
pub use atmega_hal::pac;

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

#[doc(no_inline)]
#[cfg(feature = "mcu-attiny")]
pub use attiny_hal as hal;
Expand Down Expand Up @@ -130,7 +139,7 @@ pub mod port;
pub use port::Pins;

/// Analog to Digital converter.
#[cfg(feature = "mcu-atmega")]
#[cfg(any(feature = "mcu-atmega", feature = "mcu-atxmega"))]
pub mod adc {
pub use crate::hal::adc::{
channel, AdcChannel, AdcOps, AdcSettings, Channel, ClockDivider, ReferenceVoltage,
Expand All @@ -140,7 +149,7 @@ pub mod adc {
pub type Adc = crate::hal::Adc<crate::DefaultClock>;
}
#[doc(no_inline)]
#[cfg(feature = "mcu-atmega")]
#[cfg(any(feature = "mcu-atmega", feature = "mcu-atxmega"))]
pub use adc::Adc;

/// I2C bus controller.
Expand All @@ -165,7 +174,7 @@ pub mod spi {
#[cfg(feature = "mcu-atmega")]
pub use spi::Spi;

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

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

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

#[cfg(feature = "board-selected")]
#[cfg(all(feature = "board-selected", not(feature = "nano-every")))]
pub mod eeprom {
pub use crate::hal::eeprom::{Eeprom, EepromOps, OutOfBoundsError};
}
#[doc(no_inline)]
#[cfg(feature = "board-selected")]
#[cfg(all(feature = "board-selected", not(feature = "nano-every")))]
pub use eeprom::Eeprom;

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

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

Expand Down Expand Up @@ -251,6 +260,19 @@ macro_rules! default_serial {
};
}

#[cfg(any(feature = "nano-every"))]
#[macro_export]
macro_rules! default_serial {
($p:expr, $pins:expr, $baud:expr) => {
$crate::Usart::new(
$p.USART3,
$pins.rx,
$pins.tx.into_output(),
$crate::hal::usart::BaudrateAtxExt::into_baudrate($baud),
)
};
}

/// Convenience macro to instantiate the [`Usart`] driver for this board.
///
/// # Example
Expand Down
126 changes: 126 additions & 0 deletions arduino-hal/src/port/every.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
pub use atxmega_hal::port::{mode, Pin};

avr_hal_generic::renamed_pins! {
/// Pins of the **Arduino Nano Every**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins {
/// `A0`
///
/// * AIN3 (ADC input pin 3)
/// * INT27: External Interrupt
pub a0: atxmega_hal::port::PD3 = pd3,
/// `A1`
///
/// * AIN2 (ADC input pin 2)
/// * INT26: External Interrupt
pub a1: atxmega_hal::port::PD2 = pd2,
/// `A2`
///
/// * AIN1 (ADC input channel 2)
/// * INT25: External Interrupt
pub a2: atxmega_hal::port::PD1 = pd1,
/// `A3`
///
/// * AIN0 (ADC input channel 0)
/// * INT24: External Interrupt
pub a3: atxmega_hal::port::PD0 = pd0,
/// `A4`
///
/// * AIN12 (ADC input channel 12)
/// * SDA (2-wire serial bus data input/output line)
/// * INT2: External Interrupt
pub a4: atxmega_hal::port::PF2 = pf2,
/// `A5`
///
/// * AIN13 (ADC input channel 13)
/// * SCL (2-wire serial bus clock line)
/// * INT3: External Interrupt
pub a5: atxmega_hal::port::PF3 = pf3,
/// `A6`
///
/// * AIN4 (ADC input channel 5)
/// * INT28: External Interrupt
pub a6: atxmega_hal::port::PD4 = pd4,
/// `A7`
///
/// * AIN5 (ADC input channel 5)
/// * INT29: External Interrupt
pub a7: atxmega_hal::port::PD5 = pd5,
/// `D0` / `RX`
///
/// * RXD (USART input pin)
/// * INT20: External Interrupt
pub d0: atxmega_hal::port::PC5 = pc5,
/// `D1` / `TX`
///
/// * TXD (USART output pin)
/// * INT21: External Interrupt
pub d1: atxmega_hal::port::PC4 = pc4,
/// `D2`
///
/// * INT0: External Interrupt
pub d2: atxmega_hal::port::PA0 = pa0,
/// `D3`
///
/// * AIN15 (analog comparator positive input)
/// * INT45: External Interrupt
pub d3: atxmega_hal::port::PF5 = pf5,
/// `D4`
///
/// * INT22: External Interrupt
pub d4: atxmega_hal::port::PC6 = pc6,
/// `D5`
///
/// * **PWM**:
/// * INT22: External Interrupt
pub d5: atxmega_hal::port::PB2 = pb2,
/// `D6`
///
/// * **PWM**
/// * AIN14 (analog comparator positive input)
/// * INT44: External Interrupt
pub d6: atxmega_hal::port::PF4 = pf4,
/// `D7`
///
/// * INT1: External Interrupt
pub d7: atxmega_hal::port::PA1 = pa1,
/// `D8`
///
/// * INT35: External Interrupt
pub d8: atxmega_hal::port::PE3 = pe3,
/// `D9`
///
/// * **PWM**
/// * INT9: External Interrupt
pub d9: atxmega_hal::port::PB0 = pb0,
/// `D10`
///
/// * **PWM**
/// * INT10: External Interrupt
pub d10: atxmega_hal::port::PB1 = pb1,
/// `D11`
///
/// * **PWM**
/// * INT32: External Interrupt
pub d11: atxmega_hal::port::PE0 = pe0,
/// `D12`
///
/// * INT33: External Interrupt
pub d12: atxmega_hal::port::PE1 = pe1,
/// `D13`
///
/// * SCK (SPI bus master clock input)
/// * INT34: External Interrupt
/// * L LED on Arduino Uno
pub d13: atxmega_hal::port::PE2 = pe2,

pub rx : atxmega_hal::port::PB5= pb5,
pub tx : atxmega_hal::port::PB4 = pb4,
}

impl Pins {
type Pin = Pin;
type McuPins = atxmega_hal::Pins;
}
}
6 changes: 6 additions & 0 deletions arduino-hal/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ mod uno;
feature = "sparkfun-promini-5v"
))]
pub use uno::*;
#[cfg(feature = "nano-every")]
mod every;

#[cfg(feature = "nano-every")]
pub use every::*;

#[cfg(feature = "sparkfun-promicro")]
mod promicro;
#[cfg(feature = "sparkfun-promicro")]
Expand Down
2 changes: 1 addition & 1 deletion avr-hal-generic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cfg-if = "1"
nb = "1.1.0"
ufmt = "0.2.0"
paste = "1.0.0"
avr-device = "0.5.4"
avr-device = "0.7.0"
embedded-storage = "0.2"
embedded-hal = "1.0"
embedded-hal-bus = "0.1"
Expand Down
Loading

0 comments on commit c4fee5f

Please sign in to comment.