Poll for device before initializing

This commit is contained in:
2026-09-04 09:26:54 -04:00
parent 257d1d0202
commit 8e9266e764
2 changed files with 27 additions and 1 deletions

View File

@@ -125,6 +125,11 @@ impl SpriteAtlas {
continue; continue;
} }
let c = match c as u8 {
0..33 => '?',
_ => c,
};
let sprite_index = c as usize - 33; let sprite_index = c as usize - 33;
width += self.entries[sprite_index].width as usize + 1; width += self.entries[sprite_index].width as usize + 1;
} }

View File

@@ -2,7 +2,7 @@ use cortex_m::delay::Delay;
use embedded_hal::i2c::I2c; use embedded_hal::i2c::I2c;
use rp2040_hal::i2c::Error; use rp2040_hal::i2c::Error;
use defmt as _; use defmt::{self as _, println, warn};
use crate::graphics::GraphicsBuf; use crate::graphics::GraphicsBuf;
@@ -28,6 +28,27 @@ pub struct SH1106Dev {
impl SH1106Dev { impl SH1106Dev {
pub fn new(delay: &mut Delay, mut i2c: &mut dyn I2c<Error = Error>) -> Self { pub fn new(delay: &mut Delay, mut i2c: &mut dyn I2c<Error = Error>) -> Self {
let mut rx_buff = [0u8; 1];
loop {
let res = match i2c.read(SH1106_I2C_ADDR, &mut rx_buff) {
Ok(_) => true,
Err(_) => {
warn!("sh1106 no comms");
false
}
};
if res && (rx_buff[0] & 0x80) == 0 {
break;
}
println!("Waiting for sh1106 oled init...");
delay.delay_ms(500);
}
println!("sh1106 OLED found.");
send_command(&mut i2c, &SH1106Cmd::DisplayOnOff, 0x00); send_command(&mut i2c, &SH1106Cmd::DisplayOnOff, 0x00);
delay.delay_ms(100); delay.delay_ms(100);
send_command(&mut i2c, &SH1106Cmd::DisplayInvert, 0); send_command(&mut i2c, &SH1106Cmd::DisplayInvert, 0);