Skip to content

Commit

Permalink
Merge half pull request hackndev#1 from posborne/new-build
Browse files Browse the repository at this point in the history
examples: Fix blink demo on lpc17xx for new-build
  • Loading branch information
mcoffin committed May 16, 2015
2 parents 7065020 + 323acd3 commit f0db182
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 51 deletions.
79 changes: 28 additions & 51 deletions examples/app_blink.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,37 @@
#![feature(plugin, no_std, core)]
#![crate_type="staticlib"]
#![feature(no_std, core, start)]
#![no_std]
#![plugin(macro_platformtree)]

extern crate core;
extern crate zinc;
#[macro_use] #[no_link] extern crate macro_platformtree;

platformtree!(
lpc17xx@mcu {
clock {
source = "main-oscillator";
source_frequency = 12_000_000;
pll {
m = 50;
n = 3;
divisor = 4;
}
}

timer {
timer@1 {
counter = 25;
divisor = 4;
}
}
use zinc::hal::timer::Timer;
use zinc::hal::lpc17xx::{pin, timer};
use zinc::hal::pin::GpioDirection;
use zinc::hal::pin::Gpio;
use core::option::Option::Some;

gpio {
1 {
led1@18 { direction = "out"; }
led2@20 { direction = "out"; }
}
}
}
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
main();
0
}

os {
single_task {
loop = "run";
args {
timer = &timer;
led1 = &led1;
led2 = &led2;
}
pub fn main() {
zinc::hal::mem_init::init_stack();
zinc::hal::mem_init::init_data();

// P1.20 => LED-2 (mbed LPC1768)
let led2 = pin::Pin::new(
pin::Port::Port1, 21,
pin::Function::Gpio,
Some(GpioDirection::Out));

let timer = timer::Timer::new(timer::TimerPeripheral::Timer0, 25, 4);

loop {
led2.set_high();
timer.wait_ms(10);
led2.set_low();
timer.wait_ms(10);
}
}
);

fn run(args: &pt::run_args) {
use zinc::hal::pin::Gpio;
use zinc::hal::timer::Timer;

args.led1.set_high();
args.led2.set_low();
args.timer.wait(1);

args.led1.set_low();
args.led2.set_high();
args.timer.wait(1);
}
60 changes: 60 additions & 0 deletions examples/app_blink_pt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#![feature(plugin, no_std, core)]
#![crate_type="staticlib"]
#![no_std]
#![plugin(macro_platformtree)]

extern crate core;
extern crate zinc;
#[macro_use] #[no_link] extern crate macro_platformtree;

platformtree!(
lpc17xx@mcu {
clock {
source = "main-oscillator";
source_frequency = 12_000_000;
pll {
m = 50;
n = 3;
divisor = 4;
}
}

timer {
timer@1 {
counter = 25;
divisor = 4;
}
}

gpio {
1 {
led1@18 { direction = "out"; }
led2@20 { direction = "out"; }
}
}
}

os {
single_task {
loop = "run";
args {
timer = &timer;
led1 = &led1;
led2 = &led2;
}
}
}
);

fn run(args: &pt::run_args) {
use zinc::hal::pin::Gpio;
use zinc::hal::timer::Timer;

args.led1.set_high();
args.led2.set_low();
args.timer.wait(1);

args.led1.set_low();
args.led2.set_high();
args.timer.wait(1);
}

0 comments on commit f0db182

Please sign in to comment.