Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
feat(sys): add colors to xapi in llemu
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Nov 18, 2023
1 parent 77f6a2d commit d2efe4d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@
"vexlink"
],
"rust-analyzer.check.allTargets": false,
"rust-analyzer.cargo.features": [
"xapi"
],
"rust-analyzer.check.targets": [
"${workspaceFolder}/armv7a-vexos-eabi.json",
"wasm32-unknown-unknown",
]
}
3 changes: 3 additions & 0 deletions pros-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ no-link = []

[build-dependencies]
cfg-if = "1.0"

[dependencies]
cfg-if = "1.0"
72 changes: 62 additions & 10 deletions pros-sys/src/llemu.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
#[cfg(feature = "xapi")]
compile_error!("LVGL bindings (xapi) are a todo for now");
// #[cfg(feature = "xapi")]
// compile_error!("LVGL bindings (xapi) are a todo for now");

use cfg_if::cfg_if;

pub const LCD_BTN_LEFT: core::ffi::c_int = 4;
pub const LCD_BTN_CENTER: core::ffi::c_int = 2;
pub const LCD_BTN_RIGHT: core::ffi::c_int = 1;

pub type lcd_button_cb_fn_t = Option<unsafe extern "C" fn()>;

#[cfg(feature = "xapi")]
#[repr(C)]
pub struct lcd_s_t {
//TODO
cfg_if! {
if #[cfg(feature = "xapi")] {
// #[repr(C)]
// pub struct lcd_s_t {
// //TODO
// }

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct lv_color_t {
pub blue: u8,
pub green: u8,
pub red: u8,
pub alpha: u8,
}

impl From<u32> for lv_color_t {
fn from(color: u32) -> Self {
Self {
blue: (color & 0xFF) as u8,
green: ((color >> 8) & 0xFF) as u8,
red: ((color >> 16) & 0xFF) as u8,
alpha: ((color >> 24) & 0xFF) as u8,
}
}
}

impl From<lv_color_t> for u32 {
fn from(color: lv_color_t) -> Self {
(color.blue as u32)
| ((color.green as u32) << 8)
| ((color.red as u32) << 16)
| ((color.alpha as u32) << 24)
}
}
}
}

extern "C" {
Expand Down Expand Up @@ -149,8 +183,26 @@ extern "C" {
\return The buttons pressed as a bit mask*/
pub fn lcd_read_buttons() -> u8;

#[cfg(feature = "xapi")]
pub fn lcd_set_background_color(); //TODO
#[cfg(feature = "xapi")]
pub fn lcd_set_text_color(); //TODO
cfg_if! {
if #[cfg(feature = "xapi")] {
/** Changes the color of the LCD background to a provided color expressed in
type lv_color_t.
\param color
A color of type lv_color_t
\return void
*/
pub fn lcd_set_background_color(color: lv_color_t);
/** Changes the text color of the LCD to a provided color expressed in
type lv_color_t.
\param color
A color of type lv_color_t
\return void
*/
pub fn lcd_set_text_color(color: lv_color_t);
}
}
}

0 comments on commit d2efe4d

Please sign in to comment.