Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

use a enum-based API #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ optional = true
version = "0.1.1"

[dependencies.nrf51-memory-map]
branch = "enum2"
git = "https://github.com/japaric/nrf51-memory-map"

[features]
Expand Down
8 changes: 3 additions & 5 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ use nrf51822::led::Led;
pub fn main() -> ! {
let timer0 = unsafe { peripheral::timer0_mut() };

// configure as timer
timer0.mode.write(|w| w.mode(false));
timer0.mode.write(|w| w.mode().timer());

// 24-bit timer
timer0.bitmode.write(|w| w.bitmode(2));
timer0.bitmode.write(|w| w.bitmode()._24bit());

// prescaler = 2 ^ 4 = 16
timer0.prescaler.write(|w| w.prescaler(4));

// clear the timer after the `compare` value is reached
timer0.shorts.modify(|_, w| w.compare0_clear(true));
timer0.shorts.modify(|_, w| w.compare0_clear().enabled());

// reset the timer after 1_000_000 ticks
// NOTE clock frequency = 16 MHz
Expand Down
6 changes: 3 additions & 3 deletions src/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ pub struct Led;

impl Led {
pub fn off(&self) {
unsafe { ::peripheral::gpio_mut().outclr.write(|w| w.pin8(true)) }
unsafe { ::peripheral::gpio_mut().outclr.write(|w| w.pin8().clear()) }
}

pub fn on(&self) {
unsafe { ::peripheral::gpio_mut().outset.write(|w| w.pin8(true)) }
unsafe { ::peripheral::gpio_mut().outset.write(|w| w.pin8().set()) }
}
}

pub fn init() {
unsafe {
// configure P8 as output
::peripheral::gpio_mut().dirset.write(|w| w.pin8(true));
::peripheral::gpio_mut().dirset.write(|w| w.pin8().set());
}
}