Commit 967590b8 authored by Astro's avatar Astro
Browse files

l0dable: add bme680

parent 1d1c9c4b
......@@ -7,10 +7,12 @@ use l0dable::*;
main!(main);
fn main() {
writeln!(UART, "Hello from Rust\r").unwrap();
let bme = BME680::start();
let display = Display::open();
let light = LightSensor::start();
for t in 0..Display::W {
writeln!(UART, "BME: {:?}\r", bme.read()).unwrap();
display.clear(Color::yellow());
display.print(160 - t, 10, b"Hello Rust\0", Color::white(), Color::black());
......
use core::mem::uninitialized;
use super::bindings::*;
pub struct BME680;
pub type SensorData = bme680_sensor_data;
impl BME680 {
pub fn start() -> Self {
if unsafe { epic_bme680_init() } != 0 {
panic!("Cannot start light sensor");
}
BME680
}
pub fn read(&self) -> Option<SensorData> {
let mut result = unsafe { uninitialized() };
if unsafe { epic_bme680_read_sensors(&mut result) } == 0 {
Some(result)
} else {
None
}
}
}
impl Drop for BME680 {
fn drop(&mut self) {
unsafe { epic_bme680_deinit(); }
}
}
......@@ -81,6 +81,8 @@ mod utime;
pub use utime::time;
mod fmt_buffer;
pub use fmt_buffer::FmtBuffer;
mod bme680;
pub use bme680::BME680;
pub fn exit(ret: i32) -> ! {
unsafe {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment