Use Rgb565 as default

This commit is contained in:
Rafael Caricio 2020-04-21 10:52:21 +02:00
parent 7578e6c20c
commit 6d7d00759b
11 changed files with 413 additions and 901 deletions

View file

@ -1,14 +1,3 @@
/**
* @file lv_conf.h
*
*/
/*
* COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER
*/
#if 1 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/* clang-format off */
@ -56,7 +45,7 @@
/* Dot Per Inch: used to initialize default sizes.
* E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI 100 /*[px]*/
#define LV_DPI 298 /*[px]*/
/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
typedef int16_t lv_coord_t;
@ -72,7 +61,7 @@ typedef int16_t lv_coord_t;
#define LV_MEM_CUSTOM 0
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (128U * 1024U)
# define LV_MEM_SIZE (4U * 1024U)
/* Complier prefix for a big array declaration */
# define LV_MEM_ATTR
@ -145,10 +134,10 @@ typedef void * lv_group_user_data_t;
#endif /*LV_USE_GROUP*/
/* 1: Enable GPU interface*/
#define LV_USE_GPU 1
#define LV_USE_GPU 0
/* 1: Enable file system (might be required for images */
#define LV_USE_FILESYSTEM 1
#define LV_USE_FILESYSTEM 0
#if LV_USE_FILESYSTEM
/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_fs_drv_user_data_t;
@ -224,7 +213,7 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
*===============*/
/*1: Enable the log module*/
#define LV_USE_LOG 1
#define LV_USE_LOG 0
#if LV_USE_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
@ -237,7 +226,7 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
/* 1: Print the log with 'printf';
* 0: user need to register a callback with `lv_log_register_print_cb`*/
# define LV_LOG_PRINTF 1
# define LV_LOG_PRINTF 0
#endif /*LV_USE_LOG*/
/*=================
@ -253,7 +242,7 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
* The behavior of asserts can be overwritten by redefining them here.
* E.g. #define LV_ASSERT_MEM(p) <my_assert_code>
*/
#define LV_USE_DEBUG 1
#define LV_USE_DEBUG 0
#if LV_USE_DEBUG
/*Check if the parameter is NULL. (Quite fast) */
@ -265,11 +254,11 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
/* Check the strings.
* Search for NULL, very long strings, invalid characters, and unnatural repetitions. (Slow)
* If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */
#define LV_USE_ASSERT_STR 1
#define LV_USE_ASSERT_STR 0
/* Check NULL, the object's type and existence (e.g. not deleted). (Quite slow)
* If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */
#define LV_USE_ASSERT_OBJ 1
#define LV_USE_ASSERT_OBJ 0
/*Check if the styles are properly initialized. (Fast)*/
#define LV_USE_ASSERT_STYLE 1
@ -282,13 +271,13 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
#define LV_THEME_LIVE_UPDATE 0 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#define LV_USE_THEME_TEMPL 0 /*Just for test*/
#define LV_USE_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#define LV_USE_THEME_ALIEN 1 /*Dark futuristic theme*/
#define LV_USE_THEME_NIGHT 1 /*Dark elegant theme*/
#define LV_USE_THEME_MONO 1 /*Mono color theme for monochrome displays*/
#define LV_USE_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/
#define LV_USE_THEME_ZEN 1 /*Peaceful, mainly light theme */
#define LV_USE_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/
#define LV_USE_THEME_DEFAULT 0 /*Built mainly from the built-in styles. Consumes very few RAM*/
#define LV_USE_THEME_ALIEN 0 /*Dark futuristic theme*/
#define LV_USE_THEME_NIGHT 0 /*Dark elegant theme*/
#define LV_USE_THEME_MONO 0 /*Mono color theme for monochrome displays*/
#define LV_USE_THEME_MATERIAL 0 /*Flat theme with bold colors and light shadows*/
#define LV_USE_THEME_ZEN 0 /*Peaceful, mainly light theme */
#define LV_USE_THEME_NEMO 0 /*Water-like theme based on the movie "Finding Nemo"*/
/*==================
* FONT USAGE
@ -302,10 +291,10 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
/* Robot fonts with bpp = 4
* https://fonts.google.com/specimen/Roboto */
#define LV_FONT_ROBOTO_12 1
#define LV_FONT_ROBOTO_16 1
#define LV_FONT_ROBOTO_22 1
#define LV_FONT_ROBOTO_28 1
#define LV_FONT_ROBOTO_12 0
#define LV_FONT_ROBOTO_16 0
#define LV_FONT_ROBOTO_22 0
#define LV_FONT_ROBOTO_28 1
/* Demonstrate special features */
#define LV_FONT_ROBOTO_12_SUBPX 1
@ -313,7 +302,7 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
/*Pixel perfect monospace font
* http://pelulamu.net/unscii/ */
#define LV_FONT_UNSCII_8 1
#define LV_FONT_UNSCII_8 0
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
@ -324,7 +313,7 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
#define LV_FONT_CUSTOM_DECLARE
/*Always set a default font from the built-in fonts*/
#define LV_FONT_DEFAULT &lv_font_roboto_16
#define LV_FONT_DEFAULT &lv_font_roboto_28
/* Enable it if you have fonts with a lot of characters.
* The limit depends on the font size, font face and bpp
@ -351,7 +340,7 @@ typedef void * lv_font_user_data_t;
* */
#define LV_TXT_ENC LV_TXT_ENC_UTF8
/*Can break (wrap) texts on these chars*/
/*Can break (wrap) texts on these chars*/
#define LV_TXT_BREAK_CHARS " ,.;:-_"
@ -374,7 +363,7 @@ typedef void * lv_font_user_data_t;
* Allows mixing Left-to-Right and Right-to-Left texts.
* The direction will be processed according to the Unicode Bidirectioanl Algorithm:
* https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/
#define LV_USE_BIDI 1
#define LV_USE_BIDI 0
#if LV_USE_BIDI
/* Set the default direction. Supported values:
* `LV_BIDI_DIR_LTR` Left-to-Right
@ -588,5 +577,3 @@ typedef void * lv_obj_user_data_t;
#include "lvgl/src/lv_conf_checker.h"
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

View file

@ -1,14 +1,18 @@
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{
BinaryColorTheme, OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
};
use lvgl;
use lvgl::Object;
use lvgl_sys;
use std::sync::mpsc;
use std::time::Duration;
use embedded_graphics::pixelcolor::Rgb888;
use embedded_graphics::mock_display::MockDisplay;
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window, BinaryColorTheme, SimulatorEvent};
fn main() -> Result<(), String> {
let mut display: SimulatorDisplay<Rgb888> = SimulatorDisplay::new(Size::new(lvgl_sys::LV_HOR_RES_MAX,lvgl_sys::LV_VER_RES_MAX));
let mut display = SimulatorDisplay::new(Size::new(
lvgl_sys::LV_HOR_RES_MAX,
lvgl_sys::LV_VER_RES_MAX,
));
let output_settings = OutputSettingsBuilder::new()
.theme(BinaryColorTheme::OledBlue)
@ -64,6 +68,16 @@ fn main() -> Result<(), String> {
power.set_label_align(lvgl::LabelAlign::Right);
power.set_align(&mut screen, lvgl::Align::InTopRight, 0, 0);
let (stop_ch, read_ch) = mpsc::channel();
let tick_thr = std::thread::spawn(move || loop {
::std::thread::sleep(Duration::from_millis(5));
unsafe {
lvgl_sys::lv_tick_inc(5);
}
if read_ch.try_recv().is_ok() {
break;
}
});
let mut i = 0;
'running: loop {
@ -73,12 +87,14 @@ fn main() -> Result<(), String> {
time.set_text(format!("21:{:02}\0", i).as_str());
i = 1 + i;
::std::thread::sleep(Duration::from_millis(10));
::std::thread::sleep(Duration::from_millis(
lvgl_sys::LV_DISP_DEF_REFR_PERIOD as u64,
));
unsafe {
lvgl_sys::lv_task_handler();
lvgl_sys::lv_tick_inc(10);
}
window.update(&display);
for event in window.events() {
@ -89,6 +105,9 @@ fn main() -> Result<(), String> {
}
}
stop_ch.send(true).unwrap();
tick_thr.join().unwrap();
Ok(())
}

View file

@ -8,7 +8,7 @@ fn main() {
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.canonicalize()
.unwrap();
let include_dir = project_dir.join("include");
let shims_dir = project_dir.join("shims");
let vendor = project_dir.join("vendor");
let vendor_src = vendor.join("lvgl").join("src");
@ -55,7 +55,7 @@ fn main() {
add_c_files(&mut cfg, vendor_src.join("lv_themes"));
add_c_files(&mut cfg, vendor_src.join("lv_themes"));
add_c_files(&mut cfg, &lv_config_dir);
add_c_files(&mut cfg, &include_dir);
add_c_files(&mut cfg, &shims_dir);
cfg.define("LV_CONF_INCLUDE_SIMPLE", Some("1"))
.include(&vendor_src)
@ -72,7 +72,7 @@ fn main() {
vendor.to_str().unwrap(),
];
bindgen::Builder::default()
.header(include_dir.join("lvgl_sys.h").to_str().unwrap())
.header(shims_dir.join("lvgl_sys.h").to_str().unwrap())
.layout_tests(false)
.use_core()
.ctypes_prefix("cty")

View file

@ -1,6 +0,0 @@
#include "lvgl_sys.h"
lv_color_t lvsys_color_make(uint8_t r, uint8_t g, uint8_t b)
{
return LV_COLOR_MAKE(r, g, b);
}

View file

@ -1,16 +0,0 @@
#ifndef LVGL_API_H
#define LVGL_API_H
#ifdef __cplusplus
extern "C" {
#endif
#include "lvgl/lvgl.h"
lv_color_t lvsys_color_make(uint8_t r, uint8_t g, uint8_t b);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LVGL_API*/

26
lvgl-sys/shims/lvgl_sys.c Normal file
View file

@ -0,0 +1,26 @@
#include "lvgl_sys.h"
lv_color_t _LV_COLOR_MAKE(uint8_t r, uint8_t g, uint8_t b)
{
return LV_COLOR_MAKE(r, g, b);
}
uint16_t _LV_COLOR_GET_R(lv_color_t color)
{
return LV_COLOR_GET_R(color);
}
uint16_t _LV_COLOR_GET_G(lv_color_t color)
{
return LV_COLOR_GET_G(color);
}
uint16_t _LV_COLOR_GET_B(lv_color_t color)
{
return LV_COLOR_GET_B(color);
}
uint16_t _LV_COLOR_GET_A(lv_color_t color)
{
return LV_COLOR_GET_A(color);
}

21
lvgl-sys/shims/lvgl_sys.h Normal file
View file

@ -0,0 +1,21 @@
#ifndef LVGL_API_H
#define LVGL_API_H
#ifdef __cplusplus
extern "C" {
#endif
#include "lvgl/lvgl.h"
lv_color_t _LV_COLOR_MAKE(uint8_t r, uint8_t g, uint8_t b);
uint16_t _LV_COLOR_GET_R(lv_color_t color);
uint16_t _LV_COLOR_GET_G(lv_color_t color);
uint16_t _LV_COLOR_GET_B(lv_color_t color);
uint16_t _LV_COLOR_GET_A(lv_color_t color);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LVGL_API*/

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
pub mod bindings;
mod bindings;
pub use bindings::*;
#[cfg(test)]

View file

@ -1,16 +1,16 @@
use crate::objx::ObjectX;
use core::marker::PhantomData;
use core::mem::MaybeUninit;
use core::ptr;
use embedded_graphics;
use embedded_graphics::pixelcolor::raw::RawU16;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::{drawable, DrawTarget};
use core::mem::MaybeUninit;
use embedded_graphics::pixelcolor::Rgb888;
use core::marker::PhantomData;
pub struct DisplayDriver<'a, T>
where
T: DrawTarget<Rgb888>,
where
T: DrawTarget<Rgb565>,
{
raw: lvgl_sys::lv_disp_drv_t,
display_buffer: MaybeUninit<lvgl_sys::lv_disp_buf_t>,
@ -18,8 +18,9 @@ pub struct DisplayDriver<'a, T>
phantom: &'a PhantomData<T>,
}
impl<'a, T> DisplayDriver<'a, T> where
T: DrawTarget<Rgb888>
impl<'a, T> DisplayDriver<'a, T>
where
T: DrawTarget<Rgb565>,
{
pub fn new(device: &'a mut T) -> Self {
// Create a display buffer for LittlevGL
@ -71,28 +72,32 @@ unsafe extern "C" fn display_callback_wrapper<T>(
area: *const lvgl_sys::lv_area_t,
color_p: *mut lvgl_sys::lv_color_t,
) where
T: DrawTarget<Rgb888>,
T: DrawTarget<Rgb565>,
{
// We need to make sure panics can't escape across the FFI boundary.
//let _ = panic::catch_unwind(|| {
let mut i = 0;
let disp = *disp_drv;
//let _ = std::panic::catch_unwind(|| {
let mut i = 0;
let display_driver = *disp_drv;
// Rust code closure reference
let device = &mut *(disp.user_data as *mut T);
// Rust code closure reference
let device = &mut *(display_driver.user_data as *mut T);
for y in (*area).y1..=(*area).y2 {
for x in (*area).x1..=(*area).x2 {
// Convert C color representation to high-level Rust
let raw_color = *color_p.add(i);
i = i + 1;
let color = Rgb888::new(raw_color.ch.red, raw_color.ch.green, raw_color.ch.blue);
// Callback the Rust closure to flush the new points to the screen
let _ = device.draw_pixel(drawable::Pixel(Point::new(x as i32, y as i32), color));
}
for y in (*area).y1..=(*area).y2 {
for x in (*area).x1..=(*area).x2 {
let raw_color = *color_p.add(i);
i = i + 1;
// Convert Lvgl to embedded-graphics color
let color = Rgb565::new(
lvgl_sys::_LV_COLOR_GET_R(raw_color) as u8,
lvgl_sys::_LV_COLOR_GET_G(raw_color) as u8,
lvgl_sys::_LV_COLOR_GET_B(raw_color) as u8,
);
let _ = device.draw_pixel(drawable::Pixel(Point::new(x as i32, y as i32), color));
}
// Indicate to LittlevGL that you are ready with the flushing
lvgl_sys::lv_disp_flush_ready(disp_drv);
}
// Indicate to LittlevGL that you are ready with the flushing
lvgl_sys::lv_disp_flush_ready(disp_drv);
//}); // end of panic::catch_unwind
}

View file

@ -261,7 +261,7 @@ pub struct Color {
impl Color {
pub fn from_rgb((r, g, b): (u8, u8, u8)) -> Self {
let raw = unsafe { lvgl_sys::lvsys_color_make(r, g, b) };
let raw = unsafe { lvgl_sys::_LV_COLOR_MAKE(r, g, b) };
Self { raw }
}
}