Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"editor.formatOnSave": true,
"rust-client.channel": "nightly-2018-11-30",
"rust.target": "thumbv7em-none-eabi",
}
"rust.all_targets": false,
}
10 changes: 4 additions & 6 deletions examples/button_read.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![feature(alloc)]
#![no_std]

extern crate alloc;

use alloc::string::String;
use core::fmt::Write;
use tock::buttons;
use tock::buttons::ButtonState;
use tock::console::Console;
Expand All @@ -19,9 +16,10 @@ fn main() {

loop {
match button.read() {
ButtonState::Pressed => console.write(String::from("pressed\n")),
ButtonState::Released => console.write(String::from("released\n")),
ButtonState::Pressed => writeln!(console, "pressed"),
ButtonState::Released => writeln!(console, "released"),
}
.unwrap();
timer::sleep(Duration::from_ms(500));
}
}
23 changes: 11 additions & 12 deletions examples/button_subscribe.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#![feature(alloc)]
#![no_std]

extern crate alloc;

use alloc::string::String;
use core::fmt::Write;
use tock::buttons;
use tock::buttons::ButtonState;
use tock::console::Console;
use tock::fmt;
use tock::timer;
use tock::timer::Duration;

Expand All @@ -16,13 +12,16 @@ fn main() {
let mut console = Console::new();

let mut with_callback = buttons::with_callback(|button_num: usize, state| {
console.write(String::from("\nButton: "));
console.write(fmt::u32_as_hex(button_num as u32));
console.write(String::from(" - State: "));
console.write(String::from(match state {
ButtonState::Pressed => "pressed",
ButtonState::Released => "released",
}));
writeln!(
console,
"Button: {} - State: {}",
button_num,
match state {
ButtonState::Pressed => "pressed",
ButtonState::Released => "released",
}
)
.unwrap();
});

let mut buttons = with_callback.init().unwrap();
Expand Down
9 changes: 3 additions & 6 deletions examples/gpio_read.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![feature(alloc)]
#![no_std]

extern crate alloc;

use alloc::string::String;
use core::fmt::Write;
use tock::console::Console;
use tock::gpio::{GpioPinUnitialized, InputMode};
use tock::timer;
Expand All @@ -17,9 +14,9 @@ fn main() {

loop {
if pin.read() {
console.write(String::from("true\n"));
writeln!(console, "true").unwrap();
} else {
console.write(String::from("false\n"));
writeln!(console, "false").unwrap();
}
timer::sleep(Duration::from_ms(500));
}
Expand Down
5 changes: 3 additions & 2 deletions examples/hardware_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
extern crate alloc;

use alloc::string::String;
use core::fmt::Write;
use tock::console::Console;
use tock::timer;
use tock::timer::Duration;

fn main() {
let mut console = Console::new();
console.write(String::from("[test-results]\n"));
writeln!(console, "[test-results]").unwrap();
let mut string = String::from("heap_test = \"Heap ");
string.push_str("works.\"\n");
console.write(string);
writeln!(console, "{}", string).unwrap();

for _ in 0.. {
timer::sleep(Duration::from_ms(500))
Expand Down
10 changes: 2 additions & 8 deletions examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
#![feature(alloc)]
#![no_std]

extern crate alloc;

use alloc::string::String;
use core::fmt::Write;
use tock::console::Console;
use tock::timer;
use tock::timer::Duration;

// TODO: Make format!/alloc::string::ToString work
fn main() {
let mut console = Console::new();

for i in 0.. {
console.write(String::from("Hello world! "));
console.write(tock::fmt::u32_as_decimal(i));
console.write(String::from("\n"));
writeln!(console, "Hello world! {}", i).unwrap();
timer::sleep(Duration::from_ms(500))
}
}
18 changes: 5 additions & 13 deletions examples/sensors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![feature(alloc)]
#![no_std]

extern crate alloc;

use alloc::fmt::Write;
use core::fmt::Write;
use tock::console::Console;
use tock::sensors::*;
use tock::timer;
Expand All @@ -16,15 +13,10 @@ fn main() {
let mut light = AmbientLightSensor;
let mut ninedof = unsafe { Ninedof::new() };
loop {
write!(&mut console, "Humidity: {}\n", humidity.read()).unwrap();
write!(&mut console, "Temperature: {}\n", temperature.read()).unwrap();
write!(&mut console, "Light: {}\n", light.read()).unwrap();
write!(
&mut console,
"Accel: {}\n",
ninedof.read_acceleration()
)
.unwrap();
writeln!(console, "Humidity: {}\n", humidity.read()).unwrap();
writeln!(console, "Temperature: {}\n", temperature.read()).unwrap();
writeln!(console, "Light: {}\n", light.read()).unwrap();
writeln!(console, "Accel: {}\n", ninedof.read_acceleration()).unwrap();
timer::sleep(Duration::from_ms(500));
}
}
7 changes: 1 addition & 6 deletions examples/simple_ble.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#![no_std]
#![feature(alloc)]

extern crate alloc;

use alloc::string::String;
use serde::Serialize;
use tock::ble_composer;
use tock::ble_composer::BlePayload;
Expand All @@ -22,7 +18,6 @@ struct LedCommand {
fn main() {
let led = led::get(0).unwrap();

let name = String::from("Tock!");
let uuid: [u8; 2] = [0x00, 0x18];

let payload = corepack::to_bytes(LedCommand { nr: 2, st: true }).unwrap();
Expand All @@ -35,7 +30,7 @@ fn main() {

gap_payload.add(
ble_composer::gap_types::COMPLETE_LOCAL_NAME,
name.as_bytes(),
"Tock!".as_bytes(),
);
gap_payload.add_service_payload([91, 79], &payload);

Expand Down
9 changes: 2 additions & 7 deletions examples/temperature.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#![feature(alloc)]
#![no_std]

extern crate alloc;

use alloc::string::String;
use core::fmt::Write;
use tock::console::Console;
use tock::temperature;

fn main() {
let mut console = Console::new();

let mut with_callback = temperature::with_callback(|result: isize| {
console.write(String::from("Temperature: "));
console.write(tock::fmt::i32_as_decimal(result as i32));
console.write(String::from("\n"));
writeln!(console, "Temperature: {}", result).unwrap();
});

let _temperature = with_callback.start_measurement();
Expand Down
11 changes: 5 additions & 6 deletions examples/timer_subscribe.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![feature(alloc)]
#![no_std]

extern crate alloc;

use alloc::string::String;
use core::fmt::Write;
use tock::console::Console;
use tock::syscalls;
use tock::timer;
Expand All @@ -13,9 +10,11 @@ fn main() {
let mut console = Console::new();

let mut with_callback = timer::with_callback(|_, _| {
console.write(String::from(
writeln!(
console,
"This line is printed 2 seconds after the start of the program.",
))
)
.unwrap();
});

let mut timer = with_callback.init().unwrap();
Expand Down
84 changes: 0 additions & 84 deletions src/fmt.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub mod buttons;
pub mod console;
pub mod debug;
pub mod electronics;
pub mod fmt;
pub mod gpio;
pub mod led;
pub mod result;
Expand Down