Skip to content
Snippets Groups Projects
Commit edb66534 authored by Astro's avatar Astro :gear:
Browse files

l0dable: more of the good stuff

parent 3b65a1f1
No related branches found
No related tags found
No related merge requests found
use super::bindings::*; use super::bindings::*;
#[derive(Debug, Clone, Copy)]
#[repr(C)] #[repr(C)]
pub struct Color(u16); pub struct Color(u16);
...@@ -9,11 +10,11 @@ impl Color { ...@@ -9,11 +10,11 @@ impl Color {
} }
pub fn blue() -> Self { pub fn blue() -> Self {
Self::rgb8(0xff, 0, 0) Self::rgb8(0, 0, 0xff)
} }
pub fn green() -> Self { pub fn green() -> Self {
Self::rgb8(0xff, 0, 0) Self::rgb8(0, 0xff, 0)
} }
pub fn black() -> Self { pub fn black() -> Self {
...@@ -67,11 +68,19 @@ pub enum LineStyle { ...@@ -67,11 +68,19 @@ pub enum LineStyle {
Dotted = disp_linestyle_LINESTYLE_DOTTED, Dotted = disp_linestyle_LINESTYLE_DOTTED,
} }
#[repr(u32)]
pub enum FillStyle {
Empty = disp_fillstyle_FILLSTYLE_EMPTY,
Filled = disp_fillstyle_FILLSTYLE_FILLED,
}
pub struct Display; pub struct Display;
impl Display { impl Display {
pub const W: u16 = 160; pub const W: u16 = 160;
pub const H: u16 = 80; pub const H: u16 = 80;
pub const FONT_W: u16 = 14;
pub const FONT_H: u16 = 20;
pub fn open() -> Self { pub fn open() -> Self {
unsafe { epic_disp_open(); } unsafe { epic_disp_open(); }
...@@ -105,11 +114,17 @@ impl Display { ...@@ -105,11 +114,17 @@ impl Display {
} }
} }
// pub fn rect(&self) { pub fn rect(&self, x1: u16, y1: u16, x2: u16, y2: u16, color: Color, fillstyle: FillStyle, pixelsize: u16) {
// } unsafe {
epic_disp_rect(x1, y1, x2, y2, color.0, fillstyle as u32, pixelsize);
}
}
// pub fn circle(&self) { pub fn circ(&self, x: u16, y: u16, rad: u16, color: Color, fillstyle: FillStyle, pixelsize: u16) {
// } unsafe {
epic_disp_circ(x, y, rad, color.0, fillstyle as u32, pixelsize);
}
}
} }
impl Drop for Display { impl Drop for Display {
......
//! Stolen from https://stackoverflow.com/questions/39488327/how-to-format-output-to-a-byte-array-with-no-std-and-no-allocator
use core::fmt;
pub struct FmtBuffer<'a> {
buf: &'a mut [u8],
offset: usize,
}
impl<'a> FmtBuffer<'a> {
pub fn new(buf: &'a mut [u8]) -> Self {
FmtBuffer {
buf: buf,
offset: 0,
}
}
}
impl<'a> fmt::Write for FmtBuffer<'a> {
fn write_str(&mut self, s: &str) -> fmt::Result {
let bytes = s.as_bytes();
// Skip over already-copied data
let remainder = &mut self.buf[self.offset..];
// Check if there is space remaining (return error instead of panicking)
if remainder.len() < bytes.len() { return Err(core::fmt::Error); }
// Make the two slices the same length
let remainder = &mut remainder[..bytes.len()];
// Copy
remainder.copy_from_slice(bytes);
// Update offset to avoid overwriting
self.offset += bytes.len();
Ok(())
}
}
...@@ -64,7 +64,7 @@ pub mod bindings { ...@@ -64,7 +64,7 @@ pub mod bindings {
use bindings::*; use bindings::*;
mod display; mod display;
pub use display::{Display, Color, LineStyle}; pub use display::{Display, Color, LineStyle, FillStyle};
mod buttons; mod buttons;
pub use buttons::Buttons; pub use buttons::Buttons;
pub mod uart; pub mod uart;
...@@ -72,6 +72,11 @@ pub const UART: uart::Uart = uart::Uart; ...@@ -72,6 +72,11 @@ pub const UART: uart::Uart = uart::Uart;
mod light_sensor; mod light_sensor;
pub use light_sensor::LightSensor; pub use light_sensor::LightSensor;
pub mod vibra; pub mod vibra;
pub mod trng;
mod utime;
pub use utime::time;
mod fmt_buffer;
pub use fmt_buffer::FmtBuffer;
pub fn exit(ret: i32) -> ! { pub fn exit(ret: i32) -> ! {
unsafe { unsafe {
......
use super::bindings::*;
pub fn read(dest: &mut [u8]) -> bool {
unsafe { epic_trng_read(dest.as_mut_ptr(), dest.len()) != 0 }
}
use super::bindings::*;
pub fn time() -> u32 {
unsafe { epic_rtc_get_seconds() }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment