Skip to content

Commit

Permalink
Switch to no deprecated globals as default
Browse files Browse the repository at this point in the history
  • Loading branch information
innermatrix committed Dec 9, 2024
1 parent 7a896ef commit ab03998
Show file tree
Hide file tree
Showing 75 changed files with 502 additions and 431 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ jobs:
- name: Compile board crate (without examples)
if: "${{ matrix.m.type == 'board' && !matrix.m.examples }}"
run: cd "arduino-hal/" && cargo build --features "${{ matrix.m.name }}"
- name: Compile board crate (without examples) (no deprecated globals)
- name: Compile board crate (without examples) (deprecated globals)
if: "${{ matrix.m.type == 'board' && !matrix.m.examples }}"
run: cd "arduino-hal/" && cargo build --features "${{ matrix.m.name }}-no-deprecated-globals"
run: cd "arduino-hal/" && cargo build --features "${{ matrix.m.name }}-deprecated-globals"
- name: Test-compile HAL crate for an MCU
if: "${{ matrix.m.type == 'mcu' }}"
run: cd "mcu/${{ matrix.m.crate }}" && cargo build --features "${{ matrix.m.name }}" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"
- name: Test-compile HAL crate for an MCU (no deprecated globals)
- name: Test-compile HAL crate for an MCU (deprecated globals)
if: "${{ matrix.m.crate == 'attiny-hal' || matrix.m.crate == 'atmega-hal' }}"
run: >-
cd "mcu/${{ matrix.m.crate }}" &&
cargo build --features "${{ matrix.m.name }}-no-deprecated-globals" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"
cargo build --features "${{ matrix.m.name }}-deprecated-globals" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"
ravedude:
name: "ravedude"
Expand Down
35 changes: 17 additions & 18 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.2.0"
version = "0.3.0"

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

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

# Board-specific targets. Due to use of deprecated globals, only one board can be selected at a time
# In arduino-hal 0.3.0 the defaults will change to no deprecated globals
arduino-diecimila = ["arduino-diecimila-deprecated-globals"]
arduino-leonardo = ["arduino-leonardo-deprecated-globals"]
arduino-mega2560 = ["arduino-mega2560-deprecated-globals"]
arduino-mega1280 = ["arduino-mega1280-deprecated-globals"]
arduino-nano = ["arduino-nano-deprecated-globals"]
arduino-uno = ["arduino-uno-deprecated-globals"]
trinket-pro = ["trinket-pro-deprecated-globals"]
sparkfun-promicro = ["sparkfun-promicro-deprecated-globals"]
sparkfun-promini-3v3 = ["sparkfun-promini-3v3-deprecated-globals"]
sparkfun-promini-5v = ["sparkfun-promini-5v-deprecated-globals"]
trinket = ["trinket-deprecated-globals"]
nano168 = ["nano168-deprecated-globals"]

# Board-specific targets with deprecated globals. This is the default in arduino-hal <0.3.0
# Board-specific targets.
arduino-diecimila = ["arduino-diecimila-no-deprecated-globals"]
arduino-leonardo = ["arduino-leonardo-no-deprecated-globals"]
arduino-mega2560 = ["arduino-mega2560-no-deprecated-globals"]
arduino-mega1280 = ["arduino-mega1280-no-deprecated-globals"]
arduino-nano = ["arduino-nano-no-deprecated-globals"]
arduino-uno = ["arduino-uno-no-deprecated-globals"]
trinket-pro = ["trinket-pro-no-deprecated-globals"]
sparkfun-promicro = ["sparkfun-promicro-no-deprecated-globals"]
sparkfun-promini-3v3 = ["sparkfun-promini-3v3-no-deprecated-globals"]
sparkfun-promini-5v = ["sparkfun-promini-5v-no-deprecated-globals"]
trinket = ["trinket-no-deprecated-globals"]
nano168 = ["nano168-no-deprecated-globals"]

# Board-specific targets with deprecated globals. This was the default in arduino-hal <0.3.0
arduino-diecimila-deprecated-globals = [
"_board-arduino-diecimila",
"atmega-hal/deprecated-globals",
Expand Down Expand Up @@ -61,7 +60,7 @@ sparkfun-promini-5v-deprecated-globals = [
trinket-deprecated-globals = ["_board-trinket", "attiny-hal/deprecated-globals", "deprecated-globals"]
nano168-deprecated-globals = ["_board-nano168", "atmega-hal/deprecated-globals", "deprecated-globals"]

# Board-specific targets without deprecated globals. This will be the default in arduino-hal 0.3.0
# Board-specific targets without deprecated globals. This is the default in arduino-hal 0.3.0
arduino-diecimila-no-deprecated-globals = ["_board-arduino-diecimila"]
arduino-leonardo-no-deprecated-globals = ["_board-arduino-leonardo"]
arduino-mega2560-no-deprecated-globals = ["_board-arduino-mega2560"]
Expand Down
4 changes: 2 additions & 2 deletions arduino-hal/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ pub use crate::sparkfun::pro_mini_3v3 as board;
#[cfg(feature = "_board-sparkfun-promini-5v")]
pub use crate::sparkfun::pro_mini_5v as board;

#[cfg(feature = "_mcu-attiny")]
pub use attiny_hal as hal;
#[cfg(feature = "_mcu-atmega")]
pub use atmega_hal as hal;
#[cfg(feature = "_mcu-attiny")]
pub use attiny_hal as hal;

pub use board::{
clock,
Expand Down
1 change: 1 addition & 0 deletions arduino-hal/src/impl/usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ macro_rules! impl_usart_atmega {

#[cfg(feature = "_mcu-atmega")]
pub(crate) use impl_usart_atmega;

1 change: 0 additions & 1 deletion arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@ mod globals;

#[cfg(feature = "deprecated-globals")]
pub use globals::*;

15 changes: 8 additions & 7 deletions examples/arduino-diecimila/src/bin/diecimila-adc.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use panic_halt as _;

use arduino_hal::adc;
use arduino_hal::arduino::diecimila as board;
use board::prelude::*;
use board::adc;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);
let mut serial = board::default_serial!(dp, pins, 57600);

let mut adc = arduino_hal::Adc::new(dp.ADC, Default::default());
let mut adc = board::Adc::new(dp.ADC, Default::default());

let (vbg, gnd) = (
adc.read_blocking(&adc::channel::Vbg),
Expand All @@ -38,6 +39,6 @@ fn main() -> ! {
}

ufmt::uwriteln!(&mut serial, "").unwrap_infallible();
arduino_hal::delay_ms(1000);
board::delay_ms(1000);
}
}
8 changes: 5 additions & 3 deletions examples/arduino-diecimila/src/bin/diecimila-blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

use panic_halt as _;

use arduino_hal::arduino::diecimila as board;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);

let mut led = pins.d13.into_output().downgrade();

loop {
led.toggle();
arduino_hal::delay_ms(1000);
board::delay_ms(1000);
}
}
16 changes: 9 additions & 7 deletions examples/arduino-diecimila/src/bin/diecimila-i2cdetect.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use panic_halt as _;

use arduino_hal::arduino::diecimila as board;
use board::prelude::*;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);
let mut serial = board::default_serial!(dp, pins, 57600);

let mut i2c = arduino_hal::I2c::new(
let mut i2c = board::I2c::new(
dp.TWI,
pins.a4.into_pull_up_input(),
pins.a5.into_pull_up_input(),
50000,
);

ufmt::uwriteln!(&mut serial, "Write direction test:\r").unwrap_infallible();
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Write)
i2c.i2cdetect(&mut serial, board::i2c::Direction::Write)
.unwrap_infallible();
ufmt::uwriteln!(&mut serial, "\r\nRead direction test:\r").unwrap_infallible();
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Read)
i2c.i2cdetect(&mut serial, board::i2c::Direction::Read)
.unwrap_infallible();

loop {}
Expand Down
15 changes: 8 additions & 7 deletions examples/arduino-diecimila/src/bin/diecimila-spi-feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use arduino_hal::spi;
use arduino_hal::arduino::diecimila as board;
use board::prelude::*;
use board::spi;
use embedded_hal_v0::spi::FullDuplex;
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);

// set up serial interface for text output
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let mut serial = board::default_serial!(dp, pins, 57600);

// Create SPI interface.
let (mut spi, _) = arduino_hal::Spi::new(
let (mut spi, _) = board::Spi::new(
dp.SPI,
pins.d13.into_output(),
pins.d11.into_output(),
Expand All @@ -45,6 +46,6 @@ fn main() -> ! {
let data = nb::block!(spi.read()).unwrap_infallible();

ufmt::uwriteln!(&mut serial, "data: {}\r", data).unwrap_infallible();
arduino_hal::delay_ms(1000);
board::delay_ms(1000);
}
}
9 changes: 5 additions & 4 deletions examples/arduino-diecimila/src/bin/diecimila-usart.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use panic_halt as _;

use arduino_hal::arduino::diecimila as board;
use board::prelude::*;
use embedded_hal_v0::serial::Read;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);
let mut serial = board::default_serial!(dp, pins, 57600);

ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").unwrap_infallible();

Expand Down
15 changes: 8 additions & 7 deletions examples/arduino-leonardo/src/bin/leonardo-adc.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use arduino_hal::arduino::leonardo as board;
use board::prelude::*;
use panic_halt as _;

use arduino_hal::adc;
use board::adc;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);
let mut serial = board::default_serial!(dp, pins, 57600);

let mut adc = arduino_hal::Adc::new(dp.ADC, Default::default());
let mut adc = board::Adc::new(dp.ADC, Default::default());

let (vbg, gnd, tmp) = (
adc.read_blocking(&adc::channel::Vbg),
Expand Down Expand Up @@ -45,6 +46,6 @@ fn main() -> ! {
}

ufmt::uwriteln!(&mut serial, "").unwrap_infallible();
arduino_hal::delay_ms(1000);
board::delay_ms(1000);
}
}
7 changes: 4 additions & 3 deletions examples/arduino-leonardo/src/bin/leonardo-blink.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#![no_std]
#![no_main]

use arduino_hal::arduino::leonardo as board;
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);

let mut leds = [
pins.led_rx.into_output().downgrade(),
Expand All @@ -23,7 +24,7 @@ fn main() -> ! {
loop {
for i in 0..3 {
leds[i].toggle();
arduino_hal::delay_ms(100);
board::delay_ms(100);
leds[i].toggle();
}
}
Expand Down
16 changes: 9 additions & 7 deletions examples/arduino-leonardo/src/bin/leonardo-i2cdetect.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use arduino_hal::arduino::leonardo as board;

use board::prelude::*;
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);
let mut serial = board::default_serial!(dp, pins, 57600);

let mut i2c = arduino_hal::I2c::new(
let mut i2c = board::I2c::new(
dp.TWI,
pins.d2.into_pull_up_input(),
pins.d3.into_pull_up_input(),
50000,
);

ufmt::uwriteln!(&mut serial, "Write direction test:\r").unwrap_infallible();
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Write)
i2c.i2cdetect(&mut serial, board::i2c::Direction::Write)
.unwrap_infallible();
ufmt::uwriteln!(&mut serial, "\r\nRead direction test:\r").unwrap_infallible();
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Read)
i2c.i2cdetect(&mut serial, board::i2c::Direction::Read)
.unwrap_infallible();

loop {}
Expand Down
16 changes: 9 additions & 7 deletions examples/arduino-leonardo/src/bin/leonardo-spi-feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@
#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use arduino_hal::spi;
use arduino_hal::arduino::leonardo as board;

use board::prelude::*;
use board::spi;
use embedded_hal_v0::spi::FullDuplex;
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let dp = board::Peripherals::take().unwrap();
let pins = board::pins!(dp);

// set up serial interface for text output
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let mut serial = board::default_serial!(dp, pins, 57600);

// Create SPI interface.
let (mut spi, _) = arduino_hal::Spi::new(
let (mut spi, _) = board::Spi::new(
dp.SPI,
pins.sck.into_output(),
pins.mosi.into_output(),
Expand All @@ -45,6 +47,6 @@ fn main() -> ! {
let data = nb::block!(spi.read()).unwrap_infallible();

ufmt::uwriteln!(&mut serial, "data: {}\r", data).unwrap_infallible();
arduino_hal::delay_ms(1000);
board::delay_ms(1000);
}
}
Loading

0 comments on commit ab03998

Please sign in to comment.