mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add brightness setting function
This commit is contained in:
parent
342b524209
commit
73021cb2ed
4 changed files with 27 additions and 1 deletions
|
|
@ -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 _;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<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();
|
||||
|
|
|
|||
|
|
@ -870,6 +870,13 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
|||
let bitmap = buffer.to_original::<BaosecBitmap, _>().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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue