-
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
1 changed file
with
50 additions
and
0 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,50 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
#[allow(unused)] | ||
use panic_halt; | ||
|
||
use metro_m4 as 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(115200.hz()); | ||
|
||
let mut pins = hal::Pins::new(peripherals.PORT); | ||
let rx = pins.d0.into_pull_up_input(&mut pins.port); | ||
let tx = pins.d1.into_push_pull_output(&mut pins.port); | ||
|
||
let mut serial = bitbang_hal::serial::Serial::new(tx, rx, timer); | ||
|
||
let mut delay = Delay::new(core.SYST, &mut clocks); | ||
|
||
loop { | ||
for byte in b"Hello, World!" { | ||
block!(serial.write(*byte)).unwrap(); | ||
} | ||
delay.delay_ms(1000u16); | ||
} | ||
} |