Logger, spi driver
This commit is contained in:
parent
8d04034926
commit
7d14d10923
|
@ -8,6 +8,7 @@ set(C_SOURCES
|
|||
"src/drivers/user_config_driver.c"
|
||||
"src/impl/user_lvgl_impl.c"
|
||||
"src/tasks/user_lvgl_task.c"
|
||||
"src/utils/user_log_util.c"
|
||||
)
|
||||
|
||||
set(C_INCLUDES
|
||||
|
@ -35,4 +36,5 @@ add_subdirectory(lib)
|
|||
add_executable(${CMAKE_PROJECT_NAME} ${C_SOURCES})
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} ${C_LIBRARIES})
|
||||
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE ${C_DEFINES})
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${C_INCLUDES})
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${C_INCLUDES})
|
||||
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE "-pthread")
|
|
@ -12,4 +12,7 @@ typedef struct {
|
|||
config_t libconfig_cfg;
|
||||
} user_config_t;
|
||||
|
||||
user_config_ret_t user_config_init(user_config_t *config, char *config_file);
|
||||
user_config_ret_t user_config_deinit(user_config_t *config);
|
||||
|
||||
#endif
|
|
@ -3,13 +3,15 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
USER_SPI_OK,
|
||||
USER_SPI_ERROR
|
||||
} user_spi_ret_t;
|
||||
typedef enum { USER_SPI_OK, USER_SPI_ERROR } user_spi_ret_t;
|
||||
|
||||
typedef struct {
|
||||
int spidev_fd;
|
||||
} user_spi_driver_t;
|
||||
|
||||
user_spi_ret_t user_spi_driver_init(user_spi_driver_t *spi, char *path);
|
||||
user_spi_ret_t user_spi_driver_deinit(user_spi_driver_t *spi);
|
||||
user_spi_ret_t user_spi_driver_xfer(user_spi_driver_t *spi, uint8_t *tx_buf,
|
||||
uint8_t rx_buf, uint32_t len);
|
||||
|
||||
#endif
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
/* Swap the 2 bytes of RGB565 color.
|
||||
* Useful if the display has a 8 bit interface (e.g. SPI)*/
|
||||
#define LV_COLOR_16_SWAP 0
|
||||
#define LV_COLOR_16_SWAP 1
|
||||
|
||||
/* 1: Enable screen transparency.
|
||||
* Useful for OSD or other overlapping GUIs.
|
||||
|
@ -77,7 +77,7 @@ typedef int16_t lv_coord_t;
|
|||
* The graphical objects and other related data are stored here. */
|
||||
|
||||
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
|
||||
#define LV_MEM_CUSTOM 0
|
||||
#define LV_MEM_CUSTOM 1
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
|
||||
# define LV_MEM_SIZE (32U * 1024U)
|
||||
|
@ -99,7 +99,7 @@ typedef int16_t lv_coord_t;
|
|||
|
||||
/* Use the standard memcpy and memset instead of LVGL's own functions.
|
||||
* The standard functions might or might not be faster depending on their implementation. */
|
||||
#define LV_MEMCPY_MEMSET_STD 0
|
||||
#define LV_MEMCPY_MEMSET_STD 1
|
||||
|
||||
/* Garbage Collector settings
|
||||
* Used if lvgl is binded to higher level language and the memory is managed by that language */
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef __USER_LOG_UTIL_H
|
||||
#define __USER_LOG_UTIL_H
|
||||
|
||||
typedef enum {
|
||||
USER_LOG_DEBUG = 1,
|
||||
USER_LOG_INFO,
|
||||
USER_LOG_WARN,
|
||||
USER_LOG_ERROR,
|
||||
USER_LOG_FATAL
|
||||
} user_log_level_t;
|
||||
|
||||
#define USER_LOG(level, fmt, ...) user_log_print(level, "["__FILE__ ":%d] " fmt, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
void user_log_print(user_log_level_t level, char *fmt, ...);
|
||||
|
||||
#endif
|
|
@ -16,4 +16,4 @@ set(ST7789_LCD_SOURCES
|
|||
"st7789_lcd/st7789_lcd.c"
|
||||
)
|
||||
|
||||
add_library(st7789 STATIC ${ST7789_LCD_SOURCES})
|
||||
add_library(st7789 STATIC ${ST7789_LCD_SOURCES})
|
||||
|
|
|
@ -16,7 +16,7 @@ agent: {
|
|||
dc_pin: {
|
||||
path = "/dev/gpiochip1";
|
||||
line = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
|
@ -1,9 +1,14 @@
|
|||
#include "utils/user_log_util.h"
|
||||
|
||||
#include "drivers/user_config_driver.h"
|
||||
|
||||
user_config_ret_t user_config_init(user_config_t *config, char *config_file) {
|
||||
USER_LOG(USER_LOG_INFO, "Config init.");
|
||||
|
||||
config_init(&config->libconfig_cfg);
|
||||
|
||||
if(!config_read_file(&config->libconfig_cfg, config_file)) {
|
||||
USER_LOG(USER_LOG_ERROR, "Failed to read config file %s.", config_file);
|
||||
return USER_CONFIG_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,35 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "drivers/user_config_driver.h"
|
||||
#include "utils/user_log_util.h"
|
||||
|
||||
#include "drivers/user_spi_driver.h"
|
||||
|
||||
user_spi_ret_t user_spi_driver_init(user_spi_driver_t *spi) {
|
||||
|
||||
user_spi_ret_t user_spi_driver_init(user_spi_driver_t *spi, char *path) {
|
||||
USER_LOG(USER_LOG_INFO, "SPI driver init.");
|
||||
|
||||
spi->spidev_fd = open(path, O_RDWR);
|
||||
if(spi->spidev_fd < 0) {
|
||||
USER_LOG(USER_LOG_ERROR, "Failed to open spidev device, %s",
|
||||
strerror(errno));
|
||||
|
||||
return USER_SPI_ERROR;
|
||||
}
|
||||
|
||||
return USER_SPI_OK;
|
||||
}
|
||||
|
||||
user_spi_ret_t user_spi_driver_deinit(user_spi_driver_t *spi) {
|
||||
USER_LOG(USER_LOG_INFO, "SPI driver deinit.");
|
||||
|
||||
close(spi->spidev_fd);
|
||||
}
|
||||
|
||||
user_spi_ret_t user_spi_driver_xfer(user_spi_driver_t *spi, uint8_t * tx_buf, uint8_t rx_buf, uint32_t len) {
|
||||
user_spi_ret_t user_spi_driver_xfer(user_spi_driver_t *spi, uint8_t *tx_buf,
|
||||
uint8_t rx_buf, uint32_t len) {
|
||||
//
|
||||
}
|
35
src/main.c
35
src/main.c
|
@ -5,15 +5,50 @@
|
|||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "drivers/user_config_driver.h"
|
||||
#include "drivers/user_spi_driver.h"
|
||||
#include "utils/user_log_util.h"
|
||||
#include "tasks/user_tasks.h"
|
||||
|
||||
uint8_t g_running = 1;
|
||||
|
||||
user_config_t g_config;
|
||||
user_spi_driver_t g_spi;
|
||||
|
||||
static void signal_handler(int signo) {
|
||||
if(signo == SIGINT) {
|
||||
g_running = 0;
|
||||
}
|
||||
USER_LOG(USER_LOG_INFO, "Signal %d captured, stopping.", signo);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
USER_LOG(USER_LOG_INFO, "Application started.");
|
||||
|
||||
if(signal(SIGINT, signal_handler) == SIG_ERR) {
|
||||
USER_LOG(USER_LOG_FATAL, "Cannot register signal handler.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
user_config_init(&g_config, "config.cfg");
|
||||
if(user_spi_driver_init(&g_spi, "/dev/spidev0.0") != USER_SPI_OK) {
|
||||
USER_LOG(USER_LOG_FATAL, "Failed to initialize SPI driver.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
user_lvgl_task_init();
|
||||
|
||||
USER_LOG(USER_LOG_INFO, "Initialized, main thread sleeping.");
|
||||
while(g_running) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
user_lvgl_task_deinit();
|
||||
|
||||
user_spi_driver_deinit(&g_spi);
|
||||
user_config_deinit(&g_config);
|
||||
|
||||
USER_LOG(USER_LOG_INFO, "Application exit.");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "lvgl.h"
|
||||
|
||||
#include "utils/user_log_util.h"
|
||||
#include "tasks/user_tasks.h"
|
||||
|
||||
extern uint8_t g_running;
|
||||
|
@ -18,19 +19,33 @@ void *user_lv_tick(void *arguments);
|
|||
int user_lvgl_task_init(void) {
|
||||
int ret;
|
||||
|
||||
USER_LOG(USER_LOG_INFO, "lv_init() called.");
|
||||
|
||||
lv_init();
|
||||
|
||||
ret = pthread_create(&user_lv_task_thread, NULL, user_lv_task, NULL);
|
||||
if(ret) return ret;
|
||||
ret = pthread_create(&user_lv_tick_thread, NULL, user_lv_tick, NULL);
|
||||
if(ret) return ret;
|
||||
|
||||
USER_LOG(USER_LOG_INFO, "LVGL threads created.");
|
||||
|
||||
pthread_setname_np(user_lv_task_thread, "LV_TASK");
|
||||
pthread_setname_np(user_lv_tick_thread, "LV_TICK");
|
||||
}
|
||||
|
||||
int user_lvgl_task_deinit(void) {
|
||||
USER_LOG(USER_LOG_INFO, "LVGL task_deinit() called.");
|
||||
|
||||
pthread_join(user_lv_task_thread, NULL);
|
||||
pthread_join(user_lv_tick_thread, NULL);
|
||||
|
||||
USER_LOG(USER_LOG_INFO, "LVGL threads joined.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *user_lv_task(void *arguments) {
|
||||
|
||||
while(g_running) {
|
||||
usleep(30 * 1000);
|
||||
lv_task_handler();
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "utils/user_log_util.h"
|
||||
|
||||
void user_log_print(user_log_level_t level, char *fmt, ...) {
|
||||
char *level_str;
|
||||
switch(level) {
|
||||
case USER_LOG_DEBUG:
|
||||
level_str = "[DEBUG]";
|
||||
case USER_LOG_INFO:
|
||||
level_str = "[INFO]";
|
||||
break;
|
||||
case USER_LOG_WARN:
|
||||
level_str = "[WARN]";
|
||||
break;
|
||||
case USER_LOG_ERROR:
|
||||
level_str = "[ERROR]";
|
||||
break;
|
||||
case USER_LOG_FATAL:
|
||||
level_str = "[FATAL]";
|
||||
break;
|
||||
default:
|
||||
level_str = "[UNKNOWN]";
|
||||
break;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
fprintf(stderr, "[% 9d]%s ", time(NULL), level_str);
|
||||
vfprintf(stderr, fmt, args);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
va_end(args);
|
||||
}
|
Loading…
Reference in New Issue