Skip to content

Commit

Permalink
Add support for Sparkfun ProMini 3.3V 8MHz
Browse files Browse the repository at this point in the history
  • Loading branch information
tippfehlr authored and Rahix committed Mar 31, 2024
1 parent 2eb28fa commit 21342dc
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- type: board
name: sparkfun-promicro
examples: true
- type: board
name: sparkfun-promini-3v3
examples: true
- type: board
name: sparkfun-promini-5v
examples: true
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"examples/arduino-uno",
"examples/nano168",
"examples/sparkfun-promicro",
"examples/sparkfun-promini-3v3",
"examples/sparkfun-promini-5v",
"examples/trinket-pro",
"examples/trinket",
Expand Down
5 changes: 3 additions & 2 deletions arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ rt = ["avr-device/rt"]
critical-section-impl = ["avr-device/critical-section-impl"]

board-selected = []
mcu-atmega=[]
mcu-attiny=[]
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"]
Expand All @@ -21,6 +21,7 @@ arduino-nano = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enable-extra-
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"]
Expand Down
2 changes: 1 addition & 1 deletion arduino-hal/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ pub(crate) mod default {
feature = "nano168",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(feature = "trinket")]
#[cfg(any(feature = "trinket", feature = "sparkfun-promini-3v3"))]
pub type DefaultClock = avr_hal_generic::clock::MHz8;
}
8 changes: 7 additions & 1 deletion arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#![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-promini-3v3",
doc = "**SparkFun ProMini 3.3V (8MHz)**."
)]
#![cfg_attr(
feature = "sparkfun-promini-5v",
doc = "**SparkFun ProMini 5V (16MHz)**."
Expand Down Expand Up @@ -63,6 +67,7 @@ compile_error!(
* arduino-nano
* arduino-uno
* sparkfun-promicro
* sparkfun-promini-3v3
* sparkfun-promini-5v
* trinket-pro
* trinket
Expand Down Expand Up @@ -265,7 +270,8 @@ macro_rules! default_serial {
#[cfg(any(
feature = "arduino-nano",
feature = "nano168",
feature = "sparkfun-promini-5v"
feature = "sparkfun-promini-3v3",
feature = "sparkfun-promini-5v",
))]
#[macro_export]
macro_rules! default_serial {
Expand Down
2 changes: 2 additions & 0 deletions arduino-hal/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ pub use mega::*;
feature = "arduino-nano",
feature = "arduino-uno",
feature = "nano168",
feature = "sparkfun-promini-3v3",
feature = "sparkfun-promini-5v"
))]
mod uno;
#[cfg(any(
feature = "arduino-nano",
feature = "arduino-uno",
feature = "nano168",
feature = "sparkfun-promini-3v3",
feature = "sparkfun-promini-5v"
))]
pub use uno::*;
Expand Down
2 changes: 1 addition & 1 deletion arduino-hal/src/port/uno.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 Uno**, **Arduino Nano**, and **SparkFun ProMini 5V (16MHz)**.
/// Pins of the **Arduino Uno**, **Arduino Nano**, **SparkFun ProMini 3.3V (8Mhz)**, and **SparkFun ProMini 5V (16MHz)**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins {
Expand Down
8 changes: 8 additions & 0 deletions examples/sparkfun-promini-3v3/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
target = "../../avr-specs/avr-atmega328p.json"

[target.'cfg(target_arch = "avr")']
runner = "ravedude promini-3v3"

[unstable]
build-std = ["core"]
20 changes: 20 additions & 0 deletions examples/sparkfun-promini-3v3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "sparkfun-promini-3v3-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-promini-3v3"]
25 changes: 25 additions & 0 deletions examples/sparkfun-promini-3v3/src/bin/promini-3v3-blink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![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);

// Digital pin 13 is also connected to an onboard LED marked "L"
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);
}
}
26 changes: 26 additions & 0 deletions ravedude/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn get_board(board: &str) -> Option<Box<dyn Board>> {
"mega1280" => Box::new(ArduinoMega1280),
"diecimila" => Box::new(ArduinoDiecimila),
"promicro" => Box::new(SparkFunProMicro),
"promini-3v3" => Box::new(SparkFunProMini3V),
"promini-5v" => Box::new(SparkFunProMini5V),
"trinket-pro" => Box::new(TrinketPro),
"trinket" => Box::new(Trinket),
Expand Down Expand Up @@ -313,6 +314,31 @@ impl Board for SparkFunProMicro {
}
}

struct SparkFunProMini3V;

impl Board for SparkFunProMini3V {
fn display_name(&self) -> &str {
"SparkFun Pro Mini 3.3V (8MHz)"
}

fn needs_reset(&self) -> Option<&str> {
None
}

fn avrdude_options(&self) -> avrdude::AvrdudeOptions {
avrdude::AvrdudeOptions {
programmer: "arduino",
partno: "atmega328p",
baudrate: Some(57600),
do_chip_erase: true,
}
}

fn guess_port(&self) -> Option<anyhow::Result<std::path::PathBuf>> {
Some(Err(anyhow::anyhow!("Not able to guess port")))
}
}

struct SparkFunProMini5V;

impl Board for SparkFunProMini5V {
Expand Down
1 change: 1 addition & 0 deletions ravedude/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct Args {
/// * mega1280
/// * diecimila
/// * promicro
/// * promini-3v3
/// * promini-5v
/// * trinket-pro
/// * trinket
Expand Down

0 comments on commit 21342dc

Please sign in to comment.