Skip to content
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 @@ -37,6 +37,7 @@ members = [
"examples/sparkfun-promini-5v",
"examples/trinket-pro",
"examples/trinket",
"examples/usbtiny",
]
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 @@ -30,6 +30,7 @@ sparkfun-promini-3v3 = ["mcu-atmega", "atmega-hal/atmega328p", "atmega-hal/enabl
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"]
usbtiny = ["mcu-attiny", "attiny-hal/attiny85", "board-selected"]

# We must select a board to build on docs.rs
docsrs = ["arduino-uno"]
Expand Down
2 changes: 2 additions & 0 deletions arduino-hal/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ pub(crate) mod default {
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(any(feature = "trinket", feature = "sparkfun-promini-3v3"))]
pub type DefaultClock = avr_hal_generic::clock::MHz8;
#[cfg(any(feature = "usbtiny"))]
pub type DefaultClock = avr_hal_generic::clock::MHz1;
}
2 changes: 2 additions & 0 deletions arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 = "usbtiny", doc = "**USBTiny**.")]
//! 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 @@ -74,6 +75,7 @@ compile_error!(
* trinket-pro
* trinket
* nano168
* usbtiny
"
);

Expand Down
5 changes: 5 additions & 0 deletions arduino-hal/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ pub use trinket_pro::*;
mod trinket;
#[cfg(feature = "trinket")]
pub use trinket::*;

#[cfg(feature = "usbtiny")]
mod usbtiny;
#[cfg(feature = "usbtiny")]
pub use usbtiny::*;
23 changes: 23 additions & 0 deletions arduino-hal/src/port/usbtiny.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub use attiny_hal::port::{mode, Pin, PinMode, PinOps};

avr_hal_generic::renamed_pins! {
pub struct Pins {
/// `#0`: `PB0`, `0`, `PCINT0`, `D1`(SPI), `SDA`(I2C), `MOSI`, `AREF`, `OC0A`, `AIN0`
pub d0: attiny_hal::port::PB0 = pb0,
/// `#1`: `PB1`, `1`, `PCINT1`, `D0`(SPI), `SDA`(I2C), `MISO`, `AREF`, `OC0B`, `OC1A`, `AIN1`
pub d1: attiny_hal::port::PB1 = pb1,
/// `#2`: `PB2`, `2/A1`, `PCINT2` `SCK`(SPI), `SCL`(I2C), `INT0`, `ADC1`
pub d2: attiny_hal::port::PB2 = pb2,
/// `#3`: `PB3`, `3/A3`, `PCINT3`, `ACD3`, `XTAL1`
pub d3: attiny_hal::port::PB3 = pb3,
/// `#4`: `PB4`, `4/A2`, `PCINT4`, `OCB1`, `ADC2`, `XTAL2`
pub d4: attiny_hal::port::PB4 = pb4,
/// `#5`: `PB5`, `5/A0`, `PCINT5`, `RESET`, `ADC0`
pub d5: attiny_hal::port::PB5 = pb5,
}

impl Pins {
type Pin = Pin;
type McuPins = attiny_hal::Pins;
}
}
9 changes: 9 additions & 0 deletions examples/usbtiny/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build]
target = "avr-none"
rustflags = ["-C", "target-cpu=attiny85"]

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

[unstable]
build-std = ["core"]
14 changes: 14 additions & 0 deletions examples/usbtiny/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "usbtiny-examples"
version = "0.0.0"
authors = ["Derek Hemingson <shadetheartist@gmail.com>"]
edition = "2021"
publish = false

[dependencies]
panic-halt = "1.0.0"
embedded-hal = "1.0.0"

[dependencies.arduino-hal]
path = "../../arduino-hal"
features = ["usbtiny"]
5 changes: 5 additions & 0 deletions examples/usbtiny/Ravedude.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[general]
board = "usbtiny"

# For documentation about this file, check here:
# https://github.com/Rahix/avr-hal/blob/main/ravedude/README.md#ravedudetoml-format
19 changes: 19 additions & 0 deletions examples/usbtiny/src/bin/usbtiny-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 an onboard LED marked "L"
let mut led = pins.d1.into_output();
led.set_high();

loop {
led.toggle();
arduino_hal::delay_ms(100);
}
}
24 changes: 24 additions & 0 deletions examples/usbtiny/src/bin/usbtiny-custom-clock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![no_std]
#![no_main]

use arduino_hal::clock::MHz8;
use arduino_hal::hal::delay::Delay;
use embedded_hal::delay::DelayNs;
use panic_halt as _;


#[arduino_hal::entry]
fn main() -> ! {

let dp = arduino_hal::Peripherals::take().unwrap();
let pins: arduino_hal::Pins = arduino_hal::pins!(dp);


let mut led = pins.d1.into_output();
let mut delay: Delay<MHz8> = Delay::new();

loop {
led.toggle();
delay.delay_ms(1);
}
}
11 changes: 11 additions & 0 deletions ravedude/src/boards.toml
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,14 @@
do-chip-erase = true

# The AVR Butterfly does not have USB-Serial, thus no port is known or needed.
[usbtiny]
name = "USBTiny"

[usbtiny.reset]
automatic = true

[usbtiny.avrdude]
programmer = "usbtiny"
partno = "attiny85"
baudrate = -1
do-chip-erase = true