From a58794230539e87f449beb508b07c806fa50b8f0 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 10 Aug 2021 20:18:47 +0200 Subject: [PATCH 01/31] Fix changelog.txt whitespace --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 07c0a27a..529e682b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,7 +3,7 @@ ***************************************************************************** *** After Release 2.9 *** -CHANGE: Added type gImage to replace V2.x gdispImage +CHANGE: Added type gImage to replace V2.x gdispImage FIX: Fixed GWIN console widget scroll FIX: A warning and adjusted is made if GDISP_IMAGE_BMP_BLIT_BUFFER_SIZE is less than 40 bytes. From 9c0678a2911e132cdd2607f30cc1d22eb167a987 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 12 Aug 2021 12:20:07 +0200 Subject: [PATCH 02/31] Avoid duplicate const specifier compiler warnings The original code is perfectly valid standard C. However, some compilers (especially GCC) complain about duplicate const specifiers anyway. At this point we cave in as there doesn't seem to be any efforts to fix this problem by the corresponding compiler vendors. uGFX v3 will no longer suffer from this problem as the driver interface works differently in this area. --- drivers/multiple/Win32/gdisp_lld_Win32.c | 8 ++++++-- src/gdisp/gdisp.c | 4 ++-- src/gdisp/gdisp_driver.h | 6 +++++- src/gdriver/gdriver.h | 10 +++++++++- src/gfile/gfile.c | 5 ++++- src/gfile/gfile_fs_rom.c | 7 ++++++- src/ginput/ginput_mouse.c | 6 +++++- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c index 1ec52a37..5b1390e7 100644 --- a/drivers/multiple/Win32/gdisp_lld_Win32.c +++ b/drivers/multiple/Win32/gdisp_lld_Win32.c @@ -99,7 +99,11 @@ static gBool Win32MouseInit(GMouse *m, unsigned driverinstance); static gBool Win32MouseRead(GMouse *m, GMouseReading *prd); - const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + /** + * This should be: const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + * However, some major compilers complain about the duplicate const specifier even though this is perfectly valid standard C. + */ + const GMouseVMT GMOUSE_DRIVER_VMT[1] = {{ { GDRIVER_TYPE_MOUSE, GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY, @@ -885,7 +889,7 @@ LLDSPEC gBool gdisp_lld_init(GDisplay *g) { // Create the associated mouse #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE priv->mouseenabled = hWndParent ? gFalse : gTrue; - priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); + priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT*)GMOUSE_DRIVER_VMT, g); #endif sprintf(buf, APP_NAME " - %u", g->systemdisplay+1); diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 7b5438d7..c309dcbd 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -574,7 +574,7 @@ void _gdispInit(void) #elif GDISP_TOTAL_DISPLAYS > 1 { unsigned i; - extern const GDISPVMT const GDISPVMT_OnlyOne[1]; + extern const GDISPVMT GDISPVMT_OnlyOne[1]; if (!(GDISPVMT_OnlyOne->d.flags & GDISP_VFLG_DYNAMICONLY)) { for(i = 0; i < GDISP_TOTAL_DISPLAYS; i++) @@ -583,7 +583,7 @@ void _gdispInit(void) } #else { - extern const GDISPVMT const GDISPVMT_OnlyOne[1]; + extern const GDISPVMT GDISPVMT_OnlyOne[1]; if (!(GDISPVMT_OnlyOne->d.flags & GDISP_VFLG_DYNAMICONLY)) gdriverRegister(&GDISPVMT_OnlyOne->d, 0); diff --git a/src/gdisp/gdisp_driver.h b/src/gdisp/gdisp_driver.h index 936e2657..327e0b0a 100644 --- a/src/gdisp/gdisp_driver.h +++ b/src/gdisp/gdisp_driver.h @@ -732,7 +732,11 @@ typedef struct GDISPVMT { #endif // Build the VMT - const GDISPVMT const GDISP_DRIVER_VMT[1] = {{ + /* + * This should read: const GDISPVMT const GDISP_DRIVER_VMT[1] = {{ + * However, some major C compilers complain about duplicate const specifiers although this is perfectly valid standard C. + */ + const GDISPVMT GDISP_DRIVER_VMT[1] = {{ { GDRIVER_TYPE_DISPLAY, 0, sizeof(GDisplay), _gdispInitDriver, _gdispPostInitDriver, _gdispDeInitDriver }, gdisp_lld_init, #if GDISP_HARDWARE_DEINIT diff --git a/src/gdriver/gdriver.h b/src/gdriver/gdriver.h index 2b3ef7da..6a1f2061 100644 --- a/src/gdriver/gdriver.h +++ b/src/gdriver/gdriver.h @@ -86,8 +86,16 @@ typedef struct GDriverVMT { * const GDriverVMT const * mylist = { DRIVER_LIST }; * * + * @note This could be one single typedef. However, some major compilers complain about duplicate const specifiers even though this is perfectly + * valid standard C. As this problem has become worse over time we opt for splitting this into two separate typedefs to prevent these + * compilers from throwing warnings. + * The single typedef would look like this: + * + * typedef const struct GDriverVMT const GDriverVMTList[1]; + * */ -typedef const struct GDriverVMT const GDriverVMTList[1]; +typedef const struct GDriverVMT ConstGDriverVMT; +typedef ConstGDriverVMT const GDriverVMTList[1]; /*===========================================================================*/ /* External declarations. */ diff --git a/src/gfile/gfile.c b/src/gfile/gfile.c index 720ab815..4f535c39 100644 --- a/src/gfile/gfile.c +++ b/src/gfile/gfile.c @@ -36,8 +36,11 @@ /** * The order of the file-systems below determines the order * that they are searched to find a file. + * + * This should read: static const GFILEVMT const * FsArray[] = { + * However, some major C compilers complain about duplicate const specifiers although this is perfectly valid standard C. */ -static const GFILEVMT const * FsArray[] = { +static const GFILEVMT* FsArray[] = { #if GFILE_NEED_USERFS &FsUSERVMT, #endif diff --git a/src/gfile/gfile_fs_rom.c b/src/gfile/gfile_fs_rom.c index 56181086..57b27530 100644 --- a/src/gfile/gfile_fs_rom.c +++ b/src/gfile/gfile_fs_rom.c @@ -34,7 +34,12 @@ typedef struct ROMFS_DIRENTRY { #define ROMFS_DIRENTRY_HEAD 0 #include "romfs_files.h" -static const ROMFS_DIRENTRY const *FsROMHead = ROMFS_DIRENTRY_HEAD; + +/* + * This should be: static const ROMFS_DIRENTRY const *FsROMHead = ROMFS_DIRENTRY_HEAD; + * However, some major compilers complain about the duplicate const specifier even though this is perfectly valid standard C. + */ +static const ROMFS_DIRENTRY *FsROMHead = ROMFS_DIRENTRY_HEAD; typedef struct ROMFileList { gfileList fl; diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index 6d08e1f3..b3ef3d81 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -663,7 +663,11 @@ void _gmouseInit(void) { // One and only one mouse #else { - extern const GMouseVMT const GMOUSEVMT_OnlyOne[1]; + /* + * This should be: extern const GMouseVMT const GMOUSEVMT_OnlyOne[1]; + * However, some major compilers complain about the duplicate const specifier even though this is perfectly valid standard C. + */ + extern const GMouseVMT GMOUSEVMT_OnlyOne[1]; if (!(GMOUSEVMT_OnlyOne->d.flags & GMOUSE_VFLG_DYNAMICONLY)) gdriverRegister(&GMOUSEVMT_OnlyOne->d, GDISP); From 85c7b0882505bac23cd1a1b95fe526fa68242256 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 12 Aug 2021 12:22:54 +0200 Subject: [PATCH 03/31] Update changelog.txt --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 529e682b..d41f7cd0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ CHANGE: Added type gImage to replace V2.x gdispImage FIX: Fixed GWIN console widget scroll FIX: A warning and adjusted is made if GDISP_IMAGE_BMP_BLIT_BUFFER_SIZE is less than 40 bytes. +FIX: Prevent compiler warnings on duplicate const specifiers. *** Release 2.9 *** From 346375c00161239a434b878fe74d574862b6d159 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 12 Aug 2021 12:47:08 +0200 Subject: [PATCH 04/31] Add experimental support for ChibiOS 6.x kernel --- changelog.txt | 1 + src/gos/gos_chibios.c | 2 +- src/gos/gos_chibios.h | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index d41f7cd0..944ffd76 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,7 @@ CHANGE: Added type gImage to replace V2.x gdispImage FIX: Fixed GWIN console widget scroll FIX: A warning and adjusted is made if GDISP_IMAGE_BMP_BLIT_BUFFER_SIZE is less than 40 bytes. FIX: Prevent compiler warnings on duplicate const specifiers. +FEATURE: Added support for ChibiOS 6.x kernel. *** Release 2.9 *** diff --git a/src/gos/gos_chibios.c b/src/gos/gos_chibios.c index 674d090f..9de04579 100644 --- a/src/gos/gos_chibios.c +++ b/src/gos/gos_chibios.c @@ -11,7 +11,7 @@ #include -#if CH_KERNEL_MAJOR < 2 || CH_KERNEL_MAJOR > 5 +#if CH_KERNEL_MAJOR < 2 || CH_KERNEL_MAJOR > 6 #error "GOS: Unsupported version of ChibiOS" #endif diff --git a/src/gos/gos_chibios.h b/src/gos/gos_chibios.h index d2a8db3c..19b17b4e 100644 --- a/src/gos/gos_chibios.h +++ b/src/gos/gos_chibios.h @@ -35,7 +35,11 @@ #endif typedef systime_t gTicks; typedef cnt_t gSemcount; -typedef msg_t gThreadreturn; +#if CH_KERNEL_MAJOR >= 6 + typedef void gThreadreturn; +#else + typedef msg_t gThreadreturn; +#endif typedef tprio_t gThreadpriority; #define gSemMaxCount ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1)) From beb815e109acf021742ad8ad06f15abe15a596eb Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 12 Aug 2021 20:08:02 +0200 Subject: [PATCH 05/31] Board STM32F746-Discovery: Fix rouge-ly replaced types --- .../stm32f746g_raw32_system.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/boards/base/STM32F746-Discovery/stm32f746g_raw32_system.c b/boards/base/STM32F746-Discovery/stm32f746g_raw32_system.c index e0be3b23..56d3b16a 100644 --- a/boards/base/STM32F746-Discovery/stm32f746g_raw32_system.c +++ b/boards/base/STM32F746-Discovery/stm32f746g_raw32_system.c @@ -66,11 +66,11 @@ #include "stm32f7xx.h" #if !defined (HSE_VALUE) - #define HSE_VALUE ((gU32)25000000) /*!< Default value of the External oscillator in Hz */ + #define HSE_VALUE ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) - #define HSI_VALUE ((gU32)16000000) /*!< Value of the Internal oscillator in Hz*/ + #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** @@ -125,9 +125,9 @@ is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ - gU32 SystemCoreClock = 16000000; - const gU8 AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; - const gU8 APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; + uint32_t SystemCoreClock = 16000000; + const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; + const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} @@ -163,19 +163,19 @@ void SystemInit(void) #endif /* Reset the RCC clock configuration to the default reset state ------------*/ /* Set HSION bit */ - RCC->CR |= (gU32)0x00000001; + RCC->CR |= (uint32_t)0x00000001; /* Reset CFGR register */ RCC->CFGR = 0x00000000; /* Reset HSEON, CSSON and PLLON bits */ - RCC->CR &= (gU32)0xFEF6FFFF; + RCC->CR &= (uint32_t)0xFEF6FFFF; /* Reset PLLCFGR register */ RCC->PLLCFGR = 0x24003010; /* Reset HSEBYP bit */ - RCC->CR &= (gU32)0xFFFBFFFF; + RCC->CR &= (uint32_t)0xFFFBFFFF; /* Disable all interrupts */ RCC->CIR = 0x00000000; @@ -230,7 +230,7 @@ void SystemInit(void) */ void SystemCoreClockUpdate(void) { - gU32 tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; + uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; @@ -287,8 +287,8 @@ void SystemCoreClockUpdate(void) */ void SystemInit_ExtMemCtl(void) { - register gU32 tmpreg = 0, timeout = 0xFFFF; - register __IO gU32 index; + register uint32_t tmpreg = 0, timeout = 0xFFFF; + register __IO uint32_t index; /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and GPIOH interface clock */ From 6fa3520f2a8a48088afc9825b42d7ddef5e0fbc6 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 12 Aug 2021 20:22:49 +0200 Subject: [PATCH 06/31] Refactor STM32LTDC driver to outsource hardware specifics such as clock setup to the board file --- .../STM32F746-Discovery/board_STM32LTDC.h | 21 ++++++++++++++++ changelog.txt | 1 + .../STM32LTDC/board_STM32LTDC_template.h | 15 ++++++++++- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 25 +++---------------- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/boards/base/STM32F746-Discovery/board_STM32LTDC.h b/boards/base/STM32F746-Discovery/board_STM32LTDC.h index a3b02ca7..1f432c65 100644 --- a/boards/base/STM32F746-Discovery/board_STM32LTDC.h +++ b/boards/base/STM32F746-Discovery/board_STM32LTDC.h @@ -393,6 +393,27 @@ static void configureLcdPins(void) { #endif } +static GFXINLINE void init_ltdc_clock() +{ + // Reset the LTDC peripheral + RCC->APB2RSTR |= RCC_APB2RSTR_LTDCRST; + RCC->APB2RSTR = 0; + + // Enable the LTDC clock + RCC->DCKCFGR1 = (RCC->DCKCFGR1 & ~RCC_DCKCFGR1_PLLSAIDIVR) | (1 << 16); + + // Enable the peripheral + RCC->APB2ENR |= RCC_APB2ENR_LTDCEN; +} + +#if LTDC_USE_DMA2D + static GFXINLINE void init_dma2d_clock() + { + // Enable DMA2D clock + RCC->AHB1ENR |= RCC_AHB1ENR_DMA2DEN; + } +#endif + static GFXINLINE void init_board(GDisplay *g) { (void) g; diff --git a/changelog.txt b/changelog.txt index 944ffd76..8138e766 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ FIX: Fixed GWIN console widget scroll FIX: A warning and adjusted is made if GDISP_IMAGE_BMP_BLIT_BUFFER_SIZE is less than 40 bytes. FIX: Prevent compiler warnings on duplicate const specifiers. FEATURE: Added support for ChibiOS 6.x kernel. +CHANGE: Refactor STM32LTDC driver to outsource hardware specifics such as clock setup to the board file. *** Release 2.9 *** diff --git a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h index 20e47b5e..de5f7b3e 100644 --- a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h +++ b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h @@ -55,7 +55,20 @@ static const ltdcConfig driverCfg = { #endif }; -static GFXINLINE void init_board(GDisplay* g) { +static GFXINLINE void init_ltdc_clock() +{ + // Setup LTDC clock and enable the peripheral +} + +#if LTDC_USE_DMA2D + static GFXINLINE void init_dma2d_clock() + { + // Setup DMA2D clock and enable the peripheral + } +#endif + +static GFXINLINE void init_board(GDisplay* g) +{ // This is function only called once with the display for the background layer. (void)g; } diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 7cb8e8a0..6f05ff32 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -166,25 +166,8 @@ static void _ltdc_init(void) { // Set up the display scanning gU32 hacc, vacc; - // Reset the LTDC peripheral - RCC->APB2RSTR |= RCC_APB2RSTR_LTDCRST; - RCC->APB2RSTR = 0; - - // Enable the LTDC clock - #if !LTDC_NO_CLOCK_INIT - #if defined(STM32F469xx) - RCC->DCKCFGR = (RCC->DCKCFGR & ~RCC_DCKCFGR_PLLSAIDIVR); - #elif defined(STM32F4) || defined(STM32F429_439xx) || defined(STM32F429xx) - RCC->DCKCFGR = (RCC->DCKCFGR & ~RCC_DCKCFGR_PLLSAIDIVR) | (1 << 16); - #elif defined(STM32F7) || defined(STM32F746xx) - RCC->DCKCFGR1 = (RCC->DCKCFGR1 & ~RCC_DCKCFGR1_PLLSAIDIVR) | (1 << 16); - #else - #error STM32LTDC driver not implemented for your platform - #endif - #endif - - // Enable the peripheral - RCC->APB2ENR |= RCC_APB2ENR_LTDCEN; + // Let the board handle LTDC clock setups + init_ltdc_clock(); // Turn off the controller and its interrupts LTDC->GCR = 0; @@ -425,8 +408,8 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { static void dma2d_init(void) { - // Enable DMA2D clock - RCC->AHB1ENR |= RCC_AHB1ENR_DMA2DEN; + // Let the board handle the clock setup + init_dma2d_clock(); // Output color format #if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB565 From 37450998e1e77e2c0ea6c864be4e7e19ec9a6022 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 12 Aug 2021 20:31:49 +0200 Subject: [PATCH 07/31] STM32LTDC: Fix board function signatures --- boards/base/STM32F746-Discovery/board_STM32LTDC.h | 4 ++-- drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/boards/base/STM32F746-Discovery/board_STM32LTDC.h b/boards/base/STM32F746-Discovery/board_STM32LTDC.h index 1f432c65..e5e203be 100644 --- a/boards/base/STM32F746-Discovery/board_STM32LTDC.h +++ b/boards/base/STM32F746-Discovery/board_STM32LTDC.h @@ -393,7 +393,7 @@ static void configureLcdPins(void) { #endif } -static GFXINLINE void init_ltdc_clock() +static GFXINLINE void init_ltdc_clock(void) { // Reset the LTDC peripheral RCC->APB2RSTR |= RCC_APB2RSTR_LTDCRST; @@ -407,7 +407,7 @@ static GFXINLINE void init_ltdc_clock() } #if LTDC_USE_DMA2D - static GFXINLINE void init_dma2d_clock() + static GFXINLINE void init_dma2d_clock(void) { // Enable DMA2D clock RCC->AHB1ENR |= RCC_AHB1ENR_DMA2DEN; diff --git a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h index de5f7b3e..5911e9c8 100644 --- a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h +++ b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h @@ -55,13 +55,13 @@ static const ltdcConfig driverCfg = { #endif }; -static GFXINLINE void init_ltdc_clock() +static GFXINLINE void init_ltdc_clock(void) { // Setup LTDC clock and enable the peripheral } #if LTDC_USE_DMA2D - static GFXINLINE void init_dma2d_clock() + static GFXINLINE void init_dma2d_clock(void) { // Setup DMA2D clock and enable the peripheral } From cf01cb2e7c6bd5b703c3a7c21565732705315e27 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 13 Aug 2021 11:51:47 +0200 Subject: [PATCH 08/31] GDISP: Move extern GDISPVMT declarations outside of function body This prevents generation of "nested-externs" compiler warnings. --- src/gdisp/gdisp.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index c309dcbd..1ade4ff6 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -555,15 +555,22 @@ static void line_clip(GDisplay *g) { /* Driver exported functions. */ /*===========================================================================*/ +// Gather GDISP VMT(S) +// These are only needed in _gdispInit(). However, we want to prevent generating nested-externs compiler warnings. +#if defined(GDISP_DRIVER_LIST) + extern GDISPVMTLIST GDISP_DRIVER_LIST; +#else + extern const GDISPVMT GDISPVMT_OnlyOne[1]; +#endif + void _gdispInit(void) { // GDISP_DRIVER_LIST is defined - create each driver instance #if defined(GDISP_DRIVER_LIST) { - unsigned i; + unsigned i; typedef const GDISPVMT const GDISPVMTLIST[1]; - extern GDISPVMTLIST GDISP_DRIVER_LIST; static const GDISPVMT * const dclist[] = {GDISP_DRIVER_LIST}; for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) { @@ -573,8 +580,7 @@ void _gdispInit(void) } #elif GDISP_TOTAL_DISPLAYS > 1 { - unsigned i; - extern const GDISPVMT GDISPVMT_OnlyOne[1]; + unsigned i; if (!(GDISPVMT_OnlyOne->d.flags & GDISP_VFLG_DYNAMICONLY)) { for(i = 0; i < GDISP_TOTAL_DISPLAYS; i++) @@ -583,8 +589,6 @@ void _gdispInit(void) } #else { - extern const GDISPVMT GDISPVMT_OnlyOne[1]; - if (!(GDISPVMT_OnlyOne->d.flags & GDISP_VFLG_DYNAMICONLY)) gdriverRegister(&GDISPVMT_OnlyOne->d, 0); } From b1b264b6a1b689dea513f5b6fc02d37b8e38d269 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 16 Aug 2021 16:25:04 +0200 Subject: [PATCH 09/31] Fix legacy string --- demos/benchmarks/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/benchmarks/main.c b/demos/benchmarks/main.c index 772885fa..f010dd57 100644 --- a/demos/benchmarks/main.c +++ b/demos/benchmarks/main.c @@ -98,7 +98,7 @@ void benchmark(void) { height = gdispGetHeight(); font = gdispOpenFont("UI2 Double"); - gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, GFX_WHITE, gJustifyCenter); + gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter); font = gdispOpenFont("UI2"); gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, GFX_WHITE, gJustifyCenter); From a9cf2bdfe280a39b45ce485970309bc7765c7a2b Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 17 Aug 2021 12:32:12 +0200 Subject: [PATCH 10/31] STM32LTDC: Enable DMA cache flushing on H7 platforms --- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 6f05ff32..6f03ac32 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -23,6 +23,9 @@ #undef GDISP_SCREEN_HEIGHT #endif +#ifndef LTDC_USE_DOUBLE_BUFFERING + #define LTDC_USE_DOUBLE_BUFFERING GFXOFF +#endif #ifndef LTDC_USE_DMA2D #define LTDC_USE_DMA2D GFXOFF #endif @@ -38,7 +41,7 @@ #if LTDC_USE_DMA2D #include "stm32_dma2d.h" - #if defined(STM32F7) || defined(STM32F746xx) + #if defined(STM32F7) || defined(STM32H7) || defined(STM32F746xx) #undef LTDC_DMA_CACHE_FLUSH #define LTDC_DMA_CACHE_FLUSH GFXON #endif From 94fd096fddb6adf7e0d4c5889d49b357454abdfa Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 17 Aug 2021 13:26:54 +0200 Subject: [PATCH 11/31] STM32LTDC: Rename ALLOW_2ND_LAYER to LTDC_USE_2ND_LAYER --- .../chibios/board_STM32LTDC.h | 4 +-- .../STM32F439i-Eval/CubeHal/board_STM32LTDC.h | 4 +-- .../STM32F746-Discovery/board_STM32LTDC.h | 4 +-- .../STM32LTDC/board_STM32LTDC_template.h | 4 +-- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 3 --- drivers/gdisp/STM32LTDC/readme.md | 25 +++++++++++++++++++ drivers/gdisp/STM32LTDC/readme.txt | 11 -------- 7 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 drivers/gdisp/STM32LTDC/readme.md delete mode 100644 drivers/gdisp/STM32LTDC/readme.txt diff --git a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h index 20f028f9..7e6fbd48 100644 --- a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h +++ b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h @@ -23,7 +23,7 @@ static const SPIConfig spi_cfg = { ((1 << 3) & SPI_CR1_BR) | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_MSTR }; -#define ALLOW_2ND_LAYER GFXON +#define LTDC_USE_2ND_LAYER GFXON static const ltdcConfig driverCfg = { 240, 320, @@ -47,7 +47,7 @@ static const ltdcConfig driverCfg = { 0xFF, // alpha LTDC_LEF_ENABLE // flags }, -#if ALLOW_2ND_LAYER +#if LTDC_USE_2ND_LAYER { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_BANK_ADDR+(240 * 320 * LTDC_PIXELBYTES)), // Frame buffer address 240, 320, // width, height diff --git a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h index d598efac..c3a16d8a 100644 --- a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h +++ b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h @@ -19,7 +19,7 @@ #include "stm32f4xx_hal.h" #include "stm324x9i_eval_sdram.h" -#define ALLOW_2ND_LAYER GFXON +#define LTDC_USE_2ND_LAYER GFXON // Panel parameters // This panel is a AMPIRE640480 panel. @@ -48,7 +48,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if ALLOW_2ND_LAYER +#if LTDC_USE_2ND_LAYER { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(640 * 480 * LTDC_PIXELBYTES)), // Frame buffer address 640, 480, // Width, Height (pixels) diff --git a/boards/base/STM32F746-Discovery/board_STM32LTDC.h b/boards/base/STM32F746-Discovery/board_STM32LTDC.h index e5e203be..494ee4eb 100644 --- a/boards/base/STM32F746-Discovery/board_STM32LTDC.h +++ b/boards/base/STM32F746-Discovery/board_STM32LTDC.h @@ -36,7 +36,7 @@ #define AFRH AFR[1] #endif -#define ALLOW_2ND_LAYER GFXON +#define LTDC_USE_2ND_LAYER GFXON static const ltdcConfig driverCfg = { 480, 272, // Width, Height (pixels) @@ -62,7 +62,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if ALLOW_2ND_LAYER +#if LTDC_USE_2ND_LAYER { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(480 * 272 * LTDC_PIXELBYTES)), // Frame buffer address 480, 272, // Width, Height (pixels) diff --git a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h index 5911e9c8..d2c32581 100644 --- a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h +++ b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h @@ -8,7 +8,7 @@ #ifndef _GDISP_LLD_BOARD_H #define _GDISP_LLD_BOARD_H -#define ALLOW_2ND_LAYER GFXON +#define LTDC_USE_2ND_LAYER GFXON static const ltdcConfig driverCfg = { 480, 272, // Width, Height (pixels) @@ -34,7 +34,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if ALLOW_2ND_LAYER +#if LTDC_USE_2ND_LAYER { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(480 * 272 * LTDC_PIXELBYTES)), // Frame buffer address 480, 272, // Width, Height (pixels) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 6f03ac32..5267ee5b 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -23,9 +23,6 @@ #undef GDISP_SCREEN_HEIGHT #endif -#ifndef LTDC_USE_DOUBLE_BUFFERING - #define LTDC_USE_DOUBLE_BUFFERING GFXOFF -#endif #ifndef LTDC_USE_DMA2D #define LTDC_USE_DMA2D GFXOFF #endif diff --git a/drivers/gdisp/STM32LTDC/readme.md b/drivers/gdisp/STM32LTDC/readme.md new file mode 100644 index 00000000..baa5ebbd --- /dev/null +++ b/drivers/gdisp/STM32LTDC/readme.md @@ -0,0 +1,25 @@ +# Usage +To use this driver: + +1. Add in your `gfxconf.h`: + a) `#define GFX_USE_GDISP GFXON` + +2. To your makefile add the following lines: +``` + include $(GFXLIB)/gfx.mk + include $(GFXLIB)/drivers/gdisp/STM32LTDC/driver.mk +``` + +3. Add a `board_STM32LTDC.h` to you project directory (or board directory) + based on one of the templates. + +# 2nd layer +Two things need to happen in order to use the 2nd LTDC layer: + - Set `LTDC_USE_2ND_LAYER` to `GFXON` in the board file. + - Set `GDISP_TOTAL_DISPLAYS` to `2` in `gfxconf.h`. + +The 2nd layer is exposed as a separate display. Use `gdispGetDisplay()` to retrieve the individual layers. + +For more information, see: + - https://wiki.ugfx.io/index.php/Multiple_displays#Example_-_Same_controller + - https://wiki.ugfx.io/index.php/Multiple_displays#Access_the_displays diff --git a/drivers/gdisp/STM32LTDC/readme.txt b/drivers/gdisp/STM32LTDC/readme.txt deleted file mode 100644 index dcc17d39..00000000 --- a/drivers/gdisp/STM32LTDC/readme.txt +++ /dev/null @@ -1,11 +0,0 @@ -To use this driver: - -1. Add in your gfxconf.h: - a) #define GFX_USE_GDISP GFXON - -2. To your makefile add the following lines: - include $(GFXLIB)/gfx.mk - include $(GFXLIB)/drivers/gdisp/STM32LTDC/driver.mk - -3. Add a board_STM32LTDC.h to you project directory (or board directory) - based on one of the templates. From 2de054b530ba250c7a9aee7ed4a3db8a1b614c74 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 17 Aug 2021 13:29:49 +0200 Subject: [PATCH 12/31] STM32LTDC: Remove obsolete LTDC_NO_CLOCK_INIT define --- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 5267ee5b..fab2d4e7 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -26,9 +26,6 @@ #ifndef LTDC_USE_DMA2D #define LTDC_USE_DMA2D GFXOFF #endif -#ifndef LTDC_NO_CLOCK_INIT - #define LTDC_NO_CLOCK_INIT GFXOFF -#endif #ifndef LTDC_DMA_CACHE_FLUSH #define LTDC_DMA_CACHE_FLUSH GFXOFF #endif From 91247717a07392197a71df8f6740a62562670fca Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 17 Aug 2021 13:40:57 +0200 Subject: [PATCH 13/31] STM32LTDC: Expose more options to board file --- .../chibios/board_STM32LTDC.h | 2 + .../STM32F439i-Eval/CubeHal/board_STM32LTDC.h | 2 + .../CubeHAL/board_STM32LTDC.h | 4 ++ .../STM32F746-Discovery/board_STM32LTDC.h | 2 + .../STM32LTDC/board_STM32LTDC_template.h | 4 +- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 37 +++++++++---------- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h index 7e6fbd48..73dadbd9 100644 --- a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h +++ b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h @@ -23,7 +23,9 @@ static const SPIConfig spi_cfg = { ((1 << 3) & SPI_CR1_BR) | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_MSTR }; +#define LTDC_USE_DMA2D GFXON #define LTDC_USE_2ND_LAYER GFXON +#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms static const ltdcConfig driverCfg = { 240, 320, diff --git a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h index c3a16d8a..bb9d740c 100644 --- a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h +++ b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h @@ -19,7 +19,9 @@ #include "stm32f4xx_hal.h" #include "stm324x9i_eval_sdram.h" +#define LTDC_USE_DMA2D GFXON #define LTDC_USE_2ND_LAYER GFXON +#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms // Panel parameters // This panel is a AMPIRE640480 panel. diff --git a/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h b/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h index 1571966b..3498cd1e 100644 --- a/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h +++ b/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h @@ -8,6 +8,10 @@ #ifndef _GDISP_LLD_BOARD_H #define _GDISP_LLD_BOARD_H +#define LTDC_USE_DMA2D GFXON +#define LTDC_USE_2ND_LAYER GFXON +#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms + /* Avoid naming collisions with CubeHAL. */ #if GFX_COMPAT_V2 && GFX_COMPAT_OLDCOLORS #undef Red diff --git a/boards/base/STM32F746-Discovery/board_STM32LTDC.h b/boards/base/STM32F746-Discovery/board_STM32LTDC.h index 494ee4eb..1cc57ca8 100644 --- a/boards/base/STM32F746-Discovery/board_STM32LTDC.h +++ b/boards/base/STM32F746-Discovery/board_STM32LTDC.h @@ -36,7 +36,9 @@ #define AFRH AFR[1] #endif +#define LTDC_USE_DMA2D GFXON #define LTDC_USE_2ND_LAYER GFXON +#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms static const ltdcConfig driverCfg = { 480, 272, // Width, Height (pixels) diff --git a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h index d2c32581..30d5df1d 100644 --- a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h +++ b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h @@ -8,7 +8,9 @@ #ifndef _GDISP_LLD_BOARD_H #define _GDISP_LLD_BOARD_H -#define LTDC_USE_2ND_LAYER GFXON +#define LTDC_USE_DMA2D GFXON +#define LTDC_USE_2ND_LAYER GFXOFF +#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms static const ltdcConfig driverCfg = { 480, 272, // Width, Height (pixels) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index fab2d4e7..50e45056 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -12,6 +12,10 @@ #define GDISP_DRIVER_VMT GDISPVMT_STM32LTDC #include "gdisp_lld_config.h" #include "../../../src/gdisp/gdisp_driver.h" +#include "stm32_ltdc.h" +#if LTDC_USE_DMA2D + #include "stm32_dma2d.h" +#endif #if defined(GDISP_SCREEN_HEIGHT) || defined(GDISP_SCREEN_HEIGHT) #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT @@ -23,25 +27,6 @@ #undef GDISP_SCREEN_HEIGHT #endif -#ifndef LTDC_USE_DMA2D - #define LTDC_USE_DMA2D GFXOFF -#endif -#ifndef LTDC_DMA_CACHE_FLUSH - #define LTDC_DMA_CACHE_FLUSH GFXOFF -#endif - -#include "stm32_ltdc.h" - -#if LTDC_USE_DMA2D - #include "stm32_dma2d.h" - - #if defined(STM32F7) || defined(STM32H7) || defined(STM32F746xx) - #undef LTDC_DMA_CACHE_FLUSH - #define LTDC_DMA_CACHE_FLUSH GFXON - #endif -#endif - - typedef struct ltdcLayerConfig { // Frame LLDCOLOR_TYPE* frame; // Frame buffer address @@ -90,6 +75,20 @@ typedef struct ltdcConfig { #include "board_STM32LTDC.h" +#ifndef LTDC_USE_DMA2D + #define LTDC_USE_DMA2D GFXOFF +#endif +#ifndef LTDC_DMA_CACHE_FLUSH + #define LTDC_DMA_CACHE_FLUSH GFXOFF +#endif + +#if LTDC_USE_DMA2D + #if defined(STM32F7) || defined(STM32H7) || defined(STM32F746xx) + #undef LTDC_DMA_CACHE_FLUSH + #define LTDC_DMA_CACHE_FLUSH GFXON + #endif +#endif + /*===========================================================================*/ /* Driver local definitions. */ /*===========================================================================*/ From 7f78be1183f73afa647ad16fca1dd4736c8cfa65 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 17 Aug 2021 14:23:57 +0200 Subject: [PATCH 14/31] STM32LTDC: Rename user config options for consistency & add docs --- .../chibios/board_STM32LTDC.h | 6 +-- .../STM32F439i-Eval/CubeHal/board_STM32LTDC.h | 6 +-- .../CubeHAL/board_STM32LTDC.h | 4 -- .../STM32F746-Discovery/board_STM32LTDC.h | 8 +-- .../STM32LTDC/board_STM32LTDC_template.h | 8 +-- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 51 +++++++++++-------- drivers/gdisp/STM32LTDC/gdisp_lld_config.h | 7 ++- drivers/gdisp/STM32LTDC/readme.md | 14 +++-- 8 files changed, 49 insertions(+), 55 deletions(-) diff --git a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h index 73dadbd9..f599c81e 100644 --- a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h +++ b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h @@ -23,10 +23,6 @@ static const SPIConfig spi_cfg = { ((1 << 3) & SPI_CR1_BR) | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_MSTR }; -#define LTDC_USE_DMA2D GFXON -#define LTDC_USE_2ND_LAYER GFXON -#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms - static const ltdcConfig driverCfg = { 240, 320, 10, 2, @@ -49,7 +45,7 @@ static const ltdcConfig driverCfg = { 0xFF, // alpha LTDC_LEF_ENABLE // flags }, -#if LTDC_USE_2ND_LAYER +#if STM32LTDC_USE_LAYER2 { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_BANK_ADDR+(240 * 320 * LTDC_PIXELBYTES)), // Frame buffer address 240, 320, // width, height diff --git a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h index bb9d740c..c78cc982 100644 --- a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h +++ b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h @@ -19,10 +19,6 @@ #include "stm32f4xx_hal.h" #include "stm324x9i_eval_sdram.h" -#define LTDC_USE_DMA2D GFXON -#define LTDC_USE_2ND_LAYER GFXON -#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms - // Panel parameters // This panel is a AMPIRE640480 panel. @@ -50,7 +46,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if LTDC_USE_2ND_LAYER +#if STM32LTDC_USE_LAYER2 { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(640 * 480 * LTDC_PIXELBYTES)), // Frame buffer address 640, 480, // Width, Height (pixels) diff --git a/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h b/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h index 3498cd1e..1571966b 100644 --- a/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h +++ b/boards/base/STM32F469i-Discovery/CubeHAL/board_STM32LTDC.h @@ -8,10 +8,6 @@ #ifndef _GDISP_LLD_BOARD_H #define _GDISP_LLD_BOARD_H -#define LTDC_USE_DMA2D GFXON -#define LTDC_USE_2ND_LAYER GFXON -#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms - /* Avoid naming collisions with CubeHAL. */ #if GFX_COMPAT_V2 && GFX_COMPAT_OLDCOLORS #undef Red diff --git a/boards/base/STM32F746-Discovery/board_STM32LTDC.h b/boards/base/STM32F746-Discovery/board_STM32LTDC.h index 1cc57ca8..2c28103a 100644 --- a/boards/base/STM32F746-Discovery/board_STM32LTDC.h +++ b/boards/base/STM32F746-Discovery/board_STM32LTDC.h @@ -36,10 +36,6 @@ #define AFRH AFR[1] #endif -#define LTDC_USE_DMA2D GFXON -#define LTDC_USE_2ND_LAYER GFXON -#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms - static const ltdcConfig driverCfg = { 480, 272, // Width, Height (pixels) 41, 10, // Horizontal, Vertical sync (pixels) @@ -64,7 +60,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if LTDC_USE_2ND_LAYER +#if STM32LTDC_USE_LAYER2 { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(480 * 272 * LTDC_PIXELBYTES)), // Frame buffer address 480, 272, // Width, Height (pixels) @@ -408,7 +404,7 @@ static GFXINLINE void init_ltdc_clock(void) RCC->APB2ENR |= RCC_APB2ENR_LTDCEN; } -#if LTDC_USE_DMA2D +#if STM32LTDC_USE_DMA2D static GFXINLINE void init_dma2d_clock(void) { // Enable DMA2D clock diff --git a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h index 30d5df1d..91623334 100644 --- a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h +++ b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h @@ -8,10 +8,6 @@ #ifndef _GDISP_LLD_BOARD_H #define _GDISP_LLD_BOARD_H -#define LTDC_USE_DMA2D GFXON -#define LTDC_USE_2ND_LAYER GFXOFF -#define LTDC_DMA_CACHE_FLUSH GFXOFF // This will be turned on automatically on certain systems/platforms - static const ltdcConfig driverCfg = { 480, 272, // Width, Height (pixels) 41, 10, // Horizontal, Vertical sync (pixels) @@ -36,7 +32,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if LTDC_USE_2ND_LAYER +#if STM32LTDC_USE_LAYER2 { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(480 * 272 * LTDC_PIXELBYTES)), // Frame buffer address 480, 272, // Width, Height (pixels) @@ -62,7 +58,7 @@ static GFXINLINE void init_ltdc_clock(void) // Setup LTDC clock and enable the peripheral } -#if LTDC_USE_DMA2D +#if STM32LTDC_USE_DMA2D static GFXINLINE void init_dma2d_clock(void) { // Setup DMA2D clock and enable the peripheral diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 50e45056..716bb93d 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -13,7 +13,7 @@ #include "gdisp_lld_config.h" #include "../../../src/gdisp/gdisp_driver.h" #include "stm32_ltdc.h" -#if LTDC_USE_DMA2D +#if STM32LTDC_USE_DMA2D #include "stm32_dma2d.h" #endif @@ -27,6 +27,27 @@ #undef GDISP_SCREEN_HEIGHT #endif +#ifndef STM32LTDC_DMA_CACHE_FLUSH + #define STM32LTDC_DMA_CACHE_FLUSH GFXOFF +#endif +#ifndef STM32LTDC_USE_DMA2D + #define STM32LTDC_USE_DMA2D GFXOFF +#endif +#ifndef STM32LTDC_USE_LAYER2 + #define STM32LTDC_USE_LAYER2 GFXOFF +#endif +#ifndef STM32LTDC_USE_RGB565 + #define STM32LTDC_USE_RGB565 GFXOFF +#endif + +// Force DMA cache flushing on certain platforms/systems. +#if STM32LTDC_USE_DMA2D + #if defined(STM32F7) || defined(STM32H7) || defined(STM32F746xx) + #undef STM32LTDC_DMA_CACHE_FLUSH + #define STM32LTDC_DMA_CACHE_FLUSH GFXON + #endif +#endif + typedef struct ltdcLayerConfig { // Frame LLDCOLOR_TYPE* frame; // Frame buffer address @@ -75,20 +96,6 @@ typedef struct ltdcConfig { #include "board_STM32LTDC.h" -#ifndef LTDC_USE_DMA2D - #define LTDC_USE_DMA2D GFXOFF -#endif -#ifndef LTDC_DMA_CACHE_FLUSH - #define LTDC_DMA_CACHE_FLUSH GFXOFF -#endif - -#if LTDC_USE_DMA2D - #if defined(STM32F7) || defined(STM32H7) || defined(STM32F746xx) - #undef LTDC_DMA_CACHE_FLUSH - #define LTDC_DMA_CACHE_FLUSH GFXON - #endif -#endif - /*===========================================================================*/ /* Driver local definitions. */ /*===========================================================================*/ @@ -226,7 +233,7 @@ LLDSPEC gBool gdisp_lld_init(GDisplay* g) { _ltdc_init(); // Initialise DMA2D - #if LTDC_USE_DMA2D + #if STM32LTDC_USE_DMA2D dma2d_init(); #endif @@ -297,7 +304,7 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay* g) { pos = PIXIL_POS(g, g->p.x, g->p.y); #endif - #if LTDC_USE_DMA2D + #if STM32LTDC_USE_DMA2D while(DMA2D->CR & DMA2D_CR_START); #endif @@ -335,7 +342,7 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { pos = PIXIL_POS(g, g->p.x, g->p.y); #endif - #if LTDC_USE_DMA2D + #if STM32LTDC_USE_DMA2D while(DMA2D->CR & DMA2D_CR_START); #endif @@ -393,8 +400,8 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { } #endif -#if LTDC_USE_DMA2D - #if LTDC_DMA_CACHE_FLUSH +#if STM32LTDC_USE_DMA2D + #if STM32LTDC_DMA_CACHE_FLUSH #if defined(__CC_ARM) #define __ugfxDSB() __dsb(0xF) #else // GCC like @@ -459,7 +466,7 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { shape = (g->p.cx << 16) | (g->p.cy); #endif - #if LTDC_DMA_CACHE_FLUSH + #if STM32LTDC_DMA_CACHE_FLUSH { // This is slightly less than optimal as we flush the whole line in the source and destination image // instead of just the cx portion but this saves us having to iterate over each line. @@ -524,7 +531,7 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { srcstart = LTDC_PIXELBYTES * ((gU32)g->p.x2 * g->p.y1 * + g->p.x1) + (gU32)g->p.ptr; dststart = (gU32)PIXEL_ADDR(g, PIXIL_POS(g, g->p.x, g->p.y)); - #if LTDC_DMA_CACHE_FLUSH + #if STM32LTDC_DMA_CACHE_FLUSH { // This is slightly less than optimal as we flush the whole line in the source and destination image // instead of just the cx portion but this saves us having to iterate over each line. diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h index 0061adb0..75190eb8 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h @@ -14,7 +14,6 @@ /* Driver hardware support. */ /*===========================================================================*/ -#define LTDC_USE_DMA2D GFXON #define GDISP_HARDWARE_DRAWPIXEL GFXON #define GDISP_HARDWARE_PIXELREAD GFXON #define GDISP_HARDWARE_CONTROL GFXON @@ -22,10 +21,10 @@ // Both these pixel formats are supported - pick one. // RGB565 obviously is faster and uses less RAM but with lower color resolution than RGB888 -#if defined(GDISP_LTDC_USE_RGB565) && GDISP_LTDC_USE_RGB565 +#if defined(STM32LTDC_USE_RGB565) && STM32LTDC_USE_RGB565 #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 #if GDISP_TOTAL_DISPLAYS > 1 - #error "LTDC: You must use RGB888 pixel format with LTDC when using dual layers as only RGB888 currently supports using alpha" + #error "GDISP - STM32LTDC: You must use RGB888 pixel format with LTDC when using dual layers as only RGB888 currently supports using alpha" #endif #else #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 @@ -36,7 +35,7 @@ /* Don't change stuff below this line. Please. */ /*===========================================================================*/ -#if LTDC_USE_DMA2D +#if STM32LTDC_USE_DMA2D // DMA2D supports accelerated fills #define GDISP_HARDWARE_FILLS GFXON diff --git a/drivers/gdisp/STM32LTDC/readme.md b/drivers/gdisp/STM32LTDC/readme.md index baa5ebbd..cd7f4578 100644 --- a/drivers/gdisp/STM32LTDC/readme.md +++ b/drivers/gdisp/STM32LTDC/readme.md @@ -12,11 +12,19 @@ To use this driver: 3. Add a `board_STM32LTDC.h` to you project directory (or board directory) based on one of the templates. + +# Configuration +Configuration options available in `gfxconf.h`: + +| Option | Default | Description | +| --- | --- | --- | +| `STM32LTDC_DMA_CACHE_FLUSH` | `GFOFF` | Whether to flush the DMA cache on DMA2D operations. This will be turned on automatically on certian platforms/systems. | +| `STM32LTDC_USE_DMA2D` | `GFXON` | Whether to use the DMA2D peripheral for hardware acceleration. | +| `STM32LTDC_USE_LAYER2` | `GFXOFF` | Whether to use the 2nd LTDC layer. | +| `STM32LTDC_USE_RGB565` | `GFXOFF` | Whether to use RGB565 instead of RGB888. | # 2nd layer -Two things need to happen in order to use the 2nd LTDC layer: - - Set `LTDC_USE_2ND_LAYER` to `GFXON` in the board file. - - Set `GDISP_TOTAL_DISPLAYS` to `2` in `gfxconf.h`. +To use the 2nd LTDC layer, set `STM32LTDC_USE_LAYER2` to `GFXON` in `gfxconf.h`. The 2nd layer is exposed as a separate display. Use `gdispGetDisplay()` to retrieve the individual layers. From 8804f3a381552f6e98f50b7e28776363a2a4cf1d Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 17 Aug 2021 15:55:02 +0200 Subject: [PATCH 15/31] STM32LTDC: Fix misspelled macro (internally only) --- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 716bb93d..56a716b2 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -111,7 +111,7 @@ typedef struct ltdcConfig { /* Driver local routines. */ /*===========================================================================*/ -#define PIXIL_POS(g, x, y) ((y) * ((ltdcLayerConfig *)g->priv)->pitch + (x) * LTDC_PIXELBYTES) +#define PIXEL_POS(g, x, y) ((y) * ((ltdcLayerConfig *)g->priv)->pitch + (x) * LTDC_PIXELBYTES) #define PIXEL_ADDR(g, pos) ((LLDCOLOR_TYPE *)((gU8 *)((ltdcLayerConfig *)g->priv)->frame+pos)) /*===========================================================================*/ @@ -288,20 +288,20 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay* g) { switch(g->g.Orientation) { case gOrientation0: default: - pos = PIXIL_POS(g, g->p.x, g->p.y); + pos = PIXEL_POS(g, g->p.x, g->p.y); break; case gOrientation90: - pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); + pos = PIXEL_POS(g, g->p.y, g->g.Width-g->p.x-1); break; case gOrientation180: - pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); + pos = PIXEL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); break; case gOrientation270: - pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); + pos = PIXEL_POS(g, g->g.Height-g->p.y-1, g->p.x); break; } #else - pos = PIXIL_POS(g, g->p.x, g->p.y); + pos = PIXEL_POS(g, g->p.x, g->p.y); #endif #if STM32LTDC_USE_DMA2D @@ -326,20 +326,20 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { switch(g->g.Orientation) { case gOrientation0: default: - pos = PIXIL_POS(g, g->p.x, g->p.y); + pos = PIXEL_POS(g, g->p.x, g->p.y); break; case gOrientation90: - pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); + pos = PIXEL_POS(g, g->p.y, g->g.Width-g->p.x-1); break; case gOrientation180: - pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); + pos = PIXEL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); break; case gOrientation270: - pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); + pos = PIXEL_POS(g, g->g.Height-g->p.y-1, g->p.x); break; } #else - pos = PIXIL_POS(g, g->p.x, g->p.y); + pos = PIXEL_POS(g, g->p.x, g->p.y); #endif #if STM32LTDC_USE_DMA2D @@ -440,28 +440,28 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { switch(g->g.Orientation) { case gOrientation0: default: - pos = PIXIL_POS(g, g->p.x, g->p.y); + pos = PIXEL_POS(g, g->p.x, g->p.y); lineadd = g->g.Width - g->p.cx; shape = (g->p.cx << 16) | (g->p.cy); break; case gOrientation90: - pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-g->p.cx); + pos = PIXEL_POS(g, g->p.y, g->g.Width-g->p.x-g->p.cx); lineadd = g->g.Height - g->p.cy; shape = (g->p.cy << 16) | (g->p.cx); break; case gOrientation180: - pos = PIXIL_POS(g, g->g.Width-g->p.x-g->p.cx, g->g.Height-g->p.y-g->p.cy); + pos = PIXEL_POS(g, g->g.Width-g->p.x-g->p.cx, g->g.Height-g->p.y-g->p.cy); lineadd = g->g.Width - g->p.cx; shape = (g->p.cx << 16) | (g->p.cy); break; case gOrientation270: - pos = PIXIL_POS(g, g->g.Height-g->p.y-g->p.cy, g->p.x); + pos = PIXEL_POS(g, g->g.Height-g->p.y-g->p.cy, g->p.x); lineadd = g->g.Height - g->p.cy; shape = (g->p.cy << 16) | (g->p.cx); break; } #else - pos = PIXIL_POS(g, g->p.x, g->p.y); + pos = PIXEL_POS(g, g->p.x, g->p.y); lineadd = g->g.Width - g->p.cx; shape = (g->p.cx << 16) | (g->p.cy); #endif @@ -529,7 +529,7 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { gU32 srcstart, dststart; srcstart = LTDC_PIXELBYTES * ((gU32)g->p.x2 * g->p.y1 * + g->p.x1) + (gU32)g->p.ptr; - dststart = (gU32)PIXEL_ADDR(g, PIXIL_POS(g, g->p.x, g->p.y)); + dststart = (gU32)PIXEL_ADDR(g, PIXEL_POS(g, g->p.x, g->p.y)); #if STM32LTDC_DMA_CACHE_FLUSH { From 5e3159064ab5c7c1f1c029ca372d6200317f7564 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 17 Aug 2021 15:56:06 +0200 Subject: [PATCH 16/31] Fix typo in readme --- drivers/gdisp/STM32LTDC/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gdisp/STM32LTDC/readme.md b/drivers/gdisp/STM32LTDC/readme.md index cd7f4578..e1e9baf9 100644 --- a/drivers/gdisp/STM32LTDC/readme.md +++ b/drivers/gdisp/STM32LTDC/readme.md @@ -18,7 +18,7 @@ Configuration options available in `gfxconf.h`: | Option | Default | Description | | --- | --- | --- | -| `STM32LTDC_DMA_CACHE_FLUSH` | `GFOFF` | Whether to flush the DMA cache on DMA2D operations. This will be turned on automatically on certian platforms/systems. | +| `STM32LTDC_DMA_CACHE_FLUSH` | `GFXOFF` | Whether to flush the DMA cache on DMA2D operations. This will be turned on automatically on certian platforms/systems. | | `STM32LTDC_USE_DMA2D` | `GFXON` | Whether to use the DMA2D peripheral for hardware acceleration. | | `STM32LTDC_USE_LAYER2` | `GFXOFF` | Whether to use the 2nd LTDC layer. | | `STM32LTDC_USE_RGB565` | `GFXOFF` | Whether to use RGB565 instead of RGB888. | From 08c2358542135423a5752b9492c0784efaf2ba99 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 16:38:23 +0200 Subject: [PATCH 17/31] STM32LTDC: Support double buffering --- .../chibios/board_STM32LTDC.h | 2 +- .../STM32F439i-Eval/CubeHal/board_STM32LTDC.h | 2 +- .../STM32F746-Discovery/board_STM32LTDC.h | 2 +- .../STM32LTDC/board_STM32LTDC_template.h | 2 +- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 66 ++++++++++++++----- drivers/gdisp/STM32LTDC/gdisp_lld_config.h | 8 ++- drivers/gdisp/STM32LTDC/readme.md | 53 ++++++++++++++- 7 files changed, 113 insertions(+), 22 deletions(-) diff --git a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h index f599c81e..cdcb69f9 100644 --- a/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h +++ b/boards/base/STM32F429i-Discovery/chibios/board_STM32LTDC.h @@ -45,7 +45,7 @@ static const ltdcConfig driverCfg = { 0xFF, // alpha LTDC_LEF_ENABLE // flags }, -#if STM32LTDC_USE_LAYER2 +#if STM32LTDC_USE_LAYER2 || STM32LTDC_USE_DOUBLEBUFFERING { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_BANK_ADDR+(240 * 320 * LTDC_PIXELBYTES)), // Frame buffer address 240, 320, // width, height diff --git a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h index c78cc982..2a423761 100644 --- a/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h +++ b/boards/base/STM32F439i-Eval/CubeHal/board_STM32LTDC.h @@ -46,7 +46,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if STM32LTDC_USE_LAYER2 +#if STM32LTDC_USE_LAYER2 || STM32LTDC_USE_DOUBLEBUFFERING { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(640 * 480 * LTDC_PIXELBYTES)), // Frame buffer address 640, 480, // Width, Height (pixels) diff --git a/boards/base/STM32F746-Discovery/board_STM32LTDC.h b/boards/base/STM32F746-Discovery/board_STM32LTDC.h index 2c28103a..0d1214c3 100644 --- a/boards/base/STM32F746-Discovery/board_STM32LTDC.h +++ b/boards/base/STM32F746-Discovery/board_STM32LTDC.h @@ -60,7 +60,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if STM32LTDC_USE_LAYER2 +#if STM32LTDC_USE_LAYER2 || STM32LTDC_USE_DOUBLEBUFFERING { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(480 * 272 * LTDC_PIXELBYTES)), // Frame buffer address 480, 272, // Width, Height (pixels) diff --git a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h index 91623334..70b7c024 100644 --- a/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h +++ b/drivers/gdisp/STM32LTDC/board_STM32LTDC_template.h @@ -32,7 +32,7 @@ static const ltdcConfig driverCfg = { LTDC_LEF_ENABLE // Layer configuration flags }, -#if STM32LTDC_USE_LAYER2 +#if STM32LTDC_USE_LAYER2 || STM32LTDC_USE_DOUBLEBUFFERING { // Foreground layer config (if turned on) (LLDCOLOR_TYPE *)(SDRAM_DEVICE_ADDR+(480 * 272 * LTDC_PIXELBYTES)), // Frame buffer address 480, 272, // Width, Height (pixels) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 56a716b2..278a2aea 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -40,6 +40,17 @@ #define STM32LTDC_USE_RGB565 GFXOFF #endif +// Prevent usage of 2nd layer and double buffering at the same time. +// See readme.md for more inforamtion. +#if STM32LTDC_USE_LAYER2 && STM32LTDC_USE_DOUBLEBUFFERING + #error "GDISP - STM32LTDC: Cannot use 2nd LTDC layer and double buffering at the same time. See the driver's readme.md for more information." +#endif + +// Double buffering requires GDISP_NEED_CONTROL for the buffer swap command +#if STM32LTDC_USE_DOUBLEBUFFERING && !GDISP_NEED_CONTROL + #error "GDISP - STM32LTDC: Double buffering requires GDISP_NEED_CONTROL." +#endif + // Force DMA cache flushing on certain platforms/systems. #if STM32LTDC_USE_DMA2D #if defined(STM32F7) || defined(STM32H7) || defined(STM32F746xx) @@ -73,8 +84,8 @@ typedef struct ltdcConfig { gCoord hsync, vsync; // Horizontal and Vertical sync pixels gCoord hbackporch, vbackporch; // Horizontal and Vertical back porch pixels gCoord hfrontporch, vfrontporch; // Horizontal and Vertical front porch pixels - gU32 syncflags; // Sync flags - gU32 bgcolor; // Clear screen color RGB888 + gU32 syncflags; // Sync flags + gU32 bgcolor; // Clear screen color RGB888 ltdcLayerConfig bglayer; // Background layer config ltdcLayerConfig fglayer; // Foreground layer config @@ -225,7 +236,8 @@ LLDSPEC gBool gdisp_lld_init(GDisplay* g) { g->board = 0; switch(g->controllerdisplay) { - case 0: // Display 0 is the background layer + // Display 0 is the background layer + case 0: // Init the board init_board(g); @@ -250,23 +262,26 @@ LLDSPEC gBool gdisp_lld_init(GDisplay* g) { break; - case 1: // Display 1 is the foreground layer - - if (!(driverCfg.fglayer.layerflags & LTDC_LEF_ENABLE)) - return gFalse; - - // Load the foreground layer - _ltdc_layer_init(LTDC_Layer2, &driverCfg.fglayer); - _ltdc_reload(); - + // Display 1 is the foreground layer or the 2nd buffer for double buffering + case 1: g->priv = (void *)&driverCfg.fglayer; - // Finish Init the board - post_init_board(g); + #if STM32LTDC_USE_LAYER2 + if (!(driverCfg.fglayer.layerflags & LTDC_LEF_ENABLE)) + return gFalse; + + // Load the foreground layer + _ltdc_layer_init(LTDC_Layer2, &driverCfg.fglayer); + _ltdc_reload(); + + // Finish Init the board + post_init_board(g); + #endif break; - default: // There is only 1 LTDC in the CPU and only the 2 layers in the LTDC. + // There is only 1 LTDC in the CPU and only the 2 layers in the LTDC. + default: return gFalse; } @@ -396,6 +411,27 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { set_backlight(g, (unsigned)g->p.ptr); g->g.Backlight = (unsigned)g->p.ptr; return; + + #if STM32LTDC_USE_DOUBLEBUFFERING + case STM32LTDC_CONTROL_SHOW_BUFFER: + { + // Wait for end-of-line interrupt + // We use simple polling here as end-of-line interrupts are very frequent and usually happen in sub-millisecond intervals. + while (LTDC->ISR & LTDC_ISR_LIF); + + // Update framebuffer address in LTDC register + // As we currently only support one layer when doublebuffering is enabled, this change happens only to layer 1. + LTDC_Layer1->CFBAR = (gU32)(((ltdcLayerConfig*)g->priv)->frame) & LTDC_LxCFBAR_CFBADD; + + // Reload after LTDC config register modifications + _ltdc_reload(); + + return; + } + #endif + + default: + return; } } #endif diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h index 75190eb8..1ea27d9a 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h @@ -20,7 +20,6 @@ // Both these pixel formats are supported - pick one. // RGB565 obviously is faster and uses less RAM but with lower color resolution than RGB888 - #if defined(STM32LTDC_USE_RGB565) && STM32LTDC_USE_RGB565 #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 #if GDISP_TOTAL_DISPLAYS > 1 @@ -30,11 +29,16 @@ #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 #endif - /*===========================================================================*/ /* Don't change stuff below this line. Please. */ /*===========================================================================*/ +// LLD command to swap buffers if double buffering is enabled. +#if STM32LTDC_USE_DOUBLEBUFFERING + #define STM32LTDC_CONTROL_SHOW_BUFFER (GDISP_CONTROL_LLD+0) +#endif + +// Adjust driver config if DMA2D is enabled. #if STM32LTDC_USE_DMA2D // DMA2D supports accelerated fills #define GDISP_HARDWARE_FILLS GFXON diff --git a/drivers/gdisp/STM32LTDC/readme.md b/drivers/gdisp/STM32LTDC/readme.md index e1e9baf9..d9395ede 100644 --- a/drivers/gdisp/STM32LTDC/readme.md +++ b/drivers/gdisp/STM32LTDC/readme.md @@ -20,7 +20,8 @@ Configuration options available in `gfxconf.h`: | --- | --- | --- | | `STM32LTDC_DMA_CACHE_FLUSH` | `GFXOFF` | Whether to flush the DMA cache on DMA2D operations. This will be turned on automatically on certian platforms/systems. | | `STM32LTDC_USE_DMA2D` | `GFXON` | Whether to use the DMA2D peripheral for hardware acceleration. | -| `STM32LTDC_USE_LAYER2` | `GFXOFF` | Whether to use the 2nd LTDC layer. | +| `STM32LTDC_USE_LAYER2` | `GFXOFF` | Whether to use the 2nd LTDC layer. See the corresponding section below. | +| `STM32LTDC_USE_DOUBLEBUFFERING` | `GFXOFF` | Whether to use double buffering. See the corresponding section below. | | `STM32LTDC_USE_RGB565` | `GFXOFF` | Whether to use RGB565 instead of RGB888. | # 2nd layer @@ -31,3 +32,53 @@ The 2nd layer is exposed as a separate display. Use `gdispGetDisplay()` to retri For more information, see: - https://wiki.ugfx.io/index.php/Multiple_displays#Example_-_Same_controller - https://wiki.ugfx.io/index.php/Multiple_displays#Access_the_displays + +# Double buffering +Double buffering can be enabled by setting `STM32LTDC_USE_DOUBLEBUFFERING` to `GFXON`. + +When double buffering is enabled, the 2nd LTDC layer cannot be used. While this limitation is easy to remove from a software perspective, there is little benefit in doing so. Double buffering requires, as the name implies, twice the memory. If the 2nd layer would be used together with double buffering strategy, a total of four full framebuffers would be required. Years of real-world experience shows that there's practically never enough memory bandwidth available to do this. + +To use double buffering in an application, retrieve the two buffers via `gdispGetDisplay()`. +Whenever a buffer swap is necessary, use `gdispGControl(g, STM32LTDC_CONTROL_SHOW_BUFFER, NULL);` where `g` is the buffer to be shown. + +Simple example: +```c +#include "gfx.h" + +static GDisplay* _display1; +static GDisplay* _display2; + +// Requests a buffer swap on the driver level +static void _setActiveBuffer(GDisplay* g) +{ + gdispGControl(g, STM32LTDC_CONTROL_SHOW_BUFFER, NULL); +} + +int main(void) +{ + // Initialize uGFX library + gfxInit(); + + // Get the two buffers + _display1 = gdispGetDisplay(0); + if (!_display1) + gfxHalt("could not get display 1"); + _display2 = gdispGetDisplay(1); + if (!_display2) + gfxHalt("could not get display 2"); + + // Render to each buffer + gdispGClear(_display1, GFX_BLUE); + gdispGClear(_display2, GFX_RED); + + // Switch between buffers + while (gTrue) { + gfxSleepMilliseconds(800); + _setActiveBuffer(_display1); + gfxSleepMilliseconds(800); + _setActiveBuffer(_display2); + } + + return 0; +} +``` From d980418e8127f12c3b1957ca2610c98704cff7a4 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 16:46:04 +0200 Subject: [PATCH 18/31] STM32LTDC: Update readme.md --- drivers/gdisp/STM32LTDC/readme.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gdisp/STM32LTDC/readme.md b/drivers/gdisp/STM32LTDC/readme.md index d9395ede..564f6d59 100644 --- a/drivers/gdisp/STM32LTDC/readme.md +++ b/drivers/gdisp/STM32LTDC/readme.md @@ -25,7 +25,9 @@ Configuration options available in `gfxconf.h`: | `STM32LTDC_USE_RGB565` | `GFXOFF` | Whether to use RGB565 instead of RGB888. | # 2nd layer -To use the 2nd LTDC layer, set `STM32LTDC_USE_LAYER2` to `GFXON` in `gfxconf.h`. +To use the 2nd LTDC layer: + - set `STM32LTDC_USE_LAYER2` to `GFXON` in `gfxconf.h`. + - set `GDISP_TOTAL_DISPLAYS` to `2` in `gfxconf.h`. The 2nd layer is exposed as a separate display. Use `gdispGetDisplay()` to retrieve the individual layers. @@ -34,7 +36,9 @@ For more information, see: - https://wiki.ugfx.io/index.php/Multiple_displays#Access_the_displays # Double buffering -Double buffering can be enabled by setting `STM32LTDC_USE_DOUBLEBUFFERING` to `GFXON`. +To use double buffering: + - set `STM32LTDC_USE_DOUBLEBUFFERING` to `GFXON` in `gfxconf.h`. + - set `GDISP_TOTAL_DISPLAYS` to `2` in `gfxconf.h`. When double buffering is enabled, the 2nd LTDC layer cannot be used. While this limitation is easy to remove from a software perspective, there is little benefit in doing so. Double buffering requires, as the name implies, twice the memory. If the 2nd layer would be used together with double buffering strategy, a total of four full framebuffers would be required. Years of real-world experience shows that there's practically never enough memory bandwidth available to do this. From 72200af286d262f6b4ba1431a97e2bf2e6d92f57 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 17:05:29 +0200 Subject: [PATCH 19/31] Update changelog.txt --- changelog.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 8138e766..7fdda575 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,7 +8,13 @@ FIX: Fixed GWIN console widget scroll FIX: A warning and adjusted is made if GDISP_IMAGE_BMP_BLIT_BUFFER_SIZE is less than 40 bytes. FIX: Prevent compiler warnings on duplicate const specifiers. FEATURE: Added support for ChibiOS 6.x kernel. -CHANGE: Refactor STM32LTDC driver to outsource hardware specifics such as clock setup to the board file. +CHANGE: STM32LTDC driver: Refactor to outsource clock setup for LTDC & DMA2D peripherals to the board file. +CHANGE: STM32LTDC driver: Remove obsolete LTDC_NO_CLOCK_INIT macro as this clock setup is now outsourced to the board file. +CHANGE: STM32LTDC driver: Automatically enable DMA cache flushing on STM32H7 platforms. +CHANGE: STM32LTDC driver: Rename ALLOW_2ND_LAYER to STM32LTDC_USE_LAYER2. +CHANGE: STM32LTDC driver: Rename LTDC_DMA_CACHE_FLUSH to STM32LTDC_DMA_CACHE_FLUSH. +CHANGE: STM32LTDC driver: Rename GDISP_LTDC_USE_RGB565 to STM32LTDC_USE_RGB565. +FEATURE: STM32LTDC driver: Support double buffering. This introduces STM32LTDC_USE_DOUBLEBUFFERING. *** Release 2.9 *** From 77f10024e0bb51688fe6d28cb196205da3b4e70c Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 17:12:12 +0200 Subject: [PATCH 20/31] STM32LTDC: Improve pixel format detection if 2nd layer is used This is necessary as using double buffering via STM32LTDC_USE_DOUBLEBUFFERING will also result in GDISP_TOTAL_DISPLAYS being larger than 1. --- drivers/gdisp/STM32LTDC/gdisp_lld_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h index 1ea27d9a..38fbad7f 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h @@ -22,8 +22,8 @@ // RGB565 obviously is faster and uses less RAM but with lower color resolution than RGB888 #if defined(STM32LTDC_USE_RGB565) && STM32LTDC_USE_RGB565 #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 - #if GDISP_TOTAL_DISPLAYS > 1 - #error "GDISP - STM32LTDC: You must use RGB888 pixel format with LTDC when using dual layers as only RGB888 currently supports using alpha" + #if defined(STM32LTDC_USE_LAYER2) && STM32LTDC_USE_LAYER2 + #error "GDISP - STM32LTDC: You must use RGB888 pixel format with LTDC when using both layers as only RGB888 currently supports using alpha." #endif #else #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 From 409b8d449005f7ca62898d6e8b7b299ef817a37d Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 18:09:49 +0200 Subject: [PATCH 21/31] Update changelog.txt --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 7fdda575..4985986a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -11,6 +11,7 @@ FEATURE: Added support for ChibiOS 6.x kernel. CHANGE: STM32LTDC driver: Refactor to outsource clock setup for LTDC & DMA2D peripherals to the board file. CHANGE: STM32LTDC driver: Remove obsolete LTDC_NO_CLOCK_INIT macro as this clock setup is now outsourced to the board file. CHANGE: STM32LTDC driver: Automatically enable DMA cache flushing on STM32H7 platforms. +CHANGE: STM32LTDC driver: Rename LTDC_USE_DMA2D to STM32LTDC_USE_DMA2D. CHANGE: STM32LTDC driver: Rename ALLOW_2ND_LAYER to STM32LTDC_USE_LAYER2. CHANGE: STM32LTDC driver: Rename LTDC_DMA_CACHE_FLUSH to STM32LTDC_DMA_CACHE_FLUSH. CHANGE: STM32LTDC driver: Rename GDISP_LTDC_USE_RGB565 to STM32LTDC_USE_RGB565. From c57bd0837968395cc0375fd98abcb3f3ba27cac7 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 18:26:41 +0200 Subject: [PATCH 22/31] Fix comment --- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 278a2aea..d7b37a3e 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -610,6 +610,6 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { } #endif -#endif /* LTDC_USE_DMA2D */ +#endif /* STM32LTDC_USE_DMA2D */ #endif /* GFX_USE_GDISP */ From b98a6c258ca73e2dc3c20a85380d7c18b3a5441d Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 19:17:04 +0200 Subject: [PATCH 23/31] Update /demos/benchmarks This uses GOS functionalities to count ticks instead of hardware specific cycle counters. --- demos/benchmarks/main.c | 123 ++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 82 deletions(-) diff --git a/demos/benchmarks/main.c b/demos/benchmarks/main.c index f010dd57..1aebac46 100644 --- a/demos/benchmarks/main.c +++ b/demos/benchmarks/main.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu - * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket + * Copyright (c) 2012 - 2021, Joel Bodenmann aka Tectu + * Copyright (c) 2012 - 2021, Andrew Hannam aka inmarket * * All rights reserved. * @@ -31,87 +31,33 @@ #include "string.h" #include "gfx.h" -#define SCB_DEMCR (*(volatile unsigned *)0xE000EDFC) -#define CPU_RESET_CYCLECOUNTER do { SCB_DEMCR = SCB_DEMCR | 0x01000000; \ -DWT_CYCCNT = 0; \ -DWT_CTRL = DWT_CTRL | 1 ; } while(0) +#define RESULT_STR_LENGTH 32 -static int uitoa(unsigned int value, char * buf, int max) { - int n = 0; - int i = 0; - unsigned int tmp = 0; - - if (!buf) - return -3; - - if (2 > max) - return -4; - - i=1; - tmp = value; - if (0 > tmp) { - tmp *= -1; - i++; - } - for (;;) { - tmp /= 10; - if (0 >= tmp) - break; - i++; - } - if (i >= max) { - buf[0] = '?'; - buf[1] = 0x0; - return 2; - } - - n = i; - tmp = value; - if (0 > tmp) { - tmp *= -1; - } - buf[i--] = 0x0; - for (;;) { - buf[i--] = (tmp % 10) + '0'; - tmp /= 10; - if (0 >= tmp) { - break; - } - } - if (-1 != i) { - buf[i--] = '-'; - } - - return n; -} - -void benchmark(void) { - gU32 i, pixels, ms, pps; - char pps_str[25]; +void benchmark(void) +{ gCoord height, width, rx, ry, rcx, rcy; gColor random_color; + gCoord fontHeight; gFont font; - gdispSetOrientation(gOrientation90); - + // Prepare resources width = gdispGetWidth(); height = gdispGetHeight(); - font = gdispOpenFont("UI2 Double"); + font = gdispOpenFont("*"); + fontHeight = gdispGetFontMetric(font, gFontHeight); + // Show intro message gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter); - - font = gdispOpenFont("UI2"); gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, GFX_WHITE, gJustifyCenter); - gfxSleepMilliseconds(3000); - /* seed for the rand() */ - srand(DWT_CYCCNT); - pixels = 0; + // Seed RNG + srand(0); - CPU_RESET_CYCLECOUNTER; - - for (i = 0; i < 5000; i++) { + // Render rectangles and count ticks & pixels + gU64 pixels = 0; + const gTicks ticksStart = gfxSystemTicks(); + for (gU32 i = 0; i < 5000; i++) { random_color = (rand() % 65535); rx = (rand() % (width-10)); ry = (rand() % (height-10)); @@ -121,19 +67,33 @@ void benchmark(void) { gdispFillArea(rx, ry, rcx, rcy, random_color); pixels += (rcx+1)*(rcy+1); } + const gTicks ticksEnd = gfxSystemTicks(); + + // Calculate result + char str_ticks[RESULT_STR_LENGTH]; + char str_seconds[RESULT_STR_LENGTH]; + char str_pps[RESULT_STR_LENGTH]; + { + // Figure out how many ticks are 1 second + const gTicks ticksPerSecond = gfxMillisecondsToTicks(1000); + + const gTicks ticksElapsed = ticksEnd - ticksStart; + const float secondsElapsed = (float)ticksElapsed / (float)ticksPerSecond; + gU32 pps = (float)pixels / secondsElapsed; - ms = DWT_CYCCNT / 168000; - pps = (float)pixels/((float)ms/1000.0f); + // Produce strings + memset(str_ticks, 0, RESULT_STR_LENGTH); + memset(str_seconds, 0, RESULT_STR_LENGTH); + memset(str_pps, 0, RESULT_STR_LENGTH); + snprintg(str_ticks, RESULT_STR_LENGTH, "%d ticks", ticksElapsed); + snprintg(str_pps, RESULT_STR_LENGTH, "%d pixels/s", pps); + } - memset (pps_str, 0, sizeof(pps_str)); - uitoa(pps, pps_str, sizeof(pps_str)); - strcat(pps_str, " Pixels/s"); - - font = gdispOpenFont("UI2 Double"); + // Show result gdispClear(GFX_BLACK); - gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, GFX_WHITE, gJustifyCenter); - gdispDrawStringBox(0, height/2, width, 30, pps_str, font, GFX_WHITE, gJustifyCenter); - //gdispDrawString(20, height/2, pps_str, font, GFX_WHITE); + gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter); + gdispDrawStringBox(0, height/2+0*(fontHeight+10), width, 30, str_ticks, font, GFX_WHITE, gJustifyCenter); + gdispDrawStringBox(0, height/2+1*(fontHeight+10), width, 30, str_pps, font, GFX_WHITE, gJustifyCenter); } int main(void) { @@ -141,9 +101,8 @@ int main(void) { benchmark(); - while(1) { + while (gTrue) gfxSleepMilliseconds(500); - } return 0; } From c713719326b610403b7db195d43b9d172fed3967 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 19:18:04 +0200 Subject: [PATCH 24/31] Update /demos/benchmarks configuration file --- demos/benchmarks/gfxconf.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/demos/benchmarks/gfxconf.h b/demos/benchmarks/gfxconf.h index 3133e757..e9f15e54 100644 --- a/demos/benchmarks/gfxconf.h +++ b/demos/benchmarks/gfxconf.h @@ -48,5 +48,10 @@ /* Builtin Fonts */ #define GDISP_INCLUDE_FONT_UI2 GFXON +/* GFILE */ +#define GFX_USE_GFILE GFXON +#define GFILE_NEED_PRINTG GFXON +#define GFILE_NEED_STRINGS GFXON + #endif /* _GFXCONF_H */ From 853f2cba981a072159c2626d4f7817b4ce88ab7e Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 20:51:56 +0200 Subject: [PATCH 25/31] Relocate current benchmark to /demos/benchmarks/rectangles --- changelog.txt | 1 + demos/benchmarks/{ => rectangles}/demo.mk | 0 demos/benchmarks/{ => rectangles}/gfxconf.h | 0 demos/benchmarks/{ => rectangles}/main.c | 216 ++++++++++---------- 4 files changed, 109 insertions(+), 108 deletions(-) rename demos/benchmarks/{ => rectangles}/demo.mk (100%) rename demos/benchmarks/{ => rectangles}/gfxconf.h (100%) rename demos/benchmarks/{ => rectangles}/main.c (97%) diff --git a/changelog.txt b/changelog.txt index 4985986a..36657d48 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,6 +16,7 @@ CHANGE: STM32LTDC driver: Rename ALLOW_2ND_LAYER to STM32LTDC_USE_LAYER2. CHANGE: STM32LTDC driver: Rename LTDC_DMA_CACHE_FLUSH to STM32LTDC_DMA_CACHE_FLUSH. CHANGE: STM32LTDC driver: Rename GDISP_LTDC_USE_RGB565 to STM32LTDC_USE_RGB565. FEATURE: STM32LTDC driver: Support double buffering. This introduces STM32LTDC_USE_DOUBLEBUFFERING. +FIX: Improve /demos/benchmarks/rectangles *** Release 2.9 *** diff --git a/demos/benchmarks/demo.mk b/demos/benchmarks/rectangles/demo.mk similarity index 100% rename from demos/benchmarks/demo.mk rename to demos/benchmarks/rectangles/demo.mk diff --git a/demos/benchmarks/gfxconf.h b/demos/benchmarks/rectangles/gfxconf.h similarity index 100% rename from demos/benchmarks/gfxconf.h rename to demos/benchmarks/rectangles/gfxconf.h diff --git a/demos/benchmarks/main.c b/demos/benchmarks/rectangles/main.c similarity index 97% rename from demos/benchmarks/main.c rename to demos/benchmarks/rectangles/main.c index 1aebac46..458b298d 100644 --- a/demos/benchmarks/main.c +++ b/demos/benchmarks/rectangles/main.c @@ -1,108 +1,108 @@ -/* - * Copyright (c) 2012 - 2021, Joel Bodenmann aka Tectu - * Copyright (c) 2012 - 2021, Andrew Hannam aka inmarket - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "stdlib.h" -#include "string.h" -#include "gfx.h" - -#define RESULT_STR_LENGTH 32 - -void benchmark(void) -{ - gCoord height, width, rx, ry, rcx, rcy; - gColor random_color; - gCoord fontHeight; - gFont font; - - // Prepare resources - width = gdispGetWidth(); - height = gdispGetHeight(); - font = gdispOpenFont("*"); - fontHeight = gdispGetFontMetric(font, gFontHeight); - - // Show intro message - gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter); - gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, GFX_WHITE, gJustifyCenter); - gfxSleepMilliseconds(3000); - - // Seed RNG - srand(0); - - // Render rectangles and count ticks & pixels - gU64 pixels = 0; - const gTicks ticksStart = gfxSystemTicks(); - for (gU32 i = 0; i < 5000; i++) { - random_color = (rand() % 65535); - rx = (rand() % (width-10)); - ry = (rand() % (height-10)); - rcx = (rand() % ((width-rx)-10))+10; - rcy = (rand() % ((height-ry)-10))+10; - - gdispFillArea(rx, ry, rcx, rcy, random_color); - pixels += (rcx+1)*(rcy+1); - } - const gTicks ticksEnd = gfxSystemTicks(); - - // Calculate result - char str_ticks[RESULT_STR_LENGTH]; - char str_seconds[RESULT_STR_LENGTH]; - char str_pps[RESULT_STR_LENGTH]; - { - // Figure out how many ticks are 1 second - const gTicks ticksPerSecond = gfxMillisecondsToTicks(1000); - - const gTicks ticksElapsed = ticksEnd - ticksStart; - const float secondsElapsed = (float)ticksElapsed / (float)ticksPerSecond; - gU32 pps = (float)pixels / secondsElapsed; - - // Produce strings - memset(str_ticks, 0, RESULT_STR_LENGTH); - memset(str_seconds, 0, RESULT_STR_LENGTH); - memset(str_pps, 0, RESULT_STR_LENGTH); - snprintg(str_ticks, RESULT_STR_LENGTH, "%d ticks", ticksElapsed); - snprintg(str_pps, RESULT_STR_LENGTH, "%d pixels/s", pps); - } - - // Show result - gdispClear(GFX_BLACK); - gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter); - gdispDrawStringBox(0, height/2+0*(fontHeight+10), width, 30, str_ticks, font, GFX_WHITE, gJustifyCenter); - gdispDrawStringBox(0, height/2+1*(fontHeight+10), width, 30, str_pps, font, GFX_WHITE, gJustifyCenter); -} - -int main(void) { - gfxInit(); - - benchmark(); - - while (gTrue) - gfxSleepMilliseconds(500); - - return 0; -} +/* + * Copyright (c) 2012 - 2021, Joel Bodenmann aka Tectu + * Copyright (c) 2012 - 2021, Andrew Hannam aka inmarket + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stdlib.h" +#include "string.h" +#include "gfx.h" + +#define RESULT_STR_LENGTH 32 + +void benchmark(void) +{ + gCoord height, width, rx, ry, rcx, rcy; + gColor random_color; + gCoord fontHeight; + gFont font; + + // Prepare resources + width = gdispGetWidth(); + height = gdispGetHeight(); + font = gdispOpenFont("*"); + fontHeight = gdispGetFontMetric(font, gFontHeight); + + // Show intro message + gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter); + gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, GFX_WHITE, gJustifyCenter); + gfxSleepMilliseconds(3000); + + // Seed RNG + srand(0); + + // Render rectangles and count ticks & pixels + gU64 pixels = 0; + const gTicks ticksStart = gfxSystemTicks(); + for (gU32 i = 0; i < 5000; i++) { + random_color = (rand() % 65535); + rx = (rand() % (width-10)); + ry = (rand() % (height-10)); + rcx = (rand() % ((width-rx)-10))+10; + rcy = (rand() % ((height-ry)-10))+10; + + gdispFillArea(rx, ry, rcx, rcy, random_color); + pixels += (rcx+1)*(rcy+1); + } + const gTicks ticksEnd = gfxSystemTicks(); + + // Calculate result + char str_ticks[RESULT_STR_LENGTH]; + char str_seconds[RESULT_STR_LENGTH]; + char str_pps[RESULT_STR_LENGTH]; + { + // Figure out how many ticks are 1 second + const gTicks ticksPerSecond = gfxMillisecondsToTicks(1000); + + const gTicks ticksElapsed = ticksEnd - ticksStart; + const float secondsElapsed = (float)ticksElapsed / (float)ticksPerSecond; + gU32 pps = (float)pixels / secondsElapsed; + + // Produce strings + memset(str_ticks, 0, RESULT_STR_LENGTH); + memset(str_seconds, 0, RESULT_STR_LENGTH); + memset(str_pps, 0, RESULT_STR_LENGTH); + snprintg(str_ticks, RESULT_STR_LENGTH, "%d ticks", ticksElapsed); + snprintg(str_pps, RESULT_STR_LENGTH, "%d pixels/s", pps); + } + + // Show result + gdispClear(GFX_BLACK); + gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter); + gdispDrawStringBox(0, height/2+0*(fontHeight+10), width, 30, str_ticks, font, GFX_WHITE, gJustifyCenter); + gdispDrawStringBox(0, height/2+1*(fontHeight+10), width, 30, str_pps, font, GFX_WHITE, gJustifyCenter); +} + +int main(void) { + gfxInit(); + + benchmark(); + + while (gTrue) + gfxSleepMilliseconds(500); + + return 0; +} From 888c7e8640caf02082adc23c967c5c0ba49a5146 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 18 Aug 2021 20:58:53 +0200 Subject: [PATCH 26/31] STM32LTDC: Fix bug in DMA2D blitting Thanks to @nathanwiebe for reporting this: https://community.ugfx.io/topic/3159-a-bug-in-the-stm32-ltdc-driver --- changelog.txt | 1 + drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 36657d48..a7dfbf34 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,6 +16,7 @@ CHANGE: STM32LTDC driver: Rename ALLOW_2ND_LAYER to STM32LTDC_USE_LAYER2. CHANGE: STM32LTDC driver: Rename LTDC_DMA_CACHE_FLUSH to STM32LTDC_DMA_CACHE_FLUSH. CHANGE: STM32LTDC driver: Rename GDISP_LTDC_USE_RGB565 to STM32LTDC_USE_RGB565. FEATURE: STM32LTDC driver: Support double buffering. This introduces STM32LTDC_USE_DOUBLEBUFFERING. +FIX: STM32LTDC driver: Fix bug in gdisp_lld_blit_area() which affected blits with source coordinates other than (0, 0). FIX: Improve /demos/benchmarks/rectangles diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index d7b37a3e..a2c5955f 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -564,7 +564,7 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { LLDSPEC void gdisp_lld_blit_area(GDisplay* g) { gU32 srcstart, dststart; - srcstart = LTDC_PIXELBYTES * ((gU32)g->p.x2 * g->p.y1 * + g->p.x1) + (gU32)g->p.ptr; + srcstart = LTDC_PIXELBYTES * ((gU32)g->p.x2 * g->p.y1 + g->p.x1) + (gU32)g->p.ptr; dststart = (gU32)PIXEL_ADDR(g, PIXEL_POS(g, g->p.x, g->p.y)); #if STM32LTDC_DMA_CACHE_FLUSH From b3216fa0cceaa6d2751a6e1602554d5da66d0436 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 19 Aug 2021 13:48:44 +0200 Subject: [PATCH 27/31] Minor doxygen fixes --- Doxygenfile | 2 +- src/gos/gos_zephyr.h | 2 +- src/gwin/gwin_container.c | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Doxygenfile b/Doxygenfile index 0df8e3b2..bfc1f574 100644 --- a/Doxygenfile +++ b/Doxygenfile @@ -1773,7 +1773,7 @@ COMPACT_LATEX = NO # The default value is: a4. # This tag requires that the tag GENERATE_LATEX is set to YES. -PAPER_TYPE = a4wide +PAPER_TYPE = a4 # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names # that should be included in the LaTeX output. The package can be specified just diff --git a/src/gos/gos_zephyr.h b/src/gos/gos_zephyr.h index 3213d5ca..a1dfe778 100644 --- a/src/gos/gos_zephyr.h +++ b/src/gos/gos_zephyr.h @@ -6,7 +6,7 @@ */ /** - * @file src/gos/gos_zepyhr.h + * @file src/gos/gos_zephyr.h * @brief GOS - Operating System Support header file for Zephyr RTOS. * Zephyr SDK 0.9.1 */ diff --git a/src/gwin/gwin_container.c b/src/gwin/gwin_container.c index 88c6d8b1..b8cc07b2 100644 --- a/src/gwin/gwin_container.c +++ b/src/gwin/gwin_container.c @@ -200,8 +200,10 @@ void gwinContainerDraw_Std(GWidgetObject *gw, void *param) { #undef gi } -#endif /* GDISP_NEED_IMAGE */ +#endif /* GDISP_NEED_IMAGE */ + +/** + * @} + */ #endif /* GFX_USE_GWIN && GWIN_NEED_CONTAINERS */ - -/** @} */ From b17cb215f418793fd23f0409379625c4237e0c3e Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 23 Aug 2021 15:26:15 +0200 Subject: [PATCH 28/31] STM32LTDC: Handle gOrientationPortrait and gOrientationLandscape explicitly although not supporting it --- drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c | 8 ++++++++ drivers/gdisp/STM32LTDC/readme.md | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index a2c5955f..5ec9a427 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -301,6 +301,8 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay* g) { #if GDISP_NEED_CONTROL switch(g->g.Orientation) { + case gOrientationPortrait: + case gOrientationLandscape: case gOrientation0: default: pos = PIXEL_POS(g, g->p.x, g->p.y); @@ -339,6 +341,8 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { #if GDISP_NEED_CONTROL switch(g->g.Orientation) { + case gOrientationPortrait: + case gOrientationLandscape: case gOrientation0: default: pos = PIXEL_POS(g, g->p.x, g->p.y); @@ -400,6 +404,8 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { g->g.Height = tmp; } break; + case gOrientationPortrait: + case gOrientationLandscape: default: return; } @@ -474,6 +480,8 @@ LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay* g) { #if GDISP_NEED_CONTROL switch(g->g.Orientation) { + case gOrientationPortrait: + case gOrientationLandscape: case gOrientation0: default: pos = PIXEL_POS(g, g->p.x, g->p.y); diff --git a/drivers/gdisp/STM32LTDC/readme.md b/drivers/gdisp/STM32LTDC/readme.md index 564f6d59..3489fc43 100644 --- a/drivers/gdisp/STM32LTDC/readme.md +++ b/drivers/gdisp/STM32LTDC/readme.md @@ -12,6 +12,10 @@ To use this driver: 3. Add a `board_STM32LTDC.h` to you project directory (or board directory) based on one of the templates. + +# Limitations +Currently, both `gOrientationPortrait` and `gOrientationLandscape` are not supported by this driver. + # Configuration Configuration options available in `gfxconf.h`: From ec257874a7da45826990bd75bb182d5394017dba Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 23 Aug 2021 15:28:06 +0200 Subject: [PATCH 29/31] GDISP: Explicitly handle gOrientation values where applicaple This addresses a compiler bug in some versions of GCC which warn about unhandled enum values although there is a default handler. --- src/gdisp/gdisp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 1ade4ff6..f58ebf7e 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -2885,6 +2885,10 @@ void gdispGBlitArea(GDisplay *g, gCoord x, gCoord y, gCoord cx, gCoord cy, gCoor case gOrientationPortrait: g->p.ptr = g->g.Width >= g->g.Height ? (void *)gOrientation90 : (void *)gOrientation0; break; + case gOrientation0: + case gOrientation90: + case gOrientation180: + case gOrientation270: default: break; } From 317db95c46578c399041f3f1a180bb1cd42a9faf Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 23 Aug 2021 15:46:22 +0200 Subject: [PATCH 30/31] GTRANS: Update types --- src/gtrans/gtrans.c | 2 +- src/gtrans/gtrans.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gtrans/gtrans.c b/src/gtrans/gtrans.c index 15630b20..ee2f3848 100644 --- a/src/gtrans/gtrans.c +++ b/src/gtrans/gtrans.c @@ -51,7 +51,7 @@ const char* gtransString(const char* string) return _languageCurrent->strings[i]; } -const char* gtransIndex(unsigned index) +const char* gtransIndex(gU32 index) { if (!_languageCurrent) { return 0; diff --git a/src/gtrans/gtrans.h b/src/gtrans/gtrans.h index d25b1c54..8abf0eab 100644 --- a/src/gtrans/gtrans.h +++ b/src/gtrans/gtrans.h @@ -27,7 +27,7 @@ * @brief A table containing translated strings. */ typedef struct transTable { - unsigned numEntries; /**< The number of strings that this table contains */ + gU32 numEntries; /**< The number of strings that this table contains */ const char** strings; /**< The translated strings */ } transTable; @@ -59,7 +59,7 @@ const char* gtransString(const char* string); * * @return The string at the given index of the current language or 0 if it doesn't exist. */ -const char* gtransIndex(unsigned index); +const char* gtransIndex(gU32 index); /** * @brief Set the base language. From 8d6b2c4707ec788a93cb0662b18dabf6784c7471 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 23 Aug 2021 15:46:47 +0200 Subject: [PATCH 31/31] GTRANS: Update /demos/modules/gtrans/basic --- demos/modules/gtrans/basic/gfxconf.h | 1 - demos/modules/gtrans/basic/main.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/demos/modules/gtrans/basic/gfxconf.h b/demos/modules/gtrans/basic/gfxconf.h index e41aaf03..3dfa5fe2 100644 --- a/demos/modules/gtrans/basic/gfxconf.h +++ b/demos/modules/gtrans/basic/gfxconf.h @@ -42,7 +42,6 @@ #define GDISP_NEED_VALIDATION GFXON #define GDISP_NEED_CLIP GFXON #define GDISP_NEED_TEXT GFXON -#define GDISP_NEED_ANTIALIAS GFXON #define GDISP_NEED_UTF8 GFXON #define GDISP_NEED_TEXT_KERNING GFXON diff --git a/demos/modules/gtrans/basic/main.c b/demos/modules/gtrans/basic/main.c index e4a6e608..cefb78d8 100644 --- a/demos/modules/gtrans/basic/main.c +++ b/demos/modules/gtrans/basic/main.c @@ -62,7 +62,7 @@ static const char* FrenchStrings[] = { }; static const transTable FrenchTranslation = { sizeof(FrenchStrings)/sizeof(FrenchStrings[0]), FrenchStrings }; -void updateText() +void updateText(void) { gCoord width = 400; gCoord height = 30;