From 21342dcace7184f01fdc4e9703b01197bd4b4b4f Mon Sep 17 00:00:00 2001 From: tippfehlr Date: Sun, 14 Jan 2024 20:12:17 +0100 Subject: [PATCH] Add support for Sparkfun ProMini 3.3V 8MHz --- .github/workflows/ci.yml | 3 +++ Cargo.toml | 1 + arduino-hal/Cargo.toml | 5 ++-- arduino-hal/src/clock.rs | 2 +- arduino-hal/src/lib.rs | 8 +++++- arduino-hal/src/port/mod.rs | 2 ++ arduino-hal/src/port/uno.rs | 2 +- .../sparkfun-promini-3v3/.cargo/config.toml | 8 ++++++ examples/sparkfun-promini-3v3/Cargo.toml | 20 ++++++++++++++ .../src/bin/promini-3v3-blink.rs | 25 ++++++++++++++++++ ravedude/src/board.rs | 26 +++++++++++++++++++ ravedude/src/main.rs | 1 + 12 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 examples/sparkfun-promini-3v3/.cargo/config.toml create mode 100644 examples/sparkfun-promini-3v3/Cargo.toml create mode 100644 examples/sparkfun-promini-3v3/src/bin/promini-3v3-blink.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6829e98bf..5345c91936 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 33bffe79e4..3518c13f66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/arduino-hal/Cargo.toml b/arduino-hal/Cargo.toml index 4cd6746ca5..97a4244e57 100644 --- a/arduino-hal/Cargo.toml +++ b/arduino-hal/Cargo.toml @@ -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"] @@ -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"] diff --git a/arduino-hal/src/clock.rs b/arduino-hal/src/clock.rs index 81204945c2..7c53088015 100644 --- a/arduino-hal/src/clock.rs +++ b/arduino-hal/src/clock.rs @@ -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; } diff --git a/arduino-hal/src/lib.rs b/arduino-hal/src/lib.rs index f866faf27d..e6538dfebc 100644 --- a/arduino-hal/src/lib.rs +++ b/arduino-hal/src/lib.rs @@ -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)**." @@ -63,6 +67,7 @@ compile_error!( * arduino-nano * arduino-uno * sparkfun-promicro + * sparkfun-promini-3v3 * sparkfun-promini-5v * trinket-pro * trinket @@ -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 { diff --git a/arduino-hal/src/port/mod.rs b/arduino-hal/src/port/mod.rs index f4ed4d6a9b..160d3f9811 100644 --- a/arduino-hal/src/port/mod.rs +++ b/arduino-hal/src/port/mod.rs @@ -31,6 +31,7 @@ pub use mega::*; feature = "arduino-nano", feature = "arduino-uno", feature = "nano168", + feature = "sparkfun-promini-3v3", feature = "sparkfun-promini-5v" ))] mod uno; @@ -38,6 +39,7 @@ mod uno; feature = "arduino-nano", feature = "arduino-uno", feature = "nano168", + feature = "sparkfun-promini-3v3", feature = "sparkfun-promini-5v" ))] pub use uno::*; diff --git a/arduino-hal/src/port/uno.rs b/arduino-hal/src/port/uno.rs index c3b53c9bba..ae193edd27 100644 --- a/arduino-hal/src/port/uno.rs +++ b/arduino-hal/src/port/uno.rs @@ -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 { diff --git a/examples/sparkfun-promini-3v3/.cargo/config.toml b/examples/sparkfun-promini-3v3/.cargo/config.toml new file mode 100644 index 0000000000..a7c430c58c --- /dev/null +++ b/examples/sparkfun-promini-3v3/.cargo/config.toml @@ -0,0 +1,8 @@ +[build] +target = "../../avr-specs/avr-atmega328p.json" + +[target.'cfg(target_arch = "avr")'] +runner = "ravedude promini-3v3" + +[unstable] +build-std = ["core"] diff --git a/examples/sparkfun-promini-3v3/Cargo.toml b/examples/sparkfun-promini-3v3/Cargo.toml new file mode 100644 index 0000000000..0ca64c6bb3 --- /dev/null +++ b/examples/sparkfun-promini-3v3/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "sparkfun-promini-3v3-examples" +version = "0.0.0" +authors = ["Rahix "] +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"] diff --git a/examples/sparkfun-promini-3v3/src/bin/promini-3v3-blink.rs b/examples/sparkfun-promini-3v3/src/bin/promini-3v3-blink.rs new file mode 100644 index 0000000000..8650f1274d --- /dev/null +++ b/examples/sparkfun-promini-3v3/src/bin/promini-3v3-blink.rs @@ -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); + } +} diff --git a/ravedude/src/board.rs b/ravedude/src/board.rs index 3882b56045..5bb3991327 100644 --- a/ravedude/src/board.rs +++ b/ravedude/src/board.rs @@ -18,6 +18,7 @@ pub fn get_board(board: &str) -> Option> { "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), @@ -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> { + Some(Err(anyhow::anyhow!("Not able to guess port"))) + } +} + struct SparkFunProMini5V; impl Board for SparkFunProMini5V { diff --git a/ravedude/src/main.rs b/ravedude/src/main.rs index 5722704100..d91ec780f9 100644 --- a/ravedude/src/main.rs +++ b/ravedude/src/main.rs @@ -65,6 +65,7 @@ struct Args { /// * mega1280 /// * diecimila /// * promicro + /// * promini-3v3 /// * promini-5v /// * trinket-pro /// * trinket