forked from hackndev/zinc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge half pull request hackndev#1 from posborne/new-build
examples: Fix blink demo on lpc17xx for new-build
- Loading branch information
Showing
2 changed files
with
88 additions
and
51 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 |
---|---|---|
@@ -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); | ||
} |
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,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); | ||
} |