diff --git a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/Makefile b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/Makefile index f163dad2..344e3bf4 100644 --- a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/Makefile +++ b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/Makefile @@ -16,10 +16,12 @@ GFXLIB = ../uGFX GFXBOARD = Mikromedia-Plus-STM32-M4 GFXDEMO = modules/gdisp/basics + GFXSINGLEMAKE = no # ChibiOS settings ifeq ($(OPT_OS),chibios) # See $(GFXLIB)/tools/gmake_scripts/os_chibios.mk for the list of variables + CHIBIOS_VERSION = 2 CHIBIOS = ../ChibiOS CHIBIOS_BOARD = CHIBIOS_PLATFORM = STM32F4xx @@ -34,7 +36,7 @@ endif # ARCH = arm-none-eabi- -SRCFLAGS = -ggdb -O0 +SRCFLAGS = -ggdb -O1 CFLAGS = CXXFLAGS = -fno-rtti ASFLAGS = diff --git a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/openocd.cfg b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/openocd.cfg index f8b6a6f5..b4395b52 100644 --- a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/openocd.cfg +++ b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_2.x/openocd.cfg @@ -1,4 +1,4 @@ -# This is a script file for OpenOCD 0.7.0 +# This is a script file for OpenOCD ?.?.? # # It is set up for the Mikromedia-STM32M4 board using the ST-Link JTAG adaptor. # @@ -32,11 +32,11 @@ source [find interface/stlink-v2.cfg] echo "" echo "##### Loading CPU..." -source [find target/stm32f4x_stlink.cfg] +source [find target/stm32f4x.cfg] echo "" echo "##### Configuring..." -reset_config srst_only srst_nogate +#reset_config srst_only srst_nogate #cortex_m maskisr (auto|on|off) #cortex_m vector_catch [all|none|list] #cortex_m reset_config (srst|sysresetreq|vectreset) @@ -58,10 +58,10 @@ proc Burn {file} { # If this happens to you - use the ST-Link utility to set the option byte back to normal. # If you are using a different debugger eg a FT2232 based adapter you can uncomment the line below. #stm32f2x unlock 0 - flash protect 0 0 last off - reset init - flash write_image erase $file 0x08000000 - verify_image $file 0x0 + #flash protect 0 0 last off + reset halt + flash write_image erase $file 0 elf + verify_image $file 0x0 elf #flash protect 0 0 last on reset echo "Burning Complete!" diff --git a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/Makefile b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/Makefile index 7f274b95..03ed9e2b 100644 --- a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/Makefile +++ b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/Makefile @@ -6,7 +6,7 @@ # Compiler options here. ifeq ($(USE_OPT),) # Replace -O0 with -O2 for a production build. -O2 just messes with the debugger. - USE_OPT = -O0 -g -fomit-frame-pointer -falign-functions=16 + USE_OPT = -O1 -g -fomit-frame-pointer -falign-functions=16 endif # C specific options here (added to USE_OPT). diff --git a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/openocd.cfg b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/openocd.cfg index f8b6a6f5..b4395b52 100644 --- a/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/openocd.cfg +++ b/boards/base/Mikromedia-Plus-STM32-M4/example_chibios_3.x/openocd.cfg @@ -1,4 +1,4 @@ -# This is a script file for OpenOCD 0.7.0 +# This is a script file for OpenOCD ?.?.? # # It is set up for the Mikromedia-STM32M4 board using the ST-Link JTAG adaptor. # @@ -32,11 +32,11 @@ source [find interface/stlink-v2.cfg] echo "" echo "##### Loading CPU..." -source [find target/stm32f4x_stlink.cfg] +source [find target/stm32f4x.cfg] echo "" echo "##### Configuring..." -reset_config srst_only srst_nogate +#reset_config srst_only srst_nogate #cortex_m maskisr (auto|on|off) #cortex_m vector_catch [all|none|list] #cortex_m reset_config (srst|sysresetreq|vectreset) @@ -58,10 +58,10 @@ proc Burn {file} { # If this happens to you - use the ST-Link utility to set the option byte back to normal. # If you are using a different debugger eg a FT2232 based adapter you can uncomment the line below. #stm32f2x unlock 0 - flash protect 0 0 last off - reset init - flash write_image erase $file 0x08000000 - verify_image $file 0x0 + #flash protect 0 0 last off + reset halt + flash write_image erase $file 0 elf + verify_image $file 0x0 elf #flash protect 0 0 last on reset echo "Burning Complete!" diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile index 7eb8eb3e..387656f6 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile @@ -20,6 +20,7 @@ # ChibiOS settings ifeq ($(OPT_OS),chibios) # See $(GFXLIB)/tools/gmake_scripts/os_chibios.mk for the list of variables + CHIBIOS_VERSION = 2 CHIBIOS = ../ChibiOS CHIBIOS_BOARD = CHIBIOS_PLATFORM = STM32F4xx @@ -34,7 +35,7 @@ endif # ARCH = arm-none-eabi- -SRCFLAGS = -ggdb -O0 +SRCFLAGS = -ggdb -O1 CFLAGS = CXXFLAGS = -fno-rtti ASFLAGS = diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/openocd.cfg b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/openocd.cfg index f8b6a6f5..83395e5a 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/openocd.cfg +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/openocd.cfg @@ -32,11 +32,11 @@ source [find interface/stlink-v2.cfg] echo "" echo "##### Loading CPU..." -source [find target/stm32f4x_stlink.cfg] +source [find target/stm32f4x.cfg] echo "" echo "##### Configuring..." -reset_config srst_only srst_nogate +#reset_config srst_only srst_nogate #cortex_m maskisr (auto|on|off) #cortex_m vector_catch [all|none|list] #cortex_m reset_config (srst|sysresetreq|vectreset) @@ -58,10 +58,10 @@ proc Burn {file} { # If this happens to you - use the ST-Link utility to set the option byte back to normal. # If you are using a different debugger eg a FT2232 based adapter you can uncomment the line below. #stm32f2x unlock 0 - flash protect 0 0 last off - reset init - flash write_image erase $file 0x08000000 - verify_image $file 0x0 + #flash protect 0 0 last off + reset halt + flash write_image erase $file 0 elf + verify_image $file 0x0 elf #flash protect 0 0 last on reset echo "Burning Complete!" diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile index a68e06e4..da6e199e 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile @@ -36,7 +36,7 @@ endif # ARCH = arm-none-eabi- -SRCFLAGS = -ggdb -O0 +SRCFLAGS = -ggdb -O1 CFLAGS = CXXFLAGS = -fno-rtti ASFLAGS = diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/openocd.cfg b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/openocd.cfg index f8b6a6f5..83395e5a 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/openocd.cfg +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/openocd.cfg @@ -32,11 +32,11 @@ source [find interface/stlink-v2.cfg] echo "" echo "##### Loading CPU..." -source [find target/stm32f4x_stlink.cfg] +source [find target/stm32f4x.cfg] echo "" echo "##### Configuring..." -reset_config srst_only srst_nogate +#reset_config srst_only srst_nogate #cortex_m maskisr (auto|on|off) #cortex_m vector_catch [all|none|list] #cortex_m reset_config (srst|sysresetreq|vectreset) @@ -58,10 +58,10 @@ proc Burn {file} { # If this happens to you - use the ST-Link utility to set the option byte back to normal. # If you are using a different debugger eg a FT2232 based adapter you can uncomment the line below. #stm32f2x unlock 0 - flash protect 0 0 last off - reset init - flash write_image erase $file 0x08000000 - verify_image $file 0x0 + #flash protect 0 0 last off + reset halt + flash write_image erase $file 0 elf + verify_image $file 0x0 elf #flash protect 0 0 last on reset echo "Burning Complete!" diff --git a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile index 652d43dd..60a46752 100644 --- a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile +++ b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile @@ -16,6 +16,7 @@ GFXLIB = ../uGFX GFXBOARD = Olimex-SAM7EX256-GE8 GFXDEMO = modules/gdisp/basics + GFXSINGLEMAKE = no # ChibiOS settings ifeq ($(OPT_OS),chibios) diff --git a/boards/base/STM32F429i-Discovery/board.mk b/boards/base/STM32F429i-Discovery/board.mk index 09116393..cbf08097 100644 --- a/boards/base/STM32F429i-Discovery/board.mk +++ b/boards/base/STM32F429i-Discovery/board.mk @@ -3,5 +3,5 @@ GFXSRC += $(GFXLIB)/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram $(GFXLIB)/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.c GFXDEFS += -DGFX_USE_OS_CHIBIOS=TRUE -include $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/driver.mk +include $(GFXLIB)/drivers/gdisp/STM32LTDC/driver.mk include $(GFXLIB)/drivers/ginput/touch/STMPE811/driver.mk diff --git a/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h b/boards/base/STM32F429i-Discovery/board_STM32LTDC.h similarity index 56% rename from boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h rename to boards/base/STM32F429i-Discovery/board_STM32LTDC.h index cdea4b54..8cd3048d 100644 --- a/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h +++ b/boards/base/STM32F429i-Discovery/board_STM32LTDC.h @@ -48,7 +48,104 @@ static const ltdcConfig driverCfg = { LTDC_UNUSED_LAYER_CONFIG }; -static GFXINLINE void init_board(GDisplay *g) { +#include "ili9341.h" + +static void acquire_bus(GDisplay *g) { + (void) g; + + spiSelect(SPI_PORT); +} + +static void release_bus(GDisplay *g) { + (void) g; + + spiUnselect(SPI_PORT); +} + +static void write_index(GDisplay *g, uint8_t index) { + static uint8_t sindex; + (void) g; + + palClearPad(DC_PORT, DC_PIN); + sindex = index; + spiSend(SPI_PORT, 1, &sindex); +} + +static void write_data(GDisplay *g, uint8_t data) { + static uint8_t sdata; + (void) g; + + palSetPad(DC_PORT, DC_PIN); + sdata = data; + spiSend(SPI_PORT, 1, &sdata); +} + +static void Init9341(GDisplay *g) { + #define REG_TYPEMASK 0xFF00 + #define REG_DATAMASK 0x00FF + + #define REG_DATA 0x0000 + #define REG_COMMAND 0x0100 + #define REG_DELAY 0x0200 + + static const uint16_t initdata[] = { + REG_COMMAND | ILI9341_CMD_RESET, + REG_DELAY | 5, + REG_COMMAND | ILI9341_CMD_DISPLAY_OFF, + REG_COMMAND | ILI9341_SET_FRAME_CTL_NORMAL, 0x00, 0x1B, + REG_COMMAND | ILI9341_SET_FUNCTION_CTL, 0x0A, 0xA2, + REG_COMMAND | ILI9341_SET_POWER_CTL_1, 0x10, + REG_COMMAND | ILI9341_SET_POWER_CTL_2, 0x10, + #if 1 + REG_COMMAND | ILI9341_SET_VCOM_CTL_1, 0x45, 0x15, + REG_COMMAND | ILI9341_SET_VCOM_CTL_2, 0x90, + #else + REG_COMMAND | ILI9341_SET_VCOM_CTL_1, 0x35, 0x3E, + REG_COMMAND | ILI9341_SET_VCOM_CTL_2, 0xBE, + #endif + REG_COMMAND | ILI9341_SET_MEM_ACS_CTL, 0xC8, + REG_COMMAND | ILI9341_SET_RGB_IF_SIG_CTL, 0xC2, + REG_COMMAND | ILI9341_SET_FUNCTION_CTL, 0x0A, 0xA7, 0x27, 0x04, + REG_COMMAND | ILI9341_SET_COL_ADDR, 0x00, 0x00, 0x00, 0xEF, + REG_COMMAND | ILI9341_SET_PAGE_ADDR, 0x00, 0x00, 0x01, 0x3F, + REG_COMMAND | ILI9341_SET_IF_CTL, 0x01, 0x00, 0x06, + REG_COMMAND | ILI9341_SET_GAMMA, 0x01, + REG_COMMAND | ILI9341_SET_PGAMMA, + #if 1 + 0x0F, 0x29, 0x24, 0x0C, 0x0E, 0x09, 0x4E, 0x78, + 0x3C, 0x09, 0x13, 0x05, 0x17, 0x11, 0x00, + #else + 0x1F, 0x1a, 0x18, 0x0a, 0x0f, 0x06, 0x45, 0x87, + 0x32, 0x0a, 0x07, 0x02, 0x07, 0x05, 0x00, + #endif + REG_COMMAND | ILI9341_SET_NGAMMA, + #if 1 + 0x00, 0x16, 0x1B, 0x04, 0x11, 0x07, 0x31, 0x33, + 0x42, 0x05, 0x0C, 0x0A, 0x28, 0x2F, 0x0F, + #else + 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3a, 0x78, + 0x4d, 0x05, 0x18, 0x0d, 0x38, 0x3a, 0x1f, + #endif + REG_COMMAND | ILI9341_CMD_SLEEP_OFF, + REG_DELAY | 10, + REG_COMMAND | ILI9341_CMD_DISPLAY_ON, + REG_COMMAND | ILI9341_SET_MEM + }; + + const uint16_t *p; + + acquire_bus(g); + for(p = initdata; p < &initdata[sizeof(initdata)/sizeof(initdata[0])]; p++) { + switch(*p & REG_TYPEMASK) { + case REG_DATA: write_data(g, *p); break; + case REG_COMMAND: write_index(g, *p); break; + case REG_DELAY: gfxSleepMilliseconds(*p & 0xFF); break; + } + } + release_bus(g); +} + +static void init_board(GDisplay *g) { // As we are not using multiple displays we set g->board to NULL as we don't use it. g->board = 0; @@ -84,6 +181,8 @@ static GFXINLINE void init_board(GDisplay *g) { memset((void *)SDRAM_BANK_ADDR, 0, 0x400000); spiStart(SPI_PORT, &spi_cfg); + + Init9341(g); break; } } @@ -97,34 +196,4 @@ static GFXINLINE void set_backlight(GDisplay *g, uint8_t percent) { (void) percent; } -static GFXINLINE void acquire_bus(GDisplay *g) { - (void) g; - - spiSelect(SPI_PORT); -} - -static GFXINLINE void release_bus(GDisplay *g) { - (void) g; - - spiUnselect(SPI_PORT); -} - -static GFXINLINE void write_index(GDisplay *g, uint8_t index) { - static uint8_t sindex; - (void) g; - - palClearPad(DC_PORT, DC_PIN); - sindex = index; - spiSend(SPI_PORT, 1, &sindex); -} - -static GFXINLINE void write_data(GDisplay *g, uint8_t data) { - static uint8_t sdata; - (void) g; - - palSetPad(DC_PORT, DC_PIN); - sdata = data; - spiSend(SPI_PORT, 1, &sdata); -} - #endif /* _GDISP_LLD_BOARD_H */ diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile b/boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile index 6c1bb94c..f5a1b2c2 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile @@ -16,6 +16,7 @@ GFXLIB = ../uGFX GFXBOARD = STM32F429i-Discovery GFXDEMO = modules/gdisp/basics + GFXSINGLEMAKE = no # ChibiOS settings ifeq ($(OPT_OS),chibios) @@ -33,7 +34,7 @@ endif # ARCH = arm-none-eabi- -SRCFLAGS = -ggdb -O0 +SRCFLAGS = -ggdb -O1 CFLAGS = CXXFLAGS = -fno-rtti ASFLAGS = diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg b/boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg index f8b6a6f5..b4395b52 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg @@ -1,4 +1,4 @@ -# This is a script file for OpenOCD 0.7.0 +# This is a script file for OpenOCD ?.?.? # # It is set up for the Mikromedia-STM32M4 board using the ST-Link JTAG adaptor. # @@ -32,11 +32,11 @@ source [find interface/stlink-v2.cfg] echo "" echo "##### Loading CPU..." -source [find target/stm32f4x_stlink.cfg] +source [find target/stm32f4x.cfg] echo "" echo "##### Configuring..." -reset_config srst_only srst_nogate +#reset_config srst_only srst_nogate #cortex_m maskisr (auto|on|off) #cortex_m vector_catch [all|none|list] #cortex_m reset_config (srst|sysresetreq|vectreset) @@ -58,10 +58,10 @@ proc Burn {file} { # If this happens to you - use the ST-Link utility to set the option byte back to normal. # If you are using a different debugger eg a FT2232 based adapter you can uncomment the line below. #stm32f2x unlock 0 - flash protect 0 0 last off - reset init - flash write_image erase $file 0x08000000 - verify_image $file 0x0 + #flash protect 0 0 last off + reset halt + flash write_image erase $file 0 elf + verify_image $file 0x0 elf #flash protect 0 0 last on reset echo "Burning Complete!" diff --git a/boards/base/STM32F429i-Discovery/example_chibios_3.x/Makefile b/boards/base/STM32F429i-Discovery/example_chibios_3.x/Makefile index d7ee1d20..87eb6e61 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_3.x/Makefile +++ b/boards/base/STM32F429i-Discovery/example_chibios_3.x/Makefile @@ -16,6 +16,7 @@ GFXLIB = ../path/to/ugfx GFXBOARD = STM32F429i-Discovery GFXDEMO = modules/gdisp/basics + GFXSINGLEMAKE = no # ChibiOS settings ifeq ($(OPT_OS),chibios) @@ -36,7 +37,7 @@ endif # ARCH = arm-none-eabi- -SRCFLAGS = -ggdb -O0 +SRCFLAGS = -ggdb -O1 CFLAGS = CXXFLAGS = -fno-rtti ASFLAGS = diff --git a/boards/base/STM32F429i-Discovery/example_chibios_3.x/openocd.cfg b/boards/base/STM32F429i-Discovery/example_chibios_3.x/openocd.cfg index f8b6a6f5..b4395b52 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_3.x/openocd.cfg +++ b/boards/base/STM32F429i-Discovery/example_chibios_3.x/openocd.cfg @@ -1,4 +1,4 @@ -# This is a script file for OpenOCD 0.7.0 +# This is a script file for OpenOCD ?.?.? # # It is set up for the Mikromedia-STM32M4 board using the ST-Link JTAG adaptor. # @@ -32,11 +32,11 @@ source [find interface/stlink-v2.cfg] echo "" echo "##### Loading CPU..." -source [find target/stm32f4x_stlink.cfg] +source [find target/stm32f4x.cfg] echo "" echo "##### Configuring..." -reset_config srst_only srst_nogate +#reset_config srst_only srst_nogate #cortex_m maskisr (auto|on|off) #cortex_m vector_catch [all|none|list] #cortex_m reset_config (srst|sysresetreq|vectreset) @@ -58,10 +58,10 @@ proc Burn {file} { # If this happens to you - use the ST-Link utility to set the option byte back to normal. # If you are using a different debugger eg a FT2232 based adapter you can uncomment the line below. #stm32f2x unlock 0 - flash protect 0 0 last off - reset init - flash write_image erase $file 0x08000000 - verify_image $file 0x0 + #flash protect 0 0 last off + reset halt + flash write_image erase $file 0 elf + verify_image $file 0x0 elf #flash protect 0 0 last on reset echo "Burning Complete!" diff --git a/drivers/gdisp/STM32F429iDiscovery/ili9341.h b/boards/base/STM32F429i-Discovery/ili9341.h similarity index 100% rename from drivers/gdisp/STM32F429iDiscovery/ili9341.h rename to boards/base/STM32F429i-Discovery/ili9341.h diff --git a/boards/base/STM32F746-Discovery/board.mk b/boards/base/STM32F746-Discovery/board.mk index a8ad0f1a..87bfcde3 100644 --- a/boards/base/STM32F746-Discovery/board.mk +++ b/boards/base/STM32F746-Discovery/board.mk @@ -15,7 +15,7 @@ ifeq ($(OPT_OS),raw32) $(GFXLIB)/boards/base/STM32F746-Discovery/stm32f746g_raw32_ugfx.c \ $(GFXLIB)/boards/base/STM32F746-Discovery/stm32f746g_raw32_system.c \ $(GFXLIB)/boards/base/STM32F746-Discovery/stm32f746g_raw32_interrupts.c - GFXDEFS += GFX_OS_EXTRA_INIT_FUNCTION=Raw32OSInit GFX_OS_INIT_NO_WARNING=TRUE + GFXDEFS += GFX_OS_PRE_INIT_FUNCTION=Raw32OSInit GFX_OS_INIT_NO_WARNING=TRUE GFXINC += $(CMSIS)/Device/ST/STM32F7xx/Include \ $(CMSIS)/Include \ $(STMHAL)/Inc diff --git a/boards/base/STM32F746-Discovery/stm32f746g_raw32_ugfx.c b/boards/base/STM32F746-Discovery/stm32f746g_raw32_ugfx.c index aaf3c391..2f6af0dd 100644 --- a/boards/base/STM32F746-Discovery/stm32f746g_raw32_ugfx.c +++ b/boards/base/STM32F746-Discovery/stm32f746g_raw32_ugfx.c @@ -16,7 +16,6 @@ #endif static void SystemClock_Config(void); -static void CPU_CACHE_Enable(void); void Raw32OSInit(void) { /* Enable the CPU Cache's */ diff --git a/demos/modules/gwin/frame/gfxconf.h b/demos/modules/gwin/frame/gfxconf.h index c6dcd80f..0c14f6b4 100644 --- a/demos/modules/gwin/frame/gfxconf.h +++ b/demos/modules/gwin/frame/gfxconf.h @@ -24,6 +24,9 @@ //#define GFX_USE_OS_LINUX TRUE //#define GFX_USE_OS_OSX TRUE +// Oops - rand() seems to use malloc() +#define GFX_EMULATE_MALLOC TRUE + /////////////////////////////////////////////////////////////////////////// // GDISP // /////////////////////////////////////////////////////////////////////////// diff --git a/demos/modules/gwin/frame/main.c b/demos/modules/gwin/frame/main.c index a97525ab..6668ddbb 100644 --- a/demos/modules/gwin/frame/main.c +++ b/demos/modules/gwin/frame/main.c @@ -1,5 +1,5 @@ #include "gfx.h" -#include "stdio.h" +#include static GListener gl; static GHandle ghFrame1; diff --git a/demos/modules/gwin/textedit/gfxconf.h b/demos/modules/gwin/textedit/gfxconf.h index 4faaae82..263ae035 100644 --- a/demos/modules/gwin/textedit/gfxconf.h +++ b/demos/modules/gwin/textedit/gfxconf.h @@ -65,8 +65,8 @@ #define GINPUT_NEED_MOUSE TRUE /* One or both of these */ -#define GINPUT_NEED_KEYBOARD TRUE -#define GWIN_NEED_KEYBOARD TRUE +//#define GINPUT_NEED_KEYBOARD TRUE +#define GWIN_NEED_KEYBOARD TRUE /* Features for the GQUEUE subsystem. */ #define GFX_USE_GQUEUE TRUE diff --git a/drivers/gdisp/SSD1331/gdisp_lld_SSD1331.c b/drivers/gdisp/SSD1331/gdisp_lld_SSD1331.c index 93a5d0a8..af2a0e06 100644 --- a/drivers/gdisp/SSD1331/gdisp_lld_SSD1331.c +++ b/drivers/gdisp/SSD1331/gdisp_lld_SSD1331.c @@ -110,12 +110,12 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { write_cmd(g, SSD1331_DISPLAY_ON); - // Release the bus - release_bus(g); - // Finish Init post_init_board(g); + // Release the bus + release_bus(g); + /* Initialise the GDISP structure */ g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; diff --git a/drivers/gdisp/SSD1351/gdisp_lld_SSD1351.c b/drivers/gdisp/SSD1351/gdisp_lld_SSD1351.c index e7fd6cff..87aaf38f 100644 --- a/drivers/gdisp/SSD1351/gdisp_lld_SSD1351.c +++ b/drivers/gdisp/SSD1351/gdisp_lld_SSD1351.c @@ -118,8 +118,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { write_cmd(g, 0xAF); // sleep mode OFF (display on) write_cmd(g, 0x5C); // write to RAM - release_bus(g); - // Finish Init post_init_board(g); diff --git a/drivers/gdisp/STM32F429iDiscovery/board_STM32F429iDiscovery_template.h b/drivers/gdisp/STM32F429iDiscovery/board_STM32F429iDiscovery_template.h deleted file mode 100644 index e13af4b3..00000000 --- a/drivers/gdisp/STM32F429iDiscovery/board_STM32F429iDiscovery_template.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GDISP_LLD_BOARD_H -#define _GDISP_LLD_BOARD_H - -static const ltdcConfig driverCfg = { - 240, 320, - 10, 2, - 20, 2, - 10, 4, - 0, - 0x000000, - { - (LLDCOLOR_TYPE *)SDRAM_BANK_ADDR, // frame - 240, 320, // width, height - 240 * LTDC_PIXELBYTES, // pitch - LTDC_PIXELFORMAT, // fmt - 0, 0, // x, y - 240, 320, // cx, cy - LTDC_COLOR_FUCHSIA, // defcolor - 0x980088, // keycolor - LTDC_BLEND_FIX1_FIX2, // blending - 0, // palette - 0, // palettelen - 0xFF, // alpha - LTDC_LEF_ENABLE // flags - }, - LTDC_UNUSED_LAYER_CONFIG -}; - -static GFXINLINE void init_board(GDisplay *g) { - - // As we are not using multiple displays we set g->board to NULL as we don't use it. - g->board = 0; - - switch(g->controllerdisplay) { - case 0: // Set up for Display 0 - // Your init here - break; - } -} - -static GFXINLINE void post_init_board(GDisplay *g) { -} - -static GFXINLINE void set_backlight(GDisplay *g, uint8_t percent) { -} - -static GFXINLINE void acquire_bus(GDisplay *g) { -} - -static GFXINLINE void release_bus(GDisplay *g) { -} - -static GFXINLINE void write_index(GDisplay *g, uint8_t index) { -} - -static GFXINLINE void write_data(GDisplay *g, uint8_t data) { -} - -#endif /* _GDISP_LLD_BOARD_H */ diff --git a/drivers/gdisp/STM32F429iDiscovery/driver.mk b/drivers/gdisp/STM32F429iDiscovery/driver.mk deleted file mode 100644 index afad5b85..00000000 --- a/drivers/gdisp/STM32F429iDiscovery/driver.mk +++ /dev/null @@ -1,2 +0,0 @@ -GFXINC += $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery -GFXSRC += $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c diff --git a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c deleted file mode 100644 index 91e914d3..00000000 --- a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#include "gfx.h" - -#if GFX_USE_GDISP - -#if defined(GDISP_SCREEN_HEIGHT) - #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored." - #undef GISP_SCREEN_HEIGHT -#endif -#if defined(GDISP_SCREEN_WIDTH) - #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored." - #undef GDISP_SCREEN_WIDTH -#endif - -#ifndef LTDC_USE_DMA2D - #define LTDC_USE_DMA2D FALSE -#endif - -#define GDISP_DRIVER_VMT GDISPVMT_STM32F429iDiscovery -#include "gdisp_lld_config.h" -#include "../../../src/gdisp/gdisp_driver.h" - -#include "stm32_ltdc.h" - -#if LTDC_USE_DMA2D - #include "stm32_dma2d.h" -#endif - -typedef struct ltdcLayerConfig { - // frame - LLDCOLOR_TYPE *frame; // Frame buffer address - coord_t width, height; // Frame size in pixels - coord_t pitch; // Line pitch, in bytes - uint16_t fmt; // Pixel format in LTDC format - - // window - coord_t x, y; // Start pixel position of the virtual layer - coord_t cx, cy; // Size of the virtual layer - - uint32_t defcolor; // Default color, ARGB8888 - uint32_t keycolor; // Color key, RGB888 - uint32_t blending; // Blending factors - const uint32_t *palette; // The palette, RGB888 (can be NULL) - uint16_t palettelen; // Palette length - uint8_t alpha; // Constant alpha factor - uint8_t layerflags; // Layer configuration -} ltdcLayerConfig; - -#define LTDC_UNUSED_LAYER_CONFIG { 0, 1, 1, 1, LTDC_FMT_L8, 0, 0, 1, 1, 0x000000, 0x000000, LTDC_BLEND_FIX1_FIX2, 0, 0, 0, 0 } - -typedef struct ltdcConfig { - coord_t width, height; // Screen size - coord_t hsync, vsync; // Horizontal and Vertical sync pixels - coord_t hbackporch, vbackporch; // Horizontal and Vertical back porch pixels - coord_t hfrontporch, vfrontporch; // Horizontal and Vertical front porch pixels - uint8_t syncflags; // Sync flags - uint32_t bgcolor; // Clear screen color RGB888 - - ltdcLayerConfig bglayer; // Background layer config - ltdcLayerConfig fglayer; // Foreground layer config -} ltdcConfig; - -#if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB565 - #define LTDC_PIXELFORMAT LTDC_FMT_RGB565 - #define LTDC_PIXELBYTES 2 - #define LTDC_PIXELBITS 16 -#elif GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888 - #define LTDC_PIXELFORMAT LTDC_FMT_RGB888 - #define LTDC_PIXELBYTES 3 - #define LTDC_PIXELBITS 24 -#else - #error "GDISP: STM32F4iDiscovery - unsupported pixel format" -#endif - -#include "board_STM32F429iDiscovery.h" - -#include "ili9341.h" - -/*===========================================================================*/ -/* Driver local definitions. */ -/*===========================================================================*/ - -#ifndef GDISP_INITIAL_CONTRAST - #define GDISP_INITIAL_CONTRAST 50 -#endif -#ifndef GDISP_INITIAL_BACKLIGHT - #define GDISP_INITIAL_BACKLIGHT 100 -#endif - -/*===========================================================================*/ -/* Driver local routines . */ -/*===========================================================================*/ - -#define PIXIL_POS(g, x, y) ((y) * driverCfg.bglayer.pitch + (x) * LTDC_PIXELBYTES) -#define PIXEL_ADDR(g, pos) ((LLDCOLOR_TYPE *)((uint8_t *)driverCfg.bglayer.frame+pos)) - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -static void InitController(GDisplay *g) { - #define REG_TYPEMASK 0xFF00 - #define REG_DATAMASK 0x00FF - - #define REG_DATA 0x0000 - #define REG_COMMAND 0x0100 - #define REG_DELAY 0x0200 - - static const uint16_t initdata[] = { - REG_COMMAND | ILI9341_CMD_RESET, - REG_DELAY | 5, - REG_COMMAND | ILI9341_CMD_DISPLAY_OFF, - REG_COMMAND | ILI9341_SET_FRAME_CTL_NORMAL, 0x00, 0x1B, - REG_COMMAND | ILI9341_SET_FUNCTION_CTL, 0x0A, 0xA2, - REG_COMMAND | ILI9341_SET_POWER_CTL_1, 0x10, - REG_COMMAND | ILI9341_SET_POWER_CTL_2, 0x10, - #if 1 - REG_COMMAND | ILI9341_SET_VCOM_CTL_1, 0x45, 0x15, - REG_COMMAND | ILI9341_SET_VCOM_CTL_2, 0x90, - #else - REG_COMMAND | ILI9341_SET_VCOM_CTL_1, 0x35, 0x3E, - REG_COMMAND | ILI9341_SET_VCOM_CTL_2, 0xBE, - #endif - REG_COMMAND | ILI9341_SET_MEM_ACS_CTL, 0xC8, - REG_COMMAND | ILI9341_SET_RGB_IF_SIG_CTL, 0xC2, - REG_COMMAND | ILI9341_SET_FUNCTION_CTL, 0x0A, 0xA7, 0x27, 0x04, - REG_COMMAND | ILI9341_SET_COL_ADDR, 0x00, 0x00, 0x00, 0xEF, - REG_COMMAND | ILI9341_SET_PAGE_ADDR, 0x00, 0x00, 0x01, 0x3F, - REG_COMMAND | ILI9341_SET_IF_CTL, 0x01, 0x00, 0x06, - REG_COMMAND | ILI9341_SET_GAMMA, 0x01, - REG_COMMAND | ILI9341_SET_PGAMMA, - #if 1 - 0x0F, 0x29, 0x24, 0x0C, 0x0E, 0x09, 0x4E, 0x78, - 0x3C, 0x09, 0x13, 0x05, 0x17, 0x11, 0x00, - #else - 0x1F, 0x1a, 0x18, 0x0a, 0x0f, 0x06, 0x45, 0x87, - 0x32, 0x0a, 0x07, 0x02, 0x07, 0x05, 0x00, - #endif - REG_COMMAND | ILI9341_SET_NGAMMA, - #if 1 - 0x00, 0x16, 0x1B, 0x04, 0x11, 0x07, 0x31, 0x33, - 0x42, 0x05, 0x0C, 0x0A, 0x28, 0x2F, 0x0F, - #else - 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3a, 0x78, - 0x4d, 0x05, 0x18, 0x0d, 0x38, 0x3a, 0x1f, - #endif - REG_COMMAND | ILI9341_CMD_SLEEP_OFF, - REG_DELAY | 10, - REG_COMMAND | ILI9341_CMD_DISPLAY_ON, - REG_COMMAND | ILI9341_SET_MEM - }; - - const uint16_t *p; - - acquire_bus(g); - for(p = initdata; p < &initdata[sizeof(initdata)/sizeof(initdata[0])]; p++) { - switch(*p & REG_TYPEMASK) { - case REG_DATA: write_data(g, *p); break; - case REG_COMMAND: write_index(g, *p); break; - case REG_DELAY: gfxSleepMilliseconds(*p & 0xFF); break; - } - } - release_bus(g); -} - -static void LTDC_Reload(void) { - LTDC->SRCR |= LTDC_SRCR_IMR; - while (LTDC->SRCR & (LTDC_SRCR_IMR | LTDC_SRCR_VBR)) - gfxYield(); -} - -static void LTDC_LayerInit(LTDC_Layer_TypeDef *pLayReg, const ltdcLayerConfig * pCfg) { - static const uint8_t fmt2Bpp[] = { - 4, /* LTDC_FMT_ARGB8888 */ - 3, /* LTDC_FMT_RGB888 */ - 2, /* LTDC_FMT_RGB565 */ - 2, /* LTDC_FMT_ARGB1555 */ - 2, /* LTDC_FMT_ARGB4444 */ - 1, /* LTDC_FMT_L8 */ - 1, /* LTDC_FMT_AL44 */ - 2 /* LTDC_FMT_AL88 */ - }; - uint32_t start, stop; - - // Set the framebuffer dimensions and format - pLayReg->PFCR = (pLayReg->PFCR & ~LTDC_LxPFCR_PF) | ((uint32_t)pCfg->fmt & LTDC_LxPFCR_PF); - pLayReg->CFBAR = (uint32_t)pCfg->frame & LTDC_LxCFBAR_CFBADD; - pLayReg->CFBLR = ((((uint32_t)pCfg->pitch << 16) & LTDC_LxCFBLR_CFBP) | (((uint32_t)fmt2Bpp[pCfg->fmt] * pCfg->width + 3) & LTDC_LxCFBLR_CFBLL)); - pLayReg->CFBLNR = (uint32_t)pCfg->height & LTDC_LxCFBLNR_CFBLNBR; - - // Set the display window boundaries - start = (uint32_t)pCfg->x + driverCfg.hsync + driverCfg.hbackporch; - stop = start + pCfg->cx - 1; - pLayReg->WHPCR = ((start << 0) & LTDC_LxWHPCR_WHSTPOS) | ((stop << 16) & LTDC_LxWHPCR_WHSPPOS); - start = (uint32_t)pCfg->y + driverCfg.vsync + driverCfg.vbackporch; - stop = start + pCfg->cy - 1; - pLayReg->WVPCR = ((start << 0) & LTDC_LxWVPCR_WVSTPOS) | ((stop << 16) & LTDC_LxWVPCR_WVSPPOS); - - // Set colors - pLayReg->DCCR = pCfg->defcolor; - pLayReg->CKCR = (pLayReg->CKCR & ~0x00FFFFFF) | (pCfg->keycolor & 0x00FFFFFF); - pLayReg->CACR = (pLayReg->CACR & ~LTDC_LxCACR_CONSTA) | ((uint32_t)pCfg->alpha & LTDC_LxCACR_CONSTA); - pLayReg->BFCR = (pLayReg->BFCR & ~(LTDC_LxBFCR_BF1 | LTDC_LxBFCR_BF2)) | ((uint32_t)pCfg->blending & (LTDC_LxBFCR_BF1 | LTDC_LxBFCR_BF2)); - for (start = 0; start < pCfg->palettelen; start++) - pLayReg->CLUTWR = ((uint32_t)start << 24) | (pCfg->palette[start] & 0x00FFFFFF); - - // Final flags - pLayReg->CR = (pLayReg->CR & ~LTDC_LEF_MASK) | ((uint32_t)pCfg->layerflags & LTDC_LEF_MASK); -} - -static void LTDC_Init(void) { - // Set up the display scanning - uint32_t hacc, vacc; - - /* Reset the LTDC hardware module.*/ - RCC->APB2RSTR |= RCC_APB2RSTR_LTDCRST; - RCC->APB2RSTR = 0; - - /* Enable the LTDC clock.*/ - RCC->DCKCFGR = (RCC->DCKCFGR & ~RCC_DCKCFGR_PLLSAIDIVR) | (1 << 16); /* /4 */ - - // Enable the module - RCC->APB2ENR |= RCC_APB2ENR_LTDCEN; - - // Turn off the controller and its interrupts. - LTDC->GCR = 0; - LTDC->IER = 0; - LTDC_Reload(); - - // Set synchronization params - hacc = driverCfg.hsync - 1; - vacc = driverCfg.vsync - 1; - LTDC->SSCR = ((hacc << 16) & LTDC_SSCR_HSW) | ((vacc << 0) & LTDC_SSCR_VSH); - - // Set accumulated back porch params - hacc += driverCfg.hbackporch; - vacc += driverCfg.vbackporch; - LTDC->BPCR = ((hacc << 16) & LTDC_BPCR_AHBP) | ((vacc << 0) & LTDC_BPCR_AVBP); - - // Set accumulated active params - hacc += driverCfg.width; - vacc += driverCfg.height; - LTDC->AWCR = ((hacc << 16) & LTDC_AWCR_AAW) | ((vacc << 0) & LTDC_AWCR_AAH); - - // Set accumulated total params - hacc += driverCfg.hfrontporch; - vacc += driverCfg.vfrontporch; - LTDC->TWCR = ((hacc << 16) & LTDC_TWCR_TOTALW) | ((vacc << 0) & LTDC_TWCR_TOTALH); - - // Set signal polarities and other flags - LTDC->GCR = driverCfg.syncflags & (LTDC_EF_MASK & ~LTDC_EF_ENABLE); - - // Set background color - LTDC->BCCR = (LTDC->BCCR & ~0x00FFFFFF) | (driverCfg.bgcolor & 0x00FFFFFF); - - // Load the background layer - LTDC_LayerInit(LTDC_Layer1, &driverCfg.bglayer); - - // Load the foreground layer - LTDC_LayerInit(LTDC_Layer2, &driverCfg.fglayer); - - // Interrupt handling - //nvicEnableVector(STM32_LTDC_EV_NUMBER, CORTEX_PRIORITY_MASK(STM32_LTDC_EV_IRQ_PRIORITY)); - //nvicEnableVector(STM32_LTDC_ER_NUMBER, CORTEX_PRIORITY_MASK(STM32_LTDC_ER_IRQ_PRIORITY)); - // Possible flags - LTDC_IER_RRIE, LTDC_IER_LIE, LTDC_IER_FUIE, LTDC_IER_TERRIE etc - LTDC->IER = 0; - - // Set everything going - LTDC_Reload(); - LTDC->GCR |= LTDC_GCR_LTDCEN; - LTDC_Reload(); -} - -LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - - // Initialize the private structure - g->priv = 0; - g->board = 0; - //if (!(g->priv = gfxAlloc(sizeof(fbPriv)))) - // gfxHalt("GDISP Framebuffer: Failed to allocate private memory"); - - // Init the board - init_board(g); - //((fbPriv *)g->priv)->fbi.cfg = init_board(g); - - // Initialise the ILI9341 controller - InitController(g); - - // Initialise the LTDC controller - LTDC_Init(); - - // Initialise DMA2D - #if LTDC_USE_DMA2D - dma2d_init(); - #endif - - // Initialise DMA2D - //dma2dStart(&DMA2DD1, &dma2d_cfg); - //dma2d_test(); - - // Finish Init the board - post_init_board(g); - - /* Turn on the back-light */ - set_backlight(g, GDISP_INITIAL_BACKLIGHT); - - /* Initialise the GDISP structure */ - g->g.Width = driverCfg.bglayer.width; - g->g.Height = driverCfg.bglayer.height; - g->g.Orientation = GDISP_ROTATE_0; - g->g.Powermode = powerOn; - g->g.Backlight = GDISP_INITIAL_BACKLIGHT; - g->g.Contrast = GDISP_INITIAL_CONTRAST; - return TRUE; -} - -LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { - unsigned pos; - - #if GDISP_NEED_CONTROL - switch(g->g.Orientation) { - case GDISP_ROTATE_0: - default: - pos = PIXIL_POS(g, g->p.x, g->p.y); - break; - case GDISP_ROTATE_90: - pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); - break; - case GDISP_ROTATE_180: - pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); - break; - case GDISP_ROTATE_270: - pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); - break; - } - #else - pos = PIXIL_POS(g, g->p.x, g->p.y); - #endif - - PIXEL_ADDR(g, pos)[0] = gdispColor2Native(g->p.color); -} - -LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { - unsigned pos; - LLDCOLOR_TYPE color; - - #if GDISP_NEED_CONTROL - switch(g->g.Orientation) { - case GDISP_ROTATE_0: - default: - pos = PIXIL_POS(g, g->p.x, g->p.y); - break; - case GDISP_ROTATE_90: - pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); - break; - case GDISP_ROTATE_180: - pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); - break; - case GDISP_ROTATE_270: - pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); - break; - } - #else - pos = PIXIL_POS(g, g->p.x, g->p.y); - #endif - - color = PIXEL_ADDR(g, pos)[0]; - return gdispNative2Color(color); -} - -#if GDISP_NEED_CONTROL - LLDSPEC void gdisp_lld_control(GDisplay *g) { - switch(g->p.x) { - case GDISP_CONTROL_POWER: - if (g->g.Powermode == (powermode_t)g->p.ptr) - return; - switch((powermode_t)g->p.ptr) { - case powerOff: case powerOn: case powerSleep: case powerDeepSleep: - // TODO - break; - default: - return; - } - g->g.Powermode = (powermode_t)g->p.ptr; - return; - - case GDISP_CONTROL_ORIENTATION: - if (g->g.Orientation == (orientation_t)g->p.ptr) - return; - switch((orientation_t)g->p.ptr) { - case GDISP_ROTATE_0: - case GDISP_ROTATE_180: - if (g->g.Orientation == GDISP_ROTATE_90 || g->g.Orientation == GDISP_ROTATE_270) { - coord_t tmp; - - tmp = g->g.Width; - g->g.Width = g->g.Height; - g->g.Height = tmp; - } - break; - case GDISP_ROTATE_90: - case GDISP_ROTATE_270: - if (g->g.Orientation == GDISP_ROTATE_0 || g->g.Orientation == GDISP_ROTATE_180) { - coord_t tmp; - - tmp = g->g.Width; - g->g.Width = g->g.Height; - g->g.Height = tmp; - } - break; - default: - return; - } - g->g.Orientation = (orientation_t)g->p.ptr; - return; - - case GDISP_CONTROL_BACKLIGHT: - if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; - set_backlight(g, (unsigned)g->p.ptr); - g->g.Backlight = (unsigned)g->p.ptr; - return; - - case GDISP_CONTROL_CONTRAST: - if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; - // TODO - g->g.Contrast = (unsigned)g->p.ptr; - return; - } - } -#endif - -#if LTDC_USE_DMA2D - static void dma2d_init(void) - { - // Enable DMA2D clock (DMA2DEN = 1) - RCC->AHB1ENR |= RCC_AHB1ENR_DMA2DEN; - - // Output color format - #if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB565 - DMA2D->OPFCCR = OPFCCR_RGB565; - #elif GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888 - DMA2D->OPFCCR = OPFCCR_OPFCCR_RGB888; - #endif - - // Foreground color format - #if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB565 - DMA2D->FGPFCCR = FGPFCCR_CM_RGB565; - #elif GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888 - DMA2D->FGPFCCR = FGPFCCR_CM_RGB888; - #endif - } - - // Uses p.x,p.y p.cx,p.cy p.color - LLDSPEC void gdisp_lld_fill_area(GDisplay* g) - { - LLDCOLOR_TYPE c; - - // Wait until DMA2D is ready - while (1) { - if (!(DMA2D->CR & DMA2D_CR_START)) { - break; - } - } - - c = gdispColor2Native(g->p.color); - - // Output color register - DMA2D->OCOLR = (uint32_t)c; - - // Output memory address register - DMA2D->OMAR = g->p.y * g->g.Width * LTDC_PIXELBYTES + g->p.x * LTDC_PIXELBYTES + (uint32_t)driverCfg.bglayer.frame; - - // Output offset register (in pixels) - DMA2D->OOR = g->g.Width - g->p.cx; - - // PL (pixel per lines to be transferred); NL (number of lines) - DMA2D->NLR = (g->p.cx << 16) | (g->p.cy); - - // Set MODE to R2M and Start the process - DMA2D->CR = DMA2D_CR_MODE_R2M | DMA2D_CR_START; - } - - // Uses p.x,p.y p.cx,p.cy p.x1,p.y1 (=srcx,srcy) p.x2 (=srccx), p.ptr (=buffer) - LLDSPEC void gdisp_lld_blit_area(GDisplay* g) - { - // Wait until DMA2D is ready - while (1) { - if (!(DMA2D->CR & DMA2D_CR_START)) { - break; - } - } - - // Foreground memory address register - DMA2D->FGMAR = g->p.y1 * g->p.x2 * LTDC_PIXELBYTES + g->p.x1 * LTDC_PIXELBYTES + (uint32_t)g->p.ptr; - - // Foreground offset register (expressed in pixels) - DMA2D->FGOR = g->p.x2 - g->p.cx; - - // Output memory address register - DMA2D->OMAR = g->p.y * g->g.Width * LTDC_PIXELBYTES + g->p.x * LTDC_PIXELBYTES + (uint32_t)driverCfg.bglayer.frame; - - // Output offset register (expressed in pixels) - DMA2D->OOR = g->g.Width - g->p.cx; - - // PL (pixel per lines to be transferred); NL (number of lines) - DMA2D->NLR = (g->p.cx << 16) | (g->p.cy); - - // Set MODE to M2M and Start the process - DMA2D->CR = DMA2D_CR_MODE_M2M | DMA2D_CR_START; - } - -#endif /* LTDC_USE_DMA2D */ - -#endif /* GFX_USE_GDISP */ diff --git a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h deleted file mode 100644 index c661f67c..00000000 --- a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GDISP_LLD_CONFIG_H -#define _GDISP_LLD_CONFIG_H - -#if GFX_USE_GDISP - -/*===========================================================================*/ -/* Driver hardware support. */ -/*===========================================================================*/ - -#define LTDC_USE_DMA2D TRUE -#define GDISP_HARDWARE_DRAWPIXEL TRUE -#define GDISP_HARDWARE_PIXELREAD TRUE -#define GDISP_HARDWARE_CONTROL TRUE -#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 - - -/*===========================================================================*/ -/* Don't change stuff below this line. Please. */ -/*===========================================================================*/ - -#if LTDC_USE_DMA2D - #define GDISP_HARDWARE_FILLS TRUE - #define GDISP_HARDWARE_BITFILLS TRUE -#else - #define GDISP_HARDWARE_FILLS FALSE - #define GDISP_HARDWARE_BITFILLS FALSE -#endif /* GDISP_USE_DMA2D */ - -#endif /* GFX_USE_GDISP */ - -#endif /* _GDISP_LLD_CONFIG_H */ diff --git a/drivers/gdisp/STM32F429iDiscovery/readme.txt b/drivers/gdisp/STM32F429iDiscovery/readme.txt deleted file mode 100644 index ce2dd03b..00000000 --- a/drivers/gdisp/STM32F429iDiscovery/readme.txt +++ /dev/null @@ -1,11 +0,0 @@ -To use this driver: - -1. Add in your gfxconf.h: - a) #define GFX_USE_GDISP TRUE - -2. To your makefile add the following lines: - include $(GFXLIB)/gfx.mk - include $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/driver.mk - -3. Add a board_STM32F429iDiscovery.h to you project directory (or board directory) - base on one of the templates. diff --git a/drivers/gdisp/STM32F429iDiscovery/stm32_dma2d.h b/drivers/gdisp/STM32F429iDiscovery/stm32_dma2d.h deleted file mode 100644 index d3374d05..00000000 --- a/drivers/gdisp/STM32F429iDiscovery/stm32_dma2d.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _STM32_DMA2D_H -#define _STM32_DMA2D_H - -#define OPFCCR_ARGB8888 0x00 -#define OPFCCR_RGB888 0x01 -#define OPFCCR_RGB565 0x02 -#define OPFCCR_ARGB1555 0x03 -#define OPFCCR_ARGB4444 0x04 - -#define FGPFCCR_CM_RGB888 0x01 -#define FGPFCCR_CM_RGB565 0x02 - -#define DMA2D_CR_MODE_R2M ((uint32_t)0x00030000) /* Register-to-memory mode */ -#define DMA2D_CR_MODE_M2M ((uint32_t)0x00000000) /* Register-to-memory mode */ - -static void dma2d_init(void); - -#endif /* _STM32_DMA2D_H */ diff --git a/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h b/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h deleted file mode 100644 index 866b9d89..00000000 --- a/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef STM32_LTDC_H -#define STM32_LTDC_H - -// LTDC enable flags -#define LTDC_EF_ENABLE (1 << 0) /**< LTDC enabled.*/ -#define LTDC_EF_DITHER (1 << 16) /**< Dithering enabled.*/ -#define LTDC_EF_PIXCLK_INVERT (1 << 28) /**< Inverted pixel clock.*/ -#define LTDC_EF_DATAEN_HIGH (1 << 29) /**< Active-high data enable.*/ -#define LTDC_EF_VSYNC_HIGH (1 << 30) /**< Active-high vsync.*/ -#define LTDC_EF_HSYNC_HIGH (1 << 31) /**< Active-high hsync.*/ - -#define LTDC_EF_MASK (LTDC_EF_ENABLE | LTDC_EF_DITHER | LTDC_EF_PIXCLK_INVERT | LTDC_EF_DATAEN_HIGH | LTDC_EF_VSYNC_HIGH | LTDC_EF_HSYNC_HIGH) - -// LTDC layer enable flags -#define LTDC_LEF_ENABLE (1 << 0) /**< Layer enabled*/ -#define LTDC_LEF_KEYING (1 << 1) /**< Color keying enabled.*/ -#define LTDC_LEF_PALETTE (1 << 4) /**< Palette enabled.*/ - -#define LTDC_LEF_MASK (LTDC_LEF_ENABLE | LTDC_LEF_KEYING | LTDC_LEF_PALETTE) - -// LTDC pixel formats -#define LTDC_FMT_ARGB8888 0 /**< ARGB-8888 format.*/ -#define LTDC_FMT_RGB888 1 /**< RGB-888 format.*/ -#define LTDC_FMT_RGB565 2 /**< RGB-565 format.*/ -#define LTDC_FMT_ARGB1555 3 /**< ARGB-1555 format.*/ -#define LTDC_FMT_ARGB4444 4 /**< ARGB-4444 format.*/ -#define LTDC_FMT_L8 5 /**< L-8 format.*/ -#define LTDC_FMT_AL44 6 /**< AL-44 format.*/ -#define LTDC_FMT_AL88 7 /**< AL-88 format.*/ - -// LTDC pixel format aliased raw masks -#define LTDC_XMASK_ARGB8888 0xFFFFFFFF /**< ARGB-8888 aliased mask.*/ -#define LTDC_XMASK_RGB888 0x00FFFFFF /**< RGB-888 aliased mask.*/ -#define LTDC_XMASK_RGB565 0x00F8FCF8 /**< RGB-565 aliased mask.*/ -#define LTDC_XMASK_ARGB1555 0x80F8F8F8 /**< ARGB-1555 aliased mask.*/ -#define LTDC_XMASK_ARGB4444 0xF0F0F0F0 /**< ARGB-4444 aliased mask.*/ -#define LTDC_XMASK_L8 0x000000FF /**< L-8 aliased mask.*/ -#define LTDC_XMASK_AL44 0xF00000F0 /**< AL-44 aliased mask.*/ -#define LTDC_XMASK_AL88 0xFF0000FF /**< AL-88 aliased mask.*/ - -// LTDC blending factors -#define LTDC_BLEND_FIX1_FIX2 0x0405 /**< cnst1; 1 - cnst2 */ -#define LTDC_BLEND_FIX1_MOD2 0x0407 /**< cnst1; 1 - a2 * cnst2 */ -#define LTDC_BLEND_MOD1_FIX2 0x0605 /**< a1 * cnst1; 1 - cnst2 */ -#define LTDC_BLEND_MOD1_MOD2 0x0607 /**< a1 * cnst1; 1 - a2 * cnst2 */ - -// LTDC parameter bounds -#define LTDC_MIN_SCREEN_WIDTH 1 -#define LTDC_MIN_SCREEN_HEIGHT 1 -#define LTDC_MAX_SCREEN_WIDTH 800 -#define LTDC_MAX_SCREEN_HEIGHT 600 - -#define LTDC_MIN_HSYNC_WIDTH 1 -#define LTDC_MIN_VSYNC_HEIGHT 1 -#define LTDC_MAX_HSYNC_WIDTH (1 << 12) -#define LTDC_MAX_VSYNC_HEIGHT (1 << 11) - -#define LTDC_MIN_HBP_WIDTH 0 -#define LTDC_MIN_VBP_HEIGHT 0 -#define LTDC_MAX_HBP_WIDTH (1 << 12) -#define LTDC_MAX_VBP_HEIGHT (1 << 11) - -#define LTDC_MIN_ACC_HBP_WIDTH 1 -#define LTDC_MIN_ACC_VBP_HEIGHT 1 -#define LTDC_MAX_ACC_HBP_WIDTH (1 << 12) -#define LTDC_MAX_ACC_VBP_HEIGHT (1 << 11) - -#define LTDC_MIN_HFP_WIDTH 0 -#define LTDC_MIN_VFP_HEIGHT 0 -#define LTDC_MAX_HFP_WIDTH (1 << 12) -#define LTDC_MAX_VFP_HEIGHT (1 << 11) - -#define LTDC_MIN_ACTIVE_WIDTH 0 -#define LTDC_MIN_ACTIVE_HEIGHT 0 -#define LTDC_MAX_ACTIVE_WIDTH (1 << 12) -#define LTDC_MAX_ACTIVE_HEIGHT (1 << 11) - -#define LTDC_MIN_ACC_ACTIVE_WIDTH 1 -#define LTDC_MIN_ACC_ACTIVE_HEIGHT 1 -#define LTDC_MAX_ACC_ACTIVE_WIDTH (1 << 12) -#define LTDC_MAX_ACC_ACTIVE_HEIGHT (1 << 11) - -#define LTDC_MIN_ACC_TOTAL_WIDTH 1 -#define LTDC_MIN_ACC_TOTAL_HEIGHT 1 -#define LTDC_MAX_ACC_TOTAL_WIDTH (1 << 12) -#define LTDC_MAX_ACC_TOTAL_HEIGHT (1 << 11) - -#define LTDC_MIN_LINE_INTERRUPT_POS 0 -#define LTDC_MAX_LINE_INTERRUPT_POS ((1 << 11) - 1) - -#define LTDC_MIN_WINDOW_HSTART 0 -#define LTDC_MIN_WINDOW_HSTART 0 -#define LTDC_MAX_WINDOW_HSTOP ((1 << 12) - 1) -#define LTDC_MAX_WINDOW_HSTOP ((1 << 12) - 1) - -#define LTDC_MIN_WINDOW_VSTART 0 -#define LTDC_MIN_WINDOW_VSTART 0 -#define LTDC_MAX_WINDOW_VSTOP ((1 << 11) - 1) -#define LTDC_MAX_WINDOW_VSTOP ((1 << 11) - 1) - -#define LTDC_MIN_FRAME_WIDTH_BYTES 0 -#define LTDC_MIN_FRAME_HEIGHT_LINES 0 -#define LTDC_MIN_FRAME_PITCH_BYTES 0 -#define LTDC_MAX_FRAME_WIDTH_BYTES ((1 << 13) - 1 - 3) -#define LTDC_MAX_FRAME_HEIGHT_LINES ((1 << 11) - 1) -#define LTDC_MAX_FRAME_PITCH_BYTES ((1 << 13) - 1) - -#define LTDC_MIN_PIXFMT_ID 0 -#define LTDC_MAX_PIXFMT_ID 7 - -#define LTDC_MAX_PALETTE_LENGTH 256 - -// LTDC basic ARGB-8888 colors. -#define LTDC_COLOR_BLACK 0xFF000000 -#define LTDC_COLOR_MAROON 0xFF800000 -#define LTDC_COLOR_GREEN 0xFF008000 -#define LTDC_COLOR_OLIVE 0xFF808000 -#define LTDC_COLOR_NAVY 0xFF000080 -#define LTDC_COLOR_PURPLE 0xFF800080 -#define LTDC_COLOR_TEAL 0xFF008080 -#define LTDC_COLOR_SILVER 0xFFC0C0C0 -#define LTDC_COLOR_GRAY 0xFF808080 -#define LTDC_COLOR_RED 0xFFFF0000 -#define LTDC_COLOR_LIME 0xFF00FF00 -#define LTDC_COLOR_YELLOW 0xFFFFFF00 -#define LTDC_COLOR_BLUE 0xFF0000FF -#define LTDC_COLOR_FUCHSIA 0xFFFF00FF -#define LTDC_COLOR_AQUA 0xFF00FFFF -#define LTDC_COLOR_WHITE 0xFFFFFFFF - -#ifndef STM32F429_439xx -#error "Currently only STM32F429xx and STM32F439xx are supported" -#endif - -#endif /* STM32_LTDC_H */ diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c index 949088b5..9d1aafa0 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_STM32LTDC.c @@ -102,17 +102,13 @@ typedef struct ltdcConfig { /* Driver exported functions. */ /*===========================================================================*/ -static void _ltdc_reload(void) -{ +static void _ltdc_reload(void) { LTDC->SRCR |= LTDC_SRCR_IMR; - - while (LTDC->SRCR & (LTDC_SRCR_IMR | LTDC_SRCR_VBR)) { + while (LTDC->SRCR & (LTDC_SRCR_IMR | LTDC_SRCR_VBR)) gfxYield(); - } } -static void _ltdc_layer_init(LTDC_Layer_TypeDef* pLayReg, const ltdcLayerConfig* pCfg) -{ +static void _ltdc_layer_init(LTDC_Layer_TypeDef* pLayReg, const ltdcLayerConfig* pCfg) { static const uint8_t fmt2Bpp[] = { 4, /* LTDC_FMT_ARGB8888 */ 3, /* LTDC_FMT_RGB888 */ @@ -151,8 +147,7 @@ static void _ltdc_layer_init(LTDC_Layer_TypeDef* pLayReg, const ltdcLayerConfig* pLayReg->CR = (pLayReg->CR & ~LTDC_LEF_MASK) | ((uint32_t)pCfg->layerflags & LTDC_LEF_MASK); } -static void _ltdc_init(void) -{ +static void _ltdc_init(void) { // Set up the display scanning uint32_t hacc, vacc; @@ -161,9 +156,9 @@ static void _ltdc_init(void) RCC->APB2RSTR = 0; // Enable the LTDC clock - #if defined(STM32F4) + #if defined(STM32F4) || defined(STM32F429_439xx) || defined(STM32F429xx) RCC->DCKCFGR = (RCC->DCKCFGR & ~RCC_DCKCFGR_PLLSAIDIVR) | (1 << 16); - #elif defined(STM32F7) + #elif defined(STM32F7) || defined(STM32F746xx) RCC->DCKCFGR1 = (RCC->DCKCFGR1 & ~RCC_DCKCFGR1_PLLSAIDIVR) | (1 << 16); #else #error STM32LTDC driver not implemented for your platform @@ -219,8 +214,7 @@ static void _ltdc_init(void) _ltdc_reload(); } -LLDSPEC bool_t gdisp_lld_init(GDisplay* g) -{ +LLDSPEC bool_t gdisp_lld_init(GDisplay* g) { // Initialize the private structure g->priv = 0; g->board = 0; @@ -253,8 +247,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay* g) return TRUE; } -LLDSPEC void gdisp_lld_draw_pixel(GDisplay* g) -{ +LLDSPEC void gdisp_lld_draw_pixel(GDisplay* g) { unsigned pos; #if GDISP_NEED_CONTROL @@ -277,11 +270,14 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay* g) pos = PIXIL_POS(g, g->p.x, g->p.y); #endif - PIXEL_ADDR(g, pos)[0] = gdispColor2Native(g->p.color); + #if LTDC_USE_DMA2D + while(DMA2D->CR & DMA2D_CR_START); + #endif + + PIXEL_ADDR(g, pos)[0] = gdispColor2Native(g->p.color); } -LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay* g) -{ +LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay* g) { unsigned pos; LLDCOLOR_TYPE color; @@ -305,24 +301,28 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay* g) pos = PIXIL_POS(g, g->p.x, g->p.y); #endif + #if LTDC_USE_DMA2D + while(DMA2D->CR & DMA2D_CR_START); + #endif + color = PIXEL_ADDR(g, pos)[0]; return gdispNative2Color(color); } #if GDISP_NEED_CONTROL - LLDSPEC void gdisp_lld_control(GDisplay* g) - { + LLDSPEC void gdisp_lld_control(GDisplay* g) { switch(g->p.x) { case GDISP_CONTROL_POWER: - // Don't do anything if it is the same power mode if (g->g.Powermode == (powermode_t)g->p.ptr) return; switch((powermode_t)g->p.ptr) { + case powerOff: case powerOn: case powerSleep: case powerDeepSleep: + // TODO + break; default: return; } - g->g.Powermode = (powermode_t)g->p.ptr; return; @@ -353,7 +353,6 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay* g) default: return; } - g->g.Orientation = (orientation_t)g->p.ptr; return; @@ -373,8 +372,7 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay* g) #endif #if LTDC_USE_DMA2D - static void dma2d_init(void) - { + static void dma2d_init(void) { // Enable DMA2D clock RCC->AHB1ENR |= RCC_AHB1ENR_DMA2DEN; @@ -396,91 +394,88 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay* g) // Uses p.x,p.y p.cx,p.cy p.color LLDSPEC void gdisp_lld_fill_area(GDisplay* g) { - uint32_t reg_omar = 0; - uint32_t reg_oor = 0; - uint32_t reg_nlr = 0; + uint32_t pos; + uint32_t lineadd; + uint32_t shape; // Wait until DMA2D is ready - while (1) { - if (!(DMA2D->CR & DMA2D_CR_START)) { - break; - } - } + while(DMA2D->CR & DMA2D_CR_START); - // Calculate pixel positions and stuff like that #if GDISP_NEED_CONTROL switch(g->g.Orientation) { case GDISP_ROTATE_0: default: - reg_omar = g->p.y * g->g.Width * LTDC_PIXELBYTES + g->p.x * LTDC_PIXELBYTES + (uint32_t)driverCfg.bglayer.frame; - reg_oor = g->g.Width - g->p.cx; - reg_nlr = (g->p.cx << 16) | (g->p.cy); + pos = PIXIL_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 GDISP_ROTATE_90: + pos = PIXIL_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 GDISP_ROTATE_180: - reg_omar = g->g.Width * (g->g.Height - g->p.y - g->p.cy) * LTDC_PIXELBYTES + (g->g.Width - g->p.x - g->p.cx) * LTDC_PIXELBYTES + (uint32_t)driverCfg.bglayer.frame; - reg_oor = g->g.Width - g->p.cx; - reg_nlr = (g->p.cy << 16) | (g->p.cx); + pos = PIXIL_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 GDISP_ROTATE_270: + pos = PIXIL_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 - reg_omar = g->p.y * g->g.Width * LTDC_PIXELBYTES + g->p.x * LTDC_PIXELBYTES + (uint32_t)driverCfg.bglayer.frame; - reg_oor = g->g.Width - g->p.cx; - reg_nlr = (g->p.cx << 16) | (g->p.cy); + pos = PIXIL_POS(g, g->p.x, g->p.y); + lineadd = g->g.Width - g->p.cx; + shape = (g->p.cx << 16) | (g->p.cy); #endif - - // Output memory address register - DMA2D->OMAR = reg_omar; - - // Output offset register (in pixels) - DMA2D->OOR = reg_oor; - - // PL (pixel per lines to be transferred); NL (number of lines) - DMA2D->NLR = reg_nlr; - - // Output color register + + // Start the DMA2D + DMA2D->OMAR = (uint32_t)PIXEL_ADDR(g, pos); + DMA2D->OOR = lineadd; + DMA2D->NLR = shape; DMA2D->OCOLR = (uint32_t)(gdispColor2Native(g->p.color)); - - // Set MODE to R2M and Start the process DMA2D->CR = DMA2D_CR_MODE_R2M | DMA2D_CR_START; } - // Uses p.x,p.y p.cx,p.cy p.x1,p.y1 (=srcx,srcy) p.x2 (=srccx), p.ptr (=buffer) - LLDSPEC void gdisp_lld_blit_area(GDisplay* g) - { - // Wait until DMA2D is ready - while (1) { - if (!(DMA2D->CR & DMA2D_CR_START)) { - break; - } + /* Oops - the DMA2D only supports GDISP_ROTATE_0. + * + * Where the width is 1 we can trick it for other orientations. + * That is worthwhile as a width of 1 is common. For other + * situations we need to fall back to pixel pushing. + * + * Additionally, although DMA2D can translate color formats + * it can only do it for a small range of formats. For any + * other formats we also need to fall back to pixel pushing. + * + * As the code to actually do all that for other than the + * simplest case (orientation == GDISP_ROTATE_0 and + * GDISP_PIXELFORMAT == GDISP_LLD_PIXELFORMAT) is very complex + * we will always pixel push for now. In practice that is OK as + * access to the framebuffer is fast - probably faster than DMA2D. + * It just uses more CPU. + */ + #if GDISP_HARDWARE_BITFILLS + // Uses p.x,p.y p.cx,p.cy p.x1,p.y1 (=srcx,srcy) p.x2 (=srccx), p.ptr (=buffer) + LLDSPEC void gdisp_lld_blit_area(GDisplay* g) { + // Wait until DMA2D is ready + while(DMA2D->CR & DMA2D_CR_START); + + // Source setup + DMA2D->FGMAR = LTDC_PIXELBYTES * (g->p.y1 * g->p.x2 + g->p.x1) + (uint32_t)g->p.ptr; + DMA2D->FGOR = g->p.x2 - g->p.cx; + + // Output setup + DMA2D->OMAR = (uint32_t)PIXEL_ADDR(g, PIXIL_POS(g, g->p.x, g->p.y)); + DMA2D->OOR = g->g.Width - g->p.cx; + DMA2D->NLR = (g->p.cx << 16) | (g->p.cy); + + // Set MODE to M2M and Start the process + DMA2D->CR = DMA2D_CR_MODE_M2M | DMA2D_CR_START; } - - // Foreground memory address register - DMA2D->FGMAR = g->p.y1 * g->p.x2 * LTDC_PIXELBYTES + g->p.x1 * LTDC_PIXELBYTES + (uint32_t)g->p.ptr; - - // Foreground offset register (expressed in pixels) - DMA2D->FGOR = g->p.x2 - g->p.cx; - - // Output memory address register - DMA2D->OMAR = g->p.y * g->g.Width * LTDC_PIXELBYTES + g->p.x * LTDC_PIXELBYTES + (uint32_t)driverCfg.bglayer.frame; - - // Output offset register (expressed in pixels) - DMA2D->OOR = g->g.Width - g->p.cx; - - // PL (pixel per lines to be transferred); NL (number of lines) - DMA2D->NLR = (g->p.cx << 16) | (g->p.cy); - - // Set MODE to M2M and Start the process - DMA2D->CR = DMA2D_CR_MODE_M2M | DMA2D_CR_START; - } + #endif #endif /* LTDC_USE_DMA2D */ - #endif /* GFX_USE_GDISP */ diff --git a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h index 846fc1f0..5c3b1883 100644 --- a/drivers/gdisp/STM32LTDC/gdisp_lld_config.h +++ b/drivers/gdisp/STM32LTDC/gdisp_lld_config.h @@ -14,11 +14,15 @@ /* Driver hardware support. */ /*===========================================================================*/ -#define LTDC_USE_DMA2D FALSE // Currently has display artifacts -#define GDISP_HARDWARE_DRAWPIXEL TRUE -#define GDISP_HARDWARE_PIXELREAD TRUE -#define GDISP_HARDWARE_CONTROL TRUE -#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 +#define LTDC_USE_DMA2D TRUE +#define GDISP_HARDWARE_DRAWPIXEL TRUE +#define GDISP_HARDWARE_PIXELREAD TRUE +#define GDISP_HARDWARE_CONTROL TRUE + +// Both these pixel formats are supported - pick one. +// RGB565 obviously is faster and uses less RAM but with lower color resolution than RGB888 +#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 +//#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 /*===========================================================================*/ @@ -26,11 +30,14 @@ /*===========================================================================*/ #if LTDC_USE_DMA2D + // DMA2D supports accelerated fills #define GDISP_HARDWARE_FILLS TRUE - #define GDISP_HARDWARE_BITFILLS TRUE -#else - #define GDISP_HARDWARE_FILLS FALSE - #define GDISP_HARDWARE_BITFILLS FALSE + + // Accelerated bitfills are also possible but only for GDISP_ROTATE_0 + // and if no color translation is required (for now) + #if !GDISP_NEED_CONTROL && GDISP_PIXELFORMAT == GDISP_LLD_PIXELFORMAT + #define GDISP_HARDWARE_BITFILLS TRUE + #endif #endif /* GDISP_USE_DMA2D */ #endif /* GFX_USE_GDISP */ diff --git a/gfxconf.example.h b/gfxconf.example.h index 046b77ed..03f1f264 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -54,6 +54,7 @@ // #define GFX_OS_PRE_INIT_FUNCTION myHardwareInitRoutine // #define GFX_OS_EXTRA_INIT_FUNCTION myOSInitRoutine // #define GFX_OS_EXTRA_DEINIT_FUNCTION myOSDeInitRoutine +// #define GFX_EMULATE_MALLOC FALSE /////////////////////////////////////////////////////////////////////////// diff --git a/src/gdisp/gdisp_image.h b/src/gdisp/gdisp_image.h index 4613bea7..2b6fdf19 100644 --- a/src/gdisp/gdisp_image.h +++ b/src/gdisp/gdisp_image.h @@ -66,7 +66,7 @@ typedef struct gdispImage { uint32_t maxmemused; /* @< How much RAM has been allocated (maximum) */ #endif const struct gdispImageHandlers * fns; /* @< Don't mess with this! */ - struct gdispImagePrivate * priv; /* @< Don't mess with this! */ + void * priv; /* @< Don't mess with this! */ } gdispImage; #ifdef __cplusplus diff --git a/src/gdisp/gdisp_image_bmp.c b/src/gdisp/gdisp_image_bmp.c index 73549ae3..371fdf2d 100644 --- a/src/gdisp/gdisp_image_bmp.c +++ b/src/gdisp/gdisp_image_bmp.c @@ -53,14 +53,17 @@ typedef struct gdispImagePrivate_BMP { } gdispImagePrivate_BMP; void gdispImageClose_BMP(gdispImage *img) { - if (img->priv) { + gdispImagePrivate_BMP *priv; + + priv = (gdispImagePrivate_BMP *)img->priv; + if (priv) { #if GDISP_NEED_IMAGE_BMP_1 || GDISP_NEED_IMAGE_BMP_4 || GDISP_NEED_IMAGE_BMP_4_RLE || GDISP_NEED_IMAGE_BMP_8 || GDISP_NEED_IMAGE_BMP_8_RLE - if (img->priv->palette) - gdispImageFree(img, (void *)img->priv->palette, img->priv->palsize*sizeof(color_t)); + if (priv->palette) + gdispImageFree(img, (void *)priv->palette, priv->palsize*sizeof(color_t)); #endif - if (img->priv->frame0cache) - gdispImageFree(img, (void *)img->priv->frame0cache, img->width*img->height*sizeof(pixel_t)); - gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate_BMP)); + if (priv->frame0cache) + gdispImageFree(img, (void *)priv->frame0cache, img->width*img->height*sizeof(pixel_t)); + gdispImageFree(img, (void *)priv, sizeof(gdispImagePrivate_BMP)); img->priv = 0; } } @@ -89,11 +92,11 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) { img->flags = 0; /* Allocate our private area */ - if (!(img->priv = (gdispImagePrivate_BMP *)gdispImageAlloc(img, sizeof(gdispImagePrivate_BMP)))) + if (!(img->priv = gdispImageAlloc(img, sizeof(gdispImagePrivate_BMP)))) return GDISP_IMAGE_ERR_NOMEMORY; /* Initialise the essential bits in the private area */ - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; priv->frame0cache = 0; priv->bmpflags = 0; #if GDISP_NEED_IMAGE_BMP_1 || GDISP_NEED_IMAGE_BMP_4 || GDISP_NEED_IMAGE_BMP_4_RLE || GDISP_NEED_IMAGE_BMP_8 || GDISP_NEED_IMAGE_BMP_8_RLE @@ -119,7 +122,7 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) { // Detect our bitmap version if (offsetColorTable == 12+14) { - img->priv->bmpflags |= BMP_V2; + priv->bmpflags |= BMP_V2; // Read the header if (gfileRead(img->f, priv->buf, 12-4) != 12-4) @@ -129,7 +132,7 @@ gdispImageError gdispImageOpen_BMP(gdispImage *img) { // Get the height img->height = gdispImageGetAlignedLE16(priv->buf, 2); if (img->height < 0) { - img->priv->bmpflags |= BMP_TOP_TO_BOTTOM; + priv->bmpflags |= BMP_TOP_TO_BOTTOM; img->height = -img->height; } // Get the planes @@ -361,7 +364,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { color_t * pc; coord_t len; - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; pc = priv->buf; len = 0; @@ -372,7 +375,7 @@ static coord_t getPixels(gdispImage *img, coord_t x) { uint8_t b[4]; uint8_t m; - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; pc = priv->buf; len = 0; @@ -703,7 +706,7 @@ gdispImageError gdispImageCache_BMP(gdispImage *img) { size_t len; /* If we are already cached - just return OK */ - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; if (priv->frame0cache) return GDISP_IMAGE_ERR_OK; @@ -720,6 +723,8 @@ gdispImageError gdispImageCache_BMP(gdispImage *img) { priv->rlecode = 0; #endif + pcs = priv->buf; // This line is just to prevent a compiler warning. + if (priv->bmpflags & BMP_TOP_TO_BOTTOM) { for(y = 0, pcd = priv->frame0cache; y < img->height; y++) { x = 0; pos = 0; @@ -756,7 +761,7 @@ gdispImageError gdispGImageDraw_BMP(GDisplay *g, gdispImage *img, coord_t x, coo coord_t mx, my; coord_t pos, len, st; - priv = img->priv; + priv = (gdispImagePrivate_BMP *)img->priv; /* Check some reasonableness */ if (sx >= img->width || sy >= img->height) return GDISP_IMAGE_ERR_OK; diff --git a/src/gdisp/gdisp_image_gif.c b/src/gdisp/gdisp_image_gif.c index f3e9d8dd..5a3f68c6 100644 --- a/src/gdisp/gdisp_image_gif.c +++ b/src/gdisp/gdisp_image_gif.c @@ -117,7 +117,7 @@ static gdispImageError startDecodeGif(gdispImage *img) { gifimgdecode * decode; uint16_t cnt; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // We need the decode ram, and possibly a palette if (!(decode = (gifimgdecode *)gdispImageAlloc(img, sizeof(gifimgdecode)+priv->frame.palsize*sizeof(color_t)))) @@ -179,7 +179,7 @@ baddatacleanup: static void stopDecodeGif(gdispImage *img) { gdispImagePrivate_GIF * priv; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // Free the decode data if (priv->decode) { @@ -214,7 +214,7 @@ static uint16_t getBytesGif(gdispImage *img) { uint16_t code, prefix; uint8_t bdata; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; decode = priv->decode; cnt = 0; @@ -346,7 +346,7 @@ static gdispImageError initFrameGif(gdispImage *img) { uint8_t blocktype; uint8_t blocksz; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // Save the dispose info from the existing frame priv->dispose.flags = priv->frame.flags; @@ -504,7 +504,7 @@ void gdispImageClose_GIF(gdispImage *img) { gifimgcache * cache; gifimgcache * ncache; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; if (priv) { // Free any stored frames cache = priv->cache; @@ -515,7 +515,7 @@ void gdispImageClose_GIF(gdispImage *img) { } if (priv->palette) gdispImageFree(img, (void *)priv->palette, priv->palsize*sizeof(color_t)); - gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate_GIF)); + gdispImageFree(img, (void *)priv, sizeof(gdispImagePrivate_GIF)); img->priv = 0; } } @@ -539,11 +539,11 @@ gdispImageError gdispImageOpen_GIF(gdispImage *img) { img->flags = 0; /* Allocate our private area */ - if (!(img->priv = (gdispImagePrivate_GIF *)gdispImageAlloc(img, sizeof(gdispImagePrivate_GIF)))) + if (!(img->priv = gdispImageAlloc(img, sizeof(gdispImagePrivate_GIF)))) return GDISP_IMAGE_ERR_NOMEMORY; /* Initialise the essential bits in the private area */ - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; priv->flags = 0; priv->palsize = 0; priv->palette = 0; @@ -610,7 +610,7 @@ gdispImageError gdispImageCache_GIF(gdispImage *img) { uint16_t cnt; /* If we are already cached - just return OK */ - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; if (priv->curcache) return GDISP_IMAGE_ERR_OK; @@ -779,7 +779,7 @@ gdispImageError gdispGImageDraw_GIF(GDisplay *g, gdispImage *img, coord_t x, coo uint16_t cnt, gcnt; uint8_t col; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; /* Handle previous frame disposing */ if (priv->dispose.flags & (GIFL_DISPOSECLEAR|GIFL_DISPOSEREST)) { @@ -1116,7 +1116,7 @@ delaytime_t gdispImageNext_GIF(gdispImage *img) { delaytime_t delay; uint8_t blocksz; - priv = img->priv; + priv = (gdispImagePrivate_GIF *)img->priv; // Save the delay and convert to millisecs delay = (delaytime_t)priv->frame.delay * 10; diff --git a/src/gdisp/gdisp_image_native.c b/src/gdisp/gdisp_image_native.c index df7c9f72..28706564 100644 --- a/src/gdisp/gdisp_image_native.c +++ b/src/gdisp/gdisp_image_native.c @@ -26,16 +26,19 @@ void *gdispImageAlloc(gdispImage *img, size_t sz); void gdispImageFree(gdispImage *img, void *ptr, size_t sz); -typedef struct gdispImagePrivate { +typedef struct gdispImagePrivate_NATIVE { pixel_t *frame0cache; pixel_t buf[BLIT_BUFFER_SIZE_NATIVE]; - } gdispImagePrivate; + } gdispImagePrivate_NATIVE; void gdispImageClose_NATIVE(gdispImage *img) { - if (img->priv) { - if (img->priv->frame0cache) - gdispImageFree(img, (void *)img->priv->frame0cache, img->width * img->height * sizeof(pixel_t)); - gdispImageFree(img, (void *)img->priv, sizeof(gdispImagePrivate)); + gdispImagePrivate_NATIVE * priv; + + priv = (gdispImagePrivate_NATIVE *)img->priv; + if (priv) { + if (priv->frame0cache) + gdispImageFree(img, (void *)priv->frame0cache, img->width * img->height * sizeof(pixel_t)); + gdispImageFree(img, (void *)priv, sizeof(gdispImagePrivate_NATIVE)); img->priv = 0; } } @@ -59,9 +62,9 @@ gdispImageError gdispImageOpen_NATIVE(gdispImage *img) { img->height = (((uint16_t)hdr[4])<<8) | (hdr[5]); if (img->width < 1 || img->height < 1) return GDISP_IMAGE_ERR_BADDATA; - if (!(img->priv = (gdispImagePrivate *)gdispImageAlloc(img, sizeof(gdispImagePrivate)))) + if (!(img->priv = gdispImageAlloc(img, sizeof(gdispImagePrivate_NATIVE)))) return GDISP_IMAGE_ERR_NOMEMORY; - img->priv->frame0cache = 0; + ((gdispImagePrivate_NATIVE *)(img->priv))->frame0cache = 0; img->type = GDISP_IMAGE_TYPE_NATIVE; return GDISP_IMAGE_ERR_OK; @@ -69,20 +72,22 @@ gdispImageError gdispImageOpen_NATIVE(gdispImage *img) { gdispImageError gdispImageCache_NATIVE(gdispImage *img) { size_t len; + gdispImagePrivate_NATIVE * priv; /* If we are already cached - just return OK */ - if (img->priv->frame0cache) + priv = (gdispImagePrivate_NATIVE *)img->priv; + if (priv->frame0cache) return GDISP_IMAGE_ERR_OK; /* We need to allocate the cache */ len = img->width * img->height * sizeof(pixel_t); - img->priv->frame0cache = (pixel_t *)gdispImageAlloc(img, len); - if (!img->priv->frame0cache) + priv->frame0cache = (pixel_t *)gdispImageAlloc(img, len); + if (!priv->frame0cache) return GDISP_IMAGE_ERR_NOMEMORY; /* Read the entire bitmap into cache */ gfileSetPos(img->f, FRAME0POS_NATIVE); - if (gfileRead(img->f, img->priv->frame0cache, len) != len) + if (gfileRead(img->f, priv->frame0cache, len) != len) return GDISP_IMAGE_ERR_BADDATA; return GDISP_IMAGE_ERR_OK; @@ -91,6 +96,9 @@ gdispImageError gdispImageCache_NATIVE(gdispImage *img) { gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy) { coord_t mx, mcx; size_t pos, len; + gdispImagePrivate_NATIVE * priv; + + priv = (gdispImagePrivate_NATIVE *)img->priv; /* Check some reasonableness */ if (sx >= img->width || sy >= img->height) return GDISP_IMAGE_ERR_OK; @@ -98,8 +106,8 @@ gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, if (sy + cy > img->height) cy = img->height - sy; /* Draw from the image cache - if it exists */ - if (img->priv->frame0cache) { - gdispGBlitArea(g, x, y, cx, cy, sx, sy, img->width, img->priv->frame0cache); + if (priv->frame0cache) { + gdispGBlitArea(g, x, y, cx, cy, sx, sy, img->width, priv->frame0cache); return GDISP_IMAGE_ERR_OK; } @@ -115,14 +123,14 @@ gdispImageError gdispGImageDraw_NATIVE(GDisplay *g, gdispImage *img, coord_t x, for(mx = x, mcx = cx; mcx > 0; mcx -= len, mx += len) { // Read the data len = gfileRead(img->f, - img->priv->buf, + priv->buf, mcx > BLIT_BUFFER_SIZE_NATIVE ? (BLIT_BUFFER_SIZE_NATIVE*sizeof(pixel_t)) : (mcx * sizeof(pixel_t))) / sizeof(pixel_t); if (!len) return GDISP_IMAGE_ERR_BADDATA; /* Blit the chunk of data */ - gdispGBlitArea(g, mx, y, len, 1, 0, 0, len, img->priv->buf); + gdispGBlitArea(g, mx, y, len, 1, 0, 0, len, priv->buf); } /* Get the position for the start of the next line */ diff --git a/src/gos/gos.h b/src/gos/gos.h index c3cdca50..1c4ef865 100644 --- a/src/gos/gos.h +++ b/src/gos/gos.h @@ -175,6 +175,23 @@ */ void gfxFree(void *ptr); + /** + * @brief Use gfxAlloc and gfxFree to implement malloc() and free() + * + * @notes Sometimes your application will include functions that + * want to internally use malloc() and free(). As the default + * implementations of these in your C library are almost + * invariably incorrect for an embedded platform, this option + * allows you to emulate those calls with gfxAlloc() and gfxFree(). + * An example is the C library routine rand() which on many + * implementations internally uses malloc(). + * + * @api + */ + #ifndef GFX_EMULATE_MALLOC + #define GFX_EMULATE_MALLOC FALSE + #endif + /** * @brief Yield the current thread * @details Give up the rest of the current time slice for this thread in order to give other threads diff --git a/src/gos/gos_arduino.h b/src/gos/gos_arduino.h index 6a18aaec..3019d271 100644 --- a/src/gos/gos_arduino.h +++ b/src/gos/gos_arduino.h @@ -31,7 +31,7 @@ /* Type definitions */ /*===========================================================================*/ -typedef bool bool_t; +typedef unsigned char bool_t; #if 0 // Already defined by Arduino diff --git a/src/gos/gos_options.h b/src/gos/gos_options.h index 4b33f5ac..0c6fd7a7 100644 --- a/src/gos/gos_options.h +++ b/src/gos/gos_options.h @@ -181,9 +181,10 @@ #define GFX_FREERTOS_USE_TRACE FALSE #endif /** - * @brief How much RAM should uGFX use for the heap + * @brief How much RAM should uGFX use for the heap when using its own internal heap allocator * @details Defaults to 0. - * @note Only used when the generic ugfx heap code is used (GFX_USE_OS_RAW32, GFX_USE_OS_ARDUINO, GFX_US_OS_KEIL, GFX_USE_OS_CMSIS) + * @note Only used when the internal ugfx heap allocator is used + * (GFX_USE_OS_RAW32, GFX_USE_OS_ARDUINO, GFX_US_OS_KEIL, GFX_USE_OS_CMSIS) * @note If 0 then the standard C runtime malloc(), free() and realloc() * are used. * @note If it is non-zero then this is the number of bytes of RAM diff --git a/src/gos/gos_rules.h b/src/gos/gos_rules.h index b0184eb0..d2e64ff1 100644 --- a/src/gos/gos_rules.h +++ b/src/gos/gos_rules.h @@ -32,5 +32,16 @@ #error "GOS: GFX_FREERTOS_USE_TRACE is only available for the FreeRTOS port." #endif +#if GFX_EMULATE_MALLOC + #if GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX || GFX_USE_OS_ECOS || \ + (GFX_OS_HEAP_SIZE == 0 && (GFX_USE_OS_RAW32 || GFX_USE_OS_ARDUINO || GFX_USE_OS_CMSIS || GFX_USE_OS_KEIL)) + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GOS: Cannot emulate malloc as gfxAlloc() internally uses malloc on this platform" + #endif + #undef GFX_EMULATE_MALLOC + #define GFX_EMULATE_MALLOC FALSE + #endif +#endif + #endif /* _GOS_RULES_H */ /** @} */ diff --git a/src/gos/gos_x_heap.c b/src/gos/gos_x_heap.c index cd78f403..7e79d1c6 100644 --- a/src/gos/gos_x_heap.c +++ b/src/gos/gos_x_heap.c @@ -194,3 +194,14 @@ #endif #endif /* GOS_NEED_X_HEAP */ + +#if GFX_EMULATE_MALLOC + #include + + void* malloc(size_t size) { + return gfxAlloc(size); + } + void free(void *ptr) { + gfxFree(ptr); + } +#endif diff --git a/src/gos/gos_x_heap.h b/src/gos/gos_x_heap.h index 3612989c..0fbfc905 100644 --- a/src/gos/gos_x_heap.h +++ b/src/gos/gos_x_heap.h @@ -5,38 +5,10 @@ * http://ugfx.org/license.html */ -/** - * The raw32 GOS implementation supports any 32 bit processor with or without an - * underlying operating system. It uses cooperative multi-tasking. Be careful - * when writing device drivers not to disturb the assumptions this creates by performing - * call-backs to uGFX code unless you define the INTERRUPTS_OFF() and INTERRUPTS_ON() macros. - * It still requires some C runtime library support... - * enough startup to initialise the stack, interrupts, static data etc and call main(). - * setjmp() and longjmp() - for threading - * memcpy() - for heap and threading - * malloc(), realloc and free() - if GFX_OS_HEAP_SIZE == 0 - * - * You must also define the following routines in your own code so that timing functions will work... - * systemticks_t gfxSystemTicks(void); - * systemticks_t gfxMillisecondsToTicks(delaytime_t ms); - */ #ifndef _GOS_X_HEAP_H #define _GOS_X_HEAP_H -#if GOS_NEED_X_HEAP - - -/*===========================================================================*/ -/* Special Macros */ -/*===========================================================================*/ - -/** - * @brief Set the maximum size of the heap. - * @note If set to 0 then the C runtime library malloc() and free() are used. - */ -#ifndef GFX_OS_HEAP_SIZE - #define GFX_OS_HEAP_SIZE 0 -#endif +#if GOS_NEED_X_HEAP || defined(__DOXYGEN__) /*===========================================================================*/ /* Type definitions */ @@ -46,7 +18,17 @@ extern "C" { #endif - #if GFX_OS_HEAP_SIZE != 0 + #if GFX_OS_HEAP_SIZE != 0 || defined(__DOXYGEN__) + /** + * @brief Take a chunk of memory and add it to the available heap + * @note Memory added must obviously not already be on the heap. + * @note It is allowable to add multiple non-contiguous blocks of memory + * to the heap. If however it is contiguous with a previously added block + * it will get merged with the existing block in order to allow + * allocations that span the boundary. + * @pre GFX_OS_HEAP_SIZE != 0 and an operating system that uses the + * internal ugfx heap allocator rather than its own allocator. + */ void gfxAddHeapBlock(void *ptr, size_t sz); #endif diff --git a/src/gwin/gwin_keyboard.c b/src/gwin/gwin_keyboard.c index 7080cd5d..59befa3f 100644 --- a/src/gwin/gwin_keyboard.c +++ b/src/gwin/gwin_keyboard.c @@ -364,7 +364,7 @@ GSourceHandle gwinKeyboardGetEventSource(GHandle gh) { return (GSourceHandle)gh; } -void gwinKeyboardSetLayout(GHandle gh, struct GVKeyTable *layout) { +void gwinKeyboardSetLayout(GHandle gh, const struct GVKeyTable *layout) { #define gk ((GKeyboardObject *)gh) if (gh->vmt != (gwinVMT *)&keyboardVMT) diff --git a/src/gwin/gwin_keyboard.h b/src/gwin/gwin_keyboard.h index 347b4bb4..a09127bd 100644 --- a/src/gwin/gwin_keyboard.h +++ b/src/gwin/gwin_keyboard.h @@ -101,7 +101,7 @@ GSourceHandle gwinKeyboardGetEventSource(GHandle gh); * @note Changing the layout resets the keyboard to key set 0 of the keyboard and cancels any * pending shifts. */ -void gwinKeyboardSetLayout(GHandle gh, struct GVKeyTable *layout); +void gwinKeyboardSetLayout(GHandle gh, const struct GVKeyTable *layout); /** * @defgroup Renderings_Keyboard Renderings