mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +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
|
// IFRAM space reserved for UDMA channel commands
|
||||||
const SIDEBAND_LEN: usize = 256;
|
const SIDEBAND_LEN: usize = 256;
|
||||||
|
|
||||||
|
// 0x4f is a bit too bright
|
||||||
|
pub const DEFAULT_BRIGHTNESS: u8 = 0x3f;
|
||||||
|
|
||||||
pub struct MainThreadToken(());
|
pub struct MainThreadToken(());
|
||||||
impl MainThreadToken {
|
impl MainThreadToken {
|
||||||
pub fn new() -> Self { MainThreadToken(()) }
|
pub fn new() -> Self { MainThreadToken(()) }
|
||||||
|
|
@ -465,7 +468,7 @@ impl<'a> Oled128x128<'a> {
|
||||||
SetDCDCSettings(0x0),
|
SetDCDCSettings(0x0),
|
||||||
SetStartLine(0),
|
SetStartLine(0),
|
||||||
SetDisplayOffset(0),
|
SetDisplayOffset(0),
|
||||||
SetContrastControl(0x3f), // was 0x4f, was a bit too bright
|
SetContrastControl(DEFAULT_BRIGHTNESS),
|
||||||
SetAddressMode(AddressMode::Column),
|
SetAddressMode(AddressMode::Column),
|
||||||
SetSegmentReMap(false),
|
SetSegmentReMap(false),
|
||||||
SetCOMScanDirection(Direction::Inverted),
|
SetCOMScanDirection(Direction::Inverted),
|
||||||
|
|
@ -513,6 +516,11 @@ impl<'a> Oled128x128<'a> {
|
||||||
self.powerdown = false;
|
self.powerdown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn brightness(&mut self, level: u8) {
|
||||||
|
let bytes = Command::SetContrastControl(level).encode();
|
||||||
|
self.send_command(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn render_bitmap(&mut self, bitmap: ux_api::service::api::BaosecBitmap) {
|
pub fn render_bitmap(&mut self, bitmap: ux_api::service::api::BaosecBitmap) {
|
||||||
const W: isize = WIDTH as _;
|
const W: isize = WIDTH as _;
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,8 @@ pub enum GfxOpcode {
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
/// This call is specific and highly optimized to the display on Baosec
|
/// This call is specific and highly optimized to the display on Baosec
|
||||||
BaosecBitmap,
|
BaosecBitmap,
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
Brightness,
|
||||||
|
|
||||||
/// Gutter for invalid calls
|
/// Gutter for invalid calls
|
||||||
InvalidCall,
|
InvalidCall,
|
||||||
|
|
|
||||||
|
|
@ -792,6 +792,15 @@ impl Gfx {
|
||||||
Ok(())
|
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")]
|
#[cfg(feature = "hosted-baosec")]
|
||||||
pub fn acquire_qr(&self) -> Result<QrAcquisition, xous::Error> {
|
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();
|
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();
|
let bitmap = buffer.to_original::<BaosecBitmap, _>().unwrap();
|
||||||
display.render_bitmap(bitmap);
|
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,
|
GfxOpcode::Quit => break,
|
||||||
_ => {
|
_ => {
|
||||||
// This is perfectly normal because not all opcodes are handled by all platforms.
|
// This is perfectly normal because not all opcodes are handled by all platforms.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue