8000 . · PyDevices/lv_micropython_cmod@fa65a01 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa65a01

Browse files
committed
.
1 parent 23e266c commit fa65a01

File tree

5 files changed

+120
-7
lines changed

5 files changed

+120
-7
lines changed

lv_conf.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef LV_CONF_H
1818
#define LV_CONF_H
1919

20+
#define LV_STDLIB_MICROPYTHON_OVERRIDE 254
21+
2022
/*If you need to include anything here, do it inside the `__ASSEMBLY__` guard */
2123
#if 0 && defined(__ASSEMBLY__)
2224
#include "my_include.h"
@@ -40,7 +42,7 @@
4042
* - LV_STDLIB_RTTHREAD: RT-Thread implementation
4143
* - LV_STDLIB_CUSTOM: Implement the functions externally
4244
*/
43-
#define LV_USE_STDLIB_MALLOC LV_STDLIB_MICROPYTHON
45+
#define LV_USE_STDLIB_MALLOC LV_STDLIB_MICROPYTHON_OVERRIDE
4446
#define LV_USE_STDLIB_STRING LV_STDLIB_BUILTIN
4547
#define LV_USE_STDLIB_SPRINTF LV_STDLIB_BUILTIN
4648

lv_mem_core_micropython.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @file lv_malloc_core.c
3+
*/
4+
5+
/*********************
6+
* INCLUDES
7+
*********************/
8+
#include "lvgl/src/stdlib/lv_mem.h"
9+
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_MICROPYTHON_OVERRIDE
10+
#include <py/mpconfig.h>
11+
#include <py/misc.h>
12+
#include <py/gc.h>
13+
/*********************
14+
* DEFINES
15+
*********************/
16+
17+
/**********************
18+
* TYPEDEFS
19+
**********************/
20+
21+
/**********************
22+
* STATIC PROTOTYPES
23+
**********************/
24+
25+
/**********************
26+
* STATIC VARIABLES
27+
**********************/
28+
29+
/**********************
30+
* MACROS
31+
**********************/
32+
33+
/**********************
34+
* GLOBAL FUNCTIONS
35+
**********************/
36+
37+
void lv_mem_init(void)
38+
{
39+
return; /*Nothing to init*/
40+
}
41+
42+
void lv_mem_deinit(void)
43+
{
44+
return; /*Nothing to deinit*/
45+
46+
}
47+
48+
lv_mem_pool_t lv_mem_add_pool(void * mem, size_t bytes)
49+
{
50+
/*Not supported*/
51+
LV_UNUSED(mem);
52+
LV_UNUSED(bytes);
53+
return NULL;
54+
}
55+
56+
void lv_mem_remove_pool(lv_mem_pool_t pool)
57+
{
58+
/*Not supported*/
59+
LV_UNUSED(pool);
60+
return;
61+
}
62+
63+
void * lv_malloc_core(size_t size)
64+
{
65+
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
66+
return gc_alloc(size, true);
67+
#else
68+
return m_malloc(size);
69+
#endif
70+
}
71+
72+
void * lv_realloc_core(void * p, size_t new_size)
73+
{
74+
75+
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
76+
return gc_realloc(p, new_size, true);
77+
#else
78+
return m_realloc(p, new_size);
79+
#endif
80+
}
81+
82+
void lv_free_core(void * p)
83+
{
84+
85+
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
86+
gc_free(p);
87+
88+
#else
89+
m_free(p);
90+
#endif
91+
}
92+
93+
void lv_mem_monitor_core(lv_mem_monitor_t * mon_p)
94+
{
95+
/*Not supported*/
96+
LV_UNUSED(mon_p);
97+
return;
98+
}
99+
100+
lv_result_t lv_mem_test_core(void)
101+
{
102+
/*Not supported*/
103+
return LV_RESULT_OK;
104+
}
105+
106+
/**********************
107+
* STATIC FUNCTIONS
108+
**********************/
109+
110+
#endif /*LV_STDLIB_MICROPYTHON*/

lvmp.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(LV_MPY_METADATA ${LV_MP}.json)
1919
set(LV_JSON ${CMAKE_BINARY_DIR}/lvgl_all.json)
2020
set(LV_ALL_H ${CMAKE_BINARY_DIR}/lvgl_all.h)
2121
file(GLOB_RECURSE LV_HEADERS ${LVGL_DIR}/src/*.h ${LV_BINDINGS_DIR}/lv_conf.h)
22-
file(GLOB_RECURSE SOURCES ${LVGL_DIR}/src/*.c)
22+
file(GLOB_RECURSE SOURCES ${LV_BINDINGS_DIR}/lv_mem_core_micropython.c ${LVGL_DIR}/src/*.c)
2323

2424
message(STATUS "Starting the CMake configuration for Micropython with LVGL bindings")
2525

micropython.mk

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ LV_JSON = $(BUILD)/lvgl_all.json
2525
LV_ALL_H = $(BUILD)/lvgl_all.h
2626
LV_HEADERS = $(shell find $(LVGL_DIR) -type f -name '*.h') $(LV_BINDINGS_DIR)/lv_conf.h
2727

28-
CFLAGS_USERMOD += $(LV_CFLAGS)
29-
CFLAGS_USERMOD += -I$(LV_BINDINGS_DIR)
3028
CFLAGS_USERMOD += -I$(LVGL_DIR)
29+
CFLAGS_USERMOD += -I$(LV_BINDINGS_DIR)
30+
CFLAGS_USERMOD += $(LV_CFLAGS)
3131
CFLAGS_USERMOD += -Wno-unused-function
3232

33+
SRC_USERMOD_LIB_C += $(LV_BINDINGS_DIR)/lv_mem_core_micropython.c
34+
SRC_USERMOD_LIB_C += $(shell find $(LVGL_DIR)/src -type f -name "*.c")
35+
SRC_USERMOD_C += $(LV_MP)
36+
3337
# Create lvgl_all.h file (if gen_json.py exists) and lvgl_all.json file
3438
ifneq (,$(wildcard $(LVGL_DIR)/scripts/gen_json/gen_json.py))
3539
$(LV_JSON): $(LV_HEADERS) $(LVGL_DIR)/scripts/gen_json/gen_json.py
@@ -51,6 +55,3 @@ $(LV_MP): $(LV_HEADERS) $(LV_BINDINGS_DIR)/gen_mpy.py $(LV_JSON)
5155
.PHONY: LV_MP
5256
LV_JSON: $(LV_JSON)
5357
LV_MP: $(LV_MP)
54-
55-
SRC_USERMOD_C += $(LV_MP)
56-
SRC_THIRDPARTY_C += $(subst $(TOP)/,,$(shell find $(LVGL_DIR)/src -type f -name "*.c"))

0 commit comments

Comments
 (0)
0