fw-rust: Create a print u8
function for setup
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Create `print_u8()` helper function to print `u8` primitives to lcd. Refactor contrast and backlight variables to also keep them in a global `AtomicU8`.
This commit is contained in:
parent
c2920ea334
commit
7d8f5f6870
3 changed files with 55 additions and 14 deletions
|
@ -11,7 +11,7 @@ use atmega_hal::{
|
|||
};
|
||||
use avr_device::interrupt;
|
||||
use avr_eeprom::{eeprom, Eeprom};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use core::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||
use embedded_hal::{
|
||||
blocking::delay::DelayMs,
|
||||
spi::{Mode, Phase, Polarity},
|
||||
|
@ -28,8 +28,8 @@ use rotary::{Direction, Rotary};
|
|||
use screen::Screens;
|
||||
|
||||
eeprom! {
|
||||
static eeprom CONTRAST: u8 = 8;
|
||||
static eeprom BACKLIGHT: u8 = 1;
|
||||
static eeprom EEPROM_CONTRAST: u8 = 8;
|
||||
static eeprom EEPROM_BACKLIGHT: u8 = 1;
|
||||
}
|
||||
|
||||
pub enum Input {
|
||||
|
@ -42,6 +42,8 @@ pub enum Input {
|
|||
static UPDATE_ENCODER: AtomicBool = AtomicBool::new(false);
|
||||
static UPDATE_BUTTON: AtomicBool = AtomicBool::new(false);
|
||||
static UPDATE_TIMER: AtomicBool = AtomicBool::new(false);
|
||||
static CONTRAST: AtomicU8 = AtomicU8::new(0);
|
||||
static BACKLIGHT: AtomicU8 = AtomicU8::new(0);
|
||||
|
||||
#[interrupt(atmega328p)]
|
||||
#[allow(non_snake_case)]
|
||||
|
@ -76,8 +78,8 @@ fn main() -> ! {
|
|||
let mut delay = Delay::<MHz8>::new();
|
||||
|
||||
// Get contrast and backlight from EEPROM
|
||||
let contrast = eeprom.read_value(&CONTRAST);
|
||||
let backlight = eeprom.read_value(&BACKLIGHT);
|
||||
CONTRAST.store(eeprom.read_value(&EEPROM_CONTRAST), Ordering::SeqCst);
|
||||
BACKLIGHT.store(eeprom.read_value(&EEPROM_BACKLIGHT), Ordering::SeqCst);
|
||||
|
||||
// Init display backlight
|
||||
let tc0 = dp.TC0;
|
||||
|
@ -92,7 +94,8 @@ fn main() -> ! {
|
|||
w
|
||||
});
|
||||
tc0.ocr0a.write(|w| unsafe { w.bits(255) });
|
||||
tc0.ocr0b.write(|w| unsafe { w.bits(backlight) });
|
||||
tc0.ocr0b
|
||||
.write(|w| unsafe { w.bits(BACKLIGHT.load(Ordering::SeqCst)) });
|
||||
pins.pd5.into_output();
|
||||
|
||||
// Init SPI
|
||||
|
@ -114,7 +117,7 @@ fn main() -> ! {
|
|||
|
||||
// Init LCD
|
||||
let mut lcd = Lcd::new(spi, pins.pb0.into_output(), pins.pb1.into_output());
|
||||
lcd.init(contrast);
|
||||
lcd.init(CONTRAST.load(Ordering::SeqCst));
|
||||
|
||||
// Init encoder
|
||||
let mut encoder = Rotary::new(pins.pb6.into_pull_up_input(), pins.pb7.into_pull_up_input());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue