Skip to content

Commit b791fda

Browse files
committed
feat: add nano every support
1 parent 5079e1e commit b791fda

File tree

21 files changed

+757
-52
lines changed

21 files changed

+757
-52
lines changed

arduino-hal/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ critical-section-impl = ["avr-device/critical-section-impl"]
1919
board-selected = []
2020
mcu-atmega = []
2121
mcu-attiny = []
22+
mcu-atxmega = []
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"]
2526
arduino-mega1280 = ["mcu-atmega", "atmega-hal/atmega1280", "board-selected"]
2627
arduino-nano = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc", "board-selected"]
2728
arduino-uno = ["mcu-atmega", "atmega-hal/atmega328p", "board-selected"]
29+
nano-every = ["mcu-atxmega", "atxmega-hal/atmega4809", "atxmega-hal/enable-extra-adc","board-selected"]
2830
trinket-pro = ["mcu-atmega", "atmega-hal/atmega328p", "board-selected"]
2931
sparkfun-promicro = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
3032
sparkfun-promini-3v3 = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc", "board-selected"]
@@ -51,6 +53,9 @@ path = "../avr-hal-generic/"
5153
path = "../mcu/atmega-hal/"
5254
optional = true
5355

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

6469
[dependencies.avr-device]
65-
version = "0.5.4"
70+
path = "../../avr-device"
71+
optional = true
6672

6773
# Because this crate has its own check that at least one device is selected, we
6874
# can safely "circumvent" the check in `avr-device`.

arduino-hal/src/clock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(crate) mod default {
2121
feature = "arduino-mega1280",
2222
feature = "arduino-nano",
2323
feature = "arduino-uno",
24+
feature = "nano-every",
2425
feature = "sparkfun-promicro",
2526
feature = "sparkfun-promini-5v",
2627
feature = "trinket-pro",

arduino-hal/src/lib.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![cfg_attr(feature = "arduino-mega1280", doc = "**Arduino Mega 1280**.")]
1313
#![cfg_attr(feature = "arduino-nano", doc = "**Arduino Nano**.")]
1414
#![cfg_attr(feature = "arduino-uno", doc = "**Arduino Uno**.")]
15+
#![cfg_attr(feature = "nano-every", doc = "**Nano Every**.")]
1516
#![cfg_attr(feature = "sparkfun-promicro", doc = "**SparkFun ProMicro**.")]
1617
#![cfg_attr(
1718
feature = "sparkfun-promini-3v3",
@@ -66,6 +67,7 @@ compile_error!(
6667
* arduino-mega1280
6768
* arduino-nano
6869
* arduino-uno
70+
* nano-every
6971
* sparkfun-promicro
7072
* sparkfun-promini-3v3
7173
* sparkfun-promini-5v
@@ -101,6 +103,13 @@ pub use atmega_hal as hal;
101103
#[cfg(feature = "mcu-atmega")]
102104
pub use atmega_hal::pac;
103105

106+
#[doc(no_inline)]
107+
#[cfg(feature = "mcu-atxmega")]
108+
pub use atxmega_hal as hal;
109+
#[doc(no_inline)]
110+
#[cfg(feature = "mcu-atxmega")]
111+
pub use atxmega_hal::pac;
112+
104113
#[doc(no_inline)]
105114
#[cfg(feature = "mcu-attiny")]
106115
pub use attiny_hal as hal;
@@ -130,7 +139,7 @@ pub mod port;
130139
pub use port::Pins;
131140

132141
/// Analog to Digital converter.
133-
#[cfg(feature = "mcu-atmega")]
142+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-atxmega"))]
134143
pub mod adc {
135144
pub use crate::hal::adc::{
136145
channel, AdcChannel, AdcOps, AdcSettings, Channel, ClockDivider, ReferenceVoltage,
@@ -140,7 +149,7 @@ pub mod adc {
140149
pub type Adc = crate::hal::Adc<crate::DefaultClock>;
141150
}
142151
#[doc(no_inline)]
143-
#[cfg(feature = "mcu-atmega")]
152+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-atxmega"))]
144153
pub use adc::Adc;
145154

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

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

@@ -177,15 +186,15 @@ pub mod usart {
177186
}
178187

179188
#[doc(no_inline)]
180-
#[cfg(feature = "mcu-atmega")]
189+
#[cfg(any(feature = "mcu-atmega", feature = "mcu-atxmega"))]
181190
pub use usart::Usart;
182191

183-
#[cfg(feature = "board-selected")]
192+
#[cfg(all(feature = "board-selected", not(feature = "nano-every")))]
184193
pub mod eeprom {
185194
pub use crate::hal::eeprom::{Eeprom, EepromOps, OutOfBoundsError};
186195
}
187196
#[doc(no_inline)]
188-
#[cfg(feature = "board-selected")]
197+
#[cfg(all(feature = "board-selected", not(feature = "nano-every")))]
189198
pub use eeprom::Eeprom;
190199

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

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

@@ -251,6 +260,19 @@ macro_rules! default_serial {
251260
};
252261
}
253262

263+
#[cfg(any(feature = "nano-every"))]
264+
#[macro_export]
265+
macro_rules! default_serial {
266+
($p:expr, $pins:expr, $baud:expr) => {
267+
$crate::Usart::new(
268+
$p.USART3,
269+
$pins.rx,
270+
$pins.tx.into_output(),
271+
$crate::hal::usart::BaudrateAtxExt::into_baudrate($baud),
272+
)
273+
};
274+
}
275+
254276
/// Convenience macro to instantiate the [`Usart`] driver for this board.
255277
///
256278
/// # Example

arduino-hal/src/port/every.rs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
pub use atxmega_hal::port::{mode, Pin};
2+
3+
avr_hal_generic::renamed_pins! {
4+
/// Pins of the **Arduino Nano Every**.
5+
///
6+
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
7+
pub struct Pins {
8+
/// `A0`
9+
///
10+
/// * AIN3 (ADC input pin 3)
11+
/// * INT27: External Interrupt
12+
pub a0: atxmega_hal::port::PD3 = pd3,
13+
/// `A1`
14+
///
15+
/// * AIN2 (ADC input pin 2)
16+
/// * INT26: External Interrupt
17+
pub a1: atxmega_hal::port::PD2 = pd2,
18+
/// `A2`
19+
///
20+
/// * AIN1 (ADC input channel 2)
21+
/// * INT25: External Interrupt
22+
pub a2: atxmega_hal::port::PD1 = pd1,
23+
/// `A3`
24+
///
25+
/// * AIN0 (ADC input channel 0)
26+
/// * INT24: External Interrupt
27+
pub a3: atxmega_hal::port::PD0 = pd0,
28+
/// `A4`
29+
///
30+
/// * AIN12 (ADC input channel 12)
31+
/// * SDA (2-wire serial bus data input/output line)
32+
/// * INT2: External Interrupt
33+
pub a4: atxmega_hal::port::PF2 = pf2,
34+
/// `A5`
35+
///
36+
/// * AIN13 (ADC input channel 13)
37+
/// * SCL (2-wire serial bus clock line)
38+
/// * INT3: External Interrupt
39+
pub a5: atxmega_hal::port::PF3 = pf3,
40+
/// `A6`
41+
///
42+
/// * AIN4 (ADC input channel 5)
43+
/// * INT28: External Interrupt
44+
pub a6: atxmega_hal::port::PD4 = pd4,
45+
/// `A7`
46+
///
47+
/// * AIN5 (ADC input channel 5)
48+
/// * INT29: External Interrupt
49+
pub a7: atxmega_hal::port::PD5 = pd5,
50+
/// `D0` / `RX`
51+
///
52+
/// * RXD (USART input pin)
53+
/// * INT20: External Interrupt
54+
pub d0: atxmega_hal::port::PC5 = pc5,
55+
/// `D1` / `TX`
56+
///
57+
/// * TXD (USART output pin)
58+
/// * INT21: External Interrupt
59+
pub d1: atxmega_hal::port::PC4 = pc4,
60+
/// `D2`
61+
///
62+
/// * INT0: External Interrupt
63+
pub d2: atxmega_hal::port::PA0 = pa0,
64+
/// `D3`
65+
///
66+
/// * AIN15 (analog comparator positive input)
67+
/// * INT45: External Interrupt
68+
pub d3: atxmega_hal::port::PF5 = pf5,
69+
/// `D4`
70+
///
71+
/// * INT22: External Interrupt
72+
pub d4: atxmega_hal::port::PC6 = pc6,
73+
/// `D5`
74+
///
75+
/// * **PWM**:
76+
/// * INT22: External Interrupt
77+
pub d5: atxmega_hal::port::PB2 = pb2,
78+
/// `D6`
79+
///
80+
/// * **PWM**
81+
/// * AIN14 (analog comparator positive input)
82+
/// * INT44: External Interrupt
83+
pub d6: atxmega_hal::port::PF4 = pf4,
84+
/// `D7`
85+
///
86+
/// * INT1: External Interrupt
87+
pub d7: atxmega_hal::port::PA1 = pa1,
88+
/// `D8`
89+
///
90+
/// * INT35: External Interrupt
91+
pub d8: atxmega_hal::port::PE3 = pe3,
92+
/// `D9`
93+
///
94+
/// * **PWM**
95+
/// * INT9: External Interrupt
96+
pub d9: atxmega_hal::port::PB0 = pb0,
97+
/// `D10`
98+
///
99+
/// * **PWM**
100+
/// * INT10: External Interrupt
101+
pub d10: atxmega_hal::port::PB1 = pb1,
102+
/// `D11`
103+
///
104+
/// * **PWM**
105+
/// * INT32: External Interrupt
106+
pub d11: atxmega_hal::port::PE0 = pe0,
107+
/// `D12`
108+
///
109+
/// * INT33: External Interrupt
110+
pub d12: atxmega_hal::port::PE1 = pe1,
111+
/// `D13`
112+
///
113+
/// * SCK (SPI bus master clock input)
114+
/// * INT34: External Interrupt
115+
/// * L LED on Arduino Uno
116+
pub d13: atxmega_hal::port::PE2 = pe2,
117+
118+
pub rx : atxmega_hal::port::PB5= pb5,
119+
pub tx : atxmega_hal::port::PB4 = pb4,
120+
}
121+
122+
impl Pins {
123+
type Pin = Pin;
124+
type McuPins = atxmega_hal::Pins;
125+
}
126+
}

arduino-hal/src/port/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ mod uno;
4343
feature = "sparkfun-promini-5v"
4444
))]
4545
pub use uno::*;
46+
#[cfg(feature = "nano-every")]
47+
mod every;
48+
49+
#[cfg(feature = "nano-every")]
50+
pub use every::*;
51+
4652
#[cfg(feature = "sparkfun-promicro")]
4753
mod promicro;
4854
#[cfg(feature = "sparkfun-promicro")]

avr-hal-generic/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ cfg-if = "1"
2121
nb = "1.1.0"
2222
ufmt = "0.2.0"
2323
paste = "1.0.0"
24-
avr-device = "0.5.4"
2524
embedded-storage = "0.2"
2625
embedded-hal = "1.0"
2726
embedded-hal-bus = "0.1"
2827
unwrap-infallible = "0.1.5"
2928

29+
[dependencies.avr-device]
30+
path = "../../avr-device"
31+
3032
[dependencies.embedded-hal-v0]
3133
version = "0.2.3"
3234
package = "embedded-hal"

0 commit comments

Comments
 (0)