Skip to content

Commit

Permalink
add serial example
Browse files Browse the repository at this point in the history
  • Loading branch information
sajattack committed Mar 5, 2019
1 parent 6ff0472 commit b80de7a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions examples/serial.rs
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);
}
}

0 comments on commit b80de7a

Please sign in to comment.