Skip to content

Commit 06944b5

Browse files
authored
Merge pull request #13 from torfmaster/master
Modernize libtock-rs
2 parents f8de19d + b8f7789 commit 06944b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2266
-366
lines changed

.cargo/config

Lines changed: 0 additions & 7 deletions
This file was deleted.

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "tock"]
2+
path = tock
3+
url = https://github.com/helena-project/tock
4+
[submodule "xargo"]
5+
path = xargo
6+
url = https://github.com/japaric/xargo

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: rust
2+
rust:
3+
- nightly-2018-02-23
4+
5+
os:
6+
- linux
7+
8+
cache:
9+
directories:
10+
- $HOME/.cargo
11+
- xargo/target
12+
- tock/userland/tools/elf2tbf/target
13+
14+
install:
15+
- wget -c https://developer.arm.com/-/media/Files/downloads/gnu-rm/6-2016q4/gcc-arm-none-eabi-6_2-2016q4-20161216-linux.tar.bz2
16+
- tar -xjf gcc-arm-none-eabi-6_2-2016q4-20161216-linux.tar.bz2
17+
- rustup component add rust-src
18+
19+
script:
20+
- export PATH="$PATH:gcc-arm-none-eabi-6_2-2016q4/bin"
21+
- export RUSTFLAGS="$RUSTFLAGS -D warnings"
22+
- cargo test --lib
23+
- ./build_examples.sh

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"rust-client.channel": "nightly-2018-02-23",
4+
}

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ authors = ["Tock Project Developers <[email protected]>"]
55
license = "MIT/Apache-2.0"
66

77
[dependencies]
8-
linked_list_allocator = "0.4.3"
8+
linked_list_allocator = "0.5.0"
9+
10+
[dev-dependencies]
11+
corepack = { version="~0.3.1", default-features=false, features = ["alloc"] }
12+
serde_derive = { version = "~1.0.10", default-features = false }
13+
serde = { version = "~1.0.10", default-features = false }
914

1015
[profile.dev]
1116
panic = "abort"

Cross.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1+
[![Build Status](https://travis-ci.org/torfmaster/libtock-rs.svg?branch=master)](https://travis-ci.org/torfmaster/libtock-rs)
12
# libtock-rs
23
Rust userland library for Tock (WIP)
34

45
## Getting Started
56

67
This project is nascent and still under heavy development, but first steps:
78

8-
1. First, update rustup to ensure you have the latest toolchain available:
9+
1. Ensure you have a working toolchain available:
910

10-
`rustup update`
11-
12-
or
13-
14-
`rustup install nightly`
11+
`rustup install nightly-2017-12-16`
1512

16-
2. Get a copy of the latest nightly, in this repo's root:
13+
2. Get a copy of this toolchain, in this repo's root:
1714

18-
`rustup override set nightly`
19-
20-
Your rustc should be at least this new:
21-
```
22-
$ rustc --version
23-
rustc 1.21.0-nightly (7ac979d8c 2017-08-16)
24-
```
15+
`rustup override set nightly-2017-12-16`
2516

2617
3. Need to grab a copy of the rust sources:
2718

build_examples.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
export RUST_TARGET_PATH=`pwd`
5+
export CARGO_INCREMENTAL=0
6+
7+
cargo run --manifest-path xargo/Cargo.toml -- build --release --target=thumbv7em-tock-eabi --examples

examples/ble_ess.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use alloc::fmt::Write;
88
use tock::console::Console;
99
use tock::ipc::ble_ess::{self, ReadingType};
1010
use tock::sensors::*;
11+
use tock::timer;
12+
use tock::timer::Duration;
1113

1214
fn main() {
1315
let mut console = Console::new();
@@ -17,7 +19,7 @@ fn main() {
1719
Ok(ess) => ess,
1820
_ => {
1921
write!(&mut console, "BLE IPC Service not installed\n").unwrap();
20-
return
22+
return;
2123
}
2224
};
2325
write!(&mut console, "Found BLE IPC Service\n").unwrap();
@@ -26,14 +28,13 @@ fn main() {
2628
let mut temperature = TemperatureSensor;
2729
let mut light = AmbientLightSensor;
2830
loop {
29-
3031
// Temperature
3132
let temp = temperature.read();
3233
write!(&mut console, "Temperature: {}\n", temp).unwrap();
3334
if let Err(_) = ess.set_reading(ReadingType::Temperature, temp) {
3435
write!(&mut console, "Failed to set temperature\n").unwrap_or(());
3536
}
36-
37+
3738
// Light
3839
let lx = light.read();
3940
write!(&mut console, "Light: {}\n", lx).unwrap();
@@ -48,7 +49,6 @@ fn main() {
4849
write!(&mut console, "Failed to set temperature\n").unwrap_or(());
4950
}
5051

51-
tock::timer::delay_ms(5000);
52+
timer::sleep(Duration::from_ms(5000))
5253
}
5354
}
54-

examples/ble_scanning.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#![no_std]
2+
#![feature(alloc)]
3+
4+
extern crate alloc;
5+
extern crate corepack;
6+
extern crate serde;
7+
#[macro_use]
8+
extern crate serde_derive;
9+
extern crate tock;
10+
11+
// Macro usages are not detected
12+
#[allow(unused_imports)]
13+
use alloc::*;
14+
use tock::ble_parser;
15+
use tock::led;
16+
use tock::simple_ble::BleDriver;
17+
use tock::syscalls;
18+
19+
#[derive(Deserialize)]
20+
struct LedCommand {
21+
pub nr: u8,
22+
pub st: bool,
23+
}
24+
25+
fn main() {
26+
let buffer = [0; tock::simple_ble::BUFFER_SIZE_SCAN];
27+
BleDriver::start(&buffer, |_: usize, _: usize| {
28+
match ble_parser::find(&buffer, tock::simple_ble::gap_data::SERVICE_DATA as u8) {
29+
Some(payload) => {
30+
let payload: Vec<u8> = payload.iter().map(|&x| *x).collect::<Vec<u8>>();
31+
let msg: LedCommand = corepack::from_bytes(payload.as_slice()).unwrap();
32+
let msg_led = led::get(msg.nr as isize);
33+
match msg_led {
34+
Some(msg_led) => if msg.st {
35+
msg_led.on();
36+
} else {
37+
msg_led.off();
38+
},
39+
_ => (),
40+
}
41+
}
42+
None => (),
43+
}
44+
}).unwrap();
45+
46+
loop {
47+
syscalls::yieldk();
48+
}
49+
}

0 commit comments

Comments
 (0)