diff --git a/Cargo.toml b/Cargo.toml index 37e13b64cc..badaa588fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ members = [ "examples/sparkfun-promini-5v", "examples/trinket-pro", "examples/trinket", + "examples/usbtiny", ] exclude = [ # The RAVEDUDE! Yeah! diff --git a/arduino-hal/Cargo.toml b/arduino-hal/Cargo.toml index 234bfa1607..3fdbe05979 100644 --- a/arduino-hal/Cargo.toml +++ b/arduino-hal/Cargo.toml @@ -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"] diff --git a/arduino-hal/src/clock.rs b/arduino-hal/src/clock.rs index 67d4230015..e5c609ab9f 100644 --- a/arduino-hal/src/clock.rs +++ b/arduino-hal/src/clock.rs @@ -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; } diff --git a/arduino-hal/src/lib.rs b/arduino-hal/src/lib.rs index e0d5c69373..1d33b3de5d 100644 --- a/arduino-hal/src/lib.rs +++ b/arduino-hal/src/lib.rs @@ -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 //! @@ -74,6 +75,7 @@ compile_error!( * trinket-pro * trinket * nano168 + * usbtiny " ); diff --git a/arduino-hal/src/port/mod.rs b/arduino-hal/src/port/mod.rs index 93eacd8d6f..b2246d5722 100644 --- a/arduino-hal/src/port/mod.rs +++ b/arduino-hal/src/port/mod.rs @@ -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::*; \ No newline at end of file diff --git a/arduino-hal/src/port/usbtiny.rs b/arduino-hal/src/port/usbtiny.rs new file mode 100644 index 0000000000..0666819142 --- /dev/null +++ b/arduino-hal/src/port/usbtiny.rs @@ -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; + } +} diff --git a/examples/usbtiny/.cargo/config.toml b/examples/usbtiny/.cargo/config.toml new file mode 100644 index 0000000000..bb43f7c968 --- /dev/null +++ b/examples/usbtiny/.cargo/config.toml @@ -0,0 +1,9 @@ +[build] +target = "avr-none" +rustflags = ["-C", "target-cpu=attiny85"] + +[target.'cfg(target_arch = "avr")'] +runner = "ravedude" + +[unstable] +build-std = ["core"] diff --git a/examples/usbtiny/Cargo.toml b/examples/usbtiny/Cargo.toml new file mode 100644 index 0000000000..515673643c --- /dev/null +++ b/examples/usbtiny/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "usbtiny-examples" +version = "0.0.0" +authors = ["Derek Hemingson "] +edition = "2021" +publish = false + +[dependencies] +panic-halt = "1.0.0" +embedded-hal = "1.0.0" + +[dependencies.arduino-hal] +path = "../../arduino-hal" +features = ["usbtiny"] diff --git a/examples/usbtiny/Ravedude.toml b/examples/usbtiny/Ravedude.toml new file mode 100644 index 0000000000..94c9707c8d --- /dev/null +++ b/examples/usbtiny/Ravedude.toml @@ -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 diff --git a/examples/usbtiny/src/bin/usbtiny-blink.rs b/examples/usbtiny/src/bin/usbtiny-blink.rs new file mode 100644 index 0000000000..a7541ecace --- /dev/null +++ b/examples/usbtiny/src/bin/usbtiny-blink.rs @@ -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); + } +} diff --git a/examples/usbtiny/src/bin/usbtiny-custom-clock.rs b/examples/usbtiny/src/bin/usbtiny-custom-clock.rs new file mode 100644 index 0000000000..f4951d7e0d --- /dev/null +++ b/examples/usbtiny/src/bin/usbtiny-custom-clock.rs @@ -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 = Delay::new(); + + loop { + led.toggle(); + delay.delay_ms(1); + } +} diff --git a/ravedude/src/boards.toml b/ravedude/src/boards.toml index 3379139943..fb2dbde221 100644 --- a/ravedude/src/boards.toml +++ b/ravedude/src/boards.toml @@ -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