-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlv_mem_core_circuitpython.c
More file actions
101 lines (85 loc) · 1.98 KB
/
Copy pathlv_mem_core_circuitpython.c
File metadata and controls
101 lines (85 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @file lv_mem_core_circuitpython.c
*
* GC-aware LVGL heap for CircuitPython.
*
* Wire up by:
* 1. In lv_conf.h (CP build only):
* #define LV_STDLIB_CIRCUITPYTHON_OVERRIDE 253
* #define LV_USE_STDLIB_MALLOC LV_STDLIB_CIRCUITPYTHON_OVERRIDE
* 2. Add this file to the CircuitPython board / extmod sources list.
*
* Uses CircuitPython's m_malloc/m_realloc/m_free, which route through the
* garbage-collected heap (see py/malloc.c).
*/
/*********************
* INCLUDES
*********************/
#include "lvgl/src/stdlib/lv_mem.h"
/* Must match lv_conf.h when building for CircuitPython. */
#ifndef LV_STDLIB_CIRCUITPYTHON_OVERRIDE
#define LV_STDLIB_CIRCUITPYTHON_OVERRIDE 253
#endif
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_CIRCUITPYTHON_OVERRIDE
#include <py/mpconfig.h>
#include <py/misc.h>
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
#include <py/gc.h>
#endif
/*********************
* DEFINES
*********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_mem_init(void)
{
/* Nothing to init — CP heap is already running. */
}
void lv_mem_deinit(void)
{
/* Nothing to deinit. */
}
lv_mem_pool_t lv_mem_add_pool(void *mem, size_t bytes)
{
LV_UNUSED(mem);
LV_UNUSED(bytes);
return NULL;
}
void lv_mem_remove_pool(lv_mem_pool_t pool)
{
LV_UNUSED(pool);
}
void *lv_malloc_core(size_t size)
{
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
return gc_alloc(size, true);
#else
return m_malloc(size);
#endif
}
void *lv_realloc_core(void *p, size_t new_size)
{
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
return gc_realloc(p, new_size, true);
#else
return m_realloc(p, new_size);
#endif
}
void lv_free_core(void *p)
{
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
gc_free(p);
#else
m_free(p);
#endif
}
void lv_mem_monitor_core(lv_mem_monitor_t *mon_p)
{
LV_UNUSED(mon_p);
}
lv_result_t lv_mem_test_core(void)
{
return LV_RESULT_OK;
}
#endif /* LV_USE_STDLIB_MALLOC == LV_STDLIB_CIRCUITPYTHON_OVERRIDE */