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

l0dable: doc

parent c7d11c22
No related branches found
No related tags found
No related merge requests found
Pipeline #3779 passed
/// Accelerometer, Gyroscope, Orientation
use core::{
fmt::{self, Display, Write},
marker::PhantomData,
......@@ -53,6 +55,10 @@ pub struct Sensor<S: SensorType> {
}
impl<S: SensorType> Sensor<S> {
/// Use one of:
/// - `BHI160::<Accelerometer>::start()`
/// - `BHI160::<Gyroscope>::start()`
/// - `BHI160::<Orientation>::start()`
fn new(stream_id: i32) -> Self {
Self {
stream_id,
......
/// Enviromental sensor
use card10_sys::*;
use core::mem::uninitialized;
......
use card10_sys::*;
/// Button inputs
pub struct Buttons {
state: u32,
}
impl Buttons {
/// Read the current button state
pub fn read() -> Self {
let mask = epic_button_BUTTON_LEFT_BOTTOM
| epic_button_BUTTON_RIGHT_BOTTOM
......
......@@ -84,12 +84,14 @@ pub enum Font {
Font24 = disp_font_name_DISP_FONT24 as u8,
}
/// Immediate mode routines
impl Display {
pub const W: u16 = 160;
pub const H: u16 = 80;
pub const FONT_W: u16 = 14;
pub const FONT_H: u16 = 20;
/// Open the display, return an instance
pub fn open() -> Self {
unsafe {
epic_disp_open();
......@@ -97,18 +99,22 @@ impl Display {
Display
}
/// Write Epicardium's framebuffer to the display
pub fn update(&self) {
unsafe {
epic_disp_update();
}
}
/// Clear everything with a solid `color`
pub fn clear(&self, color: Color) {
unsafe {
epic_disp_clear(color.0);
}
}
/// Print text
///
/// s must be 0-terminated
pub fn print(&self, x: u16, y: u16, s: &[u8], fg: Color, bg: Color) {
unsafe {
......@@ -116,6 +122,8 @@ impl Display {
}
}
/// Print text with a selected font
///
/// s must be 0-terminated
pub fn print_adv(&self, font: Font, x: u16, y: u16, s: &[u8], fg: Color, bg: Color) {
unsafe {
......@@ -123,12 +131,14 @@ impl Display {
}
}
/// Set a pixel
pub fn pixel(&self, x: u16, y: u16, color: Color) {
unsafe {
epic_disp_pixel(x, y, color.0);
}
}
/// Draw a line
pub fn line(
&self,
x1: u16,
......@@ -159,6 +169,7 @@ impl Display {
}
}
/// Draw a circle
pub fn circ(
&self,
x: u16,
......@@ -173,6 +184,10 @@ impl Display {
}
}
/// Obtain a handle for a framebuffer.
///
/// Don't use `display.send()` but `framebuffer.send()` as long as
/// it is in use.
pub fn framebuffer<'d>(&'d self) -> FrameBuffer<'d> {
FrameBuffer::uninitialized(self)
}
......@@ -186,6 +201,8 @@ impl Drop for Display {
}
}
/// Convenience text display
///
/// Requires `card10_alloc::init()` and `extern crate alloc;`
#[macro_export]
macro_rules! display {
......@@ -203,6 +220,8 @@ macro_rules! display {
});
}
/// Convenience text display with selected font
///
/// Requires `card10_alloc::init()` and `extern crate alloc;`
#[macro_export]
macro_rules! display_adv {
......
//! File System support (unfinished)
use core::mem::uninitialized;
use core::str::from_utf8_unchecked;
......
//! Lights
use card10_sys::*;
#[derive(Clone, Copy)]
......@@ -6,6 +8,9 @@ pub enum LEDColor {
HSV(f32, f32, f32),
}
/// Update all RGB LEDs
///
/// `f` must supply a `LEDColor` for `0..=10`.
pub fn update_rgb_leds<F>(f: F)
where
F: Fn(i32) -> LEDColor,
......
//! [Repository](https://git.card10.badge.events.ccc.de/astro/rust-card10)
#![no_std]
mod os;
......
use card10_sys::*;
/// Light sensor
pub struct LightSensor {
// Prevent creation of this struct by all but this module.
_private: (),
}
impl LightSensor {
/// Start sensing light
pub fn start() -> Self {
if unsafe { epic_light_sensor_run() } != 0 {
panic!("Cannot start light sensor");
......@@ -13,6 +15,7 @@ impl LightSensor {
LightSensor { _private: () }
}
/// Obtain current light sensor reading
pub fn get(&self) -> Option<u16> {
let mut result = 0;
if unsafe { epic_light_sensor_get(&mut result) } == 0 {
......
use card10_sys::*;
/// Execute Python script or ELF file
pub fn exec(path: &str) -> ! {
let mut pathbuf = super::str_to_cstr(path);
unsafe {
......@@ -8,6 +9,7 @@ pub fn exec(path: &str) -> ! {
unreachable!()
}
/// Exit current l0dable
pub fn exit(ret: i32) -> ! {
unsafe {
epic_exit(ret);
......@@ -15,6 +17,7 @@ pub fn exit(ret: i32) -> ! {
unreachable!()
}
/// Cause a reboot
pub fn system_reset() -> ! {
unsafe {
epic_system_reset();
......
//! Real-time clock functionality
use card10_sys::*;
use core::ops::Sub;
/// Implemented for `Seconds` and `Milliseconds`
pub trait Time {
/// Get current time
fn time() -> Self;
/// Set the time (TODO)
fn set_time(&self);
}
......@@ -20,8 +25,8 @@ impl Time for Seconds {
let s = unsafe { epic_rtc_get_seconds() };
Seconds(s)
}
/// TODO
fn set_time(&self) {
// TODO
}
}
......@@ -46,8 +51,8 @@ impl Time for MilliSeconds {
let ms = unsafe { epic_rtc_get_milliseconds() };
MilliSeconds(ms)
}
/// TODO
fn set_time(&self) {
// TODO
}
}
......
//! True Random Number Generator
use card10_sys::*;
/// Read bytes from the True Random Number Generated
pub fn read(dest: &mut [u8]) -> bool {
unsafe { epic_trng_read(dest.as_mut_ptr(), dest.len()) != 0 }
}
......@@ -2,6 +2,10 @@ use core::fmt::Write;
use card10_sys::*;
/// USB UART, 115200 baud
///
/// Supports use of `write!(Uart, "{}", ...);` Use `println!(...);`
/// for convenience.
pub struct Uart;
impl Write for Uart {
......
//! Vibration motor
use card10_sys::*;
/// Set vibration motor to off/on
pub fn set(status: bool) {
unsafe {
epic_vibra_set(status.into());
}
}
/// Vibrate for a duration
pub fn vibrate(millis: i32) {
unsafe {
epic_vibra_vibrate(millis);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment