Implement native function pointer check, addr conversion and register, update documents (#185)
Modified WASM runtime API: - wasm_runtime_module_malloc() - wasm_runtime_lookup_function() Introduced runtime API - wasm_runtime_register_natives()
This commit is contained in:
@ -112,3 +112,9 @@ First, connect PC and STM32 with UART. Then install to use host_tool.</br>
|
||||
- Install AOT version WASM application
|
||||
`wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app.aot ui_app.wasm`
|
||||
`./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app.aot`
|
||||
|
||||
|
||||
|
||||
The graphic user interface demo photo:
|
||||
|
||||

|
||||
@ -42,7 +42,6 @@ include_directories(
|
||||
set (SOURCES
|
||||
${PROJECT_SRC_DIR}/main.c
|
||||
${PROJECT_SRC_DIR}/iwasm_main.c
|
||||
${PROJECT_SRC_DIR}/../../ext_lib_export.c
|
||||
${LV_DRIVERS_SOURCES}
|
||||
)
|
||||
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
#include "lib_export.h"
|
||||
#include "sensor_native_api.h"
|
||||
#include "connection_native_api.h"
|
||||
#include "gui_native_api.h"
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] = {
|
||||
#include "runtime_sensor.inl"
|
||||
#include "connection.inl"
|
||||
#include "wamr_gui.inl"
|
||||
};
|
||||
|
||||
#include "ext_lib_export.h"
|
||||
@ -73,5 +73,4 @@ target_sources(app PRIVATE
|
||||
${LVGL_DRV_SRCS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src/ext_lib_export.c
|
||||
)
|
||||
|
||||
@ -4,7 +4,6 @@ This sample demonstrates that a graphic user interface application in WebAssembl
|
||||
|
||||
In this sample, the whole LittlevGL source code is built into the WebAssembly code with the user application. The platform interfaces defined by LittlevGL is implemented in the runtime and exported to the application through the declarations from source "ext_lib_export.c" as below:
|
||||
|
||||
EXPORT_WASM_API(display_init),
|
||||
EXPORT_WASM_API(display_input_read),
|
||||
EXPORT_WASM_API(display_flush),
|
||||
EXPORT_WASM_API(display_fill),
|
||||
|
||||
@ -38,7 +38,7 @@ fi
|
||||
|
||||
echo "##################### 0. build wamr-sdk littlevgl start#####################"
|
||||
cd ${WAMR_DIR}/wamr-sdk
|
||||
./build_sdk.sh -n littlevgl -x ${PROJECT_DIR}/wamr_config_littlevgl.cmake -e ${LV_CFG_PATH}
|
||||
./build_sdk.sh -n littlevgl -x ${PROJECT_DIR}/wamr_config_littlevgl.cmake -e ${LV_CFG_PATH} -c
|
||||
[ $? -eq 0 ] || exit $?
|
||||
echo "#####################build wamr-sdk littlevgl success"
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
|
||||
|
||||
add_executable (vgl_wasm_runtime src/platform/${WAMR_BUILD_PLATFORM}/main.c
|
||||
src/platform/${WAMR_BUILD_PLATFORM}/iwasm_main.c
|
||||
src/ext_lib_export.c src/platform/${WAMR_BUILD_PLATFORM}/display_indev.c
|
||||
src/platform/${WAMR_BUILD_PLATFORM}/display_indev.c
|
||||
src/platform/${WAMR_BUILD_PLATFORM}/mouse.c)
|
||||
|
||||
target_link_libraries (vgl_wasm_runtime vmlib -lm -ldl -lpthread -lSDL2)
|
||||
|
||||
@ -58,11 +58,11 @@ enum {
|
||||
|
||||
extern void xpt2046_init(void);
|
||||
|
||||
extern bool touchscreen_read(lv_indev_data_t * data);
|
||||
extern bool touchscreen_read(lv_indev_data_t *data);
|
||||
|
||||
extern bool mouse_read(lv_indev_data_t * data);
|
||||
extern bool mouse_read(lv_indev_data_t *data);
|
||||
|
||||
extern void display_init(wasm_exec_env_t exec_env);
|
||||
extern void display_init(void);
|
||||
|
||||
extern void display_deinit(wasm_exec_env_t exec_env);
|
||||
|
||||
@ -70,22 +70,21 @@ extern int time_get_ms(wasm_exec_env_t exec_env);
|
||||
|
||||
extern void display_flush(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
int32 color_p_offset);
|
||||
lv_color_t *color);
|
||||
|
||||
extern void display_fill(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
lv_color_t color_p);
|
||||
lv_color_t *color);
|
||||
|
||||
extern void display_map(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p);
|
||||
const lv_color_t *color);
|
||||
|
||||
extern bool display_input_read(wasm_exec_env_t exec_env,
|
||||
int32 data_offset);
|
||||
extern bool display_input_read(wasm_exec_env_t exec_env, void *data);
|
||||
|
||||
void display_vdb_write(wasm_exec_env_t exec_env,
|
||||
int32 buf_offset, lv_coord_t buf_w, lv_coord_t x,
|
||||
lv_coord_t y, int32 color_p_offset, lv_opa_t opa);
|
||||
void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
||||
lv_color_t *color, lv_opa_t opa);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
#include "lib_export.h"
|
||||
#include "sensor_native_api.h"
|
||||
#include "connection_native_api.h"
|
||||
#include "display_indev.h"
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] = {
|
||||
#include "runtime_sensor.inl"
|
||||
#include "connection.inl"
|
||||
EXPORT_WASM_API(display_init),
|
||||
EXPORT_WASM_API(display_input_read),
|
||||
EXPORT_WASM_API(display_flush),
|
||||
EXPORT_WASM_API(display_fill),
|
||||
EXPORT_WASM_API(display_vdb_write),
|
||||
EXPORT_WASM_API(display_map),
|
||||
EXPORT_WASM_API(time_get_ms)
|
||||
};
|
||||
|
||||
#include "ext_lib_export.h"
|
||||
@ -41,7 +41,7 @@ static volatile bool sdl_refr_qry = false;
|
||||
static volatile bool sdl_quit_qry = false;
|
||||
|
||||
void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p)
|
||||
const lv_color_t * color)
|
||||
{
|
||||
/*Return if the area is out the screen*/
|
||||
if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1
|
||||
@ -53,10 +53,10 @@ void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
uint32_t w = x2 - x1 + 1;
|
||||
|
||||
for (y = y1; y <= y2; y++) {
|
||||
memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color_p,
|
||||
memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color,
|
||||
w * sizeof(lv_color_t));
|
||||
|
||||
color_p += w;
|
||||
color += w;
|
||||
}
|
||||
sdl_refr_qry = true;
|
||||
|
||||
@ -72,7 +72,7 @@ void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
* @param color fill color
|
||||
*/
|
||||
void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
lv_color_t color)
|
||||
lv_color_t *color)
|
||||
{
|
||||
/*Return if the area is out the screen*/
|
||||
if (x2 < 0)
|
||||
@ -92,7 +92,7 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
uint32_t color32 = color.full; //lv_color_to32(color);
|
||||
uint32_t color32 = color->full; //lv_color_to32(color);
|
||||
|
||||
for (x = act_x1; x <= act_x2; x++) {
|
||||
for (y = act_y1; y <= act_y2; y++) {
|
||||
@ -109,10 +109,10 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
* @param y1 top coordinate
|
||||
* @param x2 right coordinate
|
||||
* @param y2 bottom coordinate
|
||||
* @param color_p an array of colors
|
||||
* @param color an array of colors
|
||||
*/
|
||||
void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p)
|
||||
const lv_color_t *color)
|
||||
{
|
||||
/*Return if the area is out the screen*/
|
||||
if (x2 < 0)
|
||||
@ -135,11 +135,11 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
|
||||
for (y = act_y1; y <= act_y2; y++) {
|
||||
for (x = act_x1; x <= act_x2; x++) {
|
||||
tft_fb[y * MONITOR_HOR_RES + x] = color_p->full; //lv_color_to32(*color_p);
|
||||
color_p++;
|
||||
tft_fb[y * MONITOR_HOR_RES + x] = color->full; //lv_color_to32(*color);
|
||||
color++;
|
||||
}
|
||||
|
||||
color_p += x2 - act_x2;
|
||||
color += x2 - act_x2;
|
||||
}
|
||||
|
||||
sdl_refr_qry = true;
|
||||
@ -147,62 +147,64 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
|
||||
|
||||
void
|
||||
display_init(wasm_exec_env_t exec_env)
|
||||
display_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
display_flush(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
int32 color_p_offset)
|
||||
lv_color_t *color)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
|
||||
return;
|
||||
lv_color_t * color_p = wasm_runtime_addr_app_to_native(module_inst,
|
||||
color_p_offset);
|
||||
|
||||
monitor_flush(x1, y1, x2, y2, color_p);
|
||||
if (!wasm_runtime_validate_native_addr(module_inst,
|
||||
color, sizeof(lv_color_t)))
|
||||
return;
|
||||
|
||||
monitor_flush(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
void
|
||||
display_fill(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
lv_color_t color_p)
|
||||
lv_color_t *color)
|
||||
{
|
||||
monitor_fill(x1, y1, x2, y2, color_p);
|
||||
monitor_fill(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
void
|
||||
display_map(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p)
|
||||
const lv_color_t *color)
|
||||
{
|
||||
monitor_map(x1, y1, x2, y2, color_p);
|
||||
monitor_map(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
typedef struct display_input_data {
|
||||
lv_point_t point;
|
||||
int32 user_data_offset;
|
||||
uint8 state;
|
||||
} display_input_data;
|
||||
|
||||
bool
|
||||
display_input_read(wasm_exec_env_t exec_env,
|
||||
int32 data_p_offset)
|
||||
void *input_data_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
display_input_data *data_app = (display_input_data*)input_data_app;
|
||||
bool ret;
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, data_p_offset, 1))
|
||||
|
||||
if (!wasm_runtime_validate_native_addr(module_inst,
|
||||
data_app,
|
||||
sizeof(display_input_data)))
|
||||
return false;
|
||||
|
||||
struct {
|
||||
lv_point_t point;
|
||||
int32 user_data_offset;
|
||||
uint8 state;
|
||||
} *data_app;
|
||||
|
||||
lv_indev_data_t data = {0};
|
||||
|
||||
ret = mouse_read(&data);
|
||||
|
||||
data_app = wasm_runtime_addr_app_to_native(module_inst,
|
||||
data_p_offset);
|
||||
|
||||
data_app->point = data.point;
|
||||
data_app->user_data_offset =
|
||||
wasm_runtime_addr_native_to_app(module_inst, data.user_data);
|
||||
@ -218,35 +220,17 @@ display_deinit(wasm_exec_env_t exec_env)
|
||||
|
||||
void
|
||||
display_vdb_write(wasm_exec_env_t exec_env,
|
||||
int32 buf_offset, lv_coord_t buf_w, lv_coord_t x,
|
||||
lv_coord_t y, int32 color_p_offset, lv_opa_t opa)
|
||||
void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
||||
lv_color_t *color, lv_opa_t opa)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
|
||||
unsigned char *buf_xy = (unsigned char*)buf + 4 * x + 4 * y * buf_w;
|
||||
|
||||
if (!wasm_runtime_validate_native_addr(module_inst,
|
||||
color, sizeof(lv_color_t)))
|
||||
return;
|
||||
lv_color_t *color = wasm_runtime_addr_app_to_native(module_inst,
|
||||
color_p_offset);
|
||||
|
||||
void *buf = wasm_runtime_addr_app_to_native(module_inst, buf_offset);
|
||||
|
||||
unsigned char *buf_xy = buf + 4 * x + 4 * y * buf_w;
|
||||
lv_color_t * temp = (lv_color_t *) buf_xy;
|
||||
*temp = *color;
|
||||
/*
|
||||
if (opa != LV_OPA_COVER) {
|
||||
lv_color_t mix_color;
|
||||
|
||||
mix_color.red = *buf_xy;
|
||||
mix_color.green = *(buf_xy+1);
|
||||
mix_color.blue = *(buf_xy+2);
|
||||
color = lv_color_mix(color, mix_color, opa);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
*buf_xy = color->red;
|
||||
*(buf_xy + 1) = color->green;
|
||||
*(buf_xy + 2) = color->blue;
|
||||
*/
|
||||
*(lv_color_t *)buf_xy = *color;
|
||||
}
|
||||
|
||||
int monitor_sdl_refr_thread(void * param)
|
||||
|
||||
@ -32,6 +32,10 @@
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wasm_export.h"
|
||||
#include "sensor_native_api.h"
|
||||
#include "connection_native_api.h"
|
||||
#include "display_indev.h"
|
||||
|
||||
#define MAX 2048
|
||||
|
||||
#ifndef CONNECTION_UART
|
||||
@ -389,7 +393,9 @@ static bool parse_args(int argc, char *argv[])
|
||||
{ "uart", required_argument, NULL, 'u' },
|
||||
{ "baudrate", required_argument, NULL, 'b' },
|
||||
#endif
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
{ "wasi_root", required_argument, NULL, 'w' },
|
||||
#endif
|
||||
{ "help", required_argument, NULL, 'h' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
@ -421,12 +427,14 @@ static bool parse_args(int argc, char *argv[])
|
||||
printf("uart baudrate: %s\n", optarg);
|
||||
break;
|
||||
#endif
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
case 'w':
|
||||
if (!wasm_set_wasi_root_dir(optarg)) {
|
||||
printf("Fail to set wasi root dir: %s\n", optarg);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 'h':
|
||||
showUsage();
|
||||
return false;
|
||||
@ -439,10 +447,22 @@ static bool parse_args(int argc, char *argv[])
|
||||
return true;
|
||||
}
|
||||
|
||||
static NativeSymbol native_symbols[] = {
|
||||
#include "runtime_sensor.inl"
|
||||
#include "connection.inl"
|
||||
EXPORT_WASM_API_WITH_SIG(display_input_read, "(*)i"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_flush, "(iiii*)"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_fill, "(iiii*)"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_vdb_write, "(*iii*i)"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_map, "(iiii*)"),
|
||||
EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i")
|
||||
};
|
||||
|
||||
// Driver function
|
||||
int iwasm_main(int argc, char *argv[])
|
||||
{
|
||||
korp_thread tid;
|
||||
uint32 n_native_symbols;
|
||||
|
||||
if (!parse_args(argc, argv))
|
||||
return -1;
|
||||
@ -457,6 +477,13 @@ int iwasm_main(int argc, char *argv[])
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
/* Register native functions */
|
||||
n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
|
||||
if (!wasm_runtime_register_natives("env",
|
||||
native_symbols, n_native_symbols)) {
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
if (!init_connection_framework()) {
|
||||
vm_thread_sys_destroy();
|
||||
goto fail1;
|
||||
|
||||
@ -15,10 +15,12 @@
|
||||
#define MONITOR_ZOOM 1
|
||||
#endif
|
||||
|
||||
extern int ili9340_init();
|
||||
|
||||
static int lcd_initialized = 0;
|
||||
|
||||
void
|
||||
display_init(wasm_exec_env_t exec_env)
|
||||
display_init(void)
|
||||
{
|
||||
if (lcd_initialized != 0) {
|
||||
return;
|
||||
@ -32,23 +34,23 @@ display_init(wasm_exec_env_t exec_env)
|
||||
void
|
||||
display_flush(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
int32 color_p_offset)
|
||||
lv_color_t *color)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
|
||||
struct display_buffer_descriptor desc;
|
||||
|
||||
if (!wasm_runtime_validate_native_addr(module_inst,
|
||||
color, sizeof(lv_color_t)))
|
||||
return;
|
||||
lv_color_t * color_p = wasm_runtime_addr_app_to_native(module_inst,
|
||||
color_p_offset);
|
||||
|
||||
u16_t w = x2 - x1 + 1;
|
||||
u16_t h = y2 - y1 + 1;
|
||||
struct display_buffer_descriptor desc;
|
||||
|
||||
desc.buf_size = 3 * w * h;
|
||||
desc.width = w;
|
||||
desc.pitch = w;
|
||||
desc.height = h;
|
||||
display_write(NULL, x1, y1, &desc, (void *) color_p);
|
||||
display_write(NULL, x1, y1, &desc, (void *)color);
|
||||
|
||||
/*lv_flush_ready();*/
|
||||
}
|
||||
@ -56,27 +58,28 @@ display_flush(wasm_exec_env_t exec_env,
|
||||
void
|
||||
display_fill(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
lv_color_t color_p)
|
||||
lv_color_t *color)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
display_map(wasm_exec_env_t exec_env,
|
||||
int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p)
|
||||
const lv_color_t *color)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
display_input_read(wasm_exec_env_t exec_env, int32 data_p_offset)
|
||||
display_input_read(wasm_exec_env_t exec_env, void *data)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, data_p_offset, 1))
|
||||
return false;
|
||||
lv_indev_data_t * data = wasm_runtime_addr_app_to_native(module_inst,
|
||||
data_p_offset);
|
||||
lv_indev_data_t *lv_data = (lv_indev_data_t*)data;
|
||||
|
||||
return touchscreen_read(data);
|
||||
if (!wasm_runtime_validate_native_addr(module_inst,
|
||||
lv_data, sizeof(lv_indev_data_t)))
|
||||
return false;
|
||||
|
||||
return touchscreen_read(lv_data);
|
||||
}
|
||||
|
||||
void
|
||||
@ -86,28 +89,16 @@ display_deinit(wasm_exec_env_t exec_env)
|
||||
|
||||
void
|
||||
display_vdb_write(wasm_exec_env_t exec_env,
|
||||
int32 buf_offset, lv_coord_t buf_w, lv_coord_t x,
|
||||
lv_coord_t y, int32 color_p_offset, lv_opa_t opa)
|
||||
void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
||||
lv_color_t *color, lv_opa_t opa)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, color_p_offset, 1))
|
||||
u8_t *buf_xy = (u8_t*)buf + 3 * x + 3 * y * buf_w;
|
||||
|
||||
if (!wasm_runtime_validate_native_addr(module_inst,
|
||||
color, sizeof(lv_color_t)))
|
||||
return;
|
||||
lv_color_t *color = wasm_runtime_addr_app_to_native(module_inst,
|
||||
color_p_offset);
|
||||
|
||||
void *buf = wasm_runtime_addr_app_to_native(module_inst, buf_offset);
|
||||
|
||||
u8_t *buf_xy = buf + 3 * x + 3 * y * buf_w;
|
||||
/*
|
||||
if (opa != LV_OPA_COVER) {
|
||||
lv_color_t mix_color;
|
||||
|
||||
mix_color.red = *buf_xy;
|
||||
mix_color.green = *(buf_xy+1);
|
||||
mix_color.blue = *(buf_xy+2);
|
||||
color = lv_color_mix(color, mix_color, opa);
|
||||
}
|
||||
*/
|
||||
*buf_xy = color->red;
|
||||
*(buf_xy + 1) = color->green;
|
||||
*(buf_xy + 2) = color->blue;
|
||||
|
||||
@ -15,6 +15,9 @@
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wasm_export.h"
|
||||
#include "sensor_native_api.h"
|
||||
#include "connection_native_api.h"
|
||||
#include "display_indev.h"
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <drivers/uart.h>
|
||||
@ -30,7 +33,6 @@ int uart_char_cnt = 0;
|
||||
static void uart_irq_callback(struct device *dev)
|
||||
{
|
||||
unsigned char ch;
|
||||
int size = 0;
|
||||
|
||||
while (uart_poll_in(dev, &ch) == 0) {
|
||||
uart_char_cnt++;
|
||||
@ -77,11 +79,21 @@ timer_ctx_t timer_ctx;
|
||||
|
||||
static char global_heap_buf[370 * 1024] = { 0 };
|
||||
|
||||
extern void display_init(void);
|
||||
static NativeSymbol native_symbols[] = {
|
||||
#include "runtime_sensor.inl"
|
||||
#include "connection.inl"
|
||||
EXPORT_WASM_API_WITH_SIG(display_input_read, "(*)i"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_flush, "(iiii*)"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_fill, "(iiii*)"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_vdb_write, "(*iii*i)"),
|
||||
EXPORT_WASM_API_WITH_SIG(display_map, "(iiii*)"),
|
||||
EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i")
|
||||
};
|
||||
|
||||
int iwasm_main()
|
||||
{
|
||||
korp_thread tid, tm_tid;
|
||||
uint32 n_native_symbols;
|
||||
|
||||
host_init();
|
||||
|
||||
@ -95,6 +107,13 @@ int iwasm_main()
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
/* Register native functions */
|
||||
n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
|
||||
if (!wasm_runtime_register_natives("env",
|
||||
native_symbols, n_native_symbols)) {
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
display_init();
|
||||
|
||||
// timer manager
|
||||
|
||||
@ -65,5 +65,4 @@ target_sources(app PRIVATE
|
||||
${LVGL_DRV_SRCS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src/ext_lib_export.c
|
||||
)
|
||||
|
||||
@ -10,13 +10,26 @@
|
||||
|
||||
#include "lvgl/lv_misc/lv_color.h"
|
||||
#include "lvgl/lv_hal/lv_hal_indev.h"
|
||||
|
||||
extern void display_init(void);
|
||||
extern void display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p);
|
||||
extern bool display_input_read(lv_indev_data_t * data);
|
||||
|
||||
extern void display_deinit(void);
|
||||
extern void display_vdb_write(void *buf, lv_coord_t buf_w, lv_coord_t x,
|
||||
lv_coord_t y, lv_color_t *color, lv_opa_t opa);
|
||||
|
||||
extern void display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color);
|
||||
|
||||
extern bool display_input_read(lv_indev_data_t *data);
|
||||
|
||||
extern void display_vdb_write(void *buf,
|
||||
lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
||||
lv_color_t *color, lv_opa_t opa);
|
||||
|
||||
void display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t *color);
|
||||
|
||||
void display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t *color);
|
||||
|
||||
extern uint32_t time_get_ms(void);
|
||||
|
||||
#endif
|
||||
|
||||
@ -119,27 +119,32 @@ void on_init()
|
||||
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
|
||||
*/
|
||||
void display_flush_wrapper(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p)
|
||||
const lv_color_t * color_p)
|
||||
{
|
||||
display_flush(x1, y1, x2, y2, color_p);
|
||||
lv_flush_ready();
|
||||
}
|
||||
void display_vdb_write_wrapper(uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
|
||||
lv_coord_t y, lv_color_t color, lv_opa_t opa)
|
||||
|
||||
void display_vdb_write_wrapper(uint8_t *buf,
|
||||
lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
||||
lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
display_vdb_write(buf, buf_w, x, y, &color, opa);
|
||||
}
|
||||
extern void display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
lv_color_t color_p);
|
||||
extern void display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
const lv_color_t * color_p);
|
||||
|
||||
void display_fill_wrapper(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
lv_color_t color)
|
||||
{
|
||||
display_fill(x1, y1, x2, y2, &color);
|
||||
}
|
||||
|
||||
static void hal_init(void)
|
||||
{
|
||||
/* Add a display*/
|
||||
lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
||||
disp_drv.disp_flush = display_flush_wrapper; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/
|
||||
disp_drv.disp_fill = display_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/
|
||||
disp_drv.disp_fill = display_fill_wrapper; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/
|
||||
disp_drv.disp_map = display_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/
|
||||
#if LV_VDB_SIZE != 0
|
||||
disp_drv.vdb_wr = display_vdb_write_wrapper;
|
||||
|
||||
@ -27,7 +27,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
|
||||
#Note: uncomment below line to use UART mode
|
||||
#add_definitions (-DCONNECTION_UART)
|
||||
|
||||
add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c)
|
||||
add_executable (simple src/main.c src/iwasm_main.c)
|
||||
target_link_libraries (simple vmlib -lm -ldl -lpthread -lrt)
|
||||
|
||||
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
#include "lib_export.h"
|
||||
#include "sensor_native_api.h"
|
||||
#include "timer_native_api.h"
|
||||
#include "req_resp_native_api.h"
|
||||
#include "connection_native_api.h"
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] = {
|
||||
#include "runtime_sensor.inl"
|
||||
#include "connection.inl"
|
||||
};
|
||||
|
||||
#include "ext_lib_export.h"
|
||||
Reference in New Issue
Block a user