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 Digistump Digispark board #367

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 @@ -20,6 +20,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 @@ -23,6 +23,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 @@ -15,6 +15,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 = "**Digistump Digispark**.")]
//! 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 @@ -60,6 +61,7 @@ compile_error!(
* trinket-pro
* trinket
* nano168
* digispark
"
);

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

avr_hal_generic::renamed_pins! {
type Pin = Pin;

pub struct Pins from attiny_hal::Pins {
/// `#0`: `PB0`, `DI`(SPI), `SDA`(I2C)
pub d0: attiny_hal::port::PB0 = pb0,
/// `#1`: `PB1`, `DO`(SPI), Builtin LED
pub d1: attiny_hal::port::PB1 = pb1,
/// `#2`: `PB2`, `SCK`(SPI), `SCL`(I2C)
pub d2: attiny_hal::port::PB2 = pb2,
/// `#3`: `PB3`, USB-
pub d3: attiny_hal::port::PB3 = pb3,
/// `#4`: `PB4`, USB+
pub d4: attiny_hal::port::PB4 = pb4,
/// `#5`: `PB5`, Reset
pub d5: 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 = "micronucleus-runner"

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

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

[dependencies.arduino-hal]
path = "../../arduino-hal/"
features = ["digispark"]
25 changes: 25 additions & 0 deletions examples/digispark/src/bin/digispark-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 1 is also connected to an onboard LED marked "L"
let mut led = pins.d1.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);
}
}
28 changes: 28 additions & 0 deletions examples/digispark/src/bin/digispark-simple-pwm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*!
* Example of using simple_pwm to fade the built-in LED in and out.
*/

#![no_std]
#![no_main]

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

#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);

let timer0 = Timer0Pwm::new(dp.TC0, Prescaler::Prescale64);

// Digital pin 1 is also connected to an onboard LED marked "L"
let mut pwm_led = pins.d1.into_output().into_pwm(&timer0);
pwm_led.enable();

loop {
for x in (0..=255).chain((0..=254).rev()) {
pwm_led.set_duty(x);
arduino_hal::delay_ms(10);
}
}
}