-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
136 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# vim:ft=toml: | ||
[target.thumbv7em-none-eabihf] | ||
runner = 'arm-none-eabi-gdb' | ||
rustflags = [ | ||
"-C", "link-arg=-Tlink.x", | ||
] | ||
|
||
[build] | ||
target = "thumbv7em-none-eabihf" |
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,56 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
#[allow(unused)] | ||
use panic_halt; | ||
|
||
use metro_m4 as hal; | ||
use embedded_hal; | ||
use hal::clock::GenericClockController; | ||
use hal::delay::Delay; | ||
use hal::prelude::*; | ||
use hal::{entry, CorePeripherals, Peripherals}; | ||
use hal::timer::TimerCounter; | ||
use nb::block; | ||
use bitbang_hal; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let mut peripherals = Peripherals::take().unwrap(); | ||
let core = CorePeripherals::take().unwrap(); | ||
let mut clocks = GenericClockController::with_external_32kosc( | ||
peripherals.GCLK, | ||
&mut peripherals.MCLK, | ||
&mut peripherals.OSC32KCTRL, | ||
&mut peripherals.OSCCTRL, | ||
&mut peripherals.NVMCTRL, | ||
); | ||
|
||
let gclk0 = clocks.gclk0(); | ||
let timer_clock = clocks.tc2_tc3(&gclk0).unwrap(); | ||
let mut timer = TimerCounter::tc3_( | ||
&timer_clock, | ||
peripherals.TC3, | ||
&mut peripherals.MCLK); | ||
timer.start(6.mhz()); // results in a SPI frequency of 3MHz | ||
|
||
let mut pins = hal::Pins::new(peripherals.PORT); | ||
let miso = pins.miso.into_pull_up_input(&mut pins.port); | ||
let mosi = pins.mosi.into_push_pull_output(&mut pins.port); | ||
let sck = pins.sck.into_push_pull_output(&mut pins.port); | ||
|
||
let mode = embedded_hal::spi::Mode { | ||
polarity: embedded_hal::spi::Polarity::IdleLow, | ||
phase: embedded_hal::spi::Phase::CaptureOnFirstTransition, | ||
}; | ||
let mut spi = bitbang_hal::spi::SPI::new(mode, miso, mosi, sck, timer); | ||
|
||
let mut delay = Delay::new(core.SYST, &mut clocks); | ||
|
||
loop { | ||
for byte in b"Hello, World!" { | ||
block!(spi.send(*byte)).unwrap(); | ||
} | ||
delay.delay_ms(1000u16); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,3 @@ | |
pub mod i2c; | ||
pub mod spi; | ||
pub mod serial; | ||
pub mod time; |
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
Oops, something went wrong.