fw-rust: Initialize the LCD display

Send commands via SPI to the LCD display to initialize and configure
it.
This commit is contained in:
finga 2022-03-04 13:17:18 +01:00
parent 643e5f1af4
commit 817776d735

View file

@ -2,12 +2,18 @@
#![no_main]
use atmega_hal::{
clock::MHz8,
delay::Delay,
pins,
spi::{DataOrder, SerialClockRate, Settings, Spi},
Peripherals,
};
use avr_device::interrupt;
use embedded_hal::spi::{Mode, Phase, Polarity};
use embedded_hal::{
blocking::delay::DelayMs,
spi::{FullDuplex, Mode, Phase, Polarity},
};
use nb::block;
use panic_halt as _;
#[atmega_hal::entry]
@ -15,9 +21,10 @@ fn main() -> ! {
// Disable interrupts when initializing
interrupt::disable();
// Get peripherals and pins
// Get peripherals, pins and delay
let dp = Peripherals::take().unwrap();
let pins = pins!(dp);
let mut delay = Delay::<MHz8>::new();
// Init display backlight
let tc0 = dp.TC0;
@ -37,7 +44,7 @@ fn main() -> ! {
pins.pd5.into_output();
// Init SPI
let (_, _) = Spi::new(
let (mut spi, _) = Spi::new(
dp.SPI,
pins.pb5.into_output(),
pins.pb3.into_output(),
@ -53,6 +60,26 @@ fn main() -> ! {
},
);
// Init LCD
let _lcd_cd = pins.pb0.into_output();
let mut lcd_rst = pins.pb1.into_output();
// TODO: Test if delay is really needed
delay.delay_ms(1_u8);
lcd_rst.set_high();
// TODO: Try to reduce delay to a minimum
delay.delay_ms(5_u8);
block!(spi.send(0x40)).unwrap(); // (6) Set Scroll Line: Display start line 0
block!(spi.send(0xA1)).unwrap(); // (13) Set SEG direction: SEG reverse
block!(spi.send(0xC0)).unwrap(); // (14) Set COM direction: Normal COM0 - COM63
block!(spi.send(0xA6)).unwrap(); // (11) Set Inverse Display: Display inverse off
block!(spi.send(0xA2)).unwrap(); // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65)
block!(spi.send(0x2F)).unwrap(); // (5) Set Power Control: Booster, Regulator and Follower on
block!(spi.send(0x27)).unwrap(); // (8) Set VLCD Resistor Ratio: Set Contrast
block!(spi.send(0x81)).unwrap(); // (9) Set Electronic Volume: Set Contrast
block!(spi.send(0x08)).unwrap(); // (9) Set Electronic Volume: Set Contrast // TODO: Use EEPROM
block!(spi.send(0xAF)).unwrap(); // (12) Set Display Enable: Display on
// Enable interrupts
unsafe { interrupt::enable() };