diff --git a/libs/bao1x-hal/src/sh1107.rs b/libs/bao1x-hal/src/sh1107.rs index 46d20a3bb..d940ef124 100644 --- a/libs/bao1x-hal/src/sh1107.rs +++ b/libs/bao1x-hal/src/sh1107.rs @@ -514,6 +514,22 @@ impl<'a> Oled128x128<'a> { Ok(()) } + pub fn flip_vertical(&mut self, flip: bool) -> Result<(), xous::Error> { + use Command::*; + let cmds = if flip { + // flipped + [SetSegmentReMap(true), SetCOMScanDirection(Direction::Normal)] + } else { + // normal + [SetSegmentReMap(false), SetCOMScanDirection(Direction::Inverted)] + }; + for c in cmds { + let bytes = c.encode(); + self.send_command(bytes)?; + } + Ok(()) + } + pub fn powerdown(&mut self) { self.powerdown = true; // assert reset diff --git a/libs/ux-api/src/service/api.rs b/libs/ux-api/src/service/api.rs index 05eb265f6..236439f5f 100644 --- a/libs/ux-api/src/service/api.rs +++ b/libs/ux-api/src/service/api.rs @@ -112,6 +112,8 @@ pub enum GfxOpcode { BaosecBitmap, #[cfg(feature = "board-baosec")] Brightness, + #[cfg(feature = "board-baosec")] + FlipScreen, /// Gutter for invalid calls InvalidCall, diff --git a/libs/ux-api/src/service/gfx.rs b/libs/ux-api/src/service/gfx.rs index 112905735..07f1b730c 100644 --- a/libs/ux-api/src/service/gfx.rs +++ b/libs/ux-api/src/service/gfx.rs @@ -801,6 +801,21 @@ impl Gfx { .map(|_| ()) } + #[cfg(feature = "board-baosec")] + pub fn flip_screen(&self, flip: bool) -> Result<(), xous::Error> { + send_message( + self.conn, + Message::new_blocking_scalar( + GfxOpcode::FlipScreen.to_usize().unwrap(), + if flip { 1 } else { 0 }, + 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 96632db9e..fbd9b795a 100644 --- a/services/bao-video/src/main.rs +++ b/services/bao-video/src/main.rs @@ -902,6 +902,14 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { .unwrap_or_else(|_| display_timeout_handler(&udma_global, &mut display)); } } + #[cfg(feature = "board-baosec")] + GfxOpcode::FlipScreen => { + if let Some(scalar) = msg.body.scalar_message_mut() { + display + .flip_vertical(scalar.arg1 != 0) + .unwrap_or_else(|_| display_timeout_handler(&udma_global, &mut display)) + } + } GfxOpcode::Quit => break, _ => { // This is perfectly normal because not all opcodes are handled by all platforms.