From 24f6ee00c5cb822be94c6b84ca660874355a0027 Mon Sep 17 00:00:00 2001 From: JP Stringham Date: Sun, 28 Dec 2025 10:57:06 -0500 Subject: [PATCH] Fixing more typo --- src/lib.rs | 2 +- src/main.rs | 2 +- src/ssh1106.rs | 126 ------------------------------------------------- 3 files changed, 2 insertions(+), 128 deletions(-) delete mode 100644 src/ssh1106.rs diff --git a/src/lib.rs b/src/lib.rs index d667ba1..9ecee7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ #![no_std] pub mod graphics; -pub mod ssh1106; +pub mod sh1106; diff --git a/src/main.rs b/src/main.rs index 323ae0d..bcac557 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ fn main() -> ! { let mut led_pin = pins.gpio25.into_push_pull_output(); 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."); let mut gfx_buf = sh1106_pico_rs::graphics::GraphicsBuf::new(); diff --git a/src/ssh1106.rs b/src/ssh1106.rs deleted file mode 100644 index 5fa2bca..0000000 --- a/src/ssh1106.rs +++ /dev/null @@ -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) -> 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, 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, 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, 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, page: u8) { - send_command(i2c, &SH1106Cmd::SetPage, page & 0b0000_0111); -} - -fn clr_screen(i2c: &mut dyn I2c) { - 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, 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) { - _ => (), - }; -}