Skip to content

Commit

Permalink
Add basic support for Trinket M0 board
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBergman authored and wez committed Oct 17, 2018
1 parent 30ecc39 commit 4afe988
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ There are a couple of crates provided by this repo:
* [`gemma_m0`](https://wez.github.io/atsamd21-rs/atsamd21e18a/gemma_m0/) is a board support crate
for the Adafruit Gemma M0 board. Similar to the Metro M0 crate, it re-exports the
`atsamd21-hal` crate functionality using more convenient names.
* [`trinket_m0`](https://wez.github.io/atsamd21-rs/atsamd21e18a/trinket_m0/) is a board support crate
for the Adafruit Trinket M0 board. Similar to the Metro M0 crate, it re-exports the
`atsamd21-hal` crate functionality using more convenient names.
* [`itsybitsy_m0`](https://wez.github.io/atsamd21-rs/atsamd21g18a/itsybitsy_m0/) is a board support crate
for the Adafruit ItsyBitsy M0 board. It re-exports the `atsamd21-hal` crate functionality
using more convenient names; for example, the IO pins are exported using the labels
Expand Down
34 changes: 34 additions & 0 deletions boards/trinket_m0/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "trinket_m0"
version = "0.1.0"
authors = ["Ben Bergman <ben@benbergman.ca>"]
description = "Board Support crate for the Adafruit Trinket M0"
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/wez/atsamd21-rs"
readme = "README.md"
documentation = "https://wez.github.io/atsamd21-rs/atsamd21e18a/trinket_m0/"

[dependencies]
cortex-m = "~0.5"
embedded-hal = "~0.2"
nb = "~0.1"

[dependencies.cortex-m-rt]
version = "~0.6"
optional = true

[dependencies.atsamd21-hal]
path = "../../hal"
version = "~0.2"
default-features = false

[dev-dependencies]
panic-abort = "~0.2"

[features]
# ask the HAL to enable atsamd21e18a support
default = ["rt", "atsamd21-hal/samd21e18a"]
rt = ["cortex-m-rt", "atsamd21-hal/samd21e18a-rt"]
unproven = ["atsamd21-hal/unproven"]
use_semihosting = []
10 changes: 10 additions & 0 deletions boards/trinket_m0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Adafruit Trinket M0 Board Support Crate

This crate provides a type-safe API for working with the [Adafruit Trinket M0
board](https://www.adafruit.com/product/3501).

## Examples?

Check out the repository for examples:

https://github.com/wez/atsamd21-rs/tree/master/boards/trinket_m0/examples
16 changes: 16 additions & 0 deletions boards/trinket_m0/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
if env::var_os("CARGO_FEATURE_RT").is_some() {
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=memory.x");
}
println!("cargo:rerun-if-changed=build.rs");
}
31 changes: 31 additions & 0 deletions boards/trinket_m0/examples/blinky_basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![no_std]
#![no_main]

extern crate trinket_m0 as hal;
extern crate panic_abort;

use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::prelude::*;
use hal::{entry, CorePeripherals, Peripherals};

#[entry]
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.GCLK,
&mut peripherals.PM,
&mut peripherals.SYSCTRL,
&mut peripherals.NVMCTRL,
);
let mut pins = hal::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let mut delay = Delay::new(core.SYST, &mut clocks);
loop {
delay.delay_ms(200u8);
red_led.set_high();
delay.delay_ms(200u8);
red_led.set_low();
}
}
8 changes: 8 additions & 0 deletions boards/trinket_m0/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MEMORY
{
/* Leave 8k for the default bootloader on the Trinket M0 */
FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
}
_stack_start = ORIGIN(RAM) + LENGTH(RAM);

45 changes: 45 additions & 0 deletions boards/trinket_m0/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#![no_std]
#![recursion_limit="1024"]

extern crate atsamd21_hal as hal;

#[cfg(feature = "rt")]
extern crate cortex_m_rt;
#[cfg(feature = "rt")]
pub use cortex_m_rt::entry;

pub use hal::atsamd21e18a::*;
use hal::prelude::*;
pub use hal::*;

use gpio::{Floating, Input, Port};

define_pins!(
/// Maps the pins to their arduino names and
/// the numbers printed on the board.
struct Pins,
target_device: atsamd21e18a,

pin d0 = a8,
pin d1 = a2,
pin d2 = a9,
pin d3 = a7,
pin d4 = a6,

/// Digital pin number 13, which is also attached to
/// the red LED. PWM capable.
pin d13 = a10,

/// The DotStar clock
pin dotstar_ci = a1,
/// The DotStar data line
pin dotstar_di = a0,

pin swdio = a31,
pin swdclk = a30,

/// The USB D- pad
pin usb_dm = a24,
/// The USB D+ pad
pin usb_dp = a25,
);
1 change: 1 addition & 0 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ set -xe
cargo build --manifest-path boards/metro_m0/Cargo.toml --example blinky_basic
cargo build --manifest-path boards/gemma_m0/Cargo.toml --examples
cargo build --manifest-path boards/itsybitsy_m0/Cargo.toml --examples
cargo build --manifest-path boards/trinket_m0/Cargo.toml --examples
cargo build --manifest-path boards/samd21_mini/Cargo.toml --examples
cargo build --manifest-path boards/arduino_mkrzero/Cargo.toml --examples
2 changes: 1 addition & 1 deletion build-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# get enabled for the HAL module are different and we don't want to
# emit misleading docs.
crates_by_pac = {
'atsamd21e18a': ['gemma_m0'],
'atsamd21e18a': ['gemma_m0', 'trinket_m0'],
'atsamd21g18a': ['metro_m0', 'samd21_mini', 'arduino_mkrzero', 'itsybitsy_m0']
}

Expand Down

0 comments on commit 4afe988

Please sign in to comment.