Poll for device before initializing
This commit is contained in:
@@ -125,6 +125,11 @@ impl SpriteAtlas {
|
||||
continue;
|
||||
}
|
||||
|
||||
let c = match c as u8 {
|
||||
0..33 => '?',
|
||||
_ => c,
|
||||
};
|
||||
|
||||
let sprite_index = c as usize - 33;
|
||||
width += self.entries[sprite_index].width as usize + 1;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use cortex_m::delay::Delay;
|
||||
use embedded_hal::i2c::I2c;
|
||||
use rp2040_hal::i2c::Error;
|
||||
|
||||
use defmt as _;
|
||||
use defmt::{self as _, println, warn};
|
||||
|
||||
use crate::graphics::GraphicsBuf;
|
||||
|
||||
@@ -28,6 +28,27 @@ pub struct SH1106Dev {
|
||||
|
||||
impl SH1106Dev {
|
||||
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);
|
||||
delay.delay_ms(100);
|
||||
send_command(&mut i2c, &SH1106Cmd::DisplayInvert, 0);
|
||||
|
||||
Reference in New Issue
Block a user