From 190f2c3cb8d29e10f71119352b912369dc5a1fb7 Mon Sep 17 00:00:00 2001 From: ani Date: Tue, 24 Oct 2023 18:17:47 -0400 Subject: [PATCH] Support the SparkFun ProMini 5V --- .github/workflows/ci.yml | 3 +++ Cargo.toml | 1 + arduino-hal/Cargo.toml | 1 + arduino-hal/src/clock.rs | 1 + arduino-hal/src/lib.rs | 4 ++- arduino-hal/src/port/mod.rs | 4 +-- arduino-hal/src/port/uno.rs | 2 +- .../sparkfun-promini-5v/.cargo/config.toml | 8 ++++++ examples/sparkfun-promini-5v/Cargo.toml | 16 ++++++++++++ .../src/bin/promini-5v-blink.rs | 25 ++++++++++++++++++ ravedude/src/board.rs | 26 +++++++++++++++++++ ravedude/src/main.rs | 1 + 12 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 examples/sparkfun-promini-5v/.cargo/config.toml create mode 100644 examples/sparkfun-promini-5v/Cargo.toml create mode 100644 examples/sparkfun-promini-5v/src/bin/promini-5v-blink.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8137e705a4..94636edf8a 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-5v + examples: true - type: board name: trinket-pro examples: true diff --git a/Cargo.toml b/Cargo.toml index ae61c621bb..edb6402040 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ members = [ "examples/arduino-uno", "examples/nano168", "examples/sparkfun-promicro", + "examples/sparkfun-promini-5v", "examples/trinket-pro", "examples/trinket", ] diff --git a/arduino-hal/Cargo.toml b/arduino-hal/Cargo.toml index 7a04f9a5e9..0d5ea4c5f9 100644 --- a/arduino-hal/Cargo.toml +++ b/arduino-hal/Cargo.toml @@ -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-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 af1db44848..81204945c2 100644 --- a/arduino-hal/src/clock.rs +++ b/arduino-hal/src/clock.rs @@ -22,6 +22,7 @@ pub(crate) mod default { feature = "arduino-nano", feature = "arduino-uno", feature = "sparkfun-promicro", + feature = "sparkfun-promini-5v", feature = "trinket-pro", feature = "nano168", ))] diff --git a/arduino-hal/src/lib.rs b/arduino-hal/src/lib.rs index 487c34ca0a..25b4c03ff6 100644 --- a/arduino-hal/src/lib.rs +++ b/arduino-hal/src/lib.rs @@ -13,6 +13,7 @@ #![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-5v", doc = "**SparkFun ProMini 5V (16MHz)**.")] #![cfg_attr(feature = "trinket-pro", doc = "**Trinket Pro**.")] #![cfg_attr(feature = "trinket", doc = "**Trinket**.")] #![cfg_attr(feature = "nano168", doc = "**Nano clone (ATmega168)**.")] @@ -59,6 +60,7 @@ compile_error!( * arduino-nano * arduino-uno * sparkfun-promicro + * sparkfun-promini-5v * trinket-pro * trinket * nano168 @@ -257,7 +259,7 @@ macro_rules! default_serial { ) }; } -#[cfg(any(feature = "arduino-nano", feature = "nano168"))] +#[cfg(any(feature = "arduino-nano", feature = "nano168", feature = "sparkfun-promini-5v"))] #[macro_export] macro_rules! default_serial { ($p:expr, $pins:expr, $baud:expr) => { diff --git a/arduino-hal/src/port/mod.rs b/arduino-hal/src/port/mod.rs index ce94ced476..ce85b31cc1 100644 --- a/arduino-hal/src/port/mod.rs +++ b/arduino-hal/src/port/mod.rs @@ -27,9 +27,9 @@ pub use leonardo::*; mod mega; #[cfg(any(feature = "arduino-mega2560", feature = "arduino-mega1280"))] pub use mega::*; -#[cfg(any(feature = "arduino-nano", feature = "arduino-uno", feature = "nano168"))] +#[cfg(any(feature = "arduino-nano", feature = "arduino-uno", feature = "nano168", feature = "sparkfun-promini-5v"))] mod uno; -#[cfg(any(feature = "arduino-nano", feature = "arduino-uno", feature = "nano168"))] +#[cfg(any(feature = "arduino-nano", feature = "arduino-uno", feature = "nano168", feature = "sparkfun-promini-5v"))] pub use uno::*; #[cfg(feature = "sparkfun-promicro")] mod promicro; diff --git a/arduino-hal/src/port/uno.rs b/arduino-hal/src/port/uno.rs index 301e5ef007..0894bf2863 100644 --- a/arduino-hal/src/port/uno.rs +++ b/arduino-hal/src/port/uno.rs @@ -3,7 +3,7 @@ pub use atmega_hal::port::{mode, Pin, PinOps, PinMode}; avr_hal_generic::renamed_pins! { type Pin = Pin; - /// Pins of the **Arduino Uno**. + /// Pins of the **Arduino Uno**, **Arduino Nano**, and **SparkFun ProMini 5V (16MHz)**. /// /// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro. pub struct Pins from atmega_hal::Pins { diff --git a/examples/sparkfun-promini-5v/.cargo/config.toml b/examples/sparkfun-promini-5v/.cargo/config.toml new file mode 100644 index 0000000000..b16ae4ec3a --- /dev/null +++ b/examples/sparkfun-promini-5v/.cargo/config.toml @@ -0,0 +1,8 @@ +[build] +target = "../../avr-specs/avr-atmega328p.json" + +[target.'cfg(target_arch = "avr")'] +runner = "ravedude promini-5v" + +[unstable] +build-std = ["core"] diff --git a/examples/sparkfun-promini-5v/Cargo.toml b/examples/sparkfun-promini-5v/Cargo.toml new file mode 100644 index 0000000000..6b48bec2c5 --- /dev/null +++ b/examples/sparkfun-promini-5v/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "sparkfun-promini-5v-examples" +version = "0.0.0" +authors = ["Rahix "] +edition = "2018" +publish = false + +[dependencies] +panic-halt = "0.2.0" +ufmt = "0.1.0" +nb = "0.1.2" +embedded-hal = "0.2.3" + +[dependencies.arduino-hal] +path = "../../arduino-hal/" +features = ["sparkfun-promini-5v"] diff --git a/examples/sparkfun-promini-5v/src/bin/promini-5v-blink.rs b/examples/sparkfun-promini-5v/src/bin/promini-5v-blink.rs new file mode 100644 index 0000000000..8650f1274d --- /dev/null +++ b/examples/sparkfun-promini-5v/src/bin/promini-5v-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 2f21093ad9..dd8dca0bca 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-5v" => Box::new(SparkFunProMini5V), "trinket-pro" => Box::new(TrinketPro), "trinket" => Box::new(Trinket), "nano168" => Box::new(Nano168), @@ -316,6 +317,31 @@ impl Board for SparkFunProMicro { } } +struct SparkFunProMini5V; + +impl Board for SparkFunProMini5V { + fn display_name(&self) -> &str { + "SparkFun Pro Mini 5V (16MHz)" + } + + 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 TrinketPro; impl Board for TrinketPro { diff --git a/ravedude/src/main.rs b/ravedude/src/main.rs index 53a787bafb..6973278b43 100644 --- a/ravedude/src/main.rs +++ b/ravedude/src/main.rs @@ -61,6 +61,7 @@ struct Args { /// * mega1280 /// * diecimila /// * promicro + /// * promini-5v /// * trinket-pro /// * trinket /// * nano168