Added configuration file for board, fixed multiple memory related
issues.
This commit is contained in:
parent
5be4660e7c
commit
42525061bd
|
@ -10,7 +10,20 @@ typedef struct {
|
|||
struct gpiod_line *line;
|
||||
} user_gpio_t;
|
||||
|
||||
int user_gpio_init(user_gpio_t *gpio, char *chip, uint32_t offset, uint8_t output_enabled);
|
||||
typedef enum {
|
||||
USER_GPIO_INTR_RISING = 0x01,
|
||||
USER_GPIO_INTR_FALLING = 0x02,
|
||||
} user_gpio_intr_t;
|
||||
|
||||
typedef enum {
|
||||
USER_GPIO_EVENT_FALLING,
|
||||
USER_GPIO_EVENT_RISING
|
||||
} user_gpio_event_t;
|
||||
|
||||
typedef void (*gpio_irq_callback_t)(void *user_data, user_gpio_event_t event);
|
||||
|
||||
int user_gpio_init(user_gpio_t *gpio, char *chip, uint32_t offset,
|
||||
uint8_t output_enabled);
|
||||
int user_gpio_set(user_gpio_t *gpio, uint8_t value);
|
||||
int user_gpio_get(user_gpio_t *gpio, uint8_t *value);
|
||||
int user_gpio_deinit(user_gpio_t *gpio);
|
||||
|
|
|
@ -6,11 +6,6 @@ agent: {
|
|||
};
|
||||
|
||||
drivers: {
|
||||
spi: {
|
||||
path = "/dev/spidev0.0";
|
||||
clock_speed = 10000000;
|
||||
};
|
||||
|
||||
i2c: {
|
||||
path = "/dev/i2c-1";
|
||||
};
|
||||
|
@ -18,6 +13,10 @@ agent: {
|
|||
|
||||
devices: {
|
||||
lcd: {
|
||||
spi: {
|
||||
path = "/dev/spidev0.0";
|
||||
clock_speed = 10000000;
|
||||
};
|
||||
dc_pin: {
|
||||
path = "/dev/gpiochip1";
|
||||
line = 229;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
version = "1.0";
|
||||
|
||||
agent: {
|
||||
common: {
|
||||
log_level = 1;
|
||||
};
|
||||
|
||||
drivers: {
|
||||
i2c: {
|
||||
path = "/dev/i2c-1";
|
||||
};
|
||||
};
|
||||
|
||||
devices: {
|
||||
lcd: {
|
||||
spi: {
|
||||
path = "/dev/spidev0.1";
|
||||
clock_speed = 24000000;
|
||||
};
|
||||
dc_pin: {
|
||||
path = "/dev/gpiochip1";
|
||||
line = 229;
|
||||
};
|
||||
reset_pin: {
|
||||
path = "/dev/gpiochip1";
|
||||
line = 230;
|
||||
};
|
||||
backlight_pin: {
|
||||
path = "/dev/gpiochip1";
|
||||
line = 231;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
libraries: {
|
||||
lvgl: {
|
||||
fs_base = "lvgl_fs";
|
||||
};
|
||||
};
|
||||
|
||||
theme: {
|
||||
background = "A:images/background.bin"
|
||||
};
|
||||
};
|
|
@ -0,0 +1,44 @@
|
|||
version = "1.0";
|
||||
|
||||
agent: {
|
||||
common: {
|
||||
log_level = 1;
|
||||
};
|
||||
|
||||
drivers: {
|
||||
i2c: {
|
||||
path = "/dev/i2c-1";
|
||||
};
|
||||
};
|
||||
|
||||
devices: {
|
||||
lcd: {
|
||||
spi: {
|
||||
path = "/dev/spidev0.1";
|
||||
clock_speed = 24000000;
|
||||
};
|
||||
dc_pin: {
|
||||
path = "/dev/gpiochip0";
|
||||
line = 24;
|
||||
};
|
||||
reset_pin: {
|
||||
path = "/dev/gpiochip0";
|
||||
line = 23;
|
||||
};
|
||||
backlight_pin: {
|
||||
path = "/dev/gpiochip0";
|
||||
line = 12;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
libraries: {
|
||||
lvgl: {
|
||||
fs_base = "lvgl_fs";
|
||||
};
|
||||
};
|
||||
|
||||
theme: {
|
||||
background = "A:images/background.bin"
|
||||
};
|
||||
};
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
#include "drivers/user_gpio_driver.h"
|
||||
|
||||
#define CONSUMER_NAME "SA"
|
||||
|
||||
int user_gpio_init(user_gpio_t *gpio, char *chip, uint32_t offset, uint8_t output_enabled) {
|
||||
int user_gpio_init(user_gpio_t *gpio, char *chip, uint32_t offset,
|
||||
uint8_t output_enabled) {
|
||||
|
||||
gpio->chip = gpiod_chip_open(chip);
|
||||
if(gpio->chip == NULL) {
|
||||
|
@ -21,9 +23,9 @@ int user_gpio_init(user_gpio_t *gpio, char *chip, uint32_t offset, uint8_t outpu
|
|||
int ret;
|
||||
|
||||
if(output_enabled) {
|
||||
ret = gpiod_line_request_output(gpio->line, "SA", 1);
|
||||
ret = gpiod_line_request_output(gpio->line, CONSUMER_NAME, 1);
|
||||
} else {
|
||||
gpiod_line_request_input(gpio->line, "SA");
|
||||
gpiod_line_request_input(gpio->line, CONSUMER_NAME);
|
||||
}
|
||||
|
||||
if(ret != 0) {
|
||||
|
@ -45,7 +47,36 @@ int user_gpio_set(user_gpio_t *gpio, uint8_t value) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int user_gpio_get(user_gpio_t *gpio, uint8_t *value){
|
||||
int user_gpio_setup_intr(user_gpio_t *gpio, user_gpio_intr_t type) {
|
||||
|
||||
int request_type = 0;
|
||||
if(type == USER_GPIO_EVENT_RISING)
|
||||
request_type = GPIOD_LINE_REQUEST_EVENT_RISING_EDGE;
|
||||
else if(type == USER_GPIO_EVENT_FALLING)
|
||||
request_type = GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE;
|
||||
else if(type == USER_GPIO_EVENT_RISING | USER_GPIO_INTR_FALLING)
|
||||
request_type = GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES;
|
||||
|
||||
const struct gpiod_line_request_config config =
|
||||
{
|
||||
.consumer = CONSUMER_NAME,
|
||||
.request_type = request_type,
|
||||
};
|
||||
|
||||
int ret = gpiod_line_request(gpio->line, &config, 0);
|
||||
if(ret != 0) {
|
||||
USER_LOG(USER_LOG_ERROR, "Failed to reserve GPIO line for interrupt.");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int user_gpio_intr_poll(user_gpio_t *gpio) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_gpio_get(user_gpio_t *gpio, uint8_t *value) {
|
||||
*value = gpiod_line_get_value(gpio->line);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -42,6 +42,10 @@ void user_lvgl_impl_flush_cb(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
|||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
bool user_lvgl_indev_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
||||
//
|
||||
}
|
||||
|
||||
void *user_lvgl_impl_fs_open_cb(lv_fs_drv_t *drv, const char *path,
|
||||
lv_fs_mode_t mode) {
|
||||
char canonical_path[256];
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "impl/user_st7789_impl.h"
|
||||
|
||||
extern user_config_t g_config;
|
||||
extern user_spi_driver_t g_spi;
|
||||
|
||||
int _user_st7789_impl_init_pin(user_gpio_t *gpio, char *pin_name, uint8_t is_output) {
|
||||
char *chip;
|
||||
|
@ -33,14 +32,40 @@ int user_st7789_impl_init(void *handle) {
|
|||
|
||||
user_st7789_impl_t *impl = handle;
|
||||
|
||||
memset(impl, 0x00, sizeof(user_st7789_impl_t));
|
||||
|
||||
impl->cs_gpio = malloc(sizeof(user_gpio_t));
|
||||
if(!impl->cs_gpio) return -1;
|
||||
if(!impl->cs_gpio) goto free_and_exit;
|
||||
impl->dc_gpio = malloc(sizeof(user_gpio_t));
|
||||
if(!impl->dc_gpio) return -1;
|
||||
if(!impl->dc_gpio) goto free_and_exit;
|
||||
impl->reset_gpio = malloc(sizeof(user_gpio_t));
|
||||
if(!impl->reset_gpio) return -1;
|
||||
if(!impl->reset_gpio) goto free_and_exit;
|
||||
impl->bl_gpio = malloc(sizeof(user_gpio_t));
|
||||
if(!impl->bl_gpio) return -1;
|
||||
if(!impl->bl_gpio) goto free_and_exit;
|
||||
impl->spi_driver = malloc(sizeof(user_spi_driver_t));
|
||||
if(!impl->spi_driver) goto free_and_exit;
|
||||
|
||||
char *spi_path = user_config_lookup_string(&g_config, "agent.devices.lcd.spi.path");
|
||||
if(spi_path == NULL) {
|
||||
USER_LOG(USER_LOG_WARN, "SPI device path not found, using default.");
|
||||
spi_path = "/dev/spidev0.0";
|
||||
}
|
||||
|
||||
int spi_speed;
|
||||
if(user_config_lookup_int(&g_config, "agent.devices.lcd.spi.clock_speed", &spi_speed) != 0) {
|
||||
USER_LOG(USER_LOG_ERROR, "SPI device speed not found, using default.");
|
||||
spi_speed = 10000000;
|
||||
}
|
||||
|
||||
if(user_spi_driver_init(impl->spi_driver, spi_path, spi_speed) != 0) {
|
||||
USER_LOG(USER_LOG_FATAL, "SPI driver initialization failed.");
|
||||
goto free_and_exit;
|
||||
}
|
||||
|
||||
if(_user_st7789_impl_init_pin(impl->dc_gpio, "dc", 1) != 0) {
|
||||
USER_LOG(USER_LOG_ERROR, "DC pin not found, can not continue.");
|
||||
goto deinit_spi_and_exit;
|
||||
}
|
||||
|
||||
if(_user_st7789_impl_init_pin(impl->cs_gpio, "cs", 1) != 0) {
|
||||
free(impl->cs_gpio);
|
||||
|
@ -48,11 +73,6 @@ int user_st7789_impl_init(void *handle) {
|
|||
USER_LOG(USER_LOG_WARN, "No CS pin found, SPI must be correctly configured.");
|
||||
}
|
||||
|
||||
if(_user_st7789_impl_init_pin(impl->dc_gpio, "dc", 1) != 0) {
|
||||
USER_LOG(USER_LOG_ERROR, "DC pin not found.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
if(_user_st7789_impl_init_pin(impl->reset_gpio, "reset", 1) != 0) {
|
||||
free(impl->reset_gpio);
|
||||
impl->reset_gpio = NULL;
|
||||
|
@ -65,9 +85,18 @@ int user_st7789_impl_init(void *handle) {
|
|||
USER_LOG(USER_LOG_WARN, "No backlight pin found.");
|
||||
}
|
||||
|
||||
impl->spi_driver = &g_spi;
|
||||
|
||||
return 0;
|
||||
|
||||
deinit_spi_and_exit:
|
||||
user_spi_driver_deinit(impl->spi_driver);
|
||||
|
||||
free_and_exit:
|
||||
if(impl->cs_gpio) free(impl->cs_gpio);
|
||||
if(impl->dc_gpio) free(impl->dc_gpio);
|
||||
if(impl->bl_gpio) free(impl->bl_gpio);
|
||||
if(impl->reset_gpio) free(impl->reset_gpio);
|
||||
if(impl->spi_driver) free(impl->spi_driver);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void user_st7789_impl_deinit(void *handle) {
|
||||
|
@ -90,6 +119,10 @@ void user_st7789_impl_deinit(void *handle) {
|
|||
user_gpio_deinit(impl->bl_gpio);
|
||||
free(impl->bl_gpio);
|
||||
}
|
||||
if(impl->spi_driver) {
|
||||
user_spi_driver_deinit(impl->spi_driver);
|
||||
free(impl->spi_driver);
|
||||
}
|
||||
}
|
||||
|
||||
st7789_ret_t user_st7789_impl_write_cmd(void *handle, uint8_t *cmd,
|
||||
|
|
19
src/main.c
19
src/main.c
|
@ -13,7 +13,6 @@
|
|||
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) {
|
||||
|
@ -39,23 +38,6 @@ int main(int argc, const char *argv[]) {
|
|||
user_config_lookup_int(&g_config, "agent.common.log_level", (int *)&log_level);
|
||||
user_log_set_level(log_level);
|
||||
|
||||
char *spi_path = user_config_lookup_string(&g_config, "agent.drivers.spi.path");
|
||||
if(spi_path == NULL) {
|
||||
USER_LOG(USER_LOG_ERROR, "Failed to find SPI device from config, using default.");
|
||||
spi_path = "/dev/spidev0.0";
|
||||
}
|
||||
|
||||
int spi_speed;
|
||||
if(user_config_lookup_int(&g_config, "agent.drivers.spi.clock_speed", &spi_speed) != 0) {
|
||||
USER_LOG(USER_LOG_ERROR, "Failed to find SPI speed from config, using default.");
|
||||
spi_speed = 10000000;
|
||||
}
|
||||
|
||||
if(user_spi_driver_init(&g_spi, spi_path, spi_speed) != 0) {
|
||||
USER_LOG(USER_LOG_FATAL, "Failed to initialize SPI driver.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
user_lvgl_task_init();
|
||||
user_clock_task_init();
|
||||
|
||||
|
@ -67,7 +49,6 @@ int main(int argc, const char *argv[]) {
|
|||
user_clock_task_deinit();
|
||||
user_lvgl_task_deinit();
|
||||
|
||||
user_spi_driver_deinit(&g_spi);
|
||||
user_config_deinit(&g_config);
|
||||
|
||||
USER_LOG(USER_LOG_INFO, "Application exit.");
|
||||
|
|
Loading…
Reference in New Issue