Commit edb66534 authored by Astro's avatar Astro
Browse files

l0dable: more of the good stuff

parent 3b65a1f1
use super::bindings::*;
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Color(u16);
......@@ -9,11 +10,11 @@ impl Color {
}
pub fn blue() -> Self {
Self::rgb8(0xff, 0, 0)
Self::rgb8(0, 0, 0xff)
}
pub fn green() -> Self {
Self::rgb8(0xff, 0, 0)
Self::rgb8(0, 0xff, 0)
}
pub fn black() -> Self {
......@@ -67,11 +68,19 @@ pub enum LineStyle {
Dotted = disp_linestyle_LINESTYLE_DOTTED,
}
#[repr(u32)]
pub enum FillStyle {
Empty = disp_fillstyle_FILLSTYLE_EMPTY,
Filled = disp_fillstyle_FILLSTYLE_FILLED,
}
pub struct Display;
impl Display {
pub const W: u16 = 160;
pub const H: u16 = 80;
pub const FONT_W: u16 = 14;
pub const FONT_H: u16 = 20;
pub fn open() -> Self {
unsafe { epic_disp_open(); }
......@@ -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 {
......
//! 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 {
use bindings::*;
mod display;
pub use display::{Display, Color, LineStyle};
pub use display::{Display, Color, LineStyle, FillStyle};
mod buttons;
pub use buttons::Buttons;
pub mod uart;
......@@ -72,6 +72,11 @@ pub const UART: uart::Uart = uart::Uart;
mod light_sensor;
pub use light_sensor::LightSensor;
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) -> ! {
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() }
}
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