diff --git a/.vscode/settings.json b/.vscode/settings.json index c9eb925f..4f651be4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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", + ] } diff --git a/pros-sys/Cargo.toml b/pros-sys/Cargo.toml index d26cfae1..20da4d78 100644 --- a/pros-sys/Cargo.toml +++ b/pros-sys/Cargo.toml @@ -24,3 +24,6 @@ no-link = [] [build-dependencies] cfg-if = "1.0" + +[dependencies] +cfg-if = "1.0" diff --git a/pros-sys/src/llemu.rs b/pros-sys/src/llemu.rs index 4eb6b9c3..c4a4c251 100644 --- a/pros-sys/src/llemu.rs +++ b/pros-sys/src/llemu.rs @@ -1,5 +1,7 @@ -#[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; @@ -7,10 +9,42 @@ pub const LCD_BTN_RIGHT: core::ffi::c_int = 1; pub type lcd_button_cb_fn_t = Option; -#[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 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 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" { @@ -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); + } + } }