#![deny(unsafe_code)]
#![deny(warnings)]
#![no_std]
mod font;
mod pcd8544_gpio;
mod pcd8544_spi;
pub use pcd8544_gpio::Pcd8544Gpio;
pub use pcd8544_spi::Pcd8544Spi;
const DISPLAY_WIDTH: usize = 84;
const DISPLAY_HEIGHT: usize = 6;
const BUFFER_SIZE: usize = DISPLAY_WIDTH * DISPLAY_HEIGHT;
pub trait Pcd8544 {
fn command(&mut self, command: u8);
fn data(&mut self, data: &[u8]);
fn init(&mut self) {
self.command(0x21);
self.command(0xB1);
self.command(0x04);
self.command(0x13);
self.command(0x20);
self.command(0x0C);
self.clear();
}
fn print_char(&mut self, c: u8) {
let i = (c as usize) - 0x20;
self.data(&font::ASCII[i]);
self.data(&[0x00]);
}
fn print(&mut self, s: &str) {
for byte in s.bytes() {
match byte {
0x20..=0x7e => self.print_char(byte),
_ => self.print_char(b'?'),
}
}
}
fn set_position(&mut self, x: u8, y: u8) {
assert!(usize::from(x) < DISPLAY_WIDTH);
assert!(usize::from(y) < DISPLAY_HEIGHT);
self.command(0x40 + y);
self.command(0x80 + x);
}
fn draw_buffer(&mut self, buffer: &[u8; 6 * 84]) {
self.command(0x22); self.set_position(0, 0);
self.data(buffer);
self.command(0x20); self.set_position(0, 0);
}
fn clear(&mut self) {
self.set_position(0, 0);
self.data(&[0u8; BUFFER_SIZE]);
self.set_position(0, 0);
}
}