Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
- type: board
name: arduino-nano
examples: true
- type: board
name: arduino-micro
examples: true
- type: board
name: nano168
examples: true
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"examples/arduino-mega2560",
"examples/arduino-mega1280",
"examples/arduino-nano",
"examples/arduino-micro",
"examples/arduino-uno",
"examples/atmega2560",
"examples/nano168",
Expand Down
1 change: 1 addition & 0 deletions arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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-micro = ["mcu-atmega", "atmega-hal/atmega32u4", "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"]
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 @@ -20,6 +20,7 @@ pub(crate) mod default {
feature = "arduino-mega2560",
feature = "arduino-mega1280",
feature = "arduino-nano",
feature = "arduino-micro",
feature = "arduino-uno",
feature = "sparkfun-promicro",
feature = "sparkfun-promini-5v",
Expand Down
4 changes: 3 additions & 1 deletion arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![cfg_attr(feature = "arduino-leonardo", doc = "**Arduino Leonardo**.")]
#![cfg_attr(feature = "arduino-mega2560", doc = "**Arduino Mega 2560**.")]
#![cfg_attr(feature = "arduino-mega1280", doc = "**Arduino Mega 1280**.")]
#![cfg_attr(feature = "arduino-micro", doc = "**Arduino Micro**.")]
#![cfg_attr(feature = "arduino-nano", doc = "**Arduino Nano**.")]
#![cfg_attr(feature = "arduino-uno", doc = "**Arduino Uno**.")]
#![cfg_attr(feature = "sparkfun-promicro", doc = "**SparkFun ProMicro**.")]
Expand Down Expand Up @@ -64,6 +65,7 @@ compile_error!(
* arduino-leonardo
* arduino-mega2560
* arduino-mega1280
* arduino-micro
* arduino-nano
* arduino-uno
* sparkfun-promicro
Expand Down Expand Up @@ -238,7 +240,7 @@ macro_rules! pins {
/// let pins = arduino_hal::pins!(dp);
/// let serial = arduino_hal::default_serial!(dp, pins, 57600);
/// ```
#[cfg(any(feature = "arduino-leonardo"))]
#[cfg(any(feature = "arduino-leonardo", feature = "arduino-micro"))]
#[macro_export]
macro_rules! default_serial {
($p:expr, $pins:expr, $baud:expr) => {
Expand Down
2 changes: 1 addition & 1 deletion arduino-hal/src/port/leonardo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use atmega_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
/// Pins of the **Arduino Leonardo**.
/// Pins of the **Arduino Leonardo** and **Arduno Micro**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins {
Expand Down
4 changes: 2 additions & 2 deletions arduino-hal/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
mod diecimila;
#[cfg(feature = "arduino-diecimila")]
pub use diecimila::*;
#[cfg(feature = "arduino-leonardo")]
#[cfg(any(feature = "arduino-leonardo", feature = "arduino-micro"))]
mod leonardo;
#[cfg(feature = "arduino-leonardo")]
#[cfg(any(feature = "arduino-leonardo", feature = "arduino-micro"))]
pub use leonardo::*;
#[cfg(any(feature = "arduino-mega2560", feature = "arduino-mega1280"))]
mod mega;
Expand Down
6 changes: 6 additions & 0 deletions examples/arduino-leonardo/src/bin/leonardo-usart.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*!
* Demonstration of writing to and reading from the serial console.
*
* Note: To communicate with the Arduino over its hardware serial port, you must
* connect an external USB-to-UART adapter to the board’s RX and TX pins.
*/
#![no_std]
#![no_main]

Expand Down
9 changes: 9 additions & 0 deletions examples/arduino-micro/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build]
target = "avr-none"
rustflags = ["-C", "target-cpu=atmega32u4"]

[target.'cfg(target_arch = "avr")']
runner = "ravedude"

[unstable]
build-std = ["core"]
14 changes: 14 additions & 0 deletions examples/arduino-micro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "arduino-micro-examples"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
panic-halt = "1.0.0"
ufmt = "0.2.0"
nb = "1.1.0"

[dependencies.arduino-hal]
path = "../../arduino-hal/"
features = ["arduino-micro"]
12 changes: 12 additions & 0 deletions examples/arduino-micro/Ravedude.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[general]
board = "micro"

# The Arduino Micro does not have a UART console like other Arduino boards.
# Instead, it can emulate a console device over USB, but this is not yet
# supported in `avr-hal`. To get console output from an Arduino Micro, you
# need to connect an external usb-serial converter to the TX/RX pins of your
# board.
open-console = false

# For documentation about this file, check here:
# https://github.com/Rahix/avr-hal/blob/main/ravedude/README.md#ravedudetoml-format
28 changes: 28 additions & 0 deletions examples/arduino-micro/src/bin/micro-blink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*!
* Blink the builtin LED - the "Hello World" of embedded programming.
*/
#![no_std]
#![no_main]

use panic_halt as _;

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

// pin D13 is connected to an onboard LED
let mut led = pins.d13.into_output();
led.set_high();

loop {
led.toggle();
arduino_hal::delay_ms(100);
led.toggle();
arduino_hal::delay_ms(100);
led.toggle();
arduino_hal::delay_ms(100);
led.toggle();
arduino_hal::delay_ms(800);
}
}
33 changes: 33 additions & 0 deletions examples/arduino-micro/src/bin/micro-simple-pwm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*!
* Example of using simple_pwm to fade in and out the builtin LED.
*
* The Arduino Micro's bootloader does a similar animation, with a period of
* about one second per pulse. This example animation has a period of about five
* seconds per pulse in order to make it easily distinguishable from the
* bootloader's animation.
*/
#![no_std]
#![no_main]

use arduino_hal::simple_pwm::IntoPwmPin;
use arduino_hal::simple_pwm::Prescaler;
use arduino_hal::simple_pwm::Timer4Pwm;
use panic_halt as _;

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

let timer4 = Timer4Pwm::new(dp.TC4, Prescaler::Prescale64);

let mut pwm_led = pins.d13.into_output().into_pwm(&timer4);
pwm_led.enable();

loop {
for x in (0..=255).chain((0..=254).rev()) {
pwm_led.set_duty(x);
arduino_hal::delay_ms(10);
}
}
}
28 changes: 28 additions & 0 deletions examples/arduino-micro/src/bin/micro-usart.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*!
* Demonstration of writing to and reading from the serial console.
*
* Note: To communicate with the Arduino over its hardware serial port, you must
* connect an external USB-to-UART adapter to the board’s RX and TX pins.
*/
#![no_std]
#![no_main]

use arduino_hal::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);

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

loop {
// Read a byte from the serial connection
let b = nb::block!(serial.read()).unwrap_infallible();

// Answer
ufmt::uwriteln!(&mut serial, "Got {}!\r", b).unwrap_infallible();
}
}