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
58 changed files with 1261 additions and 957 deletions

View File

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

View File

@ -5,18 +5,21 @@
#include <stdlib.h>
#include <sys/time.h>
extern int
iwasm_main(int argc, char *argv[]);
extern int iwasm_main(int argc, char *argv[]);
int main(int argc, char *argv[])
int
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;
gettimeofday(&tv, NULL);
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
*/
*/
/*********************
* INCLUDES
*********************/
@ -30,7 +30,8 @@
/**********************
* STATIC PROTOTYPES
**********************/
static void xpt2046_corr(int16_t * x, int16_t * y);
static void
xpt2046_corr(int16_t *x, int16_t *y);
#if 0
static void xpt2046_avg(int16_t * x, int16_t * y);
#endif
@ -63,17 +64,19 @@ lv_indev_data_t touch_point;
lv_indev_data_t last_touch_point;
#define TOUCH_READ_THREAD_STACK_SIZE 4096
static K_THREAD_STACK_DEFINE(touch_read_thread_stack, TOUCH_READ_THREAD_STACK_SIZE);
static K_THREAD_STACK_DEFINE(touch_read_thread_stack,
TOUCH_READ_THREAD_STACK_SIZE);
static struct k_thread touch_thread_data;
static struct k_sem sem_touch_read;
K_MUTEX_DEFINE( spi_display_touch_mutex);
K_MUTEX_DEFINE(spi_display_touch_mutex);
int cnt = 0;
int touch_read_times = 0;
int last_pen_interrupt_time = 0;
void xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
u32_t pins)
void
xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
u32_t pins)
{
cnt++;
if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) {
@ -81,10 +84,10 @@ void xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb,
touch_read_times++;
last_pen_interrupt_time = k_uptime_get_32();
}
}
void disable_pen_interrupt()
void
disable_pen_interrupt()
{
int ret = 0;
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");
}
}
void enable_pen_interrupt()
void
enable_pen_interrupt()
{
int ret = 0;
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;
bool ret = false;
@ -118,12 +123,11 @@ void touch_screen_read_thread()
ret = xpt2046_read(&touch_point);
if (ret) {
if ((abs(last_touch_point.point.x - touch_point.point.x) < 4)
&& (abs(last_touch_point.point.y - touch_point.point.y)
< 4)) {
&& (abs(last_touch_point.point.y - touch_point.point.y)
< 4)) {
break;
}
last_touch_point = touch_point;
}
}
enable_pen_interrupt();
@ -131,7 +135,8 @@ void touch_screen_read_thread()
}
}
void xpt2046_init(void)
void
xpt2046_init(void)
{
int ret;
input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME);
@ -140,7 +145,7 @@ void xpt2046_init(void)
printf("device not found. Aborting test.");
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.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8);
@ -171,8 +176,7 @@ void xpt2046_init(void)
/* Setup GPIO input */
ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN,
(GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE
| GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE)
);
| GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE));
if (ret) {
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,
TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread,
NULL, NULL, NULL, 5,
0, K_NO_WAIT);
NULL, NULL, NULL, 5, 0, K_NO_WAIT);
printf("xpt2046_init ok \n");
}
@ -204,7 +207,8 @@ void xpt2046_init(void)
* @param data store the read data here
* @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_y = 0;
@ -258,7 +262,8 @@ bool xpt2046_read(lv_indev_data_t * data)
/**********************
* 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
int16_t swap_tmp;
@ -278,10 +283,10 @@ static void xpt2046_corr(int16_t * x, int16_t * y)
(*y) = 0;
(*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)
/ (XPT2046_Y_MAX - XPT2046_Y_MIN);
/ (XPT2046_Y_MAX - XPT2046_Y_MIN);
#if XPT2046_X_INV != 0
(*x) = XPT2046_HOR_RES - (*x);
@ -290,7 +295,6 @@ static void xpt2046_corr(int16_t * x, int16_t * y)
#if XPT2046_Y_INV != 0
(*y) = XPT2046_VER_RES - (*y);
#endif
}
#if 0
@ -323,7 +327,8 @@ static void xpt2046_avg(int16_t * x, int16_t * y)
}
#endif
bool touchscreen_read(lv_indev_data_t * data)
bool
touchscreen_read(lv_indev_data_t *data)
{
/*Store the collected data*/
data->point.x = last_touch_point.point.x;

View File

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

View File

@ -28,9 +28,11 @@ extern "C" {
#endif
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_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 {
@ -142,8 +144,9 @@ typedef int (*display_blanking_off_api)(const struct device *dev);
* See display_write() for argument description
*/
typedef int (*display_write_api)(const struct device *dev, const u16_t x,
const u16_t y, const struct display_buffer_descriptor *desc,
const void *buf);
const u16_t y,
const struct display_buffer_descriptor *desc,
const void *buf);
/**
* @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
*/
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
@ -166,7 +171,7 @@ typedef void *(*display_get_framebuffer_api)(const struct device *dev);
* See display_set_brightness() for argument description
*/
typedef int (*display_set_brightness_api)(const struct device *dev,
const u8_t brightness);
const u8_t brightness);
/**
* @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
*/
typedef int (*display_set_contrast_api)(const struct device *dev,
const u8_t contrast);
const u8_t contrast);
/**
* @typedef display_get_capabilities_api
* @brief Callback API to get display capabilities
* See display_get_capabilities() for argument description
*/
typedef void (*display_get_capabilities_api)(const struct device *dev,
struct display_capabilities * capabilities);
typedef void (*display_get_capabilities_api)(
const struct device *dev, struct display_capabilities *capabilities);
/**
* @typedef display_set_pixel_format_api
* @brief Callback API to set pixel format used by the display
* See display_set_pixel_format() for argument description
*/
typedef int (*display_set_pixel_format_api)(const struct device *dev,
const enum display_pixel_format pixel_format);
typedef int (*display_set_pixel_format_api)(
const struct device *dev, const enum display_pixel_format pixel_format);
/**
* @typedef display_set_orientation_api
* @brief Callback API to set orientation used by the display
* See display_set_orientation() for argument description
*/
typedef int (*display_set_orientation_api)(const struct device *dev,
const enum display_orientation orientation);
typedef int (*display_set_orientation_api)(
const struct device *dev, const enum display_orientation orientation);
/**
* @brief Display driver API
@ -229,9 +234,9 @@ extern struct display_driver_api ili9340_api1;
*
* @retval 0 on success else negative errno code.
*/
static inline int display_write(const struct device *dev, const u16_t x,
const u16_t y, const struct display_buffer_descriptor *desc,
const void *buf)
static inline int
display_write(const struct device *dev, const u16_t x, const u16_t y,
const struct display_buffer_descriptor *desc, const void *buf)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
@ -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.
*/
static inline int display_read(const struct device *dev, const u16_t x,
const u16_t y, const struct display_buffer_descriptor *desc, void *buf)
static inline int
display_read(const struct device *dev, const u16_t x, const u16_t y,
const struct display_buffer_descriptor *desc, void *buf)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
@ -268,7 +274,8 @@ static inline int display_read(const struct device *dev, const u16_t x,
* 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 *)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.
*/
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 *)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.
*/
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 *)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.
*/
static inline int display_set_brightness(const struct device *dev,
u8_t brightness)
static inline int
display_set_brightness(const struct device *dev, u8_t brightness)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
@ -337,7 +346,8 @@ static inline int display_set_brightness(const struct device *dev,
*
* @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 *)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 capabilities Pointer to capabilities structure to populate
*/
static inline void display_get_capabilities(const struct device *dev,
struct display_capabilities * capabilities)
static inline void
display_get_capabilities(const struct device *dev,
struct display_capabilities *capabilities)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
@ -368,8 +379,9 @@ static inline void display_get_capabilities(const struct device *dev,
*
* @retval 0 on success else negative errno code.
*/
static inline int display_set_pixel_format(const struct device *dev,
const enum display_pixel_format pixel_format)
static inline int
display_set_pixel_format(const struct device *dev,
const enum display_pixel_format pixel_format)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;
@ -385,8 +397,9 @@ static inline int display_set_pixel_format(const struct device *dev,
*
* @retval 0 on success else negative errno code.
*/
static inline int display_set_orientation(const struct device *dev,
const enum display_orientation orientation)
static inline int
display_set_orientation(const struct device *dev,
const enum display_orientation orientation)
{
struct display_driver_api *api = &ili9340_api1;
//(struct display_driver_api *)dev->driver_api;

View File

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

View File

@ -6,7 +6,8 @@
#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];
@ -24,11 +25,11 @@ void ili9340_lcd_init(struct ili9340_data *data)
ili9340_transmit(data, ILI9340_CMD_VCOM_CTRL_2, tx_data, 1);
tx_data[0] =
ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR;
ILI9340_DATA_MEM_ACCESS_CTRL_MV | ILI9340_DATA_MEM_ACCESS_CTRL_BGR;
ili9340_transmit(data, ILI9340_CMD_MEM_ACCESS_CTRL, tx_data, 1);
tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT |
ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT;
tx_data[0] = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT
| ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT;
ili9340_transmit(data, ILI9340_CMD_PIXEL_FORMAT_SET, tx_data, 1);
tx_data[0] = 0x00;

View File

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

View File

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

View File

@ -6,21 +6,21 @@
#define __PIN_CONFIG_JLF_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_2"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 10*1000
#define DT_ILITEK_ILI9340_0_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_PIN 5
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER "GPIO_0"
#define DT_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN 4
#define XPT2046_SPI_DEVICE_NAME "SPI_2"
#define XPT2046_SPI_MAX_FREQUENCY 10*1000
#define XPT2046_SPI_MAX_FREQUENCY 10 * 1000
#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_PIN 7
#define XPT2046_PEN_GPIO_PIN 7
#define HOST_DEVICE_COMM_UART_NAME "UART_1"
#endif /* __PIN_CONFIG_JLF_H__ */

View File

@ -6,24 +6,24 @@
#define __PIN_CONFIG_STM32_H__
#define DT_ILITEK_ILI9340_0_BUS_NAME "SPI_1"
#define DT_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY 24*1000*1000
#define DT_ILITEK_ILI9340_0_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_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_PIN 11
#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_CONTROLLER "GPIOC"
#define DT_ILITEK_ILI9340_0_CS_GPIO_PIN 10
#define XPT2046_SPI_DEVICE_NAME "SPI_1"
#define XPT2046_SPI_MAX_FREQUENCY 12*1000*1000
#define XPT2046_SPI_MAX_FREQUENCY 12 * 1000 * 1000
#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_PIN 1
#define XPT2046_PEN_GPIO_PIN 1
#define HOST_DEVICE_COMM_UART_NAME "UART_6"