Remove unused folder samples/gui and samples/littlevgl (#3853)

They had been moved to wamr-app-framework repo:
https://github.com/bytecodealliance/wamr-app-framework/tree/main/samples
This commit is contained in:
Wenyong Huang 2024-10-14 21:43:17 +08:00 committed by GitHub
parent b16b6044ee
commit e2680e5332
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 0 additions and 1346 deletions

View File

@ -1,84 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include "wasm_app.h"
#include "wa-inc/lvgl/lvgl.h"
#include "wa-inc/timer_wasm_app.h"
extern char g_widget_text[];
static void
btn_event_cb(lv_obj_t *btn, lv_event_t event);
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 = 100;
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);
}
++count;
}
void
on_init()
{
char *text;
hello_world_label = lv_label_create(NULL, NULL);
lv_label_set_text(hello_world_label, "Hello world!");
text = lv_label_get_text(hello_world_label);
printf("Label text %lu %s \n", strlen(text), text);
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
count_label = lv_label_create(NULL, NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
/* Create a button on the currently loaded screen */
btn1 = lv_btn_create(NULL, NULL);
/* Set function to be called when the button is released */
lv_obj_set_event_cb(btn1, (lv_event_cb_t)btn_event_cb);
/* Align below the label */
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0);
/* 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(NULL, NULL);
lv_label_set_text(label_count1, "100");
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 void
btn_event_cb(lv_obj_t *btn, lv_event_t event)
{
if (event == LV_EVENT_RELEASED) {
label_count1_value--;
snprintf(label_count1_str, sizeof(label_count1_str), "%d",
label_count1_value);
lv_label_set_text(label_count1, label_count1_str);
if (label_count1_value == 0)
label_count1_value = 100;
}
}

View File

@ -1,84 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include "wasm_app.h"
#include "wa-inc/lvgl/lvgl.h"
#include "wa-inc/timer_wasm_app.h"
extern char g_widget_text[];
static void
btn_event_cb(lv_obj_t *btn, lv_event_t event);
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 = 1;
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);
}
++count;
}
void
on_init()
{
char *text;
hello_world_label = lv_label_create(NULL, NULL);
lv_label_set_text(hello_world_label, "Hello world!");
text = lv_label_get_text(hello_world_label);
printf("Label text %lu %s \n", strlen(text), text);
lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
count_label = lv_label_create(NULL, NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
/* Create a button on the current loaded screen */
btn1 = lv_btn_create(NULL, NULL);
/* Set function to be called when the button is released */
lv_obj_set_event_cb(btn1, (lv_event_cb_t)btn_event_cb);
/* Align below the label */
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0);
/* 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(NULL, NULL);
lv_label_set_text(label_count1, "1");
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 void
btn_event_cb(lv_obj_t *btn, lv_event_t event)
{
if (event == LV_EVENT_RELEASED) {
label_count1_value++;
snprintf(label_count1_str, sizeof(label_count1_str), "%d",
label_count1_value);
lv_label_set_text(label_count1, label_count1_str);
if (label_count1_value == 100)
label_count1_value = 0;
}
}

View File

@ -1,348 +0,0 @@
/**
* @file XPT2046.c
*/
/*********************
* INCLUDES
*********************/
#include "XPT2046.h"
#include "board_config.h"
#include "stdio.h"
#include <string.h>
#include "drivers/spi.h"
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
#include <zephyr.h>
#include <kernel.h>
#else
#include <zephyr/kernel.h>
#endif
#if USE_XPT2046
#include <stddef.h>
#define abs(x) ((x) < 0 ? -(x) : (x))
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void
xpt2046_corr(int16_t *x, int16_t *y);
#if 0
static void xpt2046_avg(int16_t * x, int16_t * y);
#endif
/**********************
* STATIC VARIABLES
**********************/
int16_t avg_buf_x[XPT2046_AVG];
int16_t avg_buf_y[XPT2046_AVG];
uint8_t avg_last;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the XPT2046
*/
struct device *input_dev;
struct spi_config spi_conf_xpt2046;
struct spi_cs_control xpt2046_cs_ctrl;
struct device *xpt2046_pen_gpio_dev;
static struct gpio_callback gpio_cb;
lv_indev_data_t touch_point;
lv_indev_data_t last_touch_point;
#define TOUCH_READ_THREAD_STACK_SIZE 4096
static K_THREAD_STACK_DEFINE(touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE);
static struct k_thread touch_thread_data;
static struct k_sem sem_touch_read;
K_MUTEX_DEFINE(spi_display_touch_mutex);
int cnt = 0;
int touch_read_times = 0;
int last_pen_interrupt_time = 0;
void
xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
u32_t pins)
{
cnt++;
if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) {
k_sem_give(&sem_touch_read);
touch_read_times++;
last_pen_interrupt_time = k_uptime_get_32();
}
}
void
disable_pen_interrupt()
{
int ret = 0;
ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
if (ret != 0) {
printf("gpio_pin_configure GPIO_INPUT failed\n");
}
}
void
enable_pen_interrupt()
{
int ret = 0;
ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
if (ret != 0) {
printf("gpio_pin_configure failed\n");
}
}
void
touch_screen_read_thread()
{
int i;
bool ret = false;
for (;;) {
k_sem_take(&sem_touch_read, K_FOREVER);
memset(&last_touch_point, 0, sizeof(lv_indev_data_t));
memset(&touch_point, 0, sizeof(lv_indev_data_t));
memset(avg_buf_x, 0, sizeof(avg_buf_x));
memset(avg_buf_y, 0, sizeof(avg_buf_y));
k_mutex_lock(&spi_display_touch_mutex, K_FOREVER);
disable_pen_interrupt();
for (i = 0; i < 100; i++) {
ret = xpt2046_read(&touch_point);
if (ret) {
if ((abs(last_touch_point.point.x - touch_point.point.x) < 4)
&& (abs(last_touch_point.point.y - touch_point.point.y)
< 4)) {
break;
}
last_touch_point = touch_point;
}
}
enable_pen_interrupt();
k_mutex_unlock(&spi_display_touch_mutex);
}
}
void
xpt2046_init(void)
{
int ret;
input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME);
if (input_dev == NULL) {
printf("device not found. Aborting test.");
return;
}
memset((void *)&touch_point, 0, sizeof(lv_indev_data_t));
spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY;
spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
spi_conf_xpt2046.slave = 0;
spi_conf_xpt2046.cs = NULL;
#ifdef XPT2046_CS_GPIO_CONTROLLER
xpt2046_cs_ctrl.gpio_dev = device_get_binding(XPT2046_CS_GPIO_CONTROLLER);
if (xpt2046_cs_ctrl.gpio_dev == NULL) {
printk("Cannot find %s!\n", XPT2046_CS_GPIO_CONTROLLER);
return;
}
gpio_pin_configure(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN,
GPIO_OUTPUT);
gpio_pin_set(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN, 1);
xpt2046_cs_ctrl.gpio_pin = XPT2046_CS_GPIO_PIN;
xpt2046_cs_ctrl.delay = 0;
spi_conf_xpt2046.cs = &xpt2046_cs_ctrl;
#endif
#ifdef XPT2046_PEN_GPIO_CONTROLLER
xpt2046_pen_gpio_dev = device_get_binding(XPT2046_PEN_GPIO_CONTROLLER);
if (!xpt2046_pen_gpio_dev) {
printk("Cannot find %s!\n", XPT2046_PEN_GPIO_CONTROLLER);
return;
}
/* Setup GPIO input */
ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN,
(GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE
| GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE));
if (ret) {
printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN);
}
gpio_init_callback(&gpio_cb, xpt2046_pen_gpio_callback,
BIT(XPT2046_PEN_GPIO_PIN));
ret = gpio_add_callback(xpt2046_pen_gpio_dev, &gpio_cb);
if (ret) {
printk("gpio_add_callback error\n");
}
ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
if (ret) {
printk("gpio_enable_callback error\n");
}
#endif
k_sem_init(&sem_touch_read, 0, 1);
k_thread_create(&touch_thread_data, touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread,
NULL, NULL, NULL, 5, 0, K_NO_WAIT);
printf("xpt2046_init ok \n");
}
/**
* Get the current position and state of the touchpad
* @param data store the read data here
* @return false: because no ore data to be read
*/
bool
xpt2046_read(lv_indev_data_t *data)
{
static int16_t last_x = 0;
static int16_t last_y = 0;
bool valid = true;
int s32_ret = 0;
int16_t x = 0;
int16_t y = 0;
char tx1[16] = { 0 };
char rx1[16] = { 0 };
struct spi_buf tx_buf = { .buf = &tx1, .len = 3 };
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 };
struct spi_buf rx_buf = { .buf = &rx1, .len = 3 };
struct spi_buf_set rx_bufs = { .buffers = &rx_buf, .count = 1 };
tx1[0] = CMD_X_READ;
s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs);
if (s32_ret != 0) {
printf("spi_transceive return failed:%d\n", s32_ret);
}
x = rx1[1] << 8;
x += rx1[2];
tx1[0] = CMD_Y_READ;
s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs);
if (s32_ret != 0) {
printf("spi_transceive return failed:%d\n", s32_ret);
}
y = rx1[1] << 8;
y += rx1[2];
x = x >> 3;
y = y >> 3;
xpt2046_corr(&x, &y);
if (y <= 0 || (x > 320)) {
valid = false;
}
last_x = x;
last_y = y;
data->point.x = x;
data->point.y = y;
data->state = valid == false ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR;
return valid;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void
xpt2046_corr(int16_t *x, int16_t *y)
{
#if XPT2046_XY_SWAP != 0
int16_t swap_tmp;
swap_tmp = *x;
*x = *y;
*y = swap_tmp;
#endif
if ((*x) > XPT2046_X_MIN)
(*x) -= XPT2046_X_MIN;
else
(*x) = 0;
if ((*y) > XPT2046_Y_MIN)
(*y) -= XPT2046_Y_MIN;
else
(*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES)
/ (XPT2046_X_MAX - XPT2046_X_MIN);
(*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES)
/ (XPT2046_Y_MAX - XPT2046_Y_MIN);
#if XPT2046_X_INV != 0
(*x) = XPT2046_HOR_RES - (*x);
#endif
#if XPT2046_Y_INV != 0
(*y) = XPT2046_VER_RES - (*y);
#endif
}
#if 0
static void xpt2046_avg(int16_t * x, int16_t * y)
{
/*Shift out the oldest data*/
uint8_t i;
for (i = XPT2046_AVG - 1; i > 0; i--) {
avg_buf_x[i] = avg_buf_x[i - 1];
avg_buf_y[i] = avg_buf_y[i - 1];
}
/*Insert the new point*/
avg_buf_x[0] = *x;
avg_buf_y[0] = *y;
if (avg_last < XPT2046_AVG)
avg_last++;
/*Sum the x and y coordinates*/
int32_t x_sum = 0;
int32_t y_sum = 0;
for (i = 0; i < avg_last; i++) {
x_sum += avg_buf_x[i];
y_sum += avg_buf_y[i];
}
/*Normalize the sums*/
(*x) = (int32_t) x_sum / avg_last;
(*y) = (int32_t) y_sum / avg_last;
}
#endif
bool
touchscreen_read(lv_indev_data_t *data)
{
/*Store the collected data*/
data->point.x = last_touch_point.point.x;
data->point.y = last_touch_point.point.y;
data->state = last_touch_point.state;
if (last_touch_point.state == LV_INDEV_STATE_PR) {
last_touch_point.state = LV_INDEV_STATE_REL;
}
return false;
}
#endif

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
#define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
#include "board_config.h"
#include <autoconf.h>
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
#include <zephyr.h>
#else
#include <zephyr/kernel.h>
#endif
#define ILI9340_CMD_ENTER_SLEEP 0x10
#define ILI9340_CMD_EXIT_SLEEP 0x11
#define ILI9340_CMD_GAMMA_SET 0x26
#define ILI9340_CMD_DISPLAY_OFF 0x28
#define ILI9340_CMD_DISPLAY_ON 0x29
#define ILI9340_CMD_COLUMN_ADDR 0x2a
#define ILI9340_CMD_PAGE_ADDR 0x2b
#define ILI9340_CMD_MEM_WRITE 0x2c
#define ILI9340_CMD_MEM_ACCESS_CTRL 0x36
#define ILI9340_CMD_PIXEL_FORMAT_SET 0x3A
#define ILI9340_CMD_FRAME_CTRL_NORMAL_MODE 0xB1
#define ILI9340_CMD_DISPLAY_FUNCTION_CTRL 0xB6
#define ILI9340_CMD_POWER_CTRL_1 0xC0
#define ILI9340_CMD_POWER_CTRL_2 0xC1
#define ILI9340_CMD_VCOM_CTRL_1 0xC5
#define ILI9340_CMD_VCOM_CTRL_2 0xC7
#define ILI9340_CMD_POSITVE_GAMMA_CORRECTION 0xE0
#define ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION 0xE1
#define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80
#define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40
#define ILI9340_DATA_MEM_ACCESS_CTRL_MV 0x20
#define ILI9340_DATA_MEM_ACCESS_CTRL_ML 0x10
#define ILI9340_DATA_MEM_ACCESS_CTRL_BGR 0x08
#define ILI9340_DATA_MEM_ACCESS_CTRL_MH 0x04
#define ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT 0x60
#define ILI9340_DATA_PIXEL_FORMAT_RGB_16_BIT 0x50
#define ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT 0x06
#define ILI9340_DATA_PIXEL_FORMAT_MCU_16_BIT 0x05
struct ili9340_data;
/**
* Send data to ILI9340 display controller
*
* @param data Device data structure
* @param cmd Command to send to display controller
* @param tx_data Data to transmit to the display controller
* In case no data should be transmitted pass a NULL pointer
* @param tx_len Number of bytes in tx_data buffer
*
*/
void
ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data,
size_t tx_len);
/**
* Perform LCD specific initialization
*
* @param data Device data structure
*/
void
ili9340_lcd_init(struct ili9340_data *data);
#define DT_ILITEK_ILI9340_0_LABEL "DISPLAY"
#define CONFIG_DISPLAY_LOG_LEVEL 0
#endif /* ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ */

View File

@ -1,195 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bh_platform.h"
#include "runtime_lib.h"
#include "native_interface.h"
#include "app_manager_export.h"
#include "board_config.h"
#include "bh_common.h"
#include "bh_queue.h"
#include "runtime_sensor.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#include "display.h"
#include "lvgl.h"
extern bool
init_sensor_framework();
extern void
exit_sensor_framework();
extern int
aee_host_msg_callback(void *msg, uint32_t msg_len);
extern bool
touchscreen_read(lv_indev_data_t *data);
extern int
ili9340_init();
extern void
xpt2046_init(void);
extern void
wgl_init();
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
#include <zephyr.h>
#else
#include <zephyr/kernel.h>
#endif
#include <drivers/uart.h>
#include <device.h>
int uart_char_cnt = 0;
static void
uart_irq_callback(struct device *dev)
{
unsigned char ch;
while (uart_poll_in(dev, &ch) == 0) {
uart_char_cnt++;
aee_host_msg_callback(&ch, 1);
}
}
struct device *uart_dev = NULL;
static bool
host_init()
{
uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME);
if (!uart_dev) {
printf("UART: Device driver not found.\n");
return false;
}
uart_irq_rx_enable(uart_dev);
uart_irq_callback_set(uart_dev, uart_irq_callback);
return true;
}
int
host_send(void *ctx, const char *buf, int size)
{
if (!uart_dev)
return 0;
for (int i = 0; i < size; i++)
uart_poll_out(uart_dev, buf[i]);
return size;
}
void
host_destroy()
{}
/* clang-format off */
host_interface interface = {
.init = host_init,
.send = host_send,
.destroy = host_destroy
};
/* clang-format on */
timer_ctx_t timer_ctx;
static char global_heap_buf[270 * 1024] = { 0 };
static uint8_t color_copy[320 * 10 * 3];
static void
display_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color)
{
u16_t w = area->x2 - area->x1 + 1;
u16_t h = area->y2 - area->y1 + 1;
struct display_buffer_descriptor desc;
int i;
uint8_t *color_p = color_copy;
desc.buf_size = 3 * w * h;
desc.width = w;
desc.pitch = w;
desc.height = h;
for (i = 0; i < w * h; i++, color++) {
color_p[i * 3] = color->ch.red;
color_p[i * 3 + 1] = color->ch.green;
color_p[i * 3 + 2] = color->ch.blue;
}
display_write(NULL, area->x1, area->y1, &desc, (void *)color_p);
lv_disp_flush_ready(disp_drv); /* in v5.3 is lv_flush_ready */
}
static bool
display_input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
return touchscreen_read(data);
}
/**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics
* library
*/
static void
hal_init(void)
{
xpt2046_init();
ili9340_init();
display_blanking_off(NULL);
/*Create a display buffer*/
static lv_disp_buf_t disp_buf1;
static lv_color_t buf1_1[320 * 10];
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 320 * 10);
/*Create a display*/
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.buffer = &disp_buf1;
disp_drv.flush_cb = display_flush;
// disp_drv.hor_res = 200;
// disp_drv.ver_res = 100;
lv_disp_drv_register(&disp_drv);
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 = display_input_read;
lv_indev_drv_register(&indev_drv);
}
int
iwasm_main()
{
RuntimeInitArgs init_args;
host_init();
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;
}
wgl_init();
hal_init();
/* timer manager */
if (!init_wasm_timer()) {
goto fail;
}
app_manager_startup(&interface);
fail:
wasm_runtime_destroy();
return -1;
}

View File

@ -1,349 +0,0 @@
/**
* @file XPT2046.c
*/
/*********************
* INCLUDES
*********************/
#include "XPT2046.h"
#include "board_config.h"
#include "stdio.h"
#include <string.h>
#include "drivers/spi.h"
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
#include <zephyr.h>
#include <kernel.h>
#else
#include <zephyr/kernel.h>
#endif
#if USE_XPT2046
#include <stddef.h>
#define abs(x) ((x) < 0 ? -(x) : (x))
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void
xpt2046_corr(int16_t *x, int16_t *y);
#if 0
static void xpt2046_avg(int16_t * x, int16_t * y);
#endif
/**********************
* STATIC VARIABLES
**********************/
int16_t avg_buf_x[XPT2046_AVG];
int16_t avg_buf_y[XPT2046_AVG];
uint8_t avg_last;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the XPT2046
*/
struct device *input_dev;
struct spi_config spi_conf_xpt2046;
struct spi_cs_control xpt2046_cs_ctrl;
struct device *xpt2046_pen_gpio_dev;
static struct gpio_callback gpio_cb;
lv_indev_data_t touch_point;
lv_indev_data_t last_touch_point;
#define TOUCH_READ_THREAD_STACK_SIZE 4096
static K_THREAD_STACK_DEFINE(touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE);
static struct k_thread touch_thread_data;
static struct k_sem sem_touch_read;
K_MUTEX_DEFINE(spi_display_touch_mutex);
int cnt = 0;
int touch_read_times = 0;
int last_pen_interrupt_time = 0;
void
xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
uint32_t pins)
{
cnt++;
if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) {
k_sem_give(&sem_touch_read);
touch_read_times++;
last_pen_interrupt_time = k_uptime_get_32();
}
}
void
disable_pen_interrupt()
{
int ret = 0;
ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
if (ret != 0) {
printf("gpio_pin_configure GPIO_INPUT failed\n");
}
}
void
enable_pen_interrupt()
{
int ret = 0;
ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
if (ret != 0) {
printf("gpio_pin_configure failed\n");
}
}
void
touch_screen_read_thread()
{
int i;
bool ret = false;
for (;;) {
k_sem_take(&sem_touch_read, K_FOREVER);
memset(&last_touch_point, 0, sizeof(lv_indev_data_t));
memset(&touch_point, 0, sizeof(lv_indev_data_t));
memset(avg_buf_x, 0, sizeof(avg_buf_x));
memset(avg_buf_y, 0, sizeof(avg_buf_y));
k_mutex_lock(&spi_display_touch_mutex, K_FOREVER);
disable_pen_interrupt();
for (i = 0; i < 100; i++) {
ret = xpt2046_read(&touch_point);
if (ret) {
if ((abs(last_touch_point.point.x - touch_point.point.x) < 4)
&& (abs(last_touch_point.point.y - touch_point.point.y)
< 4)) {
break;
}
last_touch_point = touch_point;
}
}
enable_pen_interrupt();
k_mutex_unlock(&spi_display_touch_mutex);
}
}
void
xpt2046_init(void)
{
int ret;
input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME);
if (input_dev == NULL) {
printf("device not found. Aborting test.");
return;
}
memset((void *)&touch_point, 0, sizeof(lv_indev_data_t));
spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY;
spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
spi_conf_xpt2046.slave = 0;
spi_conf_xpt2046.cs = NULL;
#ifdef XPT2046_CS_GPIO_CONTROLLER
xpt2046_cs_ctrl.gpio_dev = device_get_binding(XPT2046_CS_GPIO_CONTROLLER);
if (xpt2046_cs_ctrl.gpio_dev == NULL) {
printk("Cannot find %s!\n", XPT2046_CS_GPIO_CONTROLLER);
return;
}
gpio_pin_configure(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN,
GPIO_OUTPUT);
gpio_pin_set(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN, 1);
xpt2046_cs_ctrl.gpio_pin = XPT2046_CS_GPIO_PIN;
xpt2046_cs_ctrl.delay = 0;
spi_conf_xpt2046.cs = &xpt2046_cs_ctrl;
#endif
#ifdef XPT2046_PEN_GPIO_CONTROLLER
xpt2046_pen_gpio_dev = device_get_binding(XPT2046_PEN_GPIO_CONTROLLER);
if (!xpt2046_pen_gpio_dev) {
printk("Cannot find %s!\n", XPT2046_PEN_GPIO_CONTROLLER);
return;
}
/* Setup GPIO input */
ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN,
(GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE
| GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE));
if (ret) {
printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN);
}
gpio_init_callback(&gpio_cb, xpt2046_pen_gpio_callback,
BIT(XPT2046_PEN_GPIO_PIN));
ret = gpio_add_callback(xpt2046_pen_gpio_dev, &gpio_cb);
if (ret) {
printk("gpio_add_callback error\n");
}
ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
if (ret) {
printk("gpio_enable_callback error\n");
}
#endif
k_sem_init(&sem_touch_read, 0, 1);
k_thread_create(&touch_thread_data, touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread,
NULL, NULL, NULL, 5, 0, K_NO_WAIT);
printf("xpt2046_init ok \n");
}
/**
* Get the current position and state of the touchpad
* @param data store the read data here
* @return false: because no ore data to be read
*/
bool
xpt2046_read(lv_indev_data_t *data)
{
static int16_t last_x = 0;
static int16_t last_y = 0;
bool valid = true;
int s32_ret = 0;
int16_t x = 0;
int16_t y = 0;
char tx1[16] = { 0 };
char rx1[16] = { 0 };
struct spi_buf tx_buf = { .buf = &tx1, .len = 3 };
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 };
struct spi_buf rx_buf = { .buf = &rx1, .len = 3 };
struct spi_buf_set rx_bufs = { .buffers = &rx_buf, .count = 1 };
tx1[0] = CMD_X_READ;
s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs);
if (s32_ret != 0) {
printf("spi_transceive return failed:%d\n", s32_ret);
}
x = rx1[1] << 8;
x += rx1[2];
tx1[0] = CMD_Y_READ;
s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs);
if (s32_ret != 0) {
printf("spi_transceive return failed:%d\n", s32_ret);
}
y = rx1[1] << 8;
y += rx1[2];
x = x >> 3;
y = y >> 3;
xpt2046_corr(&x, &y);
if (y <= 0 || (x > 320)) {
valid = false;
}
last_x = x;
last_y = y;
data->point.x = x;
data->point.y = y;
data->state = valid == false ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR;
return valid;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void
xpt2046_corr(int16_t *x, int16_t *y)
{
#if XPT2046_XY_SWAP != 0
int16_t swap_tmp;
swap_tmp = *x;
*x = *y;
*y = swap_tmp;
#endif
if ((*x) > XPT2046_X_MIN)
(*x) -= XPT2046_X_MIN;
else
(*x) = 0;
if ((*y) > XPT2046_Y_MIN)
(*y) -= XPT2046_Y_MIN;
else
(*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES)
/ (XPT2046_X_MAX - XPT2046_X_MIN);
(*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES)
/ (XPT2046_Y_MAX - XPT2046_Y_MIN);
#if XPT2046_X_INV != 0
(*x) = XPT2046_HOR_RES - (*x);
#endif
#if XPT2046_Y_INV != 0
(*y) = XPT2046_VER_RES - (*y);
#endif
}
#if 0
static void xpt2046_avg(int16_t * x, int16_t * y)
{
/*Shift out the oldest data*/
uint8_t i;
for (i = XPT2046_AVG - 1; i > 0; i--) {
avg_buf_x[i] = avg_buf_x[i - 1];
avg_buf_y[i] = avg_buf_y[i - 1];
}
/*Insert the new point*/
avg_buf_x[0] = *x;
avg_buf_y[0] = *y;
if (avg_last < XPT2046_AVG)
avg_last++;
/*Sum the x and y coordinates*/
int32_t x_sum = 0;
int32_t y_sum = 0;
for (i = 0; i < avg_last; i++) {
x_sum += avg_buf_x[i];
y_sum += avg_buf_y[i];
}
/*Normalize the sums*/
(*x) = (int32_t) x_sum / avg_last;
(*y) = (int32_t) y_sum / avg_last;
}
#endif
bool
touchscreen_read(lv_indev_data_t *data)
{
/*Store the collected data*/
data->point.x = last_touch_point.point.x;
data->point.y = last_touch_point.point.y;
data->state = last_touch_point.state;
if (last_touch_point.state == LV_INDEV_STATE_PR) {
last_touch_point.state = LV_INDEV_STATE_REL;
}
return false;
}
#endif

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
#define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
#include "board_config.h"
#include <autoconf.h>
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
#include <zephyr.h>
#else
#include <zephyr/kernel.h>
#endif
#define ILI9340_CMD_ENTER_SLEEP 0x10
#define ILI9340_CMD_EXIT_SLEEP 0x11
#define ILI9340_CMD_GAMMA_SET 0x26
#define ILI9340_CMD_DISPLAY_OFF 0x28
#define ILI9340_CMD_DISPLAY_ON 0x29
#define ILI9340_CMD_COLUMN_ADDR 0x2a
#define ILI9340_CMD_PAGE_ADDR 0x2b
#define ILI9340_CMD_MEM_WRITE 0x2c
#define ILI9340_CMD_MEM_ACCESS_CTRL 0x36
#define ILI9340_CMD_PIXEL_FORMAT_SET 0x3A
#define ILI9340_CMD_FRAME_CTRL_NORMAL_MODE 0xB1
#define ILI9340_CMD_DISPLAY_FUNCTION_CTRL 0xB6
#define ILI9340_CMD_POWER_CTRL_1 0xC0
#define ILI9340_CMD_POWER_CTRL_2 0xC1
#define ILI9340_CMD_VCOM_CTRL_1 0xC5
#define ILI9340_CMD_VCOM_CTRL_2 0xC7
#define ILI9340_CMD_POSITVE_GAMMA_CORRECTION 0xE0
#define ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION 0xE1
#define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80
#define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40
#define ILI9340_DATA_MEM_ACCESS_CTRL_MV 0x20
#define ILI9340_DATA_MEM_ACCESS_CTRL_ML 0x10
#define ILI9340_DATA_MEM_ACCESS_CTRL_BGR 0x08
#define ILI9340_DATA_MEM_ACCESS_CTRL_MH 0x04
#define ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT 0x60
#define ILI9340_DATA_PIXEL_FORMAT_RGB_16_BIT 0x50
#define ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT 0x06
#define ILI9340_DATA_PIXEL_FORMAT_MCU_16_BIT 0x05
struct ili9340_data;
/**
* Send data to ILI9340 display controller
*
* @param data Device data structure
* @param cmd Command to send to display controller
* @param tx_data Data to transmit to the display controller
* In case no data should be transmitted pass a NULL pointer
* @param tx_len Number of bytes in tx_data buffer
*
*/
void
ili9340_transmit(struct ili9340_data *data, uint8_t cmd, void *tx_data,
size_t tx_len);
/**
* Perform LCD specific initialization
*
* @param data Device data structure
*/
void
ili9340_lcd_init(struct ili9340_data *data);
#define DT_ILITEK_ILI9340_0_LABEL "DISPLAY"
#define CONFIG_DISPLAY_LOG_LEVEL 0
#endif /* ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ */

View File

@ -1,136 +0,0 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bh_platform.h"
#include "runtime_lib.h"
#include "native_interface.h"
#include "app_manager_export.h"
#include "board_config.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 "sensor_native_api.h"
#include "connection_native_api.h"
#include "display_indev.h"
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
#include <zephyr.h>
#else
#include <zephyr/kernel.h>
#endif
#include <drivers/uart.h>
#include <device.h>
extern bool
init_sensor_framework();
extern void
exit_sensor_framework();
extern int
aee_host_msg_callback(void *msg, uint32_t msg_len);
int uart_char_cnt = 0;
static void
uart_irq_callback(const struct device *dev, void *user_data)
{
unsigned char ch;
while (uart_poll_in(dev, &ch) == 0) {
uart_char_cnt++;
aee_host_msg_callback(&ch, 1);
}
(void)user_data;
}
const struct device *uart_dev = NULL;
static bool
host_init()
{
uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME);
if (!uart_dev) {
printf("UART: Device driver not found.\n");
return false;
}
uart_irq_rx_enable(uart_dev);
uart_irq_callback_set(uart_dev, uart_irq_callback);
return true;
}
int
host_send(void *ctx, const char *buf, int size)
{
if (!uart_dev)
return 0;
for (int i = 0; i < size; i++)
uart_poll_out(uart_dev, buf[i]);
return size;
}
void
host_destroy()
{}
/* clang-format off */
host_interface interface = {
.init = host_init,
.send = host_send,
.destroy = host_destroy
};
/* clang-format on */
timer_ctx_t timer_ctx;
static char global_heap_buf[350 * 1024] = { 0 };
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")
};
int
iwasm_main()
{
RuntimeInitArgs init_args;
host_init();
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;
}
display_init();
/* timer manager */
if (!init_wasm_timer()) {
goto fail;
}
app_manager_startup(&interface);
fail:
wasm_runtime_destroy();
return -1;
}