Skip to content

Commit 3bf45ae

Browse files
committed
Upgrade arduino-hal to latest version.
1 parent 673fca7 commit 3bf45ae

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

Cargo.toml

+12-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,18 @@ ufmt = "0.1.0"
5252
version = "1.0"
5353
default-features = false
5454

55+
[dev-dependencies.avr-device]
56+
version = "0.3"
57+
features = ["atmega328p", "rt"]
5558

56-
[dev-dependencies.arduino-uno]
59+
[dev-dependencies.arduino-hal]
5760
# It is not yet available via crates.io
5861
git = "https://github.com/Rahix/avr-hal.git"
59-
rev = "0c6cf1675c2724354f1adeaeee69992acd371e80"
62+
rev = "e897783816437a677aa577ddfdaa34e9a1e86d96"
63+
features = ["arduino-uno"]
64+
65+
[dev-dependencies.atmega-hal]
66+
# It is not yet available via crates.io
67+
git = "https://github.com/Rahix/avr-hal.git"
68+
rev = "e897783816437a677aa577ddfdaa34e9a1e86d96"
69+

examples/printer/mod.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@
1010

1111
// Import the Arduino libraries, interestingly they don't cause problems perse
1212
// on other architectures. Through, we will not use there.
13-
use arduino_uno::prelude::*;
13+
use arduino_hal::port::mode::AnyInput;
14+
use arduino_hal::port::mode::Input;
15+
use arduino_hal::port::mode::Output;
16+
use arduino_hal::port::Pin;
17+
use arduino_hal::prelude::*;
1418

1519

1620
#[cfg(target_arch = "avr")]
17-
pub struct Printer(pub arduino_uno::Serial<arduino_uno::hal::port::mode::Floating>);
21+
pub struct Printer(
22+
pub arduino_hal::usart::Usart<
23+
avr_device::atmega328p::USART0,
24+
Pin<Input<AnyInput>, atmega_hal::port::PD0>,
25+
Pin<Output, atmega_hal::port::PD1>,
26+
>,
27+
);
1828
#[cfg(not(target_arch = "avr"))]
1929
pub struct Printer;
2030

examples/uno-serial.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
// Define no_std only for AVR
3535
#![cfg_attr(target_arch = "avr", no_std)]
36-
#![no_main]
36+
#![cfg_attr(target_arch = "avr", no_main)]
3737

3838

3939
use avr_progmem::progmem;
@@ -55,23 +55,17 @@ progmem! {
5555
mod printer;
5656
use printer::Printer;
5757

58-
#[no_mangle]
58+
#[cfg_attr(target_arch = "avr", arduino_hal::entry)]
5959
fn main() -> ! {
6060
let mut printer = {
6161
#[cfg(target_arch = "avr")]
6262
{
6363
// Initialize the USB-Serial output on the Arduino Uno
6464

65-
let dp = arduino_uno::Peripherals::take().unwrap();
65+
let dp = arduino_hal::Peripherals::take().unwrap();
66+
let pins = arduino_hal::pins!(dp);
67+
let serial = arduino_hal::default_serial!(dp, pins, 9600);
6668

67-
let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD);
68-
69-
let serial = arduino_uno::Serial::new(
70-
dp.USART0,
71-
pins.d0,
72-
pins.d1.into_output(&mut pins.ddr),
73-
9600,
74-
);
7569
Printer(serial)
7670
}
7771
#[cfg(not(target_arch = "avr"))]

examples/uno-string.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// Define no_std only for AVR
77
#![cfg_attr(target_arch = "avr", no_std)]
8-
#![no_main]
8+
#![cfg_attr(target_arch = "avr", no_main)]
99
//
1010
// To unwrap the Option in const context
1111
#![feature(const_option)]
@@ -46,23 +46,17 @@ temporary DRAM necessary.
4646
mod printer;
4747
use printer::Printer;
4848

49-
#[no_mangle]
49+
#[cfg_attr(target_arch = "avr", arduino_hal::entry)]
5050
fn main() -> ! {
5151
let mut printer = {
5252
#[cfg(target_arch = "avr")]
5353
{
5454
// Initialize the USB-Serial output on the Arduino Uno
5555

56-
let dp = arduino_uno::Peripherals::take().unwrap();
56+
let dp = arduino_hal::Peripherals::take().unwrap();
57+
let pins = arduino_hal::pins!(dp);
58+
let serial = arduino_hal::default_serial!(dp, pins, 9600);
5759

58-
let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD);
59-
60-
let serial = arduino_uno::Serial::new(
61-
dp.USART0,
62-
pins.d0,
63-
pins.d1.into_output(&mut pins.ddr),
64-
9600,
65-
);
6660
Printer(serial)
6761
}
6862
#[cfg(not(target_arch = "avr"))]

0 commit comments

Comments
 (0)