diff --git a/libs/bao1x-hal/src/sh1107.rs b/libs/bao1x-hal/src/sh1107.rs index c31472913..a2fdda791 100644 --- a/libs/bao1x-hal/src/sh1107.rs +++ b/libs/bao1x-hal/src/sh1107.rs @@ -14,6 +14,9 @@ pub const PAGE: u8 = ROW as u8 / 8; // IFRAM space reserved for UDMA channel commands const SIDEBAND_LEN: usize = 256; +// 0x4f is a bit too bright +pub const DEFAULT_BRIGHTNESS: u8 = 0x3f; + pub struct MainThreadToken(()); impl MainThreadToken { pub fn new() -> Self { MainThreadToken(()) } @@ -465,7 +468,7 @@ impl<'a> Oled128x128<'a> { SetDCDCSettings(0x0), SetStartLine(0), SetDisplayOffset(0), - SetContrastControl(0x3f), // was 0x4f, was a bit too bright + SetContrastControl(DEFAULT_BRIGHTNESS), SetAddressMode(AddressMode::Column), SetSegmentReMap(false), SetCOMScanDirection(Direction::Inverted), @@ -513,6 +516,11 @@ impl<'a> Oled128x128<'a> { self.powerdown = false; } + pub fn brightness(&mut self, level: u8) { + let bytes = Command::SetContrastControl(level).encode(); + self.send_command(bytes); + } + #[cfg(feature = "std")] pub fn render_bitmap(&mut self, bitmap: ux_api::service::api::BaosecBitmap) { const W: isize = WIDTH as _; diff --git a/libs/ux-api/src/service/api.rs b/libs/ux-api/src/service/api.rs index 24ba52b47..05eb265f6 100644 --- a/libs/ux-api/src/service/api.rs +++ b/libs/ux-api/src/service/api.rs @@ -110,6 +110,8 @@ pub enum GfxOpcode { #[cfg(feature = "board-baosec")] /// This call is specific and highly optimized to the display on Baosec BaosecBitmap, + #[cfg(feature = "board-baosec")] + Brightness, /// Gutter for invalid calls InvalidCall, diff --git a/libs/ux-api/src/service/gfx.rs b/libs/ux-api/src/service/gfx.rs index 409392f7a..112905735 100644 --- a/libs/ux-api/src/service/gfx.rs +++ b/libs/ux-api/src/service/gfx.rs @@ -792,6 +792,15 @@ impl Gfx { Ok(()) } + #[cfg(feature = "board-baosec")] + pub fn brightness(&self, level: u8) -> Result<(), xous::Error> { + send_message( + self.conn, + Message::new_blocking_scalar(GfxOpcode::Brightness.to_usize().unwrap(), level as usize, 0, 0, 0), + ) + .map(|_| ()) + } + #[cfg(feature = "hosted-baosec")] pub fn acquire_qr(&self) -> Result { let dummy = "otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30".to_string(); diff --git a/services/bao-video/src/main.rs b/services/bao-video/src/main.rs index 92f2a8f86..175a19920 100644 --- a/services/bao-video/src/main.rs +++ b/services/bao-video/src/main.rs @@ -870,6 +870,13 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { let bitmap = buffer.to_original::().unwrap(); display.render_bitmap(bitmap); } + #[cfg(feature = "board-baosec")] + GfxOpcode::Brightness => { + if let Some(scalar) = msg.body.scalar_message_mut() { + let brightness = scalar.arg1.min(255) as u8; + display.brightness(brightness); + } + } GfxOpcode::Quit => break, _ => { // This is perfectly normal because not all opcodes are handled by all platforms.