diff --git a/drivers/Kconfig b/drivers/Kconfig index 2b16ea0337..06e0aec9a3 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -19,17 +19,20 @@ rsource "motor_driver/Kconfig" rsource "my9221/Kconfig" endmenu # Actuator Device Drivers +menu "Display Device Drivers" +rsource "disp_dev/Kconfig" +rsource "dsp0401/Kconfig" +rsource "hd44780/Kconfig" +rsource "ili9341/Kconfig" +endmenu # Display Device Drivers + menu "Miscellaneous Device Drivers" rsource "at/Kconfig" rsource "at24mac/Kconfig" -rsource "disp_dev/Kconfig" rsource "ds1307/Kconfig" rsource "ds3231/Kconfig" rsource "ds3234/Kconfig" -rsource "dsp0401/Kconfig" rsource "edbg_eui/Kconfig" -rsource "hd44780/Kconfig" -rsource "ili9341/Kconfig" rsource "io1_xplained/Kconfig" rsource "uart_half_duplex/Kconfig" endmenu # Miscellaneous Device Drivers diff --git a/drivers/ili9341/Kconfig b/drivers/ili9341/Kconfig index f63d082f74..78a30b0cfe 100644 --- a/drivers/ili9341/Kconfig +++ b/drivers/ili9341/Kconfig @@ -13,3 +13,47 @@ config MODULE_ILI9341 select MODULE_PERIPH_SPI select MODULE_PERIPH_GPIO select MODULE_XTIMER + +menuconfig KCONFIG_USEMODULE_ILI9341 + bool "Configure ILI9341 driver" + depends on USEMODULE_ILI9341 + help + Configure the ILI9341 display driver using Kconfig. + +if KCONFIG_USEMODULE_ILI9341 + +config ILI9341_GVDD + int "GVDD voltage level (in millivolts)" + default 4800 + range 3000 6000 + help + Configure GVDD level, which is a reference level for the VCOM level and + the grayscale voltage level. GVDD should be ≦ (AVDD - 0.5) V . + +config ILI9341_VCOMH + int "VCOMH voltage level (in millivolts)" + default 4250 + range 2700 5875 + help + Configure the high level of VCOM AC voltage. VCOM needs to be adjusted + to match the capacitance and performance specifications of the TFT panel + to maximize contrast and minimize flickering + +config ILI9341_VCOML + int "VCOML voltage level (in millivolts)" + default -2000 + range -2500 0 + help + Configure the low level of VCOM AC voltage. VCOM needs to be adjusted to + match the capacitance and performance specifications of the TFT panel to + maximize contrast and minimize flickering + +config ILI9341_LE_MODE + bool "Enable little endian to big endian conversion" + help + Enable this configuration to convert little endian colors to big endian. + ILI9341 device requires colors to be send in big endian RGB-565 format. + Enabling this option allows for little endian colors. Enabling this + however will slow down the driver as it cannot use DMA anymore. + +endif # KCONFIG_USEMODULE_ILI9341 diff --git a/drivers/ili9341/ili9341.c b/drivers/ili9341/ili9341.c index 5f6967db30..455c3faffb 100644 --- a/drivers/ili9341/ili9341.c +++ b/drivers/ili9341/ili9341.c @@ -23,6 +23,8 @@ #include "byteorder.h" #include "periph/spi.h" #include "xtimer.h" +#include "kernel_defines.h" + #include "ili9341.h" #include "ili9341_internal.h" @@ -114,15 +116,15 @@ int ili9341_init(ili9341_t *dev, const ili9341_params_t *params) _write_cmd(dev, ILI9341_CMD_DISPOFF, NULL, 0); /* PWRCTL1/2 */ - command_params[0] = _ili9341_calc_pwrctl1(ILI9341_GVDD); + command_params[0] = _ili9341_calc_pwrctl1(CONFIG_ILI9341_GVDD); _write_cmd(dev, ILI9341_CMD_PWCTRL1, command_params, 1); command_params[0] = 0x10; /* PWRCTL 0 0 0 */ _write_cmd(dev, ILI9341_CMD_PWCTRL2, command_params, 1); /* VCOMCTL */ - command_params[0] = _ili9341_calc_vmh(ILI9341_VCOMH); - command_params[1] = _ili9341_calc_vml(ILI9341_VCOML); + command_params[0] = _ili9341_calc_vmh(CONFIG_ILI9341_VCOMH); + command_params[1] = _ili9341_calc_vml(CONFIG_ILI9341_VCOML); _write_cmd(dev, ILI9341_CMD_VMCTRL1, command_params, 2); command_params[0] = 0x86; @@ -248,9 +250,11 @@ void ili9341_fill(const ili9341_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, _ili9341_set_area(dev, x1, x2, y1, y2); /* Memory access command */ _ili9341_cmd_start(dev, ILI9341_CMD_RAMWR, true); -#if ILI9341_LE_MODE - color = htons(color); -#endif + + if (IS_ACTIVE(CONFIG_ILI9341_LE_MODE)) { + color = htons(color); + } + for (int i = 0; i < (num_pix - 1); i++) { spi_transfer_bytes(dev->params->spi, dev->params->cs_pin, true, (uint8_t *)&color, NULL, sizeof(color)); @@ -277,20 +281,20 @@ void ili9341_pixmap(const ili9341_t *dev, uint16_t x1, uint16_t x2, /* Memory access command */ _ili9341_cmd_start(dev, ILI9341_CMD_RAMWR, true); -#if ILI9341_LE_MODE - for (size_t i = 0; i < num_pix - 1; i++) { - uint16_t ncolor = htons(*(color + i)); - spi_transfer_bytes(dev->params->spi, dev->params->cs_pin, true, + if (IS_ACTIVE(CONFIG_ILI9341_LE_MODE)) { + for (size_t i = 0; i < num_pix - 1; i++) { + uint16_t ncolor = htons(*(color + i)); + spi_transfer_bytes(dev->params->spi, dev->params->cs_pin, true, + &ncolor, NULL, sizeof(uint16_t)); + } + uint16_t ncolor = htons(*(color + num_pix - 1)); + spi_transfer_bytes(dev->params->spi, dev->params->cs_pin, false, &ncolor, NULL, sizeof(uint16_t)); } - uint16_t ncolor = htons(*(color + num_pix - 1)); - spi_transfer_bytes(dev->params->spi, dev->params->cs_pin, false, - &ncolor, NULL, sizeof(uint16_t)); -#else - spi_transfer_bytes(dev->params->spi, dev->params->cs_pin, false, - (const uint8_t *)color, NULL, num_pix * 2); - -#endif + else { + spi_transfer_bytes(dev->params->spi, dev->params->cs_pin, false, + (const uint8_t *)color, NULL, num_pix * 2); + } spi_release(dev->params->spi); } diff --git a/drivers/include/ili9341.h b/drivers/include/ili9341.h index 638ca8a4a1..06e8ae7876 100644 --- a/drivers/include/ili9341.h +++ b/drivers/include/ili9341.h @@ -23,7 +23,7 @@ * implemented here operates over SPI to communicate with the device. * * The device requires colors to be send in big endian RGB-565 format. The - * @ref ILI9341_LE_MODE compile time option can switch this, but only use this + * @ref CONFIG_ILI9341_LE_MODE compile time option can switch this, but only use this * when strictly necessary. This option will slow down the driver as it * certainly can't use DMA anymore, every short has to be converted before * transfer. @@ -52,28 +52,35 @@ extern "C" { /** * @brief ILI9341 gvdd level. * - * Default GVDD voltage of 4.8V + * Default GVDD voltage of 4.8V. GVDD is reference level for the VCOM level and + * the grayscale voltage level. GVDD should be ≦ (AVDD - 0.5) V . */ -#ifndef ILI9341_GVDD -#define ILI9341_GVDD 4800 +#ifndef CONFIG_ILI9341_GVDD +#define CONFIG_ILI9341_GVDD 4800 #endif /** * @brief ILI9341 VCOMH voltage level. * - * Default VCOMH voltage of 4.25V + * Default VCOMH voltage of 4.25V. VCOMH represents the high level of VCOM AC + * voltage. VCOM levels needs to be adjusted to match the capacitance and + * performance specifications of the TFT panel to maximize contrast and minimize + * flickering. */ -#ifndef ILI9341_VCOMH -#define ILI9341_VCOMH 4250 +#ifndef CONFIG_ILI9341_VCOMH +#define CONFIG_ILI9341_VCOMH 4250 #endif /** * @brief ILI9341 VCOML voltage level. * - * Default VCOMH voltage of -2V + * Default VCOML voltage of -2V. VCOML represents the low level of VCOM AC + * voltage. VCOM levels needs to be adjusted to match the capacitance and + * performance specifications of the TFT panel to maximize contrast and minimize + * flickering */ -#ifndef ILI9341_VCOML -#define ILI9341_VCOML -2000 +#ifndef CONFIG_ILI9341_VCOML +#define CONFIG_ILI9341_VCOML -2000 #endif /** @@ -82,8 +89,8 @@ extern "C" { * Compile time switch to change the driver to convert little endian * colors to big endian. */ -#ifndef ILI9341_LE_MODE -#define ILI9341_LE_MODE (0) +#ifdef DOXYGEN +#define CONFIG_ILI9341_LE_MODE #endif /** @} */ diff --git a/tests/driver_ili9341/Makefile b/tests/driver_ili9341/Makefile index cb1b116be4..be97670a5e 100644 --- a/tests/driver_ili9341/Makefile +++ b/tests/driver_ili9341/Makefile @@ -4,10 +4,13 @@ include ../Makefile.tests_common USEMODULE += ili9341 USEMODULE += xtimer -CFLAGS += -DILI9341_LE_MODE - include $(RIOTBASE)/Makefile.include +# Check if being configured via Kconfig +ifndef CONFIG_KCONFIG_USEMODULE_ILI9341 +CFLAGS += -DCONFIG_ILI9341_LE_MODE +endif + # The AVR architecture stores the image in the RAM, this usually doesn't fit. # This flag excludes the image from the test ifneq (,$(filter arch_avr8,$(FEATURES_USED)))