Apply clang format for samples files (#833)

Apply clang format for c source files under samples folder
This commit is contained in:
Wenyong Huang 2021-11-15 12:48:35 +08:00 committed by GitHub
parent 37a14c9825
commit 3ded9ece83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 1261 additions and 957 deletions

View File

@ -8,23 +8,27 @@
#include "bh_read_file.h" #include "bh_read_file.h"
#include "bh_getopt.h" #include "bh_getopt.h"
int intToStr(int x, char* str, int str_len, int digit); int
int get_pow(int x, int y); intToStr(int x, char *str, int str_len, int digit);
int32_t calculate_native(int32_t n, int32_t func1, int32_t func2); int
get_pow(int x, int y);
int32_t
calculate_native(int32_t n, int32_t func1, int32_t func2);
void print_usage(void) void
print_usage(void)
{ {
fprintf(stdout, "Options:\r\n"); fprintf(stdout, "Options:\r\n");
fprintf(stdout, " -f [path of wasm file] \n"); fprintf(stdout, " -f [path of wasm file] \n");
} }
int
int main(int argc, char *argv_main[]) main(int argc, char *argv_main[])
{ {
static char global_heap_buf[512 * 1024]; static char global_heap_buf[512 * 1024];
char *buffer, error_buf[128]; char *buffer, error_buf[128];
int opt; int opt;
char * wasm_path = NULL; char *wasm_path = NULL;
wasm_module_t module = NULL; wasm_module_t module = NULL;
wasm_module_inst_t module_inst = NULL; wasm_module_inst_t module_inst = NULL;
@ -32,25 +36,23 @@ int main(int argc, char *argv_main[])
uint32 buf_size, stack_size = 8092, heap_size = 8092; uint32 buf_size, stack_size = 8092, heap_size = 8092;
wasm_function_inst_t func = NULL; wasm_function_inst_t func = NULL;
wasm_function_inst_t func2 = NULL; wasm_function_inst_t func2 = NULL;
char * native_buffer = NULL; char *native_buffer = NULL;
uint32_t wasm_buffer = 0; uint32_t wasm_buffer = 0;
RuntimeInitArgs init_args; RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(RuntimeInitArgs)); memset(&init_args, 0, sizeof(RuntimeInitArgs));
while ((opt = getopt(argc, argv_main, "hf:")) != -1) while ((opt = getopt(argc, argv_main, "hf:")) != -1) {
{ switch (opt) {
switch (opt) case 'f':
{ wasm_path = optarg;
case 'f': break;
wasm_path = optarg; case 'h':
break; print_usage();
case 'h': return 0;
print_usage(); case '?':
return 0; print_usage();
case '?': return 0;
print_usage();
return 0;
} }
} }
if (optind == 1) { if (optind == 1) {
@ -64,26 +66,20 @@ int main(int argc, char *argv_main[])
// For the function signature specifications, goto the link: // For the function signature specifications, goto the link:
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md // https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md
static NativeSymbol native_symbols[] = static NativeSymbol native_symbols[] = {
{
{ {
"intToStr", // the name of WASM function name "intToStr", // the name of WASM function name
intToStr, // the native function pointer intToStr, // the native function pointer
"(i*~i)i", // the function prototype signature, avoid to use i32 "(i*~i)i", // the function prototype signature, avoid to use i32
NULL // attachment is NULL NULL // attachment is NULL
}, },
{ {
"get_pow", // the name of WASM function name "get_pow", // the name of WASM function name
get_pow, // the native function pointer get_pow, // the native function pointer
"(ii)i", // the function prototype signature, avoid to use i32 "(ii)i", // the function prototype signature, avoid to use i32
NULL // attachment is NULL NULL // attachment is NULL
}, },
{ { "calculate_native", calculate_native, "(iii)i", NULL }
"calculate_native",
calculate_native,
"(iii)i",
NULL
}
}; };
init_args.mem_alloc_type = Alloc_With_Pool; init_args.mem_alloc_type = Alloc_With_Pool;
@ -102,30 +98,27 @@ int main(int argc, char *argv_main[])
buffer = bh_read_file_to_buffer(wasm_path, &buf_size); buffer = bh_read_file_to_buffer(wasm_path, &buf_size);
if(!buffer) { if (!buffer) {
printf("Open wasm app file [%s] failed.\n", wasm_path); printf("Open wasm app file [%s] failed.\n", wasm_path);
goto fail; goto fail;
} }
module = wasm_runtime_load(buffer, buf_size, error_buf, sizeof(error_buf)); module = wasm_runtime_load(buffer, buf_size, error_buf, sizeof(error_buf));
if(!module) { if (!module) {
printf("Load wasm module failed. error: %s\n", error_buf); printf("Load wasm module failed. error: %s\n", error_buf);
goto fail; goto fail;
} }
module_inst = wasm_runtime_instantiate(module, module_inst = wasm_runtime_instantiate(module, stack_size, heap_size,
stack_size, error_buf, sizeof(error_buf));
heap_size,
error_buf,
sizeof(error_buf));
if(!module_inst) { if (!module_inst) {
printf("Instantiate wasm module failed. error: %s\n", error_buf); printf("Instantiate wasm module failed. error: %s\n", error_buf);
goto fail; goto fail;
} }
exec_env = wasm_runtime_create_exec_env(module_inst, stack_size); exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
if(!exec_env) { if (!exec_env) {
printf("Create wasm execution environment failed.\n"); printf("Create wasm execution environment failed.\n");
goto fail; goto fail;
} }
@ -135,72 +128,90 @@ int main(int argc, char *argv_main[])
argv[0] = 10; argv[0] = 10;
// the second arg will occupy two array elements // the second arg will occupy two array elements
memcpy(&argv[1], &arg_d, sizeof(arg_d)); memcpy(&argv[1], &arg_d, sizeof(arg_d));
*(float*)(argv+3) = 300.002; *(float *)(argv + 3) = 300.002;
if(!(func = wasm_runtime_lookup_function(module_inst, "generate_float", NULL))){ if (!(func = wasm_runtime_lookup_function(module_inst, "generate_float",
NULL))) {
printf("The generate_float wasm function is not found.\n"); printf("The generate_float wasm function is not found.\n");
goto fail; goto fail;
} }
// pass 4 elements for function arguments // pass 4 elements for function arguments
if (!wasm_runtime_call_wasm(exec_env, func, 4, argv) ) { if (!wasm_runtime_call_wasm(exec_env, func, 4, argv)) {
printf("call wasm function generate_float failed. %s\n", wasm_runtime_get_exception(module_inst)); printf("call wasm function generate_float failed. %s\n",
wasm_runtime_get_exception(module_inst));
goto fail; goto fail;
} }
float ret_val; float ret_val;
memcpy(&ret_val, argv, sizeof(float)); memcpy(&ret_val, argv, sizeof(float));
printf("Native finished calling wasm function generate_float(), returned a float value: %ff\n", ret_val ); printf("Native finished calling wasm function generate_float(), returned a "
"float value: %ff\n",
ret_val);
// Next we will pass a buffer to the WASM function // Next we will pass a buffer to the WASM function
uint32 argv2[4]; uint32 argv2[4];
// must allocate buffer from wasm instance memory space (never use pointer from host runtime) // must allocate buffer from wasm instance memory space (never use pointer
wasm_buffer = wasm_runtime_module_malloc(module_inst, 100, (void**)&native_buffer); // from host runtime)
wasm_buffer =
wasm_runtime_module_malloc(module_inst, 100, (void **)&native_buffer);
memcpy(argv2, &ret_val, sizeof(float)); // the first argument memcpy(argv2, &ret_val, sizeof(float)); // the first argument
argv2[1] = wasm_buffer; // the second argument is the wasm buffer address argv2[1] = wasm_buffer; // the second argument is the wasm buffer address
argv2[2] = 100; // the third argument is the wasm buffer size argv2[2] = 100; // the third argument is the wasm buffer size
argv2[3] = 3; // the last argument is the digits after decimal point for converting float to string argv2[3] = 3; // the last argument is the digits after decimal point for
// converting float to string
if(!(func2 = wasm_runtime_lookup_function(module_inst, "float_to_string", NULL))){ if (!(func2 = wasm_runtime_lookup_function(module_inst, "float_to_string",
printf("The wasm function float_to_string wasm function is not found.\n"); NULL))) {
printf(
"The wasm function float_to_string wasm function is not found.\n");
goto fail; goto fail;
} }
if (wasm_runtime_call_wasm(exec_env, func2, 4, argv2) ) { if (wasm_runtime_call_wasm(exec_env, func2, 4, argv2)) {
printf("Native finished calling wasm function: float_to_string, returned a formatted string: %s\n", native_buffer); printf("Native finished calling wasm function: float_to_string, "
"returned a formatted string: %s\n",
native_buffer);
} }
else { else {
printf("call wasm function float_to_string failed. error: %s\n", wasm_runtime_get_exception(module_inst)); printf("call wasm function float_to_string failed. error: %s\n",
wasm_runtime_get_exception(module_inst));
goto fail; goto fail;
} }
wasm_function_inst_t func3 = wasm_runtime_lookup_function(module_inst, wasm_function_inst_t func3 =
"calculate", wasm_runtime_lookup_function(module_inst, "calculate", NULL);
NULL);
if (!func3) { if (!func3) {
printf("The wasm function calculate is not found.\n"); printf("The wasm function calculate is not found.\n");
goto fail; goto fail;
} }
uint32_t argv3[1] = {3}; uint32_t argv3[1] = { 3 };
if (wasm_runtime_call_wasm(exec_env, func3, 1, argv3)) { if (wasm_runtime_call_wasm(exec_env, func3, 1, argv3)) {
uint32_t result = *(uint32_t*)argv3; uint32_t result = *(uint32_t *)argv3;
printf("Native finished calling wasm function: calculate, return: %d\n", result); printf("Native finished calling wasm function: calculate, return: %d\n",
} else { result);
printf("call wasm function calculate failed. error: %s\n", wasm_runtime_get_exception(module_inst)); }
else {
printf("call wasm function calculate failed. error: %s\n",
wasm_runtime_get_exception(module_inst));
goto fail; goto fail;
} }
fail: fail:
if(exec_env) wasm_runtime_destroy_exec_env(exec_env); if (exec_env)
if(module_inst) { wasm_runtime_destroy_exec_env(exec_env);
if(wasm_buffer) wasm_runtime_module_free(module_inst, wasm_buffer); if (module_inst) {
if (wasm_buffer)
wasm_runtime_module_free(module_inst, wasm_buffer);
wasm_runtime_deinstantiate(module_inst); wasm_runtime_deinstantiate(module_inst);
} }
if(module) wasm_runtime_unload(module); if (module)
if(buffer) BH_FREE(buffer); wasm_runtime_unload(module);
if (buffer)
BH_FREE(buffer);
wasm_runtime_destroy(); wasm_runtime_destroy();
return 0; return 0;
} }

View File

@ -8,12 +8,12 @@
#include "math.h" #include "math.h"
extern bool extern bool
wasm_runtime_call_indirect(wasm_exec_env_t exec_env, wasm_runtime_call_indirect(wasm_exec_env_t exec_env, uint32_t element_indices,
uint32_t element_indices,
uint32_t argc, uint32_t argv[]); uint32_t argc, uint32_t argv[]);
// The first parameter is not exec_env because it is invoked by native funtions // The first parameter is not exec_env because it is invoked by native funtions
void reverse(char * str, int len) void
reverse(char *str, int len)
{ {
int i = 0, j = len - 1, temp; int i = 0, j = len - 1, temp;
while (i < j) { while (i < j) {
@ -32,11 +32,12 @@ void reverse(char * str, int len)
// digit is the number of digits required in the output. // digit is the number of digits required in the output.
// If digit is more than the number of digits in x, // If digit is more than the number of digits in x,
// then 0s are added at the beginning. // then 0s are added at the beginning.
int intToStr(wasm_exec_env_t exec_env, int x, char* str, int str_len, int digit) int
intToStr(wasm_exec_env_t exec_env, int x, char *str, int str_len, int digit)
{ {
int i = 0; int i = 0;
printf ("calling into native function: %s\n", __FUNCTION__); printf("calling into native function: %s\n", __FUNCTION__);
while (x) { while (x) {
// native is responsible for checking the str_len overflow // native is responsible for checking the str_len overflow
@ -64,8 +65,10 @@ int intToStr(wasm_exec_env_t exec_env, int x, char* str, int str_len, int digit)
return i; return i;
} }
int get_pow(wasm_exec_env_t exec_env, int x, int y) { int
printf ("calling into native function: %s\n", __FUNCTION__); get_pow(wasm_exec_env_t exec_env, int x, int y)
{
printf("calling into native function: %s\n", __FUNCTION__);
return (int)pow(x, y); return (int)pow(x, y);
} }

View File

@ -8,21 +8,25 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
int intToStr(int x, char* str, int str_len, int digit); int
int get_pow(int x, int y); intToStr(int x, char *str, int str_len, int digit);
int32_t calculate_native(int32_t n, int32_t func1, int32_t func2); int
get_pow(int x, int y);
int32_t
calculate_native(int32_t n, int32_t func1, int32_t func2);
// //
// Primitive parameters functions // Primitive parameters functions
// //
float generate_float(int iteration, double seed1, float seed2) float
generate_float(int iteration, double seed1, float seed2)
{ {
float ret; float ret;
printf ("calling into WASM function: %s\n", __FUNCTION__); printf("calling into WASM function: %s\n", __FUNCTION__);
for (int i=0; i<iteration; i++){ for (int i = 0; i < iteration; i++) {
ret += 1.0f/seed1 + seed2; ret += 1.0f / seed1 + seed2;
} }
return ret; return ret;
@ -30,10 +34,11 @@ float generate_float(int iteration, double seed1, float seed2)
// Converts a floating-point/double number to a string. // Converts a floating-point/double number to a string.
// intToStr() is implemented outside wasm app // intToStr() is implemented outside wasm app
void float_to_string(float n, char* res, int res_size, int afterpoint) void
float_to_string(float n, char *res, int res_size, int afterpoint)
{ {
printf ("calling into WASM function: %s\n", __FUNCTION__); printf("calling into WASM function: %s\n", __FUNCTION__);
// Extract integer part // Extract integer part
int ipart = (int)n; int ipart = (int)n;
@ -57,25 +62,28 @@ void float_to_string(float n, char* res, int res_size, int afterpoint)
} }
} }
int32_t mul7(int32_t n) int32_t
mul7(int32_t n)
{ {
printf ("calling into WASM function: %s,", __FUNCTION__); printf("calling into WASM function: %s,", __FUNCTION__);
n = n * 7; n = n * 7;
printf (" %s return %d \n", __FUNCTION__, n); printf(" %s return %d \n", __FUNCTION__, n);
return n; return n;
} }
int32_t mul5(int32_t n) int32_t
mul5(int32_t n)
{ {
printf ("calling into WASM function: %s,", __FUNCTION__); printf("calling into WASM function: %s,", __FUNCTION__);
n = n * 5; n = n * 5;
printf (" %s return %d \n", __FUNCTION__, n); printf(" %s return %d \n", __FUNCTION__, n);
return n; return n;
} }
int32_t calculate(int32_t n) int32_t
calculate(int32_t n)
{ {
printf ("calling into WASM function: %s\n", __FUNCTION__); printf("calling into WASM function: %s\n", __FUNCTION__);
int32_t (*f1)(int32_t) = &mul5; int32_t (*f1)(int32_t) = &mul5;
int32_t (*f2)(int32_t) = &mul7; int32_t (*f2)(int32_t) = &mul7;
return calculate_native(n, (uint32_t)f1, (uint32_t)f2); return calculate_native(n, (uint32_t)f1, (uint32_t)f2);

View File

@ -5,4 +5,5 @@
#include <stdio.h> #include <stdio.h>
int time_get_ms(); int
time_get_ms();

View File

@ -10,7 +10,8 @@
extern char g_widget_text[]; extern char g_widget_text[];
static void btn_event_cb(lv_obj_t *btn, lv_event_t event); static void
btn_event_cb(lv_obj_t *btn, lv_event_t event);
uint32_t count = 0; uint32_t count = 0;
char count_str[11] = { 0 }; char count_str[11] = { 0 };
@ -21,7 +22,8 @@ lv_obj_t *label_count1;
int label_count1_value = 100; int label_count1_value = 100;
char label_count1_str[11] = { 0 }; char label_count1_str[11] = { 0 };
void timer1_update(user_timer_t timer1) void
timer1_update(user_timer_t timer1)
{ {
if ((count % 100) == 0) { if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count / 100); snprintf(count_str, sizeof(count_str), "%d", count / 100);
@ -30,7 +32,8 @@ void timer1_update(user_timer_t timer1)
++count; ++count;
} }
void on_init() void
on_init()
{ {
char *text; char *text;
@ -43,8 +46,11 @@ void on_init()
count_label = lv_label_create(NULL, NULL); count_label = lv_label_create(NULL, NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
btn1 = lv_btn_create(NULL, NULL); /*Create a button on the currently loaded screen*/ btn1 = lv_btn_create(
lv_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/ NULL, NULL); /*Create a button on the currently loaded screen*/
lv_obj_set_event_cb(
btn1,
btn_event_cb); /*Set function to be called when the button is released*/
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/ lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/
/*Create a label on the button*/ /*Create a label on the button*/
@ -64,12 +70,13 @@ void on_init()
printf("Fail to create timer.\n"); printf("Fail to create timer.\n");
} }
static void btn_event_cb(lv_obj_t *btn, lv_event_t event) static void
btn_event_cb(lv_obj_t *btn, lv_event_t event)
{ {
if(event == LV_EVENT_RELEASED) { if (event == LV_EVENT_RELEASED) {
label_count1_value--; label_count1_value--;
snprintf(label_count1_str, sizeof(label_count1_str), snprintf(label_count1_str, sizeof(label_count1_str), "%d",
"%d", label_count1_value); label_count1_value);
lv_label_set_text(label_count1, label_count1_str); lv_label_set_text(label_count1, label_count1_str);
if (label_count1_value == 0) if (label_count1_value == 0)
label_count1_value = 100; label_count1_value = 100;

View File

@ -10,7 +10,8 @@
extern char g_widget_text[]; extern char g_widget_text[];
static void btn_event_cb(lv_obj_t *btn, lv_event_t event); static void
btn_event_cb(lv_obj_t *btn, lv_event_t event);
uint32_t count = 0; uint32_t count = 0;
char count_str[11] = { 0 }; char count_str[11] = { 0 };
@ -21,7 +22,8 @@ lv_obj_t *label_count1;
int label_count1_value = 1; int label_count1_value = 1;
char label_count1_str[11] = { 0 }; char label_count1_str[11] = { 0 };
void timer1_update(user_timer_t timer1) void
timer1_update(user_timer_t timer1)
{ {
if ((count % 100) == 0) { if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count / 100); snprintf(count_str, sizeof(count_str), "%d", count / 100);
@ -30,7 +32,8 @@ void timer1_update(user_timer_t timer1)
++count; ++count;
} }
void on_init() void
on_init()
{ {
char *text; char *text;
@ -43,8 +46,11 @@ void on_init()
count_label = lv_label_create(NULL, NULL); count_label = lv_label_create(NULL, NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
btn1 = lv_btn_create(NULL, NULL); /*Create a button on the currently loaded screen*/ btn1 = lv_btn_create(
lv_obj_set_event_cb(btn1, btn_event_cb); /*Set function to be called when the button is released*/ NULL, NULL); /*Create a button on the currently loaded screen*/
lv_obj_set_event_cb(
btn1,
btn_event_cb); /*Set function to be called when the button is released*/
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/ lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/
/*Create a label on the button*/ /*Create a label on the button*/
@ -64,15 +70,15 @@ void on_init()
printf("Fail to create timer.\n"); printf("Fail to create timer.\n");
} }
static void btn_event_cb(lv_obj_t *btn, lv_event_t event) static void
btn_event_cb(lv_obj_t *btn, lv_event_t event)
{ {
if(event == LV_EVENT_RELEASED) { if (event == LV_EVENT_RELEASED) {
label_count1_value++; label_count1_value++;
snprintf(label_count1_str, sizeof(label_count1_str), snprintf(label_count1_str, sizeof(label_count1_str), "%d",
"%d", label_count1_value); label_count1_value);
lv_label_set_text(label_count1, label_count1_str); lv_label_set_text(label_count1, label_count1_str);
if (label_count1_value == 100) if (label_count1_value == 100)
label_count1_value = 0; label_count1_value = 0;
} }
} }

View File

@ -45,11 +45,16 @@ static char *uart_device = "/dev/ttyS2";
static int baudrate = B115200; static int baudrate = B115200;
#endif #endif
extern void init_sensor_framework(); extern void
extern void exit_sensor_framework(); init_sensor_framework();
extern void exit_connection_framework(); extern void
extern int aee_host_msg_callback(void *msg, uint32_t msg_len); exit_sensor_framework();
extern bool init_connection_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 #ifndef CONNECTION_UART
int listenfd = -1; int listenfd = -1;
@ -63,7 +68,8 @@ int uartfd = -1;
static bool server_mode = false; static bool server_mode = false;
// Function designed for chat between client and server. // Function designed for chat between client and server.
void* func(void* arg) void *
func(void *arg)
{ {
char buff[MAX]; char buff[MAX];
int n; int n;
@ -77,7 +83,8 @@ void* func(void* arg)
if (sockfd == -1) { if (sockfd == -1) {
printf("socket creation failed...\n"); printf("socket creation failed...\n");
return NULL; return NULL;
} else }
else
printf("Socket successfully created..\n"); printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr)); bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT // assign IP, PORT
@ -86,11 +93,12 @@ void* func(void* arg)
servaddr.sin_port = htons(port); servaddr.sin_port = htons(port);
// connect the client socket to server socket // connect the client socket to server socket
if (connect(sockfd, (SA*) &servaddr, sizeof(servaddr)) != 0) { if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n"); printf("connection with the server failed...\n");
sleep(10); sleep(10);
continue; continue;
} else { }
else {
printf("connected to the server..\n"); printf("connected to the server..\n");
} }
@ -101,7 +109,7 @@ void* func(void* arg)
// read the message from client and copy it in buffer // read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff)); n = read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents // print buffer which contains the client contents
//fprintf(stderr, "recieved %d bytes from host: %s", n, buff); // fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
// socket disconnected // socket disconnected
if (n <= 0) if (n <= 0)
@ -115,12 +123,14 @@ void* func(void* arg)
close(sockfd); close(sockfd);
} }
static bool host_init() static bool
host_init()
{ {
return true; return true;
} }
int host_send(void * ctx, const char *buf, int size) int
host_send(void *ctx, const char *buf, int size)
{ {
int ret; int ret;
@ -139,7 +149,8 @@ int host_send(void * ctx, const char *buf, int size)
return -1; return -1;
} }
void host_destroy() void
host_destroy()
{ {
if (server_mode) if (server_mode)
close(listenfd); close(listenfd);
@ -149,13 +160,16 @@ void host_destroy()
pthread_mutex_unlock(&sock_lock); pthread_mutex_unlock(&sock_lock);
} }
/* clang-format off */
host_interface interface = { host_interface interface = {
.init = host_init, .init = host_init,
.send = host_send, .send = host_send,
.destroy = host_destroy .destroy = host_destroy
}; };
/* clang-format on */
void* func_server_mode(void* arg) void *
func_server_mode(void *arg)
{ {
int clilent; int clilent;
struct sockaddr_in serv_addr, cli_addr; struct sockaddr_in serv_addr, cli_addr;
@ -175,14 +189,14 @@ void* func_server_mode(void* arg)
} }
/* Initialize socket structure */ /* Initialize socket structure */
bzero((char *) &serv_addr, sizeof(serv_addr)); bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port); serv_addr.sin_port = htons(port);
/* Now bind the host address using bind() call.*/ /* Now bind the host address using bind() call.*/
if (bind(listenfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("ERROR on binding"); perror("ERROR on binding");
exit(1); exit(1);
} }
@ -193,7 +207,7 @@ void* func_server_mode(void* arg)
while (1) { while (1) {
pthread_mutex_lock(&sock_lock); pthread_mutex_lock(&sock_lock);
sockfd = accept(listenfd, (struct sockaddr *) &cli_addr, &clilent); sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent);
pthread_mutex_unlock(&sock_lock); pthread_mutex_unlock(&sock_lock);
@ -227,7 +241,8 @@ void* func_server_mode(void* arg)
} }
#else #else
static int parse_baudrate(int baud) static int
parse_baudrate(int baud)
{ {
switch (baud) { switch (baud) {
case 9600: case 9600:
@ -270,7 +285,8 @@ static int parse_baudrate(int baud)
return -1; return -1;
} }
} }
static bool uart_init(const char *device, int baudrate, int *fd) static bool
uart_init(const char *device, int baudrate, int *fd)
{ {
int uart_fd; int uart_fd;
struct termios uart_term; struct termios uart_term;
@ -301,7 +317,8 @@ static bool uart_init(const char *device, int baudrate, int *fd)
return true; return true;
} }
static void *func_uart_mode(void *arg) static void *
func_uart_mode(void *arg)
{ {
int n; int n;
char buff[MAX]; char buff[MAX];
@ -328,7 +345,8 @@ static void *func_uart_mode(void *arg)
return NULL; return NULL;
} }
static int uart_send(void * ctx, const char *buf, int size) static int
uart_send(void *ctx, const char *buf, int size)
{ {
int ret; int ret;
@ -337,17 +355,24 @@ static int uart_send(void * ctx, const char *buf, int size)
return ret; return ret;
} }
static void uart_destroy() static void
uart_destroy()
{ {
close(uartfd); close(uartfd);
} }
static host_interface interface = { .send = uart_send, .destroy = uart_destroy }; /* clang-format off */
static host_interface interface = {
.send = uart_send,
.destroy = uart_destroy
};
/* clang-format on */
#endif #endif
static char global_heap_buf[270 * 1024] = { 0 }; static char global_heap_buf[270 * 1024] = { 0 };
/* clang-format off */
static void showUsage() static void showUsage()
{ {
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
@ -369,24 +394,26 @@ static void showUsage()
printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n"); printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n");
#endif #endif
} }
/* clang-format on */
static bool parse_args(int argc, char *argv[]) static bool
parse_args(int argc, char *argv[])
{ {
int c; int c;
while (1) { while (1) {
int optIndex = 0; int optIndex = 0;
static struct option longOpts[] = { static struct option longOpts[] = {
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' }, { "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' }, { "host_address", required_argument, NULL, 'a' },
{ "port", required_argument, NULL, 'p' }, { "port", required_argument, NULL, 'p' },
#else #else
{ "uart", required_argument, NULL, 'u' }, { "uart", required_argument, NULL, 'u' },
{ "baudrate", required_argument, NULL, 'b' }, { "baudrate", required_argument, NULL, 'b' },
#endif #endif
{ "help", required_argument, NULL, 'h' }, { "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
c = getopt_long(argc, argv, "sa:p:u:b:h", longOpts, &optIndex); c = getopt_long(argc, argv, "sa:p:u:b:h", longOpts, &optIndex);
@ -429,17 +456,20 @@ static bool parse_args(int argc, char *argv[])
} }
/** /**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics
* library
*/ */
static void hal_init(void) static void
hal_init(void)
{ {
/* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ /* Use the 'monitor' driver which creates window on PC's monitor to simulate
* a display*/
monitor_init(); monitor_init();
/*Create a display buffer*/ /*Create a display buffer*/
static lv_disp_buf_t disp_buf1; static lv_disp_buf_t disp_buf1;
static lv_color_t buf1_1[480*10]; static lv_color_t buf1_1[480 * 10];
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 480*10); lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 480 * 10);
/*Create a display*/ /*Create a display*/
lv_disp_drv_t disp_drv; lv_disp_drv_t disp_drv;
@ -454,17 +484,20 @@ static void hal_init(void)
lv_disp_drv_register(&disp_drv); lv_disp_drv_register(&disp_drv);
/* Add the mouse as input device /* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse*/ * Use the 'mouse' driver which reads the PC's mouse*/
mouse_init(); mouse_init();
lv_indev_drv_t indev_drv; lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/ lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER; 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*/ 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); lv_indev_drv_register(&indev_drv);
} }
// Driver function // Driver function
int iwasm_main(int argc, char *argv[]) int
iwasm_main(int argc, char *argv[])
{ {
RuntimeInitArgs init_args; RuntimeInitArgs init_args;
korp_tid tid; korp_tid tid;
@ -500,11 +533,12 @@ int iwasm_main(int argc, char *argv[])
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
if (server_mode) if (server_mode)
os_thread_create(&tid, func_server_mode, NULL, os_thread_create(&tid, func_server_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE); BH_APPLET_PRESERVED_STACK_SIZE);
else else
os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE); os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
#else #else
os_thread_create(&tid, func_uart_mode, NULL, BH_APPLET_PRESERVED_STACK_SIZE); os_thread_create(&tid, func_uart_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
#endif #endif
app_manager_startup(&interface); app_manager_startup(&interface);

View File

@ -5,18 +5,21 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
extern int
iwasm_main(int argc, char *argv[]);
extern int iwasm_main(int argc, char *argv[]); int
int main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
return iwasm_main(argc,argv); return iwasm_main(argc, argv);
} }
int time_get_ms() int
time_get_ms()
{ {
static struct timeval tv; static struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
return (int) time_in_mill; return (int)time_in_mill;
} }

View File

@ -1,6 +1,6 @@
/** /**
* @file XPT2046.c * @file XPT2046.c
*/ */
/********************* /*********************
* INCLUDES * INCLUDES
*********************/ *********************/
@ -30,7 +30,8 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void xpt2046_corr(int16_t * x, int16_t * y); static void
xpt2046_corr(int16_t *x, int16_t *y);
#if 0 #if 0
static void xpt2046_avg(int16_t * x, int16_t * y); static void xpt2046_avg(int16_t * x, int16_t * y);
#endif #endif
@ -63,17 +64,19 @@ lv_indev_data_t touch_point;
lv_indev_data_t last_touch_point; lv_indev_data_t last_touch_point;
#define TOUCH_READ_THREAD_STACK_SIZE 4096 #define TOUCH_READ_THREAD_STACK_SIZE 4096
static K_THREAD_STACK_DEFINE(touch_read_thread_stack, TOUCH_READ_THREAD_STACK_SIZE); static K_THREAD_STACK_DEFINE(touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE);
static struct k_thread touch_thread_data; static struct k_thread touch_thread_data;
static struct k_sem sem_touch_read; static struct k_sem sem_touch_read;
K_MUTEX_DEFINE( spi_display_touch_mutex); K_MUTEX_DEFINE(spi_display_touch_mutex);
int cnt = 0; int cnt = 0;
int touch_read_times = 0; int touch_read_times = 0;
int last_pen_interrupt_time = 0; int last_pen_interrupt_time = 0;
void xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb, void
u32_t pins) xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
u32_t pins)
{ {
cnt++; cnt++;
if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) { if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) {
@ -81,10 +84,10 @@ void xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
touch_read_times++; touch_read_times++;
last_pen_interrupt_time = k_uptime_get_32(); last_pen_interrupt_time = k_uptime_get_32();
} }
} }
void disable_pen_interrupt() void
disable_pen_interrupt()
{ {
int ret = 0; int ret = 0;
ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
@ -92,7 +95,8 @@ void disable_pen_interrupt()
printf("gpio_pin_configure GPIO_INPUT failed\n"); printf("gpio_pin_configure GPIO_INPUT failed\n");
} }
} }
void enable_pen_interrupt() void
enable_pen_interrupt()
{ {
int ret = 0; int ret = 0;
ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
@ -101,7 +105,8 @@ void enable_pen_interrupt()
} }
} }
void touch_screen_read_thread() void
touch_screen_read_thread()
{ {
int i; int i;
bool ret = false; bool ret = false;
@ -118,12 +123,11 @@ void touch_screen_read_thread()
ret = xpt2046_read(&touch_point); ret = xpt2046_read(&touch_point);
if (ret) { if (ret) {
if ((abs(last_touch_point.point.x - touch_point.point.x) < 4) if ((abs(last_touch_point.point.x - touch_point.point.x) < 4)
&& (abs(last_touch_point.point.y - touch_point.point.y) && (abs(last_touch_point.point.y - touch_point.point.y)
< 4)) { < 4)) {
break; break;
} }
last_touch_point = touch_point; last_touch_point = touch_point;
} }
} }
enable_pen_interrupt(); enable_pen_interrupt();
@ -131,7 +135,8 @@ void touch_screen_read_thread()
} }
} }
void xpt2046_init(void) void
xpt2046_init(void)
{ {
int ret; int ret;
input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME); input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME);
@ -140,7 +145,7 @@ void xpt2046_init(void)
printf("device not found. Aborting test."); printf("device not found. Aborting test.");
return; return;
} }
memset((void *) &touch_point, 0, sizeof(lv_indev_data_t)); memset((void *)&touch_point, 0, sizeof(lv_indev_data_t));
spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY; spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY;
spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8); spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
@ -171,8 +176,7 @@ void xpt2046_init(void)
/* Setup GPIO input */ /* Setup GPIO input */
ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN, ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN,
(GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE (GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE
| GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE) | GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE));
);
if (ret) { if (ret) {
printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN); printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN);
} }
@ -194,8 +198,7 @@ void xpt2046_init(void)
k_thread_create(&touch_thread_data, touch_read_thread_stack, k_thread_create(&touch_thread_data, touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread, TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread,
NULL, NULL, NULL, 5, NULL, NULL, NULL, 5, 0, K_NO_WAIT);
0, K_NO_WAIT);
printf("xpt2046_init ok \n"); printf("xpt2046_init ok \n");
} }
@ -204,7 +207,8 @@ void xpt2046_init(void)
* @param data store the read data here * @param data store the read data here
* @return false: because no ore data to be read * @return false: because no ore data to be read
*/ */
bool xpt2046_read(lv_indev_data_t * data) bool
xpt2046_read(lv_indev_data_t *data)
{ {
static int16_t last_x = 0; static int16_t last_x = 0;
static int16_t last_y = 0; static int16_t last_y = 0;
@ -258,7 +262,8 @@ bool xpt2046_read(lv_indev_data_t * data)
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static void xpt2046_corr(int16_t * x, int16_t * y) static void
xpt2046_corr(int16_t *x, int16_t *y)
{ {
#if XPT2046_XY_SWAP != 0 #if XPT2046_XY_SWAP != 0
int16_t swap_tmp; int16_t swap_tmp;
@ -278,10 +283,10 @@ static void xpt2046_corr(int16_t * x, int16_t * y)
(*y) = 0; (*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES) (*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES)
/ (XPT2046_X_MAX - XPT2046_X_MIN); / (XPT2046_X_MAX - XPT2046_X_MIN);
(*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES) (*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES)
/ (XPT2046_Y_MAX - XPT2046_Y_MIN); / (XPT2046_Y_MAX - XPT2046_Y_MIN);
#if XPT2046_X_INV != 0 #if XPT2046_X_INV != 0
(*x) = XPT2046_HOR_RES - (*x); (*x) = XPT2046_HOR_RES - (*x);
@ -290,7 +295,6 @@ static void xpt2046_corr(int16_t * x, int16_t * y)
#if XPT2046_Y_INV != 0 #if XPT2046_Y_INV != 0
(*y) = XPT2046_VER_RES - (*y); (*y) = XPT2046_VER_RES - (*y);
#endif #endif
} }
#if 0 #if 0
@ -323,7 +327,8 @@ static void xpt2046_avg(int16_t * x, int16_t * y)
} }
#endif #endif
bool touchscreen_read(lv_indev_data_t * data) bool
touchscreen_read(lv_indev_data_t *data)
{ {
/*Store the collected data*/ /*Store the collected data*/
data->point.x = last_touch_point.point.x; data->point.x = last_touch_point.point.x;

View File

@ -8,17 +8,17 @@
#define USE_XPT2046 1 #define USE_XPT2046 1
# define XPT2046_HOR_RES 320 #define XPT2046_HOR_RES 320
# define XPT2046_VER_RES 240 #define XPT2046_VER_RES 240
# define XPT2046_X_MIN 200 #define XPT2046_X_MIN 200
# define XPT2046_Y_MIN 200 #define XPT2046_Y_MIN 200
# define XPT2046_X_MAX 3800 #define XPT2046_X_MAX 3800
# define XPT2046_Y_MAX 3800 #define XPT2046_Y_MAX 3800
# define XPT2046_AVG 4 #define XPT2046_AVG 4
# define XPT2046_INV 0 #define XPT2046_INV 0
#define CMD_X_READ 0b10010000 #define CMD_X_READ 0b10010000
#define CMD_Y_READ 0b11010000 #define CMD_Y_READ 0b11010000
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -28,7 +28,6 @@ extern "C" {
* INCLUDES * INCLUDES
*********************/ *********************/
#if USE_XPT2046 #if USE_XPT2046
#include <autoconf.h> #include <autoconf.h>
#include <stdint.h> #include <stdint.h>
@ -48,8 +47,10 @@ extern "C" {
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
void xpt2046_init(void); void
bool xpt2046_read(lv_indev_data_t * data); xpt2046_init(void);
bool
xpt2046_read(lv_indev_data_t *data);
/********************** /**********************
* MACROS * MACROS

View File

@ -28,9 +28,11 @@ extern "C" {
#endif #endif
enum display_pixel_format { enum display_pixel_format {
PIXEL_FORMAT_RGB_888 = BIT(0), PIXEL_FORMAT_MONO01 = BIT(1), /* 0=Black 1=White */ 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_MONO10 = BIT(2), /* 1=Black 0=White */
PIXEL_FORMAT_ARGB_8888 = BIT(3), PIXEL_FORMAT_RGB_565 = BIT(4), PIXEL_FORMAT_ARGB_8888 = BIT(3),
PIXEL_FORMAT_RGB_565 = BIT(4),
}; };
enum display_screen_info { enum display_screen_info {
@ -142,8 +144,9 @@ typedef int (*display_blanking_off_api)(const struct device *dev);
* See display_write() for argument description * See display_write() for argument description
*/ */
typedef int (*display_write_api)(const struct device *dev, const u16_t x, typedef int (*display_write_api)(const struct device *dev, const u16_t x,
const u16_t y, const struct display_buffer_descriptor *desc, const u16_t y,
const void *buf); const struct display_buffer_descriptor *desc,
const void *buf);
/** /**
* @typedef display_read_api * @typedef display_read_api
@ -151,7 +154,9 @@ typedef int (*display_write_api)(const struct device *dev, const u16_t x,
* See display_read() for argument description * See display_read() for argument description
*/ */
typedef int (*display_read_api)(const struct device *dev, const u16_t x, 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); const u16_t y,
const struct display_buffer_descriptor *desc,
void *buf);
/** /**
* @typedef display_get_framebuffer_api * @typedef display_get_framebuffer_api
@ -166,7 +171,7 @@ typedef void *(*display_get_framebuffer_api)(const struct device *dev);
* See display_set_brightness() for argument description * See display_set_brightness() for argument description
*/ */
typedef int (*display_set_brightness_api)(const struct device *dev, typedef int (*display_set_brightness_api)(const struct device *dev,
const u8_t brightness); const u8_t brightness);
/** /**
* @typedef display_set_contrast_api * @typedef display_set_contrast_api
@ -174,31 +179,31 @@ typedef int (*display_set_brightness_api)(const struct device *dev,
* See display_set_contrast() for argument description * See display_set_contrast() for argument description
*/ */
typedef int (*display_set_contrast_api)(const struct device *dev, typedef int (*display_set_contrast_api)(const struct device *dev,
const u8_t contrast); const u8_t contrast);
/** /**
* @typedef display_get_capabilities_api * @typedef display_get_capabilities_api
* @brief Callback API to get display capabilities * @brief Callback API to get display capabilities
* See display_get_capabilities() for argument description * See display_get_capabilities() for argument description
*/ */
typedef void (*display_get_capabilities_api)(const struct device *dev, typedef void (*display_get_capabilities_api)(
struct display_capabilities * capabilities); const struct device *dev, struct display_capabilities *capabilities);
/** /**
* @typedef display_set_pixel_format_api * @typedef display_set_pixel_format_api
* @brief Callback API to set pixel format used by the display * @brief Callback API to set pixel format used by the display
* See display_set_pixel_format() for argument description * See display_set_pixel_format() for argument description
*/ */
typedef int (*display_set_pixel_format_api)(const struct device *dev, typedef int (*display_set_pixel_format_api)(
const enum display_pixel_format pixel_format); const struct device *dev, const enum display_pixel_format pixel_format);
/** /**
* @typedef display_set_orientation_api * @typedef display_set_orientation_api
* @brief Callback API to set orientation used by the display * @brief Callback API to set orientation used by the display
* See display_set_orientation() for argument description * See display_set_orientation() for argument description
*/ */
typedef int (*display_set_orientation_api)(const struct device *dev, typedef int (*display_set_orientation_api)(
const enum display_orientation orientation); const struct device *dev, const enum display_orientation orientation);
/** /**
* @brief Display driver API * @brief Display driver API
@ -229,9 +234,9 @@ extern struct display_driver_api ili9340_api1;
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_write(const struct device *dev, const u16_t x, static inline int
const u16_t y, const struct display_buffer_descriptor *desc, display_write(const struct device *dev, const u16_t x, const u16_t y,
const void *buf) const struct display_buffer_descriptor *desc, const void *buf)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -250,8 +255,9 @@ static inline int display_write(const struct device *dev, const u16_t x,
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_read(const struct device *dev, const u16_t x, static inline int
const u16_t y, const struct display_buffer_descriptor *desc, void *buf) 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 *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -268,7 +274,8 @@ static inline int display_read(const struct device *dev, const u16_t x,
* is not supported * is not supported
* *
*/ */
static inline void *display_get_framebuffer(const struct device *dev) static inline void *
display_get_framebuffer(const struct device *dev)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -283,7 +290,8 @@ static inline void *display_get_framebuffer(const struct device *dev)
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_blanking_on(const struct device *dev) static inline int
display_blanking_on(const struct device *dev)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -298,7 +306,8 @@ static inline int display_blanking_on(const struct device *dev)
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_blanking_off(const struct device *dev) static inline int
display_blanking_off(const struct device *dev)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -317,8 +326,8 @@ static inline int display_blanking_off(const struct device *dev)
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_set_brightness(const struct device *dev, static inline int
u8_t brightness) display_set_brightness(const struct device *dev, u8_t brightness)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -337,7 +346,8 @@ static inline int display_set_brightness(const struct device *dev,
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_set_contrast(const struct device *dev, u8_t contrast) static inline int
display_set_contrast(const struct device *dev, u8_t contrast)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -351,8 +361,9 @@ static inline int display_set_contrast(const struct device *dev, u8_t contrast)
* @param dev Pointer to device structure * @param dev Pointer to device structure
* @param capabilities Pointer to capabilities structure to populate * @param capabilities Pointer to capabilities structure to populate
*/ */
static inline void display_get_capabilities(const struct device *dev, static inline void
struct display_capabilities * capabilities) display_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -368,8 +379,9 @@ static inline void display_get_capabilities(const struct device *dev,
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_set_pixel_format(const struct device *dev, static inline int
const enum display_pixel_format pixel_format) 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 *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;
@ -385,8 +397,9 @@ static inline int display_set_pixel_format(const struct device *dev,
* *
* @retval 0 on success else negative errno code. * @retval 0 on success else negative errno code.
*/ */
static inline int display_set_orientation(const struct device *dev, static inline int
const enum display_orientation orientation) display_set_orientation(const struct device *dev,
const enum display_orientation orientation)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;

View File

@ -9,7 +9,7 @@
//#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL //#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL
//#include <logging/log.h> //#include <logging/log.h>
//LOG_MODULE_REGISTER(display_ili9340); // LOG_MODULE_REGISTER(display_ili9340);
#define LOG_ERR printf #define LOG_ERR printf
#define LOG_DBG printf #define LOG_DBG printf
#define LOG_WRN printf #define LOG_WRN printf
@ -26,7 +26,7 @@ struct ili9340_data {
struct device *spi_dev; struct device *spi_dev;
struct spi_config spi_config; struct spi_config spi_config;
#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER #ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER
struct spi_cs_control cs_ctrl; struct spi_cs_control cs_ctrl;
#endif #endif
}; };
@ -35,13 +35,15 @@ struct ili9340_data ili9340_data1;
#define ILI9340_CMD_DATA_PIN_COMMAND 0 #define ILI9340_CMD_DATA_PIN_COMMAND 0
#define ILI9340_CMD_DATA_PIN_DATA 1 #define ILI9340_CMD_DATA_PIN_DATA 1
static void ili9340_exit_sleep(struct ili9340_data *data) static void
ili9340_exit_sleep(struct ili9340_data *data)
{ {
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0); ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
//k_sleep(Z_TIMEOUT_MS(120)); // k_sleep(Z_TIMEOUT_MS(120));
} }
int ili9340_init() int
ili9340_init()
{ {
struct ili9340_data *data = &ili9340_data1; struct ili9340_data *data = &ili9340_data1;
printf("Initializing display driver\n"); printf("Initializing display driver\n");
@ -50,20 +52,22 @@ int ili9340_init()
return -EPERM; return -EPERM;
} }
data->spi_config.frequency = DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY; 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.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; data->spi_config.slave = DT_ILITEK_ILI9340_0_BASE_ADDRESS;
#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER #ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER
data->cs_ctrl.gpio_dev = data->cs_ctrl.gpio_dev =
device_get_binding(DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER); 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.gpio_pin = DT_ILITEK_ILI9340_0_CS_GPIO_PIN;
data->cs_ctrl.delay = 0; data->cs_ctrl.delay = 0;
data->spi_config.cs = &(data->cs_ctrl); data->spi_config.cs = &(data->cs_ctrl);
#else #else
data->spi_config.cs = NULL; data->spi_config.cs = NULL;
#endif #endif
data->reset_gpio = device_get_binding( data->reset_gpio =
DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER); device_get_binding(DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER);
if (data->reset_gpio == NULL) { if (data->reset_gpio == NULL) {
return -EPERM; return -EPERM;
} }
@ -71,9 +75,9 @@ int ili9340_init()
gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN,
GPIO_OUTPUT); GPIO_OUTPUT);
data->command_data_gpio = device_get_binding( data->command_data_gpio =
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER); device_get_binding(DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER);
if (data->command_data_gpio == NULL) { if (data->command_data_gpio == NULL) {
return -EPERM; return -EPERM;
} }
@ -97,8 +101,9 @@ int ili9340_init()
return 0; return 0;
} }
static void ili9340_set_mem_area(struct ili9340_data *data, const u16_t x, static void
const u16_t y, const u16_t w, const u16_t h) 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]; u16_t spi_data[2];
@ -111,11 +116,12 @@ static void ili9340_set_mem_area(struct ili9340_data *data, const u16_t x,
ili9340_transmit(data, ILI9340_CMD_PAGE_ADDR, &spi_data[0], 4); 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, static int
const struct display_buffer_descriptor *desc, const void *buf) 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; struct ili9340_data *data = (struct ili9340_data *)&ili9340_data1;
const u8_t *write_data_start = (u8_t *) buf; const u8_t *write_data_start = (u8_t *)buf;
struct spi_buf tx_buf; struct spi_buf tx_buf;
struct spi_buf_set tx_bufs; struct spi_buf_set tx_bufs;
u16_t write_cnt; u16_t write_cnt;
@ -130,11 +136,12 @@ static int ili9340_write(const struct device *dev, const u16_t x, const u16_t y,
if (desc->pitch > desc->width) { if (desc->pitch > desc->width) {
write_h = 1U; write_h = 1U;
nbr_of_writes = desc->height; nbr_of_writes = desc->height;
} else { }
else {
write_h = desc->height; write_h = desc->height;
nbr_of_writes = 1U; nbr_of_writes = 1U;
} }
ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *) write_data_start, ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *)write_data_start,
3 * desc->width * write_h); 3 * desc->width * write_h);
tx_bufs.buffers = &tx_buf; tx_bufs.buffers = &tx_buf;
@ -142,7 +149,7 @@ static int ili9340_write(const struct device *dev, const u16_t x, const u16_t y,
write_data_start += (3 * desc->pitch); write_data_start += (3 * desc->pitch);
for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) { for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) {
tx_buf.buf = (void *) write_data_start; tx_buf.buf = (void *)write_data_start;
tx_buf.len = 3 * desc->width * write_h; tx_buf.len = 3 * desc->width * write_h;
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
write_data_start += (3 * desc->pitch); write_data_start += (3 * desc->pitch);
@ -151,62 +158,69 @@ static int ili9340_write(const struct device *dev, const u16_t x, const u16_t y,
return 0; return 0;
} }
static int ili9340_read(const struct device *dev, const u16_t x, const u16_t y, static int
const struct display_buffer_descriptor *desc, void *buf) 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"); LOG_ERR("Reading not supported\n");
return -ENOTSUP; return -ENOTSUP;
} }
static void *ili9340_get_framebuffer(const struct device *dev) static void *
ili9340_get_framebuffer(const struct device *dev)
{ {
LOG_ERR("Direct framebuffer access not supported\n"); LOG_ERR("Direct framebuffer access not supported\n");
return NULL; return NULL;
} }
static int ili9340_display_blanking_off(const struct device *dev) static int
ili9340_display_blanking_off(const struct device *dev)
{ {
struct ili9340_data *data = (struct ili9340_data *) dev->driver_data; struct ili9340_data *data = (struct ili9340_data *)dev->driver_data;
LOG_DBG("Turning display blanking off\n"); LOG_DBG("Turning display blanking off\n");
ili9340_transmit(data, ILI9340_CMD_DISPLAY_ON, NULL, 0); ili9340_transmit(data, ILI9340_CMD_DISPLAY_ON, NULL, 0);
return 0; return 0;
} }
static int ili9340_display_blanking_on(const struct device *dev) static int
ili9340_display_blanking_on(const struct device *dev)
{ {
struct ili9340_data *data = (struct ili9340_data *) dev->driver_data; struct ili9340_data *data = (struct ili9340_data *)dev->driver_data;
LOG_DBG("Turning display blanking on\n"); LOG_DBG("Turning display blanking on\n");
ili9340_transmit(data, ILI9340_CMD_DISPLAY_OFF, NULL, 0); ili9340_transmit(data, ILI9340_CMD_DISPLAY_OFF, NULL, 0);
return 0; return 0;
} }
static int ili9340_set_brightness(const struct device *dev, static int
const u8_t brightness) ili9340_set_brightness(const struct device *dev, const u8_t brightness)
{ {
LOG_WRN("Set brightness not implemented\n"); LOG_WRN("Set brightness not implemented\n");
return -ENOTSUP; return -ENOTSUP;
} }
static int ili9340_set_contrast(const struct device *dev, const u8_t contrast) static int
ili9340_set_contrast(const struct device *dev, const u8_t contrast)
{ {
LOG_ERR("Set contrast not supported\n"); LOG_ERR("Set contrast not supported\n");
return -ENOTSUP; return -ENOTSUP;
} }
static int ili9340_set_pixel_format(const struct device *dev, static int
const enum display_pixel_format pixel_format) ili9340_set_pixel_format(const struct device *dev,
const enum display_pixel_format pixel_format)
{ {
if (pixel_format == PIXEL_FORMAT_RGB_888) { if (pixel_format == PIXEL_FORMAT_RGB_888) {
return 0; return 0;
} }
LOG_ERR("Pixel format change not implemented\n"); LOG_ERR("Pixel format change not implemented\n");
return -ENOTSUP; return -ENOTSUP;
} }
static int ili9340_set_orientation(const struct device *dev, static int
const enum display_orientation orientation) ili9340_set_orientation(const struct device *dev,
const enum display_orientation orientation)
{ {
if (orientation == DISPLAY_ORIENTATION_NORMAL) { if (orientation == DISPLAY_ORIENTATION_NORMAL) {
return 0; return 0;
@ -215,8 +229,9 @@ static int ili9340_set_orientation(const struct device *dev,
return -ENOTSUP; return -ENOTSUP;
} }
static void ili9340_get_capabilities(const struct device *dev, static void
struct display_capabilities *capabilities) ili9340_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities)
{ {
memset(capabilities, 0, sizeof(struct display_capabilities)); memset(capabilities, 0, sizeof(struct display_capabilities));
capabilities->x_resolution = 320; capabilities->x_resolution = 320;
@ -226,22 +241,24 @@ static void ili9340_get_capabilities(const struct device *dev,
capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL; capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL;
} }
void ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data, void
size_t tx_len) ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data,
size_t tx_len)
{ {
data = (struct ili9340_data *) &ili9340_data1; data = (struct ili9340_data *)&ili9340_data1;
struct spi_buf tx_buf = { .buf = &cmd, .len = 1 }; struct spi_buf tx_buf = { .buf = &cmd, .len = 1 };
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 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, gpio_pin_set(data->command_data_gpio,
ILI9340_CMD_DATA_PIN_COMMAND); DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_COMMAND);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
if (tx_data != NULL) { if (tx_data != NULL) {
tx_buf.buf = tx_data; tx_buf.buf = tx_data;
tx_buf.len = tx_len; tx_buf.len = tx_len;
gpio_pin_set(data->command_data_gpio, gpio_pin_set(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_DATA); ILI9340_CMD_DATA_PIN_DATA);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
} }
} }

View File

@ -52,15 +52,17 @@ struct ili9340_data;
* @param tx_len Number of bytes in tx_data buffer * @param tx_len Number of bytes in tx_data buffer
* *
*/ */
void ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data, void
size_t tx_len); ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data,
size_t tx_len);
/** /**
* Perform LCD specific initialization * Perform LCD specific initialization
* *
* @param data Device data structure * @param data Device data structure
*/ */
void ili9340_lcd_init(struct ili9340_data *data); void
ili9340_lcd_init(struct ili9340_data *data);
#define DT_ILITEK_ILI9340_0_LABEL "DISPLAY" #define DT_ILITEK_ILI9340_0_LABEL "DISPLAY"
#define CONFIG_DISPLAY_LOG_LEVEL 0 #define CONFIG_DISPLAY_LOG_LEVEL 0

View File

@ -6,7 +6,8 @@
#include "display_ili9340.h" #include "display_ili9340.h"
void ili9340_lcd_init(struct ili9340_data *data) void
ili9340_lcd_init(struct ili9340_data *data)
{ {
u8_t tx_data[15]; u8_t tx_data[15];
@ -24,11 +25,11 @@ void ili9340_lcd_init(struct ili9340_data *data)
ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1); ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1);
tx_data[0] = tx_data[0] =
ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR; ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR;
ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1); ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1);
tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT | tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT
ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT; | ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT;
ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1); ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1);
tx_data[0] = 0x00; tx_data[0] = 0x00;

View File

@ -16,13 +16,20 @@
#include "display.h" #include "display.h"
#include "lvgl.h" #include "lvgl.h"
extern void init_sensor_framework(); extern void
extern void exit_sensor_framework(); init_sensor_framework();
extern int aee_host_msg_callback(void *msg, uint32_t msg_len); extern void
extern bool touchscreen_read(lv_indev_data_t * data); exit_sensor_framework();
extern int ili9340_init(); extern int
extern void xpt2046_init(void); aee_host_msg_callback(void *msg, uint32_t msg_len);
extern void wgl_init(); extern bool
touchscreen_read(lv_indev_data_t *data);
extern int
ili9340_init();
extern void
xpt2046_init(void);
extern void
wgl_init();
#include <zephyr.h> #include <zephyr.h>
#include <drivers/uart.h> #include <drivers/uart.h>
@ -30,7 +37,8 @@ extern void wgl_init();
int uart_char_cnt = 0; int uart_char_cnt = 0;
static void uart_irq_callback(struct device *dev) static void
uart_irq_callback(struct device *dev)
{ {
unsigned char ch; unsigned char ch;
@ -42,7 +50,8 @@ static void uart_irq_callback(struct device *dev)
struct device *uart_dev = NULL; struct device *uart_dev = NULL;
static bool host_init() static bool
host_init()
{ {
uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME); uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME);
if (!uart_dev) { if (!uart_dev) {
@ -54,7 +63,8 @@ static bool host_init()
return true; return true;
} }
int host_send(void * ctx, const char *buf, int size) int
host_send(void *ctx, const char *buf, int size)
{ {
if (!uart_dev) if (!uart_dev)
return 0; return 0;
@ -65,15 +75,17 @@ int host_send(void * ctx, const char *buf, int size)
return size; return size;
} }
void host_destroy() void
{ host_destroy()
} {}
/* clang-format off */
host_interface interface = { host_interface interface = {
.init = host_init, .init = host_init,
.send = host_send, .send = host_send,
.destroy = host_destroy .destroy = host_destroy
}; };
/* clang-format on */
timer_ctx_t timer_ctx; timer_ctx_t timer_ctx;
@ -81,9 +93,8 @@ static char global_heap_buf[270 * 1024] = { 0 };
static uint8_t color_copy[320 * 10 * 3]; static uint8_t color_copy[320 * 10 * 3];
static void display_flush(lv_disp_drv_t *disp_drv, static void
const lv_area_t *area, display_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color)
lv_color_t *color)
{ {
u16_t w = area->x2 - area->x1 + 1; u16_t w = area->x2 - area->x1 + 1;
u16_t h = area->y2 - area->y1 + 1; u16_t h = area->y2 - area->y1 + 1;
@ -102,20 +113,23 @@ static void display_flush(lv_disp_drv_t *disp_drv,
color_p[i * 3 + 2] = color->ch.blue; color_p[i * 3 + 2] = color->ch.blue;
} }
display_write(NULL, area->x1, area->y1, &desc, (void *) color_p); display_write(NULL, area->x1, area->y1, &desc, (void *)color_p);
lv_disp_flush_ready(disp_drv); /* in v5.3 is lv_flush_ready */ 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) static bool
display_input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{ {
return touchscreen_read(data); return touchscreen_read(data);
} }
/** /**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics
* library
*/ */
static void hal_init(void) static void
hal_init(void)
{ {
xpt2046_init(); xpt2046_init();
ili9340_init(); ili9340_init();
@ -123,12 +137,12 @@ static void hal_init(void)
/*Create a display buffer*/ /*Create a display buffer*/
static lv_disp_buf_t disp_buf1; static lv_disp_buf_t disp_buf1;
static lv_color_t buf1_1[320*10]; static lv_color_t buf1_1[320 * 10];
lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 320*10); lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 320 * 10);
/*Create a display*/ /*Create a display*/
lv_disp_drv_t disp_drv; lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); /*Basic initialization*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.buffer = &disp_buf1; disp_drv.buffer = &disp_buf1;
disp_drv.flush_cb = display_flush; disp_drv.flush_cb = display_flush;
// disp_drv.hor_res = 200; // disp_drv.hor_res = 200;
@ -136,13 +150,14 @@ static void hal_init(void)
lv_disp_drv_register(&disp_drv); lv_disp_drv_register(&disp_drv);
lv_indev_drv_t indev_drv; lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/ lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = display_input_read; indev_drv.read_cb = display_input_read;
lv_indev_drv_register(&indev_drv); lv_indev_drv_register(&indev_drv);
} }
int iwasm_main() int
iwasm_main()
{ {
RuntimeInitArgs init_args; RuntimeInitArgs init_args;
host_init(); host_init();

View File

@ -10,17 +10,20 @@
#include "bh_log.h" #include "bh_log.h"
#include "wasm_export.h" #include "wasm_export.h"
extern int iwasm_main(); extern int
iwasm_main();
void main(void) void
main(void)
{ {
iwasm_main(); iwasm_main();
for(;;){ for (;;) {
k_sleep(Z_TIMEOUT_MS(1000)); k_sleep(Z_TIMEOUT_MS(1000));
} }
} }
int time_get_ms() int
time_get_ms()
{ {
return k_uptime_get_32(); return k_uptime_get_32();
} }

View File

@ -6,21 +6,21 @@
#define __PIN_CONFIG_JLF_H__ #define __PIN_CONFIG_JLF_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2" #define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10*1000 #define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 #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_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 5 #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_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4 #define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4
#define XPT2046_SPI_DEVICE_NAME "SPI_2" #define XPT2046_SPI_DEVICE_NAME "SPI_2"
#define XPT2046_SPI_MAX_FREQUENCY 10*1000 #define XPT2046_SPI_MAX_FREQUENCY 10 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIO_0" #define XPT2046_CS_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_CS_GPIO_PIN 6 #define XPT2046_CS_GPIO_PIN 6
#define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0" #define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_PEN_GPIO_PIN 7 #define XPT2046_PEN_GPIO_PIN 7
#define HOST_DEVICE_COMM_UART_NAME "UART_1" #define HOST_DEVICE_COMM_UART_NAME "UART_1"
#endif /* __PIN_CONFIG_JLF_H__ */ #endif /* __PIN_CONFIG_JLF_H__ */

View File

@ -6,24 +6,24 @@
#define __PIN_CONFIG_STM32_H__ #define __PIN_CONFIG_STM32_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_1" #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_SPI_MAX_FREQUENCY 24 * 1000 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 #define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC" #define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 12 #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_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 11 #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_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10 #define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10
#define XPT2046_SPI_DEVICE_NAME "SPI_1" #define XPT2046_SPI_DEVICE_NAME "SPI_1"
#define XPT2046_SPI_MAX_FREQUENCY 12*1000*1000 #define XPT2046_SPI_MAX_FREQUENCY 12 * 1000 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIOD" #define XPT2046_CS_GPIO_CONTROLLER "GPIOD"
#define XPT2046_CS_GPIO_PIN 0 #define XPT2046_CS_GPIO_PIN 0
#define XPT2046_PEN_GPIO_CONTROLLER "GPIOD" #define XPT2046_PEN_GPIO_CONTROLLER "GPIOD"
#define XPT2046_PEN_GPIO_PIN 1 #define XPT2046_PEN_GPIO_PIN 1
#define HOST_DEVICE_COMM_UART_NAME "UART_6" #define HOST_DEVICE_COMM_UART_NAME "UART_6"

View File

@ -10,13 +10,19 @@
#include "mouse.h" #include "mouse.h"
#include "lvgl/lv_misc/lv_color.h" #include "lvgl/lv_misc/lv_color.h"
#include "lvgl/lv_hal/lv_hal_indev.h" #include "lvgl/lv_hal/lv_hal_indev.h"
extern void display_init(void); extern void
extern void display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, display_init(void);
const lv_color_t * color_p); extern void
extern bool display_input_read(lv_indev_data_t * data); display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
extern void display_deinit(void); const lv_color_t *color_p);
extern void display_vdb_write(void *buf, lv_coord_t buf_w, lv_coord_t x, extern bool
lv_coord_t y, lv_color_t *color, lv_opa_t opa); display_input_read(lv_indev_data_t *data);
extern int time_get_ms(); 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 #endif

View File

@ -13,7 +13,7 @@
* DEFINES * DEFINES
*********************/ *********************/
#ifndef MONITOR_ZOOM #ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1 #define MONITOR_ZOOM 1
#endif #endif
/********************** /**********************
@ -42,17 +42,18 @@ static int16_t last_y = 0;
/** /**
* Initialize the mouse * Initialize the mouse
*/ */
void mouse_init(void) void
{ mouse_init(void)
{}
}
/** /**
* Get the current position and state of the mouse * Get the current position and state of the mouse
* @param data store the mouse data here * @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be read * @return false: because the points are not buffered, so no more data to be
* read
*/ */
bool mouse_read(lv_indev_data_t * data) bool
mouse_read(lv_indev_data_t *data)
{ {
/*Store the collected data*/ /*Store the collected data*/
data->point.x = last_x; data->point.x = last_x;
@ -65,27 +66,27 @@ bool mouse_read(lv_indev_data_t * data)
/** /**
* It will be called from the main SDL thread * It will be called from the main SDL thread
*/ */
void mouse_handler(SDL_Event * event) void
mouse_handler(SDL_Event *event)
{ {
switch (event->type) { switch (event->type) {
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (event->button.button == SDL_BUTTON_LEFT) if (event->button.button == SDL_BUTTON_LEFT)
left_button_down = false; left_button_down = false;
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if (event->button.button == SDL_BUTTON_LEFT) { if (event->button.button == SDL_BUTTON_LEFT) {
left_button_down = true; 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_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / 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; break;
} }
} }
/********************** /**********************

View File

@ -43,18 +43,22 @@ extern "C" {
/** /**
* Initialize the mouse * Initialize the mouse
*/ */
void mouse_init(void); void
mouse_init(void);
/** /**
* Get the current position and state of the mouse * Get the current position and state of the mouse
* @param data store the mouse data here * @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be read * @return false: because the points are not buffered, so no more data to be
* read
*/ */
bool mouse_read(lv_indev_data_t * data); bool
mouse_read(lv_indev_data_t *data);
/** /**
* It will be called from the main SDL thread * It will be called from the main SDL thread
*/ */
void mouse_handler(SDL_Event *event); void
mouse_handler(SDL_Event *event);
/********************** /**********************
* MACROS * MACROS

View File

@ -11,19 +11,23 @@
#define MONITOR_HOR_RES 320 #define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240 #define MONITOR_VER_RES 240
#ifndef MONITOR_ZOOM #ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1 #define MONITOR_ZOOM 1
#endif #endif
#define SDL_REFR_PERIOD 50 #define SDL_REFR_PERIOD 50
void monitor_sdl_init(void); void
void monitor_sdl_refr_core(void); monitor_sdl_init(void);
void monitor_sdl_clean_up(void); void
monitor_sdl_refr_core(void);
void
monitor_sdl_clean_up(void);
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES]; 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, void
lv_color_t *color, lv_opa_t opa) 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; unsigned char *buf_xy = buf + 4 * x + 4 * y * buf_w;
lv_color_t * temp = (lv_color_t *) buf_xy; lv_color_t *temp = (lv_color_t *)buf_xy;
*temp = *color; *temp = *color;
/* /*
if (opa != LV_OPA_COVER) { if (opa != LV_OPA_COVER) {
@ -36,28 +40,30 @@ void display_vdb_write(void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
} }
*/ */
} }
int time_get_ms() int
time_get_ms()
{ {
static struct timeval tv; static struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
return (int) time_in_mill; return (int)time_in_mill;
} }
SDL_Window * window; SDL_Window *window;
SDL_Renderer * renderer; SDL_Renderer *renderer;
SDL_Texture * texture; SDL_Texture *texture;
static volatile bool sdl_inited = false; static volatile bool sdl_inited = false;
static volatile bool sdl_refr_qry = false; static volatile bool sdl_refr_qry = false;
static volatile bool sdl_quit_qry = false; static volatile bool sdl_quit_qry = false;
void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
const lv_color_t * color_p) 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*/ /*Return if the area is out the screen*/
if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1 if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1
|| y1 > MONITOR_VER_RES - 1) { || y1 > MONITOR_VER_RES - 1) {
return; return;
} }
@ -65,14 +71,13 @@ void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
uint32_t w = x2 - x1 + 1; uint32_t w = x2 - x1 + 1;
for (y = y1; y <= y2; y++) { for (y = y1; y <= y2; y++) {
memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color_p, memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color_p,
w * sizeof(lv_color_t)); w * sizeof(lv_color_t));
color_p += w; color_p += w;
} }
sdl_refr_qry = true; sdl_refr_qry = true;
/*IMPORTANT! It must be called to tell the system the flush is ready*/ /*IMPORTANT! It must be called to tell the system the flush is ready*/
} }
/** /**
@ -83,8 +88,8 @@ void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
* @param y2 bottom coordinate * @param y2 bottom coordinate
* @param color fill color * @param color fill color
*/ */
void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
lv_color_t color) 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*/ /*Return if the area is out the screen*/
if (x2 < 0) if (x2 < 0)
@ -104,7 +109,7 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
int32_t x; int32_t x;
int32_t y; int32_t y;
uint32_t color32 = color.full; //lv_color_to32(color); uint32_t color32 = color.full; // lv_color_to32(color);
for (x = act_x1; x <= act_x2; x++) { for (x = act_x1; x <= act_x2; x++) {
for (y = act_y1; y <= act_y2; y++) { for (y = act_y1; y <= act_y2; y++) {
@ -123,8 +128,9 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
* @param y2 bottom coordinate * @param y2 bottom coordinate
* @param color_p an array of colors * @param color_p an array of colors
*/ */
void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
const lv_color_t * color_p) 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*/ /*Return if the area is out the screen*/
if (x2 < 0) if (x2 < 0)
@ -147,7 +153,8 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
for (y = act_y1; y <= act_y2; y++) { for (y = act_y1; y <= act_y2; y++) {
for (x = act_x1; x <= act_x2; x++) { for (x = act_x1; x <= act_x2; x++) {
tft_fb[y * MONITOR_HOR_RES + x] = color_p->full; //lv_color_to32(*color_p); tft_fb[y * MONITOR_HOR_RES + x] =
color_p->full; // lv_color_to32(*color_p);
color_p++; color_p++;
} }
@ -157,39 +164,42 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
sdl_refr_qry = true; sdl_refr_qry = true;
} }
void display_init(void) void
{ display_init(void)
} {}
void display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
const lv_color_t * color_p) 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); monitor_flush(x1, y1, x2, y2, color_p);
} }
void display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
lv_color_t color_p) 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); monitor_fill(x1, y1, x2, y2, color_p);
} }
void display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
const lv_color_t * color_p) 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); monitor_map(x1, y1, x2, y2, color_p);
} }
bool display_input_read(lv_indev_data_t * data) bool
display_input_read(lv_indev_data_t *data)
{ {
return mouse_read(data); return mouse_read(data);
} }
void display_deinit(void) void
{ display_deinit(void)
{}
} int
monitor_sdl_refr_thread(void *param)
int monitor_sdl_refr_thread(void * param)
{ {
(void) param; (void)param;
/*If not OSX initialize SDL in the Thread*/ /*If not OSX initialize SDL in the Thread*/
monitor_sdl_init(); monitor_sdl_init();
@ -205,19 +215,21 @@ int monitor_sdl_refr_thread(void * param)
return 0; return 0;
} }
void monitor_sdl_refr_core(void) void
monitor_sdl_refr_core(void)
{ {
if (sdl_refr_qry != false) { if (sdl_refr_qry != false) {
sdl_refr_qry = false; sdl_refr_qry = false;
SDL_UpdateTexture(texture, NULL, tft_fb, SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t)); MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
/*Test: Draw a background to test transparent screens (LV_COLOR_SCREEN_TRANSP)*/ /*Test: Draw a background to test transparent screens
// SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff); * (LV_COLOR_SCREEN_TRANSP)*/
// SDL_Rect r; // SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
// r.x = 0; r.y = 0; r.w = MONITOR_HOR_RES; r.w = MONITOR_VER_RES; // SDL_Rect r;
// SDL_RenderDrawRect(renderer, &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*/ /*Update the renderer with the texture containing the rendered image*/
SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
@ -231,29 +243,29 @@ void monitor_sdl_refr_core(void)
if ((&event)->type == SDL_WINDOWEVENT) { if ((&event)->type == SDL_WINDOWEVENT) {
switch ((&event)->window.event) { switch ((&event)->window.event) {
#if SDL_VERSION_ATLEAST(2, 0, 5) #if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_TAKE_FOCUS: case SDL_WINDOWEVENT_TAKE_FOCUS:
#endif #endif
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
SDL_UpdateTexture(texture, NULL, tft_fb, SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t)); MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
break; break;
default: default:
break; break;
} }
} }
} }
/*Sleep some time*/ /*Sleep some time*/
SDL_Delay(SDL_REFR_PERIOD); SDL_Delay(SDL_REFR_PERIOD);
} }
int quit_filter(void * userdata, SDL_Event * event) int
quit_filter(void *userdata, SDL_Event *event)
{ {
(void) userdata; (void)userdata;
if (event->type == SDL_QUIT) { if (event->type == SDL_QUIT) {
sdl_quit_qry = true; sdl_quit_qry = true;
@ -262,7 +274,8 @@ int quit_filter(void * userdata, SDL_Event * event)
return 1; return 1;
} }
void monitor_sdl_clean_up(void) void
monitor_sdl_clean_up(void)
{ {
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
@ -270,34 +283,37 @@ void monitor_sdl_clean_up(void)
SDL_Quit(); SDL_Quit();
} }
void monitor_sdl_init(void) void
monitor_sdl_init(void)
{ {
/*Initialize the SDL*/ /*Initialize the SDL*/
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
SDL_SetEventFilter(quit_filter, NULL); SDL_SetEventFilter(quit_filter, NULL);
window = SDL_CreateWindow("TFT Simulator", SDL_WINDOWPOS_UNDEFINED, window = SDL_CreateWindow(
SDL_WINDOWPOS_UNDEFINED, "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*/ 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); renderer = SDL_CreateRenderer(window, -1, 0);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES); SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES,
MONITOR_VER_RES);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
/*Initialize the frame buffer to gray (77 is an empirical value) */ /*Initialize the frame buffer to gray (77 is an empirical value) */
memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t)); memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
SDL_UpdateTexture(texture, NULL, tft_fb, SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t)); MONITOR_HOR_RES * sizeof(uint32_t));
sdl_refr_qry = true; sdl_refr_qry = true;
sdl_inited = true; sdl_inited = true;
} }
void display_SDL_init() void
display_SDL_init()
{ {
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL); SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
while (sdl_inited == false) while (sdl_inited == false)
; /*Wait until 'sdl_refr' initializes the SDL*/ ; /*Wait until 'sdl_refr' initializes the SDL*/
} }

View File

@ -5,4 +5,5 @@
#include <stdio.h> #include <stdio.h>
int time_get_ms(); int
time_get_ms();

View File

@ -28,9 +28,10 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void hal_init(void); static void
//static int tick_thread(void * data); hal_init(void);
//static void memory_monitor(void * param); // static int tick_thread(void * data);
// static void memory_monitor(void * param);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@ -47,22 +48,23 @@ uint32_t count = 0;
char count_str[11] = { 0 }; char count_str[11] = { 0 };
lv_obj_t *hello_world_label; lv_obj_t *hello_world_label;
lv_obj_t *count_label; lv_obj_t *count_label;
lv_obj_t * btn1; lv_obj_t *btn1;
lv_obj_t * label_count1; lv_obj_t *label_count1;
int label_count1_value = 0; int label_count1_value = 0;
char label_count1_str[11] = { 0 }; char label_count1_str[11] = { 0 };
static lv_res_t btn_rel_action(lv_obj_t * btn) static lv_res_t
btn_rel_action(lv_obj_t *btn)
{ {
label_count1_value++; label_count1_value++;
snprintf(label_count1_str, sizeof(label_count1_str), snprintf(label_count1_str, sizeof(label_count1_str), "%d",
"%d", label_count1_value); label_count1_value);
lv_label_set_text(label_count1, label_count1_str); lv_label_set_text(label_count1, label_count1_str);
return LV_RES_OK; return LV_RES_OK;
} }
int
int main() main()
{ {
void display_SDL_init(); void display_SDL_init();
display_SDL_init(); display_SDL_init();
@ -80,23 +82,26 @@ int main()
count_label = lv_label_create(lv_scr_act(), NULL); count_label = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); 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*/ btn1 = lv_btn_create(
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, btn_rel_action); /*Set function to be called when the button is released*/ 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*/ lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 20); /*Align below the label*/
/*Create a label on the button*/ /*Create a label on the button*/
lv_obj_t * btn_label = lv_label_create(btn1, NULL); lv_obj_t *btn_label = lv_label_create(btn1, NULL);
lv_label_set_text(btn_label, "Click ++"); lv_label_set_text(btn_label, "Click ++");
label_count1 = lv_label_create(lv_scr_act(), NULL); label_count1 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label_count1, "0"); lv_label_set_text(label_count1, "0");
lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
while(1) { while (1) {
/* Periodically call the lv_task handler. /* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/ * It could be done in a timer interrupt or an OS task too.*/
if ((count % 100) == 0) { if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count/ 100); snprintf(count_str, sizeof(count_str), "%d", count / 100);
lv_label_set_text(count_label, count_str); lv_label_set_text(count_label, count_str);
} }
lv_task_handler(); lv_task_handler();
@ -112,31 +117,41 @@ int main()
**********************/ **********************/
/** /**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library * 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, void
const lv_color_t * color_p) 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); display_flush(x1, y1, x2, y2, color_p);
lv_flush_ready(); lv_flush_ready();
} }
void display_vdb_write_wrapper(uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, void
lv_coord_t y, lv_color_t color, lv_opa_t opa) 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); 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, extern void
lv_color_t color_p); display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
extern void display_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color_p);
const lv_color_t * color_p); extern void
static void hal_init(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*/ /* Add a display*/
lv_disp_drv_t disp_drv; lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); /*Basic initialization*/ 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_flush =
disp_drv.disp_fill = display_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ display_flush_wrapper; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h
disp_drv.disp_map = display_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ (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 #if LV_VDB_SIZE != 0
disp_drv.vdb_wr = display_vdb_write_wrapper; disp_drv.vdb_wr = display_vdb_write_wrapper;
#endif #endif
@ -144,12 +159,12 @@ static void hal_init(void)
/* Add the mouse as input device /* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse*/ * Use the 'mouse' driver which reads the PC's mouse*/
// mouse_init(); // mouse_init();
lv_indev_drv_t indev_drv; lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/ lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_POINTER; 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*/ indev_drv.read =
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv); 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

@ -28,18 +28,18 @@ typedef struct {
typedef struct { typedef struct {
union { union {
lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/ 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 key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/ 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*/ 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*/ 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_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
} lv_indev_data_t; } lv_indev_data_t;
enum { enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR };
LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR
};
enum { enum {
LV_OPA_TRANSP = 0, LV_OPA_TRANSP = 0,
LV_OPA_0 = 0, LV_OPA_0 = 0,
@ -56,35 +56,41 @@ enum {
LV_OPA_COVER = 255, LV_OPA_COVER = 255,
}; };
extern void xpt2046_init(void); extern void
xpt2046_init(void);
extern bool touchscreen_read(lv_indev_data_t *data); extern bool
touchscreen_read(lv_indev_data_t *data);
extern bool mouse_read(lv_indev_data_t *data); extern bool
mouse_read(lv_indev_data_t *data);
extern void display_init(void); extern void
display_init(void);
extern void display_deinit(wasm_exec_env_t exec_env); extern void
display_deinit(wasm_exec_env_t exec_env);
extern int time_get_ms(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, extern void
int32_t x1, int32_t y1, int32_t x2, int32_t y2, display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
lv_color_t *color); int32_t y2, lv_color_t *color);
extern void display_fill(wasm_exec_env_t exec_env, extern void
int32_t x1, int32_t y1, int32_t x2, int32_t y2, display_fill(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
lv_color_t *color); int32_t y2, lv_color_t *color);
extern void display_map(wasm_exec_env_t exec_env, extern void
int32_t x1, int32_t y1, int32_t x2, int32_t y2, display_map(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
const lv_color_t *color); int32_t y2, const lv_color_t *color);
extern bool display_input_read(wasm_exec_env_t exec_env, void *data); extern bool
display_input_read(wasm_exec_env_t exec_env, void *data);
void display_vdb_write(wasm_exec_env_t exec_env, void
void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w,
lv_color_t *color, lv_opa_t opa); lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa);
#endif #endif

View File

@ -14,12 +14,15 @@
#define MONITOR_HOR_RES 320 #define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240 #define MONITOR_VER_RES 240
#ifndef MONITOR_ZOOM #ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1 #define MONITOR_ZOOM 1
#endif #endif
#define SDL_REFR_PERIOD 50 #define SDL_REFR_PERIOD 50
void monitor_sdl_init(void); void
void monitor_sdl_refr_core(void); monitor_sdl_init(void);
void monitor_sdl_clean_up(void); void
monitor_sdl_refr_core(void);
void
monitor_sdl_clean_up(void);
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES]; static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES];
@ -30,22 +33,23 @@ time_get_ms(wasm_exec_env_t exec_env)
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000; long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
return (int) time_in_mill; return (int)time_in_mill;
} }
SDL_Window * window; SDL_Window *window;
SDL_Renderer * renderer; SDL_Renderer *renderer;
SDL_Texture * texture; SDL_Texture *texture;
static volatile bool sdl_inited = false; static volatile bool sdl_inited = false;
static volatile bool sdl_refr_qry = false; static volatile bool sdl_refr_qry = false;
static volatile bool sdl_quit_qry = false; static volatile bool sdl_quit_qry = false;
void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
const lv_color_t * color) 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*/ /*Return if the area is out the screen*/
if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1 if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1
|| y1 > MONITOR_VER_RES - 1) { || y1 > MONITOR_VER_RES - 1) {
return; return;
} }
@ -71,8 +75,8 @@ void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
* @param y2 bottom coordinate * @param y2 bottom coordinate
* @param color fill color * @param color fill color
*/ */
void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
lv_color_t *color) 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*/ /*Return if the area is out the screen*/
if (x2 < 0) if (x2 < 0)
@ -92,7 +96,7 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
int32_t x; int32_t x;
int32_t y; int32_t y;
uint32_t color32 = color->full; //lv_color_to32(color); uint32_t color32 = color->full; // lv_color_to32(color);
for (x = act_x1; x <= act_x2; x++) { for (x = act_x1; x <= act_x2; x++) {
for (y = act_y1; y <= act_y2; y++) { for (y = act_y1; y <= act_y2; y++) {
@ -111,8 +115,9 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
* @param y2 bottom coordinate * @param y2 bottom coordinate
* @param color an array of colors * @param color an array of colors
*/ */
void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
const lv_color_t *color) 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*/ /*Return if the area is out the screen*/
if (x2 < 0) if (x2 < 0)
@ -135,7 +140,8 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
for (y = act_y1; y <= act_y2; y++) { for (y = act_y1; y <= act_y2; y++) {
for (x = act_x1; x <= act_x2; x++) { for (x = act_x1; x <= act_x2; x++) {
tft_fb[y * MONITOR_HOR_RES + x] = color->full; //lv_color_to32(*color); tft_fb[y * MONITOR_HOR_RES + x] =
color->full; // lv_color_to32(*color);
color++; color++;
} }
@ -145,38 +151,33 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
sdl_refr_qry = true; sdl_refr_qry = true;
} }
void void
display_init(void) display_init(void)
{ {}
}
void void
display_flush(wasm_exec_env_t exec_env, display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t y2, lv_color_t *color)
lv_color_t *color)
{ {
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (!wasm_runtime_validate_native_addr(module_inst, if (!wasm_runtime_validate_native_addr(module_inst, color,
color, sizeof(lv_color_t))) sizeof(lv_color_t)))
return; return;
monitor_flush(x1, y1, x2, y2, color); monitor_flush(x1, y1, x2, y2, color);
} }
void void
display_fill(wasm_exec_env_t exec_env, display_fill(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t y2, lv_color_t *color)
lv_color_t *color)
{ {
monitor_fill(x1, y1, x2, y2, color); monitor_fill(x1, y1, x2, y2, color);
} }
void void
display_map(wasm_exec_env_t exec_env, display_map(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t y2, const lv_color_t *color)
const lv_color_t *color)
{ {
monitor_map(x1, y1, x2, y2, color); monitor_map(x1, y1, x2, y2, color);
} }
@ -188,20 +189,17 @@ typedef struct display_input_data {
} display_input_data; } display_input_data;
bool bool
display_input_read(wasm_exec_env_t exec_env, display_input_read(wasm_exec_env_t exec_env, void *input_data_app)
void *input_data_app)
{ {
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
display_input_data *data_app = (display_input_data*)input_data_app; display_input_data *data_app = (display_input_data *)input_data_app;
bool ret; bool ret;
if (!wasm_runtime_validate_native_addr(module_inst, if (!wasm_runtime_validate_native_addr(module_inst, data_app,
data_app,
sizeof(display_input_data))) sizeof(display_input_data)))
return false; return false;
lv_indev_data_t data = { 0 };
lv_indev_data_t data = {0};
ret = mouse_read(&data); ret = mouse_read(&data);
@ -215,27 +213,26 @@ display_input_read(wasm_exec_env_t exec_env,
void void
display_deinit(wasm_exec_env_t exec_env) display_deinit(wasm_exec_env_t exec_env)
{ {}
}
void void
display_vdb_write(wasm_exec_env_t exec_env, display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w,
void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa)
lv_color_t *color, lv_opa_t opa)
{ {
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
unsigned char *buf_xy = (unsigned char*)buf + 4 * x + 4 * y * buf_w; unsigned char *buf_xy = (unsigned char *)buf + 4 * x + 4 * y * buf_w;
if (!wasm_runtime_validate_native_addr(module_inst, if (!wasm_runtime_validate_native_addr(module_inst, color,
color, sizeof(lv_color_t))) sizeof(lv_color_t)))
return; return;
*(lv_color_t *)buf_xy = *color; *(lv_color_t *)buf_xy = *color;
} }
int monitor_sdl_refr_thread(void * param) int
monitor_sdl_refr_thread(void *param)
{ {
(void) param; (void)param;
/*If not OSX initialize SDL in the Thread*/ /*If not OSX initialize SDL in the Thread*/
monitor_sdl_init(); monitor_sdl_init();
@ -250,14 +247,16 @@ int monitor_sdl_refr_thread(void * param)
return 0; return 0;
} }
extern void mouse_handler(SDL_Event *event); extern void
void monitor_sdl_refr_core(void) mouse_handler(SDL_Event *event);
void
monitor_sdl_refr_core(void)
{ {
if (sdl_refr_qry != false) { if (sdl_refr_qry != false) {
sdl_refr_qry = false; sdl_refr_qry = false;
SDL_UpdateTexture(texture, NULL, tft_fb, SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t)); MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
/*Update the renderer with the texture containing the rendered image*/ /*Update the renderer with the texture containing the rendered image*/
SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderCopy(renderer, texture, NULL, NULL);
@ -272,29 +271,29 @@ void monitor_sdl_refr_core(void)
if ((&event)->type == SDL_WINDOWEVENT) { if ((&event)->type == SDL_WINDOWEVENT) {
switch ((&event)->window.event) { switch ((&event)->window.event) {
#if SDL_VERSION_ATLEAST(2, 0, 5) #if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_TAKE_FOCUS: case SDL_WINDOWEVENT_TAKE_FOCUS:
#endif #endif
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
SDL_UpdateTexture(texture, NULL, tft_fb, SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t)); MONITOR_HOR_RES * sizeof(uint32_t));
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
break; break;
default: default:
break; break;
} }
} }
} }
/*Sleep some time*/ /*Sleep some time*/
SDL_Delay(SDL_REFR_PERIOD); SDL_Delay(SDL_REFR_PERIOD);
} }
int quit_filter(void * userdata, SDL_Event * event) int
quit_filter(void *userdata, SDL_Event *event)
{ {
(void) userdata; (void)userdata;
if (event->type == SDL_QUIT) { if (event->type == SDL_QUIT) {
sdl_quit_qry = true; sdl_quit_qry = true;
@ -303,7 +302,8 @@ int quit_filter(void * userdata, SDL_Event * event)
return 1; return 1;
} }
void monitor_sdl_clean_up(void) void
monitor_sdl_clean_up(void)
{ {
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
@ -311,34 +311,37 @@ void monitor_sdl_clean_up(void)
SDL_Quit(); SDL_Quit();
} }
void monitor_sdl_init(void) void
monitor_sdl_init(void)
{ {
/*Initialize the SDL*/ /*Initialize the SDL*/
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
SDL_SetEventFilter(quit_filter, NULL); SDL_SetEventFilter(quit_filter, NULL);
window = SDL_CreateWindow("TFT Simulator", SDL_WINDOWPOS_UNDEFINED, window = SDL_CreateWindow(
SDL_WINDOWPOS_UNDEFINED, "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*/ 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); renderer = SDL_CreateRenderer(window, -1, 0);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES); SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES,
MONITOR_VER_RES);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
/*Initialize the frame buffer to gray (77 is an empirical value) */ /*Initialize the frame buffer to gray (77 is an empirical value) */
memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t)); memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
SDL_UpdateTexture(texture, NULL, tft_fb, SDL_UpdateTexture(texture, NULL, tft_fb,
MONITOR_HOR_RES * sizeof(uint32_t)); MONITOR_HOR_RES * sizeof(uint32_t));
sdl_refr_qry = true; sdl_refr_qry = true;
sdl_inited = true; sdl_inited = true;
} }
void display_SDL_init() void
display_SDL_init()
{ {
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL); SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
while (sdl_inited == false) while (sdl_inited == false)
; /*Wait until 'sdl_refr' initializes the SDL*/ ; /*Wait until 'sdl_refr' initializes the SDL*/
} }

View File

@ -43,11 +43,16 @@ static char *uart_device = "/dev/ttyS2";
static int baudrate = B115200; static int baudrate = B115200;
#endif #endif
extern void init_sensor_framework(); extern void
extern void exit_sensor_framework(); init_sensor_framework();
extern void exit_connection_framework(); extern void
extern int aee_host_msg_callback(void *msg, uint32_t msg_len); exit_sensor_framework();
extern bool init_connection_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 #ifndef CONNECTION_UART
int listenfd = -1; int listenfd = -1;
@ -61,7 +66,8 @@ int uartfd = -1;
static bool server_mode = false; static bool server_mode = false;
// Function designed for chat between client and server. // Function designed for chat between client and server.
void* func(void* arg) void *
func(void *arg)
{ {
char buff[MAX]; char buff[MAX];
int n; int n;
@ -75,7 +81,8 @@ void* func(void* arg)
if (sockfd == -1) { if (sockfd == -1) {
printf("socket creation failed...\n"); printf("socket creation failed...\n");
return NULL; return NULL;
} else }
else
printf("Socket successfully created..\n"); printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr)); bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT // assign IP, PORT
@ -84,11 +91,12 @@ void* func(void* arg)
servaddr.sin_port = htons(port); servaddr.sin_port = htons(port);
// connect the client socket to server socket // connect the client socket to server socket
if (connect(sockfd, (SA*) &servaddr, sizeof(servaddr)) != 0) { if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n"); printf("connection with the server failed...\n");
sleep(10); sleep(10);
continue; continue;
} else { }
else {
printf("connected to the server..\n"); printf("connected to the server..\n");
} }
@ -99,7 +107,7 @@ void* func(void* arg)
// read the message from client and copy it in buffer // read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff)); n = read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents // print buffer which contains the client contents
//fprintf(stderr, "recieved %d bytes from host: %s", n, buff); // fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
// socket disconnected // socket disconnected
if (n <= 0) if (n <= 0)
@ -113,12 +121,14 @@ void* func(void* arg)
close(sockfd); close(sockfd);
} }
static bool host_init() static bool
host_init()
{ {
return true; return true;
} }
int host_send(void * ctx, const char *buf, int size) int
host_send(void *ctx, const char *buf, int size)
{ {
int ret; int ret;
@ -137,7 +147,8 @@ int host_send(void * ctx, const char *buf, int size)
return -1; return -1;
} }
void host_destroy() void
host_destroy()
{ {
if (server_mode) if (server_mode)
close(listenfd); close(listenfd);
@ -147,13 +158,12 @@ void host_destroy()
pthread_mutex_unlock(&sock_lock); pthread_mutex_unlock(&sock_lock);
} }
host_interface interface = { host_interface interface = { .init = host_init,
.init = host_init,
.send = host_send, .send = host_send,
.destroy = host_destroy .destroy = host_destroy };
};
void* func_server_mode(void* arg) void *
func_server_mode(void *arg)
{ {
int clilent; int clilent;
struct sockaddr_in serv_addr, cli_addr; struct sockaddr_in serv_addr, cli_addr;
@ -173,14 +183,14 @@ void* func_server_mode(void* arg)
} }
/* Initialize socket structure */ /* Initialize socket structure */
bzero((char *) &serv_addr, sizeof(serv_addr)); bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port); serv_addr.sin_port = htons(port);
/* Now bind the host address using bind() call.*/ /* Now bind the host address using bind() call.*/
if (bind(listenfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("ERROR on binding"); perror("ERROR on binding");
exit(1); exit(1);
} }
@ -191,7 +201,7 @@ void* func_server_mode(void* arg)
while (1) { while (1) {
pthread_mutex_lock(&sock_lock); pthread_mutex_lock(&sock_lock);
sockfd = accept(listenfd, (struct sockaddr *) &cli_addr, &clilent); sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent);
pthread_mutex_unlock(&sock_lock); pthread_mutex_unlock(&sock_lock);
@ -225,7 +235,8 @@ void* func_server_mode(void* arg)
} }
#else #else
static int parse_baudrate(int baud) static int
parse_baudrate(int baud)
{ {
switch (baud) { switch (baud) {
case 9600: case 9600:
@ -268,7 +279,8 @@ static int parse_baudrate(int baud)
return -1; return -1;
} }
} }
static bool uart_init(const char *device, int baudrate, int *fd) static bool
uart_init(const char *device, int baudrate, int *fd)
{ {
int uart_fd; int uart_fd;
struct termios uart_term; struct termios uart_term;
@ -299,7 +311,8 @@ static bool uart_init(const char *device, int baudrate, int *fd)
return true; return true;
} }
static void *func_uart_mode(void *arg) static void *
func_uart_mode(void *arg)
{ {
int n; int n;
char buff[MAX]; char buff[MAX];
@ -326,7 +339,8 @@ static void *func_uart_mode(void *arg)
return NULL; return NULL;
} }
static int uart_send(void * ctx, const char *buf, int size) static int
uart_send(void *ctx, const char *buf, int size)
{ {
int ret; int ret;
@ -335,12 +349,14 @@ static int uart_send(void * ctx, const char *buf, int size)
return ret; return ret;
} }
static void uart_destroy() static void
uart_destroy()
{ {
close(uartfd); close(uartfd);
} }
static host_interface interface = { .send = uart_send, .destroy = uart_destroy }; static host_interface interface = { .send = uart_send,
.destroy = uart_destroy };
#endif #endif
@ -350,6 +366,7 @@ static char global_heap_buf[400 * 1024] = { 0 };
static char global_heap_buf[270 * 1024] = { 0 }; static char global_heap_buf[270 * 1024] = { 0 };
#endif #endif
/* clang-format off */
static void showUsage() static void showUsage()
{ {
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
@ -373,8 +390,10 @@ static void showUsage()
printf("\nNote:\n"); printf("\nNote:\n");
printf("\tUse -w|--wasi_root to specify the root dir (default to '.') of WASI wasm modules. \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[]) static bool
parse_args(int argc, char *argv[])
{ {
int c; int c;
@ -382,17 +401,17 @@ static bool parse_args(int argc, char *argv[])
int optIndex = 0; int optIndex = 0;
static struct option longOpts[] = { static struct option longOpts[] = {
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' }, { "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' }, { "host_address", required_argument, NULL, 'a' },
{ "port", required_argument, NULL, 'p' }, { "port", required_argument, NULL, 'p' },
#else #else
{ "uart", required_argument, NULL, 'u' }, { "uart", required_argument, NULL, 'u' },
{ "baudrate", required_argument, NULL, 'b' }, { "baudrate", required_argument, NULL, 'b' },
#endif #endif
#if WASM_ENABLE_LIBC_WASI != 0 #if WASM_ENABLE_LIBC_WASI != 0
{ "wasi_root", required_argument, NULL, 'w' }, { "wasi_root", required_argument, NULL, 'w' },
#endif #endif
{ "help", required_argument, NULL, 'h' }, { "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@ -453,7 +472,8 @@ static NativeSymbol native_symbols[] = {
}; };
// Driver function // Driver function
int iwasm_main(int argc, char *argv[]) int
iwasm_main(int argc, char *argv[])
{ {
RuntimeInitArgs init_args; RuntimeInitArgs init_args;
korp_tid tid; korp_tid tid;
@ -493,11 +513,12 @@ int iwasm_main(int argc, char *argv[])
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
if (server_mode) if (server_mode)
os_thread_create(&tid, func_server_mode, NULL, os_thread_create(&tid, func_server_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE); BH_APPLET_PRESERVED_STACK_SIZE);
else else
os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE); os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
#else #else
os_thread_create(&tid, func_uart_mode, NULL, BH_APPLET_PRESERVED_STACK_SIZE); os_thread_create(&tid, func_uart_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
#endif #endif
app_manager_startup(&interface); app_manager_startup(&interface);

View File

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

View File

@ -14,7 +14,7 @@
* DEFINES * DEFINES
*********************/ *********************/
#ifndef MONITOR_ZOOM #ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1 #define MONITOR_ZOOM 1
#endif #endif
/********************** /**********************
@ -43,17 +43,18 @@ static int16_t last_y = 0;
/** /**
* Initialize the mouse * Initialize the mouse
*/ */
void mouse_init(void) void
{ mouse_init(void)
{}
}
/** /**
* Get the current position and state of the mouse * Get the current position and state of the mouse
* @param data store the mouse data here * @param data store the mouse data here
* @return false: because the points are not buffered, so no more data to be read * @return false: because the points are not buffered, so no more data to be
* read
*/ */
bool mouse_read(lv_indev_data_t * data) bool
mouse_read(lv_indev_data_t *data)
{ {
/*Store the collected data*/ /*Store the collected data*/
data->point.x = last_x; data->point.x = last_x;
@ -66,27 +67,27 @@ bool mouse_read(lv_indev_data_t * data)
/** /**
* It will be called from the main SDL thread * It will be called from the main SDL thread
*/ */
void mouse_handler(SDL_Event * event) void
mouse_handler(SDL_Event *event)
{ {
switch (event->type) { switch (event->type) {
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (event->button.button == SDL_BUTTON_LEFT) if (event->button.button == SDL_BUTTON_LEFT)
left_button_down = false; left_button_down = false;
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if (event->button.button == SDL_BUTTON_LEFT) { if (event->button.button == SDL_BUTTON_LEFT) {
left_button_down = true; 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_x = event->motion.x / MONITOR_ZOOM;
last_y = event->motion.y / 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; break;
} }
} }
/********************** /**********************

View File

@ -1,6 +1,6 @@
/** /**
* @file XPT2046.c * @file XPT2046.c
*/ */
/********************* /*********************
* INCLUDES * INCLUDES
*********************/ *********************/
@ -30,7 +30,8 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void xpt2046_corr(int16_t * x, int16_t * y); static void
xpt2046_corr(int16_t *x, int16_t *y);
#if 0 #if 0
static void xpt2046_avg(int16_t * x, int16_t * y); static void xpt2046_avg(int16_t * x, int16_t * y);
#endif #endif
@ -63,18 +64,20 @@ lv_indev_data_t touch_point;
lv_indev_data_t last_touch_point; lv_indev_data_t last_touch_point;
#define TOUCH_READ_THREAD_STACK_SIZE 4096 #define TOUCH_READ_THREAD_STACK_SIZE 4096
static K_THREAD_STACK_DEFINE(touch_read_thread_stack, TOUCH_READ_THREAD_STACK_SIZE); static K_THREAD_STACK_DEFINE(touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE);
static struct k_thread touch_thread_data; static struct k_thread touch_thread_data;
static struct k_sem sem_touch_read; static struct k_sem sem_touch_read;
K_MUTEX_DEFINE( spi_display_touch_mutex); K_MUTEX_DEFINE(spi_display_touch_mutex);
int cnt = 0; int cnt = 0;
int touch_read_times = 0; int touch_read_times = 0;
int last_pen_interrupt_time = 0; int last_pen_interrupt_time = 0;
void xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb, void
uint32_t pins) xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
uint32_t pins)
{ {
cnt++; cnt++;
if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) { if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) {
@ -82,10 +85,10 @@ void xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
touch_read_times++; touch_read_times++;
last_pen_interrupt_time = k_uptime_get_32(); last_pen_interrupt_time = k_uptime_get_32();
} }
} }
void disable_pen_interrupt() void
disable_pen_interrupt()
{ {
int ret = 0; int ret = 0;
ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
@ -93,7 +96,8 @@ void disable_pen_interrupt()
printf("gpio_pin_configure GPIO_INPUT failed\n"); printf("gpio_pin_configure GPIO_INPUT failed\n");
} }
} }
void enable_pen_interrupt() void
enable_pen_interrupt()
{ {
int ret = 0; int ret = 0;
ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN);
@ -102,7 +106,8 @@ void enable_pen_interrupt()
} }
} }
void touch_screen_read_thread() void
touch_screen_read_thread()
{ {
int i; int i;
bool ret = false; bool ret = false;
@ -119,12 +124,11 @@ void touch_screen_read_thread()
ret = xpt2046_read(&touch_point); ret = xpt2046_read(&touch_point);
if (ret) { if (ret) {
if ((abs(last_touch_point.point.x - touch_point.point.x) < 4) if ((abs(last_touch_point.point.x - touch_point.point.x) < 4)
&& (abs(last_touch_point.point.y - touch_point.point.y) && (abs(last_touch_point.point.y - touch_point.point.y)
< 4)) { < 4)) {
break; break;
} }
last_touch_point = touch_point; last_touch_point = touch_point;
} }
} }
enable_pen_interrupt(); enable_pen_interrupt();
@ -132,7 +136,8 @@ void touch_screen_read_thread()
} }
} }
void xpt2046_init(void) void
xpt2046_init(void)
{ {
int ret; int ret;
input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME); input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME);
@ -141,7 +146,7 @@ void xpt2046_init(void)
printf("device not found. Aborting test."); printf("device not found. Aborting test.");
return; return;
} }
memset((void *) &touch_point, 0, sizeof(lv_indev_data_t)); memset((void *)&touch_point, 0, sizeof(lv_indev_data_t));
spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY; spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY;
spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8); spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
@ -172,8 +177,7 @@ void xpt2046_init(void)
/* Setup GPIO input */ /* Setup GPIO input */
ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN, ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN,
(GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE (GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE
| GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE) | GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE));
);
if (ret) { if (ret) {
printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN); printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN);
} }
@ -195,8 +199,7 @@ void xpt2046_init(void)
k_thread_create(&touch_thread_data, touch_read_thread_stack, k_thread_create(&touch_thread_data, touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread, TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread,
NULL, NULL, NULL, 5, NULL, NULL, NULL, 5, 0, K_NO_WAIT);
0, K_NO_WAIT);
printf("xpt2046_init ok \n"); printf("xpt2046_init ok \n");
} }
@ -205,7 +208,8 @@ void xpt2046_init(void)
* @param data store the read data here * @param data store the read data here
* @return false: because no ore data to be read * @return false: because no ore data to be read
*/ */
bool xpt2046_read(lv_indev_data_t * data) bool
xpt2046_read(lv_indev_data_t *data)
{ {
static int16_t last_x = 0; static int16_t last_x = 0;
static int16_t last_y = 0; static int16_t last_y = 0;
@ -259,7 +263,8 @@ bool xpt2046_read(lv_indev_data_t * data)
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static void xpt2046_corr(int16_t * x, int16_t * y) static void
xpt2046_corr(int16_t *x, int16_t *y)
{ {
#if XPT2046_XY_SWAP != 0 #if XPT2046_XY_SWAP != 0
int16_t swap_tmp; int16_t swap_tmp;
@ -279,10 +284,10 @@ static void xpt2046_corr(int16_t * x, int16_t * y)
(*y) = 0; (*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES) (*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES)
/ (XPT2046_X_MAX - XPT2046_X_MIN); / (XPT2046_X_MAX - XPT2046_X_MIN);
(*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES) (*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES)
/ (XPT2046_Y_MAX - XPT2046_Y_MIN); / (XPT2046_Y_MAX - XPT2046_Y_MIN);
#if XPT2046_X_INV != 0 #if XPT2046_X_INV != 0
(*x) = XPT2046_HOR_RES - (*x); (*x) = XPT2046_HOR_RES - (*x);
@ -291,7 +296,6 @@ static void xpt2046_corr(int16_t * x, int16_t * y)
#if XPT2046_Y_INV != 0 #if XPT2046_Y_INV != 0
(*y) = XPT2046_VER_RES - (*y); (*y) = XPT2046_VER_RES - (*y);
#endif #endif
} }
#if 0 #if 0
@ -324,7 +328,8 @@ static void xpt2046_avg(int16_t * x, int16_t * y)
} }
#endif #endif
bool touchscreen_read(lv_indev_data_t * data) bool
touchscreen_read(lv_indev_data_t *data)
{ {
/*Store the collected data*/ /*Store the collected data*/
data->point.x = last_touch_point.point.x; data->point.x = last_touch_point.point.x;

View File

@ -8,18 +8,17 @@
#define USE_XPT2046 1 #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 XPT2046_HOR_RES 320 #define CMD_X_READ 0b10010000
# define XPT2046_VER_RES 240 #define CMD_Y_READ 0b11010000
# 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 #ifdef __cplusplus
extern "C" { extern "C" {
@ -37,9 +36,7 @@ extern "C" {
#include "device.h" #include "device.h"
#include "drivers/gpio.h" #include "drivers/gpio.h"
#if 1 #if 1
enum { enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR };
LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR
};
typedef uint8_t lv_indev_state_t; typedef uint8_t lv_indev_state_t;
typedef int16_t lv_coord_t; typedef int16_t lv_coord_t;
typedef struct { typedef struct {
@ -49,12 +46,14 @@ typedef struct {
typedef struct { typedef struct {
union { union {
lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/ 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 key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/ 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*/ 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*/ 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_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
} lv_indev_data_t; } lv_indev_data_t;
#endif #endif
@ -70,8 +69,10 @@ typedef struct {
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
void xpt2046_init(void); void
bool xpt2046_read(lv_indev_data_t * data); xpt2046_init(void);
bool
xpt2046_read(lv_indev_data_t *data);
/********************** /**********************
* MACROS * MACROS

View File

@ -143,8 +143,8 @@ typedef int (*display_blanking_off_api)(const struct device *dev);
* @brief Callback API for writing data to the display * @brief Callback API for writing data to the display
* See display_write() for argument description * See display_write() for argument description
*/ */
typedef int (*display_write_api)(const struct device *dev, typedef int (*display_write_api)(const struct device *dev, const uint16_t x,
const uint16_t x, const uint16_t y, const uint16_t y,
const struct display_buffer_descriptor *desc, const struct display_buffer_descriptor *desc,
const void *buf); const void *buf);
@ -153,8 +153,8 @@ typedef int (*display_write_api)(const struct device *dev,
* @brief Callback API for reading data from the display * @brief Callback API for reading data from the display
* See display_read() for argument description * See display_read() for argument description
*/ */
typedef int (*display_read_api)(const struct device *dev, typedef int (*display_read_api)(const struct device *dev, const uint16_t x,
const uint16_t x, const uint16_t y, const uint16_t y,
const struct display_buffer_descriptor *desc, const struct display_buffer_descriptor *desc,
void *buf); void *buf);
@ -186,24 +186,24 @@ typedef int (*display_set_contrast_api)(const struct device *dev,
* @brief Callback API to get display capabilities * @brief Callback API to get display capabilities
* See display_get_capabilities() for argument description * See display_get_capabilities() for argument description
*/ */
typedef void (*display_get_capabilities_api)(const struct device *dev, typedef void (*display_get_capabilities_api)(
struct display_capabilities * capabilities); const struct device *dev, struct display_capabilities *capabilities);
/** /**
* @typedef display_set_pixel_format_api * @typedef display_set_pixel_format_api
* @brief Callback API to set pixel format used by the display * @brief Callback API to set pixel format used by the display
* See display_set_pixel_format() for argument description * See display_set_pixel_format() for argument description
*/ */
typedef int (*display_set_pixel_format_api)(const struct device *dev, typedef int (*display_set_pixel_format_api)(
const enum display_pixel_format pixel_format); const struct device *dev, const enum display_pixel_format pixel_format);
/** /**
* @typedef display_set_orientation_api * @typedef display_set_orientation_api
* @brief Callback API to set orientation used by the display * @brief Callback API to set orientation used by the display
* See display_set_orientation() for argument description * See display_set_orientation() for argument description
*/ */
typedef int (*display_set_orientation_api)(const struct device *dev, typedef int (*display_set_orientation_api)(
const enum display_orientation orientation); const struct device *dev, const enum display_orientation orientation);
/** /**
* @brief Display driver API * @brief Display driver API
@ -363,7 +363,7 @@ display_set_contrast(const struct device *dev, uint8_t contrast)
*/ */
static inline void static inline void
display_get_capabilities(const struct device *dev, display_get_capabilities(const struct device *dev,
struct display_capabilities * capabilities) struct display_capabilities *capabilities)
{ {
struct display_driver_api *api = &ili9340_api1; struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api; //(struct display_driver_api *)dev->driver_api;

View File

@ -9,7 +9,7 @@
//#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL //#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL
//#include <logging/log.h> //#include <logging/log.h>
//LOG_MODULE_REGISTER(display_ili9340); // LOG_MODULE_REGISTER(display_ili9340);
#define LOG_ERR printf #define LOG_ERR printf
#define LOG_DBG printf #define LOG_DBG printf
#define LOG_WRN printf #define LOG_WRN printf
@ -39,7 +39,7 @@ static void
ili9340_exit_sleep(struct ili9340_data *data) ili9340_exit_sleep(struct ili9340_data *data)
{ {
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0); ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
//k_sleep(Z_TIMEOUT_MS(120)); // k_sleep(Z_TIMEOUT_MS(120));
} }
int int
@ -53,20 +53,22 @@ ili9340_init()
return -EPERM; return -EPERM;
} }
data->spi_config.frequency = DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY; 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.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; data->spi_config.slave = DT_ILITEK_ILI9340_0_BASE_ADDRESS;
#ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER #ifdef DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER
data->cs_ctrl.gpio_dev = data->cs_ctrl.gpio_dev =
device_get_binding(DT_ILITEK_ILI9340_0_CS_GPIO_CONTROLLER); 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.gpio_pin = DT_ILITEK_ILI9340_0_CS_GPIO_PIN;
data->cs_ctrl.delay = 0; data->cs_ctrl.delay = 0;
data->spi_config.cs = &(data->cs_ctrl); data->spi_config.cs = &(data->cs_ctrl);
#else #else
data->spi_config.cs = NULL; data->spi_config.cs = NULL;
#endif #endif
data->reset_gpio = device_get_binding( data->reset_gpio =
DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER); device_get_binding(DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER);
if (data->reset_gpio == NULL) { if (data->reset_gpio == NULL) {
return -EPERM; return -EPERM;
} }
@ -74,8 +76,8 @@ ili9340_init()
gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN, gpio_pin_configure(data->reset_gpio, DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN,
GPIO_OUTPUT); GPIO_OUTPUT);
data->command_data_gpio = device_get_binding( data->command_data_gpio =
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER); device_get_binding(DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER);
if (data->command_data_gpio == NULL) { if (data->command_data_gpio == NULL) {
return -EPERM; return -EPERM;
} }
@ -101,9 +103,8 @@ ili9340_init()
} }
static void static void
ili9340_set_mem_area(struct ili9340_data *data, ili9340_set_mem_area(struct ili9340_data *data, const uint16_t x,
const uint16_t x, const uint16_t y, const uint16_t y, const uint16_t w, const uint16_t h)
const uint16_t w, const uint16_t h)
{ {
uint16_t spi_data[2]; uint16_t spi_data[2];
@ -120,8 +121,8 @@ static int
ili9340_write(const struct device *dev, const uint16_t x, const uint16_t y, ili9340_write(const struct device *dev, const uint16_t x, const uint16_t y,
const struct display_buffer_descriptor *desc, const void *buf) const struct display_buffer_descriptor *desc, const void *buf)
{ {
struct ili9340_data *data = (struct ili9340_data *) &ili9340_data1; struct ili9340_data *data = (struct ili9340_data *)&ili9340_data1;
const uint8_t *write_data_start = (uint8_t *) buf; const uint8_t *write_data_start = (uint8_t *)buf;
struct spi_buf tx_buf; struct spi_buf tx_buf;
struct spi_buf_set tx_bufs; struct spi_buf_set tx_bufs;
uint16_t write_cnt; uint16_t write_cnt;
@ -136,11 +137,12 @@ ili9340_write(const struct device *dev, const uint16_t x, const uint16_t y,
if (desc->pitch > desc->width) { if (desc->pitch > desc->width) {
write_h = 1U; write_h = 1U;
nbr_of_writes = desc->height; nbr_of_writes = desc->height;
} else { }
else {
write_h = desc->height; write_h = desc->height;
nbr_of_writes = 1U; nbr_of_writes = 1U;
} }
ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *) write_data_start, ili9340_transmit(data, ILI9340_CMD_MEM_WRITE, (void *)write_data_start,
3 * desc->width * write_h); 3 * desc->width * write_h);
tx_bufs.buffers = &tx_buf; tx_bufs.buffers = &tx_buf;
@ -148,7 +150,7 @@ ili9340_write(const struct device *dev, const uint16_t x, const uint16_t y,
write_data_start += (3 * desc->pitch); write_data_start += (3 * desc->pitch);
for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) { for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) {
tx_buf.buf = (void *) write_data_start; tx_buf.buf = (void *)write_data_start;
tx_buf.len = 3 * desc->width * write_h; tx_buf.len = 3 * desc->width * write_h;
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
write_data_start += (3 * desc->pitch); write_data_start += (3 * desc->pitch);
@ -241,22 +243,23 @@ ili9340_get_capabilities(const struct device *dev,
} }
void void
ili9340_transmit(struct ili9340_data *data, uint8_t cmd, ili9340_transmit(struct ili9340_data *data, uint8_t cmd, void *tx_data,
void *tx_data, size_t tx_len) size_t tx_len)
{ {
struct spi_buf tx_buf = { .buf = &cmd, .len = 1 }; struct spi_buf tx_buf = { .buf = &cmd, .len = 1 };
struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 }; struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 };
data = (struct ili9340_data *) &ili9340_data1; data = (struct ili9340_data *)&ili9340_data1;
gpio_pin_set(data->command_data_gpio, DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, gpio_pin_set(data->command_data_gpio,
ILI9340_CMD_DATA_PIN_COMMAND); DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_COMMAND);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
if (tx_data != NULL) { if (tx_data != NULL) {
tx_buf.buf = tx_data; tx_buf.buf = tx_data;
tx_buf.len = tx_len; tx_buf.len = tx_len;
gpio_pin_set(data->command_data_gpio, gpio_pin_set(data->command_data_gpio,
DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN, DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN,
ILI9340_CMD_DATA_PIN_DATA); ILI9340_CMD_DATA_PIN_DATA);
spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL); spi_transceive(data->spi_dev, &data->spi_config, &tx_bufs, NULL);
} }
} }

View File

@ -52,15 +52,17 @@ struct ili9340_data;
* @param tx_len Number of bytes in tx_data buffer * @param tx_len Number of bytes in tx_data buffer
* *
*/ */
void ili9340_transmit(struct ili9340_data *data, uint8_t cmd, void
void *tx_data, size_t tx_len); ili9340_transmit(struct ili9340_data *data, uint8_t cmd, void *tx_data,
size_t tx_len);
/** /**
* Perform LCD specific initialization * Perform LCD specific initialization
* *
* @param data Device data structure * @param data Device data structure
*/ */
void ili9340_lcd_init(struct ili9340_data *data); void
ili9340_lcd_init(struct ili9340_data *data);
#define DT_ILITEK_ILI9340_0_LABEL "DISPLAY" #define DT_ILITEK_ILI9340_0_LABEL "DISPLAY"
#define CONFIG_DISPLAY_LOG_LEVEL 0 #define CONFIG_DISPLAY_LOG_LEVEL 0

View File

@ -6,7 +6,8 @@
#include "display_ili9340.h" #include "display_ili9340.h"
void ili9340_lcd_init(struct ili9340_data *data) void
ili9340_lcd_init(struct ili9340_data *data)
{ {
uint8_t tx_data[15]; uint8_t tx_data[15];
@ -24,11 +25,11 @@ void ili9340_lcd_init(struct ili9340_data *data)
ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1); ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1);
tx_data[0] = tx_data[0] =
ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR; ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR;
ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1); ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1);
tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT | tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT
ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT; | ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT;
ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1); ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1);
tx_data[0] = 0x00; tx_data[0] = 0x00;

View File

@ -12,10 +12,11 @@
#define MONITOR_HOR_RES 320 #define MONITOR_HOR_RES 320
#define MONITOR_VER_RES 240 #define MONITOR_VER_RES 240
#ifndef MONITOR_ZOOM #ifndef MONITOR_ZOOM
#define MONITOR_ZOOM 1 #define MONITOR_ZOOM 1
#endif #endif
extern int ili9340_init(); extern int
ili9340_init();
static int lcd_initialized = 0; static int lcd_initialized = 0;
@ -32,15 +33,14 @@ display_init(void)
} }
void void
display_flush(wasm_exec_env_t exec_env, display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t y2, lv_color_t *color)
lv_color_t *color)
{ {
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
struct display_buffer_descriptor desc; struct display_buffer_descriptor desc;
if (!wasm_runtime_validate_native_addr(module_inst, if (!wasm_runtime_validate_native_addr(module_inst, color,
color, sizeof(lv_color_t))) sizeof(lv_color_t)))
return; return;
uint16_t w = x2 - x1 + 1; uint16_t w = x2 - x1 + 1;
@ -56,27 +56,23 @@ display_flush(wasm_exec_env_t exec_env,
} }
void void
display_fill(wasm_exec_env_t exec_env, display_fill(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t y2, lv_color_t *color)
lv_color_t *color) {}
{
}
void void
display_map(wasm_exec_env_t exec_env, display_map(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t y2, const lv_color_t *color)
const lv_color_t *color) {}
{
}
bool bool
display_input_read(wasm_exec_env_t exec_env, void *data) display_input_read(wasm_exec_env_t exec_env, void *data)
{ {
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
lv_indev_data_t *lv_data = (lv_indev_data_t*)data; lv_indev_data_t *lv_data = (lv_indev_data_t *)data;
if (!wasm_runtime_validate_native_addr(module_inst, if (!wasm_runtime_validate_native_addr(module_inst, lv_data,
lv_data, sizeof(lv_indev_data_t))) sizeof(lv_indev_data_t)))
return false; return false;
return touchscreen_read(lv_data); return touchscreen_read(lv_data);
@ -84,19 +80,17 @@ display_input_read(wasm_exec_env_t exec_env, void *data)
void void
display_deinit(wasm_exec_env_t exec_env) display_deinit(wasm_exec_env_t exec_env)
{ {}
}
void void
display_vdb_write(wasm_exec_env_t exec_env, display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w,
void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa)
lv_color_t *color, lv_opa_t opa)
{ {
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
uint8_t *buf_xy = (uint8_t*)buf + 3 * x + 3 * y * buf_w; uint8_t *buf_xy = (uint8_t *)buf + 3 * x + 3 * y * buf_w;
if (!wasm_runtime_validate_native_addr(module_inst, if (!wasm_runtime_validate_native_addr(module_inst, color,
color, sizeof(lv_color_t))) sizeof(lv_color_t)))
return; return;
*buf_xy = color->red; *buf_xy = color->red;
@ -109,4 +103,3 @@ time_get_ms(wasm_exec_env_t exec_env)
{ {
return k_uptime_get_32(); return k_uptime_get_32();
} }

View File

@ -20,15 +20,17 @@
#include <drivers/uart.h> #include <drivers/uart.h>
#include <device.h> #include <device.h>
extern void
extern void init_sensor_framework(); init_sensor_framework();
extern void exit_sensor_framework(); extern void
extern int aee_host_msg_callback(void *msg, uint32_t msg_len); exit_sensor_framework();
extern int
aee_host_msg_callback(void *msg, uint32_t msg_len);
int uart_char_cnt = 0; int uart_char_cnt = 0;
static void uart_irq_callback(const struct device *dev, static void
void *user_data) uart_irq_callback(const struct device *dev, void *user_data)
{ {
unsigned char ch; unsigned char ch;
@ -41,7 +43,8 @@ static void uart_irq_callback(const struct device *dev,
const struct device *uart_dev = NULL; const struct device *uart_dev = NULL;
static bool host_init() static bool
host_init()
{ {
uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME); uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME);
if (!uart_dev) { if (!uart_dev) {
@ -53,7 +56,8 @@ static bool host_init()
return true; return true;
} }
int host_send(void * ctx, const char *buf, int size) int
host_send(void *ctx, const char *buf, int size)
{ {
if (!uart_dev) if (!uart_dev)
return 0; return 0;
@ -64,15 +68,17 @@ int host_send(void * ctx, const char *buf, int size)
return size; return size;
} }
void host_destroy() void
{ host_destroy()
} {}
/* clang-format off */
host_interface interface = { host_interface interface = {
.init = host_init, .init = host_init,
.send = host_send, .send = host_send,
.destroy = host_destroy .destroy = host_destroy
}; };
/* clang-format on */
timer_ctx_t timer_ctx; timer_ctx_t timer_ctx;
@ -87,7 +93,8 @@ static NativeSymbol native_symbols[] = {
EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i") EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i")
}; };
int iwasm_main() int
iwasm_main()
{ {
RuntimeInitArgs init_args; RuntimeInitArgs init_args;

View File

@ -10,15 +10,17 @@
#include "bh_log.h" #include "bh_log.h"
#include "wasm_export.h" #include "wasm_export.h"
extern void display_init(void); extern void
extern int iwasm_main(); display_init(void);
extern int
iwasm_main();
void main(void) void
main(void)
{ {
display_init(); display_init();
iwasm_main(); iwasm_main();
for(;;){ for (;;) {
k_sleep(Z_TIMEOUT_MS(1000)); k_sleep(Z_TIMEOUT_MS(1000));
} }
} }

View File

@ -6,21 +6,21 @@
#define __PIN_CONFIG_JLF_H__ #define __PIN_CONFIG_JLF_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2" #define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10*1000 #define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 #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_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 5 #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_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4 #define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4
#define XPT2046_SPI_DEVICE_NAME "SPI_2" #define XPT2046_SPI_DEVICE_NAME "SPI_2"
#define XPT2046_SPI_MAX_FREQUENCY 10*1000 #define XPT2046_SPI_MAX_FREQUENCY 10 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIO_0" #define XPT2046_CS_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_CS_GPIO_PIN 6 #define XPT2046_CS_GPIO_PIN 6
#define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0" #define XPT2046_PEN_GPIO_CONTROLLER "GPIO_0"
#define XPT2046_PEN_GPIO_PIN 7 #define XPT2046_PEN_GPIO_PIN 7
#define HOST_DEVICE_COMM_UART_NAME "UART_1" #define HOST_DEVICE_COMM_UART_NAME "UART_1"
#endif /* __PIN_CONFIG_JLF_H__ */ #endif /* __PIN_CONFIG_JLF_H__ */

View File

@ -6,24 +6,24 @@
#define __PIN_CONFIG_STM32_H__ #define __PIN_CONFIG_STM32_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_1" #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_SPI_MAX_FREQUENCY 24 * 1000 * 1000
#define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1 #define DT_ILITEK_ILI9340_0_BASE_ADDRESS 1
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC" #define DT_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_RESET_GPIOS_PIN 12 #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_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 11 #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_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10 #define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10
#define XPT2046_SPI_DEVICE_NAME "SPI_1" #define XPT2046_SPI_DEVICE_NAME "SPI_1"
#define XPT2046_SPI_MAX_FREQUENCY 12*1000*1000 #define XPT2046_SPI_MAX_FREQUENCY 12 * 1000 * 1000
#define XPT2046_CS_GPIO_CONTROLLER "GPIOD" #define XPT2046_CS_GPIO_CONTROLLER "GPIOD"
#define XPT2046_CS_GPIO_PIN 0 #define XPT2046_CS_GPIO_PIN 0
#define XPT2046_PEN_GPIO_CONTROLLER "GPIOD" #define XPT2046_PEN_GPIO_CONTROLLER "GPIOD"
#define XPT2046_PEN_GPIO_PIN 1 #define XPT2046_PEN_GPIO_PIN 1
#define HOST_DEVICE_COMM_UART_NAME "UART_6" #define HOST_DEVICE_COMM_UART_NAME "UART_6"

View File

@ -11,25 +11,32 @@
#include "lvgl/lv_misc/lv_color.h" #include "lvgl/lv_misc/lv_color.h"
#include "lvgl/lv_hal/lv_hal_indev.h" #include "lvgl/lv_hal/lv_hal_indev.h"
extern void display_init(void); extern void
display_init(void);
extern void display_deinit(void); extern void
display_deinit(void);
extern void display_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, extern void
const lv_color_t * color); 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 bool
display_input_read(lv_indev_data_t *data);
extern void display_vdb_write(void *buf, extern void
lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, 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); lv_color_t *color, lv_opa_t opa);
void display_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, void
const lv_color_t *color); 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, void
const lv_color_t *color); 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); extern uint32_t
time_get_ms(void);
#endif #endif

View File

@ -29,9 +29,10 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void hal_init(void); static void
//static int tick_thread(void * data); hal_init(void);
//static void memory_monitor(void * param); // static int tick_thread(void * data);
// static void memory_monitor(void * param);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@ -48,13 +49,14 @@ uint32_t count = 0;
char count_str[11] = { 0 }; char count_str[11] = { 0 };
lv_obj_t *hello_world_label; lv_obj_t *hello_world_label;
lv_obj_t *count_label; lv_obj_t *count_label;
lv_obj_t * btn1; lv_obj_t *btn1;
lv_obj_t * label_count1; lv_obj_t *label_count1;
int label_count1_value = 0; int label_count1_value = 0;
char label_count1_str[11] = { 0 }; char label_count1_str[11] = { 0 };
void timer1_update(user_timer_t timer1) void
timer1_update(user_timer_t timer1)
{ {
if ((count % 100) == 0) { if ((count % 100) == 0) {
snprintf(count_str, sizeof(count_str), "%d", count / 100); snprintf(count_str, sizeof(count_str), "%d", count / 100);
@ -64,23 +66,23 @@ void timer1_update(user_timer_t timer1)
++count; ++count;
} }
static lv_res_t
static lv_res_t btn_rel_action(lv_obj_t * btn) btn_rel_action(lv_obj_t *btn)
{ {
label_count1_value++; label_count1_value++;
snprintf(label_count1_str, sizeof(label_count1_str), snprintf(label_count1_str, sizeof(label_count1_str), "%d",
"%d", label_count1_value); label_count1_value);
lv_label_set_text(label_count1, label_count1_str); lv_label_set_text(label_count1, label_count1_str);
return LV_RES_OK; return LV_RES_OK;
} }
void
void on_init() on_init()
{ {
/*Initialize LittlevGL*/ /* Initialize LittlevGL */
lv_init(); lv_init();
/*Initialize the HAL (display, input devices, tick) for LittlevGL*/ /* Initialize the HAL (display, input devices, tick) for LittlevGL */
hal_init(); hal_init();
hello_world_label = lv_label_create(lv_scr_act(), NULL); hello_world_label = lv_label_create(lv_scr_act(), NULL);
@ -90,12 +92,17 @@ void on_init()
count_label = lv_label_create(lv_scr_act(), NULL); count_label = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); 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*/ btn1 = lv_btn_create(
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, btn_rel_action); /*Set function to be called when the button is released*/ lv_scr_act(),
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 20); /*Align below the label*/ 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*/ /* Create a label on the button */
lv_obj_t * btn_label = lv_label_create(btn1, NULL); lv_obj_t *btn_label = lv_label_create(btn1, NULL);
lv_label_set_text(btn_label, "Click ++"); lv_label_set_text(btn_label, "Click ++");
label_count1 = lv_label_create(lv_scr_act(), NULL); label_count1 = lv_label_create(lv_scr_act(), NULL);
@ -116,56 +123,67 @@ void on_init()
**********************/ **********************/
/** /**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library * 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, void
const lv_color_t * color_p) 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); display_flush(x1, y1, x2, y2, color_p);
lv_flush_ready(); lv_flush_ready();
} }
void display_vdb_write_wrapper(uint8_t *buf, void
lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, display_vdb_write_wrapper(uint8_t *buf, lv_coord_t buf_w, lv_coord_t x,
lv_color_t color, lv_opa_t opa) lv_coord_t y, lv_color_t color, lv_opa_t opa)
{ {
display_vdb_write(buf, buf_w, x, y, &color, 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, void
lv_color_t color) 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); display_fill(x1, y1, x2, y2, &color);
} }
static void hal_init(void) static void
hal_init(void)
{ {
/* Add a display*/ /* Add a display */
lv_disp_drv_t disp_drv; lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); /*Basic initialization*/ 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_flush =
disp_drv.disp_fill = display_fill_wrapper; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ display_flush_wrapper; /* Used when `LV_VDB_SIZE != 0` in lv_conf.h
disp_drv.disp_map = display_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/ (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 #if LV_VDB_SIZE != 0
disp_drv.vdb_wr = display_vdb_write_wrapper; disp_drv.vdb_wr = display_vdb_write_wrapper;
#endif #endif
lv_disp_drv_register(&disp_drv); lv_disp_drv_register(&disp_drv);
/* Add the mouse as input device /* Add the mouse as input device
* Use the 'mouse' driver which reads the PC's mouse*/ * Use the 'mouse' driver which reads the PC's mouse */
// mouse_init(); // mouse_init();
lv_indev_drv_t indev_drv; lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/ lv_indev_drv_init(&indev_drv); /* Basic initialization */
indev_drv.type = LV_INDEV_TYPE_POINTER; 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*/ indev_drv.read =
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv); 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 */ /* Implement empry main function as wasi start function calls it */
int main(int argc, char **argv) int
main(int argc, char **argv)
{ {
(void)argc; (void)argc;
(void)argv; (void)argv;
return 0; return 0;
} }

View File

@ -5,4 +5,5 @@
#include <stdio.h> #include <stdio.h>
uint32_t time_get_ms(void); uint32_t
time_get_ms(void);

View File

@ -61,7 +61,7 @@ main()
RuntimeInitArgs init_args = { 0 }; RuntimeInitArgs init_args = { 0 };
char error_buf[128] = { 0 }; char error_buf[128] = { 0 };
/* parameters and return values */ /* parameters and return values */
char* args[1] = { 0 }; char *args[1] = { 0 };
uint8 *file_buf = NULL; uint8 *file_buf = NULL;
uint32 file_buf_size = 0; uint32 file_buf_size = 0;
@ -93,17 +93,16 @@ main()
/* load mC and let WAMR load mA and mB */ /* load mC and let WAMR load mA and mB */
printf("- wasm_runtime_load\n"); printf("- wasm_runtime_load\n");
if (!(module = wasm_runtime_load(file_buf, file_buf_size, if (!(module = wasm_runtime_load(file_buf, file_buf_size, error_buf,
error_buf, sizeof(error_buf)))) { sizeof(error_buf)))) {
printf("%s\n", error_buf); printf("%s\n", error_buf);
goto RELEASE_BINARY; goto RELEASE_BINARY;
} }
/* instantiate the module */ /* instantiate the module */
printf("- wasm_runtime_instantiate\n"); printf("- wasm_runtime_instantiate\n");
if (!(module_inst = if (!(module_inst = wasm_runtime_instantiate(
wasm_runtime_instantiate(module, stack_size, heap_size, module, stack_size, heap_size, error_buf, sizeof(error_buf)))) {
error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf); printf("%s\n", error_buf);
goto UNLOAD_MODULE; goto UNLOAD_MODULE;
} }

View File

@ -13,4 +13,3 @@ call_A()
{ {
return A(); return A();
} }

View File

@ -9,7 +9,8 @@
static pthread_mutex_t mutex; static pthread_mutex_t mutex;
static pthread_cond_t cond; static pthread_cond_t cond;
static void *thread(void *arg) static void *
thread(void *arg)
{ {
int *num = (int *)arg; int *num = (int *)arg;
@ -29,7 +30,8 @@ static void *thread(void *arg)
return NULL; return NULL;
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
pthread_t tid; pthread_t tid;
int num = 0, ret = -1; int num = 0, ret = -1;

View File

@ -14,8 +14,7 @@ static char global_heap_buf[10 * 1024 * 1024] = { 0 };
#endif #endif
static int static int
test_write_wrapper(wasm_exec_env_t exec_env, test_write_wrapper(wasm_exec_env_t exec_env, uint32 externref_idx_of_file,
uint32 externref_idx_of_file,
const char *str, int len) const char *str, int len)
{ {
FILE *file; FILE *file;
@ -35,9 +34,11 @@ test_write_wrapper(wasm_exec_env_t exec_env,
return fprintf(file, buf, str); return fprintf(file, buf, str);
} }
/* clang-format off */
static NativeSymbol native_symbols[] = { static NativeSymbol native_symbols[] = {
{ "test_write", test_write_wrapper, "(i*~)i", NULL } { "test_write", test_write_wrapper, "(i*~)i", NULL }
}; };
/* clang-format on */
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -88,7 +89,7 @@ main(int argc, char *argv[])
/* load WASM byte buffer from WASM bin file */ /* load WASM byte buffer from WASM bin file */
if (!(wasm_file_buf = if (!(wasm_file_buf =
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size))) (uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
goto fail1; goto fail1;
/* load WASM module */ /* load WASM module */
@ -100,21 +101,21 @@ main(int argc, char *argv[])
/* instantiate the module */ /* instantiate the module */
if (!(wasm_module_inst = if (!(wasm_module_inst =
wasm_runtime_instantiate(wasm_module, stack_size, heap_size, wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
error_buf, sizeof(error_buf)))) { error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf); printf("%s\n", error_buf);
goto fail3; goto fail3;
} }
/* lookup function instance */ /* lookup function instance */
if (!(func_inst = wasm_runtime_lookup_function(wasm_module_inst, if (!(func_inst =
"test", NULL))) { wasm_runtime_lookup_function(wasm_module_inst, "test", NULL))) {
printf("%s\n", "lookup function test failed"); printf("%s\n", "lookup function test failed");
goto fail4; goto fail4;
} }
if (!(exec_env = if (!(exec_env =
wasm_runtime_create_exec_env(wasm_module_inst, stack_size))) { wasm_runtime_create_exec_env(wasm_module_inst, stack_size))) {
printf("%s\n", "create exec env failed"); printf("%s\n", "create exec env failed");
goto fail4; goto fail4;
} }

View File

@ -45,11 +45,16 @@ static char *uart_device = "/dev/ttyS2";
static int baudrate = B115200; static int baudrate = B115200;
#endif #endif
extern void init_sensor_framework(); extern void
extern void exit_sensor_framework(); init_sensor_framework();
extern void exit_connection_framework(); extern void
extern int aee_host_msg_callback(void *msg, uint32_t msg_len); exit_sensor_framework();
extern bool init_connection_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 #ifndef CONNECTION_UART
int listenfd = -1; int listenfd = -1;
@ -63,7 +68,8 @@ int uartfd = -1;
static bool server_mode = false; static bool server_mode = false;
// Function designed for chat between client and server. // Function designed for chat between client and server.
void* func(void* arg) void *
func(void *arg)
{ {
char buff[MAX]; char buff[MAX];
int n; int n;
@ -77,7 +83,8 @@ void* func(void* arg)
if (sockfd == -1) { if (sockfd == -1) {
printf("socket creation failed...\n"); printf("socket creation failed...\n");
return NULL; return NULL;
} else }
else
printf("Socket successfully created..\n"); printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr)); bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT // assign IP, PORT
@ -86,11 +93,12 @@ void* func(void* arg)
servaddr.sin_port = htons(port); servaddr.sin_port = htons(port);
// connect the client socket to server socket // connect the client socket to server socket
if (connect(sockfd, (SA*) &servaddr, sizeof(servaddr)) != 0) { if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n"); printf("connection with the server failed...\n");
sleep(10); sleep(10);
continue; continue;
} else { }
else {
printf("connected to the server..\n"); printf("connected to the server..\n");
} }
@ -101,7 +109,7 @@ void* func(void* arg)
// read the message from client and copy it in buffer // read the message from client and copy it in buffer
n = read(sockfd, buff, sizeof(buff)); n = read(sockfd, buff, sizeof(buff));
// print buffer which contains the client contents // print buffer which contains the client contents
//fprintf(stderr, "recieved %d bytes from host: %s", n, buff); // fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
// socket disconnected // socket disconnected
if (n <= 0) if (n <= 0)
@ -115,12 +123,14 @@ void* func(void* arg)
close(sockfd); close(sockfd);
} }
static bool host_init() static bool
host_init()
{ {
return true; return true;
} }
int host_send(void * ctx, const char *buf, int size) int
host_send(void *ctx, const char *buf, int size)
{ {
int ret; int ret;
@ -139,7 +149,8 @@ int host_send(void * ctx, const char *buf, int size)
return -1; return -1;
} }
void host_destroy() void
host_destroy()
{ {
if (server_mode) if (server_mode)
close(listenfd); close(listenfd);
@ -149,16 +160,19 @@ void host_destroy()
pthread_mutex_unlock(&sock_lock); pthread_mutex_unlock(&sock_lock);
} }
/* clang-format off */
host_interface interface = { host_interface interface = {
.init = host_init, .init = host_init,
.send = host_send, .send = host_send,
.destroy = host_destroy .destroy = host_destroy
}; };
/* clang-format on */
/* Change it to 1 when fuzzing test */ /* Change it to 1 when fuzzing test */
#define WASM_ENABLE_FUZZ_TEST 0 #define WASM_ENABLE_FUZZ_TEST 0
void* func_server_mode(void* arg) void *
func_server_mode(void *arg)
{ {
int clilent; int clilent;
struct sockaddr_in serv_addr, cli_addr; struct sockaddr_in serv_addr, cli_addr;
@ -178,14 +192,14 @@ void* func_server_mode(void* arg)
} }
/* Initialize socket structure */ /* Initialize socket structure */
bzero((char *) &serv_addr, sizeof(serv_addr)); bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port); serv_addr.sin_port = htons(port);
/* Now bind the host address using bind() call.*/ /* Now bind the host address using bind() call.*/
if (bind(listenfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
perror("ERROR on binding"); perror("ERROR on binding");
exit(1); exit(1);
} }
@ -196,7 +210,7 @@ void* func_server_mode(void* arg)
while (1) { while (1) {
pthread_mutex_lock(&sock_lock); pthread_mutex_lock(&sock_lock);
sockfd = accept(listenfd, (struct sockaddr *) &cli_addr, &clilent); sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent);
pthread_mutex_unlock(&sock_lock); pthread_mutex_unlock(&sock_lock);
@ -228,7 +242,7 @@ void* func_server_mode(void* arg)
} }
#if WASM_ENABLE_FUZZ_TEST != 0 #if WASM_ENABLE_FUZZ_TEST != 0
/* Exit the process when host disconnect. /* Exit the process when host disconnect.
* This is helpful for reproducing failure case. */ This is helpful for reproducing failure case. */
close(sockfd); close(sockfd);
exit(1); exit(1);
#endif #endif
@ -236,7 +250,8 @@ void* func_server_mode(void* arg)
} }
#else #else
static int parse_baudrate(int baud) static int
parse_baudrate(int baud)
{ {
switch (baud) { switch (baud) {
case 9600: case 9600:
@ -279,7 +294,8 @@ static int parse_baudrate(int baud)
return -1; return -1;
} }
} }
static bool uart_init(const char *device, int baudrate, int *fd) static bool
uart_init(const char *device, int baudrate, int *fd)
{ {
int uart_fd; int uart_fd;
struct termios uart_term; struct termios uart_term;
@ -310,7 +326,8 @@ static bool uart_init(const char *device, int baudrate, int *fd)
return true; return true;
} }
static void *func_uart_mode(void *arg) static void *
func_uart_mode(void *arg)
{ {
int n; int n;
char buff[MAX]; char buff[MAX];
@ -337,7 +354,8 @@ static void *func_uart_mode(void *arg)
return NULL; return NULL;
} }
static int uart_send(void * ctx, const char *buf, int size) static int
uart_send(void *ctx, const char *buf, int size)
{ {
int ret; int ret;
@ -346,23 +364,28 @@ static int uart_send(void * ctx, const char *buf, int size)
return ret; return ret;
} }
static void uart_destroy() static void
uart_destroy()
{ {
close(uartfd); close(uartfd);
} }
static host_interface interface = { .send = uart_send, .destroy = uart_destroy }; /* clang-format off */
static host_interface interface = {
.send = uart_send,
.destroy = uart_destroy
};
/* clang-format on */
#endif #endif
static attr_container_t *
read_test_sensor(void *sensor)
static attr_container_t * read_test_sensor(void * sensor)
{ {
//luc: for test
attr_container_t *attr_obj = attr_container_create("read test sensor data"); attr_container_t *attr_obj = attr_container_create("read test sensor data");
if (attr_obj) { if (attr_obj) {
bool ret = attr_container_set_string(&attr_obj, "name", "read test sensor"); bool ret =
attr_container_set_string(&attr_obj, "name", "read test sensor");
if (!ret) { if (!ret) {
attr_container_destroy(attr_obj); attr_container_destroy(attr_obj);
return NULL; return NULL;
@ -372,15 +395,17 @@ static attr_container_t * read_test_sensor(void * sensor)
return NULL; return NULL;
} }
static bool config_test_sensor(void * s, void * config) static bool
config_test_sensor(void *s, void *config)
{ {
return false; return false;
} }
static char global_heap_buf[1024 * 1024] = { 0 }; static char global_heap_buf[1024 * 1024] = { 0 };
static void showUsage() /* clang-format off */
static void
showUsage()
{ {
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
printf("Usage:\n"); printf("Usage:\n");
@ -401,8 +426,10 @@ static void showUsage()
printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n"); printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n");
#endif #endif
} }
/* clang-format on */
static bool parse_args(int argc, char *argv[]) static bool
parse_args(int argc, char *argv[])
{ {
int c; int c;
@ -410,14 +437,14 @@ static bool parse_args(int argc, char *argv[])
int optIndex = 0; int optIndex = 0;
static struct option longOpts[] = { static struct option longOpts[] = {
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
{ "server_mode", no_argument, NULL, 's' }, { "server_mode", no_argument, NULL, 's' },
{ "host_address", required_argument, NULL, 'a' }, { "host_address", required_argument, NULL, 'a' },
{ "port", required_argument, NULL, 'p' }, { "port", required_argument, NULL, 'p' },
#else #else
{ "uart", required_argument, NULL, 'u' }, { "uart", required_argument, NULL, 'u' },
{ "baudrate", required_argument, NULL, 'b' }, { "baudrate", required_argument, NULL, 'b' },
#endif #endif
{ "help", required_argument, NULL, 'h' }, { "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@ -461,7 +488,8 @@ static bool parse_args(int argc, char *argv[])
} }
// Driver function // Driver function
int iwasm_main(int argc, char *argv[]) int
iwasm_main(int argc, char *argv[])
{ {
RuntimeInitArgs init_args; RuntimeInitArgs init_args;
korp_tid tid; korp_tid tid;
@ -499,22 +527,19 @@ int iwasm_main(int argc, char *argv[])
/* sensor framework */ /* sensor framework */
init_sensor_framework(); init_sensor_framework();
// add the sys sensor objects // add the sys sensor objects
add_sys_sensor("sensor_test", add_sys_sensor("sensor_test", "This is a sensor for test", 0, 1000,
"This is a sensor for test", read_test_sensor, config_test_sensor);
0,
1000,
read_test_sensor,
config_test_sensor);
start_sensor_framework(); start_sensor_framework();
#ifndef CONNECTION_UART #ifndef CONNECTION_UART
if (server_mode) if (server_mode)
os_thread_create(&tid, func_server_mode, NULL, os_thread_create(&tid, func_server_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE); BH_APPLET_PRESERVED_STACK_SIZE);
else else
os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE); os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
#else #else
os_thread_create(&tid, func_uart_mode, NULL, BH_APPLET_PRESERVED_STACK_SIZE); os_thread_create(&tid, func_uart_mode, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
#endif #endif
app_manager_startup(&interface); app_manager_startup(&interface);

View File

@ -3,8 +3,11 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/ */
extern void iwasm_main(); extern void
int main(int argc, char *argv[]) iwasm_main();
int
main(int argc, char *argv[])
{ {
iwasm_main(argc, argv); iwasm_main(argc, argv);
return 0; return 0;

View File

@ -13,33 +13,35 @@ static int num = 0;
static user_timer_t g_timer; static user_timer_t g_timer;
static connection_t *g_conn = NULL; static connection_t *g_conn = NULL;
void on_data1(connection_t *conn, void
conn_event_type_t type, on_data1(connection_t *conn, conn_event_type_t type, const char *data,
const char *data, uint32 len, void *user_data)
uint32 len,
void *user_data)
{ {
if (type == CONN_EVENT_TYPE_DATA) { if (type == CONN_EVENT_TYPE_DATA) {
char message[64] = {0}; char message[64] = { 0 };
memcpy(message, data, len); memcpy(message, data, len);
printf("Client got a message from server -> %s\n", message); printf("Client got a message from server -> %s\n", message);
} else if (type == CONN_EVENT_TYPE_DISCONNECT) { }
else if (type == CONN_EVENT_TYPE_DISCONNECT) {
printf("connection is close by server!\n"); printf("connection is close by server!\n");
} else { }
else {
printf("error: got unknown event type!!!\n"); printf("error: got unknown event type!!!\n");
} }
} }
/* Timer callback */ /* Timer callback */
void timer1_update(user_timer_t timer) void
timer1_update(user_timer_t timer)
{ {
char message[64] = {0}; char message[64] = { 0 };
/* Reply to server */ /* Reply to server */
snprintf(message, sizeof(message), "Hello %d", num++); snprintf(message, sizeof(message), "Hello %d", num++);
api_send_on_connection(g_conn, message, strlen(message)); api_send_on_connection(g_conn, message, strlen(message));
} }
void my_close_handler(request_t * request) void
my_close_handler(request_t *request)
{ {
response_t response[1]; response_t response[1];
@ -53,7 +55,8 @@ void my_close_handler(request_t * request)
api_response_send(response); api_response_send(response);
} }
void on_init() void
on_init()
{ {
user_timer_t timer; user_timer_t timer;
attr_container_t *args; attr_container_t *args;
@ -78,7 +81,8 @@ void on_init()
api_timer_restart(timer, 1000); api_timer_restart(timer, 1000);
} }
void on_destroy() void
on_destroy()
{ {
/* real destroy work including killing timer and closing sensor is /* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */ accomplished in wasm app library version of on_destroy() */

View File

@ -9,7 +9,8 @@
int num = 0; int num = 0;
void publish_overheat_event() void
publish_overheat_event()
{ {
attr_container_t *event; attr_container_t *event;
@ -17,18 +18,20 @@ void publish_overheat_event()
attr_container_set_string(&event, "warning", "temperature is over high"); attr_container_set_string(&event, "warning", "temperature is over high");
api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event, api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
attr_container_get_serialize_length(event)); attr_container_get_serialize_length(event));
attr_container_destroy(event); attr_container_destroy(event);
} }
/* Timer callback */ /* Timer callback */
void timer1_update(user_timer_t timer) void
timer1_update(user_timer_t timer)
{ {
publish_overheat_event(); publish_overheat_event();
} }
void start_timer() void
start_timer()
{ {
user_timer_t timer; user_timer_t timer;
@ -37,12 +40,15 @@ void start_timer()
api_timer_restart(timer, 1000); api_timer_restart(timer, 1000);
} }
void on_init() void
on_init()
{ {
start_timer(); start_timer();
} }
void on_destroy() void
on_destroy()
{ {
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */ /* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
} }

View File

@ -6,20 +6,23 @@
#include "wasm_app.h" #include "wasm_app.h"
#include "wa-inc/request.h" #include "wa-inc/request.h"
void over_heat_event_handler(request_t *request) void
over_heat_event_handler(request_t *request)
{ {
printf("### user over heat event handler called\n"); printf("### user over heat event handler called\n");
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER) if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *) request->payload); attr_container_dump((attr_container_t *)request->payload);
} }
void on_init() void
on_init()
{ {
api_subscribe_event("alert/overheat", over_heat_event_handler); api_subscribe_event("alert/overheat", over_heat_event_handler);
} }
void on_destroy() void
on_destroy()
{ {
/* real destroy work including killing timer and closing sensor is /* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */ accomplished in wasm app library version of on_destroy() */

View File

@ -6,7 +6,8 @@
#include "wasm_app.h" #include "wasm_app.h"
#include "wa-inc/request.h" #include "wa-inc/request.h"
static void url1_request_handler(request_t *request) static void
url1_request_handler(request_t *request)
{ {
response_t response[1]; response_t response[1];
attr_container_t *payload; attr_container_t *payload;
@ -14,7 +15,7 @@ static void url1_request_handler(request_t *request)
printf("[resp] ### user resource 1 handler called\n"); printf("[resp] ### user resource 1 handler called\n");
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER) if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *) request->payload); attr_container_dump((attr_container_t *)request->payload);
payload = attr_container_create("wasm app response payload"); payload = attr_container_create("wasm app response payload");
if (payload == NULL) if (payload == NULL)
@ -24,16 +25,15 @@ static void url1_request_handler(request_t *request)
attr_container_set_string(&payload, "key2", "value2"); attr_container_set_string(&payload, "key2", "value2");
make_response_for_request(request, response); make_response_for_request(request, response);
set_response(response, CONTENT_2_05, set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, (void *)payload,
FMT_ATTR_CONTAINER,
(void *)payload,
attr_container_get_serialize_length(payload)); attr_container_get_serialize_length(payload));
api_response_send(response); api_response_send(response);
attr_container_destroy(payload); attr_container_destroy(payload);
} }
static void url2_request_handler(request_t *request) static void
url2_request_handler(request_t *request)
{ {
response_t response[1]; response_t response[1];
make_response_for_request(request, response); make_response_for_request(request, response);
@ -43,14 +43,16 @@ static void url2_request_handler(request_t *request)
printf("### user resource 2 handler called\n"); printf("### user resource 2 handler called\n");
} }
void on_init() void
on_init()
{ {
/* register resource uri */ /* register resource uri */
api_register_resource_handler("/url1", url1_request_handler); api_register_resource_handler("/url1", url1_request_handler);
api_register_resource_handler("/url2", url2_request_handler); api_register_resource_handler("/url2", url2_request_handler);
} }
void on_destroy() void
on_destroy()
{ {
/* real destroy work including killing timer and closing sensor is /* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */ accomplished in wasm app library version of on_destroy() */

View File

@ -6,28 +6,30 @@
#include "wasm_app.h" #include "wasm_app.h"
#include "wa-inc/request.h" #include "wa-inc/request.h"
static void my_response_handler(response_t *response, void *user_data) static void
my_response_handler(response_t *response, void *user_data)
{ {
char *tag = (char *) user_data; char *tag = (char *)user_data;
if (response == NULL) { if (response == NULL) {
printf("[req] request timeout!\n"); printf("[req] request timeout!\n");
return; return;
} }
printf("[req] response handler called mid:%d, status:%d, fmt:%d, payload:%p, len:%d, tag:%s\n", 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->mid, response->status, response->fmt, response->payload,
response->payload_len, tag); response->payload_len, tag);
if (response->payload != NULL if (response->payload != NULL && response->payload_len > 0
&& response->payload_len > 0
&& response->fmt == FMT_ATTR_CONTAINER) { && response->fmt == FMT_ATTR_CONTAINER) {
printf("[req] dump the response payload:\n"); printf("[req] dump the response payload:\n");
attr_container_dump((attr_container_t *) response->payload); attr_container_dump((attr_container_t *)response->payload);
} }
} }
static void test_send_request(char *url, char *tag) static void
test_send_request(char *url, char *tag)
{ {
request_t request[1]; request_t request[1];
@ -35,13 +37,15 @@ static void test_send_request(char *url, char *tag)
api_send_request(request, my_response_handler, tag); api_send_request(request, my_response_handler, tag);
} }
void on_init() void
on_init()
{ {
test_send_request("/app/request_handler/url1", "a request to target app"); test_send_request("/app/request_handler/url1", "a request to target app");
test_send_request("url1", "a general request"); test_send_request("url1", "a general request");
} }
void on_destroy() void
on_destroy()
{ {
/* real destroy work including killing timer and closing sensor is /* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */ accomplished in wasm app library version of on_destroy() */

View File

@ -9,14 +9,15 @@
static sensor_t sensor = NULL; static sensor_t sensor = NULL;
/* Sensor event callback*/ /* Sensor event callback*/
void sensor_event_handler(sensor_t sensor, attr_container_t *event, void
void *user_data) sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data)
{ {
printf("### app get sensor event\n"); printf("### app get sensor event\n");
attr_container_dump(event); attr_container_dump(event);
} }
void on_init() void
on_init()
{ {
char *user_data; char *user_data;
attr_container_t *config; attr_container_t *config;
@ -39,7 +40,8 @@ void on_init()
*/ */
} }
void on_destroy() void
on_destroy()
{ {
if (NULL != sensor) { if (NULL != sensor) {
sensor_config(sensor, 0, 0, 0); sensor_config(sensor, 0, 0, 0);

View File

@ -10,12 +10,14 @@
static int num = 0; static int num = 0;
/* Timer callback */ /* Timer callback */
void timer1_update(user_timer_t timer) void
timer1_update(user_timer_t timer)
{ {
printf("Timer update %d\n", num++); printf("Timer update %d\n", num++);
} }
void on_init() void
on_init()
{ {
user_timer_t timer; user_timer_t timer;
@ -24,7 +26,8 @@ void on_init()
api_timer_restart(timer, 1000); api_timer_restart(timer, 1000);
} }
void on_destroy() void
on_destroy()
{ {
/* real destroy work including killing timer and closing sensor is /* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */ accomplished in wasm app library version of on_destroy() */

View File

@ -15,7 +15,8 @@ typedef struct ThreadArgs {
int length; int length;
} ThreadArgs; } ThreadArgs;
void *thread(void* arg) void *
thread(void *arg)
{ {
ThreadArgs *thread_arg = (ThreadArgs *)arg; ThreadArgs *thread_arg = (ThreadArgs *)arg;
wasm_exec_env_t exec_env = thread_arg->exec_env; wasm_exec_env_t exec_env = thread_arg->exec_env;
@ -48,7 +49,8 @@ void *thread(void* arg)
return (void *)(uintptr_t)argv[0]; return (void *)(uintptr_t)argv[0];
} }
void *wamr_thread_cb(wasm_exec_env_t exec_env, void *arg) void *
wamr_thread_cb(wasm_exec_env_t exec_env, void *arg)
{ {
ThreadArgs *thread_arg = (ThreadArgs *)arg; ThreadArgs *thread_arg = (ThreadArgs *)arg;
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
@ -72,7 +74,8 @@ void *wamr_thread_cb(wasm_exec_env_t exec_env, void *arg)
return (void *)(uintptr_t)argv[0]; return (void *)(uintptr_t)argv[0];
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
char *wasm_file = "wasm-apps/test.wasm"; char *wasm_file = "wasm-apps/test.wasm";
uint8 *wasm_file_buf = NULL; uint8 *wasm_file_buf = NULL;
@ -105,7 +108,7 @@ int main(int argc, char *argv[])
/* load WASM byte buffer from WASM bin file */ /* load WASM byte buffer from WASM bin file */
if (!(wasm_file_buf = if (!(wasm_file_buf =
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size))) (uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
goto fail1; goto fail1;
/* load WASM module */ /* load WASM module */
@ -117,15 +120,15 @@ int main(int argc, char *argv[])
/* instantiate the module */ /* instantiate the module */
if (!(wasm_module_inst = if (!(wasm_module_inst =
wasm_runtime_instantiate(wasm_module, stack_size, heap_size, wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
error_buf, sizeof(error_buf)))) { error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf); printf("%s\n", error_buf);
goto fail3; goto fail3;
} }
/* Create the first exec_env */ /* Create the first exec_env */
if (!(exec_env = if (!(exec_env =
wasm_runtime_create_exec_env(wasm_module_inst, stack_size))) { wasm_runtime_create_exec_env(wasm_module_inst, stack_size))) {
printf("failed to create exec_env\n"); printf("failed to create exec_env\n");
goto fail4; goto fail4;
} }
@ -198,8 +201,9 @@ int main(int argc, char *argv[])
thread_arg[i].length = 10; thread_arg[i].length = 10;
/* No need to spawn exec_env manually */ /* No need to spawn exec_env manually */
if (0 != wasm_runtime_spawn_thread(exec_env, &wasm_tid[i], if (0
wamr_thread_cb, &thread_arg[i])) { != wasm_runtime_spawn_thread(exec_env, &wasm_tid[i], wamr_thread_cb,
&thread_arg[i])) {
printf("failed to spawn thread.\n"); printf("failed to spawn thread.\n");
break; break;
} }
@ -210,7 +214,7 @@ int main(int argc, char *argv[])
sum = 0; sum = 0;
memset(result, 0, sizeof(uint32) * THREAD_NUM); memset(result, 0, sizeof(uint32) * THREAD_NUM);
for (i = 0; i < threads_created; i++) { for (i = 0; i < threads_created; i++) {
wasm_runtime_join_thread(wasm_tid[i], (void**)&result[i]); wasm_runtime_join_thread(wasm_tid[i], (void **)&result[i]);
sum += result[i]; sum += result[i];
/* No need to destroy the spawned exec_env */ /* No need to destroy the spawned exec_env */
} }

View File

@ -3,7 +3,8 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/ */
int sum(int start, int length) int
sum(int start, int length)
{ {
int sum = 0, i; int sum = 0, i;