Fixing more typo

This commit is contained in:
JP Stringham
2025-12-28 10:57:06 -05:00
parent abb6d9983e
commit 24f6ee00c5
3 changed files with 2 additions and 128 deletions

View File

@@ -1,4 +1,4 @@
#![no_std] #![no_std]
pub mod graphics; pub mod graphics;
pub mod ssh1106; pub mod sh1106;

View File

@@ -65,7 +65,7 @@ fn main() -> ! {
let mut led_pin = pins.gpio25.into_push_pull_output(); let mut led_pin = pins.gpio25.into_push_pull_output();
led_pin.set_high().unwrap(); led_pin.set_high().unwrap();
let sh1106_dev = sh1106_pico_rs::ssh1106::SH1106Dev::new(&mut delay, &mut i2c); let sh1106_dev = sh1106_pico_rs::sh1106::SH1106Dev::new(&mut delay, &mut i2c);
println!("SH1106 initialized."); println!("SH1106 initialized.");
let mut gfx_buf = sh1106_pico_rs::graphics::GraphicsBuf::new(); let mut gfx_buf = sh1106_pico_rs::graphics::GraphicsBuf::new();

View File

@@ -1,126 +0,0 @@
use cortex_m::delay::Delay;
use embedded_hal::i2c::I2c;
use rp2040_hal::i2c::Error;
use defmt as _;
use crate::graphics::GraphicsBuf;
#[allow(unused)]
#[repr(u8)]
#[derive(PartialEq, Copy, Clone)]
pub enum SH1106Cmd {
SetColumnLo = 0,
SetColumnHi = 0x10,
DisplayInvert = 0xA6,
DisplayOnOff = 0xAE,
ColDirectionNorm = 0xC0,
ColDirectionRev = 0xC8,
SetPage = 0xB0,
}
pub const SH1106_I2C_ADDR: u8 = 0x78u8 >> 1;
pub struct SH1106Dev {
ready: bool,
}
impl SH1106Dev {
pub fn new(delay: &mut Delay, mut i2c: &mut dyn I2c<Error = Error>) -> Self {
send_command(&mut i2c, &SH1106Cmd::DisplayOnOff, 0x00);
delay.delay_ms(100);
send_command(&mut i2c, &SH1106Cmd::DisplayInvert, 0);
send_command(&mut i2c, &SH1106Cmd::ColDirectionNorm, 0);
set_col(&mut i2c, 2);
set_page(&mut i2c, 0);
clr_screen(&mut i2c);
delay.delay_ms(500);
send_command(&mut i2c, &SH1106Cmd::DisplayOnOff, 0x01);
SH1106Dev { ready: true }
}
pub fn blit_framebuffer(&self, i2c: &mut dyn I2c<Error = Error>, gfx_buf: &GraphicsBuf) {
if !self.ready {
panic!("Attempted to use SSH1106 before initialized.");
}
let buf = gfx_buf.get_px_buffer();
// for each row of 8x8 pixels
for r in 0..8 {
set_page(i2c, r);
set_col(i2c, 2);
// for each cel of 8x8 pixels
for c in 0..16 {
let mut cel = [0u8; 8];
// so our x,y here would be r * 128 + c * 8
// start assembling the 8x8 cel
for x in 0..8 {
let mut col_byte = 0u8;
// for each row of the cel
for y in 0..8 {
let pix_x = (c as usize) * 8 + x;
let pix_y = (r as usize) * 8 + y;
col_byte |= buf[pix_y * 128 + pix_x] << y;
}
cel[x] = col_byte;
}
write_cel_pixels(i2c, &cel);
}
}
}
}
fn send_command(i2c: &mut dyn I2c<Error = Error>, command: &SH1106Cmd, data: u8) {
let mut writebuf: [u8; 2] = [0; 2];
writebuf[0] = 0b1000_0000;
writebuf[1] = (command.clone() as u8) | data;
match i2c.write(SH1106_I2C_ADDR, &writebuf) {
_ => (),
};
}
fn set_col(i2c: &mut dyn I2c<Error = Error>, col: u8) {
let col_lo = col & 0b0000_1111;
let col_hi = (col & 0b1111_0000) >> 4;
send_command(i2c, &SH1106Cmd::SetColumnLo, col_lo);
send_command(i2c, &SH1106Cmd::SetColumnHi, col_hi);
}
fn set_page(i2c: &mut dyn I2c<Error = Error>, page: u8) {
send_command(i2c, &SH1106Cmd::SetPage, page & 0b0000_0111);
}
fn clr_screen(i2c: &mut dyn I2c<Error = Error>) {
let mut writebuf = [0u8; 132 * 8 + 1];
writebuf[0] = 0b0100_0000;
for i in 0..8 {
match i2c.write(SH1106_I2C_ADDR, &writebuf) {
_ => (),
};
set_page(i2c, i);
}
}
fn write_cel_pixels(i2c: &mut dyn I2c<Error = Error>, data: &[u8]) {
let mut writebuf = [0b0100_0000u8; 9];
writebuf[0] = 0b0100_0000;
writebuf[1..].copy_from_slice(&data[0..8]);
match i2c.write(SH1106_I2C_ADDR, &writebuf) {
_ => (),
};
}