add ability to flip rendering of sh1107 screen

this allows a device to be flipped upside-down and have
the screen track orientation
This commit is contained in:
bunnie 2026-04-07 00:36:39 +08:00
parent 6b0972a551
commit 1ce29e80fa
4 changed files with 41 additions and 0 deletions

View file

@ -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

View file

@ -112,6 +112,8 @@ pub enum GfxOpcode {
BaosecBitmap,
#[cfg(feature = "board-baosec")]
Brightness,
#[cfg(feature = "board-baosec")]
FlipScreen,
/// Gutter for invalid calls
InvalidCall,

View file

@ -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<QrAcquisition, xous::Error> {
let dummy = "otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30".to_string();

View file

@ -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.