From ad5a3deea4bbfdde9c4f29cba425cd36199a2d41 Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Sun, 14 Jun 2020 10:51:18 +0200 Subject: [PATCH] Fix types --- lvgl-codegen/Cargo.toml | 2 +- lvgl-codegen/src/lib.rs | 45 +++++++++++++++++++++-------------------- lvgl-sys/Cargo.toml | 2 +- lvgl/Cargo.toml | 8 ++++---- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lvgl-codegen/Cargo.toml b/lvgl-codegen/Cargo.toml index 489478b..adfed16 100644 --- a/lvgl-codegen/Cargo.toml +++ b/lvgl-codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lvgl-codegen" -version = "0.1.0" +version = "0.3.0" description = "Code generation based on LVGL source code" authors = ["Rafael Caricio "] edition = "2018" diff --git a/lvgl-codegen/src/lib.rs b/lvgl-codegen/src/lib.rs index 2a16a14..260761d 100644 --- a/lvgl-codegen/src/lib.rs +++ b/lvgl-codegen/src/lib.rs @@ -15,12 +15,11 @@ const LIB_PREFIX: &str = "lv_"; lazy_static! { static ref TYPE_MAPPINGS: HashMap<&'static str, &'static str> = [ - ("uint16_t", "u16"), - ("int32_t", "i32"), - ("uint8_t", "u8"), + ("u16", "u16"), + ("i32", "i32"), + ("u8", "u8"), ("bool", "bool"), - ("_Bool", "bool"), - ("const char *", "&str"), + ("* const cty :: c_char", "&str"), ] .iter() .cloned() @@ -329,7 +328,7 @@ impl LvType { } pub fn is_str(&self) -> bool { - self.literal_name.ends_with("char *") + self.literal_name.ends_with("* const cty :: c_char") } } @@ -527,12 +526,12 @@ mod test { #[test] fn generate_method_wrapper() { - // void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end); + // pub fn lv_arc_set_bg_end_angle(arc: *mut lv_obj_t, end: u16); let arc_set_bg_end_angle = LvFunc::new( "lv_arc_set_bg_end_angle".to_string(), vec![ - LvArg::new("arc".to_string(), LvType::new("lv_obj_t *".to_string())), - LvArg::new("end".to_string(), LvType::new("uint16_t".to_string())), + LvArg::new("arc".to_string(), LvType::new("*mut lv_obj_t".to_string())), + LvArg::new("end".to_string(), LvType::new("u16".to_string())), ], None, ); @@ -556,15 +555,17 @@ mod test { #[test] fn generate_method_wrapper_for_str_types_as_argument() { - // void lv_label_set_text(lv_obj_t * label, const char * text) - let label_set_text = LvFunc::new( - "lv_label_set_text".to_string(), - vec![ - LvArg::new("label".to_string(), LvType::new("lv_obj_t *".to_string())), - LvArg::new("text".to_string(), LvType::new("const char *".to_string())), - ], - None, - ); + let bindgen_code = quote! { + extern "C" { + #[doc = " Set a new text for a label. Memory will be allocated to store the text by the label."] + #[doc = " @param label pointer to a label object"] + #[doc = " @param text '\\0' terminated character string. NULL to refresh with the current text."] + pub fn lv_label_set_text(label: *mut lv_obj_t, text: *const cty::c_char); + } + }; + let cg = CodeGen::load_func_defs(bindgen_code.to_string().as_str()).unwrap(); + + let label_set_text = cg.get(0).unwrap().clone(); let parent_widget = LvWidget { name: "label".to_string(), methods: vec![], @@ -608,17 +609,17 @@ mod test { #[test] fn generate_widget_with_constructor_code() { - // lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); + // pub fn lv_arc_create(par: *mut lv_obj_t, copy: *const lv_obj_t) -> *mut lv_obj_t; let arc_create = LvFunc::new( "lv_arc_create".to_string(), vec![ - LvArg::new("par".to_string(), LvType::new("lv_obj_t *".to_string())), + LvArg::new("par".to_string(), LvType::new("*mut lv_obj_t".to_string())), LvArg::new( "copy".to_string(), - LvType::new("const lv_obj_t *".to_string()), + LvType::new("*const lv_obj_t".to_string()), ), ], - Some(LvType::new("lv_obj_t *".to_string())), + Some(LvType::new("*mut lv_obj_t".to_string())), ); let arc_widget = LvWidget { diff --git a/lvgl-sys/Cargo.toml b/lvgl-sys/Cargo.toml index b3a9479..6e1d72f 100644 --- a/lvgl-sys/Cargo.toml +++ b/lvgl-sys/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "lvgl-sys" description = "Raw bindings to the LittlevGL C library." -version = "0.2.0" +version = "0.3.0" authors = ["Rafael Caricio "] edition = "2018" license = "MIT" diff --git a/lvgl/Cargo.toml b/lvgl/Cargo.toml index 41778cf..b6c250e 100644 --- a/lvgl/Cargo.toml +++ b/lvgl/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "lvgl" description = "LittlevGL bindings for Rust. A powerful and easy-to-use embedded GUI with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash)." -version = "0.2.1" +version = "0.3.0" authors = ["Rafael Caricio "] edition = "2018" repository = "https://github.com/rafaelcaricio/lvgl-rs" @@ -12,7 +12,7 @@ keywords = ["littlevgl", "lvgl", "graphical_interfaces"] include = ["Cargo.toml", "src/**/*", "src/widgets/generated.rs"] [dependencies] -lvgl-sys = { path = "../lvgl-sys", version = "0.2.0" } +lvgl-sys = { version = "0.3.0", path = "../lvgl-sys" } cty = "0.2.1" embedded-graphics = "0.6.2" cstr_core = { version = "0.2.0", default-features = false, features = ["alloc"] } @@ -21,6 +21,6 @@ bitflags = "1.2.1" [build-dependencies] quote = "1.0.7" proc-macro2 = "1.0.18" -lvgl-codegen = { version = "0.1.0", path = "../lvgl-codegen" } -lvgl-sys = { path = "../lvgl-sys", version = "0.2.0" } +lvgl-codegen = { version = "0.3.0", path = "../lvgl-codegen" } +lvgl-sys = { version = "0.3.0", path = "../lvgl-sys" }