Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions core/app-framework/wgl/readme.MD
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
WASM Graphic Layer (WGL)
=======

The WGL builds the littlevgl v6.0 into the runtime and exports a API layer for WASM appication programming graphic user interfaces. This approach will makes the WASM application small footprint. Another option will be built the whole littlevgl library into WASM, which is how the sample littlevgl is implemented.
The WGL builds the littlevgl v6.0 into the runtime and exports a API layer for WASM appication programming graphic user interfaces. This approach will make the WASM application small footprint. Another option is to build the whole littlevgl library into WASM, which is how the sample littlevgl is implemented.

# Challenges

When the littlevgl library is compiled into the runtime, all the widget data is actually located in the runtime native space. As the WASM sandbox won't allow the WASM application to directly access the native data, it introduced a few problems for the API porting:
When the littlevgl library is compiled into the runtime, all the widget data is actually located in the runtime native space. As the WASM sandbox won't allow the WASM application to directly access the native data, it introduced a few problems for the littlevgl API exporting:

1. Reference to the widget object
Almost each littlevgl API will take widget object as the first argument, which leads to either read or write the data associated with the object. We have to prevent the WASM app utilize this to access unauthorized the memmory.

The solution is to track the objects created by the WASM App in the native layer. Every access to the object must be validated in advance. To simplify each native wrapper function, the wgl_native_func_call() will do the validation for the object presented in the first argument.
Almost each littlevgl API takes the widget object as the first argument, which leads to either reading or writing the data associated with the object in native space. We have to prevent the WASM app utilize this method to access unauthorized memmory address.

When multiple WASM apps are creating their own UI, the object will be also validated for his owner module instance.
The solution is to track the objects created by the WASM App in the native layer. Every access to the object must be validated in advance. To simplify implementing native wrapper function, the wgl_native_func_call() will do the validation for the object presented in the first argument.

When multiple WASM apps are creating their own UI, the object should also validated for its owner module instance.

2. Access the object properties
The data structure of widget objects is no longer visible to the applications. The app has to call APIs to get/set the properties of an object.

As the data structure of widget objects is no longer visible to the applications, the app has to call APIs to get/set the properties of an object.

3. Pass function arguments in stucture pointers

We have to do serialization for the structure passing between the WASM and native.

4. Callbacks

# API compatibility with littlevgl
We wish the application continue to use the littlevgl API and keep existing header files inclusion, however it is also a bit challenging.

Firstly we have to redefine some data types such as lv_obj_t in the APIs exposed to the WASM app.
We wish the application continue to use the littlevgl API and keep existing header files inclusion, however it is also a bit challenging since we have to redefine some data types such as lv_obj_t in the APIs exposed to the WASM app.
'''
typedef void lv_obj_t;
'''
Expand All @@ -47,7 +48,7 @@ The script is also automatically executed after downloading the lvgl repo in the
# How to extend a little vgl wideget
Currently the wgl has exported the API for a few common used widgets such as button, label etc.

Refer to the implementation of these widgets for extending other widgets.
Refer to the implementation of these widgets for extending more widgets.



Expand Down
2 changes: 1 addition & 1 deletion core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void app_manager_timer_destroy(void *timer)

void app_manager_timer_start(void *timer, int timeout)
{
k_timer_start(timer, timeout, 0);
k_timer_start(timer, Z_TIMEOUT_MS(timeout), Z_TIMEOUT_MS(0));
}

void app_manager_timer_stop(void *timer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct ili9340_data ili9340_data1;
static void ili9340_exit_sleep(struct ili9340_data *data)
{
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
//k_sleep(120);
//k_sleep(Z_TIMEOUT_MS(120));
}

int ili9340_init()
Expand Down Expand Up @@ -82,11 +82,11 @@ int ili9340_init()

LOG_DBG("Resetting display driver\n");
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(1);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 0);
k_sleep(1);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(5);
k_sleep(Z_TIMEOUT_MS(5));

LOG_DBG("Initializing LCD\n");
ili9340_lcd_init(data);
Expand Down
2 changes: 1 addition & 1 deletion samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main(void)
{
iwasm_main();
for(;;){
k_sleep(1000);
k_sleep(Z_TIMEOUT_MS(1000));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct ili9340_data ili9340_data1;
static void ili9340_exit_sleep(struct ili9340_data *data)
{
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
//k_sleep(120);
//k_sleep(Z_TIMEOUT_MS(120));
}

int ili9340_init()
Expand Down Expand Up @@ -82,11 +82,11 @@ int ili9340_init()

LOG_DBG("Resetting display driver\n");
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(1);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 0);
k_sleep(1);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(5);
k_sleep(Z_TIMEOUT_MS(5));

LOG_DBG("Initializing LCD\n");
ili9340_lcd_init(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main(void)
display_init();
iwasm_main();
for(;;){
k_sleep(1000);
k_sleep(Z_TIMEOUT_MS(1000));
}
}