-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for Trinket M0 board
- Loading branch information
1 parent
30ecc39
commit 4afe988
Showing
9 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters