diff --git a/Drivers/ili9341-module/bindings/ilitek,ili9341.yaml b/Drivers/ili9341-module/bindings/ilitek,ili9341.yaml index 1588890d6..0d805b82b 100644 --- a/Drivers/ili9341-module/bindings/ilitek,ili9341.yaml +++ b/Drivers/ili9341-module/bindings/ilitek,ili9341.yaml @@ -53,6 +53,10 @@ properties: type: int default: 10 description: Size of the internal SPI transaction queue + gamma-curve: + type: int + default: 1 + description: Gamma curve preset index [0,3], sent via the MIPI DCS GAMSET (0x26) command at bring-up pin-dc: type: phandles required: true diff --git a/Drivers/ili9341-module/include/drivers/ili9341.h b/Drivers/ili9341-module/include/drivers/ili9341.h index 8c1b64a39..d7b105b5e 100644 --- a/Drivers/ili9341-module/include/drivers/ili9341.h +++ b/Drivers/ili9341-module/include/drivers/ili9341.h @@ -24,6 +24,8 @@ struct Ili9341Config { uint32_t bits_per_pixel; uint32_t pixel_clock_hz; uint8_t transaction_queue_depth; + // Gamma curve preset index [0,3], sent via the MIPI DCS GAMSET (0x26) command at bring-up. + uint8_t gamma_curve; struct GpioPinSpec pin_dc; struct GpioPinSpec pin_reset; bool reset_active_high; diff --git a/Drivers/ili9341-module/source/ili9341.cpp b/Drivers/ili9341-module/source/ili9341.cpp index 84d2cbeac..8971480dd 100644 --- a/Drivers/ili9341-module/source/ili9341.cpp +++ b/Drivers/ili9341-module/source/ili9341.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,11 @@ #define GET_CONFIG(device) (static_cast((device)->config)) +// Maps gamma-curve devicetree index [0,3] to the MIPI DCS GAMSET (0x26) parameter value. Mirrors +// the deprecated HAL's EspLcdSpiDisplay::setGammaCurve() (Drivers/EspLcdCompat) - note the +// non-linear mapping, not index+1. +static const uint8_t GAMMA_CURVE_VALUES[4] = { 0x01, 0x04, 0x02, 0x08 }; + struct Ili9341Internal { esp_lcd_panel_io_handle_t io_handle; esp_lcd_panel_handle_t panel_handle; @@ -140,6 +146,7 @@ static error_t start(Device* device) { ok = ok && (!config->swap_xy || esp_lcd_panel_swap_xy(internal->panel_handle, true) == ESP_OK); ok = ok && ((!config->mirror_x && !config->mirror_y) || esp_lcd_panel_mirror(internal->panel_handle, config->mirror_x, config->mirror_y) == ESP_OK); ok = ok && (!config->invert_color || esp_lcd_panel_invert_color(internal->panel_handle, true) == ESP_OK); + ok = ok && (config->gamma_curve >= 4 || esp_lcd_panel_io_tx_param(internal->io_handle, LCD_CMD_GAMSET, &GAMMA_CURVE_VALUES[config->gamma_curve], 1) == ESP_OK); ok = ok && esp_lcd_panel_disp_on_off(internal->panel_handle, true) == ESP_OK; if (!ok) { diff --git a/Drivers/st7789-i8080-module/bindings/sitronix,st7789-i8080.yaml b/Drivers/st7789-i8080-module/bindings/sitronix,st7789-i8080.yaml index dbf57f2c5..fcc0e4585 100644 --- a/Drivers/st7789-i8080-module/bindings/sitronix,st7789-i8080.yaml +++ b/Drivers/st7789-i8080-module/bindings/sitronix,st7789-i8080.yaml @@ -49,6 +49,10 @@ properties: type: int default: 10 description: Size of the internal transaction queue + gamma-curve: + type: int + default: 1 + description: Gamma curve preset index [0,3], sent via the MIPI DCS GAMSET (0x26) command at bring-up pin-reset: type: phandles default: GPIO_PIN_SPEC_NONE diff --git a/Drivers/st7789-i8080-module/include/drivers/st7789_i8080.h b/Drivers/st7789-i8080-module/include/drivers/st7789_i8080.h index 1a59b9c23..c71b281ff 100644 --- a/Drivers/st7789-i8080-module/include/drivers/st7789_i8080.h +++ b/Drivers/st7789-i8080-module/include/drivers/st7789_i8080.h @@ -23,6 +23,8 @@ struct St7789I8080Config { bool bgr_order; uint32_t pixel_clock_hz; uint8_t transaction_queue_depth; + // Gamma curve preset index [0,3], sent via the MIPI DCS GAMSET (0x26) command at bring-up. + uint8_t gamma_curve; struct GpioPinSpec pin_reset; bool reset_active_high; // Optional reference to this display's backlight device, NULL if none. diff --git a/Drivers/st7789-i8080-module/source/st7789_i8080.cpp b/Drivers/st7789-i8080-module/source/st7789_i8080.cpp index 6e93bcc39..6d0d12ef4 100644 --- a/Drivers/st7789-i8080-module/source/st7789_i8080.cpp +++ b/Drivers/st7789-i8080-module/source/st7789_i8080.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -24,6 +25,11 @@ #define TAG "ST7789I8080" #define GET_CONFIG(device) (static_cast((device)->config)) +// Maps gamma-curve devicetree index [0,3] to the MIPI DCS GAMSET (0x26) parameter value. Mirrors +// the deprecated HAL's EspLcdSpiDisplay::setGammaCurve() (Drivers/EspLcdCompat) - note the +// non-linear mapping, not index+1. +static const uint8_t GAMMA_CURVE_VALUES[4] = { 0x01, 0x04, 0x02, 0x08 }; + namespace { // Panel bring-up commands beyond esp_lcd_panel_init()'s generic ST7789 sequence: gate/porch/power @@ -179,6 +185,7 @@ static error_t start(Device* device) { ok = ok && (!config->swap_xy || esp_lcd_panel_swap_xy(internal->panel_handle, true) == ESP_OK); ok = ok && ((!config->mirror_x && !config->mirror_y) || esp_lcd_panel_mirror(internal->panel_handle, config->mirror_x, config->mirror_y) == ESP_OK); ok = ok && (!config->invert_color || esp_lcd_panel_invert_color(internal->panel_handle, true) == ESP_OK); + ok = ok && (config->gamma_curve >= 4 || esp_lcd_panel_io_tx_param(internal->io_handle, LCD_CMD_GAMSET, &GAMMA_CURVE_VALUES[config->gamma_curve], 1) == ESP_OK); ok = ok && esp_lcd_panel_disp_on_off(internal->panel_handle, true) == ESP_OK; if (!ok) { diff --git a/Drivers/st7789-module/bindings/sitronix,st7789.yaml b/Drivers/st7789-module/bindings/sitronix,st7789.yaml index ce89db639..a3f0d43ab 100644 --- a/Drivers/st7789-module/bindings/sitronix,st7789.yaml +++ b/Drivers/st7789-module/bindings/sitronix,st7789.yaml @@ -53,6 +53,10 @@ properties: type: int default: 10 description: Size of the internal SPI transaction queue + gamma-curve: + type: int + default: 1 + description: Gamma curve preset index [0,3], sent via the MIPI DCS GAMSET (0x26) command at bring-up pin-dc: type: phandles required: true diff --git a/Drivers/st7789-module/include/drivers/st7789.h b/Drivers/st7789-module/include/drivers/st7789.h index 87f53edf5..6358acacc 100644 --- a/Drivers/st7789-module/include/drivers/st7789.h +++ b/Drivers/st7789-module/include/drivers/st7789.h @@ -24,6 +24,8 @@ struct St7789Config { uint32_t bits_per_pixel; uint32_t pixel_clock_hz; uint8_t transaction_queue_depth; + // Gamma curve preset index [0,3], sent via the MIPI DCS GAMSET (0x26) command at bring-up. + uint8_t gamma_curve; struct GpioPinSpec pin_dc; struct GpioPinSpec pin_reset; bool reset_active_high; diff --git a/Drivers/st7789-module/source/st7789.cpp b/Drivers/st7789-module/source/st7789.cpp index 20a5bd8d4..c76742a7a 100644 --- a/Drivers/st7789-module/source/st7789.cpp +++ b/Drivers/st7789-module/source/st7789.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,11 @@ #define GET_CONFIG(device) (static_cast((device)->config)) +// Maps gamma-curve devicetree index [0,3] to the MIPI DCS GAMSET (0x26) parameter value. Mirrors +// the deprecated HAL's EspLcdSpiDisplay::setGammaCurve() (Drivers/EspLcdCompat) - note the +// non-linear mapping, not index+1. +static const uint8_t GAMMA_CURVE_VALUES[4] = { 0x01, 0x04, 0x02, 0x08 }; + struct St7789Internal { esp_lcd_panel_io_handle_t io_handle; esp_lcd_panel_handle_t panel_handle; @@ -140,6 +146,7 @@ static error_t start(Device* device) { ok = ok && (!config->swap_xy || esp_lcd_panel_swap_xy(internal->panel_handle, true) == ESP_OK); ok = ok && ((!config->mirror_x && !config->mirror_y) || esp_lcd_panel_mirror(internal->panel_handle, config->mirror_x, config->mirror_y) == ESP_OK); ok = ok && (!config->invert_color || esp_lcd_panel_invert_color(internal->panel_handle, true) == ESP_OK); + ok = ok && (config->gamma_curve >= 4 || esp_lcd_panel_io_tx_param(internal->io_handle, LCD_CMD_GAMSET, &GAMMA_CURVE_VALUES[config->gamma_curve], 1) == ESP_OK); ok = ok && esp_lcd_panel_disp_on_off(internal->panel_handle, true) == ESP_OK; if (!ok) {