Separate app-manager and app-framework from WAMR (#3129)

As planned, the app-manager and app-framework are to be migrated to
https://github.com/bytecodealliance/wamr-app-framework.

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2329
https://github.com/bytecodealliance/wasm-micro-runtime/wiki/TSC-meeting-notes
This commit is contained in:
Wenyong Huang
2024-02-20 18:12:36 +08:00
committed by GitHub
parent b9db23b983
commit 63cd567b3f
359 changed files with 45 additions and 37923 deletions

View File

@ -1,10 +1,7 @@
# Samples
- [**basic**](./basic): Demonstrating how to use runtime exposed API's to call WASM functions, how to register native functions and call them, and how to call WASM function from native function.
- **[simple](./simple/README.md)**: The runtime is integrated with most of the WAMR APP libraries, and a few WASM applications are provided for testing the WAMR APP API set. It uses **built-in libc** and executes apps in **interpreter** mode by default.
- **[file](./file/README.md)**: Demonstrating the supported file interaction API of WASI. This sample can also demonstrate the SGX IPFS (Intel Protected File System), enabling an enclave to seal and unseal data at rest.
- **[littlevgl](./littlevgl/README.md)**: Demonstrating the graphic user interface application usage on WAMR. The whole [LVGL](https://github.com/lvgl/lvgl) 2D user graphic library and the UI application are built into WASM application. It uses **WASI libc** and executes apps in **AOT mode** by default.
- **[gui](./gui/README.md)**: Move the [LVGL](https://github.com/lvgl/lvgl) library into the runtime and define a WASM application interface by wrapping the littlevgl API. It uses **WASI libc** and executes apps in **interpreter** mode by default.
- **[multi-thread](./multi-thread/)**: Demonstrating how to run wasm application which creates multiple threads to execute wasm functions concurrently, and uses mutex/cond by calling pthread related API's.
- **[spawn-thread](./spawn-thread)**: Demonstrating how to execute wasm functions of the same wasm application concurrently, in threads created by host embedder or runtime, but not the wasm application itself.
- **[wasi-threads](./wasi-threads/README.md)**: Demonstrating how to run wasm application which creates multiple threads to execute wasm functions concurrently based on lib wasi-threads.

View File

@ -1,138 +0,0 @@
"gui" sample introduction
==============
This sample demonstrates that a graphic user interface application in WebAssembly programming with WAMR graphic library(WGL) which is part of WAMR app-framework.
Compared with the [littlevgl](../littlevgl) sample, WGL compiles LittlevGL source code into the WAMR runtime and defines a set of wrapper API's for exporting to Webassembly application.
Below picture shows the WASM application is running on an STM board with an LCD touch panel.
![WAMR UI SAMPLE](../../doc/pics/vgl_demo2.png "WAMR UI DEMO")
When user clicks the blue button, the WASM application increases the counter, and the latest counter value is displayed on the top banner of the touch panel. The number on top will plus one each second, and the number on the bottom will plus one when clicked.
# Test on Linux
Install required SDK and libraries
--------------
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_32` when building WAMR runtime)
Use apt-get:
```bash
sudo apt-get install libsdl2-dev:i386
```
Or download source from www.libsdl.org:
```bash
./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32
make
sudo make install
```
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_64` when building WAMR runtime)
Use apt-get:
```bash
sudo apt-get install libsdl2-dev
```
Or download source from www.libsdl.org:
```bash
./configure
make
sudo make install
```
Build and Run
--------------
- Build
```bash
./build.sh
```
All binaries are in "out", which contains "host_tool", "ui_decrease.wasm", "ui_increase.wasm" and "wasm_runtime_wgl".
- Run WASM VM Linux applicaton & install WASM APP
First start wasm_runtime_wgl in server mode.
```bash
./wasm_runtime_wgl -s
```
Then install wasm APP by using host tool.
```bash
./host_tool -i inc -f ui_increase.wasm
# or
./host_tool -i dec -f ui_decrease.wasm
```
Test on Zephyr
================================
We can use a STM32 NUCLEO_F767ZI board with ILI9341 display and XPT2046 touch screen to run the test. Then use host_tool to remotely install wasm app into STM32.
- Build WASM VM into Zephyr system
a. clone zephyr source code
Refer to [Zephyr getting started](https://docs.zephyrproject.org/latest/getting_started/index.html).
```bash
west init zephyrproject
cd zephyrproject/zephyr
git checkout zephyr-v2.3.0
cd ..
west update
```
b. copy samples
```bash
cd zephyr/samples
cp -a <wamr_root>/samples/gui/wasm-runtime-wgl wasm-runtime-wgl
cd wasm-runtime-wgl/zephyr_build
```
c. create a link to wamr root dir
```bash
ln -s <wamr_root> wamr
```
d. build source code
```bash
mkdir build && cd build
source ../../../../zephyr-env.sh
cmake -GNinja -DBOARD=nucleo_f767zi ..
ninja flash
```
- Hardware Connections
```
+-------------------+-+------------------+
|NUCLEO-F767ZI | ILI9341 Display |
+-------------------+-+------------------+
| CN7.10 | CLK |
+-------------------+-+------------------+
| CN7.12 | MISO |
+-------------------+-+------------------+
| CN7.14 | MOSI |
+-------------------+-+------------------+
| CN11.1 | CS1 for ILI9341 |
+-------------------+-+------------------+
| CN11.2 | D/C |
+-------------------+-+------------------+
| CN11.3 | RESET |
+-------------------+-+------------------+
| CN9.25 | PEN interrupt |
+-------------------+-+------------------+
| CN9.27 | CS2 for XPT2046 |
+-------------------+-+------------------+
| CN10.14 | PC UART RX |
+-------------------+-+------------------+
| CN11.16 | PC UART RX |
+-------------------+-+------------------+
```
- Install WASM application to Zephyr using host_tool
First, connect PC and STM32 with UART. Then install to use host_tool.
```bash
sudo ./host_tool -D /dev/ttyUSBXXX -i inc -f ui_increase.wasm
# /dev/ttyUSBXXX is the UART device, e.g. /dev/ttyUSB0
```
- Install AOT version WASM application
```bash
wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app.aot ui_increase.wasm
./host_tool -D /dev/ttyUSBXXX -i inc -f ui_app.aot
```
The graphic user interface demo photo:
![WAMR samples diagram](../../doc/pics/vgl_demo.png "WAMR samples diagram")

View File

@ -1,75 +0,0 @@
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#!/bin/bash
PROJECT_DIR=$PWD
WAMR_DIR=${PWD}/../..
OUT_DIR=${PWD}/out
BUILD_DIR=${PWD}/build
WAMR_RUNTIME_CFG=${PROJECT_DIR}/wamr_config_gui.cmake
LV_CFG_PATH=${PROJECT_DIR}/lv_config
if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then
echo "Local Build Env"
cmakewrap="cmake"
makewrap="make"
else
echo "Klocwork Build Env"
cmakewrap="cmake -DCMAKE_BUILD_TYPE=Debug"
makewrap="kwinject -o $KW_OUT_FILE make"
fi
if [ ! -d $BUILD_DIR ]; then
mkdir ${BUILD_DIR}
fi
rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
echo -e "\n\n"
echo "##################### 1. build wamr-sdk gui start#####################"
cd ${WAMR_DIR}/wamr-sdk
./build_sdk.sh -n gui -x ${WAMR_RUNTIME_CFG} -e ${LV_CFG_PATH}
[ $? -eq 0 ] || exit $?
echo "#####################build wamr-sdk success"
echo "##################### 2. build wasm runtime start#####################"
cd $BUILD_DIR
mkdir -p wasm-runtime-wgl
cd wasm-runtime-wgl
$cmakewrap ${PROJECT_DIR}/wasm-runtime-wgl/linux-build -DWAMR_BUILD_SDK_PROFILE=gui
[ $? -eq 0 ] || exit $?
$makewrap
[ $? -eq 0 ] || exit $?
cp wasm_runtime_wgl ${OUT_DIR}/
echo "##################### build littlevgl wasm runtime end#####################"
echo -e "\n\n"
echo "#####################build host-tool"
cd $BUILD_DIR
mkdir -p host-tool
cd host-tool
$cmakewrap ${WAMR_DIR}/test-tools/host-tool
$makewrap
if [ $? != 0 ];then
echo "BUILD_FAIL host tool exit as $?\n"
exit 2
fi
cp host_tool ${OUT_DIR}
echo "#####################build host-tool success"
echo -e "\n\n"
echo "##################### 3. build wasm ui app start#####################"
cd ${PROJECT_DIR}/wasm-apps
export OUT_DIR=${OUT_DIR}
./build_apps.sh

View File

@ -1,498 +0,0 @@
/**
* @file lv_conf.h
*
*/
/*
* COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER
*/
#if 1 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/* clang-format off */
#include <stdint.h>
/*====================
Graphical settings
*====================*/
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX (320)
#define LV_VER_RES_MAX (240)
/* Color depth:
* - 1: 1 byte per pixel
* - 8: RGB233
* - 16: RGB565
* - 32: ARGB8888
*/
#define LV_COLOR_DEPTH 32
/* Swap the 2 bytes of RGB565 color.
* Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP 0
/* 1: Enable screen transparency.
* Useful for OSD or other overlapping GUIs.
* Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/
#define LV_COLOR_SCREEN_TRANSP 0
/*Images pixels with this color will not be drawn (with chroma keying)*/
#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#define LV_ANTIALIAS 1
/* Default display refresh period.
* Can be changed in the display driver (`lv_disp_drv_t`).*/
#define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/
/* Dot Per Inch: used to initialize default sizes.
* E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI 100 /*[px]*/
/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
typedef int16_t lv_coord_t;
/*=========================
Memory manager settings
*=========================*/
/* LittelvGL's internal memory manager's settings.
* The graphical objects and other related data are stored here. */
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#ifndef LV_MEM_CUSTOM
#define LV_MEM_CUSTOM 0
#endif
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (128U * 1024U)
/* Complier prefix for a big array declaration */
# define LV_MEM_ATTR
/* Set an address for the memory pool instead of allocating it as an array.
* Can be in external SRAM too. */
# define LV_MEM_ADR 0
/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
# define LV_MEM_AUTO_DEFRAG 1
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE "bh_platform.h" /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC BH_MALLOC /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE BH_FREE /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher level language and the memory is managed by that language */
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
#endif /* LV_ENABLE_GC */
/*=======================
Input device settings
*=======================*/
/* Input device default settings.
* Can be changed in the Input device driver (`lv_indev_drv_t`)*/
/* Input device read period in milliseconds */
#define LV_INDEV_DEF_READ_PERIOD 30
/* Drag threshold in pixels */
#define LV_INDEV_DEF_DRAG_LIMIT 10
/* Drag throw slow-down in [%]. Greater value -> faster slow-down */
#define LV_INDEV_DEF_DRAG_THROW 20
/* Long press time in milliseconds.
* Time to send `LV_EVENT_LONG_PRESSSED`) */
#define LV_INDEV_DEF_LONG_PRESS_TIME 400
/* Repeated trigger period in long press [ms]
* Time between `LV_EVENT_LONG_PRESSED_REPEAT */
#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100
/*==================
* Feature usage
*==================*/
/*1: Enable the Animations */
#define LV_USE_ANIMATION 1
#if LV_USE_ANIMATION
/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_anim_user_data_t;
#endif
/* 1: Enable shadow drawing*/
#define LV_USE_SHADOW 1
/* 1: Enable object groups (for keyboard/encoder navigation) */
#define LV_USE_GROUP 1
#if LV_USE_GROUP
typedef void * lv_group_user_data_t;
#endif /*LV_USE_GROUP*/
/* 1: Enable GPU interface*/
#define LV_USE_GPU 1
/* 1: Enable file system (might be required for images */
#define LV_USE_FILESYSTEM 1
#if LV_USE_FILESYSTEM
/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_fs_drv_user_data_t;
#endif
/*1: Add a `user_data` to drivers and objects*/
#define LV_USE_USER_DATA 1
/*========================
* Image decoder and cache
*========================*/
/* 1: Enable indexed (palette) images */
#define LV_IMG_CF_INDEXED 1
/* 1: Enable alpha indexed images */
#define LV_IMG_CF_ALPHA 1
/* Default image cache size. Image caching keeps the images opened.
* If only the built-in image formats are used there is no real advantage of caching.
* (I.e. no new image decoder is added)
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
* However the opened images might consume additional RAM.
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
#define LV_IMG_CACHE_DEF_SIZE 1
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_img_decoder_user_data_t;
/*=====================
* Compiler settings
*====================*/
/* Define a custom attribute to `lv_tick_inc` function */
#define LV_ATTRIBUTE_TICK_INC
/* Define a custom attribute to `lv_task_handler` function */
#define LV_ATTRIBUTE_TASK_HANDLER
/* With size optimization (-Os) the compiler might not align data to
* 4 or 8 byte boundary. This alignment will be explicitly applied where needed.
* E.g. __attribute__((aligned(4))) */
#define LV_ATTRIBUTE_MEM_ALIGN
/* Attribute to mark large constant arrays for example
* font's bitmaps */
#define LV_ATTRIBUTE_LARGE_CONST
/*===================
* HAL settings
*==================*/
/* 1: use a custom tick source.
* It removes the need to manually update the tick with `lv_tick_inc`) */
#define LV_TICK_CUSTOM 1
#if LV_TICK_CUSTOM == 1
#define LV_TICK_CUSTOM_INCLUDE "system_header.h" /*Header for the sys time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (time_get_ms()) /*Expression evaluating to current systime in ms*/
#endif /*LV_TICK_CUSTOM*/
typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/
typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/
/*================
* Log settings
*===============*/
/*1: Enable the log module*/
#define LV_USE_LOG 1
#if LV_USE_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
* LV_LOG_LEVEL_NONE Do not log anything
*/
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
/* 1: Print the log with 'printf';
* 0: user need to register a callback with `lv_log_register_print`*/
# define LV_LOG_PRINTF 1
#endif /*LV_USE_LOG*/
/*================
* THEME USAGE
*================*/
#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#define LV_USE_THEME_TEMPL 1 /*Just for test*/
#define LV_USE_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#define LV_USE_THEME_ALIEN 1 /*Dark futuristic theme*/
#define LV_USE_THEME_NIGHT 1 /*Dark elegant theme*/
#define LV_USE_THEME_MONO 1 /*Mono color theme for monochrome displays*/
#define LV_USE_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/
#define LV_USE_THEME_ZEN 1 /*Peaceful, mainly light theme */
#define LV_USE_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/
/*==================
* FONT USAGE
*===================*/
/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel.
* The symbols are available via `LV_SYMBOL_...` defines
* More info about fonts: https://docs.littlevgl.com/#Fonts
* To create a new font go to: https://littlevgl.com/ttf-font-to-c-array
*/
/* Robot fonts with bpp = 4
* https://fonts.google.com/specimen/Roboto */
#define LV_FONT_ROBOTO_12 1
#define LV_FONT_ROBOTO_16 1
#define LV_FONT_ROBOTO_22 1
#define LV_FONT_ROBOTO_28 1
/*Pixel perfect monospace font
* http://pelulamu.net/unscii/ */
#define LV_FONT_UNSCII_8 1
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2)
*/
#define LV_FONT_CUSTOM_DECLARE
/*Always set a default font from the built-in fonts*/
#define LV_FONT_DEFAULT &lv_font_roboto_16
/* Enable it if you have fonts with a lot of characters.
* The limit depends on the font size, font face and bpp
* but with > 10,000 characters if you see issues probably you need to enable it.*/
#define LV_FONT_FMT_TXT_LARGE 1
/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_font_user_data_t;
/*=================
* Text settings
*=================*/
/* Select a character encoding for strings.
* Your IDE or editor should have the same character encoding
* - LV_TXT_ENC_UTF8
* - LV_TXT_ENC_ASCII
* */
#define LV_TXT_ENC LV_TXT_ENC_UTF8
/*Can break (wrap) texts on these chars*/
#define LV_TXT_BREAK_CHARS " ,.;:-_"
/*===================
* LV_OBJ SETTINGS
*==================*/
/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_obj_user_data_t;
/*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
#define LV_USE_OBJ_REALIGN 1
/* Enable to make the object clickable on a larger area.
* LV_EXT_CLICK_AREA_OFF or 0: Disable this feature
* LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px)
* LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px)
*/
#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_FULL
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
*/
/*Arc (dependencies: -)*/
#define LV_USE_ARC 1
/*Bar (dependencies: -)*/
#define LV_USE_BAR 1
/*Button (dependencies: lv_cont*/
#define LV_USE_BTN 1
#if LV_USE_BTN != 0
/*Enable button-state animations - draw a circle on click (dependencies: LV_USE_ANIMATION)*/
# define LV_BTN_INK_EFFECT 1
#endif
/*Button matrix (dependencies: -)*/
#define LV_USE_BTNM 1
/*Calendar (dependencies: -)*/
#define LV_USE_CALENDAR 1
/*Canvas (dependencies: lv_img)*/
#define LV_USE_CANVAS 1
/*Check box (dependencies: lv_btn, lv_label)*/
#define LV_USE_CB 1
/*Chart (dependencies: -)*/
#define LV_USE_CHART 1
#if LV_USE_CHART
# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 20
#endif
/*Container (dependencies: -*/
#define LV_USE_CONT 1
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#define LV_USE_DDLIST 1
#if LV_USE_DDLIST != 0
/*Open and close default animation time [ms] (0: no animation)*/
# define LV_DDLIST_DEF_ANIM_TIME 200
#endif
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
#define LV_USE_GAUGE 1
/*Image (dependencies: lv_label*/
#define LV_USE_IMG 1
/*Image Button (dependencies: lv_btn*/
#define LV_USE_IMGBTN 1
#if LV_USE_IMGBTN
/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
# define LV_IMGBTN_TILED 0
#endif
/*Keyboard (dependencies: lv_btnm)*/
#define LV_USE_KB 1
/*Label (dependencies: -*/
#define LV_USE_LABEL 1
#if LV_USE_LABEL != 0
/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/
# define LV_LABEL_DEF_SCROLL_SPEED 25
/* Waiting period at beginning/end of animation cycle */
# define LV_LABEL_WAIT_CHAR_COUNT 3
/*Enable selecting text of the label */
# define LV_LABEL_TEXT_SEL 1
/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/
# define LV_LABEL_LONG_TXT_HINT 0
#endif
/*LED (dependencies: -)*/
#define LV_USE_LED 1
/*Line (dependencies: -*/
#define LV_USE_LINE 1
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#define LV_USE_LIST 1
#if LV_USE_LIST != 0
/*Default animation time of focusing to a list element [ms] (0: no animation) */
# define LV_LIST_DEF_ANIM_TIME 100
#endif
/*Line meter (dependencies: *;)*/
#define LV_USE_LMETER 1
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#define LV_USE_MBOX 1
/*Page (dependencies: lv_cont)*/
#define LV_USE_PAGE 1
#if LV_USE_PAGE != 0
/*Focus default animation time [ms] (0: no animation)*/
# define LV_PAGE_DEF_ANIM_TIME 400
#endif
/*Preload (dependencies: lv_arc, lv_anim)*/
#define LV_USE_PRELOAD 1
#if LV_USE_PRELOAD != 0
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
#endif
/*Roller (dependencies: lv_ddlist)*/
#define LV_USE_ROLLER 1
#if LV_USE_ROLLER != 0
/*Focus animation time [ms] (0: no animation)*/
# define LV_ROLLER_DEF_ANIM_TIME 200
/*Number of extra "pages" when the roller is infinite*/
# define LV_ROLLER_INF_PAGES 7
#endif
/*Slider (dependencies: lv_bar)*/
#define LV_USE_SLIDER 1
/*Spinbox (dependencies: lv_ta)*/
#define LV_USE_SPINBOX 1
/*Switch (dependencies: lv_slider)*/
#define LV_USE_SW 1
/*Text area (dependencies: lv_label, lv_page)*/
#define LV_USE_TA 1
#if LV_USE_TA != 0
# define LV_TA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
/*Table (dependencies: lv_label)*/
#define LV_USE_TABLE 1
#if LV_USE_TABLE
# define LV_TABLE_COL_MAX 12
#endif
/*Tab (dependencies: lv_page, lv_btnm)*/
#define LV_USE_TABVIEW 1
# if LV_USE_TABVIEW != 0
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TABVIEW_DEF_ANIM_TIME 300
#endif
/*Tileview (dependencies: lv_page) */
#define LV_USE_TILEVIEW 1
#if LV_USE_TILEVIEW
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TILEVIEW_DEF_ANIM_TIME 300
#endif
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#define LV_USE_WIN 1
/*==================
* Non-user section
*==================*/
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
# define _CRT_SECURE_NO_WARNINGS
#endif
/*--END OF LV_CONF_H--*/
/*Be sure every define has a default value*/
#include "lvgl/src/lv_conf_checker.h"
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -1,310 +0,0 @@
/**
* @file lv_drv_conf.h
*
*/
/*
* COPY THIS FILE AS lv_drv_conf.h
*/
#if 1 /*Set it to "1" to enable the content*/
#ifndef LV_DRV_CONF_H
#define LV_DRV_CONF_H
#include "lv_conf.h"
/*********************
* DELAY INTERFACE
*********************/
#define LV_DRV_DELAY_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/
#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/
/*********************
* DISPLAY INTERFACE
*********************/
/*------------
* Common
*------------*/
#define LV_DRV_DISP_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/
#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
/*---------
* SPI
*---------*/
#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/
#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/
/*------------------
* Parallel port
*-----------------*/
#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/
#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/
#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/
#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/
#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/
/***************************
* INPUT DEVICE INTERFACE
***************************/
/*----------
* Common
*----------*/
#define LV_DRV_INDEV_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/
/*---------
* SPI
*---------*/
#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/
/*---------
* I2C
*---------*/
#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/
#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/
#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/
#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/
#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/
/*********************
* DISPLAY DRIVERS
*********************/
/*-------------------
* Monitor of PC
*-------------------*/
#ifndef USE_MONITOR
# define USE_MONITOR 1
#endif
#if USE_MONITOR
# define MONITOR_HOR_RES LV_HOR_RES_MAX
# define MONITOR_VER_RES LV_VER_RES_MAX
/* Scale window by this factor (useful when simulating small screens) */
# define MONITOR_ZOOM 1
/* Used to test true double buffering with only address changing.
* Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */
# define MONITOR_DOUBLE_BUFFERED 0
/*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
# define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Different rendering might be used if running in a Virtual machine*/
# define MONITOR_VIRTUAL_MACHINE 0
/*Open two windows to test multi display support*/
# define MONITOR_DUAL 0
#endif
/*-----------------------------------
* Native Windows (including mouse)
*----------------------------------*/
#ifndef USE_WINDOWS
# define USE_WINDOWS 0
#endif
#define USE_WINDOWS 0
#if USE_WINDOWS
# define WINDOW_HOR_RES 480
# define WINDOW_VER_RES 320
#endif
/*----------------
* SSD1963
*--------------*/
#ifndef USE_SSD1963
# define USE_SSD1963 0
#endif
#if USE_SSD1963
# define SSD1963_HOR_RES LV_HOR_RES
# define SSD1963_VER_RES LV_VER_RES
# define SSD1963_HT 531
# define SSD1963_HPS 43
# define SSD1963_LPS 8
# define SSD1963_HPW 10
# define SSD1963_VT 288
# define SSD1963_VPS 12
# define SSD1963_FPS 4
# define SSD1963_VPW 10
# define SSD1963_HS_NEG 0 /*Negative hsync*/
# define SSD1963_VS_NEG 0 /*Negative vsync*/
# define SSD1963_ORI 0 /*0, 90, 180, 270*/
# define SSD1963_COLOR_DEPTH 16
#endif
/*----------------
* R61581
*--------------*/
#ifndef USE_R61581
# define USE_R61581 0
#endif
#if USE_R61581
# define R61581_HOR_RES LV_HOR_RES
# define R61581_VER_RES LV_VER_RES
# define R61581_HSPL 0 /*HSYNC signal polarity*/
# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/
# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/
# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */
# define R61581_VSPL 0 /*VSYNC signal polarity*/
# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/
# define R61581_VFP 8 /*Vertical Front poarch*/
# define R61581_VBP 8 /*Vertical Back poarch */
# define R61581_DPL 0 /*DCLK signal polarity*/
# define R61581_EPL 1 /*ENABLE signal polarity*/
# define R61581_ORI 0 /*0, 180*/
# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/
#endif
/*------------------------------
* ST7565 (Monochrome, low res.)
*-----------------------------*/
#ifndef USE_ST7565
# define USE_ST7565 0
#endif
#if USE_ST7565
/*No settings*/
#endif /*USE_ST7565*/
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
#ifndef USE_FBDEV
# define USE_FBDEV 1
#endif
#if USE_FBDEV
# define FBDEV_PATH "/dev/fb0"
#endif
/*********************
* INPUT DEVICES
*********************/
/*--------------
* XPT2046
*--------------*/
#ifndef USE_XPT2046
# define USE_XPT2046 0
#endif
#if USE_XPT2046
# define XPT2046_HOR_RES 480
# define XPT2046_VER_RES 320
# define XPT2046_X_MIN 200
# define XPT2046_Y_MIN 200
# define XPT2046_X_MAX 3800
# define XPT2046_Y_MAX 3800
# define XPT2046_AVG 4
# define XPT2046_INV 0
#endif
/*-----------------
* FT5406EE8
*-----------------*/
#ifndef USE_FT5406EE8
# define USE_FT5406EE8 0
#endif
#if USE_FT5406EE8
# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/
#endif
/*---------------
* AD TOUCH
*--------------*/
#ifndef USE_AD_TOUCH
# define USE_AD_TOUCH 0
#endif
#if USE_AD_TOUCH
/*No settings*/
#endif
/*---------------------------------------
* Mouse or touchpad on PC (using SDL)
*-------------------------------------*/
#ifndef USE_MOUSE
# define USE_MOUSE 1
#endif
#if USE_MOUSE
/*No settings*/
#endif
/*-------------------------------------------
* Mousewheel as encoder on PC (using SDL)
*------------------------------------------*/
#ifndef USE_MOUSEWHEEL
# define USE_MOUSEWHEEL 1
#endif
#if USE_MOUSEWHEEL
/*No settings*/
#endif
/*-------------------------------------------------
* Touchscreen as libinput interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_LIBINPUT
# define USE_LIBINPUT 0
#endif
#if USE_LIBINPUT
# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
#endif /*USE_LIBINPUT*/
/*-------------------------------------------------
* Mouse or touchpad as evdev interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_EVDEV
# define USE_EVDEV 0
#endif
#if USE_EVDEV
# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */
# if EVDEV_SCALE
# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */
# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */
# endif /*EVDEV_SCALE*/
# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
# if EVDEV_CALIBRATE
# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
# define EVDEV_HOR_MAX 200
# define EVDEV_VER_MIN 200
# define EVDEV_VER_MAX 3800
# endif /*EVDEV_SCALE*/
#endif /*USE_EVDEV*/
/*-------------------------------
* Keyboard of a PC (using SDL)
*------------------------------*/
#ifndef USE_KEYBOARD
# define USE_KEYBOARD 1
#endif
#if USE_KEYBOARD
/*No settings*/
#endif
#endif /*LV_DRV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -1,9 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
int
time_get_ms();

View File

@ -1,9 +0,0 @@
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET "X86_64")
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_ALL)

View File

@ -1,45 +0,0 @@
#!/bin/bash
APPS_ROOT=$(cd "$(dirname "$0")/" && pwd)
cd ${APPS_ROOT}
echo "OUT_DIR: ${OUT_DIR}"
if [ -z ${OUT_DIR} ]; then
OUT_DIR=${APPS_ROOT}/out
echo "set the wasm app folder: ${OUT_DIR}"
if [ -d ${OUT_DIR} ]; then
rm -rf ${OUT_DIR}
echo "removed the present output folder: ${OUT_DIR}"
fi
mkdir ${OUT_DIR}
fi
if [ -z ${WAMR_DIR} ]; then
WAMR_DIR=${APPS_ROOT}/../../..
fi
cd ${APPS_ROOT}/increase
rm -rf build
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=${WAMR_DIR}/wamr-sdk/out/gui/app-sdk/wamr_toolchain.cmake \
-DWASI_SDK_DIR=/opt/wasi-sdk
make
[ $? -eq 0 ] || exit $?
mv ui_increase.wasm ${OUT_DIR}/
# $makewrap
# mv ui_app.wasm ${OUT_DIR}/
cd ${APPS_ROOT}/decrease
make
[ $? -eq 0 ] || exit $?
mv ui_decrease.wasm ${OUT_DIR}/
echo "WASM files generated in folder ${OUT_DIR}"
echo "##################### build WASM APPs finished #####################"

View File

@ -1,29 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = /opt/wasi-sdk/bin/clang
APP_DIR = ${shell pwd}
IWASM_DIR = $(APP_DIR)/../../../../core/iwasm
SDK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk
APP_FRAMEWORK_DIR = $(APP_DIR)/../../../../wamr-sdk/out/gui/app-sdk/wamr-app-framework
DEPS_DIR = $(APP_DIR)/../../../../core/deps
CFLAGS += -O3 \
-Wno-int-conversion \
-I$(APP_DIR)/src \
-I$(APP_FRAMEWORK_DIR)/include \
-I${DEPS_DIR}
SRCS += $(APP_DIR)/src/main.c
all:
@$(CC) $(CFLAGS) $(SRCS) \
--target=wasm32 -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
--sysroot=$(SDK_DIR)/libc-builtin-sysroot \
-L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \
-Wl,--allow-undefined-file=$(SDK_DIR)/libc-builtin-sysroot/share/defined-symbols.txt \
-Wl,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_timer_callback \
-Wl,--export=on_widget_event \
-Wl,--export=__heap_base,--export=__data_end \
-o ui_decrease.wasm

View File

@ -1,20 +0,0 @@
cmake_minimum_required(VERSION 2.8)
project(wgl)
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/gui/app-sdk/wamr-app-framework/include
${WAMR_ROOT_DIR}/core/deps
)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},-L${WAMR_ROOT_DIR}/wamr-sdk/out/gui/app-sdk/wamr-app-framework/lib")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS},--export=on_init,--export=on_timer_callback,--export=on_widget_event,--export=__heap_base,--export=__data_end")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-unused-command-line-argument")
add_executable(ui_increase.wasm
${CMAKE_CURRENT_LIST_DIR}/src/main.c
)
target_link_libraries(ui_increase.wasm app_framework)

View File

@ -1,34 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = /opt/wasi-sdk/bin/clang
APP_DIR = ${shell pwd}
IWASM_DIR = ../../../../core/iwasm
APP_FRAMEWORK_DIR = ../../../../core/app-framework
DEPS_DIR = ../../../../core/deps
CFLAGS += -O3 \
-Wno-int-conversion \
-I$(APP_DIR)/src \
-I$(APP_FRAMEWORK_DIR)/base/app \
-I$(APP_FRAMEWORK_DIR)/app-native-shared \
-I$(APP_FRAMEWORK_DIR)/sensor/app \
-I$(APP_FRAMEWORK_DIR)/wgl/app \
-I$(APP_FRAMEWORK_DIR)/connection/app \
-I${DEPS_DIR}
SRCS += $(APP_DIR)/src/main.c
# For app size consideration, not all but necessary app libs are included
SRCS += $(APP_FRAMEWORK_DIR)/base/app/timer.c
SRCS += $(APP_FRAMEWORK_DIR)/wgl/app/src/*.c
all:
@$(CC) $(CFLAGS) $(SRCS) \
--target=wasm32-wasi -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-nostdlib -Wl,--allow-undefined \
-Wl,--strip-all,--no-entry \
-Wl,--export=on_init -Wl,--export=on_timer_callback \
-Wl,--export=on_widget_event \
-Wl,--export=__heap_base,--export=__data_end \
-o ui_app.wasm

View File

@ -1,54 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.9)
project (wasm_runtime_wgl)
set (WAMR_BUILD_PLATFORM "linux")
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
################ wamr runtime settings ################
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps)
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
## use library and headers in the SDK
link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/lib)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/include
${WAMR_ROOT_DIR}/wamr-sdk/out/gui/runtime-sdk/include/bi-inc/deps
${WAMR_ROOT_DIR}/core/shared/utils
${WAMR_ROOT_DIR}/core/shared/platform/${WAMR_BUILD_PLATFORM}
)
################ application related ################
set (LV_DRIVERS_DIR ${WAMR_ROOT_DIR}/core/deps/lv_drivers)
file (GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c")
set (PROJECT_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../src/platform/${WAMR_BUILD_PLATFORM})
include_directories(
${PROJECT_SRC_DIR}
${DEPS_DIR}
${DEPS_DIR}/lvgl
${DEPS_DIR}/lvgl/src
)
set (SOURCES
${PROJECT_SRC_DIR}/main.c
${PROJECT_SRC_DIR}/iwasm_main.c
${LV_DRIVERS_SOURCES}
)
add_executable (wasm_runtime_wgl ${SOURCES})
target_link_libraries (wasm_runtime_wgl vmlib -lm -ldl -lpthread -lSDL2)
#target_link_libraries(wasm_runtime_wgl PRIVATE SDL2 )

View File

@ -1,564 +0,0 @@
#ifndef CONNECTION_UART
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#else
#include <termios.h>
#endif
#include <arpa/inet.h>
#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <fcntl.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <strings.h>
#include "runtime_lib.h"
#include "runtime_timer.h"
#include "native_interface.h"
#include "app_manager_export.h"
#include "bh_platform.h"
#include "runtime_sensor.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#include "wgl.h"
#include "lv_drivers/display/monitor.h"
#include "lv_drivers/indev/mouse.h"
#define MAX 2048
#ifndef CONNECTION_UART
#define SA struct sockaddr
static char *host_address = "127.0.0.1";
static int port = 8888;
#else
static char *uart_device = "/dev/ttyS2";
static int baudrate = B115200;
#endif
extern bool
init_sensor_framework();
extern void
exit_sensor_framework();
extern void
exit_connection_framework();
extern int
aee_host_msg_callback(void *msg, uint32_t msg_len);
extern bool
init_connection_framework();
#ifndef CONNECTION_UART
int listenfd = -1;
int sockfd = -1;
static pthread_mutex_t sock_lock = PTHREAD_MUTEX_INITIALIZER;
#else
int uartfd = -1;
#endif
#ifndef CONNECTION_UART
static bool server_mode = false;
// Function designed for chat between client and server.
void *
func(void *arg)
{
char buff[MAX];
int n;
struct sockaddr_in servaddr;
while (1) {
if (sockfd != -1)
close(sockfd);
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printf("socket creation failed...\n");
return NULL;
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr(host_address);
servaddr.sin_port = htons(port);
// connect the client socket to server socket
if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n");
sleep(10);
continue;
}
else {
printf("connected to the server..\n");
}
// infinite loop for chat
for (;;) {
bzero(buff, MAX);
// read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents
// fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
// socket disconnected
if (n <= 0)
break;
aee_host_msg_callback(buff, n);
}
}
// After chatting close the socket
close(sockfd);
}
static bool
host_init()
{
return true;
}
int
host_send(void *ctx, const char *buf, int size)
{
int ret;
if (pthread_mutex_trylock(&sock_lock) == 0) {
if (sockfd == -1) {
pthread_mutex_unlock(&sock_lock);
return 0;
}
ret = write(sockfd, buf, size);
pthread_mutex_unlock(&sock_lock);
return ret;
}
return -1;
}
void
host_destroy()
{
if (server_mode)
close(listenfd);
pthread_mutex_lock(&sock_lock);
close(sockfd);
pthread_mutex_unlock(&sock_lock);
}
/* clang-format off */
host_interface interface = {
.init = host_init,
.send = host_send,
.destroy = host_destroy
};
/* clang-format on */
void *
func_server_mode(void *arg)
{
int clilent;
struct sockaddr_in serv_addr, cli_addr;
int n;
char buff[MAX];
struct sigaction sa;
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGPIPE, &sa, 0);
/* First call to socket() function */
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (listenfd < 0) {
perror("ERROR opening socket");
exit(1);
}
/* Initialize socket structure */
bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port);
/* Now bind the host address using bind() call.*/
if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("ERROR on binding");
exit(1);
}
listen(listenfd, 5);
clilent = sizeof(cli_addr);
while (1) {
pthread_mutex_lock(&sock_lock);
sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent);
pthread_mutex_unlock(&sock_lock);
if (sockfd < 0) {
perror("ERROR on accept");
exit(1);
}
printf("connection established!\n");
for (;;) {
bzero(buff, MAX);
// read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff));
// socket disconnected
if (n <= 0) {
pthread_mutex_lock(&sock_lock);
close(sockfd);
sockfd = -1;
pthread_mutex_unlock(&sock_lock);
sleep(2);
break;
}
aee_host_msg_callback(buff, n);
}
}
}
#else
static int
parse_baudrate(int baud)
{
switch (baud) {
case 9600:
return B9600;
case 19200:
return B19200;
case 38400:
return B38400;
case 57600:
return B57600;
case 115200:
return B115200;
case 230400:
return B230400;
case 460800:
return B460800;
case 500000:
return B500000;
case 576000:
return B576000;
case 921600:
return B921600;
case 1000000:
return B1000000;
case 1152000:
return B1152000;
case 1500000:
return B1500000;
case 2000000:
return B2000000;
case 2500000:
return B2500000;
case 3000000:
return B3000000;
case 3500000:
return B3500000;
case 4000000:
return B4000000;
default:
return -1;
}
}
static bool
uart_init(const char *device, int baudrate, int *fd)
{
int uart_fd;
struct termios uart_term;
uart_fd = open(device, O_RDWR | O_NOCTTY);
if (uart_fd <= 0)
return false;
memset(&uart_term, 0, sizeof(uart_term));
uart_term.c_cflag = baudrate | CS8 | CLOCAL | CREAD;
uart_term.c_iflag = IGNPAR;
uart_term.c_oflag = 0;
/* set noncanonical mode */
uart_term.c_lflag = 0;
uart_term.c_cc[VTIME] = 30;
uart_term.c_cc[VMIN] = 1;
tcflush(uart_fd, TCIFLUSH);
if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) {
close(uart_fd);
return false;
}
*fd = uart_fd;
return true;
}
static void *
func_uart_mode(void *arg)
{
int n;
char buff[MAX];
if (!uart_init(uart_device, baudrate, &uartfd)) {
printf("open uart fail! %s\n", uart_device);
return NULL;
}
for (;;) {
bzero(buff, MAX);
n = read(uartfd, buff, sizeof(buff));
if (n <= 0) {
close(uartfd);
uartfd = -1;
break;
}
aee_host_msg_callback(buff, n);
}
return NULL;
}
static int
uart_send(void *ctx, const char *buf, int size)
{
int ret;
ret = write(uartfd, buf, size);
return ret;
}
static void
uart_destroy()
{
close(uartfd);
}
/* clang-format off */
static host_interface interface = {
.send = uart_send,
.destroy = uart_destroy
};
/* clang-format on */
#endif
static char global_heap_buf[270 * 1024] = { 0 };
/* clang-format off */
static void showUsage()
{
#ifndef CONNECTION_UART
printf("Usage:\n");
printf("\nWork as TCP server mode:\n");
printf("\tvgl_wasm_runtime -s|--server_mode -p|--port <Port>\n");
printf("where\n");
printf("\t<Port> represents the port that would be listened on and the default is 8888\n");
printf("\nWork as TCP client mode:\n");
printf("\tvgl_wasm_runtime -a|--host_address <Host Address> -p|--port <Port>\n");
printf("where\n");
printf("\t<Host Address> represents the network address of host and the default is 127.0.0.1\n");
printf("\t<Port> represents the listen port of host and the default is 8888\n");
#else
printf("Usage:\n");
printf("\tvgl_wasm_runtime -u <Uart Device> -b <Baudrate>\n\n");
printf("where\n");
printf("\t<Uart Device> represents the UART device name and the default is /dev/ttyS2\n");
printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n");
#endif
}
/* clang-format on */
static bool
parse_args(int argc, char *argv[])
{
int c;
while (1) {
int optIndex = 0;
static struct option longOpts[] = {
#ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' },
{ "port", required_argument, NULL, 'p' },
#else
{ "uart", required_argument, NULL, 'u' },
{ "baudrate", required_argument, NULL, 'b' },
#endif
{ "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "sa:p:u:b:h", longOpts, &optIndex);
if (c == -1)
break;
switch (c) {
#ifndef CONNECTION_UART
case 's':
server_mode = true;
break;
case 'a':
host_address = optarg;
printf("host address: %s\n", host_address);
break;
case 'p':
port = atoi(optarg);
printf("port: %d\n", port);
break;
#else
case 'u':
uart_device = optarg;
printf("uart device: %s\n", uart_device);
break;
case 'b':
baudrate = parse_baudrate(atoi(optarg));
printf("uart baudrate: %s\n", optarg);
break;
#endif
case 'h':
showUsage();
return false;
default:
showUsage();
return false;
}
}
return true;
}
/**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics
* library
*/
static void
hal_init(void)
{
/* Use the 'monitor' driver which creates window on PC's monitor to simulate
* a display*/
monitor_init();
/*Create a display buffer*/
static lv_disp_buf_t disp_buf1;
static lv_color_t buf1_1[480 * 10];
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 480 * 10);
/*Create a display*/
lv_disp_drv_t disp_drv;
/*Basic initialization*/
memset(&disp_drv, 0, sizeof(disp_drv));
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf1;
disp_drv.flush_cb = monitor_flush;
// disp_drv.hor_res = 200;
// disp_drv.ver_res = 100;
lv_disp_drv_register(&disp_drv);
/* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse*/
mouse_init();
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb =
mouse_read; /*This function will be called periodically (by the library)
to get the mouse position and state*/
lv_indev_drv_register(&indev_drv);
}
// Driver function
int
iwasm_main(int argc, char *argv[])
{
RuntimeInitArgs init_args;
korp_tid tid;
if (!parse_args(argc, argv))
return -1;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
printf("Init runtime environment failed.\n");
return -1;
}
if (!init_connection_framework()) {
goto fail1;
}
wgl_init();
hal_init();
if (!init_sensor_framework()) {
goto fail2;
}
/* timer manager */
if (!init_wasm_timer()) {
goto fail3;
}
#ifndef CONNECTION_UART
if (server_mode)
os_thread_create(&tid, func_server_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
else
os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
#else
os_thread_create(&tid, func_uart_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
#endif
app_manager_startup(&interface);
exit_wasm_timer();
fail3:
exit_sensor_framework();
fail2:
wgl_exit();
exit_connection_framework();
fail1:
wasm_runtime_destroy();
return -1;
}

View File

@ -1,310 +0,0 @@
/**
* @file lv_drv_conf.h
*
*/
/*
* COPY THIS FILE AS lv_drv_conf.h
*/
#if 1 /*Set it to "1" to enable the content*/
#ifndef LV_DRV_CONF_H
#define LV_DRV_CONF_H
#include "lv_conf.h"
/*********************
* DELAY INTERFACE
*********************/
#define LV_DRV_DELAY_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/
#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/
/*********************
* DISPLAY INTERFACE
*********************/
/*------------
* Common
*------------*/
#define LV_DRV_DISP_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/
#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
/*---------
* SPI
*---------*/
#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/
#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/
/*------------------
* Parallel port
*-----------------*/
#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/
#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/
#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/
#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/
#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/
/***************************
* INPUT DEVICE INTERFACE
***************************/
/*----------
* Common
*----------*/
#define LV_DRV_INDEV_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/
/*---------
* SPI
*---------*/
#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/
/*---------
* I2C
*---------*/
#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/
#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/
#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/
#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/
#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/
/*********************
* DISPLAY DRIVERS
*********************/
/*-------------------
* Monitor of PC
*-------------------*/
#ifndef USE_MONITOR
# define USE_MONITOR 1
#endif
#if USE_MONITOR
# define MONITOR_HOR_RES LV_HOR_RES_MAX
# define MONITOR_VER_RES LV_VER_RES_MAX
/* Scale window by this factor (useful when simulating small screens) */
# define MONITOR_ZOOM 1
/* Used to test true double buffering with only address changing.
* Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */
# define MONITOR_DOUBLE_BUFFERED 0
/*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
# define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Different rendering might be used if running in a Virtual machine*/
# define MONITOR_VIRTUAL_MACHINE 0
/*Open two windows to test multi display support*/
# define MONITOR_DUAL 0
#endif
/*-----------------------------------
* Native Windows (including mouse)
*----------------------------------*/
#ifndef USE_WINDOWS
# define USE_WINDOWS 0
#endif
#define USE_WINDOWS 0
#if USE_WINDOWS
# define WINDOW_HOR_RES 480
# define WINDOW_VER_RES 320
#endif
/*----------------
* SSD1963
*--------------*/
#ifndef USE_SSD1963
# define USE_SSD1963 0
#endif
#if USE_SSD1963
# define SSD1963_HOR_RES LV_HOR_RES
# define SSD1963_VER_RES LV_VER_RES
# define SSD1963_HT 531
# define SSD1963_HPS 43
# define SSD1963_LPS 8
# define SSD1963_HPW 10
# define SSD1963_VT 288
# define SSD1963_VPS 12
# define SSD1963_FPS 4
# define SSD1963_VPW 10
# define SSD1963_HS_NEG 0 /*Negative hsync*/
# define SSD1963_VS_NEG 0 /*Negative vsync*/
# define SSD1963_ORI 0 /*0, 90, 180, 270*/
# define SSD1963_COLOR_DEPTH 16
#endif
/*----------------
* R61581
*--------------*/
#ifndef USE_R61581
# define USE_R61581 0
#endif
#if USE_R61581
# define R61581_HOR_RES LV_HOR_RES
# define R61581_VER_RES LV_VER_RES
# define R61581_HSPL 0 /*HSYNC signal polarity*/
# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/
# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/
# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */
# define R61581_VSPL 0 /*VSYNC signal polarity*/
# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/
# define R61581_VFP 8 /*Vertical Front poarch*/
# define R61581_VBP 8 /*Vertical Back poarch */
# define R61581_DPL 0 /*DCLK signal polarity*/
# define R61581_EPL 1 /*ENABLE signal polarity*/
# define R61581_ORI 0 /*0, 180*/
# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/
#endif
/*------------------------------
* ST7565 (Monochrome, low res.)
*-----------------------------*/
#ifndef USE_ST7565
# define USE_ST7565 0
#endif
#if USE_ST7565
/*No settings*/
#endif /*USE_ST7565*/
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
#ifndef USE_FBDEV
# define USE_FBDEV 1
#endif
#if USE_FBDEV
# define FBDEV_PATH "/dev/fb0"
#endif
/*********************
* INPUT DEVICES
*********************/
/*--------------
* XPT2046
*--------------*/
#ifndef USE_XPT2046
# define USE_XPT2046 0
#endif
#if USE_XPT2046
# define XPT2046_HOR_RES 480
# define XPT2046_VER_RES 320
# define XPT2046_X_MIN 200
# define XPT2046_Y_MIN 200
# define XPT2046_X_MAX 3800
# define XPT2046_Y_MAX 3800
# define XPT2046_AVG 4
# define XPT2046_INV 0
#endif
/*-----------------
* FT5406EE8
*-----------------*/
#ifndef USE_FT5406EE8
# define USE_FT5406EE8 0
#endif
#if USE_FT5406EE8
# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/
#endif
/*---------------
* AD TOUCH
*--------------*/
#ifndef USE_AD_TOUCH
# define USE_AD_TOUCH 0
#endif
#if USE_AD_TOUCH
/*No settings*/
#endif
/*---------------------------------------
* Mouse or touchpad on PC (using SDL)
*-------------------------------------*/
#ifndef USE_MOUSE
# define USE_MOUSE 1
#endif
#if USE_MOUSE
/*No settings*/
#endif
/*-------------------------------------------
* Mousewheel as encoder on PC (using SDL)
*------------------------------------------*/
#ifndef USE_MOUSEWHEEL
# define USE_MOUSEWHEEL 1
#endif
#if USE_MOUSEWHEEL
/*No settings*/
#endif
/*-------------------------------------------------
* Touchscreen as libinput interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_LIBINPUT
# define USE_LIBINPUT 0
#endif
#if USE_LIBINPUT
# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
#endif /*USE_LIBINPUT*/
/*-------------------------------------------------
* Mouse or touchpad as evdev interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_EVDEV
# define USE_EVDEV 0
#endif
#if USE_EVDEV
# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */
# if EVDEV_SCALE
# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */
# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */
# endif /*EVDEV_SCALE*/
# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
# if EVDEV_CALIBRATE
# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
# define EVDEV_HOR_MAX 200
# define EVDEV_VER_MIN 200
# define EVDEV_VER_MAX 3800
# endif /*EVDEV_SCALE*/
#endif /*USE_EVDEV*/
/*-------------------------------
* Keyboard of a PC (using SDL)
*------------------------------*/
#ifndef USE_KEYBOARD
# define USE_KEYBOARD 1
#endif
#if USE_KEYBOARD
/*No settings*/
#endif
#endif /*LV_DRV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -1,25 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <sys/time.h>
extern int
iwasm_main(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
return iwasm_main(argc, argv);
}
int
time_get_ms()
{
static struct timeval tv;
gettimeofday(&tv, NULL);
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
return (int)time_in_mill;
}

View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,65 +0,0 @@
/**
* @file XPT2046.h
*
*/
#ifndef XPT2046_H
#define XPT2046_H
#define USE_XPT2046 1
#define XPT2046_HOR_RES 320
#define XPT2046_VER_RES 240
#define XPT2046_X_MIN 200
#define XPT2046_Y_MIN 200
#define XPT2046_X_MAX 3800
#define XPT2046_Y_MAX 3800
#define XPT2046_AVG 4
#define XPT2046_INV 0
#define CMD_X_READ 0b10010000
#define CMD_Y_READ 0b11010000
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if USE_XPT2046
#include <autoconf.h>
#include <stdint.h>
#include <stdbool.h>
#include "lv_hal/lv_hal_indev.h"
#include "device.h"
#include "drivers/gpio.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void
xpt2046_init(void);
bool
xpt2046_read(lv_indev_data_t *data);
/**********************
* MACROS
**********************/
#endif /* USE_XPT2046 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XPT2046_H */

View File

@ -1,9 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__
#include "pin_config_stm32.h"
#endif /* __BOARD_CONFIG_H__ */

View File

@ -1,418 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Public API for display drivers and applications
*/
#ifndef ZEPHYR_INCLUDE_DISPLAY_H_
#define ZEPHYR_INCLUDE_DISPLAY_H_
/**
* @brief Display Interface
* @defgroup display_interface Display Interface
* @ingroup display_interfaces
* @{
*/
#include <device.h>
#include <stddef.h>
#include <zephyr/types.h>
#ifdef __cplusplus
extern "C" {
#endif
enum display_pixel_format {
PIXEL_FORMAT_RGB_888 = BIT(0),
PIXEL_FORMAT_MONO01 = BIT(1), /* 0=Black 1=White */
PIXEL_FORMAT_MONO10 = BIT(2), /* 1=Black 0=White */
PIXEL_FORMAT_ARGB_8888 = BIT(3),
PIXEL_FORMAT_RGB_565 = BIT(4),
};
enum display_screen_info {
/**
* If selected, one octet represents 8 pixels ordered vertically,
* otherwise ordered horizontally.
*/
SCREEN_INFO_MONO_VTILED = BIT(0),
/**
* If selected, the MSB represents the first pixel,
* otherwise MSB represents the last pixel.
*/
SCREEN_INFO_MONO_MSB_FIRST = BIT(1),
/**
* Electrophoretic Display.
*/
SCREEN_INFO_EPD = BIT(2),
/**
* Screen has two alternating ram buffers
*/
SCREEN_INFO_DOUBLE_BUFFER = BIT(3),
};
/**
* @enum display_orientation
* @brief Enumeration with possible display orientation
*
*/
enum display_orientation {
DISPLAY_ORIENTATION_NORMAL,
DISPLAY_ORIENTATION_ROTATED_90,
DISPLAY_ORIENTATION_ROTATED_180,
DISPLAY_ORIENTATION_ROTATED_270,
};
/**
* @struct display_capabilities
* @brief Structure holding display capabilities
*
* @var u16_t display_capabilities::x_resolution
* Display resolution in the X direction
*
* @var u16_t display_capabilities::y_resolution
* Display resolution in the Y direction
*
* @var u32_t display_capabilities::supported_pixel_formats
* Bitwise or of pixel formats supported by the display
*
* @var u32_t display_capabilities::screen_info
* Information about display panel
*
* @var enum display_pixel_format display_capabilities::current_pixel_format
* Currently active pixel format for the display
*
* @var enum display_orientation display_capabilities::current_orientation
* Current display orientation
*
*/
struct display_capabilities {
u16_t x_resolution;
u16_t y_resolution;
u32_t supported_pixel_formats;
u32_t screen_info;
enum display_pixel_format current_pixel_format;
enum display_orientation current_orientation;
};
/**
* @struct display_buffer_descriptor
* @brief Structure to describe display data buffer layout
*
* @var u32_t display_buffer_descriptor::buf_size
* Data buffer size in bytes
*
* @var u16_t display_buffer_descriptor::width
* Data buffer row width in pixels
*
* @var u16_t display_buffer_descriptor::height
* Data buffer column height in pixels
*
* @var u16_t display_buffer_descriptor::pitch
* Number of pixels between consecutive rows in the data buffer
*
*/
struct display_buffer_descriptor {
u32_t buf_size;
u16_t width;
u16_t height;
u16_t pitch;
};
/**
* @typedef display_blanking_on_api
* @brief Callback API to turn on display blanking
* See display_blanking_on() for argument description
*/
typedef int (*display_blanking_on_api)(const struct device *dev);
/**
* @typedef display_blanking_off_api
* @brief Callback API to turn off display blanking
* See display_blanking_off() for argument description
*/
typedef int (*display_blanking_off_api)(const struct device *dev);
/**
* @typedef display_write_api
* @brief Callback API for writing data to the display
* See display_write() for argument description
*/
typedef int (*display_write_api)(const struct device *dev, const u16_t x,
const u16_t y,
const struct display_buffer_descriptor *desc,
const void *buf);
/**
* @typedef display_read_api
* @brief Callback API for reading data from the display
* See display_read() for argument description
*/
typedef int (*display_read_api)(const struct device *dev, const u16_t x,
const u16_t y,
const struct display_buffer_descriptor *desc,
void *buf);
/**
* @typedef display_get_framebuffer_api
* @brief Callback API to get framebuffer pointer
* See display_get_framebuffer() for argument description
*/
typedef void *(*display_get_framebuffer_api)(const struct device *dev);
/**
* @typedef display_set_brightness_api
* @brief Callback API to set display brightness
* See display_set_brightness() for argument description
*/
typedef int (*display_set_brightness_api)(const struct device *dev,
const u8_t brightness);
/**
* @typedef display_set_contrast_api
* @brief Callback API to set display contrast
* See display_set_contrast() for argument description
*/
typedef int (*display_set_contrast_api)(const struct device *dev,
const u8_t contrast);
/**
* @typedef display_get_capabilities_api
* @brief Callback API to get display capabilities
* See display_get_capabilities() for argument description
*/
typedef void (*display_get_capabilities_api)(
const struct device *dev, struct display_capabilities *capabilities);
/**
* @typedef display_set_pixel_format_api
* @brief Callback API to set pixel format used by the display
* See display_set_pixel_format() for argument description
*/
typedef int (*display_set_pixel_format_api)(
const struct device *dev, const enum display_pixel_format pixel_format);
/**
* @typedef display_set_orientation_api
* @brief Callback API to set orientation used by the display
* See display_set_orientation() for argument description
*/
typedef int (*display_set_orientation_api)(
const struct device *dev, const enum display_orientation orientation);
/**
* @brief Display driver API
* API which a display driver should expose
*/
struct display_driver_api {
display_blanking_on_api blanking_on;
display_blanking_off_api blanking_off;
display_write_api write;
display_read_api read;
display_get_framebuffer_api get_framebuffer;
display_set_brightness_api set_brightness;
display_set_contrast_api set_contrast;
display_get_capabilities_api get_capabilities;
display_set_pixel_format_api set_pixel_format;
display_set_orientation_api set_orientation;
};
extern struct ili9340_data ili9340_data1;
extern struct display_driver_api ili9340_api1;
/**
* @brief Write data to display
*
* @param dev Pointer to device structure
* @param x x Coordinate of the upper left corner where to write the buffer
* @param y y Coordinate of the upper left corner where to write the buffer
* @param desc Pointer to a structure describing the buffer layout
* @param buf Pointer to buffer array
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_write(const struct device *dev, const u16_t x, const u16_t y,
const struct display_buffer_descriptor *desc, const void *buf)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->write(dev, x, y, desc, buf);
}
/**
* @brief Read data from display
*
* @param dev Pointer to device structure
* @param x x Coordinate of the upper left corner where to read from
* @param y y Coordinate of the upper left corner where to read from
* @param desc Pointer to a structure describing the buffer layout
* @param buf Pointer to buffer array
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_read(const struct device *dev, const u16_t x, const u16_t y,
const struct display_buffer_descriptor *desc, void *buf)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->read(dev, x, y, desc, buf);
}
/**
* @brief Get pointer to framebuffer for direct access
*
* @param dev Pointer to device structure
*
* @retval Pointer to frame buffer or NULL if direct framebuffer access
* is not supported
*
*/
static inline void *
display_get_framebuffer(const struct device *dev)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->get_framebuffer(dev);
}
/**
* @brief Turn display blanking on
*
* @param dev Pointer to device structure
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_blanking_on(const struct device *dev)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->blanking_on(dev);
}
/**
* @brief Turn display blanking off
*
* @param dev Pointer to device structure
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_blanking_off(const struct device *dev)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->blanking_off(dev);
}
/**
* @brief Set the brightness of the display
*
* Set the brightness of the display in steps of 1/256, where 255 is full
* brightness and 0 is minimal.
*
* @param dev Pointer to device structure
* @param brightness Brightness in steps of 1/256
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_brightness(const struct device *dev, u8_t brightness)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_brightness(dev, brightness);
}
/**
* @brief Set the contrast of the display
*
* Set the contrast of the display in steps of 1/256, where 255 is maximum
* difference and 0 is minimal.
*
* @param dev Pointer to device structure
* @param contrast Contrast in steps of 1/256
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_contrast(const struct device *dev, u8_t contrast)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_contrast(dev, contrast);
}
/**
* @brief Get display capabilities
*
* @param dev Pointer to device structure
* @param capabilities Pointer to capabilities structure to populate
*/
static inline void
display_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
api->get_capabilities(dev, capabilities);
}
/**
* @brief Set pixel format used by the display
*
* @param dev Pointer to device structure
* @param pixel_format Pixel format to be used by display
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_pixel_format(const struct device *dev,
const enum display_pixel_format pixel_format)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_pixel_format(dev, pixel_format);
}
/**
* @brief Set display orientation
*
* @param dev Pointer to device structure
* @param orientation Orientation to be used by display
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_orientation(const struct device *dev,
const enum display_orientation orientation)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_orientation(dev, orientation);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_DISPLAY_H_*/

View File

@ -1,283 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "display_ili9340.h"
#include <display.h>
//#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL
//#include <logging/log.h>
// LOG_MODULE_REGISTER(display_ili9340);
#define LOG_ERR printf
#define LOG_DBG printf
#define LOG_WRN printf
#include <drivers/gpio.h>
#include <sys/byteorder.h>
#include <drivers/spi.h>
#include <string.h>
#include <stdio.h>
struct ili9340_data {
struct device *reset_gpio;
struct device *command_data_gpio;
struct device *spi_dev;
struct spi_config spi_config;
#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER
struct spi_cs_control cs_ctrl;
#endif
};
struct ili9340_data ili9340_data1;
#define ILI9340_CMD_DATA_PIN_COMMAND 0
#define ILI9340_CMD_DATA_PIN_DATA 1
static void
ili9340_exit_sleep(struct ili9340_data *data)
{
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
// k_sleep(Z_TIMEOUT_MS(120));
}
int
ili9340_init()
{
struct ili9340_data *data = &ili9340_data1;
printf("Initializing display driver\n");
data->spi_dev = device_get_binding(DT_ILITEK_ILI9340_0_BUS_NAME);
if (data->spi_dev == NULL) {
return -EPERM;
}
data->spi_config.frequency = DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY;
data->spi_config.operation =
SPI_OP_MODE_MASTER
| SPI_WORD_SET(8); // SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
data->spi_config.slave = DT_ILITEK_ILI9340_0_BASE_ADDRESS;
#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER
data->cs_ctrl.gpio_dev =
device_get_binding(DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER);
data->cs_ctrl.gpio_pin = DT_ILITEK_ILI9340_0_CS_GPIO_PIN;
data->cs_ctrl.delay = 0;
data->spi_config.cs = &(data->cs_ctrl);
#else
data->spi_config.cs = NULL;
#endif
data->reset_gpio =
device_get_binding(DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER);
if (data->reset_gpio == NULL) {
return -EPERM;
}
gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN,
GPIO_OUTPUT);
data->command_data_gpio =
device_get_binding(DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER);
if (data->command_data_gpio == NULL) {
return -EPERM;
}
gpio_pin_configure(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, GPIO_OUTPUT);
LOG_DBG("Resetting display driver\n");
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 0);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(Z_TIMEOUT_MS(5));
LOG_DBG("Initializing LCD\n");
ili9340_lcd_init(data);
LOG_DBG("Exiting sleep mode\n");
ili9340_exit_sleep(data);
return 0;
}
static void
ili9340_set_mem_area(struct ili9340_data *data, const u16_t x, const u16_t y,
const u16_t w, const u16_t h)
{
u16_t spi_data[2];
spi_data[0] = sys_cpu_to_be16(x);
spi_data[1] = sys_cpu_to_be16(x + w - 1);
ili9340_transmit(data, ILI9340_CMD_COLUMN_ADDR, &spi_data[0], 4);
spi_data[0] = sys_cpu_to_be16(y);
spi_data[1] = sys_cpu_to_be16(y + h - 1);
ili9340_transmit(data, ILI9340_CMD_PAGE_ADDR, &spi_data[0], 4);
}
static int
ili9340_write(const struct device *dev, const u16_t x, const u16_t y,
const struct display_buffer_descriptor *desc, const void *buf)
{
struct ili9340_data *data = (struct ili9340_data *)&ili9340_data1;
const u8_t *write_data_start = (u8_t *)buf;
struct spi_buf tx_buf;
struct spi_buf_set tx_bufs;
u16_t write_cnt;
u16_t nbr_of_writes;
u16_t write_h;
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
__ASSERT((3 * desc->pitch * desc->height) <= desc->buf_size,
"Input buffer to small");
ili9340_set_mem_area(data, x, y, desc->width, desc->height);
if (desc->pitch > desc->width) {
write_h = 1U;
nbr_of_writes = desc->height;
}
else {
write_h = desc->height;
nbr_of_writes = 1U;
}
ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *)write_data_start,
3 * desc->width * write_h);
tx_bufs.buffers = &tx_buf;
tx_bufs.count = 1;
write_data_start += (3 * desc->pitch);
for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) {
tx_buf.buf = (void *)write_data_start;
tx_buf.len = 3 * desc->width * write_h;
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
write_data_start += (3 * desc->pitch);
}
return 0;
}
static int
ili9340_read(const struct device *dev, const u16_t x, const u16_t y,
const struct display_buffer_descriptor *desc, void *buf)
{
LOG_ERR("Reading not supported\n");
return -ENOTSUP;
}
static void *
ili9340_get_framebuffer(const struct device *dev)
{
LOG_ERR("Direct framebuffer access not supported\n");
return NULL;
}
static int
ili9340_display_blanking_off(const struct device *dev)
{
struct ili9340_data *data = (struct ili9340_data *)dev->driver_data;
LOG_DBG("Turning display blanking off\n");
ili9340_transmit(data, ILI9340_CMD_DISPLAY_ON, NULL, 0);
return 0;
}
static int
ili9340_display_blanking_on(const struct device *dev)
{
struct ili9340_data *data = (struct ili9340_data *)dev->driver_data;
LOG_DBG("Turning display blanking on\n");
ili9340_transmit(data, ILI9340_CMD_DISPLAY_OFF, NULL, 0);
return 0;
}
static int
ili9340_set_brightness(const struct device *dev, const u8_t brightness)
{
LOG_WRN("Set brightness not implemented\n");
return -ENOTSUP;
}
static int
ili9340_set_contrast(const struct device *dev, const u8_t contrast)
{
LOG_ERR("Set contrast not supported\n");
return -ENOTSUP;
}
static int
ili9340_set_pixel_format(const struct device *dev,
const enum display_pixel_format pixel_format)
{
if (pixel_format == PIXEL_FORMAT_RGB_888) {
return 0;
}
LOG_ERR("Pixel format change not implemented\n");
return -ENOTSUP;
}
static int
ili9340_set_orientation(const struct device *dev,
const enum display_orientation orientation)
{
if (orientation == DISPLAY_ORIENTATION_NORMAL) {
return 0;
}
LOG_ERR("Changing display orientation not implemented\n");
return -ENOTSUP;
}
static void
ili9340_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities)
{
memset(capabilities, 0, sizeof(struct display_capabilities));
capabilities->x_resolution = 320;
capabilities->y_resolution = 240;
capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_888;
capabilities->current_pixel_format = PIXEL_FORMAT_RGB_888;
capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL;
}
void
ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data,
size_t tx_len)
{
data = (struct ili9340_data *)&ili9340_data1;
struct spi_buf tx_buf = { .buf = &cmd, .len = 1 };
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 };
gpio_pin_set(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_COMMAND);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
if (tx_data != NULL) {
tx_buf.buf = tx_data;
tx_buf.len = tx_len;
gpio_pin_set(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_DATA);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
}
}
struct display_driver_api ili9340_api1 = {
.blanking_on = ili9340_display_blanking_on,
.blanking_off = ili9340_display_blanking_off,
.write = ili9340_write,
.read = ili9340_read,
.get_framebuffer = ili9340_get_framebuffer,
.set_brightness = ili9340_set_brightness,
.set_contrast = ili9340_set_contrast,
.get_capabilities = ili9340_get_capabilities,
.set_pixel_format = ili9340_set_pixel_format,
.set_orientation = ili9340_set_orientation
};
/*
DEVICE_AND_API_INIT(ili9340, DT_ILITEK_ILI9340_0_LABEL, &ili9340_init,
&ili9340_data, NULL, APPLICATION,
CONFIG_APPLICATION_INIT_PRIORITY, &ili9340_api);
*/

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "display_ili9340.h"
void
ili9340_lcd_init(struct ili9340_data *data)
{
u8_t tx_data[15];
tx_data[0] = 0x23;
ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_1, tx_data, 1);
tx_data[0] = 0x10;
ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_2, tx_data, 1);
tx_data[0] = 0x3e;
tx_data[1] = 0x28;
ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_1, tx_data, 2);
tx_data[0] = 0x86;
ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1);
tx_data[0] =
ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR;
ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1);
tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT
| ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT;
ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1);
tx_data[0] = 0x00;
tx_data[1] = 0x18;
ili9340_transmit(data, ILI9340_CMD_FRAME_CTRL_NORMAL_MODE, tx_data, 2);
tx_data[0] = 0x08;
tx_data[1] = 0x82;
tx_data[2] = 0x27;
ili9340_transmit(data, ILI9340_CMD_DISPLAY_FUNCTION_CTRL, tx_data, 3);
tx_data[0] = 0x01;
ili9340_transmit(data, ILI9340_CMD_GAMMA_SET, tx_data, 1);
tx_data[0] = 0x0F;
tx_data[1] = 0x31;
tx_data[2] = 0x2B;
tx_data[3] = 0x0C;
tx_data[4] = 0x0E;
tx_data[5] = 0x08;
tx_data[6] = 0x4E;
tx_data[7] = 0xF1;
tx_data[8] = 0x37;
tx_data[9] = 0x07;
tx_data[10] = 0x10;
tx_data[11] = 0x03;
tx_data[12] = 0x0E;
tx_data[13] = 0x09;
tx_data[14] = 0x00;
ili9340_transmit(data, ILI9340_CMD_POSITVE_GAMMA_CORRECTION, tx_data, 15);
tx_data[0] = 0x00;
tx_data[1] = 0x0E;
tx_data[2] = 0x14;
tx_data[3] = 0x03;
tx_data[4] = 0x11;
tx_data[5] = 0x07;
tx_data[6] = 0x31;
tx_data[7] = 0xC1;
tx_data[8] = 0x48;
tx_data[9] = 0x08;
tx_data[10] = 0x0F;
tx_data[11] = 0x0C;
tx_data[12] = 0x31;
tx_data[13] = 0x36;
tx_data[14] = 0x0F;
ili9340_transmit(data, ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION, tx_data, 15);
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <string.h>
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "wasm_export.h"
extern int
iwasm_main();
void
main(void)
{
iwasm_main();
for (;;) {
k_sleep(Z_TIMEOUT_MS(1000));
}
}
int
time_get_ms()
{
return k_uptime_get_32();
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef __PIN_CONFIG_JLF_H__
#define __PIN_CONFIG_JLF_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 5
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4
#define XPT2046_SPI_DEVICE_NAME "SPI_2"
#define XPT2046_SPI_MAX_FREQUENCY 10 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_CS_GPIO_PIN 6
#define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_PEN_GPIO_PIN 7
#define HOST_DEVICE_COMM_UART_NAME "UART_1"
#endif /* __PIN_CONFIG_JLF_H__ */

View File

@ -1,30 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef __PIN_CONFIG_STM32_H__
#define __PIN_CONFIG_STM32_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_1"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 24 * 1000 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 12
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 11
#define DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10
#define XPT2046_SPI_DEVICE_NAME "SPI_1"
#define XPT2046_SPI_MAX_FREQUENCY 12 * 1000 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIOD"
#define XPT2046_CS_GPIO_PIN 0
#define XPT2046_PEN_GPIO_CONTROLLER "GPIOD"
#define XPT2046_PEN_GPIO_PIN 1
#define HOST_DEVICE_COMM_UART_NAME "UART_6"
#endif /* __PIN_CONFIG_STM32_H__ */

View File

@ -1,78 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.8.2)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)
set (WAMR_BUILD_PLATFORM "zephyr")
enable_language (ASM)
add_definitions(-DWA_MALLOC=wasm_runtime_malloc)
add_definitions(-DWA_FREE=wasm_runtime_free)
# Build as THUMB by default
# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS" or "XTENSA"
# if we want to support arm_32, x86, mips or xtensa
if (NOT DEFINED WAMR_BUILD_TARGET)
set (WAMR_BUILD_TARGET "THUMBV7")
endif ()
if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()
if (NOT DEFINED WAMR_BUILD_AOT)
set (WAMR_BUILD_AOT 1)
endif ()
if (NOT DEFINED WAMR_BUILD_JIT)
# Disable JIT by default.
set (WAMR_BUILD_JIT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
# Enable libc builtin support by default
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
# Disable libc wasi support by default
set (WAMR_BUILD_LIBC_WASI 0)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
set (WAMR_BUILD_APP_FRAMEWORK 1)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_LIST)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_ALL)
endif ()
################ wamr runtime settings ################
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
################ sample project related ################
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
add_definitions(-DLV_MEM_CUSTOM=1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr)
include_directories(${WAMR_ROOT_DIR}/samples/gui/lv_config)
set (LVGL_DRV_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340_adafruit_1480.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/XPT2046.c
)
target_sources(app PRIVATE
${WAMR_RUNTIME_LIB_SOURCE}
${LVGL_DRV_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c
)

View File

@ -1,10 +0,0 @@
CONFIG_SPI=y
CONFIG_SPI_STM32=y
CONFIG_SPI_1=y
CONFIG_PRINTK=y
CONFIG_LOG=y
#CONFIG_UART_2=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_STACK_SENTINEL=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_ARM_MPU=y

View File

@ -1,8 +0,0 @@
MIT licence
Copyright (c) 2016 Gábor Kiss-Vámosi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,174 +0,0 @@
"littlevgl" sample introduction
==============
This sample demonstrates that a graphic user interface application in WebAssembly by compiling the LittlevGL v5.3, an open-source embedded 2d graphic library into the WASM bytecode.
In this sample, the whole LittlevGL v5.3 source code is built into the WebAssembly code with the user application. The platform interfaces defined by LittlevGL is implemented in the runtime and registered for WASM application through calling wasm_runtime_full_init().
```C
static NativeSymbol native_symbols[] = {
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")
};
```
The runtime component supports building target for Linux and Zephyr/STM Nucleo board. The beauty of this sample is the WebAssembly application can have identical display and behavior when running from both runtime environments. That implies we can do majority of application validation from desktop environment as long as two runtime distributions support the same set of application interface.
Below pictures show the WASM application is running on an STM board with an LCD touch panel.
![WAMR UI SAMPLE](../../doc/pics/vgl_demo2.png "WAMR UI DEMO STM32")
![WAMR UI SAMPLE](../../doc/pics/vgl_demo_linux.png "WAMR UI DEMO LINUX")
The number on top will plus one each second, and the number on the bottom will plus one when clicked. When users click the blue button, the WASM application increases the counter, and the latest counter value is displayed on the top banner of the touch panel.
The sample also provides the native Linux version of application without the runtime under folder "vgl-native-ui-app". It can help to check differences between the implementations in native and WebAssembly.
Test on Linux
================================
Install required SDK and libraries
--------------
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_32` when building WAMR runtime)
Use apt-get:
```bash
sudo apt-get install libsdl2-dev:i386
```
Or download source from www.libsdl.org:
```bash
./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32
make
sudo make install
```
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_64` when building WAMR runtime)
Use apt-get:
```bash
sudo apt-get install libsdl2-dev
```
Or download source from www.libsdl.org:
```bash
./configure
make
sudo make install
```
Build and Run
--------------
- Build
```bash
./build.sh
```
All binaries are in "out", which contains "host_tool", "vgl_native_ui_app", "ui_app.wasm" "ui_app_no_wasi.wasm "and "vgl_wasm_runtime".
- Run the native Linux build of the lvgl sample (no wasm)
```bash
./vgl_native_ui_app
```
- Run WASM VM Linux applicaton & install WASM APP
First start vgl_wasm_runtime in server mode.
```bash
./vgl_wasm_runtime -s
```
Then install and uninstall wasm APPs by using host tool.
```bash
./host_tool -i ui_wasi -f ui_app_wasi.wasm
./host_tool -q
./host_tool -u ui_wasi
./host_tool -i ui_no_wasi -f ui_app_builtin_libc.wasm
./host_tool -q
./host_tool -u ui_no_wasi
```
Test on Zephyr
================================
We can use a STM32 NUCLEO_F767ZI board with ILI9341 display and XPT2046 touch screen to run the test. Then use host_tool to remotely install wasm app into STM32.
- Build WASM VM into Zephyr system
a. clone zephyr source code
Refer to [Zephyr getting started](https://docs.zephyrproject.org/latest/getting_started/index.html).
```bash
west init zephyrproject
cd zephyrproject/zephyr
git checkout zephyr-v2.3.0
cd ..
west update
```
b. copy samples
```bash
cd zephyr/samples/
cp -a <wamr_root>/samples/littlevgl/vgl-wasm-runtime vgl-wasm-runtime
cd vgl-wasm-runtime/zephyr_build
```
c. create a link to wamr root dir
```bash
ln -s <wamr_root> wamr
```
d. build source code
Since ui_app incorporated LittlevGL source code, so it needs more RAM on the device to install the application. It is recommended that RAM SIZE not less than 380KB. In our test use nucleo_f767zi, which is supported by Zephyr. Since the littlevgl wasm app is quite big (~100KB in wasm format and ~200KB in AOT format ), there isn't enough SRAM to build interpreter and AOT together. You can only choose one of them:
- Interpreter
```bash
mkdir build && cd build
source ../../../../zephyr-env.sh
cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_AOT=0 ..
ninja flash
```
- AOT
```bash
mkdir build && cd build
source ../../../../zephyr-env.sh
cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 ..
ninja flash
```
- Hardware Connections
```
+-------------------+-+------------------+
|NUCLEO-F767ZI | ILI9341 Display |
+-------------------+-+------------------+
| CN7.10 | CLK |
+-------------------+-+------------------+
| CN7.12 | MISO |
+-------------------+-+------------------+
| CN7.14 | MOSI |
+-------------------+-+------------------+
| CN11.1 | CS1 for ILI9341 |
+-------------------+-+------------------+
| CN11.2 | D/C |
+-------------------+-+------------------+
| CN11.3 | RESET |
+-------------------+-+------------------+
| CN9.25 | PEN interrupt |
+-------------------+-+------------------+
| CN9.27 | CS2 for XPT2046 |
+-------------------+-+------------------+
| CN10.14 | PC UART RX |
+-------------------+-+------------------+
| CN11.16 | PC UART RX |
+-------------------+-+------------------+
```
- Install WASM application to Zephyr using host_tool
First, connect PC and STM32 with UART. Then install to use host_tool.
```bash
sudo ./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app_builtin_libc.wasm
# /dev/ttyUSBXXX is the UART device, e.g. /dev/ttyUSB0
```
**Note**: WASI is unavailable on zephyr currently, so you have to use the ui_app_builtin_libc.wasm which doesn't depend on WASI.
- Install AOT version WASM application
```bash
wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app_no_wasi.aot ui_app_builtin_libc.wasm
./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app_no_wasi.aot
```

View File

@ -1,102 +0,0 @@
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#!/bin/bash
PROJECT_DIR=$PWD
WAMR_DIR=${PWD}/../..
OUT_DIR=${PWD}/out
BUILD_DIR=${PWD}/build
LV_CFG_PATH=${PROJECT_DIR}/lv_config
if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then
echo "Local Build Env"
cmakewrap="cmake"
makewrap="make"
else
echo "Klocwork Build Env"
cmakewrap="cmake -DCMAKE_BUILD_TYPE=Debug"
makewrap="kwinject -o $KW_OUT_FILE make"
fi
if [ ! -d $BUILD_DIR ]; then
mkdir ${BUILD_DIR}
fi
rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
cd ${BUILD_DIR}
if [ ! -d "lvgl" ]; then
echo "starting download lvgl for v5.3 ..."
git clone https://github.com/lvgl/lvgl.git --branch v5.3
if [ $? != 0 ];then
echo "download lvgl repo failed: $?\n"
exit 2
fi
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} -c
[ $? -eq 0 ] || exit $?
echo "#####################build wamr-sdk littlevgl success"
echo -e "\n\n"
echo "##################### 1. build native-ui-app start#####################"
cd $BUILD_DIR
mkdir -p vgl-native-ui-app
cd vgl-native-ui-app
$cmakewrap ${PROJECT_DIR}/vgl-native-ui-app
$makewrap
if [ $? != 0 ];then
echo "BUILD_FAIL native-ui-app $?\n"
exit 2
fi
echo $PWD
cp vgl_native_ui_app ${OUT_DIR}
echo "#####################build native-ui-app success"
echo -e "\n\n"
echo "##################### 2. build littlevgl wasm runtime start#####################"
cd $BUILD_DIR
mkdir -p vgl-wasm-runtime
cd vgl-wasm-runtime
$cmakewrap ${PROJECT_DIR}/vgl-wasm-runtime
$makewrap
[ $? -eq 0 ] || exit $?
cp vgl_wasm_runtime ${OUT_DIR}/
echo "##################### build littlevgl wasm runtime end#####################"
echo -e "\n\n"
echo "#####################build host-tool"
cd $BUILD_DIR
mkdir -p host-tool
cd host-tool
$cmakewrap ${WAMR_DIR}/test-tools/host-tool
$makewrap
if [ $? != 0 ];then
echo "BUILD_FAIL host tool exit as $?\n"
exit 2
fi
cp host_tool ${OUT_DIR}
echo "#####################build host-tool success"
echo -e "\n\n"
echo "##################### 3. build wasm ui app start#####################"
cd ${PROJECT_DIR}/wasm-apps
if [ ! -d "${PROJECT_DIR}/wasm-apps/lvgl" ]; then
if [ -d "$BUILD_DIR/vgl-native-ui-app/lvgl" ]; then
cp -fr $BUILD_DIR/vgl-native-ui-app/lvgl ${PROJECT_DIR}/wasm-apps
fi
fi
./build_wasm_app.sh
mv *.wasm ${OUT_DIR}/
echo "##################### build wasm ui app end#####################"

View File

@ -1,389 +0,0 @@
/**
* @file lv_conf.h
*
*/
#if 1 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/*===================
Dynamic memory
*===================*/
/* Memory size which will be used by the library
* to store the graphical objects and other data */
#define LV_MEM_CUSTOM 1 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/
#if LV_MEM_CUSTOM == 0
# define LV_MEM_SIZE (64U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_ATTR /*Complier prefix for big array declaration*/
# define LV_MEM_ADR 0 /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/
# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher language and the memory is managed by that language */
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
#endif /* LV_ENABLE_GC */
/*===================
Graphical settings
*===================*/
/* Horizontal and vertical resolution of the library.*/
#define LV_HOR_RES (320)
#define LV_VER_RES (240)
/* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI 100
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#define LV_ANTIALIAS 0 /*1: Enable anti-aliasing*/
/*Screen refresh period in milliseconds*/
#define LV_REFR_PERIOD 30
/*-----------------
* VDB settings
*----------------*/
/* VDB (Virtual Display Buffer) is an internal graphics buffer.
* The GUI will be drawn into this buffer first and then
* the buffer will be passed to your `disp_drv.disp_flush` function to
* copy it to your frame buffer.
* VDB is required for: buffered drawing, opacity, anti-aliasing and shadows
* Learn more: https://docs.littlevgl.com/#Drawing*/
/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES
* Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions
* will be called to draw to the frame buffer directly*/
#define LV_VDB_SIZE ((LV_VER_RES * LV_HOR_RES) / 10)
/* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays.
* Special formats are handled with `disp_drv.vdb_wr`)*/
#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */
/* Place VDB to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#define LV_VDB_ADR 0
/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing
* The flushing should use DMA to write the frame buffer in the background */
#define LV_VDB_DOUBLE 0
/* Place VDB2 to a specific address (e.g. in external RAM)
* 0: allocate automatically into RAM
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
#define LV_VDB2_ADR 0
/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen.
* Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display.
* The best if you do in the blank period of you display to avoid tearing effect.
* Requires:
* - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES
* - LV_VDB_DOUBLE = 1
*/
#define LV_VDB_TRUE_DOUBLE_BUFFERED 0
/*=================
Misc. setting
*=================*/
/*Input device settings*/
#define LV_INDEV_READ_PERIOD 50 /*Input device read period in milliseconds*/
#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/
#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */
#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */
#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/
#define LV_INDEV_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */
/*Color settings*/
#define LV_COLOR_DEPTH 32 /*Color depth: 1/8/16/32*/
#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/
#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/
/*Text settings*/
#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */
#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/
#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */
/*Feature usage*/
#define USE_LV_ANIMATION 1 /*1: Enable all animations*/
#define USE_LV_SHADOW 1 /*1: Enable shadows*/
#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/
#define USE_LV_GPU 0 /*1: Enable GPU interface*/
#define USE_LV_REAL_DRAW 1 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/
#define USE_LV_FILESYSTEM 0 /*1: Enable file system (might be required for images*/
#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/
/*Compiler settings*/
#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */
#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */
#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/
#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */
/*HAL settings*/
#define LV_TICK_CUSTOM 1 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */
#if LV_TICK_CUSTOM == 1
#define LV_TICK_CUSTOM_INCLUDE "system_header.h" /*Header for the sys time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (time_get_ms()) /*Expression evaluating to current systime in ms*/
#endif /*LV_TICK_CUSTOM*/
/*Log settings*/
#define USE_LV_LOG 1 /*Enable/disable the log module*/
#if USE_LV_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't caused problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
*/
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
/* 1: Print the log with 'printf'; 0: user need to register a callback*/
# define LV_LOG_PRINTF 0
#endif /*USE_LV_LOG*/
/*================
* THEME USAGE
*================*/
#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
#define USE_LV_THEME_TEMPL 0 /*Just for test*/
#define USE_LV_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/
#define USE_LV_THEME_ALIEN 0 /*Dark futuristic theme*/
#define USE_LV_THEME_NIGHT 0 /*Dark elegant theme*/
#define USE_LV_THEME_MONO 0 /*Mono color theme for monochrome displays*/
#define USE_LV_THEME_MATERIAL 0 /*Flat theme with bold colors and light shadows*/
#define USE_LV_THEME_ZEN 0 /*Peaceful, mainly light theme */
#define USE_LV_THEME_NEMO 0 /*Water-like theme based on the movie "Finding Nemo"*/
/*==================
* FONT USAGE
*===================*/
/* More info about fonts: https://docs.littlevgl.com/#Fonts
* To enable a built-in font use 1,2,4 or 8 values
* which will determine the bit-per-pixel. Higher value means smoother fonts */
#define USE_LV_FONT_DEJAVU_10 0
#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_10_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_10 0
#define USE_LV_FONT_DEJAVU_20 4
#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_20_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_20 0
#define USE_LV_FONT_DEJAVU_30 0
#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_30_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_30 0
#define USE_LV_FONT_DEJAVU_40 0
#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 0
#define USE_LV_FONT_DEJAVU_40_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_40 0
#define USE_LV_FONT_MONOSPACE_8 1
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2) \
*/
#define LV_FONT_CUSTOM_DECLARE
#define LV_FONT_DEFAULT &lv_font_dejavu_20 /*Always set a default font from the built-in fonts*/
/*===================
* LV_OBJ SETTINGS
*==================*/
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
*/
/*****************
* Simple object
*****************/
/*Label (dependencies: -*/
#define USE_LV_LABEL 1
#if USE_LV_LABEL != 0
# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/
#endif
/*Image (dependencies: lv_label*/
#define USE_LV_IMG 1
#if USE_LV_IMG != 0
# define LV_IMG_CF_INDEXED 1 /*Enable indexed (palette) images*/
# define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/
#endif
/*Line (dependencies: -*/
#define USE_LV_LINE 1
/*Arc (dependencies: -)*/
#define USE_LV_ARC 1
/*******************
* Container objects
*******************/
/*Container (dependencies: -*/
#define USE_LV_CONT 1
/*Page (dependencies: lv_cont)*/
#define USE_LV_PAGE 1
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#define USE_LV_WIN 1
/*Tab (dependencies: lv_page, lv_btnm)*/
#define USE_LV_TABVIEW 1
# if USE_LV_TABVIEW != 0
# define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
/*Tileview (dependencies: lv_page) */
#define USE_LV_TILEVIEW 1
#if USE_LV_TILEVIEW
# define LV_TILEVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
/*************************
* Data visualizer objects
*************************/
/*Bar (dependencies: -)*/
#define USE_LV_BAR 1
/*Line meter (dependencies: *;)*/
#define USE_LV_LMETER 1
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
#define USE_LV_GAUGE 1
/*Chart (dependencies: -)*/
#define USE_LV_CHART 1
/*Table (dependencies: lv_label)*/
#define USE_LV_TABLE 1
#if USE_LV_TABLE
# define LV_TABLE_COL_MAX 12
#endif
/*LED (dependencies: -)*/
#define USE_LV_LED 1
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#define USE_LV_MBOX 1
/*Text area (dependencies: lv_label, lv_page)*/
#define USE_LV_TA 1
#if USE_LV_TA != 0
# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
#endif
/*Spinbox (dependencies: lv_ta)*/
#define USE_LV_SPINBOX 1
/*Calendar (dependencies: -)*/
#define USE_LV_CALENDAR 1
/*Preload (dependencies: lv_arc)*/
#define USE_LV_PRELOAD 1
#if USE_LV_PRELOAD != 0
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
#endif
/*Canvas (dependencies: lv_img)*/
#define USE_LV_CANVAS 1
/*************************
* User input objects
*************************/
/*Button (dependencies: lv_cont*/
#define USE_LV_BTN 1
#if USE_LV_BTN != 0
# define LV_BTN_INK_EFFECT 1 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/
#endif
/*Image Button (dependencies: lv_btn*/
#define USE_LV_IMGBTN 1
#if USE_LV_IMGBTN
# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
#endif
/*Button matrix (dependencies: -)*/
#define USE_LV_BTNM 1
/*Keyboard (dependencies: lv_btnm)*/
#define USE_LV_KB 1
/*Check box (dependencies: lv_btn, lv_label)*/
#define USE_LV_CB 1
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#define USE_LV_LIST 1
#if USE_LV_LIST != 0
# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */
#endif
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#define USE_LV_DDLIST 1
#if USE_LV_DDLIST != 0
# define LV_DDLIST_ANIM_TIME 200 /*Open and close default animation time [ms] (0: no animation)*/
#endif
/*Roller (dependencies: lv_ddlist)*/
#define USE_LV_ROLLER 1
#if USE_LV_ROLLER != 0
# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/
#endif
/*Slider (dependencies: lv_bar)*/
#define USE_LV_SLIDER 1
/*Switch (dependencies: lv_slider)*/
#define USE_LV_SW 1
/*************************
* Non-user section
*************************/
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
# define _CRT_SECURE_NO_WARNINGS
#endif
/*--END OF LV_CONF_H--*/
/*Be sure every define has a default value*/
#include "lvgl/lv_conf_checker.h"
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -1,310 +0,0 @@
/**
* @file lv_drv_conf.h
*
*/
/*
* COPY THIS FILE AS lv_drv_conf.h
*/
#if 1 /*Set it to "1" to enable the content*/
#ifndef LV_DRV_CONF_H
#define LV_DRV_CONF_H
#include "lv_conf.h"
/*********************
* DELAY INTERFACE
*********************/
#define LV_DRV_DELAY_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/
#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/
/*********************
* DISPLAY INTERFACE
*********************/
/*------------
* Common
*------------*/
#define LV_DRV_DISP_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/
#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
/*---------
* SPI
*---------*/
#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/
#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/
/*------------------
* Parallel port
*-----------------*/
#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/
#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/
#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/
#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/
#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/
/***************************
* INPUT DEVICE INTERFACE
***************************/
/*----------
* Common
*----------*/
#define LV_DRV_INDEV_INCLUDE <stdint.h> /*Dummy include by default*/
#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/
/*---------
* SPI
*---------*/
#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/
/*---------
* I2C
*---------*/
#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/
#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/
#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/
#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/
#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/
/*********************
* DISPLAY DRIVERS
*********************/
/*-------------------
* Monitor of PC
*-------------------*/
#ifndef USE_MONITOR
# define USE_MONITOR 1
#endif
#if USE_MONITOR
# define MONITOR_HOR_RES LV_HOR_RES_MAX
# define MONITOR_VER_RES LV_VER_RES_MAX
/* Scale window by this factor (useful when simulating small screens) */
# define MONITOR_ZOOM 1
/* Used to test true double buffering with only address changing.
* Set LV_VDB_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_VDB_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */
# define MONITOR_DOUBLE_BUFFERED 0
/*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
# define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Different rendering might be used if running in a Virtual machine*/
# define MONITOR_VIRTUAL_MACHINE 0
/*Open two windows to test multi display support*/
# define MONITOR_DUAL 0
#endif
/*-----------------------------------
* Native Windows (including mouse)
*----------------------------------*/
#ifndef USE_WINDOWS
# define USE_WINDOWS 0
#endif
#define USE_WINDOWS 0
#if USE_WINDOWS
# define WINDOW_HOR_RES 480
# define WINDOW_VER_RES 320
#endif
/*----------------
* SSD1963
*--------------*/
#ifndef USE_SSD1963
# define USE_SSD1963 0
#endif
#if USE_SSD1963
# define SSD1963_HOR_RES LV_HOR_RES
# define SSD1963_VER_RES LV_VER_RES
# define SSD1963_HT 531
# define SSD1963_HPS 43
# define SSD1963_LPS 8
# define SSD1963_HPW 10
# define SSD1963_VT 288
# define SSD1963_VPS 12
# define SSD1963_FPS 4
# define SSD1963_VPW 10
# define SSD1963_HS_NEG 0 /*Negative hsync*/
# define SSD1963_VS_NEG 0 /*Negative vsync*/
# define SSD1963_ORI 0 /*0, 90, 180, 270*/
# define SSD1963_COLOR_DEPTH 16
#endif
/*----------------
* R61581
*--------------*/
#ifndef USE_R61581
# define USE_R61581 0
#endif
#if USE_R61581
# define R61581_HOR_RES LV_HOR_RES
# define R61581_VER_RES LV_VER_RES
# define R61581_HSPL 0 /*HSYNC signal polarity*/
# define R61581_HSL 10 /*HSYNC length (Not Implemented)*/
# define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/
# define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */
# define R61581_VSPL 0 /*VSYNC signal polarity*/
# define R61581_VSL 10 /*VSYNC length (Not Implemented)*/
# define R61581_VFP 8 /*Vertical Front poarch*/
# define R61581_VBP 8 /*Vertical Back poarch */
# define R61581_DPL 0 /*DCLK signal polarity*/
# define R61581_EPL 1 /*ENABLE signal polarity*/
# define R61581_ORI 0 /*0, 180*/
# define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/
#endif
/*------------------------------
* ST7565 (Monochrome, low res.)
*-----------------------------*/
#ifndef USE_ST7565
# define USE_ST7565 0
#endif
#if USE_ST7565
/*No settings*/
#endif /*USE_ST7565*/
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
#ifndef USE_FBDEV
# define USE_FBDEV 1
#endif
#if USE_FBDEV
# define FBDEV_PATH "/dev/fb0"
#endif
/*********************
* INPUT DEVICES
*********************/
/*--------------
* XPT2046
*--------------*/
#ifndef USE_XPT2046
# define USE_XPT2046 0
#endif
#if USE_XPT2046
# define XPT2046_HOR_RES 480
# define XPT2046_VER_RES 320
# define XPT2046_X_MIN 200
# define XPT2046_Y_MIN 200
# define XPT2046_X_MAX 3800
# define XPT2046_Y_MAX 3800
# define XPT2046_AVG 4
# define XPT2046_INV 0
#endif
/*-----------------
* FT5406EE8
*-----------------*/
#ifndef USE_FT5406EE8
# define USE_FT5406EE8 0
#endif
#if USE_FT5406EE8
# define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/
#endif
/*---------------
* AD TOUCH
*--------------*/
#ifndef USE_AD_TOUCH
# define USE_AD_TOUCH 0
#endif
#if USE_AD_TOUCH
/*No settings*/
#endif
/*---------------------------------------
* Mouse or touchpad on PC (using SDL)
*-------------------------------------*/
#ifndef USE_MOUSE
# define USE_MOUSE 1
#endif
#if USE_MOUSE
/*No settings*/
#endif
/*-------------------------------------------
* Mousewheel as encoder on PC (using SDL)
*------------------------------------------*/
#ifndef USE_MOUSEWHEEL
# define USE_MOUSEWHEEL 1
#endif
#if USE_MOUSEWHEEL
/*No settings*/
#endif
/*-------------------------------------------------
* Touchscreen as libinput interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_LIBINPUT
# define USE_LIBINPUT 0
#endif
#if USE_LIBINPUT
# define LIBINPUT_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
#endif /*USE_LIBINPUT*/
/*-------------------------------------------------
* Mouse or touchpad as evdev interface (for Linux based systems)
*------------------------------------------------*/
#ifndef USE_EVDEV
# define USE_EVDEV 0
#endif
#if USE_EVDEV
# define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
# define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
# define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */
# if EVDEV_SCALE
# define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */
# define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */
# endif /*EVDEV_SCALE*/
# define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
# if EVDEV_CALIBRATE
# define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
# define EVDEV_HOR_MAX 200
# define EVDEV_VER_MIN 200
# define EVDEV_VER_MAX 3800
# endif /*EVDEV_SCALE*/
#endif /*USE_EVDEV*/
/*-------------------------------
* Keyboard of a PC (using SDL)
*------------------------------*/
#ifndef USE_KEYBOARD
# define USE_KEYBOARD 1
#endif
#if USE_KEYBOARD
/*No settings*/
#endif
#endif /*LV_DRV_CONF_H*/
#endif /*End of "Content enable"*/

View File

@ -1,137 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.9)
message ("vgl_native_ui_app...")
project (vgl_native_ui_app)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_NATIVE_LINUX -DUSE_MONITOR -DUSE_MOUSE=1")
# Currently build as 64-bit by default. Set to "NO" to build 32-bit binaries.
set (BUILD_AS_64BIT_SUPPORT "YES")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
# Add -fPIC flag if build as 64-bit
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
else ()
add_definitions (-m32)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
endif ()
endif ()
set(lv_name lvgl)
set(LVGL_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../build/lvgl)
set(LVGL_DRIVER_DIR ${CMAKE_CURRENT_LIST_DIR}/lv-drivers)
message(${LVGL_SOURCE_DIR})
include( ExternalProject )
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
SET (LVGL_SOURCES
${LVGL_SOURCE_DIR}/lv_core/lv_group.c
${LVGL_SOURCE_DIR}/lv_core/lv_indev.c
${LVGL_SOURCE_DIR}/lv_core/lv_lang.c
${LVGL_SOURCE_DIR}/lv_core/lv_obj.c
${LVGL_SOURCE_DIR}/lv_core/lv_refr.c
${LVGL_SOURCE_DIR}/lv_core/lv_style.c
${LVGL_SOURCE_DIR}/lv_core/lv_vdb.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_arc.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_img.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_label.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_line.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_rbasic.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_rect.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_triangle.c
${LVGL_SOURCE_DIR}/lv_draw/lv_draw_vbasic.c
${LVGL_SOURCE_DIR}/lv_hal/lv_hal_disp.c
${LVGL_SOURCE_DIR}/lv_hal/lv_hal_indev.c
${LVGL_SOURCE_DIR}/lv_hal/lv_hal_tick.c
${LVGL_SOURCE_DIR}/lv_misc/lv_anim.c
${LVGL_SOURCE_DIR}/lv_misc/lv_area.c
${LVGL_SOURCE_DIR}/lv_misc/lv_circ.c
${LVGL_SOURCE_DIR}/lv_misc/lv_color.c
${LVGL_SOURCE_DIR}/lv_misc/lv_font.c
${LVGL_SOURCE_DIR}/lv_misc/lv_fs.c
${LVGL_SOURCE_DIR}/lv_misc/lv_gc.c
${LVGL_SOURCE_DIR}/lv_misc/lv_ll.c
${LVGL_SOURCE_DIR}/lv_misc/lv_log.c
${LVGL_SOURCE_DIR}/lv_misc/lv_math.c
${LVGL_SOURCE_DIR}/lv_misc/lv_mem.c
${LVGL_SOURCE_DIR}/lv_misc/lv_task.c
${LVGL_SOURCE_DIR}/lv_misc/lv_templ.c
${LVGL_SOURCE_DIR}/lv_misc/lv_txt.c
${LVGL_SOURCE_DIR}/lv_objx/lv_arc.c
${LVGL_SOURCE_DIR}/lv_objx/lv_bar.c
${LVGL_SOURCE_DIR}/lv_objx/lv_btn.c
${LVGL_SOURCE_DIR}/lv_objx/lv_btnm.c
${LVGL_SOURCE_DIR}/lv_objx/lv_calendar.c
${LVGL_SOURCE_DIR}/lv_objx/lv_canvas.c
${LVGL_SOURCE_DIR}/lv_objx/lv_cb.c
${LVGL_SOURCE_DIR}/lv_objx/lv_chart.c
${LVGL_SOURCE_DIR}/lv_objx/lv_cont.c
${LVGL_SOURCE_DIR}/lv_objx/lv_ddlist.c
${LVGL_SOURCE_DIR}/lv_objx/lv_gauge.c
${LVGL_SOURCE_DIR}/lv_objx/lv_img.c
${LVGL_SOURCE_DIR}/lv_objx/lv_imgbtn.c
${LVGL_SOURCE_DIR}/lv_objx/lv_kb.c
${LVGL_SOURCE_DIR}/lv_objx/lv_label.c
${LVGL_SOURCE_DIR}/lv_objx/lv_led.c
${LVGL_SOURCE_DIR}/lv_objx/lv_line.c
${LVGL_SOURCE_DIR}/lv_objx/lv_list.c
${LVGL_SOURCE_DIR}/lv_objx/lv_lmeter.c
${LVGL_SOURCE_DIR}/lv_objx/lv_mbox.c
${LVGL_SOURCE_DIR}/lv_objx/lv_objx_templ.c
${LVGL_SOURCE_DIR}/lv_objx/lv_page.c
${LVGL_SOURCE_DIR}/lv_objx/lv_preload.c
${LVGL_SOURCE_DIR}/lv_objx/lv_roller.c
${LVGL_SOURCE_DIR}/lv_objx/lv_slider.c
${LVGL_SOURCE_DIR}/lv_objx/lv_spinbox.c
${LVGL_SOURCE_DIR}/lv_objx/lv_sw.c
${LVGL_SOURCE_DIR}/lv_objx/lv_ta.c
${LVGL_SOURCE_DIR}/lv_objx/lv_table.c
${LVGL_SOURCE_DIR}/lv_objx/lv_tabview.c
${LVGL_SOURCE_DIR}/lv_objx/lv_tileview.c
${LVGL_SOURCE_DIR}/lv_objx/lv_win.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_alien.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_default.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_material.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_mono.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_nemo.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_night.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_templ.c
${LVGL_SOURCE_DIR}/lv_themes/lv_theme_zen.c
${LVGL_SOURCE_DIR}/lv_fonts/lv_font_builtin.c
${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_20.c
${LVGL_DRIVER_DIR}/linux_display_indev.c
${LVGL_DRIVER_DIR}/indev/mouse.c
)
SET(SOURCES
${LVGL_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/main.c
)
include_directories(
${LVGL_DRIVER_DIR}
${LVGL_DRIVER_DIR}/display
${LVGL_DRIVER_DIR}/indev
${LVGL_SOURCE_DIR}
${LVGL_SOURCE_DIR}/..
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/../lv_config
)
add_executable(vgl_native_ui_app ${SOURCES} )
target_link_libraries( vgl_native_ui_app -lSDL2)

View File

@ -1,18 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 2.8.2)
project(lvgl_download NONE)
include(ExternalProject)
ExternalProject_Add(${lv_name}
GIT_REPOSITORY https://github.com/lvgl/lvgl.git
GIT_TAG v5.3
BINARY_DIR ""
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/../build/lvgl"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

View File

@ -1 +0,0 @@
**/*.o

View File

@ -1,28 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef DISPLAY_INDEV_H_
#define DISPLAY_INDEV_H_
#include <stdio.h>
#include <inttypes.h>
#include "mouse.h"
#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 int
time_get_ms();
#endif

View File

@ -1,96 +0,0 @@
/**
* @file mouse.c
*
*/
/*********************
* INCLUDES
*********************/
#include "mouse.h"
#if USE_MOUSE != 0
/*********************
* DEFINES
*********************/
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static bool left_button_down = false;
static int16_t last_x = 0;
static int16_t last_y = 0;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the mouse
*/
void
mouse_init(void)
{}
/**
* Get the current position and state of the mouse
* @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be
* read
*/
bool
mouse_read(lv_indev_data_t *data)
{
/*Store the collected data*/
data->point.x = last_x;
data->point.y = last_y;
data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
return false;
}
/**
* It will be called from the main SDL thread
*/
void
mouse_handler(SDL_Event *event)
{
switch (event->type) {
case SDL_MOUSEBUTTONUP:
if (event->button.button == SDL_BUTTON_LEFT)
left_button_down = false;
break;
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == SDL_BUTTON_LEFT) {
left_button_down = true;
last_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / MONITOR_ZOOM;
}
break;
case SDL_MOUSEMOTION:
last_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / MONITOR_ZOOM;
break;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,73 +0,0 @@
/**
* @file mouse.h
*
*/
#ifndef MOUSE_H
#define MOUSE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_drv_conf.h"
#if USE_MOUSE
#include <stdint.h>
#include <stdbool.h>
#include "lvgl/lv_hal/lv_hal_indev.h"
#ifndef MONITOR_SDL_INCLUDE_PATH
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
#endif
#include MONITOR_SDL_INCLUDE_PATH
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the mouse
*/
void
mouse_init(void);
/**
* Get the current position and state of the mouse
* @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be
* read
*/
bool
mouse_read(lv_indev_data_t *data);
/**
* It will be called from the main SDL thread
*/
void
mouse_handler(SDL_Event *event);
/**********************
* MACROS
**********************/
#endif /* USE_MOUSE */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* MOUSE_H */

View File

@ -1,319 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <stdbool.h>
#include "display_indev.h"
#include "sys/time.h"
#include "SDL2/SDL.h"
#define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
#define SDL_REFR_PERIOD 50
void
monitor_sdl_init(void);
void
monitor_sdl_refr_core(void);
void
monitor_sdl_clean_up(void);
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES];
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)
{
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);
}
*/
}
int
time_get_ms()
{
static struct timeval tv;
gettimeofday(&tv, NULL);
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
return (int)time_in_mill;
}
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
static volatile bool sdl_inited = false;
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)
{
/*Return if the area is out the screen*/
if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1
|| y1 > MONITOR_VER_RES - 1) {
return;
}
int32_t y;
uint32_t w = x2 - x1 + 1;
for (y = y1; y <= y2; y++) {
memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color_p,
w * sizeof(lv_color_t));
color_p += w;
}
sdl_refr_qry = true;
/*IMPORTANT! It must be called to tell the system the flush is ready*/
}
/**
* Fill out the marked area with a color
* @param x1 left coordinate
* @param y1 top coordinate
* @param x2 right coordinate
* @param y2 bottom coordinate
* @param color fill color
*/
void
monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
{
/*Return if the area is out the screen*/
if (x2 < 0)
return;
if (y2 < 0)
return;
if (x1 > MONITOR_HOR_RES - 1)
return;
if (y1 > MONITOR_VER_RES - 1)
return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2;
int32_t x;
int32_t y;
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++) {
tft_fb[y * MONITOR_HOR_RES + x] = color32;
}
}
sdl_refr_qry = true;
}
/**
* Put a color map to the marked area
* @param x1 left coordinate
* @param y1 top coordinate
* @param x2 right coordinate
* @param y2 bottom coordinate
* @param color_p 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)
{
/*Return if the area is out the screen*/
if (x2 < 0)
return;
if (y2 < 0)
return;
if (x1 > MONITOR_HOR_RES - 1)
return;
if (y1 > MONITOR_VER_RES - 1)
return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2;
int32_t x;
int32_t y;
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++;
}
color_p += x2 - act_x2;
}
sdl_refr_qry = true;
}
void
display_init(void)
{}
void
display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
const lv_color_t *color_p)
{
monitor_flush(x1, y1, x2, y2, color_p);
}
void
display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color_p)
{
monitor_fill(x1, y1, x2, y2, color_p);
}
void
display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
const lv_color_t *color_p)
{
monitor_map(x1, y1, x2, y2, color_p);
}
bool
display_input_read(lv_indev_data_t *data)
{
return mouse_read(data);
}
void
display_deinit(void)
{}
int
monitor_sdl_refr_thread(void *param)
{
(void)param;
/*If not OSX initialize SDL in the Thread*/
monitor_sdl_init();
/*Run until quit event not arrives*/
while (sdl_quit_qry == false) {
/*Refresh handling*/
monitor_sdl_refr_core();
}
monitor_sdl_clean_up();
exit(0);
return 0;
}
void
monitor_sdl_refr_core(void)
{
if (sdl_refr_qry != false) {
sdl_refr_qry = false;
SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer);
/*Test: Draw a background to test transparent screens
* (LV_COLOR_SCREEN_TRANSP)*/
// SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
// SDL_Rect r;
// r.x = 0; r.y = 0; r.w = MONITOR_HOR_RES; r.w =
// MONITOR_VER_RES; SDL_RenderDrawRect(renderer, &r);
/*Update the renderer with the texture containing the rendered image*/
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
SDL_Event event;
while (SDL_PollEvent(&event)) {
#if USE_MOUSE != 0
mouse_handler(&event);
#endif
if ((&event)->type == SDL_WINDOWEVENT) {
switch ((&event)->window.event) {
#if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_TAKE_FOCUS:
#endif
case SDL_WINDOWEVENT_EXPOSED:
SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
break;
default:
break;
}
}
}
/*Sleep some time*/
SDL_Delay(SDL_REFR_PERIOD);
}
int
quit_filter(void *userdata, SDL_Event *event)
{
(void)userdata;
if (event->type == SDL_QUIT) {
sdl_quit_qry = true;
}
return 1;
}
void
monitor_sdl_clean_up(void)
{
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
void
monitor_sdl_init(void)
{
/*Initialize the SDL*/
SDL_Init(SDL_INIT_VIDEO);
SDL_SetEventFilter(quit_filter, NULL);
window = SDL_CreateWindow(
"TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM,
0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
renderer = SDL_CreateRenderer(window, -1, 0);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES,
MONITOR_VER_RES);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
/*Initialize the frame buffer to gray (77 is an empirical value) */
memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t));
sdl_refr_qry = true;
sdl_inited = true;
}
void
display_SDL_init()
{
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
while (sdl_inited == false)
; /*Wait until 'sdl_refr' initializes the SDL*/
}

View File

@ -1,9 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
int
time_get_ms();

View File

@ -1,170 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
/**
* @file main
*
*/
/*********************
* INCLUDES
*********************/
#include <stdlib.h>
#include <inttypes.h>
#include "lvgl/lvgl.h"
#include "display_indev.h"
#include <unistd.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void
hal_init(void);
// static int tick_thread(void * data);
// static void memory_monitor(void * param);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
uint32_t count = 0;
char count_str[11] = { 0 };
lv_obj_t *hello_world_label;
lv_obj_t *count_label;
lv_obj_t *btn1;
lv_obj_t *label_count1;
int label_count1_value = 0;
char label_count1_str[11] = { 0 };
static lv_res_t
btn_rel_action(lv_obj_t *btn)
{
label_count1_value++;
snprintf(label_count1_str, sizeof(label_count1_str), "%d",
label_count1_value);
lv_label_set_text(label_count1, label_count1_str);
return LV_RES_OK;
}
int
main()
{
void display_SDL_init();
display_SDL_init();
/*Initialize LittlevGL*/
lv_init();
/*Initialize the HAL (display, input devices, tick) for LittlevGL*/
hal_init();
hello_world_label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(hello_world_label, "Hello world!");
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
count_label = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
btn1 = lv_btn_create(
lv_scr_act(), NULL); /*Create a button on the currently loaded screen*/
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK,
btn_rel_action); /*Set function to be called when the
button is released*/
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 20); /*Align below the label*/
/*Create a label on the button*/
lv_obj_t *btn_label = lv_label_create(btn1, NULL);
lv_label_set_text(btn_label, "Click ++");
label_count1 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label_count1, "0");
lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
while (1) {
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count / 100);
lv_label_set_text(count_label, count_str);
}
lv_task_handler();
++count;
usleep(10 * 1000); /*Just to let the system breath*/
}
return 0;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* 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)
{
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)
{
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);
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_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;
#endif
lv_disp_drv_register(&disp_drv);
/* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse*/
// mouse_init();
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read =
display_input_read; /*This function will be called periodically (by the
library) to get the mouse position and state*/
lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv);
}

View File

@ -1,36 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.9)
project (vgl_wasm_runtime)
set (WAMR_BUILD_PLATFORM "linux")
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
################ wamr runtime settings ################
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
## use library and headers in the SDK
link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/lib)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/include
${WAMR_ROOT_DIR}/wamr-sdk/out/littlevgl/runtime-sdk/include/bi-inc/deps
${WAMR_ROOT_DIR}/core/shared/utils
${WAMR_ROOT_DIR}/core/shared/platform/${WAMR_BUILD_PLATFORM}
)
############### application related ###############
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/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)

View File

@ -1,96 +0,0 @@
#ifndef DISPLAY_INDEV_H_
#define DISPLAY_INDEV_H_
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
#include "bh_platform.h"
#include "wasm_export.h"
#define USE_MOUSE 1
typedef union {
struct {
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t alpha;
};
uint32_t full;
} lv_color32_t;
typedef lv_color32_t lv_color_t;
typedef uint8_t lv_indev_state_t;
typedef int16_t lv_coord_t;
typedef uint8_t lv_opa_t;
typedef struct {
lv_coord_t x;
lv_coord_t y;
} lv_point_t;
typedef struct {
union {
lv_point_t
point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/
uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/
int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the
previous read*/
};
void *user_data; /*'lv_indev_drv_t.priv' for this driver*/
lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
} lv_indev_data_t;
enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR };
enum {
LV_OPA_TRANSP = 0,
LV_OPA_0 = 0,
LV_OPA_10 = 25,
LV_OPA_20 = 51,
LV_OPA_30 = 76,
LV_OPA_40 = 102,
LV_OPA_50 = 127,
LV_OPA_60 = 153,
LV_OPA_70 = 178,
LV_OPA_80 = 204,
LV_OPA_90 = 229,
LV_OPA_100 = 255,
LV_OPA_COVER = 255,
};
extern void
xpt2046_init(void);
extern bool
touchscreen_read(lv_indev_data_t *data);
extern bool
mouse_read(lv_indev_data_t *data);
extern void
display_init(void);
extern void
display_deinit(wasm_exec_env_t exec_env);
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, 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);
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);
extern bool
display_input_read(wasm_exec_env_t exec_env, void *data);
void
display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w,
lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa);
#endif

View File

@ -1,347 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <stdbool.h>
#include "display_indev.h"
#include "SDL2/SDL.h"
#include "sys/time.h"
#include "wasm_export.h"
#include "app_manager_export.h"
#define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
#define SDL_REFR_PERIOD 50
void
monitor_sdl_init(void);
void
monitor_sdl_refr_core(void);
void
monitor_sdl_clean_up(void);
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES];
int
time_get_ms(wasm_exec_env_t exec_env)
{
static struct timeval tv;
gettimeofday(&tv, NULL);
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
return (int)time_in_mill;
}
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
static volatile bool sdl_inited = false;
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)
{
/*Return if the area is out the screen*/
if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1
|| y1 > MONITOR_VER_RES - 1) {
return;
}
int32_t y;
uint32_t w = x2 - x1 + 1;
for (y = y1; y <= y2; y++) {
memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color,
w * sizeof(lv_color_t));
color += w;
}
sdl_refr_qry = true;
/*IMPORTANT! It must be called to tell the system the flush is ready*/
}
/**
* Fill out the marked area with a color
* @param x1 left coordinate
* @param y1 top coordinate
* @param x2 right coordinate
* @param y2 bottom coordinate
* @param color fill color
*/
void
monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color)
{
/*Return if the area is out the screen*/
if (x2 < 0)
return;
if (y2 < 0)
return;
if (x1 > MONITOR_HOR_RES - 1)
return;
if (y1 > MONITOR_VER_RES - 1)
return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2;
int32_t x;
int32_t y;
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++) {
tft_fb[y * MONITOR_HOR_RES + x] = color32;
}
}
sdl_refr_qry = true;
}
/**
* Put a color map to the marked area
* @param x1 left coordinate
* @param y1 top coordinate
* @param x2 right coordinate
* @param y2 bottom coordinate
* @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)
{
/*Return if the area is out the screen*/
if (x2 < 0)
return;
if (y2 < 0)
return;
if (x1 > MONITOR_HOR_RES - 1)
return;
if (y1 > MONITOR_VER_RES - 1)
return;
/*Truncate the area to the screen*/
int32_t act_x1 = x1 < 0 ? 0 : x1;
int32_t act_y1 = y1 < 0 ? 0 : y1;
int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2;
int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2;
int32_t x;
int32_t y;
for (y = act_y1; y <= act_y2; y++) {
for (x = act_x1; x <= act_x2; x++) {
tft_fb[y * MONITOR_HOR_RES + x] =
color->full; // lv_color_to32(*color);
color++;
}
color += x2 - act_x2;
}
sdl_refr_qry = true;
}
void
display_init(void)
{}
void
display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t y2, lv_color_t *color)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
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)
{
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)
{
monitor_map(x1, y1, x2, y2, color);
}
typedef struct display_input_data {
lv_point_t point;
uint32 user_data_offset;
uint8 state;
} display_input_data;
bool
display_input_read(wasm_exec_env_t exec_env, 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_native_addr(module_inst, data_app,
sizeof(display_input_data)))
return false;
lv_indev_data_t data = { 0 };
ret = mouse_read(&data);
data_app->point = data.point;
data_app->user_data_offset =
wasm_runtime_addr_native_to_app(module_inst, data.user_data);
data_app->state = data.state;
return ret;
}
void
display_deinit(wasm_exec_env_t exec_env)
{}
void
display_vdb_write(wasm_exec_env_t exec_env, 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);
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 *)buf_xy = *color;
}
int
monitor_sdl_refr_thread(void *param)
{
(void)param;
/*If not OSX initialize SDL in the Thread*/
monitor_sdl_init();
/*Run until quit event not arrives*/
while (sdl_quit_qry == false) {
/*Refresh handling*/
monitor_sdl_refr_core();
}
monitor_sdl_clean_up();
exit(0);
return 0;
}
extern void
mouse_handler(SDL_Event *event);
void
monitor_sdl_refr_core(void)
{
if (sdl_refr_qry != false) {
sdl_refr_qry = false;
SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer);
/*Update the renderer with the texture containing the rendered image*/
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
SDL_Event event;
while (SDL_PollEvent(&event)) {
mouse_handler(&event);
if ((&event)->type == SDL_WINDOWEVENT) {
switch ((&event)->window.event) {
#if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_TAKE_FOCUS:
#endif
case SDL_WINDOWEVENT_EXPOSED:
SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
break;
default:
break;
}
}
}
/*Sleep some time*/
SDL_Delay(SDL_REFR_PERIOD);
}
int
quit_filter(void *userdata, SDL_Event *event)
{
(void)userdata;
if (event->type == SDL_QUIT) {
sdl_quit_qry = true;
}
return 1;
}
void
monitor_sdl_clean_up(void)
{
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
void
monitor_sdl_init(void)
{
/*Initialize the SDL*/
SDL_Init(SDL_INIT_VIDEO);
SDL_SetEventFilter(quit_filter, NULL);
window = SDL_CreateWindow(
"TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM,
0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
renderer = SDL_CreateRenderer(window, -1, 0);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES,
MONITOR_VER_RES);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
/*Initialize the frame buffer to gray (77 is an empirical value) */
memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t));
sdl_refr_qry = true;
sdl_inited = true;
}
void
display_SDL_init()
{
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
while (sdl_inited == false)
; /*Wait until 'sdl_refr' initializes the SDL*/
}

View File

@ -1,544 +0,0 @@
#ifndef CONNECTION_UART
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#else
#include <termios.h>
#endif
#include <arpa/inet.h>
#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <fcntl.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <strings.h>
#include "runtime_lib.h"
#include "runtime_timer.h"
#include "native_interface.h"
#include "app_manager_export.h"
#include "bh_platform.h"
#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
#define SA struct sockaddr
static char *host_address = "127.0.0.1";
static int port = 8888;
#else
static char *uart_device = "/dev/ttyS2";
static int baudrate = B115200;
#endif
extern bool
init_sensor_framework();
extern void
exit_sensor_framework();
extern void
exit_connection_framework();
extern int
aee_host_msg_callback(void *msg, uint32_t msg_len);
extern bool
init_connection_framework();
#ifndef CONNECTION_UART
int listenfd = -1;
int sockfd = -1;
static pthread_mutex_t sock_lock = PTHREAD_MUTEX_INITIALIZER;
#else
int uartfd = -1;
#endif
#ifndef CONNECTION_UART
static bool server_mode = false;
// Function designed for chat between client and server.
void *
func(void *arg)
{
char buff[MAX];
int n;
struct sockaddr_in servaddr;
while (1) {
if (sockfd != -1)
close(sockfd);
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printf("socket creation failed...\n");
return NULL;
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr(host_address);
servaddr.sin_port = htons(port);
// connect the client socket to server socket
if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n");
sleep(10);
continue;
}
else {
printf("connected to the server..\n");
}
// infinite loop for chat
for (;;) {
bzero(buff, MAX);
// read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents
// fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
// socket disconnected
if (n <= 0)
break;
aee_host_msg_callback(buff, n);
}
}
// After chatting close the socket
close(sockfd);
}
static bool
host_init()
{
return true;
}
int
host_send(void *ctx, const char *buf, int size)
{
int ret;
if (pthread_mutex_trylock(&sock_lock) == 0) {
if (sockfd == -1) {
pthread_mutex_unlock(&sock_lock);
return 0;
}
ret = write(sockfd, buf, size);
pthread_mutex_unlock(&sock_lock);
return ret;
}
return -1;
}
void
host_destroy()
{
if (server_mode)
close(listenfd);
pthread_mutex_lock(&sock_lock);
close(sockfd);
pthread_mutex_unlock(&sock_lock);
}
host_interface interface = { .init = host_init,
.send = host_send,
.destroy = host_destroy };
void *
func_server_mode(void *arg)
{
int clilent;
struct sockaddr_in serv_addr, cli_addr;
int n;
char buff[MAX];
struct sigaction sa;
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGPIPE, &sa, 0);
/* First call to socket() function */
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (listenfd < 0) {
perror("ERROR opening socket");
exit(1);
}
/* Initialize socket structure */
bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port);
/* Now bind the host address using bind() call.*/
if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("ERROR on binding");
exit(1);
}
listen(listenfd, 5);
clilent = sizeof(cli_addr);
while (1) {
pthread_mutex_lock(&sock_lock);
sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent);
pthread_mutex_unlock(&sock_lock);
if (sockfd < 0) {
perror("ERROR on accept");
exit(1);
}
printf("connection established!\n");
for (;;) {
bzero(buff, MAX);
// read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff));
// socket disconnected
if (n <= 0) {
pthread_mutex_lock(&sock_lock);
close(sockfd);
sockfd = -1;
pthread_mutex_unlock(&sock_lock);
sleep(2);
break;
}
aee_host_msg_callback(buff, n);
}
}
}
#else
static int
parse_baudrate(int baud)
{
switch (baud) {
case 9600:
return B9600;
case 19200:
return B19200;
case 38400:
return B38400;
case 57600:
return B57600;
case 115200:
return B115200;
case 230400:
return B230400;
case 460800:
return B460800;
case 500000:
return B500000;
case 576000:
return B576000;
case 921600:
return B921600;
case 1000000:
return B1000000;
case 1152000:
return B1152000;
case 1500000:
return B1500000;
case 2000000:
return B2000000;
case 2500000:
return B2500000;
case 3000000:
return B3000000;
case 3500000:
return B3500000;
case 4000000:
return B4000000;
default:
return -1;
}
}
static bool
uart_init(const char *device, int baudrate, int *fd)
{
int uart_fd;
struct termios uart_term;
uart_fd = open(device, O_RDWR | O_NOCTTY);
if (uart_fd <= 0)
return false;
memset(&uart_term, 0, sizeof(uart_term));
uart_term.c_cflag = baudrate | CS8 | CLOCAL | CREAD;
uart_term.c_iflag = IGNPAR;
uart_term.c_oflag = 0;
/* set noncanonical mode */
uart_term.c_lflag = 0;
uart_term.c_cc[VTIME] = 30;
uart_term.c_cc[VMIN] = 1;
tcflush(uart_fd, TCIFLUSH);
if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) {
close(uart_fd);
return false;
}
*fd = uart_fd;
return true;
}
static void *
func_uart_mode(void *arg)
{
int n;
char buff[MAX];
if (!uart_init(uart_device, baudrate, &uartfd)) {
printf("open uart fail! %s\n", uart_device);
return NULL;
}
for (;;) {
bzero(buff, MAX);
n = read(uartfd, buff, sizeof(buff));
if (n <= 0) {
close(uartfd);
uartfd = -1;
break;
}
aee_host_msg_callback(buff, n);
}
return NULL;
}
static int
uart_send(void *ctx, const char *buf, int size)
{
int ret;
ret = write(uartfd, buf, size);
return ret;
}
static void
uart_destroy()
{
close(uartfd);
}
static host_interface interface = { .send = uart_send,
.destroy = uart_destroy };
#endif
#ifdef __x86_64__
static char global_heap_buf[400 * 1024] = { 0 };
#else
static char global_heap_buf[270 * 1024] = { 0 };
#endif
/* clang-format off */
static void showUsage()
{
#ifndef CONNECTION_UART
printf("Usage:\n");
printf("\nWork as TCP server mode:\n");
printf("\tvgl_wasm_runtime -s|--server_mode -p|--port <Port>\n");
printf("where\n");
printf("\t<Port> represents the port that would be listened on and the default is 8888\n");
printf("\nWork as TCP client mode:\n");
printf("\tvgl_wasm_runtime -a|--host_address <Host Address> -p|--port <Port>\n");
printf("where\n");
printf("\t<Host Address> represents the network address of host and the default is 127.0.0.1\n");
printf("\t<Port> represents the listen port of host and the default is 8888\n");
#else
printf("Usage:\n");
printf("\tvgl_wasm_runtime -u <Uart Device> -b <Baudrate>\n\n");
printf("where\n");
printf("\t<Uart Device> represents the UART device name and the default is /dev/ttyS2\n");
printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n");
#endif
printf("\nNote:\n");
printf("\tUse -w|--wasi_root to specify the root dir (default to '.') of WASI wasm modules. \n");
}
/* clang-format on */
static bool
parse_args(int argc, char *argv[])
{
int c;
while (1) {
int optIndex = 0;
static struct option longOpts[] = {
#ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' },
{ "port", required_argument, NULL, 'p' },
#else
{ "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 }
};
c = getopt_long(argc, argv, "sa:p:u:b:w:h", longOpts, &optIndex);
if (c == -1)
break;
switch (c) {
#ifndef CONNECTION_UART
case 's':
server_mode = true;
break;
case 'a':
host_address = optarg;
printf("host address: %s\n", host_address);
break;
case 'p':
port = atoi(optarg);
printf("port: %d\n", port);
break;
#else
case 'u':
uart_device = optarg;
printf("uart device: %s\n", uart_device);
break;
case 'b':
baudrate = parse_baudrate(atoi(optarg));
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;
default:
showUsage();
return false;
}
}
return true;
}
static NativeSymbol native_symbols[] = {
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[])
{
RuntimeInitArgs init_args;
korp_tid tid;
uint32 n_native_symbols;
if (!parse_args(argc, argv))
return -1;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
init_args.native_module_name = "env";
init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
init_args.native_symbols = native_symbols;
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
printf("Init runtime environment failed.\n");
return -1;
}
if (!init_connection_framework()) {
goto fail1;
}
extern void display_SDL_init();
display_SDL_init();
if (!init_sensor_framework()) {
goto fail2;
}
/* timer manager */
if (!init_wasm_timer()) {
goto fail3;
}
#ifndef CONNECTION_UART
if (server_mode)
os_thread_create(&tid, func_server_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
else
os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
#else
os_thread_create(&tid, func_uart_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
#endif
app_manager_startup(&interface);
exit_wasm_timer();
fail3:
exit_sensor_framework();
fail2:
exit_connection_framework();
fail1:
wasm_runtime_destroy();
return -1;
}

View File

@ -1,11 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
extern int
iwasm_main(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
return iwasm_main(argc, argv);
}

View File

@ -1,97 +0,0 @@
/**
* @file mouse.c
*
*/
/*********************
* INCLUDES
*********************/
#include "display_indev.h"
#include "SDL2/SDL.h"
#if USE_MOUSE != 0
/*********************
* DEFINES
*********************/
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static bool left_button_down = false;
static int16_t last_x = 0;
static int16_t last_y = 0;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the mouse
*/
void
mouse_init(void)
{}
/**
* Get the current position and state of the mouse
* @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be
* read
*/
bool
mouse_read(lv_indev_data_t *data)
{
/*Store the collected data*/
data->point.x = last_x;
data->point.y = last_y;
data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
return false;
}
/**
* It will be called from the main SDL thread
*/
void
mouse_handler(SDL_Event *event)
{
switch (event->type) {
case SDL_MOUSEBUTTONUP:
if (event->button.button == SDL_BUTTON_LEFT)
left_button_down = false;
break;
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == SDL_BUTTON_LEFT) {
left_button_down = true;
last_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / MONITOR_ZOOM;
}
break;
case SDL_MOUSEMOTION:
last_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / MONITOR_ZOOM;
break;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif

View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,87 +0,0 @@
/**
* @file XPT2046.h
*
*/
#ifndef XPT2046_H
#define XPT2046_H
#define USE_XPT2046 1
#define XPT2046_HOR_RES 320
#define XPT2046_VER_RES 240
#define XPT2046_X_MIN 200
#define XPT2046_Y_MIN 200
#define XPT2046_X_MAX 3800
#define XPT2046_Y_MAX 3800
#define XPT2046_AVG 4
#define XPT2046_INV 0
#define CMD_X_READ 0b10010000
#define CMD_Y_READ 0b11010000
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if USE_XPT2046
#include <autoconf.h>
#include <stdint.h>
#include <stdbool.h>
//#include "lvgl/lv_hal/lv_hal_indev.h"
#include "device.h"
#include "drivers/gpio.h"
#if 1
enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR };
typedef uint8_t lv_indev_state_t;
typedef int16_t lv_coord_t;
typedef struct {
lv_coord_t x;
lv_coord_t y;
} lv_point_t;
typedef struct {
union {
lv_point_t
point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/
uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/
int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the
previous read*/
};
void *user_data; /*'lv_indev_drv_t.priv' for this driver*/
lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
} lv_indev_data_t;
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void
xpt2046_init(void);
bool
xpt2046_read(lv_indev_data_t *data);
/**********************
* MACROS
**********************/
#endif /* USE_XPT2046 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* XPT2046_H */

View File

@ -1,9 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__
#include "pin_config_stm32.h"
#endif /* __BOARD_CONFIG_H__ */

View File

@ -1,418 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Public API for display drivers and applications
*/
#ifndef ZEPHYR_INCLUDE_DISPLAY_H_
#define ZEPHYR_INCLUDE_DISPLAY_H_
/**
* @brief Display Interface
* @defgroup display_interface Display Interface
* @ingroup display_interfaces
* @{
*/
#include <device.h>
#include <stddef.h>
#include <zephyr/types.h>
#ifdef __cplusplus
extern "C" {
#endif
enum display_pixel_format {
PIXEL_FORMAT_RGB_888 = BIT(0),
PIXEL_FORMAT_MONO01 = BIT(1), /* 0=Black 1=White */
PIXEL_FORMAT_MONO10 = BIT(2), /* 1=Black 0=White */
PIXEL_FORMAT_ARGB_8888 = BIT(3),
PIXEL_FORMAT_RGB_565 = BIT(4),
};
enum display_screen_info {
/**
* If selected, one octet represents 8 pixels ordered vertically,
* otherwise ordered horizontally.
*/
SCREEN_INFO_MONO_VTILED = BIT(0),
/**
* If selected, the MSB represents the first pixel,
* otherwise MSB represents the last pixel.
*/
SCREEN_INFO_MONO_MSB_FIRST = BIT(1),
/**
* Electrophoretic Display.
*/
SCREEN_INFO_EPD = BIT(2),
/**
* Screen has two alternating ram buffers
*/
SCREEN_INFO_DOUBLE_BUFFER = BIT(3),
};
/**
* @enum display_orientation
* @brief Enumeration with possible display orientation
*
*/
enum display_orientation {
DISPLAY_ORIENTATION_NORMAL,
DISPLAY_ORIENTATION_ROTATED_90,
DISPLAY_ORIENTATION_ROTATED_180,
DISPLAY_ORIENTATION_ROTATED_270,
};
/**
* @struct display_capabilities
* @brief Structure holding display capabilities
*
* @var u16_t display_capabilities::x_resolution
* Display resolution in the X direction
*
* @var u16_t display_capabilities::y_resolution
* Display resolution in the Y direction
*
* @var u32_t display_capabilities::supported_pixel_formats
* Bitwise or of pixel formats supported by the display
*
* @var u32_t display_capabilities::screen_info
* Information about display panel
*
* @var enum display_pixel_format display_capabilities::current_pixel_format
* Currently active pixel format for the display
*
* @var enum display_orientation display_capabilities::current_orientation
* Current display orientation
*
*/
struct display_capabilities {
uint16_t x_resolution;
uint16_t y_resolution;
uint32_t supported_pixel_formats;
uint32_t screen_info;
enum display_pixel_format current_pixel_format;
enum display_orientation current_orientation;
};
/**
* @struct display_buffer_descriptor
* @brief Structure to describe display data buffer layout
*
* @var u32_t display_buffer_descriptor::buf_size
* Data buffer size in bytes
*
* @var u16_t display_buffer_descriptor::width
* Data buffer row width in pixels
*
* @var u16_t display_buffer_descriptor::height
* Data buffer column height in pixels
*
* @var u16_t display_buffer_descriptor::pitch
* Number of pixels between consecutive rows in the data buffer
*
*/
struct display_buffer_descriptor {
uint32_t buf_size;
uint16_t width;
uint16_t height;
uint16_t pitch;
};
/**
* @typedef display_blanking_on_api
* @brief Callback API to turn on display blanking
* See display_blanking_on() for argument description
*/
typedef int (*display_blanking_on_api)(const struct device *dev);
/**
* @typedef display_blanking_off_api
* @brief Callback API to turn off display blanking
* See display_blanking_off() for argument description
*/
typedef int (*display_blanking_off_api)(const struct device *dev);
/**
* @typedef display_write_api
* @brief Callback API for writing data to the display
* See display_write() for argument description
*/
typedef int (*display_write_api)(const struct device *dev, const uint16_t x,
const uint16_t y,
const struct display_buffer_descriptor *desc,
const void *buf);
/**
* @typedef display_read_api
* @brief Callback API for reading data from the display
* See display_read() for argument description
*/
typedef int (*display_read_api)(const struct device *dev, const uint16_t x,
const uint16_t y,
const struct display_buffer_descriptor *desc,
void *buf);
/**
* @typedef display_get_framebuffer_api
* @brief Callback API to get framebuffer pointer
* See display_get_framebuffer() for argument description
*/
typedef void *(*display_get_framebuffer_api)(const struct device *dev);
/**
* @typedef display_set_brightness_api
* @brief Callback API to set display brightness
* See display_set_brightness() for argument description
*/
typedef int (*display_set_brightness_api)(const struct device *dev,
const uint8_t brightness);
/**
* @typedef display_set_contrast_api
* @brief Callback API to set display contrast
* See display_set_contrast() for argument description
*/
typedef int (*display_set_contrast_api)(const struct device *dev,
const uint8_t contrast);
/**
* @typedef display_get_capabilities_api
* @brief Callback API to get display capabilities
* See display_get_capabilities() for argument description
*/
typedef void (*display_get_capabilities_api)(
const struct device *dev, struct display_capabilities *capabilities);
/**
* @typedef display_set_pixel_format_api
* @brief Callback API to set pixel format used by the display
* See display_set_pixel_format() for argument description
*/
typedef int (*display_set_pixel_format_api)(
const struct device *dev, const enum display_pixel_format pixel_format);
/**
* @typedef display_set_orientation_api
* @brief Callback API to set orientation used by the display
* See display_set_orientation() for argument description
*/
typedef int (*display_set_orientation_api)(
const struct device *dev, const enum display_orientation orientation);
/**
* @brief Display driver API
* API which a display driver should expose
*/
struct display_driver_api {
display_blanking_on_api blanking_on;
display_blanking_off_api blanking_off;
display_write_api write;
display_read_api read;
display_get_framebuffer_api get_framebuffer;
display_set_brightness_api set_brightness;
display_set_contrast_api set_contrast;
display_get_capabilities_api get_capabilities;
display_set_pixel_format_api set_pixel_format;
display_set_orientation_api set_orientation;
};
extern struct ili9340_data ili9340_data1;
extern struct display_driver_api ili9340_api1;
/**
* @brief Write data to display
*
* @param dev Pointer to device structure
* @param x x Coordinate of the upper left corner where to write the buffer
* @param y y Coordinate of the upper left corner where to write the buffer
* @param desc Pointer to a structure describing the buffer layout
* @param buf Pointer to buffer array
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_write(const struct device *dev, const uint16_t x, const uint16_t y,
const struct display_buffer_descriptor *desc, const void *buf)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->write(dev, x, y, desc, buf);
}
/**
* @brief Read data from display
*
* @param dev Pointer to device structure
* @param x x Coordinate of the upper left corner where to read from
* @param y y Coordinate of the upper left corner where to read from
* @param desc Pointer to a structure describing the buffer layout
* @param buf Pointer to buffer array
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_read(const struct device *dev, const uint16_t x, const uint16_t y,
const struct display_buffer_descriptor *desc, void *buf)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->read(dev, x, y, desc, buf);
}
/**
* @brief Get pointer to framebuffer for direct access
*
* @param dev Pointer to device structure
*
* @retval Pointer to frame buffer or NULL if direct framebuffer access
* is not supported
*
*/
static inline void *
display_get_framebuffer(const struct device *dev)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->get_framebuffer(dev);
}
/**
* @brief Turn display blanking on
*
* @param dev Pointer to device structure
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_blanking_on(const struct device *dev)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->blanking_on(dev);
}
/**
* @brief Turn display blanking off
*
* @param dev Pointer to device structure
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_blanking_off(const struct device *dev)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->blanking_off(dev);
}
/**
* @brief Set the brightness of the display
*
* Set the brightness of the display in steps of 1/256, where 255 is full
* brightness and 0 is minimal.
*
* @param dev Pointer to device structure
* @param brightness Brightness in steps of 1/256
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_brightness(const struct device *dev, uint8_t brightness)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_brightness(dev, brightness);
}
/**
* @brief Set the contrast of the display
*
* Set the contrast of the display in steps of 1/256, where 255 is maximum
* difference and 0 is minimal.
*
* @param dev Pointer to device structure
* @param contrast Contrast in steps of 1/256
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_contrast(const struct device *dev, uint8_t contrast)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_contrast(dev, contrast);
}
/**
* @brief Get display capabilities
*
* @param dev Pointer to device structure
* @param capabilities Pointer to capabilities structure to populate
*/
static inline void
display_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
api->get_capabilities(dev, capabilities);
}
/**
* @brief Set pixel format used by the display
*
* @param dev Pointer to device structure
* @param pixel_format Pixel format to be used by display
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_pixel_format(const struct device *dev,
const enum display_pixel_format pixel_format)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_pixel_format(dev, pixel_format);
}
/**
* @brief Set display orientation
*
* @param dev Pointer to device structure
* @param orientation Orientation to be used by display
*
* @retval 0 on success else negative errno code.
*/
static inline int
display_set_orientation(const struct device *dev,
const enum display_orientation orientation)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
return api->set_orientation(dev, orientation);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_DISPLAY_H_*/

View File

@ -1,284 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "display_ili9340.h"
#include <display.h>
//#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL
//#include <logging/log.h>
// LOG_MODULE_REGISTER(display_ili9340);
#define LOG_ERR printf
#define LOG_DBG printf
#define LOG_WRN printf
#include <drivers/gpio.h>
#include <sys/byteorder.h>
#include <drivers/spi.h>
#include <string.h>
#include <stdio.h>
struct ili9340_data {
struct device *reset_gpio;
struct device *command_data_gpio;
struct device *spi_dev;
struct spi_config spi_config;
#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER
struct spi_cs_control cs_ctrl;
#endif
};
struct ili9340_data ili9340_data1;
#define ILI9340_CMD_DATA_PIN_COMMAND 0
#define ILI9340_CMD_DATA_PIN_DATA 1
static void
ili9340_exit_sleep(struct ili9340_data *data)
{
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
// k_sleep(Z_TIMEOUT_MS(120));
}
int
ili9340_init()
{
struct ili9340_data *data = &ili9340_data1;
printf("Initializing display driver\n");
data->spi_dev = device_get_binding(DT_ILITEK_ILI9340_0_BUS_NAME);
if (data->spi_dev == NULL) {
return -EPERM;
}
data->spi_config.frequency = DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY;
data->spi_config.operation =
SPI_OP_MODE_MASTER
| SPI_WORD_SET(8); // SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
data->spi_config.slave = DT_ILITEK_ILI9340_0_BASE_ADDRESS;
#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER
data->cs_ctrl.gpio_dev =
device_get_binding(DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER);
data->cs_ctrl.gpio_pin = DT_ILITEK_ILI9340_0_CS_GPIO_PIN;
data->cs_ctrl.delay = 0;
data->spi_config.cs = &(data->cs_ctrl);
#else
data->spi_config.cs = NULL;
#endif
data->reset_gpio =
device_get_binding(DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER);
if (data->reset_gpio == NULL) {
return -EPERM;
}
gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN,
GPIO_OUTPUT);
data->command_data_gpio =
device_get_binding(DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER);
if (data->command_data_gpio == NULL) {
return -EPERM;
}
gpio_pin_configure(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, GPIO_OUTPUT);
LOG_DBG("Resetting display driver\n");
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 0);
k_sleep(Z_TIMEOUT_MS(1));
gpio_pin_set(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, 1);
k_sleep(Z_TIMEOUT_MS(5));
LOG_DBG("Initializing LCD\n");
ili9340_lcd_init(data);
LOG_DBG("Exiting sleep mode\n");
ili9340_exit_sleep(data);
return 0;
}
static void
ili9340_set_mem_area(struct ili9340_data *data, const uint16_t x,
const uint16_t y, const uint16_t w, const uint16_t h)
{
uint16_t spi_data[2];
spi_data[0] = sys_cpu_to_be16(x);
spi_data[1] = sys_cpu_to_be16(x + w - 1);
ili9340_transmit(data, ILI9340_CMD_COLUMN_ADDR, &spi_data[0], 4);
spi_data[0] = sys_cpu_to_be16(y);
spi_data[1] = sys_cpu_to_be16(y + h - 1);
ili9340_transmit(data, ILI9340_CMD_PAGE_ADDR, &spi_data[0], 4);
}
static int
ili9340_write(const struct device *dev, const uint16_t x, const uint16_t y,
const struct display_buffer_descriptor *desc, const void *buf)
{
struct ili9340_data *data = (struct ili9340_data *)&ili9340_data1;
const uint8_t *write_data_start = (uint8_t *)buf;
struct spi_buf tx_buf;
struct spi_buf_set tx_bufs;
uint16_t write_cnt;
uint16_t nbr_of_writes;
uint16_t write_h;
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
__ASSERT((3 * desc->pitch * desc->height) <= desc->buf_size,
"Input buffer to small");
ili9340_set_mem_area(data, x, y, desc->width, desc->height);
if (desc->pitch > desc->width) {
write_h = 1U;
nbr_of_writes = desc->height;
}
else {
write_h = desc->height;
nbr_of_writes = 1U;
}
ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *)write_data_start,
3 * desc->width * write_h);
tx_bufs.buffers = &tx_buf;
tx_bufs.count = 1;
write_data_start += (3 * desc->pitch);
for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) {
tx_buf.buf = (void *)write_data_start;
tx_buf.len = 3 * desc->width * write_h;
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
write_data_start += (3 * desc->pitch);
}
return 0;
}
static int
ili9340_read(const struct device *dev, const uint16_t x, const uint16_t y,
const struct display_buffer_descriptor *desc, void *buf)
{
LOG_ERR("Reading not supported\n");
return -ENOTSUP;
}
static void *
ili9340_get_framebuffer(const struct device *dev)
{
LOG_ERR("Direct framebuffer access not supported\n");
return NULL;
}
static int
ili9340_display_blanking_off(const struct device *dev)
{
struct ili9340_data *data = (struct ili9340_data *)dev->driver_data;
LOG_DBG("Turning display blanking off\n");
ili9340_transmit(data, ILI9340_CMD_DISPLAY_ON, NULL, 0);
return 0;
}
static int
ili9340_display_blanking_on(const struct device *dev)
{
struct ili9340_data *data = (struct ili9340_data *)dev->driver_data;
LOG_DBG("Turning display blanking on\n");
ili9340_transmit(data, ILI9340_CMD_DISPLAY_OFF, NULL, 0);
return 0;
}
static int
ili9340_set_brightness(const struct device *dev, const uint8_t brightness)
{
LOG_WRN("Set brightness not implemented\n");
return -ENOTSUP;
}
static int
ili9340_set_contrast(const struct device *dev, const uint8_t contrast)
{
LOG_ERR("Set contrast not supported\n");
return -ENOTSUP;
}
static int
ili9340_set_pixel_format(const struct device *dev,
const enum display_pixel_format pixel_format)
{
if (pixel_format == PIXEL_FORMAT_RGB_888) {
return 0;
}
LOG_ERR("Pixel format change not implemented\n");
return -ENOTSUP;
}
static int
ili9340_set_orientation(const struct device *dev,
const enum display_orientation orientation)
{
if (orientation == DISPLAY_ORIENTATION_NORMAL) {
return 0;
}
LOG_ERR("Changing display orientation not implemented\n");
return -ENOTSUP;
}
static void
ili9340_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities)
{
memset(capabilities, 0, sizeof(struct display_capabilities));
capabilities->x_resolution = 320;
capabilities->y_resolution = 240;
capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_888;
capabilities->current_pixel_format = PIXEL_FORMAT_RGB_888;
capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL;
}
void
ili9340_transmit(struct ili9340_data *data, uint8_t cmd, void *tx_data,
size_t tx_len)
{
struct spi_buf tx_buf = { .buf = &cmd, .len = 1 };
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 };
data = (struct ili9340_data *)&ili9340_data1;
gpio_pin_set(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_COMMAND);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
if (tx_data != NULL) {
tx_buf.buf = tx_data;
tx_buf.len = tx_len;
gpio_pin_set(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_DATA);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
}
}
struct display_driver_api ili9340_api1 = {
.blanking_on = ili9340_display_blanking_on,
.blanking_off = ili9340_display_blanking_off,
.write = ili9340_write,
.read = ili9340_read,
.get_framebuffer = ili9340_get_framebuffer,
.set_brightness = ili9340_set_brightness,
.set_contrast = ili9340_set_contrast,
.get_capabilities = ili9340_get_capabilities,
.set_pixel_format = ili9340_set_pixel_format,
.set_orientation = ili9340_set_orientation
};
/*
DEVICE_AND_API_INIT(ili9340, DT_ILITEK_ILI9340_0_LABEL, &ili9340_init,
&ili9340_data, NULL, APPLICATION,
CONFIG_APPLICATION_INIT_PRIORITY, &ili9340_api);
*/

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "display_ili9340.h"
void
ili9340_lcd_init(struct ili9340_data *data)
{
uint8_t tx_data[15];
tx_data[0] = 0x23;
ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_1, tx_data, 1);
tx_data[0] = 0x10;
ili9340_transmit(data, ILI9340_CMD_POWER_CTRL_2, tx_data, 1);
tx_data[0] = 0x3e;
tx_data[1] = 0x28;
ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_1, tx_data, 2);
tx_data[0] = 0x86;
ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1);
tx_data[0] =
ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR;
ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1);
tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT
| ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT;
ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1);
tx_data[0] = 0x00;
tx_data[1] = 0x18;
ili9340_transmit(data, ILI9340_CMD_FRAME_CTRL_NORMAL_MODE, tx_data, 2);
tx_data[0] = 0x08;
tx_data[1] = 0x82;
tx_data[2] = 0x27;
ili9340_transmit(data, ILI9340_CMD_DISPLAY_FUNCTION_CTRL, tx_data, 3);
tx_data[0] = 0x01;
ili9340_transmit(data, ILI9340_CMD_GAMMA_SET, tx_data, 1);
tx_data[0] = 0x0F;
tx_data[1] = 0x31;
tx_data[2] = 0x2B;
tx_data[3] = 0x0C;
tx_data[4] = 0x0E;
tx_data[5] = 0x08;
tx_data[6] = 0x4E;
tx_data[7] = 0xF1;
tx_data[8] = 0x37;
tx_data[9] = 0x07;
tx_data[10] = 0x10;
tx_data[11] = 0x03;
tx_data[12] = 0x0E;
tx_data[13] = 0x09;
tx_data[14] = 0x00;
ili9340_transmit(data, ILI9340_CMD_POSITVE_GAMMA_CORRECTION, tx_data, 15);
tx_data[0] = 0x00;
tx_data[1] = 0x0E;
tx_data[2] = 0x14;
tx_data[3] = 0x03;
tx_data[4] = 0x11;
tx_data[5] = 0x07;
tx_data[6] = 0x31;
tx_data[7] = 0xC1;
tx_data[8] = 0x48;
tx_data[9] = 0x08;
tx_data[10] = 0x0F;
tx_data[11] = 0x0C;
tx_data[12] = 0x31;
tx_data[13] = 0x36;
tx_data[14] = 0x0F;
ili9340_transmit(data, ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION, tx_data, 15);
}

View File

@ -1,105 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <stdbool.h>
#include "display_indev.h"
#include "display.h"
#include "wasm_export.h"
#include "app_manager_export.h"
#define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240
#ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1
#endif
extern int
ili9340_init();
static int lcd_initialized = 0;
void
display_init(void)
{
if (lcd_initialized != 0) {
return;
}
lcd_initialized = 1;
xpt2046_init();
ili9340_init();
display_blanking_off(NULL);
}
void
display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t y2, lv_color_t *color)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
struct display_buffer_descriptor desc;
if (!wasm_runtime_validate_native_addr(module_inst, color,
sizeof(lv_color_t)))
return;
uint16_t w = x2 - x1 + 1;
uint16_t h = y2 - y1 + 1;
desc.buf_size = 3 * w * h;
desc.width = w;
desc.pitch = w;
desc.height = h;
display_write(NULL, x1, y1, &desc, (void *)color);
/*lv_flush_ready();*/
}
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)
{}
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)
{}
bool
display_input_read(wasm_exec_env_t exec_env, void *data)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
lv_indev_data_t *lv_data = (lv_indev_data_t *)data;
if (!wasm_runtime_validate_native_addr(module_inst, lv_data,
sizeof(lv_indev_data_t)))
return false;
return touchscreen_read(lv_data);
}
void
display_deinit(wasm_exec_env_t exec_env)
{}
void
display_vdb_write(wasm_exec_env_t exec_env, 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);
uint8_t *buf_xy = (uint8_t *)buf + 3 * x + 3 * y * buf_w;
if (!wasm_runtime_validate_native_addr(module_inst, color,
sizeof(lv_color_t)))
return;
*buf_xy = color->red;
*(buf_xy + 1) = color->green;
*(buf_xy + 2) = color->blue;
}
int
time_get_ms(wasm_exec_env_t exec_env)
{
return k_uptime_get_32();
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <string.h>
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "wasm_export.h"
extern void
display_init(void);
extern int
iwasm_main();
void
main(void)
{
display_init();
iwasm_main();
for (;;) {
k_sleep(Z_TIMEOUT_MS(1000));
}
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef __PIN_CONFIG_JLF_H__
#define __PIN_CONFIG_JLF_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 5
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4
#define XPT2046_SPI_DEVICE_NAME "SPI_2"
#define XPT2046_SPI_MAX_FREQUENCY 10 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_CS_GPIO_PIN 6
#define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_PEN_GPIO_PIN 7
#define HOST_DEVICE_COMM_UART_NAME "UART_1"
#endif /* __PIN_CONFIG_JLF_H__ */

View File

@ -1,30 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef __PIN_CONFIG_STM32_H__
#define __PIN_CONFIG_STM32_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_1"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 24 * 1000 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 12
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 11
#define DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10
#define XPT2046_SPI_DEVICE_NAME "SPI_1"
#define XPT2046_SPI_MAX_FREQUENCY 12 * 1000 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIOD"
#define XPT2046_CS_GPIO_PIN 0
#define XPT2046_PEN_GPIO_CONTROLLER "GPIOD"
#define XPT2046_PEN_GPIO_PIN 1
#define HOST_DEVICE_COMM_UART_NAME "UART_6"
#endif /* __PIN_CONFIG_STM32_H__ */

View File

@ -1,71 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.8.2)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)
set (WAMR_BUILD_PLATFORM "zephyr")
enable_language (ASM)
add_definitions(-DWA_MALLOC=wasm_runtime_malloc)
add_definitions(-DWA_FREE=wasm_runtime_free)
# Build as THUMB by default
# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS_32" or "XTENSA_32"
# if we want to support arm_32, x86, mips or xtensa
if (NOT DEFINED WAMR_BUILD_TARGET)
set (WAMR_BUILD_TARGET "THUMBV7")
endif ()
if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()
if (NOT DEFINED WAMR_BUILD_AOT)
set (WAMR_BUILD_AOT 1)
endif ()
if (NOT DEFINED WAMR_BUILD_JIT)
# Disable JIT by default.
set (WAMR_BUILD_JIT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
set (WAMR_BUILD_LIBC_WASI 0)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
set (WAMR_BUILD_APP_FRAMEWORK 1)
endif ()
if (NOT DEFINED WAMR_BUILD_APP_LIST)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_SENSOR WAMR_APP_BUILD_CONNECTION)
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr)
set (LVGL_DRV_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340_adafruit_1480.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_ili9340.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/display_indev.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/XPT2046.c
)
target_sources(app PRIVATE
${WAMR_RUNTIME_LIB_SOURCE}
${LVGL_DRV_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/main.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/zephyr/iwasm_main.c
)

View File

@ -1,9 +0,0 @@
CONFIG_SPI=y
CONFIG_SPI_STM32=y
CONFIG_PRINTK=y
CONFIG_LOG=y
#CONFIG_UART_2=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_STACK_SENTINEL=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_ARM_MPU=y

View File

@ -1,9 +0,0 @@
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET X86_64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 1)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_SENSOR WAMR_APP_BUILD_CONNECTION)

View File

@ -1,57 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = /opt/wasi-sdk/bin/clang
LVGL_DIR = ${shell pwd}
SDK_DIR = $(LVGL_DIR)/../../../wamr-sdk/out/littlevgl/app-sdk
APP_FRAMEWORK_DIR = $(SDK_DIR)/wamr-app-framework
LVGL_REPO_PATH=../build/lvgl
CFLAGS += -O3 \
-I$(LVGL_DIR) \
-I$(LVGL_DIR)/../build \
-I$(LVGL_DIR)/lv_drivers \
-I$(LVGL_DIR)/src \
-I$(LVGL_DIR)/../lv_config \
-I$(APP_FRAMEWORK_DIR)/include
SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_line.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_rbasic.c
SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_img.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_arc.c
SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_rect.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_triangle.c
SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw.c ${LVGL_REPO_PATH}/lv_draw/lv_draw_label.c
SRCS += ${LVGL_REPO_PATH}/lv_draw/lv_draw_vbasic.c ${LVGL_REPO_PATH}/lv_fonts/lv_font_builtin.c
SRCS += ${LVGL_REPO_PATH}/lv_fonts/lv_font_dejavu_20.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_img.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_roller.c ${LVGL_REPO_PATH}/lv_objx/lv_cb.c ${LVGL_REPO_PATH}/lv_objx/lv_led.c ${LVGL_REPO_PATH}/lv_objx/lv_cont.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_calendar.c ${LVGL_REPO_PATH}/lv_objx/lv_gauge.c ${LVGL_REPO_PATH}/lv_objx/lv_page.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_list.c ${LVGL_REPO_PATH}/lv_objx/lv_bar.c ${LVGL_REPO_PATH}/lv_objx/lv_tabview.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_mbox.c ${LVGL_REPO_PATH}/lv_objx/lv_objx_templ.c ${LVGL_REPO_PATH}/lv_objx/lv_sw.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_label.c ${LVGL_REPO_PATH}/lv_objx/lv_slider.c ${LVGL_REPO_PATH}/lv_objx/lv_ddlist.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_imgbtn.c ${LVGL_REPO_PATH}/lv_objx/lv_line.c ${LVGL_REPO_PATH}/lv_objx/lv_chart.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_btnm.c ${LVGL_REPO_PATH}/lv_objx/lv_arc.c ${LVGL_REPO_PATH}/lv_objx/lv_preload.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_win.c ${LVGL_REPO_PATH}/lv_objx/lv_lmeter.c ${LVGL_REPO_PATH}/lv_objx/lv_btn.c
SRCS += ${LVGL_REPO_PATH}/lv_objx/lv_ta.c ${LVGL_REPO_PATH}/lv_misc/lv_log.c ${LVGL_REPO_PATH}/lv_misc/lv_fs.c
SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_task.c ${LVGL_REPO_PATH}/lv_misc/lv_circ.c ${LVGL_REPO_PATH}/lv_misc/lv_anim.c
SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_color.c ${LVGL_REPO_PATH}/lv_misc/lv_txt.c ${LVGL_REPO_PATH}/lv_misc/lv_math.c
SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_mem.c ${LVGL_REPO_PATH}/lv_misc/lv_font.c ${LVGL_REPO_PATH}/lv_misc/lv_ll.c
SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_area.c ${LVGL_REPO_PATH}/lv_misc/lv_templ.c ${LVGL_REPO_PATH}/lv_misc/lv_ufs.c
SRCS += ${LVGL_REPO_PATH}/lv_misc/lv_gc.c
SRCS += ${LVGL_REPO_PATH}/lv_hal/lv_hal_tick.c ${LVGL_REPO_PATH}/lv_hal/lv_hal_indev.c ${LVGL_REPO_PATH}/lv_hal/lv_hal_disp.c
SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_mono.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_templ.c
SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_material.c ${LVGL_REPO_PATH}/lv_themes/lv_theme.c
SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_night.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_zen.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_nemo.c
SRCS += ${LVGL_REPO_PATH}/lv_themes/lv_theme_alien.c ${LVGL_REPO_PATH}/lv_themes/lv_theme_default.c
SRCS += ${LVGL_REPO_PATH}/lv_core/lv_group.c ${LVGL_REPO_PATH}/lv_core/lv_style.c ${LVGL_REPO_PATH}/lv_core/lv_indev.c
SRCS += ${LVGL_REPO_PATH}/lv_core/lv_vdb.c ${LVGL_REPO_PATH}/lv_core/lv_obj.c ${LVGL_REPO_PATH}/lv_core/lv_refr.c
SRCS += $(LVGL_DIR)/src/main.c
all:
@$(CC) $(CFLAGS) $(SRCS) \
-O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-DLV_CONF_INCLUDE_SIMPLE \
-L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \
-Wl,--allow-undefined \
-Wl,--strip-all,--no-entry \
-Wl,--export=on_init -Wl,--export=on_timer_callback \
-Wl,--export=__heap_base,--export=__data_end \
-o ui_app_wasi.wasm

View File

@ -1,59 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
CC = /opt/wasi-sdk/bin/clang
LVGL_DIR = ${shell pwd}
WAMR_DIR = ${LVGL_DIR}/../../..
SDK_DIR = $(LVGL_DIR)/../../../wamr-sdk/out/littlevgl/app-sdk
APP_FRAMEWORK_DIR = $(SDK_DIR)/wamr-app-framework
LVGL_REPO_PATH=../build/lvgl
CFLAGS += -O3 \
-I$(LVGL_DIR) \
-I$(LVGL_DIR)/../build \
-I$(LVGL_DIR)/lv_drivers \
-I$(LVGL_DIR)/src \
-I$(LVGL_DIR)/../lv_config \
-I$(APP_FRAMEWORK_DIR)/include
SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_line.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_rbasic.c
SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_img.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_arc.c
SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_rect.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_triangle.c
SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw.c $(LVGL_REPO_PATH)/lv_draw/lv_draw_label.c
SRCS += $(LVGL_REPO_PATH)/lv_draw/lv_draw_vbasic.c $(LVGL_REPO_PATH)/lv_fonts/lv_font_builtin.c
SRCS += $(LVGL_REPO_PATH)/lv_fonts/lv_font_dejavu_20.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_img.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_roller.c $(LVGL_REPO_PATH)/lv_objx/lv_cb.c $(LVGL_REPO_PATH)/lv_objx/lv_led.c $(LVGL_REPO_PATH)/lv_objx/lv_cont.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_calendar.c $(LVGL_REPO_PATH)/lv_objx/lv_gauge.c $(LVGL_REPO_PATH)/lv_objx/lv_page.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_list.c $(LVGL_REPO_PATH)/lv_objx/lv_bar.c $(LVGL_REPO_PATH)/lv_objx/lv_tabview.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_mbox.c $(LVGL_REPO_PATH)/lv_objx/lv_objx_templ.c $(LVGL_REPO_PATH)/lv_objx/lv_sw.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_label.c $(LVGL_REPO_PATH)/lv_objx/lv_slider.c $(LVGL_REPO_PATH)/lv_objx/lv_ddlist.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_imgbtn.c $(LVGL_REPO_PATH)/lv_objx/lv_line.c $(LVGL_REPO_PATH)/lv_objx/lv_chart.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_btnm.c $(LVGL_REPO_PATH)/lv_objx/lv_arc.c $(LVGL_REPO_PATH)/lv_objx/lv_preload.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_win.c $(LVGL_REPO_PATH)/lv_objx/lv_lmeter.c $(LVGL_REPO_PATH)/lv_objx/lv_btn.c
SRCS += $(LVGL_REPO_PATH)/lv_objx/lv_ta.c $(LVGL_REPO_PATH)/lv_misc/lv_log.c $(LVGL_REPO_PATH)/lv_misc/lv_fs.c
SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_task.c $(LVGL_REPO_PATH)/lv_misc/lv_circ.c $(LVGL_REPO_PATH)/lv_misc/lv_anim.c
SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_color.c $(LVGL_REPO_PATH)/lv_misc/lv_txt.c $(LVGL_REPO_PATH)/lv_misc/lv_math.c
SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_mem.c $(LVGL_REPO_PATH)/lv_misc/lv_font.c $(LVGL_REPO_PATH)/lv_misc/lv_ll.c
SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_area.c $(LVGL_REPO_PATH)/lv_misc/lv_templ.c $(LVGL_REPO_PATH)/lv_misc/lv_ufs.c
SRCS += $(LVGL_REPO_PATH)/lv_misc/lv_gc.c
SRCS += $(LVGL_REPO_PATH)/lv_hal/lv_hal_tick.c $(LVGL_REPO_PATH)/lv_hal/lv_hal_indev.c $(LVGL_REPO_PATH)/lv_hal/lv_hal_disp.c
SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_mono.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_templ.c
SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_material.c $(LVGL_REPO_PATH)/lv_themes/lv_theme.c
SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_night.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_zen.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_nemo.c
SRCS += $(LVGL_REPO_PATH)/lv_themes/lv_theme_alien.c $(LVGL_REPO_PATH)/lv_themes/lv_theme_default.c
SRCS += $(LVGL_REPO_PATH)/lv_core/lv_group.c $(LVGL_REPO_PATH)/lv_core/lv_style.c $(LVGL_REPO_PATH)/lv_core/lv_indev.c
SRCS += $(LVGL_REPO_PATH)/lv_core/lv_vdb.c $(LVGL_REPO_PATH)/lv_core/lv_obj.c $(LVGL_REPO_PATH)/lv_core/lv_refr.c
SRCS += $(LVGL_DIR)/src/main.c
all:
@$(CC) $(CFLAGS) $(SRCS) \
--target=wasm32 -Wl,--allow-undefined \
--sysroot=$(WAMR_DIR)/wamr-sdk/app/libc-builtin-sysroot \
-O3 -z stack-size=2048 -Wl,--initial-memory=65536 \
-DLV_CONF_INCLUDE_SIMPLE \
-L$(APP_FRAMEWORK_DIR)/lib -lapp_framework \
-Wl,--allow-undefined \
-Wl,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_timer_callback \
-o ui_app_builtin_libc.wasm

View File

@ -1,22 +0,0 @@
#!/bin/sh
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
WAMR_DIR=${PWD}/../../..
if [ -z $KW_BUILD ] || [ -z $KW_OUT_FILE ];then
echo "Local Build Env"
makewrap="make"
else
echo "Klocwork Build Env"
makewrap="kwinject -o $KW_OUT_FILE make"
fi
echo "make Makefile_wasm_app"
$makewrap -f Makefile_wasm_app
echo "make Makefile_wasm_app_no_wasi"
$makewrap -f Makefile_wasm_app_no_wasi
echo "completed."

View File

@ -1,42 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef DISPLAY_INDEV_H_
#define DISPLAY_INDEV_H_
#include <stdio.h>
#include <inttypes.h>
#include "lvgl/lv_misc/lv_color.h"
#include "lvgl/lv_hal/lv_hal_indev.h"
extern void
display_init(void);
extern void
display_deinit(void);
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

View File

@ -1,189 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
/**
* @file main
*
*/
/*********************
* INCLUDES
*********************/
#include <stdlib.h>
//#include <unistd.h>
#include <inttypes.h>
#include "lvgl/lvgl.h"
#include "display_indev.h"
#include "wasm_app.h"
#include "wa-inc/timer_wasm_app.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void
hal_init(void);
// static int tick_thread(void * data);
// static void memory_monitor(void * param);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
uint32_t count = 0;
char count_str[11] = { 0 };
lv_obj_t *hello_world_label;
lv_obj_t *count_label;
lv_obj_t *btn1;
lv_obj_t *label_count1;
int label_count1_value = 0;
char label_count1_str[11] = { 0 };
void
timer1_update(user_timer_t timer1)
{
if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count / 100);
lv_label_set_text(count_label, count_str);
}
lv_task_handler();
++count;
}
static lv_res_t
btn_rel_action(lv_obj_t *btn)
{
label_count1_value++;
snprintf(label_count1_str, sizeof(label_count1_str), "%d",
label_count1_value);
lv_label_set_text(label_count1, label_count1_str);
return LV_RES_OK;
}
void
on_init()
{
/* Initialize LittlevGL */
lv_init();
/* Initialize the HAL (display, input devices, tick) for LittlevGL */
hal_init();
hello_world_label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(hello_world_label, "Hello world!");
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
count_label = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
btn1 = lv_btn_create(
lv_scr_act(),
NULL); /* Create a button on the currently loaded screen */
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK,
btn_rel_action); /* Set function to be called when the
button is released */
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0,
20); /* Align below the label */
/* Create a label on the button */
lv_obj_t *btn_label = lv_label_create(btn1, NULL);
lv_label_set_text(btn_label, "Click ++");
label_count1 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label_count1, "0");
lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
/* set up a timer */
user_timer_t timer;
timer = api_timer_create(10, true, false, timer1_update);
if (timer)
api_timer_restart(timer, 10);
else
printf("Fail to create timer.\n");
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* 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)
{
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)
{
display_vdb_write(buf, buf_w, x, y, &color, opa);
}
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_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;
#endif
lv_disp_drv_register(&disp_drv);
/* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse */
// mouse_init();
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /* Basic initialization */
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read =
display_input_read; /* This function will be called periodically (by the
library) to get the mouse position and state */
lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv);
}
/* Implement empry main function as wasi start function calls it */
int
main(int argc, char **argv)
{
(void)argc;
(void)argv;
return 0;
}

View File

@ -1,9 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
uint32_t
time_get_ms(void);

View File

@ -1 +0,0 @@
/out

View File

@ -1,40 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.9)
project (simple)
################ wamr runtime settings ################
message(STATUS "WAMR_BUILD_SDK_PROFILE=${WAMR_BUILD_SDK_PROFILE}")
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
## use library and headers in the SDK
link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/${WAMR_BUILD_SDK_PROFILE}/runtime-sdk/lib)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/${WAMR_BUILD_SDK_PROFILE}/runtime-sdk/include
${WAMR_ROOT_DIR}/core/shared/utils
${WAMR_ROOT_DIR}/core/shared/platform/linux
)
################ application related ################
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)
target_link_libraries (simple vmlib -lm -ldl -lpthread -lrt)

View File

@ -1,342 +0,0 @@
"simple" sample introduction
==============
This sample demonstrates following scenarios:
- Use tool "host_tool" to remotely install/uninstall wasm applications from the WAMR runtime over either TCP socket or UART cable
- Inter-app communication programming models
- Communication between WASM applications and the remote app host_tool
- A number of WASM applications built on top of WAMR application framework API sets
Directory structure
------------------------------
```
simple/
├── build.sh
├── CMakeLists.txt
├── README.md
├── src
│   ├── ext_lib_export.c
│   ├── iwasm_main.c
│   └── main.c
└── wasm-apps
├── connection.c
├── event_publisher.c
├── event_subscriber.c
├── request_handler.c
├── request_sender.c
├── sensor.c
└── timer.c
```
- src/ext_lib_export.c<br/>
This file is used to export native APIs. See the `The mechanism of exporting Native API to WASM application` section in WAMR README.md for detail.
- src/iwam_main.c<br/>
This file is the implementation by platform integrator. It implements the interfaces that enable the application manager communicating with the host side. See `{WAMR_ROOT}/core/app-mgr/app-mgr-shared/app_manager_export.h` for the definition of the host interface.
## Set physical communication between device and remote
```
/* Interfaces of host communication */
typedef struct host_interface {
host_init_func init;
host_send_fun send;
host_destroy_fun destroy;
} host_interface;
```
The `host_init_func` is called when the application manager starts up. And `host_send_fun` is called by the application manager to send data to the host.
Define a global variable "interface" of the data structure:
```
host_interface interface = {
.init = host_init,
.send = host_send,
.destroy = host_destroy
};
```
This interface is passed to application manager during the runtime startup:
```
app_manager_startup(&interface);
```
>
**Note:** The connection between simple and host_tool is TCP by default. The simple application works as a server and the host_tool works as a client. You can also use UART connection. To achieve this you have to uncomment the below line in CMakeLists.txt and rebuild.
```
#add_definitions (-DCONNECTION_UART)`
```
To run the UART based test, you have to set up a UART hardware connection between host_tool and the simple application. See the help of host_tool for how to specify UART device parameters.
Build the sample
==============
Execute the build.sh script then all binaries including wasm application files would be generated in 'out' directory.
```
$ ./build.sh
Enter build target profile (default=host-interp) -->
arm-interp
host-aot
host-interp
\>:
```
Enter the profile name for starting your build. "host-***" profiles build the sample for executing on your development machine, and "arm-interp" profile will do cross building for ARM target platform. If "arm-interp" is entered, please ensure the ARM cross compiler toolchain is already installed in your development machine. Your should set *ARM_A7_COMPILER_DIR* and *ARM_A7_SDKTARGETSYSROOT* environment variable in your ~/.bashrc correctly. refer to the file [profiles/arm-interp/toolchain.cmake](./profiles/arm-interp/toolchain.cmake).
```
~/.bashrc:
export ARM_A7_COMPILER_DIR="/home/beihai/cross-toolchains/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin"
export ARM_A7_SDKTARGETSYSROOT="/home/beihai/cross-toolchains/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/arm-linux-gnueabihf/libc"
notes: please set the value to the actual path of your cross toolchain.
```
If you need to create additional profile for customizing your runtime, application framework or the target platforms, a new subfolder can be created under the *profiles* folder, and place your own version of "toolchain.cmake" and "wamr_config_simple.cmake" in it.
```
$wamr-root/samples/simple/profiles$ ls
arm-interp host-aot host-interp
$wamr-root/samples/simple/profiles$ ls arm-interp/
toolchain.cmake wamr_config_simple.cmake
```
**Out directory structure**
```
out/
├── host_tool
├── simple
└── wasm-apps
├── connection.wasm
├── event_publisher.wasm
├── event_subscriber.wasm
├── request_handler.wasm
├── request_sender.wasm
├── sensor.wasm
└── timer.wasm
```
- host_tool:
A small testing tool to interact with WAMR. See the usage of this tool by executing "./host_tool -h".
`./host_tool -h`
- simple:
A simple testing tool running on the host side that interact with WAMR. It is used to install, uninstall and query WASM applications in WAMR, and send request or subscribe event, etc. See the usage of this application by executing "./simple -h".
`./simple -h`
>
Run the sample
==========================
- Enter the out directory
```
$ cd ./out/
```
- Startup the 'simple' process works in TCP server mode and you would see "App Manager started." is printed.
```
$ ./simple -s
App Manager started.
```
- Query all installed applications
```
$ ./host_tool -q
response status 69
{
"num": 0
}
```
The `69` stands for response code SUCCESS. The payload is printed with JSON format where the `num` stands for application installations number and value `0` means currently no application is installed yet.
- Install the request handler wasm application<br/>
```
$ ./host_tool -i request_handler -f ./wasm-apps/request_handler.wasm
response status 65
```
Now the request handler application is running and waiting for host or other wasm application to send a request.
- Query again
```
$ ./host_tool -q
response status 69
{
"num": 1,
"applet1": "request_handler",
"heap1": 49152
}
```
In the payload, we can see `num` is 1 which means 1 application is installed. `applet1`stands for the name of the 1st application. `heap1` stands for the heap size of the 1st application.
- Send request from host to specific wasm application
```
$ ./host_tool -r /app/request_handler/url1 -A GET
response status 69
{
"key1": "value1",
"key2": "value2"
}
```
We can see a response with status `69` and a payload is received.
Output of simple application:
```
connection established!
Send request to applet: request_handler
Send request to app request_handler success.
App request_handler got request, url url1, action 1
[resp] ### user resource 1 handler called
sent 150 bytes to host
Wasm app process request success.
```
- Send a general request from host (not specify target application name)<br/>
```
$ ./host_tool -r /url1 -A GET
response status 69
{
"key1": "value1",
"key2": "value2"
}
```
Output of simple application:
```
connection established!
Send request to app request_handler success.
App request_handler got request, url /url1, action 1
[resp] ### user resource 1 handler called
sent 150 bytes to host
Wasm app process request success.
```
- Install the event publisher wasm application
```
$ ./host_tool -i pub -f ./wasm-apps/event_publisher.wasm
response status 65
```
- Subscribe event by host_tool<br/>
```
$ ./host_tool -s /alert/overheat -a 3000
response status 69
received an event alert/overheat
{
"warning": "temperature is over high"
}
received an event alert/overheat
{
"warning": "temperature is over high"
}
received an event alert/overheat
{
"warning": "temperature is over high"
}
received an event alert/overheat
{
"warning": "temperature is over high"
}
```
We can see 4 `alert/overheat` events are received in 3 seconds which is published by the `pub` application.
Output of simple
```
connection established!
am_register_event adding url:(alert/overheat)
client: -3 registered event (alert/overheat)
sent 16 bytes to host
sent 142 bytes to host
sent 142 bytes to host
sent 142 bytes to host
sent 142 bytes to host
```
- Install the event subscriber wasm application<br/>
```
$ ./host_tool -i sub -f ./wasm-apps/event_subscriber.wasm
response status 65
```
The `sub` application is installed.
Output of simple
```
connection established!
Install WASM app success!
WASM app 'sub' started
am_register_event adding url:(alert/overheat)
client: 3 registered event (alert/overheat)
sent 16 bytes to host
Send request to app sub success.
App sub got request, url alert/overheat, action 6
### user over heat event handler called
Attribute container dump:
Tag:
Attribute list:
key: warning, type: string, value: temperature is over high
Wasm app process request success.
```
We can see the `sub` application receives the `alert/overheat` event and dumps it out.<br/>
At device side, the event is represented by an attribute container which contains key-value pairs like below:
```
Attribute container dump:
Tag:
Attribute list:
key: warning, type: string, value: temperature is over high
```
`warning` is the key's name. `string` means this is a string value and `temperature is over high` is the value.
- Uninstall the wasm application<br/>
```
$ ./host_tool -u request_handler
response status 66
$ ./host_tool -u pub
response status 66
$ ./host_tool -u sub
response status 66
```
- Query again<br/>
```
$ ./host_tool -q
response status 69
{
"num": 0
}
```
>**Note:** Here we only installed part of the sample WASM applications. You can try others by yourself.
>**Note:** You have to manually kill the simple process by Ctrl+C after use.

View File

@ -1,166 +0,0 @@
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#!/bin/bash
CURR_DIR=$PWD
WAMR_DIR=${PWD}/../..
OUT_DIR=${PWD}/out
BUILD_DIR=${PWD}/build
IWASM_ROOT=${PWD}/../../core/iwasm
APP_FRAMEWORK_DIR=${PWD}/../../core/app-framework
NATIVE_LIBS=${APP_FRAMEWORK_DIR}/app-native-shared
APP_LIB_SRC="${APP_FRAMEWORK_DIR}/base/app/*.c ${APP_FRAMEWORK_DIR}/sensor/app/*.c \
${APP_FRAMEWORK_DIR}/connection/app/*.c ${NATIVE_LIBS}/*.c"
WASM_APPS=${PWD}/wasm-apps
CLEAN=
CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Debug"
CM_TOOLCHAIN=""
usage ()
{
echo "build.sh [options]"
echo " -p [profile]"
echo " -d [target]"
echo " -c, rebuild SDK"
exit 1
}
while getopts "p:dch" opt
do
case $opt in
p)
PROFILE=$OPTARG
;;
d)
CM_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Debug"
;;
c)
CLEAN="TRUE"
;;
h)
usage
exit 1;
;;
?)
echo "Unknown arg: $arg"
usage
exit 1
;;
esac
done
if [ "$CLEAN" = "TRUE" ]; then
rm -rf $CURR_DIR/cmake-build
fi
while [ ! -n "$PROFILE" ]
do
support_profiles=`ls -l "profiles/" |grep '^d' | awk '{print $9}'`
read -p "Enter build target profile (default=host-interp) -->
$support_profiles
\>:" read_platform
if [ ! -n "$read_platform" ]; then
PROFILE="host-interp"
else
PROFILE=$read_platform
fi
done
ARG_TOOLCHAIN=""
TOOL_CHAIN_FILE=$CURR_DIR/profiles/$PROFILE/toolchain.cmake
if [ -f $TOOL_CHAIN_FILE ]; then
CM_TOOLCHAIN="-DCMAKE_TOOLCHAIN_FILE=$TOOL_CHAIN_FILE"
ARG_TOOLCHAIN="-t $TOOL_CHAIN_FILE"
echo "toolchain file: $TOOL_CHAIN_FILE"
fi
SDK_CONFIG_FILE=$CURR_DIR/profiles/$PROFILE/wamr_config_simple.cmake
if [ ! -f $SDK_CONFIG_FILE ]; then
echo "SDK config file [$SDK_CONFIG_FILE] doesn't exit. quit.."
exit 1
fi
rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
mkdir ${OUT_DIR}/wasm-apps
cd ${WAMR_DIR}/core/shared/mem-alloc
PROFILE="simple-$PROFILE"
echo "#####################build wamr sdk"
cd ${WAMR_DIR}/wamr-sdk
./build_sdk.sh -n $PROFILE -x $SDK_CONFIG_FILE $ARG_TOOLCHAIN
[ $? -eq 0 ] || exit $?
echo "#####################build simple project"
cd ${CURR_DIR}
mkdir -p cmake-build/$PROFILE
cd cmake-build/$PROFILE
cmake ../.. -DWAMR_BUILD_SDK_PROFILE=$PROFILE $CM_TOOLCHAIN $CM_BUILD_TYPE
make
if [ $? != 0 ];then
echo "BUILD_FAIL simple exit as $?\n"
exit 2
fi
cp -a simple ${OUT_DIR}
echo "#####################build simple project success"
echo -e "\n\n"
echo "#####################build host-tool"
cd ${WAMR_DIR}/test-tools/host-tool
mkdir -p bin
cd bin
cmake .. $CM_TOOLCHAIN $CM_BUILD_TYPE
make
if [ $? != 0 ];then
echo "BUILD_FAIL host tool exit as $?\n"
exit 2
fi
cp host_tool ${OUT_DIR}
echo "#####################build host-tool success"
echo -e "\n\n"
echo "#####################build wasm apps"
cd ${WASM_APPS}
for i in `ls *.c`
do
APP_SRC="$i"
OUT_FILE=${i%.*}.wasm
/opt/wasi-sdk/bin/clang \
-I${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/wamr-app-framework/include \
-L${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/wamr-app-framework/lib \
-lapp_framework \
--target=wasm32 -O3 -z stack-size=4096 -Wl,--initial-memory=65536 \
--sysroot=${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/libc-builtin-sysroot \
-Wl,--allow-undefined-file=${WAMR_DIR}/wamr-sdk/out/$PROFILE/app-sdk/libc-builtin-sysroot/share/defined-symbols.txt \
-Wl,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_destroy \
-Wl,--export=on_request -Wl,--export=on_response \
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
-Wl,--export=on_connection_data \
-Wl,--export=__heap_base -Wl,--export=__data_end \
-o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
echo "build ${OUT_FILE} success"
else
echo "build ${OUT_FILE} fail"
fi
done
echo "#####################build wasm apps done"

View File

@ -1,40 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Linux) # this one is important
SET(CMAKE_SYSTEM_VERSION 1) # this one not so much
message(STATUS "*** ARM A7 toolchain file ***")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE")
if (NOT $ENV{ARM_A7_COMPILER_DIR} STREQUAL "")
SET (toolchain_sdk_dir $ENV{ARM_A7_COMPILER_DIR}/)
endif ()
if (NOT $ENV{ARM_A7_SDKTARGETSYSROOT} STREQUAL "")
SET(SDKTARGETSYSROOT $ENV{ARM_A7_SDKTARGETSYSROOT})
#SET(CMAKE_SYSROOT SDKTARGETSYSROOT)
endif ()
message(STATUS "SDKTARGETSYSROOT=${SDKTARGETSYSROOT}")
message(STATUS "toolchain_sdk_dir=${toolchain_sdk_dir}")
SET(CMAKE_C_COMPILER ${toolchain_sdk_dir}arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${toolchain_sdk_dir}arm-linux-gnueabihf-g++)
# this is the file system root of the target
SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT})
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -1,11 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET ARM)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 0)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR)

View File

@ -1,38 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Linux) # this one is important
SET(CMAKE_SYSTEM_VERSION 1) # this one not so much
message(STATUS "*** ARM A7 toolchain file ***")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE")
if (NOT $ENV{ARM_A7_COMPILER_DIR} STREQUAL "")
SET (toolchain_sdk_dir $ENV{ARM_A7_COMPILER_DIR}/)
endif ()
if (NOT $ENV{ARM_A7_SDKTARGETSYSROOT} STREQUAL "")
SET(SDKTARGETSYSROOT $ENV{ARM_A7_SDKTARGETSYSROOT})
endif ()
message(STATUS "SDKTARGETSYSROOT=${SDKTARGETSYSROOT}")
message(STATUS "toolchain_sdk_dir=${toolchain_sdk_dir}")
SET(CMAKE_C_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-gcc)
SET(CMAKE_CXX_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-g++)
# this is the file system root of the target
SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT})
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -1,12 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET AARCH64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_SIMD 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR)

View File

@ -1,38 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Linux) # this one is important
SET(CMAKE_SYSTEM_VERSION 1) # this one not so much
message(STATUS "*** ARM A7 toolchain file ***")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE")
if (NOT $ENV{ARM_A7_COMPILER_DIR} STREQUAL "")
SET (toolchain_sdk_dir $ENV{ARM_A7_COMPILER_DIR}/)
endif ()
if (NOT $ENV{ARM_A7_SDKTARGETSYSROOT} STREQUAL "")
SET(SDKTARGETSYSROOT $ENV{ARM_A7_SDKTARGETSYSROOT})
endif ()
message(STATUS "SDKTARGETSYSROOT=${SDKTARGETSYSROOT}")
message(STATUS "toolchain_sdk_dir=${toolchain_sdk_dir}")
SET(CMAKE_C_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-gcc)
SET(CMAKE_CXX_COMPILER ${toolchain_sdk_dir}aarch64-linux-gnu-g++)
# this is the file system root of the target
SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT})
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -1,12 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET AARCH64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 0)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_SIMD 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR)

View File

@ -1,11 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET X86_64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR)

View File

@ -1,11 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET X86_64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR)

View File

@ -1,11 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WAMR_BUILD_PLATFORM "darwin")
set (WAMR_BUILD_TARGET X86_64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_CONNECTION WAMR_APP_BUILD_SENSOR)

View File

@ -1,224 +0,0 @@
#!/usr/bin/env python3
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
import argparse
import shlex
import subprocess
import sys
import time
import traceback
import glob
WAMRC_CMD = "../../wamr-compiler/build/wamrc"
def compile_wasm_files_to_aot(wasm_apps_dir):
wasm_files = glob.glob(wasm_apps_dir + "/*.wasm")
print("Compile wasm app into aot files")
for wasm_file in wasm_files:
aot_file = wasm_file[0 : len(wasm_file) - 5] + ".aot";
cmd = [ WAMRC_CMD, "-o", aot_file, wasm_file ]
subprocess.check_call(cmd)
def start_server(cwd):
"""
Startup the 'simple' process works in TCP server mode
"""
app_server = subprocess.Popen(shlex.split("./simple -s "), cwd=cwd)
return app_server
def query_installed_application(cwd):
"""
Query all installed applications
"""
qry_prc = subprocess.run(
shlex.split("./host_tool -q"), cwd=cwd, check=False, capture_output=True
)
assert qry_prc.returncode == 69
return qry_prc.returncode, qry_prc.stdout
def install_wasm_application(wasm_name, wasm_file, cwd):
"""
Install a wasm application
"""
inst_prc = subprocess.run(
shlex.split(f"./host_tool -i {wasm_name} -f {wasm_file}"),
cwd=cwd,
check=False,
capture_output=True,
)
assert inst_prc.returncode == 65
return inst_prc.returncode, inst_prc.stdout
def uninstall_wasm_application(wasm_name, cwd):
"""
Uninstall a wasm application
"""
unst_prc = subprocess.run(
shlex.split(f"./host_tool -u {wasm_name}"),
cwd=cwd,
check=False,
capture_output=True,
)
assert unst_prc.returncode == 66
return unst_prc.returncode, unst_prc.stdout
def send_get_to_wasm_application(wasm_name, url, cwd):
"""
send a request (GET) from host to an applicaton
"""
qry_prc = subprocess.run(
shlex.split(f"./host_tool -r /app/{wasm_name}{url} -A GET"),
cwd=cwd,
check=False,
capture_output=True,
)
assert qry_prc.returncode == 69
return qry_prc.returncode, qry_prc.stdout
def main():
"""
GO!GO!!GO!!!
"""
parser = argparse.ArgumentParser(description="run the sample and examine outputs")
parser.add_argument("working_directory", type=str)
parser.add_argument("--aot", action='store_true', help="Test with AOT")
args = parser.parse_args()
test_aot = False
suffix = ".wasm"
if not args.aot:
print("Test with interpreter mode")
else:
print("Test with AOT mode")
test_aot = True
suffix = ".aot"
wasm_apps_dir = args.working_directory + "/wasm-apps"
compile_wasm_files_to_aot(wasm_apps_dir)
ret = 1
app_server = None
try:
app_server = start_server(args.working_directory)
# wait for a second
time.sleep(1)
print("--> Install timer" + suffix + "...")
install_wasm_application(
"timer", "./wasm-apps/timer" + suffix, args.working_directory
)
# wait for a second
time.sleep(3)
print("--> Query all installed applications...")
query_installed_application(args.working_directory)
print("--> Install event_publisher" + suffix + "...")
install_wasm_application(
"event_publisher",
"./wasm-apps/event_publisher" + suffix,
args.working_directory,
)
print("--> Install event_subscriber" + suffix + "...")
install_wasm_application(
"event_subscriber",
"./wasm-apps/event_subscriber" + suffix,
args.working_directory,
)
print("--> Query all installed applications...")
query_installed_application(args.working_directory)
print("--> Uninstall timer" + suffix + "...")
uninstall_wasm_application("timer", args.working_directory)
print("--> Query all installed applications...")
query_installed_application(args.working_directory)
print("--> Uninstall event_publisher" + suffix + "...")
uninstall_wasm_application(
"event_publisher",
args.working_directory,
)
print("--> Uninstall event_subscriber" + suffix + "...")
uninstall_wasm_application(
"event_subscriber",
args.working_directory,
)
print("--> Query all installed applications...")
query_installed_application(args.working_directory)
print("--> Install request_handler" + suffix + "...")
install_wasm_application(
"request_handler",
"./wasm-apps/request_handler" + suffix,
args.working_directory,
)
print("--> Query again...")
query_installed_application(args.working_directory)
print("--> Install request_sender" + suffix + "...")
install_wasm_application(
"request_sender",
"./wasm-apps/request_sender" + suffix,
args.working_directory,
)
print("--> Send GET to the Wasm application named request_handler...")
send_get_to_wasm_application("request_handler", "/url1", args.working_directory)
print("--> Uninstall request_handler" + suffix + "...")
uninstall_wasm_application(
"request_handler",
args.working_directory,
)
print("--> Uninstall request_sender" + suffix + "...")
uninstall_wasm_application(
"request_sender",
args.working_directory,
)
# Install a wasm app named "__exit_app_manager__" just to make app manager exit
# while the wasm app is uninstalled, so as to collect the code coverage data.
# Only available when collecting code coverage is enabled.
print("--> Install timer" + suffix + "...")
install_wasm_application(
"__exit_app_manager__", "./wasm-apps/timer" + suffix, args.working_directory
)
print("--> Uninstall timer" + suffix + "...")
uninstall_wasm_application(
"__exit_app_manager__",
args.working_directory,
)
# wait for a second
time.sleep(1)
print("--> All pass")
ret = 0
except AssertionError:
traceback.print_exc()
finally:
app_server.kill()
return ret
if __name__ == "__main__":
sys.exit(main())

View File

@ -1,568 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef CONNECTION_UART
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#else
#include <termios.h>
#endif
#include <arpa/inet.h>
#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <fcntl.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <strings.h>
#include "runtime_lib.h"
#include "runtime_timer.h"
#include "native_interface.h"
#include "app_manager_export.h"
#include "bh_platform.h"
#include "runtime_sensor.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#define MAX 2048
#ifndef CONNECTION_UART
#define SA struct sockaddr
static char *host_address = "127.0.0.1";
static int port = 8888;
#else
static char *uart_device = "/dev/ttyS2";
static int baudrate = B115200;
#endif
extern bool
init_sensor_framework();
extern void
exit_sensor_framework();
extern void
exit_connection_framework();
extern int
aee_host_msg_callback(void *msg, uint32_t msg_len);
extern bool
init_connection_framework();
#ifndef CONNECTION_UART
int listenfd = -1;
int sockfd = -1;
static pthread_mutex_t sock_lock = PTHREAD_MUTEX_INITIALIZER;
#else
int uartfd = -1;
#endif
#ifndef CONNECTION_UART
static bool server_mode = false;
// Function designed for chat between client and server.
void *
func(void *arg)
{
char buff[MAX];
int n;
struct sockaddr_in servaddr;
while (1) {
if (sockfd != -1)
close(sockfd);
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printf("socket creation failed...\n");
return NULL;
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr(host_address);
servaddr.sin_port = htons(port);
// connect the client socket to server socket
if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n");
sleep(10);
continue;
}
else {
printf("connected to the server..\n");
}
// infinite loop for chat
for (;;) {
bzero(buff, MAX);
// read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents
// fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
// socket disconnected
if (n <= 0)
break;
aee_host_msg_callback(buff, n);
}
}
// After chatting close the socket
close(sockfd);
}
static bool
host_init()
{
return true;
}
int
host_send(void *ctx, const char *buf, int size)
{
int ret;
if (pthread_mutex_trylock(&sock_lock) == 0) {
if (sockfd == -1) {
pthread_mutex_unlock(&sock_lock);
return 0;
}
ret = write(sockfd, buf, size);
pthread_mutex_unlock(&sock_lock);
return ret;
}
return -1;
}
void
host_destroy()
{
if (server_mode)
close(listenfd);
pthread_mutex_lock(&sock_lock);
close(sockfd);
pthread_mutex_unlock(&sock_lock);
}
/* clang-format off */
host_interface interface = {
.init = host_init,
.send = host_send,
.destroy = host_destroy
};
/* clang-format on */
/* Change it to 1 when fuzzing test */
#define WASM_ENABLE_FUZZ_TEST 0
void *
func_server_mode(void *arg)
{
int clilent;
struct sockaddr_in serv_addr, cli_addr;
int n;
char buff[MAX];
struct sigaction sa;
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGPIPE, &sa, 0);
/* First call to socket() function */
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (listenfd < 0) {
perror("ERROR opening socket");
exit(1);
}
/* Initialize socket structure */
bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port);
/* Now bind the host address using bind() call.*/
if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("ERROR on binding");
exit(1);
}
listen(listenfd, 5);
clilent = sizeof(cli_addr);
while (1) {
pthread_mutex_lock(&sock_lock);
sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent);
pthread_mutex_unlock(&sock_lock);
if (sockfd < 0) {
perror("ERROR on accept");
exit(1);
}
printf("connection established!\n");
for (;;) {
bzero(buff, MAX);
// read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff));
// socket disconnected
if (n <= 0) {
pthread_mutex_lock(&sock_lock);
close(sockfd);
sockfd = -1;
pthread_mutex_unlock(&sock_lock);
sleep(1);
break;
}
aee_host_msg_callback(buff, n);
}
#if WASM_ENABLE_FUZZ_TEST != 0
/* Exit the process when host disconnect.
This is helpful for reproducing failure case. */
close(sockfd);
exit(1);
#endif
}
}
#else
static int
parse_baudrate(int baud)
{
switch (baud) {
case 9600:
return B9600;
case 19200:
return B19200;
case 38400:
return B38400;
case 57600:
return B57600;
case 115200:
return B115200;
case 230400:
return B230400;
case 460800:
return B460800;
case 500000:
return B500000;
case 576000:
return B576000;
case 921600:
return B921600;
case 1000000:
return B1000000;
case 1152000:
return B1152000;
case 1500000:
return B1500000;
case 2000000:
return B2000000;
case 2500000:
return B2500000;
case 3000000:
return B3000000;
case 3500000:
return B3500000;
case 4000000:
return B4000000;
default:
return -1;
}
}
static bool
uart_init(const char *device, int baudrate, int *fd)
{
int uart_fd;
struct termios uart_term;
uart_fd = open(device, O_RDWR | O_NOCTTY);
if (uart_fd <= 0)
return false;
memset(&uart_term, 0, sizeof(uart_term));
uart_term.c_cflag = baudrate | CS8 | CLOCAL | CREAD;
uart_term.c_iflag = IGNPAR;
uart_term.c_oflag = 0;
/* set noncanonical mode */
uart_term.c_lflag = 0;
uart_term.c_cc[VTIME] = 30;
uart_term.c_cc[VMIN] = 1;
tcflush(uart_fd, TCIFLUSH);
if (tcsetattr(uart_fd, TCSANOW, &uart_term) != 0) {
close(uart_fd);
return false;
}
*fd = uart_fd;
return true;
}
static void *
func_uart_mode(void *arg)
{
int n;
char buff[MAX];
if (!uart_init(uart_device, baudrate, &uartfd)) {
printf("open uart fail! %s\n", uart_device);
return NULL;
}
for (;;) {
bzero(buff, MAX);
n = read(uartfd, buff, sizeof(buff));
if (n <= 0) {
close(uartfd);
uartfd = -1;
break;
}
aee_host_msg_callback(buff, n);
}
return NULL;
}
static int
uart_send(void *ctx, const char *buf, int size)
{
int ret;
ret = write(uartfd, buf, size);
return ret;
}
static void
uart_destroy()
{
close(uartfd);
}
/* clang-format off */
static host_interface interface = {
.send = uart_send,
.destroy = uart_destroy
};
/* clang-format on */
#endif
static attr_container_t *
read_test_sensor(void *sensor)
{
attr_container_t *attr_obj = attr_container_create("read test sensor data");
if (attr_obj) {
bool ret =
attr_container_set_string(&attr_obj, "name", "read test sensor");
if (!ret) {
attr_container_destroy(attr_obj);
return NULL;
}
return attr_obj;
}
return NULL;
}
static bool
config_test_sensor(void *s, void *config)
{
return false;
}
static char global_heap_buf[1024 * 1024] = { 0 };
/* clang-format off */
static void
showUsage()
{
#ifndef CONNECTION_UART
printf("Usage:\n");
printf("\nWork as TCP server mode:\n");
printf("\tsimple -s|--server_mode -p|--port <Port>\n");
printf("where\n");
printf("\t<Port> represents the port that would be listened on and the default is 8888\n");
printf("\nWork as TCP client mode:\n");
printf("\tsimple -a|--host_address <Host Address> -p|--port <Port>\n");
printf("where\n");
printf("\t<Host Address> represents the network address of host and the default is 127.0.0.1\n");
printf("\t<Port> represents the listen port of host and the default is 8888\n");
#else
printf("Usage:\n");
printf("\tsimple -u <Uart Device> -b <Baudrate>\n\n");
printf("where\n");
printf("\t<Uart Device> represents the UART device name and the default is /dev/ttyS2\n");
printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n");
#endif
}
/* clang-format on */
static bool
parse_args(int argc, char *argv[])
{
int c;
while (1) {
int optIndex = 0;
static struct option longOpts[] = {
#ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' },
{ "port", required_argument, NULL, 'p' },
#else
{ "uart", required_argument, NULL, 'u' },
{ "baudrate", required_argument, NULL, 'b' },
#endif
{ "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "sa:p:u:b:w:h", longOpts, &optIndex);
if (c == -1)
break;
switch (c) {
#ifndef CONNECTION_UART
case 's':
server_mode = true;
break;
case 'a':
host_address = optarg;
printf("host address: %s\n", host_address);
break;
case 'p':
port = atoi(optarg);
printf("port: %d\n", port);
break;
#else
case 'u':
uart_device = optarg;
printf("uart device: %s\n", uart_device);
break;
case 'b':
baudrate = parse_baudrate(atoi(optarg));
printf("uart baudrate: %s\n", optarg);
break;
#endif
case 'h':
showUsage();
return false;
default:
showUsage();
return false;
}
}
return true;
}
// Driver function
int
iwasm_main(int argc, char *argv[])
{
RuntimeInitArgs init_args;
korp_tid tid;
if (!parse_args(argc, argv))
return -1;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
#if USE_GLOBAL_HEAP_BUF != 0
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
#else
init_args.mem_alloc_type = Alloc_With_Allocator;
init_args.mem_alloc_option.allocator.malloc_func = malloc;
init_args.mem_alloc_option.allocator.realloc_func = realloc;
init_args.mem_alloc_option.allocator.free_func = free;
#endif
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
printf("Init runtime environment failed.\n");
return -1;
}
/* connection framework */
if (!init_connection_framework()) {
goto fail1;
}
/* sensor framework */
if (!init_sensor_framework()) {
goto fail2;
}
/* timer manager */
if (!init_wasm_timer()) {
goto fail3;
}
/* add the sys sensor objects */
add_sys_sensor("sensor_test1", "This is a sensor for test", 0, 1000,
read_test_sensor, config_test_sensor);
add_sys_sensor("sensor_test2", "This is a sensor for test", 0, 1000,
read_test_sensor, config_test_sensor);
start_sensor_framework();
#ifndef CONNECTION_UART
if (server_mode)
os_thread_create(&tid, func_server_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
else
os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
#else
os_thread_create(&tid, func_uart_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
#endif
app_manager_startup(&interface);
exit_wasm_timer();
fail3:
exit_sensor_framework();
fail2:
exit_connection_framework();
fail1:
wasm_runtime_destroy();
return -1;
}

View File

@ -1,14 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
extern void
iwasm_main();
int
main(int argc, char *argv[])
{
iwasm_main(argc, argv);
return 0;
}

View File

@ -1,89 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/connection.h"
#include "wa-inc/timer_wasm_app.h"
#include "wa-inc/request.h"
/* User global variable */
static int num = 0;
static user_timer_t g_timer;
static connection_t *g_conn = NULL;
void
on_data1(connection_t *conn, conn_event_type_t type, const char *data,
uint32 len, void *user_data)
{
if (type == CONN_EVENT_TYPE_DATA) {
char message[64] = { 0 };
memcpy(message, data, len);
printf("Client got a message from server -> %s\n", message);
}
else if (type == CONN_EVENT_TYPE_DISCONNECT) {
printf("connection is close by server!\n");
}
else {
printf("error: got unknown event type!!!\n");
}
}
/* Timer callback */
void
timer1_update(user_timer_t timer)
{
char message[64] = { 0 };
/* Reply to server */
snprintf(message, sizeof(message), "Hello %d", num++);
api_send_on_connection(g_conn, message, strlen(message));
}
void
my_close_handler(request_t *request)
{
response_t response[1];
if (g_conn != NULL) {
api_timer_cancel(g_timer);
api_close_connection(g_conn);
}
make_response_for_request(request, response);
set_response(response, DELETED_2_02, 0, NULL, 0);
api_response_send(response);
}
void
on_init()
{
user_timer_t timer;
attr_container_t *args;
char *str = "this is client!";
api_register_resource_handler("/close", my_close_handler);
args = attr_container_create("");
attr_container_set_string(&args, "address", "127.0.0.1");
attr_container_set_uint16(&args, "port", 7777);
g_conn = api_open_connection("TCP", args, on_data1, NULL);
if (g_conn == NULL) {
printf("connect to server fail!\n");
return;
}
printf("connect to server success! handle: %p\n", g_conn);
/* set up a timer */
timer = api_timer_create(1000, true, false, timer1_update);
api_timer_restart(timer, 1000);
}
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}

View File

@ -1,54 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
#include "wa-inc/timer_wasm_app.h"
int num = 0;
void
publish_overheat_event()
{
attr_container_t *event;
event = attr_container_create("event");
attr_container_set_string(&event, "warning", "temperature is over high");
api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
attr_container_get_serialize_length(event));
attr_container_destroy(event);
}
/* Timer callback */
void
timer1_update(user_timer_t timer)
{
publish_overheat_event();
}
void
start_timer()
{
user_timer_t timer;
/* set up a timer */
timer = api_timer_create(1000, true, false, timer1_update);
api_timer_restart(timer, 1000);
}
void
on_init()
{
start_timer();
}
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
void
over_heat_event_handler(request_t *request)
{
printf("### user over heat event handler called\n");
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *)request->payload);
}
void
on_init()
{
api_subscribe_event("alert/overheat", over_heat_event_handler);
}
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
static void
url1_request_handler(request_t *request)
{
response_t response[1];
attr_container_t *payload;
printf("[resp] ### user resource 1 handler called\n");
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *)request->payload);
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_string(&payload, "key1", "value1");
attr_container_set_string(&payload, "key2", "value2");
make_response_for_request(request, response);
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, (void *)payload,
attr_container_get_serialize_length(payload));
api_response_send(response);
attr_container_destroy(payload);
}
static void
url2_request_handler(request_t *request)
{
response_t response[1];
make_response_for_request(request, response);
set_response(response, DELETED_2_02, 0, NULL, 0);
api_response_send(response);
printf("### user resource 2 handler called\n");
}
void
on_init()
{
/* register resource uri */
api_register_resource_handler("/url1", url1_request_handler);
api_register_resource_handler("/url2", url2_request_handler);
}
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}

View File

@ -1,52 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
static void
my_response_handler(response_t *response, void *user_data)
{
char *tag = (char *)user_data;
if (response == NULL) {
printf("[req] request timeout!\n");
return;
}
printf("[req] response handler called mid:%d, status:%d, fmt:%d, "
"payload:%p, len:%d, tag:%s\n",
response->mid, response->status, response->fmt, response->payload,
response->payload_len, tag);
if (response->payload != NULL && response->payload_len > 0
&& response->fmt == FMT_ATTR_CONTAINER) {
printf("[req] dump the response payload:\n");
attr_container_dump((attr_container_t *)response->payload);
}
}
static void
test_send_request(char *url, char *tag)
{
request_t request[1];
init_request(request, url, COAP_PUT, 0, NULL, 0);
api_send_request(request, my_response_handler, tag);
}
void
on_init()
{
test_send_request("/app/request_handler/url1", "a request to target app");
test_send_request("url1", "a general request");
}
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}

View File

@ -1,83 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/sensor.h"
static sensor_t sensor1 = NULL;
static sensor_t sensor2 = NULL;
static char *user_data = NULL;
/* Sensor event callback*/
void
sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data)
{
if (sensor == sensor1) {
printf("### app get sensor event from sensor1\n");
attr_container_dump(event);
}
else {
printf("### app get sensor event from sensor2\n");
attr_container_dump(event);
}
}
void
on_init()
{
attr_container_t *config;
printf("### app on_init 1\n");
/* open a sensor */
user_data = malloc(100);
if (!user_data) {
printf("allocate memory failed\n");
return;
}
printf("### app on_init 2\n");
sensor1 = sensor_open("sensor_test1", 0, sensor_event_handler, user_data);
if (!sensor1) {
printf("open sensor1 failed\n");
return;
}
/* config the sensor */
sensor_config(sensor1, 1000, 0, 0);
printf("### app on_init 3\n");
sensor2 = sensor_open("sensor_test2", 0, sensor_event_handler, user_data);
if (!sensor2) {
printf("open sensor2 failed\n");
return;
}
/* config the sensor */
sensor_config(sensor2, 5000, 0, 0);
printf("### app on_init 4\n");
/*
config = attr_container_create("sensor config");
sensor_config(sensor, config);
attr_container_destroy(config);
*/
}
void
on_destroy()
{
if (NULL != sensor1) {
sensor_config(sensor1, 0, 0, 0);
}
if (NULL != sensor2) {
sensor_config(sensor2, 0, 0, 0);
}
if (NULL != user_data) {
free(user_data);
}
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}

View File

@ -1,34 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/timer_wasm_app.h"
/* User global variable */
static int num = 0;
/* Timer callback */
void
timer1_update(user_timer_t timer)
{
printf("Timer update %d\n", num++);
}
void
on_init()
{
user_timer_t timer;
/* set up a timer */
timer = api_timer_create(1000, true, false, timer1_update);
api_timer_restart(timer, 1000);
}
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}