From 62904fa6115a15802b82533a2e1fdef1a82bd06c Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 15 Mar 2021 15:14:46 +0100 Subject: [PATCH] sys/auto_init/screen: add common lcd auto_init - use auto_init_screen if disp_dev is used --- sys/auto_init/screen/auto_init_ili9341.c | 23 ++++++--- sys/auto_init/screen/auto_init_st7735.c | 62 ++++++++++++++++++++++++ sys/auto_init/screen/init.c | 4 ++ 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 sys/auto_init/screen/auto_init_st7735.c diff --git a/sys/auto_init/screen/auto_init_ili9341.c b/sys/auto_init/screen/auto_init_ili9341.c index 5ce7d86d71..f6541c783a 100644 --- a/sys/auto_init/screen/auto_init_ili9341.c +++ b/sys/auto_init/screen/auto_init_ili9341.c @@ -10,7 +10,7 @@ * @ingroup sys_auto_init * @{ * @file - * @brief initializes ili9341 display device + * @brief initializes lcd display device * * @author Alexandre Abadie * @} @@ -23,29 +23,38 @@ #include "disp_dev.h" +#include "lcd.h" +#include "lcd_disp_dev.h" + #include "ili9341.h" #include "ili9341_params.h" -#include "ili9341_disp_dev.h" -#define ILI9341_NUMOF ARRAY_SIZE(ili9341_params) +#ifndef ILI9341_NUMOF +#define ILI9341_NUMOF 0 +#endif +#ifndef ILI9341_SCREEN_NUMOF +#define ILI9341_SCREEN_NUMOF 0 +#endif static ili9341_t ili9341_devs[ILI9341_NUMOF]; + static disp_dev_reg_t disp_dev_entries[ILI9341_NUMOF]; void auto_init_ili9341(void) { - assert(ILI9341_NUMOF == ARRAY_SIZE(ili9341_screen_ids)); + assert(ILI9341_NUMOF == ILI9341_SCREEN_NUMOF); for (size_t i = 0; i < ILI9341_NUMOF; i++) { + ili9341_devs[i].dev.driver = &lcd_ili9341_driver; LOG_DEBUG("[auto_init_screen] initializing ili9341 #%u\n", i); - if (ili9341_init(&ili9341_devs[i], &ili9341_params[i]) < 0) { + if (lcd_init(&ili9341_devs[i].dev, &ili9341_params[i]) < 0) { LOG_ERROR("[auto_init_screen] error initializing ili9341 #%u\n", i); continue; } - disp_dev_entries[i].dev = (disp_dev_t *)&ili9341_devs[i]; + disp_dev_entries[i].dev = (disp_dev_t *) &ili9341_devs[i].dev; disp_dev_entries[i].screen_id = ili9341_screen_ids[i]; - disp_dev_entries[i].dev->driver = &ili9341_disp_dev_driver; + disp_dev_entries[i].dev->driver = &lcd_disp_dev_driver; /* add to disp_dev registry */ disp_dev_reg_add(&(disp_dev_entries[i])); diff --git a/sys/auto_init/screen/auto_init_st7735.c b/sys/auto_init/screen/auto_init_st7735.c new file mode 100644 index 0000000000..4247eb0e0c --- /dev/null +++ b/sys/auto_init/screen/auto_init_st7735.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2020 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys_auto_init + * @{ + * @file + * @brief initializes lcd display device + * + * @author Alexandre Abadie + * @} + */ + +#include +#include + +#include "log.h" + +#include "disp_dev.h" + +#include "lcd.h" +#include "lcd_disp_dev.h" + +#include "st7735.h" +#include "st7735_params.h" + +#ifndef ST7735_NUMOF +#define ST7735_NUMOF 0 +#endif +#ifndef ST7735_SCREEN_NUMOF +#define ST7735_SCREEN_NUMOF 0 +#endif + +static st7735_t st7735_devs[ST7735_NUMOF]; + +static disp_dev_reg_t disp_dev_entries[ST7735_NUMOF]; + +void auto_init_st7735(void) +{ + assert(ST7735_NUMOF == ST7735_SCREEN_NUMOF); + + for (size_t i = 0; i < ST7735_NUMOF; i++) { + st7735_devs[i].dev.driver = &lcd_st7735_driver; + LOG_DEBUG("[auto_init_screen] initializing st7735 #%u\n", i); + if (lcd_init(&st7735_devs[i].dev, &st7735_params[i].params) < 0) { + LOG_ERROR("[auto_init_screen] error initializing st7735 #%u\n", i); + continue; + } + + disp_dev_entries[i].dev = (disp_dev_t *) &st7735_devs[i].dev; + disp_dev_entries[i].screen_id = st7735_screen_ids[i]; + disp_dev_entries[i].dev->driver = &lcd_disp_dev_driver; + + /* add to disp_dev registry */ + disp_dev_reg_add(&(disp_dev_entries[i])); + } +} diff --git a/sys/auto_init/screen/init.c b/sys/auto_init/screen/init.c index ded52b2efa..38d38c3a4e 100644 --- a/sys/auto_init/screen/init.c +++ b/sys/auto_init/screen/init.c @@ -33,6 +33,10 @@ void auto_init_screen(void) extern void auto_init_periph_ltdc(void); auto_init_periph_ltdc(); } + if (IS_USED(MODULE_ST7735)) { + extern void auto_init_st7735(void); + auto_init_st7735(); + } } if (IS_USED(MODULE_TOUCH_DEV)) {