Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Digispark boards #401

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -45,6 +45,9 @@ jobs:
- type: board
name: nano168
examples: true
- type: board
name: digispark
examples: true
- type: mcu
name: atmega1280
spec: atmega1280
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"examples/sparkfun-promicro",
"examples/trinket-pro",
"examples/trinket",
"examples/digispark",
]
exclude = [
# The RAVEDUDE! Yeah!
Expand Down
1 change: 1 addition & 0 deletions arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ trinket-pro = ["mcu-atmega", "atmega-hal/atmega328p", "board-selected"]
sparkfun-promicro = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]
trinket = ["mcu-attiny", "attiny-hal/attiny85", "board-selected"]
nano168 = ["mcu-atmega", "atmega-hal/atmega168", "atmega-hal/enable-extra-adc", "board-selected"]
digispark = ["mcu-attiny", "attiny-hal/attiny85", "board-selected"]

[dependencies]
cfg-if = "1"
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 @@ -24,6 +24,7 @@ pub(crate) mod default {
feature = "sparkfun-promicro",
feature = "trinket-pro",
feature = "nano168",
feature = "digispark",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(feature = "trinket")]
Expand Down
2 changes: 2 additions & 0 deletions arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#![cfg_attr(feature = "trinket-pro", doc = "**Trinket Pro**.")]
#![cfg_attr(feature = "trinket", doc = "**Trinket**.")]
#![cfg_attr(feature = "nano168", doc = "**Nano clone (ATmega168)**.")]
#![cfg_attr(feature = "digispark", doc = "**Digispark (model A)**.")]
//! This means that only items which are available for this board are visible. If you are using a
//! different board, try building the documentation locally with
//!
Expand Down Expand Up @@ -62,6 +63,7 @@ compile_error!(
* trinket-pro
* trinket
* nano168
* digispark
"
);

Expand Down
49 changes: 49 additions & 0 deletions arduino-hal/src/port/digispark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pub use attiny_hal::port::{mode, Pin, PinOps, PinMode};

avr_hal_generic::renamed_pins! {
type Pin = Pin;

/// Pins of the **Digispark (model A)** .
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins from attiny_hal::Pins {
/// `P0`
///
/// * PWM: [attiny_hal::timer::Timer0Pwm]
/// * MOSI (SPI bus master/slave input)
/// * SDA (2-wire serial bus data input/output line)
/// * PCINT0 (pin change interrupt 0)
pub p0: attiny_hal::port::PB0 = pb0,
/// `P1`
///
/// * PWM: [attiny_hal::timer::Timer0Pwm]
/// * MISO (SPI bus master input/slave output)
/// * PCINT1 (pin change interrupt 1)
pub p1: attiny_hal::port::PB1 = pb1,
/// `P2`
///
/// * ADC1 (ADC input channel 1)
/// * SCK (SPI bus master clock input)
/// * SCL (2-wire serial bus clock line)
/// * PCINT2 (pin change interrupt 2)
pub p2: attiny_hal::port::PB2 = pb2,
/// `P3`
///
/// * ADC3 (ADC input channel 3)
/// * USB+ (USB data + pin)
/// * PCINT3 (pin change interrupt 3)
pub p3: attiny_hal::port::PB3 = pb3,
/// `P4`
///
/// * PWM: [attiny_hal::timer::Timer1Pwm]
/// * ADC2 (ADC input channel 2)
/// * USB- (USB data - pin)
/// * PCINT4 (pin change interrupt 4)
pub p4: attiny_hal::port::PB4 = pb4,
/// `P5`
///
/// * ADC0 (ADC input channel 0)
/// * PCINT5 (pin change interrupt 5)
pub p5: attiny_hal::port::PB5 = pb5,
}
}
4 changes: 4 additions & 0 deletions arduino-hal/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ pub use trinket_pro::*;
mod trinket;
#[cfg(feature = "trinket")]
pub use trinket::*;
#[cfg(feature = "digispark")]
mod digispark;
#[cfg(feature = "digispark")]
pub use digispark::*;
8 changes: 8 additions & 0 deletions examples/digispark/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
target = "../../avr-specs/avr-attiny85.json"

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

[unstable]
build-std = ["core"]
13 changes: 13 additions & 0 deletions examples/digispark/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "digispark-examples"
version = "0.0.0"
authors = ["Petr Scheubrein <[email protected]>"]
edition = "2021"

[dependencies]
panic-halt = "0.2.0"
embedded-hal = "0.2.7"

[dependencies.arduino-hal]
path = "../../arduino-hal/"
features = ["digispark"]
19 changes: 19 additions & 0 deletions examples/digispark/src/bin/digispark-blink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![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 1 is also connected to the onboard LED
let mut led = pins.p1.into_output();
led.set_high();

loop {
led.toggle();
arduino_hal::delay_ms(100);
}
}
10 changes: 10 additions & 0 deletions ravedude/src/avrdude/avrdude.conf
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,16 @@ programmer
usbpid = 0x0c9f;
;

programmer
id = "micronucleus";
desc = "Micronucleus for bootloader";
type = "micronucleus";
#prog_modes = PM_SPM;
connection_type = usb;
usbvid = 0x16d0;
usbpid = 0x0753;
;

programmer
id = "butterfly";
desc = "Atmel Butterfly Development Board";
Expand Down
23 changes: 23 additions & 0 deletions ravedude/src/avrdude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ pub struct AvrdudeOptions<'a> {
pub partno: &'a str,
pub baudrate: Option<u32>,
pub do_chip_erase: bool,
pub do_verify_check: bool,
pub extended_parameters: &'a [&'a str],
}

impl<'a> Default for AvrdudeOptions<'a> {
fn default() -> Self {
AvrdudeOptions {
programmer: "",
partno: "",
baudrate: None,
do_chip_erase: true,
do_verify_check: true,
extended_parameters: &[],
}
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -84,6 +99,14 @@ impl Avrdude {
command = command.arg("-b").arg(baudrate.to_string());
}

if !options.do_verify_check {
command = command.arg("-V");
}

for param in options.extended_parameters {
command = command.arg("-x").arg(param);
}

// TODO: Check that `bin` does not contain :
let mut flash_instruction: std::ffi::OsString = "flash:w:".into();
flash_instruction.push(bin);
Expand Down
41 changes: 41 additions & 0 deletions ravedude/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn get_board(board: &str) -> Option<Box<dyn Board>> {
"trinket-pro" => Box::new(TrinketPro),
"trinket" => Box::new(Trinket),
"nano168" => Box::new(Nano168),
"digispark" => Box::new(Digispark),
_ => return None,
})
}
Expand Down Expand Up @@ -63,6 +64,7 @@ impl Board for ArduinoUno {
partno: "atmega328p",
baudrate: None,
do_chip_erase: true,
..Default::default()
}
}

Expand Down Expand Up @@ -93,6 +95,7 @@ impl Board for ArduinoMicro {
partno: "atmega32u4",
baudrate: Some(115200),
do_chip_erase: true,
..Default::default()
}
}

Expand Down Expand Up @@ -125,6 +128,7 @@ impl Board for ArduinoNano {
partno: "atmega328p",
baudrate: Some(57600),
do_chip_erase: true,
..Default::default()
}
}

Expand All @@ -150,6 +154,7 @@ impl Board for ArduinoNanoNew {
partno: "atmega328p",
baudrate: Some(115200),
do_chip_erase: true,
..Default::default()
}
}

Expand Down Expand Up @@ -187,6 +192,7 @@ impl Board for ArduinoLeonardo {
partno: "atmega32u4",
baudrate: None,
do_chip_erase: true,
..Default::default()
}
}

Expand Down Expand Up @@ -218,6 +224,7 @@ impl Board for ArduinoMega1280 {
partno: "atmega1280",
baudrate: Some(57600),
do_chip_erase: false,
..Default::default()
}
}

Expand Down Expand Up @@ -245,6 +252,7 @@ impl Board for ArduinoMega2560 {
partno: "atmega2560",
baudrate: Some(115200),
do_chip_erase: false,
..Default::default()
}
}

Expand Down Expand Up @@ -277,6 +285,7 @@ impl Board for ArduinoDiecimila {
partno: "atmega168",
baudrate: Some(19200),
do_chip_erase: false,
..Default::default()
}
}

Expand All @@ -302,6 +311,7 @@ impl Board for SparkFunProMicro {
partno: "atmega32u4",
baudrate: None,
do_chip_erase: true,
..Default::default()
}
}

Expand Down Expand Up @@ -332,6 +342,7 @@ impl Board for TrinketPro {
partno: "atmega328p",
baudrate: None,
do_chip_erase: false,
..Default::default()
}
}

Expand All @@ -357,6 +368,7 @@ impl Board for Trinket {
partno: "attiny85",
baudrate: None,
do_chip_erase: true,
..Default::default()
}
}

Expand All @@ -382,10 +394,39 @@ impl Board for Nano168 {
partno: "atmega168",
baudrate: Some(19200),
do_chip_erase: false,
..Default::default()
}
}

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

struct Digispark;

impl Board for Digispark {
fn display_name(&self) -> &str {
"Digispark (Model A)"
}

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

fn avrdude_options(&self) -> avrdude::AvrdudeOptions {
avrdude::AvrdudeOptions {
programmer: "micronucleus",
partno: "attiny85",
baudrate: None,
do_chip_erase: true,
do_verify_check: false,
extended_parameters: &["wait"],
..Default::default()
}
}

fn guess_port(&self) -> Option<anyhow::Result<std::path::PathBuf>> {
None
}
}
1 change: 1 addition & 0 deletions ravedude/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct Args {
/// * trinket-pro
/// * trinket
/// * nano168
/// * digispark
#[structopt(name = "BOARD", verbatim_doc_comment)]
board: String,

Expand Down