Skip to content

Commit

Permalink
add support for SparkFun Pro Micro 3.3V (8MHz)
Browse files Browse the repository at this point in the history
  • Loading branch information
tones111 committed Dec 31, 2024
1 parent 949130a commit ed73383
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ jobs:
name: arduino-mega1280
examples: true
- type: board
name: sparkfun-promicro
name: sparkfun-promicro-3v3
examples: true
- type: board
name: sparkfun-promicro-5v
examples: true
- type: board
name: sparkfun-promini-3v3
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ members = [
"examples/arduino-uno",
"examples/atmega2560",
"examples/nano168",
"examples/sparkfun-promicro",
"examples/sparkfun-promicro-3v3",
"examples/sparkfun-promicro-5v",
"examples/sparkfun-promini-3v3",
"examples/sparkfun-promini-5v",
"examples/trinket-pro",
Expand Down
3 changes: 2 additions & 1 deletion arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ 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-promicro-3v3 = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
sparkfun-promicro-5v = ["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"]
Expand Down
8 changes: 6 additions & 2 deletions arduino-hal/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ pub(crate) mod default {
feature = "arduino-mega1280",
feature = "arduino-nano",
feature = "arduino-uno",
feature = "sparkfun-promicro",
feature = "sparkfun-promicro-5v",
feature = "sparkfun-promini-5v",
feature = "trinket-pro",
feature = "nano168",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(any(feature = "trinket", feature = "sparkfun-promini-3v3"))]
#[cfg(any(
feature = "trinket",
feature = "sparkfun-promicro-3v3",
feature = "sparkfun-promini-3v3",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz8;
}
14 changes: 11 additions & 3 deletions arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
#![cfg_attr(feature = "arduino-mega1280", doc = "**Arduino Mega 1280**.")]
#![cfg_attr(feature = "arduino-nano", doc = "**Arduino Nano**.")]
#![cfg_attr(feature = "arduino-uno", doc = "**Arduino Uno**.")]
#![cfg_attr(feature = "sparkfun-promicro", doc = "**SparkFun ProMicro**.")]
#![cfg_attr(
feature = "sparkfun-promicro-3v3",
doc = "**SparkFun ProMicro 3.3V (8MHz)**."
)]
#![cfg_attr(
feature = "sparkfun-promicro-5v",
doc = "**SparkFun ProMicro 5V (16MHz)**."
)]
#![cfg_attr(
feature = "sparkfun-promini-3v3",
doc = "**SparkFun ProMini 3.3V (8MHz)**."
Expand Down Expand Up @@ -66,7 +73,8 @@ compile_error!(
* arduino-mega1280
* arduino-nano
* arduino-uno
* sparkfun-promicro
* sparkfun-promicro-3v3
* sparkfun-promicro-5v
* sparkfun-promini-3v3
* sparkfun-promini-5v
* trinket-pro
Expand Down Expand Up @@ -259,7 +267,7 @@ macro_rules! default_serial {
/// let pins = arduino_hal::pins!(dp);
/// let serial = arduino_hal::default_serial!(dp, pins, 57600);
/// ```
#[cfg(any(feature = "sparkfun-promicro"))]
#[cfg(any(feature = "sparkfun-promicro-3v3", features = "sparkfun-promicro-5v"))]
#[macro_export]
macro_rules! default_serial {
($p:expr, $pins:expr, $baud:expr) => {
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 @@ -43,9 +43,9 @@ mod uno;
feature = "sparkfun-promini-5v"
))]
pub use uno::*;
#[cfg(feature = "sparkfun-promicro")]
#[cfg(any(feature = "sparkfun-promicro-3v3", feature = "sparkfun-promicro-5v"))]
mod promicro;
#[cfg(feature = "sparkfun-promicro")]
#[cfg(any(feature = "sparkfun-promicro-3v3", feature = "sparkfun-promicro-5v"))]
pub use promicro::*;
#[cfg(feature = "trinket-pro")]
mod trinket_pro;
Expand Down
26 changes: 26 additions & 0 deletions examples/sparkfun-promicro-3v3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "sparkfun-promicro-examples"
version = "0.0.0"
authors = ["Rahix <rahix@rahix.de>"]
edition = "2021"
publish = false

[dependencies]
panic-halt = "0.2.0"
ufmt = "0.2.0"
nb = "1.1.0"
embedded-hal = "1.0"

[dependencies.embedded-hal-v0]
version = "0.2.3"
package = "embedded-hal"

[dependencies.arduino-hal]
path = "../../arduino-hal/"
features = ["sparkfun-promicro-3v3"]

# The latest releases of `proc-macro2` do not support the rust toolchain that
# we use. Thus, we must fix this dependency to an older version where our
# toolchain is still supported. See https://github.com/Rahix/avr-hal/issues/537
[build-dependencies.proc-macro2]
version = "=1.0.79"
8 changes: 8 additions & 0 deletions examples/sparkfun-promicro-5v/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
target = "../../avr-specs/avr-atmega32u4.json"

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

[unstable]
build-std = ["core"]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package = "embedded-hal"

[dependencies.arduino-hal]
path = "../../arduino-hal/"
features = ["sparkfun-promicro"]
features = ["sparkfun-promicro-5v"]

# The latest releases of `proc-macro2` do not support the rust toolchain that
# we use. Thus, we must fix this dependency to an older version where our
Expand Down
46 changes: 46 additions & 0 deletions examples/sparkfun-promicro-5v/src/bin/promicro-adc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#![no_std]
#![no_main]

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

use arduino_hal::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 mut adc = arduino_hal::Adc::new(dp.ADC, Default::default());

let (vbg, gnd, tmp) = (
adc.read_blocking(&adc::channel::Vbg),
adc.read_blocking(&adc::channel::Gnd),
adc.read_blocking(&adc::channel::Temperature),
);
ufmt::uwriteln!(&mut serial, "Vbandgap: {}", vbg).unwrap_infallible();
ufmt::uwriteln!(&mut serial, "Ground: {}", gnd).unwrap_infallible();
ufmt::uwriteln!(&mut serial, "Temperature: {}", tmp).unwrap_infallible();

let a0 = pins.a0.into_analog_input(&mut adc);
let a1 = pins.a1.into_analog_input(&mut adc);
let a2 = pins.a2.into_analog_input(&mut adc);
let a3 = pins.a3.into_analog_input(&mut adc);

loop {
let values = [
a0.analog_read(&mut adc),
a1.analog_read(&mut adc),
a2.analog_read(&mut adc),
a3.analog_read(&mut adc),
];

for (i, v) in values.iter().enumerate() {
ufmt::uwrite!(&mut serial, "A{}: {} ", i, v).unwrap_infallible();
}

ufmt::uwriteln!(&mut serial, "").unwrap_infallible();
arduino_hal::delay_ms(1000);
}
}
22 changes: 22 additions & 0 deletions examples/sparkfun-promicro-5v/src/bin/promicro-blink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![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);

let mut led1 = pins.led_rx.into_output();
let mut led2 = pins.led_tx.into_output();

loop {
led1.set_high();
led2.set_low();
arduino_hal::delay_ms(300);
led1.set_low();
led2.set_high();
arduino_hal::delay_ms(300);
}
}
28 changes: 28 additions & 0 deletions examples/sparkfun-promicro-5v/src/bin/promicro-i2cdetect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![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);

let mut i2c = arduino_hal::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)
.unwrap_infallible();
ufmt::uwriteln!(&mut serial, "\r\nRead direction test:\r").unwrap_infallible();
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Read)
.unwrap_infallible();

loop {}
}
50 changes: 50 additions & 0 deletions examples/sparkfun-promicro-5v/src/bin/promicro-spi-feedback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! This example demonstrates how to set up a SPI interface and communicate
//! over it. The physical hardware configuation consists of connecting a
//! jumper directly from pin `~14` to pin `~16`.
//!
//! Once this program is written to the board, the serial output can be
//! accessed with
//!
//! ```
//! sudo screen /dev/ttyACM0 57600
//! ```
//!
//! You should see it output the line `data: 15` repeatedly (aka 0b00001111).
//! If the output you see is `data: 255`, you may need to check your jumper.
#![no_std]
#![no_main]

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

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

// Create SPI interface.
let (mut spi, _) = arduino_hal::Spi::new(
dp.SPI,
pins.d15.into_output(),
pins.d14.into_output(),
pins.d16.into_pull_up_input(),
pins.led_rx.into_output(),
spi::Settings::default(),
);

loop {
// Send a byte
nb::block!(spi.send(0b00001111)).unwrap_infallible();
// Because MISO is connected to MOSI, the read data should be the same
let data = nb::block!(spi.read()).unwrap_infallible();

ufmt::uwriteln!(&mut serial, "data: {}\r", data).unwrap_infallible();
arduino_hal::delay_ms(1000);
}
}
24 changes: 24 additions & 0 deletions examples/sparkfun-promicro-5v/src/bin/promicro-usart.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![no_std]
#![no_main]

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

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);

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();
}
}

0 comments on commit ed73383

Please sign in to comment.