diff --git a/src/eink_display/frame.rs b/src/eink_display/frame.rs index 36fa370..a23ceda 100644 --- a/src/eink_display/frame.rs +++ b/src/eink_display/frame.rs @@ -40,7 +40,7 @@ impl Frame { impl Default for Frame { fn default() -> Self { Frame { - buffer: [0x00; Self::BUFFER_SIZE], + buffer: [0b1111_1111; Self::BUFFER_SIZE], orientation: Orientation::Portrait, } } @@ -60,7 +60,8 @@ impl OriginDimensions for Frame { } } -enum DrawError { +#[derive(defmt::Format)] +pub(crate) enum DrawError { /// If more details about the error are needed at runtime, then add them OutOfBounds, } @@ -100,10 +101,10 @@ impl DrawTarget for Frame { let bit_index = 7 - x_hardware % 8; self.buffer[index] = match color { - // E-Ink light is not charged = white - BinaryColor::On => self.buffer[index] & !(1 << bit_index), // E-Ink dark is charged = black BinaryColor::Off => self.buffer[index] | (1 << bit_index), + // E-Ink light is not charged = white + BinaryColor::On => self.buffer[index] & !(1 << bit_index), }; } Ok(()) diff --git a/src/eink_display/mod.rs b/src/eink_display/mod.rs index 0ef6a7b..6668cc4 100644 --- a/src/eink_display/mod.rs +++ b/src/eink_display/mod.rs @@ -1,7 +1,5 @@ -use core::{convert::Infallible, ops::RangeInclusive}; - pub(crate) use crate::eink_display::error::*; -use crate::eink_display::frame::Frame; +pub(crate) use crate::eink_display::frame::Frame; use defmt::info; use embassy_time::{Duration, Timer, with_timeout}; diff --git a/src/input.rs b/src/input.rs index 360e177..9660f3a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -74,9 +74,9 @@ impl<'a> Analog<'a> { pub(crate) async fn poll(&mut self) { let values = self.read_values().await; - let button_1 = get_active_button(values.0, &PIN_1_RANGES, Pin::One); - let button_2 = get_active_button(values.1, &PIN_2_RANGES, Pin::Two); - info!("Battery? {}", values.2); + info!("Battery? {}", values.0); + let button_1 = get_active_button(values.1, &PIN_1_RANGES, Pin::One); + let button_2 = get_active_button(values.2, &PIN_2_RANGES, Pin::Two); match (button_1, button_2) { (Some(button_1), Some(button_2)) => { info!("Button 1: {}, Button 2: {}", button_1, button_2); diff --git a/src/main.rs b/src/main.rs index 81af62a..f285df8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,9 +14,14 @@ mod spi; use defmt::{error, info}; use embassy_executor::Spawner; use embassy_time::Timer; -use esp_hal::analog::adc::AdcChannel; +use embedded_graphics::Drawable; +use embedded_graphics::mono_font::MonoTextStyle; +use embedded_graphics::mono_font::ascii::FONT_10X20; +use embedded_graphics::pixelcolor::BinaryColor; +use embedded_graphics::prelude::Point; +use embedded_graphics::text::Text; use esp_hal::gpio::{self, Input, InputConfig}; -use esp_hal::peripherals::{ADC2, GPIO0, GPIO3, LPWR}; +use esp_hal::peripherals::{GPIO3, LPWR}; use esp_hal::rtc_cntl::sleep::{RtcioWakeupSource, WakeupLevel}; use esp_hal::rtc_cntl::{reset_reason, wakeup_cause}; use esp_hal::system::Cpu; @@ -24,7 +29,7 @@ use esp_hal::timer::timg::TimerGroup; use esp_hal::{clock::CpuClock, rtc_cntl::Rtc}; use {esp_backtrace as _, esp_println as _}; -use crate::eink_display::EinkDisplay; +use crate::eink_display::{EinkDisplay, Frame}; use crate::input::Analog; extern crate alloc; @@ -68,11 +73,10 @@ async fn handle_power_button( info!("Power button pressed. Turning off"); + let frame = Frame::default(); + if let Err(error) = eink_display - .display( - eink_display::RefreshMode::Full, - &[0x00; eink_display::BUFFER_SIZE], - ) + .display(eink_display::RefreshMode::Full, &frame) .await { error!( @@ -173,9 +177,13 @@ async fn run(spawner: Spawner) -> Result<(), ApplicationError> { .await .map_err(ApplicationError::SetUpEinkDisplay)?; - let mut frame = [0x00u8; eink_display::BUFFER_SIZE]; - frame[0..eink_display::BUFFER_SIZE / 2].fill(0x33); - // frame[eink_display::BUFFER_SIZE / 2..].fill(0x00); + let mut frame = Frame::default(); + + let style = MonoTextStyle::new(&FONT_10X20, BinaryColor::On); + let text = Text::new("Hello, World!", Point::new(0, 20), style); + if let Err(error) = text.draw(&mut frame) { + error!("Failed to draw text: {:?}", error); + } display .display(eink_display::RefreshMode::Full, &frame)