-
Notifications
You must be signed in to change notification settings - Fork 164
/
modSDL.c
70 lines (55 loc) · 1.95 KB
/
modSDL.c
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
#include "../include/common.h"
#include "SDL_monitor.h"
#include "SDL_mouse.h"
//////////////////////////////////////////////////////////////////////////////
STATIC mp_obj_t mp_lv_task_handler(mp_obj_t arg)
{
if (monitor_active()) monitor_sdl_refr_core();
lv_task_handler();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_lv_task_handler_obj, mp_lv_task_handler);
STATIC int tick_thread(void * data)
{
(void)data;
while(monitor_active()) {
SDL_Delay(1); /*Sleep for 1 millisecond*/
lv_tick_inc(1); /*Tell LittelvGL that 1 milliseconds were elapsed*/
mp_sched_schedule((mp_obj_t)&mp_lv_task_handler_obj, mp_const_none);
}
return 0;
}
STATIC mp_obj_t mp_init_SDL()
{
monitor_init();
SDL_CreateThread(tick_thread, "tick", NULL);
return mp_const_none;
}
STATIC mp_obj_t mp_deinit_SDL()
{
monitor_deinit();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_init_SDL_obj, mp_init_SDL);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_deinit_SDL_obj, mp_deinit_SDL);
DEFINE_PTR_OBJ(monitor_flush);
DEFINE_PTR_OBJ(monitor_fill);
DEFINE_PTR_OBJ(monitor_map);
DEFINE_PTR_OBJ(mouse_read);
STATIC const mp_rom_map_elem_t SDL_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_SDL) },
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mp_init_SDL_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&mp_deinit_SDL_obj) },
{ MP_ROM_QSTR(MP_QSTR_monitor_flush), MP_ROM_PTR(&PTR_OBJ(monitor_flush))},
{ MP_ROM_QSTR(MP_QSTR_monitor_fill), MP_ROM_PTR(&PTR_OBJ(monitor_fill))},
{ MP_ROM_QSTR(MP_QSTR_monitor_map), MP_ROM_PTR(&PTR_OBJ(monitor_map))},
{ MP_ROM_QSTR(MP_QSTR_mouse_read), MP_ROM_PTR(&PTR_OBJ(mouse_read))},
};
STATIC MP_DEFINE_CONST_DICT (
mp_module_SDL_globals,
SDL_globals_table
);
const mp_obj_module_t mp_module_SDL = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_SDL_globals
};