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 Adafruit Circuit Playground Classic #467

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -29,6 +29,7 @@ members = [
"examples/arduino-mega1280",
"examples/arduino-nano",
"examples/arduino-uno",
"examples/circuit-playground-classic",
"examples/nano168",
"examples/sparkfun-promicro",
"examples/sparkfun-promini-5v",
Expand Down
1 change: 1 addition & 0 deletions arduino-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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"]
circuit-playground-classic = ["mcu-atmega", "atmega-hal/atmega32u4", "board-selected"]

[dependencies]
cfg-if = "1"
Expand Down
5 changes: 4 additions & 1 deletion arduino-hal/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub(crate) mod default {
feature = "nano168",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz16;
#[cfg(feature = "trinket")]
#[cfg(any(
feature = "trinket",
feature = "circuit-playground-classic",
))]
pub type DefaultClock = avr_hal_generic::clock::MHz8;
}
2 changes: 2 additions & 0 deletions arduino-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 = "circuit-playground-classic", doc = "**Adafruit Circuit Playground Classic (ATmega32u4)**.")]
//! 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 @@ -64,6 +65,7 @@ compile_error!(
* trinket-pro
* trinket
* nano168
* circuit-playground-classic
"
);

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

avr_hal_generic::renamed_pins! {
/// Pins of the **Circuit Playground Classic**.
///
/// This struct is best initialized via the [`arduino_hal::pins!()`][crate::pins] macro.
pub struct Pins {
/// `#11`: `PB7`
pub d11: atmega_hal::port::PB7 = pb7,
/// `#13`: `PC7`, Builtin LED
pub d13: atmega_hal::port::PC7 = pc7,
}

impl Pins {
type Pin = Pin;
type McuPins = atmega_hal::Pins;
}
}
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 = "circuit-playground-classic")]
mod circuit_playground_classic;
#[cfg(feature = "circuit-playground-classic")]
pub use circuit_playground_classic::*;
8 changes: 8 additions & 0 deletions examples/circuit-playground-classic/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
target = "../../avr-specs/avr-atmega32u4.json"

[target.'cfg(target_arch = "avr")']
runner = "ravedude circuit-playground-classic"

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

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

[dependencies.arduino-hal]
path = "../../arduino-hal"
features = ["circuit-playground-classic"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![no_std]
#![no_main]

use panic_halt as _;

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

let pins = arduino_hal::pins!(dp);

// Digital pin 13 is also connected to an onboard LED
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);
}
}
28 changes: 28 additions & 0 deletions ravedude/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn get_board(board: &str) -> Option<Box<dyn Board>> {
"trinket" => Box::new(Trinket),
"nano168" => Box::new(Nano168),
"duemilanove" => Box::new(ArduinoDuemilanove),
"circuit-playground-classic" => Box::new(CircuitPlaygroundClassic),
_ => return None,
})
}
Expand Down Expand Up @@ -442,3 +443,30 @@ impl Board for ArduinoDuemilanove {
Some(Err(anyhow::anyhow!("Not able to guess port")))
}
}

struct CircuitPlaygroundClassic;

impl Board for CircuitPlaygroundClassic {
fn display_name(&self) -> &str {
"Circuit Playground Classic"
}

fn needs_reset(&self) -> Option<&str> {
Some("Reset the board by pressing the reset button once.")
}

fn dude_options(&self) -> avrdude::AvrdudeOptions {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nees to be avrdude_options :)

Suggested change
fn dude_options(&self) -> avrdude::AvrdudeOptions {
fn avrdude_options(&self) -> avrdude::AvrdudeOptions {

avrdude::AvrdudeOptions {
programmer: "avr109",
partno: "atmega32u4",
baudrate: None,
do_chip_erase: true,
}
}

fn guess_port(&self) -> Option<anyhow::Result<std::path::PathBuf>> {
Some(find_port_from_vid_pid_list(&[
(0x239a, 0x8011),
]))
}
}
Loading