-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jorge Aparicio
committed
Nov 23, 2016
1 parent
5a3fda8
commit a034ae2
Showing
15 changed files
with
1,359 additions
and
376 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
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,57 @@ | ||
//! Echo server and blinking LED running concurrently | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate f3; | ||
extern crate futuro; | ||
|
||
use f3::led::LEDS; | ||
use f3::serial::{Serial, Tx, Write}; | ||
use f3::timer::Timer; | ||
use futuro::prelude::*; | ||
|
||
// XXX can we get rid of this explicit state using Future adapters? | ||
enum TxState { | ||
Free(Tx), | ||
Pending(Write), | ||
} | ||
|
||
#[no_mangle] | ||
pub fn main() -> ! { | ||
let Serial { tx, mut rx } = Serial::new().unwrap(); | ||
|
||
let mut timer = Timer::new().unwrap(); | ||
let mut on = true; | ||
let mut blink = timer.periodic(100).map(|_| { | ||
if on { | ||
LEDS[0].on(); | ||
} else { | ||
LEDS[0].off(); | ||
} | ||
|
||
on = !on; | ||
}); | ||
|
||
let mut tx_state = TxState::Free(tx); | ||
let mut bytes = rx.bytes(); | ||
loop { | ||
if let Async::Ready(byte) = bytes.poll() { | ||
let tx = match tx_state { | ||
TxState::Pending(write) => write.wait(), | ||
TxState::Free(tx) => tx, | ||
}; | ||
tx_state = TxState::Pending(tx.write(byte)); | ||
} | ||
|
||
if let TxState::Pending(mut write) = tx_state { | ||
if let Async::Ready(tx) = write.poll() { | ||
tx_state = TxState::Free(tx); | ||
} else { | ||
tx_state = TxState::Pending(write); | ||
} | ||
} | ||
|
||
blink.poll(); | ||
} | ||
} |
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,41 @@ | ||
//! Echo server over Serial | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate f3; | ||
extern crate futuro; | ||
|
||
use futuro::prelude::*; | ||
use f3::serial::{Serial, Tx, Write}; | ||
|
||
// XXX can we get rid of this explicit state using Future adapters? | ||
enum TxState { | ||
Free(Tx), | ||
Pending(Write), | ||
} | ||
|
||
#[no_mangle] | ||
pub fn main() -> ! { | ||
let Serial { tx, mut rx } = Serial::new().unwrap(); | ||
|
||
let mut tx_state = TxState::Free(tx); | ||
let mut bytes = rx.bytes(); | ||
loop { | ||
if let Async::Ready(byte) = bytes.poll() { | ||
let tx = match tx_state { | ||
TxState::Pending(write) => write.wait(), | ||
TxState::Free(tx) => tx, | ||
}; | ||
tx_state = TxState::Pending(tx.write(byte)); | ||
} | ||
|
||
if let TxState::Pending(mut write) = tx_state { | ||
if let Async::Ready(tx) = write.poll() { | ||
tx_state = TxState::Free(tx); | ||
} else { | ||
tx_state = TxState::Pending(write); | ||
} | ||
} | ||
} | ||
} |
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,31 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
#[macro_use] | ||
extern crate f3; | ||
extern crate futuro; | ||
|
||
use futuro::prelude::*; | ||
use f3::i2c::{Address, I2c}; | ||
|
||
#[no_mangle] | ||
pub fn main() -> ! { | ||
const MAGNETOMETER: u8 = 0b001_1110; | ||
const MR_REG_M: u8 = 0x02; | ||
const OUT_X_H_M: u8 = 0x3; | ||
|
||
let i2c = I2c::new().unwrap(); | ||
|
||
// NOTE(write_all) configure the magnetometer to operate in continuous mode | ||
// NOTE(write+read_exact) read the magnetic field | ||
let buffer = i2c.write_all(Address::u7(MAGNETOMETER), &[MR_REG_M, 0b00]) | ||
.and_then(|i2c| i2c.write(None, OUT_X_H_M)) | ||
.and_then(|i2c| i2c.read_exact(None, [0u8; 6])) | ||
.and_then(|(i2c, buffer)| i2c.stop().map(move |_| buffer)) | ||
.wait(); | ||
|
||
iprintln!("{:?}", buffer); | ||
|
||
loop { | ||
} | ||
} |
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,28 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate f3; | ||
extern crate futuro; | ||
|
||
use f3::led::LEDS; | ||
use f3::timer::Timer; | ||
use futuro::prelude::*; | ||
|
||
#[no_mangle] | ||
pub fn main() -> ! { | ||
let mut timer = Timer::new().unwrap(); | ||
|
||
let mut on = true; | ||
let mut delay = timer.periodic(100).wait(); | ||
loop { | ||
if on { | ||
LEDS[0].on(); | ||
} else { | ||
LEDS[0].off(); | ||
} | ||
|
||
on = !on; | ||
|
||
delay.next(); | ||
} | ||
} |
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,41 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
#[macro_use] | ||
extern crate f3; | ||
extern crate futuro; | ||
|
||
use f3::i2c::I2c; | ||
use f3::l3gd20::L3gd20; | ||
use f3::lsm303dlhc::Lsm303dlhc; | ||
use f3::spi::Spi; | ||
use f3::time::Instant; | ||
use f3::timer::Timer; | ||
use futuro::prelude::*; | ||
|
||
#[no_mangle] | ||
pub fn main() -> ! { | ||
let mut lsm303dlhdc = I2c::new().map(|i2c| Lsm303dlhc::new(i2c)).unwrap(); | ||
let mut l3gd20 = Spi::new().map(|spi| L3gd20::new(spi)).unwrap(); | ||
let mut timer = Timer::new().unwrap(); | ||
let mut periodic = timer.periodic(1_000).wait(); | ||
|
||
loop { | ||
let instant = Instant::now(); | ||
let (x, y, a, ar, mf) = lsm303dlhdc.acceleration() | ||
.and_then(|(x, a)| { | ||
x.magnetic_field().map(move |(x, mf)| (x, a, mf)) | ||
}) | ||
.join(l3gd20.angular_rate()) | ||
.map(|((x, a, mf), (y, ar))| (x, y, a, ar, mf)) | ||
.wait(); | ||
l3gd20 = y; | ||
lsm303dlhdc = x; | ||
let elapsed = instant.elapsed(); | ||
|
||
iprintln!("{} ticks", elapsed); | ||
iprintln!("{:?}", (a.x(), ar.x(), mf.x())); | ||
|
||
periodic.next(); | ||
} | ||
} |
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,36 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
#[macro_use] | ||
extern crate f3; | ||
extern crate futuro; | ||
|
||
use f3::peripheral; | ||
use f3::spi::Spi; | ||
use futuro::prelude::*; | ||
|
||
#[no_mangle] | ||
pub fn main() -> ! { | ||
// WHO_AM_I | ||
const REGISTER_ADDRESS: u8 = 0x0f; | ||
// Read the register | ||
const READ: u8 = 1 << 7; | ||
|
||
let spi = Spi::new().unwrap(); | ||
let rcc = unsafe { peripheral::rcc_mut() }; | ||
let gpioe = unsafe { peripheral::gpioe_mut() }; | ||
|
||
rcc.ahbenr.modify(|_, w| w.iopeen(true)); | ||
gpioe.moder.modify(|_, w| w.moder3(0b01)); | ||
gpioe.bsrr.write(|w| w.br3(true)); | ||
|
||
let buffer = spi.transfer_all([READ | REGISTER_ADDRESS, 0b00]).wait().1; | ||
|
||
gpioe.bsrr.write(|w| w.bs3(true)); | ||
|
||
// Expected output: 0x0f - 0xd4 | ||
iprintln!("0x{:02x} - 0x{:02x}", REGISTER_ADDRESS, buffer[1]); | ||
|
||
loop { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.