mirror of https://github.com/arendst/Tasmota.git
Merge pull request #13197 from s-hadinger/ctypes_simplification
Berry simplification of `ctypes`
This commit is contained in:
commit
0c1db2b6f2
|
@ -1,11 +1,9 @@
|
|||
/********************************************************************
|
||||
* Tasmota LVGL ctypes mapping
|
||||
* Tasmota ctypes mapping
|
||||
*******************************************************************/
|
||||
#include "be_constobj.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_LVGL
|
||||
|
||||
#include "lvgl.h"
|
||||
extern __attribute__((noreturn)) void be_raisef(bvm *vm, const char *except, const char *msg, ...);
|
||||
|
||||
// binary search within an array of sorted strings
|
||||
|
@ -68,6 +66,7 @@ typedef struct be_ctypes_structure_item_t {
|
|||
typedef struct be_ctypes_structure_t {
|
||||
uint16_t size_bytes; /* size in bytes */
|
||||
uint16_t size_elt; /* number of elements */
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_structure_item_t * items;
|
||||
} be_ctypes_structure_t;
|
||||
|
||||
|
@ -97,14 +96,6 @@ int be_ctypes_init(bvm *vm) {
|
|||
src_data = (void*) be_toint(vm, 2);
|
||||
}
|
||||
|
||||
// get global array of classes from global variable '.ctypes_classes'
|
||||
be_getglobal(vm, ".ctypes_classes");
|
||||
const be_ctypes_classes_t * be_ctypes_classes = (const be_ctypes_classes_t *) be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
// berry_log_C("be_ctypes_init> be_ctypes_class = %p", be_ctypes_classes);
|
||||
const char * class_name = be_classname(vm, 1);
|
||||
// berry_log_C("be_ctypes_init> class_name = %s", class_name);
|
||||
|
||||
// call super(self, bytes)
|
||||
be_getglobal(vm, "super"); // push super function
|
||||
be_pushvalue(vm, 1); // push self instance
|
||||
|
@ -121,16 +112,10 @@ int be_ctypes_init(bvm *vm) {
|
|||
// berry_log_C("be_ctypes_init> init called");
|
||||
|
||||
// look for class definition
|
||||
int32_t class_idx = bin_search_ctypes(class_name, &be_ctypes_classes->classes[0], sizeof(be_ctypes_class_t), be_ctypes_classes->size);
|
||||
if (class_idx >= 0) {
|
||||
// found
|
||||
const be_ctypes_structure_t * definitions = be_ctypes_classes->classes[class_idx].definitions;
|
||||
// store definition in '.def'
|
||||
// berry_log_C("Found definitions = %p", definitions);
|
||||
be_pushcomptr(vm, (void*) definitions);
|
||||
be_setmember(vm, 1, ".def");
|
||||
be_pop(vm, 1);
|
||||
|
||||
be_getmember(vm, 1, "_def"); // static class comptr
|
||||
const be_ctypes_structure_t *definitions;
|
||||
definitions = (const be_ctypes_structure_t *) be_tocomptr(vm, -1);
|
||||
if (definitions) {
|
||||
// call self.resize(definitions->size_bytes)
|
||||
be_getmember(vm, 1, "resize");
|
||||
be_pushvalue(vm, 1);
|
||||
|
@ -167,9 +152,13 @@ int be_ctypes_copy(bvm *vm) {
|
|||
be_return(vm);
|
||||
}
|
||||
|
||||
// get an attribute from a ctypes structure
|
||||
// arg1: ctypes instance
|
||||
// arg2: name of the argument
|
||||
// The class has a `_def` static class attribute with the C low-level mapping definition
|
||||
int be_ctypes_member(bvm *vm) {
|
||||
int argc = be_top(vm);
|
||||
be_getmember(vm, 1, ".def");
|
||||
be_getmember(vm, 1, "_def");
|
||||
const be_ctypes_structure_t *definitions;
|
||||
definitions = (const be_ctypes_structure_t *) be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
|
@ -194,14 +183,14 @@ int be_ctypes_member(bvm *vm) {
|
|||
} else {
|
||||
// general int support
|
||||
int size = member->type; // eventually 1/2/4, positive if little endian, negative if big endian
|
||||
int sign = false; // signed int
|
||||
int sign = bfalse; // signed int
|
||||
if (size >= ctypes_i8) {
|
||||
size -= ctypes_i8 - 1;
|
||||
sign = true;
|
||||
sign = btrue;
|
||||
}
|
||||
if (size <= ctypes_be_i8) {
|
||||
size += ctypes_be_i8 - 1;
|
||||
sign = true;
|
||||
sign = btrue;
|
||||
}
|
||||
// get
|
||||
be_getmember(vm, 1, sign ? "geti" : "get"); // self.get or self.geti
|
||||
|
@ -215,14 +204,7 @@ int be_ctypes_member(bvm *vm) {
|
|||
// the int result is at top of the stack
|
||||
// check if we need an instance mapping
|
||||
if (member->mapping > 0) {
|
||||
// find the name of the class
|
||||
|
||||
// get global array of classes from global variable '.ctypes_classes'
|
||||
be_getglobal(vm, ".ctypes_classes");
|
||||
const be_ctypes_classes_t * be_ctypes_classes = (const be_ctypes_classes_t *) be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
|
||||
const char * mapping_name = be_ctypes_classes->instance_mapping[member->mapping - 1];
|
||||
const char * mapping_name = definitions->instance_mapping[member->mapping - 1];
|
||||
if (mapping_name) {
|
||||
be_getglobal(vm, mapping_name); // stack: class
|
||||
be_pushvalue(vm, -2); // stack: class, value
|
||||
|
@ -267,7 +249,7 @@ int be_ctypes_setmember(bvm *vm) {
|
|||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
be_getmember(vm, 1, ".def");
|
||||
be_getmember(vm, 1, "_def");
|
||||
const be_ctypes_structure_t *definitions;
|
||||
definitions = (const be_ctypes_structure_t *) be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
|
@ -293,14 +275,14 @@ int be_ctypes_setmember(bvm *vm) {
|
|||
} else {
|
||||
// general int support
|
||||
int size = member->type; // eventually 1/2/4, positive if little endian, negative if big endian
|
||||
int sign = false; // signed int
|
||||
int sign = bfalse; // signed int
|
||||
if (size >= ctypes_i8) {
|
||||
size -= ctypes_i8 - 1;
|
||||
sign = true;
|
||||
sign = btrue;
|
||||
}
|
||||
if (size <= ctypes_be_i8) {
|
||||
size += ctypes_be_i8 - 1;
|
||||
sign = true;
|
||||
sign = btrue;
|
||||
}
|
||||
// set
|
||||
be_getmember(vm, 1, sign ? "seti" : "set"); // self.get or self.geti
|
||||
|
@ -320,22 +302,20 @@ int be_ctypes_setmember(bvm *vm) {
|
|||
|
||||
BE_EXPORT_VARIABLE extern const bclass be_class_bytes;
|
||||
|
||||
#include "../generate/be_fixed_be_class_lv_ctypes.h"
|
||||
#include "../generate/be_fixed_be_class_ctypes.h"
|
||||
|
||||
void be_load_lvgl_ctypes_lib(bvm *vm) {
|
||||
be_pushntvclass(vm, &be_class_lv_ctypes);
|
||||
void be_load_ctypes_lib(bvm *vm) {
|
||||
be_pushntvclass(vm, &be_class_ctypes);
|
||||
be_setglobal(vm, "ctypes_bytes");
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
/* @const_object_info_begin
|
||||
class be_class_lv_ctypes (scope: global, name: ctypes_bytes, super: be_class_bytes) {
|
||||
.def, var
|
||||
class be_class_ctypes (scope: global, name: ctypes_bytes, super: be_class_bytes) {
|
||||
_def, nil()
|
||||
copy, func(be_ctypes_copy)
|
||||
init, func(be_ctypes_init)
|
||||
member, func(be_ctypes_member)
|
||||
setmember, func(be_ctypes_setmember)
|
||||
}
|
||||
@const_object_info_end */
|
||||
|
||||
#endif // USE_LVGL
|
|
@ -42,6 +42,7 @@ typedef struct be_ctypes_structure_item_t {
|
|||
typedef struct be_ctypes_structure_t {
|
||||
uint16_t size_bytes; /* size in bytes */
|
||||
uint16_t size_elt; /* number of elements */
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_structure_item_t * items;
|
||||
} be_ctypes_structure_t;
|
||||
|
||||
|
@ -56,7 +57,7 @@ typedef struct be_ctypes_classes_t {
|
|||
const be_ctypes_class_t * classes;
|
||||
} be_ctypes_classes_t;
|
||||
|
||||
BE_EXPORT_VARIABLE extern const bclass be_class_lv_ctypes;
|
||||
BE_EXPORT_VARIABLE extern const bclass be_class_ctypes;
|
||||
|
||||
void ctypes_register_class(bvm *vm, const bclass * ctypes_class, const be_ctypes_structure_t * definitions) {
|
||||
be_pushntvclass(vm, ctypes_class);
|
||||
|
@ -64,10 +65,26 @@ void ctypes_register_class(bvm *vm, const bclass * ctypes_class, const be_ctypes
|
|||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
const char * be_ctypes_instance_mappings[]; /* forward definition */
|
||||
|
||||
// Define a sub-class of ctypes with only one member which points to the ctypes defintion
|
||||
#define be_define_ctypes_class(_c_name, _def, _super, _name) \
|
||||
be_local_class(_c_name, \
|
||||
0, \
|
||||
_super, \
|
||||
be_nested_map(1, \
|
||||
( (struct bmapnode*) &(const bmapnode[]) { \
|
||||
{ be_nested_key("_def", 1985022181, 4, -1), be_const_comptr(_def) },\
|
||||
})), \
|
||||
(be_nested_const_str(_name, 0, sizeof(_name)-1)) \
|
||||
)
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
const be_ctypes_structure_t be_lv_point = {
|
||||
4, /* size in bytes */
|
||||
2, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[2]) {
|
||||
{ "x", 0, 0, 0, 12, 0 },
|
||||
{ "y", 2, 0, 0, 12, 0 },
|
||||
|
@ -76,6 +93,7 @@ const be_ctypes_structure_t be_lv_point = {
|
|||
const be_ctypes_structure_t be_lv_area = {
|
||||
8, /* size in bytes */
|
||||
4, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[4]) {
|
||||
{ "x1", 0, 0, 0, 12, 0 },
|
||||
{ "x2", 4, 0, 0, 12, 0 },
|
||||
|
@ -86,6 +104,7 @@ const be_ctypes_structure_t be_lv_area = {
|
|||
const be_ctypes_structure_t be_lv_draw_rect_dsc = {
|
||||
77, /* size in bytes */
|
||||
43, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[43]) {
|
||||
{ "bg_blend_mode", 12, 0, 0, 1, 0 },
|
||||
{ "bg_color", 2, 0, 0, 2, 1 },
|
||||
|
@ -135,6 +154,7 @@ const be_ctypes_structure_t be_lv_draw_rect_dsc = {
|
|||
const be_ctypes_structure_t be_lv_draw_line_dsc = {
|
||||
10, /* size in bytes */
|
||||
9, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[9]) {
|
||||
{ "blend_mode", 9, 0, 2, 0, 0 },
|
||||
{ "color", 0, 0, 0, 2, 1 },
|
||||
|
@ -150,6 +170,7 @@ const be_ctypes_structure_t be_lv_draw_line_dsc = {
|
|||
const be_ctypes_structure_t be_lv_draw_img_dsc = {
|
||||
14, /* size in bytes */
|
||||
9, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[9]) {
|
||||
{ "angle", 1, 0, 0, 2, 0 },
|
||||
{ "antialias", 13, 0, 1, 0, 0 },
|
||||
|
@ -165,6 +186,7 @@ const be_ctypes_structure_t be_lv_draw_img_dsc = {
|
|||
const be_ctypes_structure_t be_lv_draw_label_dsc = {
|
||||
31, /* size in bytes */
|
||||
15, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[15]) {
|
||||
{ "bidi_dir", 27, 0, 0, 1, 0 },
|
||||
{ "blend_mode", 30, 0, 0, 1, 0 },
|
||||
|
@ -186,6 +208,7 @@ const be_ctypes_structure_t be_lv_draw_label_dsc = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_common_dsc = {
|
||||
5, /* size in bytes */
|
||||
2, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[2]) {
|
||||
{ "cb", 0, 0, 0, 4, 0 },
|
||||
{ "type", 4, 0, 0, 1, 0 },
|
||||
|
@ -194,6 +217,7 @@ const be_ctypes_structure_t be_lv_draw_mask_common_dsc = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_line_param_cfg = {
|
||||
9, /* size in bytes */
|
||||
5, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[5]) {
|
||||
{ "p1_x", 0, 0, 0, 12, 0 },
|
||||
{ "p1_y", 2, 0, 0, 12, 0 },
|
||||
|
@ -205,6 +229,7 @@ const be_ctypes_structure_t be_lv_draw_mask_line_param_cfg = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_line_param = {
|
||||
35, /* size in bytes */
|
||||
15, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[15]) {
|
||||
{ "cfg_p1_x", 5, 0, 0, 12, 0 },
|
||||
{ "cfg_p1_y", 7, 0, 0, 12, 0 },
|
||||
|
@ -226,6 +251,7 @@ const be_ctypes_structure_t be_lv_draw_mask_line_param = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_angle_param_cfg = {
|
||||
8, /* size in bytes */
|
||||
4, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[4]) {
|
||||
{ "end_angle", 6, 0, 0, 12, 0 },
|
||||
{ "start_angle", 4, 0, 0, 12, 0 },
|
||||
|
@ -236,6 +262,7 @@ const be_ctypes_structure_t be_lv_draw_mask_angle_param_cfg = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_angle_param = {
|
||||
85, /* size in bytes */
|
||||
37, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[37]) {
|
||||
{ "cfg_end_angle", 11, 0, 0, 12, 0 },
|
||||
{ "cfg_start_angle", 9, 0, 0, 12, 0 },
|
||||
|
@ -279,6 +306,7 @@ const be_ctypes_structure_t be_lv_draw_mask_angle_param = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_radius_param_cfg = {
|
||||
11, /* size in bytes */
|
||||
6, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[6]) {
|
||||
{ "outer", 10, 0, 1, 0, 0 },
|
||||
{ "radius", 8, 0, 0, 12, 0 },
|
||||
|
@ -291,6 +319,7 @@ const be_ctypes_structure_t be_lv_draw_mask_radius_param_cfg = {
|
|||
const be_ctypes_structure_t be_lv_sqrt_res = {
|
||||
4, /* size in bytes */
|
||||
2, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[2]) {
|
||||
{ "f", 2, 0, 0, 2, 0 },
|
||||
{ "i", 0, 0, 0, 2, 0 },
|
||||
|
@ -299,6 +328,7 @@ const be_ctypes_structure_t be_lv_sqrt_res = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_radius_param = {
|
||||
24, /* size in bytes */
|
||||
11, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[11]) {
|
||||
{ "cfg_outer", 15, 0, 1, 0, 0 },
|
||||
{ "cfg_radius", 13, 0, 0, 12, 0 },
|
||||
|
@ -316,6 +346,7 @@ const be_ctypes_structure_t be_lv_draw_mask_radius_param = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_fade_param_cfg = {
|
||||
14, /* size in bytes */
|
||||
8, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[8]) {
|
||||
{ "coords_x1", 0, 0, 0, 12, 0 },
|
||||
{ "coords_x2", 4, 0, 0, 12, 0 },
|
||||
|
@ -330,6 +361,7 @@ const be_ctypes_structure_t be_lv_draw_mask_fade_param_cfg = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_fade_param = {
|
||||
19, /* size in bytes */
|
||||
10, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[10]) {
|
||||
{ "cfg_coords_x1", 5, 0, 0, 12, 0 },
|
||||
{ "cfg_coords_x2", 9, 0, 0, 12, 0 },
|
||||
|
@ -346,6 +378,7 @@ const be_ctypes_structure_t be_lv_draw_mask_fade_param = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_map_param_cfg = {
|
||||
12, /* size in bytes */
|
||||
5, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[5]) {
|
||||
{ "coords_x1", 0, 0, 0, 12, 0 },
|
||||
{ "coords_x2", 4, 0, 0, 12, 0 },
|
||||
|
@ -357,6 +390,7 @@ const be_ctypes_structure_t be_lv_draw_mask_map_param_cfg = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_map_param = {
|
||||
17, /* size in bytes */
|
||||
7, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[7]) {
|
||||
{ "cfg_coords_x1", 5, 0, 0, 12, 0 },
|
||||
{ "cfg_coords_x2", 9, 0, 0, 12, 0 },
|
||||
|
@ -370,6 +404,7 @@ const be_ctypes_structure_t be_lv_draw_mask_map_param = {
|
|||
const be_ctypes_structure_t be_lv_draw_mask_saved = {
|
||||
8, /* size in bytes */
|
||||
2, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[2]) {
|
||||
{ "custom_id", 4, 0, 0, 4, 0 },
|
||||
{ "param", 0, 0, 0, 4, 0 },
|
||||
|
@ -380,97 +415,45 @@ const char * be_ctypes_instance_mappings[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
const be_ctypes_classes_t be_ctypes_classes[] = {
|
||||
19,
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_class_t[19]) {
|
||||
{ "lv_area", &be_lv_area },
|
||||
{ "lv_draw_img_dsc", &be_lv_draw_img_dsc },
|
||||
{ "lv_draw_label_dsc", &be_lv_draw_label_dsc },
|
||||
{ "lv_draw_line_dsc", &be_lv_draw_line_dsc },
|
||||
{ "lv_draw_mask_angle_param", &be_lv_draw_mask_angle_param },
|
||||
{ "lv_draw_mask_angle_param_cfg", &be_lv_draw_mask_angle_param_cfg },
|
||||
{ "lv_draw_mask_common_dsc", &be_lv_draw_mask_common_dsc },
|
||||
{ "lv_draw_mask_fade_param", &be_lv_draw_mask_fade_param },
|
||||
{ "lv_draw_mask_fade_param_cfg", &be_lv_draw_mask_fade_param_cfg },
|
||||
{ "lv_draw_mask_line_param", &be_lv_draw_mask_line_param },
|
||||
{ "lv_draw_mask_line_param_cfg", &be_lv_draw_mask_line_param_cfg },
|
||||
{ "lv_draw_mask_map_param", &be_lv_draw_mask_map_param },
|
||||
{ "lv_draw_mask_map_param_cfg", &be_lv_draw_mask_map_param_cfg },
|
||||
{ "lv_draw_mask_radius_param", &be_lv_draw_mask_radius_param },
|
||||
{ "lv_draw_mask_radius_param_cfg", &be_lv_draw_mask_radius_param_cfg },
|
||||
{ "lv_draw_mask_saved", &be_lv_draw_mask_saved },
|
||||
{ "lv_draw_rect_dsc", &be_lv_draw_rect_dsc },
|
||||
{ "lv_point", &be_lv_point },
|
||||
{ "lv_sqrt_res", &be_lv_sqrt_res },
|
||||
}};
|
||||
|
||||
/* @const_object_info_begin
|
||||
class be_class_ctypes_classes (scope: global) {
|
||||
lv_area, int(0)
|
||||
lv_draw_img_dsc, int(0)
|
||||
lv_draw_label_dsc, int(0)
|
||||
lv_draw_line_dsc, int(0)
|
||||
lv_draw_mask_angle_param, int(0)
|
||||
lv_draw_mask_angle_param_cfg, int(0)
|
||||
lv_draw_mask_common_dsc, int(0)
|
||||
lv_draw_mask_fade_param, int(0)
|
||||
lv_draw_mask_fade_param_cfg, int(0)
|
||||
lv_draw_mask_line_param, int(0)
|
||||
lv_draw_mask_line_param_cfg, int(0)
|
||||
lv_draw_mask_map_param, int(0)
|
||||
lv_draw_mask_map_param_cfg, int(0)
|
||||
lv_draw_mask_radius_param, int(0)
|
||||
lv_draw_mask_radius_param_cfg, int(0)
|
||||
lv_draw_mask_saved, int(0)
|
||||
lv_draw_rect_dsc, int(0)
|
||||
lv_point, int(0)
|
||||
lv_sqrt_res, int(0)
|
||||
}
|
||||
@const_object_info_end */
|
||||
static be_define_ctypes_class(lv_area, &be_lv_area, &be_class_ctypes, "lv_area");
|
||||
static be_define_ctypes_class(lv_draw_img_dsc, &be_lv_draw_img_dsc, &be_class_ctypes, "lv_draw_img_dsc");
|
||||
static be_define_ctypes_class(lv_draw_label_dsc, &be_lv_draw_label_dsc, &be_class_ctypes, "lv_draw_label_dsc");
|
||||
static be_define_ctypes_class(lv_draw_line_dsc, &be_lv_draw_line_dsc, &be_class_ctypes, "lv_draw_line_dsc");
|
||||
static be_define_ctypes_class(lv_draw_mask_angle_param, &be_lv_draw_mask_angle_param, &be_class_ctypes, "lv_draw_mask_angle_param");
|
||||
static be_define_ctypes_class(lv_draw_mask_angle_param_cfg, &be_lv_draw_mask_angle_param_cfg, &be_class_ctypes, "lv_draw_mask_angle_param_cfg");
|
||||
static be_define_ctypes_class(lv_draw_mask_common_dsc, &be_lv_draw_mask_common_dsc, &be_class_ctypes, "lv_draw_mask_common_dsc");
|
||||
static be_define_ctypes_class(lv_draw_mask_fade_param, &be_lv_draw_mask_fade_param, &be_class_ctypes, "lv_draw_mask_fade_param");
|
||||
static be_define_ctypes_class(lv_draw_mask_fade_param_cfg, &be_lv_draw_mask_fade_param_cfg, &be_class_ctypes, "lv_draw_mask_fade_param_cfg");
|
||||
static be_define_ctypes_class(lv_draw_mask_line_param, &be_lv_draw_mask_line_param, &be_class_ctypes, "lv_draw_mask_line_param");
|
||||
static be_define_ctypes_class(lv_draw_mask_line_param_cfg, &be_lv_draw_mask_line_param_cfg, &be_class_ctypes, "lv_draw_mask_line_param_cfg");
|
||||
static be_define_ctypes_class(lv_draw_mask_map_param, &be_lv_draw_mask_map_param, &be_class_ctypes, "lv_draw_mask_map_param");
|
||||
static be_define_ctypes_class(lv_draw_mask_map_param_cfg, &be_lv_draw_mask_map_param_cfg, &be_class_ctypes, "lv_draw_mask_map_param_cfg");
|
||||
static be_define_ctypes_class(lv_draw_mask_radius_param, &be_lv_draw_mask_radius_param, &be_class_ctypes, "lv_draw_mask_radius_param");
|
||||
static be_define_ctypes_class(lv_draw_mask_radius_param_cfg, &be_lv_draw_mask_radius_param_cfg, &be_class_ctypes, "lv_draw_mask_radius_param_cfg");
|
||||
static be_define_ctypes_class(lv_draw_mask_saved, &be_lv_draw_mask_saved, &be_class_ctypes, "lv_draw_mask_saved");
|
||||
static be_define_ctypes_class(lv_draw_rect_dsc, &be_lv_draw_rect_dsc, &be_class_ctypes, "lv_draw_rect_dsc");
|
||||
static be_define_ctypes_class(lv_point, &be_lv_point, &be_class_ctypes, "lv_point");
|
||||
static be_define_ctypes_class(lv_sqrt_res, &be_lv_sqrt_res, &be_class_ctypes, "lv_sqrt_res");
|
||||
|
||||
void be_load_ctypes_definitions_lib(bvm *vm) {
|
||||
be_pushcomptr(vm, (void*) be_ctypes_classes);
|
||||
be_setglobal(vm, ".ctypes_classes");
|
||||
be_pop(vm, 1);
|
||||
|
||||
static be_define_const_empty_class(be_class_lv_area, &be_class_lv_ctypes, lv_area);
|
||||
ctypes_register_class(vm, &be_class_lv_area, &be_lv_area);
|
||||
static be_define_const_empty_class(be_class_lv_draw_img_dsc, &be_class_lv_ctypes, lv_draw_img_dsc);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_img_dsc, &be_lv_draw_img_dsc);
|
||||
static be_define_const_empty_class(be_class_lv_draw_label_dsc, &be_class_lv_ctypes, lv_draw_label_dsc);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_label_dsc, &be_lv_draw_label_dsc);
|
||||
static be_define_const_empty_class(be_class_lv_draw_line_dsc, &be_class_lv_ctypes, lv_draw_line_dsc);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_line_dsc, &be_lv_draw_line_dsc);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_angle_param, &be_class_lv_ctypes, lv_draw_mask_angle_param);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_angle_param, &be_lv_draw_mask_angle_param);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_angle_param_cfg, &be_class_lv_ctypes, lv_draw_mask_angle_param_cfg);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_angle_param_cfg, &be_lv_draw_mask_angle_param_cfg);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_common_dsc, &be_class_lv_ctypes, lv_draw_mask_common_dsc);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_common_dsc, &be_lv_draw_mask_common_dsc);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_fade_param, &be_class_lv_ctypes, lv_draw_mask_fade_param);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_fade_param, &be_lv_draw_mask_fade_param);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_fade_param_cfg, &be_class_lv_ctypes, lv_draw_mask_fade_param_cfg);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_fade_param_cfg, &be_lv_draw_mask_fade_param_cfg);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_line_param, &be_class_lv_ctypes, lv_draw_mask_line_param);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_line_param, &be_lv_draw_mask_line_param);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_line_param_cfg, &be_class_lv_ctypes, lv_draw_mask_line_param_cfg);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_line_param_cfg, &be_lv_draw_mask_line_param_cfg);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_map_param, &be_class_lv_ctypes, lv_draw_mask_map_param);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_map_param, &be_lv_draw_mask_map_param);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_map_param_cfg, &be_class_lv_ctypes, lv_draw_mask_map_param_cfg);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_map_param_cfg, &be_lv_draw_mask_map_param_cfg);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_radius_param, &be_class_lv_ctypes, lv_draw_mask_radius_param);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_radius_param, &be_lv_draw_mask_radius_param);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_radius_param_cfg, &be_class_lv_ctypes, lv_draw_mask_radius_param_cfg);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_radius_param_cfg, &be_lv_draw_mask_radius_param_cfg);
|
||||
static be_define_const_empty_class(be_class_lv_draw_mask_saved, &be_class_lv_ctypes, lv_draw_mask_saved);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_mask_saved, &be_lv_draw_mask_saved);
|
||||
static be_define_const_empty_class(be_class_lv_draw_rect_dsc, &be_class_lv_ctypes, lv_draw_rect_dsc);
|
||||
ctypes_register_class(vm, &be_class_lv_draw_rect_dsc, &be_lv_draw_rect_dsc);
|
||||
static be_define_const_empty_class(be_class_lv_point, &be_class_lv_ctypes, lv_point);
|
||||
ctypes_register_class(vm, &be_class_lv_point, &be_lv_point);
|
||||
static be_define_const_empty_class(be_class_lv_sqrt_res, &be_class_lv_ctypes, lv_sqrt_res);
|
||||
ctypes_register_class(vm, &be_class_lv_sqrt_res, &be_lv_sqrt_res);
|
||||
}
|
||||
/********************************************************************/
|
||||
|
|
|
@ -114,6 +114,8 @@ extern void be_load_md5_lib(bvm *vm);
|
|||
extern void be_load_webclient_lib(bvm *vm);
|
||||
extern void be_load_crypto_lib(bvm *vm);
|
||||
|
||||
extern void be_load_ctypes_lib(bvm *vm);
|
||||
|
||||
#ifdef USE_I2S_AUDIO_BERRY
|
||||
extern void be_load_driver_audio_lib(bvm *vm);
|
||||
#endif
|
||||
|
@ -124,7 +126,6 @@ extern void be_load_lvgl_font_lib(bvm *vm);
|
|||
extern void be_load_lv_all_lib(bvm *vm);
|
||||
extern void be_load_lvgl_cb_lib(bvm *vm);
|
||||
extern void be_load_lvgl_cb_all_lib(bvm *vm);
|
||||
extern void be_load_lvgl_ctypes_lib(bvm *vm);
|
||||
extern void be_load_ctypes_definitions_lib(bvm *vm);
|
||||
// custom widgets
|
||||
extern void be_load_lv_signal_bars_class(bvm *vm);
|
||||
|
@ -150,6 +151,7 @@ BERRY_API void be_load_custom_libs(bvm *vm)
|
|||
be_load_Driver_class(vm);
|
||||
be_load_md5_lib(vm);
|
||||
be_load_serial_lib(vm);
|
||||
be_load_ctypes_lib(vm);
|
||||
#ifdef USE_ALEXA_AVS
|
||||
be_load_crypto_lib(vm);
|
||||
#endif
|
||||
|
@ -175,7 +177,6 @@ BERRY_API void be_load_custom_libs(bvm *vm)
|
|||
be_load_lv_all_lib(vm);
|
||||
be_load_lvgl_cb_lib(vm);
|
||||
be_load_lvgl_cb_all_lib(vm);
|
||||
be_load_lvgl_ctypes_lib(vm);
|
||||
be_load_ctypes_definitions_lib(vm);
|
||||
// custom widgets
|
||||
be_load_lv_signal_bars_class(vm);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,21 +1,21 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_lv_ctypes_map) {
|
||||
static be_define_const_map_slots(be_class_ctypes_map) {
|
||||
{ be_const_key(init, -1), be_const_func(be_ctypes_init) },
|
||||
{ be_const_key(setmember, 2), be_const_func(be_ctypes_setmember) },
|
||||
{ be_const_key(_def, 3), be_const_nil() },
|
||||
{ be_const_key(member, -1), be_const_func(be_ctypes_member) },
|
||||
{ be_const_key(dot_def, -1), be_const_var(0) },
|
||||
{ be_const_key(copy, -1), be_const_func(be_ctypes_copy) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_lv_ctypes_map,
|
||||
be_class_ctypes_map,
|
||||
5
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_lv_ctypes,
|
||||
1,
|
||||
be_class_ctypes,
|
||||
0,
|
||||
(bclass *)&be_class_bytes,
|
||||
ctypes_bytes
|
||||
);
|
|
@ -1,35 +0,0 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_ctypes_classes_map) {
|
||||
{ be_const_key(lv_draw_mask_radius_param_cfg, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_img_dsc, 14), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_radius_param, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_point, 4), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_fade_param_cfg, 5), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_map_param, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_label_dsc, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_area, 17), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_angle_param_cfg, 3), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_line_param_cfg, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_saved, 12), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_map_param_cfg, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_rect_dsc, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_angle_param, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_line_dsc, 15), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_common_dsc, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_line_param, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_sqrt_res, -1), be_const_int(0) },
|
||||
{ be_const_key(lv_draw_mask_fade_param, 13), be_const_int(0) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_ctypes_classes_map,
|
||||
19
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_ctypes_classes,
|
||||
0,
|
||||
NULL,
|
||||
be_class_ctypes_classes
|
||||
);
|
|
@ -231,6 +231,8 @@ static int l_int(bvm *vm)
|
|||
be_pushint(vm, (bint)be_toreal(vm, 1));
|
||||
} else if (be_isint(vm, 1)) {
|
||||
be_pushvalue(vm, 1);
|
||||
} else if (be_iscomptr(vm, 1)) {
|
||||
be_pushint(vm, (int) be_tocomptr(vm, 1));
|
||||
} else {
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
|
|
@ -72,6 +72,11 @@ extern "C" {
|
|||
.type = BE_STRING \
|
||||
}
|
||||
|
||||
#define be_const_comptr(_val) { \
|
||||
.v.p = (void*)(_val), \
|
||||
.type = BE_COMPTR \
|
||||
}
|
||||
|
||||
#define be_const_class(_class) { \
|
||||
.v.c = &(_class), \
|
||||
.type = BE_CLASS \
|
||||
|
@ -218,6 +223,11 @@ const bntvmodule be_native_module(_module) = { \
|
|||
BE_REAL \
|
||||
}
|
||||
|
||||
#define be_const_comptr(_val) { \
|
||||
bvaldata((void*)(_val)), \
|
||||
BE_COMPTR \
|
||||
}
|
||||
|
||||
#define be_const_str(_string) { \
|
||||
bvaldata(bstring(_string)), \
|
||||
BE_STRING \
|
||||
|
|
|
@ -86,6 +86,9 @@ static int m_toptr(bvm *vm)
|
|||
if (var_basetype(v) >= BE_GCOBJECT) {
|
||||
be_pushcomptr(vm, var_toobj(v));
|
||||
be_return(vm);
|
||||
} else if (var_type(v) == BE_INT) {
|
||||
be_pushcomptr(vm, (void*) var_toint(v));
|
||||
be_return(vm);
|
||||
} else {
|
||||
be_raise(vm, "value_error", "unsupported for this type");
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ ctypes.bf_12 = 112
|
|||
ctypes.bf_13 = 113
|
||||
ctypes.bf_14 = 114
|
||||
ctypes.bf_15 = 115
|
||||
ctypes.bf_16 = 116
|
||||
|
||||
def findinlist(l, x)
|
||||
for i:0..size(l)-1
|
||||
|
@ -193,6 +194,7 @@ ctypes.print_types = def ()
|
|||
print("typedef struct be_ctypes_structure_t {")
|
||||
print(" uint16_t size_bytes; /* size in bytes */")
|
||||
print(" uint16_t size_elt; /* number of elements */")
|
||||
print(" const char **instance_mapping; /* array of instance class names for automatic instanciation of class */")
|
||||
print(" const be_ctypes_structure_item_t * items;")
|
||||
print("} be_ctypes_structure_t;")
|
||||
print()
|
||||
|
@ -207,7 +209,7 @@ ctypes.print_types = def ()
|
|||
print(" const be_ctypes_class_t * classes;")
|
||||
print("} be_ctypes_classes_t;")
|
||||
print()
|
||||
print("BE_EXPORT_VARIABLE extern const bclass be_class_lv_ctypes;")
|
||||
print("BE_EXPORT_VARIABLE extern const bclass be_class_ctypes;")
|
||||
print()
|
||||
print("void ctypes_register_class(bvm *vm, const bclass * ctypes_class, const be_ctypes_structure_t * definitions) {")
|
||||
print(" be_pushntvclass(vm, ctypes_class);")
|
||||
|
@ -215,7 +217,23 @@ ctypes.print_types = def ()
|
|||
print(" be_pop(vm, 1);")
|
||||
print("}")
|
||||
print()
|
||||
print("const char * be_ctypes_instance_mappings[]; /* forward definition */")
|
||||
print()
|
||||
|
||||
print("// Define a sub-class of ctypes with only one member which points to the ctypes defintion")
|
||||
print("#define be_define_ctypes_class(_c_name, _def, _super, _name) \\")
|
||||
print(" be_local_class(_c_name, \\")
|
||||
print(" 0, \\")
|
||||
print(" _super, \\")
|
||||
print(" be_nested_map(1, \\")
|
||||
print(" ( (struct bmapnode*) &(const bmapnode[]) { \\")
|
||||
print(" { be_nested_key(\"_def\", 1985022181, 4, -1), be_const_comptr(_def) },\\")
|
||||
print(" })), \\")
|
||||
print(" (be_nested_const_str(_name, 0, sizeof(_name)-1)) \\")
|
||||
print(" )")
|
||||
print()
|
||||
print("/********************************************************************/")
|
||||
print()
|
||||
end
|
||||
|
||||
global_classes = [] # track the list of all classes and
|
||||
|
@ -236,33 +254,13 @@ ctypes.print_classes = def ()
|
|||
|
||||
ctypes.sort(global_classes)
|
||||
|
||||
print("const be_ctypes_classes_t be_ctypes_classes[] = {")
|
||||
print(string.format(" %i,", size(global_classes)))
|
||||
print(string.format(" be_ctypes_instance_mappings,"))
|
||||
print(string.format(" (const be_ctypes_class_t[%i]) {", size(global_classes)))
|
||||
|
||||
for elt:global_classes
|
||||
print(string.format(" { \"%s\", &be_%s },", elt, elt))
|
||||
print(string.format("static be_define_ctypes_class(%s, &be_%s, &be_class_ctypes, \"%s\");", elt, elt, elt))
|
||||
end
|
||||
|
||||
print("}};")
|
||||
print()
|
||||
print("/* @const_object_info_begin")
|
||||
print("class be_class_ctypes_classes (scope: global) {")
|
||||
for elt:global_classes
|
||||
print(string.format(" %s, int(0)", elt))
|
||||
end
|
||||
print("}")
|
||||
print("@const_object_info_end */")
|
||||
print()
|
||||
|
||||
print("void be_load_ctypes_definitions_lib(bvm *vm) {")
|
||||
print(" be_pushcomptr(vm, (void*) be_ctypes_classes);")
|
||||
print(" be_setglobal(vm, \".ctypes_classes\");")
|
||||
print(" be_pop(vm, 1);")
|
||||
print()
|
||||
for elt:global_classes
|
||||
print(string.format(" static be_define_const_empty_class(be_class_%s, &be_class_lv_ctypes, %s);", elt, elt))
|
||||
print(string.format(" ctypes_register_class(vm, &be_class_%s, &be_%s);", elt, elt))
|
||||
end
|
||||
print("}")
|
||||
|
@ -316,6 +314,7 @@ class structure
|
|||
print(string.format("const be_ctypes_structure_t be_%s = {", name))
|
||||
print(string.format(" %i, /* size in bytes */", self.size_bytes))
|
||||
print(string.format(" %i, /* number of elements */", size(self.mapping)))
|
||||
print(string.format(" be_ctypes_instance_mappings,"))
|
||||
print(string.format(" (const be_ctypes_structure_item_t[%i]) {", size(self.mapping)))
|
||||
# list keys for future binary search
|
||||
var names = []
|
||||
|
@ -447,7 +446,6 @@ class structure
|
|||
self.get_closures[name] = def (b, p) return ctypes.get_bits(b, cur_offset + p, bit_offset, size_in_bits) end
|
||||
self.set_closures[name] = def (b, p, v) return ctypes.set_bits(b, cur_offset+ p, bit_offset, size_in_bits, v) end
|
||||
|
||||
self.cur_offset += size_in_bits / 8
|
||||
self.cur_offset += (self.bit_offset + size_in_bits) / 8
|
||||
self.bit_offset = (self.bit_offset + size_in_bits) % 8
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue