Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated globals #613

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
77 changes: 52 additions & 25 deletions arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "arduino-hal"
version = "0.1.0"
version = "0.4.0"

authors = ["Rahix <[email protected]>"]
edition = "2021"
Expand All @@ -16,24 +16,57 @@ rt = ["avr-device/rt"]

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

board-selected = []
mcu-atmega = []
mcu-attiny = []
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"]
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"]
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"]

# We must select a board to build on docs.rs
docsrs = ["arduino-uno"]
# Board-specific targets.
arduino-diecimila = ["_board-arduino-diecimila"]
arduino-leonardo = ["_board-arduino-leonardo"]
arduino-mega2560 = ["_board-arduino-mega2560"]
arduino-mega1280 = ["_board-arduino-mega1280"]
arduino-nano = ["_board-arduino-nano"]
arduino-uno = ["_board-arduino-uno"]
trinket-pro = ["_board-trinket-pro"]
sparkfun-promicro = ["_board-sparkfun-promicro"]
sparkfun-promini-3v3 = ["_board-sparkfun-promini-3v3"]
sparkfun-promini-5v = ["_board-sparkfun-promini-5v"]
trinket = ["_board-trinket"]
nano168 = ["_board-nano168"]

# When using this crate from another lib crate, you can use this feature to suppress the chip selection error in favor of your own error
disable-board-selection-error = ["_board-selected"]

# MCU-specific implementation features
_board-arduino-diecimila = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega168"]
_board-arduino-leonardo = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega32u4"]
_board-arduino-mega2560 = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega2560"]
_board-arduino-mega1280 = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega1280"]
_board-arduino-nano = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc"]
_board-arduino-uno = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega328p"]
_board-trinket-pro = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega328p"]
_board-sparkfun-promicro = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega32u4"]
_board-sparkfun-promini-3v3 = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc"]
_board-sparkfun-promini-5v = ["_mcu-atmega", "_default-serial", "atmega-hal/atmega328p", "atmega-hal/enable-extra-adc"]
_board-trinket = ["_mcu-attiny", "attiny-hal/attiny85"]
_board-nano168 = ["_mcu-atmega", "atmega-hal/atmega168", "atmega-hal/enable-extra-adc"]

_mcu-atmega = ["_board-selected"]
_mcu-attiny = ["_board-selected"]
_default-serial = []

_board-selected = []

docsrs = [
"arduino-diecimila",
"arduino-leonardo",
"arduino-mega2560",
"arduino-mega1280",
"arduino-nano",
"arduino-uno",
"trinket-pro",
"sparkfun-promicro",
"sparkfun-promini-3v3",
"sparkfun-promini-5v",
"trinket",
"nano168",
]

[dependencies]
cfg-if = "1"
Expand All @@ -51,12 +84,6 @@ path = "../avr-hal-generic/"
path = "../mcu/atmega-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
# is much less helpful in this situation).
features = ["disable-device-selection-error"]

[dependencies.attiny-hal]
path = "../mcu/attiny-hal/"
optional = true
Expand Down
5 changes: 5 additions & 0 deletions arduino-hal/src/adafruit/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(feature = "_board-trinket")]
pub mod trinket;

#[cfg(feature = "_board-trinket-pro")]
pub mod trinket_pro;
86 changes: 86 additions & 0 deletions arduino-hal/src/adafruit/trinket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
pub use attiny_hal::attiny85 as hal;

pub use hal::{pac, Peripherals};

pub mod clock {

//! MCU core clock support.
//!
//! This module contains common definitions to abtract over the MCU core clock speed. `avr-hal`
//! does not support changing the clock-speed at runtime.
//!
//! Most items in this module are re-exported from [`avr_hal_generic::clock`].
pub use avr_hal_generic::clock::*;

pub type DefaultClock = avr_hal_generic::clock::MHz8;
}

pub mod delay {
use crate::r#impl::impl_delay;
impl_delay! {
board: crate::adafruit::trinket
}
}

pub mod port {
use crate::adafruit::trinket as board;

pub use board::hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
pub struct Pins {
/// `#0`: `PB0`, `DI`(SPI), `SDA`(I2C)
pub d0: board::hal::port::PB0 = pb0,
/// `#1`: `PB1`, `DO`(SPI), Builtin LED
pub d1: board::hal::port::PB1 = pb1,
/// `#2`: `PB2`, `SCK`(SPI), `SCL`(I2C)
pub d2: board::hal::port::PB2 = pb2,
/// `#3`: `PB3`
pub d3: board::hal::port::PB3 = pb3,
/// `#4`: `PB4`
pub d4: board::hal::port::PB4 = pb4,
}

impl Pins {
type Pin = Pin;
type McuPins = board::hal::Pins;
}
}

/// Convenience macro to instantiate the [`Pins`] struct for this board.
///
/// # Example
/// ```no_run
/// let dp = arduino_hal::Peripherals::take().unwrap();
/// let pins = arduino_hal::pins!(dp);
/// ```
#[macro_export]
macro_rules! adafruit_trinket_pins {
($p:expr) => {
$crate::adafruit::trinket::Pins::with_mcu_pins($crate::adafruit::trinket::hal::pins!($p))
};
}

pub use adafruit_trinket_pins as pins;
}

pub mod eeprom {
use crate::r#impl::impl_eeprom;
impl_eeprom! {
board: crate::adafruit::trinket
}
}

pub mod simple_pwm {
use crate::r#impl::impl_simple_pwm;
impl_simple_pwm! {
board: crate::adafruit::trinket
}
}

pub use {
clock::DefaultClock,
delay::{delay_ms, delay_us, Delay},
eeprom::Eeprom,
port::{Pins, pins},
};
Loading