firmware: Use const
s for LCD limits
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Set the given dimensional limits of the LCD in `const`s and use them accordingly.
This commit is contained in:
parent
f971da5496
commit
59ff782d52
1 changed files with 10 additions and 6 deletions
|
@ -9,6 +9,10 @@ use nb::block;
|
||||||
|
|
||||||
use crate::{assets::SYMBOL_TABLE, DefaultClock};
|
use crate::{assets::SYMBOL_TABLE, DefaultClock};
|
||||||
|
|
||||||
|
const LCD_WIDTH: u8 = 102;
|
||||||
|
const LCD_HEIGHT: u8 = 8;
|
||||||
|
const LCD_MAX_CONTRAST: u8 = 63;
|
||||||
|
|
||||||
// TODO: Make `cd` and `rst` pins generic pins
|
// TODO: Make `cd` and `rst` pins generic pins
|
||||||
pub struct Lcd {
|
pub struct Lcd {
|
||||||
pub spi: Spi,
|
pub spi: Spi,
|
||||||
|
@ -65,28 +69,28 @@ impl Lcd {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_contrast(&mut self, contrast: u8) {
|
pub fn set_contrast(&mut self, contrast: u8) {
|
||||||
assert!(contrast <= 63);
|
assert!(contrast <= LCD_MAX_CONTRAST);
|
||||||
|
|
||||||
self.control([0x81, contrast].iter());
|
self.control([0x81, contrast].iter());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_cursor(&mut self, segment: u8, page: u8) {
|
pub fn move_cursor(&mut self, segment: u8, page: u8) {
|
||||||
assert!(segment < 102);
|
assert!(segment < LCD_WIDTH);
|
||||||
assert!(page < 8);
|
assert!(page < LCD_HEIGHT);
|
||||||
|
|
||||||
self.control([0x0F & segment, 0x10 + (segment >> 4), 0xB0 + page].iter());
|
self.control([0x0F & segment, 0x10 + (segment >> 4), 0xB0 + page].iter());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill(&mut self, segment: u8, page: u8, width: u8, data: u8) {
|
fn fill(&mut self, segment: u8, page: u8, width: u8, data: u8) {
|
||||||
assert!(segment + width <= 102);
|
assert!(segment + width <= LCD_WIDTH);
|
||||||
|
|
||||||
self.move_cursor(segment, page);
|
self.move_cursor(segment, page);
|
||||||
self.display(false, iter::repeat(&data).take(width.into()));
|
self.display(false, iter::repeat(&data).take(width.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill_area(&mut self, segment: u8, page: u8, width: u8, height: u8, data: u8) {
|
pub fn fill_area(&mut self, segment: u8, page: u8, width: u8, height: u8, data: u8) {
|
||||||
assert!(segment + width <= 102);
|
assert!(segment + width <= LCD_WIDTH);
|
||||||
assert!(page + height <= 8);
|
assert!(page + height <= LCD_HEIGHT);
|
||||||
|
|
||||||
for i in 0..height {
|
for i in 0..height {
|
||||||
self.fill(segment, page + i, width, data);
|
self.fill(segment, page + i, width, data);
|
||||||
|
|
Loading…
Reference in a new issue