From 634598c111efb2074e343cf1d64f8b253c686302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gro=C3=9F?= Date: Thu, 26 Jul 2018 15:57:07 +0200 Subject: [PATCH] improved documenation --- src/drawing/color.rs | 20 +++++++--- src/interface/connection_interface.rs | 2 +- src/interface/mod.rs | 54 ++++----------------------- src/lib.rs | 14 ++----- 4 files changed, 25 insertions(+), 65 deletions(-) diff --git a/src/drawing/color.rs b/src/drawing/color.rs index 406b7fc..a7e2354 100644 --- a/src/drawing/color.rs +++ b/src/drawing/color.rs @@ -1,11 +1,11 @@ - - +/// Only for the B/W Displays atm pub enum Color { Black, White } impl Color { + /// Get the color encoding of the color for one bit pub fn get_bit_value(&self) -> u8 { match self { Color::White => 1u8, @@ -13,6 +13,7 @@ impl Color { } } + /// Gets a full byte of black or white pixels pub fn get_byte_value(&self) -> u8 { match self { Color::White => 0xff, @@ -20,8 +21,13 @@ impl Color { } } - //position counted from the left (highest value) from 0 to 7 - //remember: 1 is white, 0 is black + + /// Get the color encoding of a specific bit in a byte + /// + /// input is the byte where one bit is gonna be selected + /// pos is counted from the left (highest value) from 0 to 7 + /// remember: 1 is white, 0 is black + /// Color is the color you want to draw with in the foreground pub(crate) fn get_color(input: u8, pos: u8, color: &Color) -> Color { match Color::is_drawable_pixel(input, pos) { true => Color::normal_color(color), @@ -29,6 +35,7 @@ impl Color { } } + // Inverses the given color from Black to White or from White to Black fn inverse_color(color: &Color) -> Color { match color { Color::White => Color::Black, @@ -36,7 +43,8 @@ impl Color { } } - + // Gives you a new owned copy of the color + //TODO: just use clone? fn normal_color(color: &Color) -> Color { match color { Color::White => Color::White, @@ -50,7 +58,7 @@ impl Color { ((input >> (7 - pos)) & 1u8) > 0u8 } - + //TODO: does basically the same as get_color, so remove one of them? pub(crate) fn convert_color(input: u8, pos: u8, foreground_color: &Color) -> Color { //match color: // - white for "nothing to draw"/background drawing diff --git a/src/interface/connection_interface.rs b/src/interface/connection_interface.rs index 8d47708..7ae2cc5 100644 --- a/src/interface/connection_interface.rs +++ b/src/interface/connection_interface.rs @@ -8,7 +8,7 @@ use hal::{ use interface::Command; -/// EPD4in2 driver +/// The Connection Interface of all (?) Waveshare EPD-Devices /// pub(crate) struct ConnectionInterface { /// SPI diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 9c23c8e..0bf783a 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -3,34 +3,27 @@ use hal::{ spi::Write, delay::* }, - spi::{Mode, Phase, Polarity}, digital::* }; +use core::marker::Sized; + use drawing::color::Color; +/// Interface for the physical connection between display and the controlling device pub mod connection_interface; -//TODO: test spi mode -/// SPI mode - -/// For more infos see [Requirements: SPI](index.html#spi) -pub const SPI_MODE: Mode = Mode { - phase: Phase::CaptureOnFirstTransition, - polarity: Polarity::IdleLow, -}; - -use core::marker::Sized; +/// All commands need to have this trait which gives the address of the command +/// which needs to be send via SPI with activated CommandsPin (Data/Command Pin in CommandMode) pub(crate) trait Command { fn address(self) -> u8; } -//TODO add LUT trait with set_fast_lut -// and set_manual_lut and set_normal_lut or sth like that +//TODO: add LUT trait with set_fast_lut and set_manual_lut and set_normal_lut or sth like that? // for partial updates - -pub trait LUTSupport { +trait LUTSupport { fn set_lut(&mut self) -> Result<(), Error>; fn set_lut_quick(&mut self) -> Result<(), Error>; fn set_lut_manual(&mut self, data: &[u8]) -> Result<(), Error>; @@ -122,37 +115,4 @@ pub trait WaveshareInterface /// /// maximum delay ~65 seconds (u16:max in ms) fn delay_ms(&mut self, delay: u16); - - /* - - - // - -set_quick_lut? - -set_normal_mode - - - fn clear_frame(&mut self, reset_color: Option) -> Result<(), E> - - fn display_frame_quick(&mut self) -> Result<(), E> - - fn display_frame(&mut self) -> Result<(), E> - - pub fn display_and_transfer_frame( - &mut self, - buffer: &[u8], - color: Option -) -> Result<(), E> - - pub fn set_partial_window( - &mut self, - buffer: &[u8], - x: u16, - y: u16, - w: u16, - l: u16, - is_dtm1: bool -) -> Result<(), E> - -*/ - } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0dd8b57..a6558f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,4 @@ //! A simple Driver for the Waveshare E-Ink Displays via SPI -//! -//! The other Waveshare E-Ink Displays should be added later on, atm it's only the 4.2"-Display -//! -//! Build with the help of documentation/code from [Waveshare](https://www.waveshare.com/wiki/4.2inch_e-Paper_Module), -//! [Ben Krasnows partial Refresh tips](https://benkrasnow.blogspot.de/2017/10/fast-partial-refresh-on-42-e-paper.html) and -//! the driver documents in the `pdfs`-folder as orientation. //! //! This driver was built using [`embedded-hal`] traits. //! @@ -44,13 +38,11 @@ //! epd4in2.sleep(); //! ``` //! -//! -//! BE CAREFUL! The Partial Drawing can "destroy" your display. -//! It needs more testing first. -//! -//! TODO: Make more assertions about buffersizes? +//! #![no_std] +//TODO: Make more assertions about buffersizes? + extern crate embedded_hal as hal;