diff --git a/examples/app_blink.rs b/examples/app_blink.rs index f94042cb..2e657e89 100644 --- a/examples/app_blink.rs +++ b/examples/app_blink.rs @@ -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); } diff --git a/examples/app_blink_pt.rs b/examples/app_blink_pt.rs new file mode 100644 index 00000000..f94042cb --- /dev/null +++ b/examples/app_blink_pt.rs @@ -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); +}