refactor(lcd): reuse the color types in the hal/color_types.h

This commit is contained in:
morris
2023-10-31 18:44:08 +08:00
parent 0c3f80495a
commit 7121e8f78d
7 changed files with 132 additions and 60 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,6 +15,14 @@ extern "C" {
typedef struct esp_lcd_panel_io_t *esp_lcd_panel_io_handle_t; /*!< Type of LCD panel IO handle */
typedef struct esp_lcd_panel_t *esp_lcd_panel_handle_t; /*!< Type of LCD panel handle */
/**
* @brief RGB element order
*/
typedef enum {
LCD_RGB_ELEMENT_ORDER_RGB, /*!< RGB element order: RGB */
LCD_RGB_ELEMENT_ORDER_BGR, /*!< RGB element order: BGR */
} lcd_rgb_element_order_t;
/** @cond */
/**
* @brief LCD color space type definition (WRONG!)
@@ -30,6 +38,11 @@ typedef enum {
// Ensure binary compatibility with lcd_color_rgb_endian_t
ESP_STATIC_ASSERT((lcd_rgb_element_order_t)ESP_LCD_COLOR_SPACE_RGB == LCD_RGB_ELEMENT_ORDER_RGB, "ESP_LCD_COLOR_SPACE_RGB is not compatible with LCD_RGB_ORDER_RGB");
ESP_STATIC_ASSERT((lcd_rgb_element_order_t)ESP_LCD_COLOR_SPACE_BGR == LCD_RGB_ELEMENT_ORDER_BGR, "ESP_LCD_COLOR_SPACE_BGR is not compatible with LCD_RGB_ORDER_BGR");
/// for backward compatible
typedef lcd_rgb_element_order_t lcd_color_rgb_endian_t;
#define LCD_RGB_ENDIAN_RGB LCD_RGB_ELEMENT_ORDER_RGB
#define LCD_RGB_ENDIAN_BGR LCD_RGB_ELEMENT_ORDER_BGR
/** @endcond */
#ifdef __cplusplus

View File

@@ -29,10 +29,6 @@ extern "C" {
#define LCD_LL_CLK_FRAC_DIV_AB_MAX 64 // LCD_CLK = LCD_CLK_S / (N + b/a), the a/b register is 6 bit-width
#define LCD_LL_PCLK_DIV_MAX 64 // LCD_PCLK = LCD_CLK / MO, the MO register is 6 bit-width
#define LCD_LL_COLOR_RANGE_TO_REG(range) (uint8_t[]){0,1}[(range)]
#define LCD_LL_CONV_STD_TO_REG(std) (uint8_t[]){0,1}[(std)]
#define LCD_LL_YUV_SAMPLE_TO_REG(sample) (uint8_t[]){0,1,2}[(sample)]
/**
* @brief Enable clock gating
*
@@ -92,7 +88,6 @@ static inline void lcd_ll_set_group_clock_coeff(lcd_cam_dev_t *dev, int div_num,
dev->lcd_clock.lcd_clkm_div_b = div_b;
}
/**
* @brief Set the PCLK clock level state when there's no transaction undergoing
*
@@ -170,7 +165,11 @@ static inline void lcd_ll_set_convert_data_width(lcd_cam_dev_t *dev, uint32_t wi
*/
static inline void lcd_ll_set_input_color_range(lcd_cam_dev_t *dev, lcd_color_range_t range)
{
dev->lcd_rgb_yuv.lcd_conv_data_in_mode = LCD_LL_COLOR_RANGE_TO_REG(range);
if (range == LCD_COLOR_RANGE_LIMIT) {
dev->lcd_rgb_yuv.lcd_conv_data_in_mode = 0;
} else if (range == LCD_COLOR_RANGE_FULL) {
dev->lcd_rgb_yuv.lcd_conv_data_in_mode = 1;
}
}
/**
@@ -181,7 +180,11 @@ static inline void lcd_ll_set_input_color_range(lcd_cam_dev_t *dev, lcd_color_ra
*/
static inline void lcd_ll_set_output_color_range(lcd_cam_dev_t *dev, lcd_color_range_t range)
{
dev->lcd_rgb_yuv.lcd_conv_data_out_mode = LCD_LL_COLOR_RANGE_TO_REG(range);
if (range == LCD_COLOR_RANGE_LIMIT) {
dev->lcd_rgb_yuv.lcd_conv_data_out_mode = 0;
} else if (range == LCD_COLOR_RANGE_FULL) {
dev->lcd_rgb_yuv.lcd_conv_data_out_mode = 1;
}
}
/**
@@ -192,7 +195,11 @@ static inline void lcd_ll_set_output_color_range(lcd_cam_dev_t *dev, lcd_color_r
*/
static inline void lcd_ll_set_yuv_convert_std(lcd_cam_dev_t *dev, lcd_yuv_conv_std_t std)
{
dev->lcd_rgb_yuv.lcd_conv_protocol_mode = LCD_LL_CONV_STD_TO_REG(std);
if (std == LCD_YUV_CONV_STD_BT601) {
dev->lcd_rgb_yuv.lcd_conv_protocol_mode = 0;
} else if (std == LCD_YUV_CONV_STD_BT709) {
dev->lcd_rgb_yuv.lcd_conv_protocol_mode = 1;
}
}
/**
@@ -204,8 +211,20 @@ static inline void lcd_ll_set_yuv_convert_std(lcd_cam_dev_t *dev, lcd_yuv_conv_s
static inline void lcd_ll_set_convert_mode_rgb_to_yuv(lcd_cam_dev_t *dev, lcd_yuv_sample_t yuv_sample)
{
dev->lcd_rgb_yuv.lcd_conv_trans_mode = 1;
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = LCD_LL_YUV_SAMPLE_TO_REG(yuv_sample);
dev->lcd_rgb_yuv.lcd_conv_yuv2yuv_mode = 3;
switch (yuv_sample) {
case LCD_YUV_SAMPLE_422:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 0;
break;
case LCD_YUV_SAMPLE_420:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 1;
break;
case LCD_YUV_SAMPLE_411:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 2;
break;
default:
abort();
}
}
/**
@@ -217,8 +236,20 @@ static inline void lcd_ll_set_convert_mode_rgb_to_yuv(lcd_cam_dev_t *dev, lcd_yu
static inline void lcd_ll_set_convert_mode_yuv_to_rgb(lcd_cam_dev_t *dev, lcd_yuv_sample_t yuv_sample)
{
dev->lcd_rgb_yuv.lcd_conv_trans_mode = 0;
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = LCD_LL_YUV_SAMPLE_TO_REG(yuv_sample);
dev->lcd_rgb_yuv.lcd_conv_yuv2yuv_mode = 3;
switch (yuv_sample) {
case LCD_YUV_SAMPLE_422:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 0;
break;
case LCD_YUV_SAMPLE_420:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 1;
break;
case LCD_YUV_SAMPLE_411:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 2;
break;
default:
abort();
}
}
/**
@@ -232,8 +263,32 @@ static inline void lcd_ll_set_convert_mode_yuv_to_yuv(lcd_cam_dev_t *dev, lcd_yu
{
HAL_ASSERT(src_sample != dst_sample);
dev->lcd_rgb_yuv.lcd_conv_trans_mode = 1;
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = LCD_LL_YUV_SAMPLE_TO_REG(src_sample);
dev->lcd_rgb_yuv.lcd_conv_yuv2yuv_mode = LCD_LL_YUV_SAMPLE_TO_REG(dst_sample);
switch (src_sample) {
case LCD_YUV_SAMPLE_422:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 0;
break;
case LCD_YUV_SAMPLE_420:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 1;
break;
case LCD_YUV_SAMPLE_411:
dev->lcd_rgb_yuv.lcd_conv_yuv_mode = 2;
break;
default:
abort();
}
switch (dst_sample) {
case LCD_YUV_SAMPLE_422:
dev->lcd_rgb_yuv.lcd_conv_yuv2yuv_mode = 0;
break;
case LCD_YUV_SAMPLE_420:
dev->lcd_rgb_yuv.lcd_conv_yuv2yuv_mode = 1;
break;
case LCD_YUV_SAMPLE_411:
dev->lcd_rgb_yuv.lcd_conv_yuv2yuv_mode = 2;
break;
default:
abort();
}
}
/**

View File

@@ -12,13 +12,6 @@
extern "C" {
#endif
/**
* @background
*
* Color Space: a specific representation of colors, e.g. RGB, YUV, etc.
* Color Pixel Format: a specific pixel format of a certain color space, e.g. RGB565, YUV422, etc.
*/
/*---------------------------------------------------------------
Color Space
---------------------------------------------------------------*/
@@ -33,7 +26,7 @@ typedef enum {
} color_space_t;
/*---------------------------------------------------------------
Color Space Format
Color Pixel Format
---------------------------------------------------------------*/
/**
* @brief Raw Format
@@ -59,6 +52,7 @@ typedef enum {
COLOR_PIXEL_YUV444, ///< 24 bits, 8 bits per Y/U/V value
COLOR_PIXEL_YUV422, ///< 16 bits, 8-bit Y per pixel, 8-bit U and V per two pixels
COLOR_PIXEL_YUV420, ///< 12 bits, 8-bit Y per pixel, 8-bit U and V per four pixels
COLOR_PIXEL_YUV411, ///< 12 bits, 8-bit Y per pixel, 8-bit U and V per four pixels
} color_pixel_yuv_format_t;
/**
@@ -70,16 +64,18 @@ typedef enum {
} color_pixel_gray_format_t;
/*---------------------------------------------------------------
Color Space Struct Type
Color Space Pixel Struct Type
---------------------------------------------------------------*/
///< Bitwidth of the `color_space_format_t:color_space` field
///< Bitwidth of the `color_space_pixel_format_t::color_space` field
#define COLOR_SPACE_BITWIDTH 8
///< Bitwidth of the `color_space_format_t:pixel_format` field
///< Bitwidth of the `color_space_pixel_format_t::pixel_format` field
#define COLOR_PIXEL_FORMAT_BITWIDTH 24
///< Helper to get `color_space_format_t:color_space` from its `color_space_pixel_format_t:color_type_id`
///< Helper to get the color_space from a unique color type ID
#define COLOR_SPACE_TYPE(color_type_id) (((color_type_id) >> COLOR_PIXEL_FORMAT_BITWIDTH) & ((1 << COLOR_SPACE_BITWIDTH) - 1))
///< Helper to get `color_space_format_t:pixel_format` from its `color_space_pixel_format_t:color_type_id`
///< Helper to get the pixel_format from a unique color type ID
#define COLOR_PIXEL_FORMAT(color_type_id) ((color_type_id) & ((1 << COLOR_PIXEL_FORMAT_BITWIDTH) - 1))
///< Make a unique ID of a color based on the value of color space and pixel format
#define COLOR_TYPE_ID(color_space, pixel_format) (((color_space) << COLOR_PIXEL_FORMAT_BITWIDTH) | (pixel_format))
/**
* @brief Color Space Info Structure
@@ -92,6 +88,26 @@ typedef union {
uint32_t color_type_id; ///< Unique type of a certain color pixel format
} color_space_pixel_format_t;
/*---------------------------------------------------------------
Color Conversion
---------------------------------------------------------------*/
/**
* @brief LCD color range
* @note The difference between a full range color and a limited range color is
* the amount of shades of black and white that they can display.
*/
typedef enum {
COLOR_RANGE_LIMIT, /*!< Limited color range, 16 is the darkest black and 235 is the brightest white */
COLOR_RANGE_FULL, /*!< Full color range, 0 is the darkest black and 255 is the brightest white */
} color_range_t;
/**
* @brief The standard used for conversion between RGB and YUV
*/
typedef enum {
COLOR_CONV_STD_RGB_YUV_BT601, /*!< YUV<->RGB conversion standard: BT.601 */
COLOR_CONV_STD_RGB_YUV_BT709, /*!< YUV<->RGB conversion standard: BT.709 */
} color_conv_std_rgb_yuv_t;
#ifdef __cplusplus
}

View File

@@ -36,13 +36,13 @@ typedef enum {
* @brief ISP Color Type
*/
typedef enum {
ISP_COLOR_RAW8 = (COLOR_SPACE_RAW << COLOR_PIXEL_FORMAT_BITWIDTH) + COLOR_PIXEL_RAW8, ///< RAW8
ISP_COLOR_RAW10 = (COLOR_SPACE_RAW << COLOR_PIXEL_FORMAT_BITWIDTH) + COLOR_PIXEL_RAW10, ///< RAW10
ISP_COLOR_RAW12 = (COLOR_SPACE_RAW << COLOR_PIXEL_FORMAT_BITWIDTH) + COLOR_PIXEL_RAW12, ///< RAW12
ISP_COLOR_RGB888 = (COLOR_SPACE_RGB << COLOR_PIXEL_FORMAT_BITWIDTH) + COLOR_PIXEL_RGB888, ///< RGB888
ISP_COLOR_RGB565 = (COLOR_SPACE_RGB << COLOR_PIXEL_FORMAT_BITWIDTH) + COLOR_PIXEL_RGB565, ///< RGB565
ISP_COLOR_YUV422 = (COLOR_SPACE_YUV << COLOR_PIXEL_FORMAT_BITWIDTH) + COLOR_PIXEL_YUV422, ///< YUV422
ISP_COLOR_YUV420 = (COLOR_SPACE_YUV << COLOR_PIXEL_FORMAT_BITWIDTH) + COLOR_PIXEL_YUV420, ///< YUV420
ISP_COLOR_RAW8 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW8), ///< RAW8
ISP_COLOR_RAW10 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW10), ///< RAW10
ISP_COLOR_RAW12 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW12), ///< RAW12
ISP_COLOR_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), ///< RGB888
ISP_COLOR_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), ///< RGB565
ISP_COLOR_YUV422 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV422), ///< YUV422
ISP_COLOR_YUV420 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV420), ///< YUV420
} isp_color_t;
/*---------------------------------------------------------------
@@ -68,7 +68,6 @@ typedef struct {
#endif
} isp_af_result_t;
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -8,6 +8,7 @@
#include "soc/soc_caps.h"
#include "soc/clk_tree_defs.h"
#include "hal/color_types.h"
#ifdef __cplusplus
extern "C" {
@@ -20,19 +21,6 @@ extern "C" {
typedef soc_periph_lcd_clk_src_t lcd_clock_source_t;
#endif
/**
* @brief RGB color endian
*/
typedef enum {
LCD_RGB_ELEMENT_ORDER_RGB, /*!< RGB element order: RGB */
LCD_RGB_ELEMENT_ORDER_BGR, /*!< RGB element order: BGR */
} lcd_rgb_element_order_t;
/// for backward compatible
typedef lcd_rgb_element_order_t lcd_color_rgb_endian_t;
#define LCD_RGB_ENDIAN_RGB LCD_RGB_ELEMENT_ORDER_RGB
#define LCD_RGB_ENDIAN_BGR LCD_RGB_ELEMENT_ORDER_BGR
/**
* @brief RGB data endian
*/
@@ -45,33 +33,33 @@ typedef enum {
* @brief LCD color space
*/
typedef enum {
LCD_COLOR_SPACE_RGB, /*!< Color space: RGB */
LCD_COLOR_SPACE_YUV, /*!< Color space: YUV */
LCD_COLOR_SPACE_RGB = COLOR_SPACE_RGB, /*!< Color space: RGB */
LCD_COLOR_SPACE_YUV = COLOR_SPACE_YUV, /*!< Color space: YUV */
} lcd_color_space_t;
/**
* @brief LCD color range
*/
typedef enum {
LCD_COLOR_RANGE_LIMIT, /*!< Limited color range */
LCD_COLOR_RANGE_FULL, /*!< Full color range */
LCD_COLOR_RANGE_LIMIT = COLOR_RANGE_LIMIT, /*!< Limited color range */
LCD_COLOR_RANGE_FULL = COLOR_RANGE_FULL, /*!< Full color range */
} lcd_color_range_t;
/**
* @brief YUV sampling method
*/
typedef enum {
LCD_YUV_SAMPLE_422, /*!< YUV 4:2:2 sampling */
LCD_YUV_SAMPLE_420, /*!< YUV 4:2:0 sampling */
LCD_YUV_SAMPLE_411, /*!< YUV 4:1:1 sampling */
LCD_YUV_SAMPLE_422 = COLOR_PIXEL_YUV422, /*!< YUV 4:2:2 sampling */
LCD_YUV_SAMPLE_420 = COLOR_PIXEL_YUV420, /*!< YUV 4:2:0 sampling */
LCD_YUV_SAMPLE_411 = COLOR_PIXEL_YUV411, /*!< YUV 4:1:1 sampling */
} lcd_yuv_sample_t;
/**
* @brief The standard used for conversion between RGB and YUV
*/
typedef enum {
LCD_YUV_CONV_STD_BT601, /*!< YUV<->RGB conversion standard: BT.601 */
LCD_YUV_CONV_STD_BT709, /*!< YUV<->RGB conversion standard: BT.709 */
LCD_YUV_CONV_STD_BT601 = COLOR_CONV_STD_RGB_YUV_BT601, /*!< YUV<->RGB conversion standard: BT.601 */
LCD_YUV_CONV_STD_BT709 = COLOR_CONV_STD_RGB_YUV_BT709, /*!< YUV<->RGB conversion standard: BT.709 */
} lcd_yuv_conv_std_t;
#ifdef __cplusplus

View File

@@ -228,6 +228,7 @@ INPUT = \
$(PROJECT_PATH)/components/freertos/FreeRTOS-Kernel/include/freertos/task.h \
$(PROJECT_PATH)/components/freertos/FreeRTOS-Kernel/include/freertos/timers.h \
$(PROJECT_PATH)/components/hal/include/hal/adc_types.h \
$(PROJECT_PATH)/components/hal/include/hal/color_types.h \
$(PROJECT_PATH)/components/hal/include/hal/dac_types.h \
$(PROJECT_PATH)/components/hal/include/hal/esp_flash_err.h \
$(PROJECT_PATH)/components/hal/include/hal/gpio_types.h \

View File

@@ -448,8 +448,8 @@ More LCD panel drivers and touch drivers are available in `ESP-IDF Component Reg
.. _lcd_panel_operations:
LCD Panel IO Operations
-----------------------
LCD Panel Basic Operations
--------------------------
* :cpp:func:`esp_lcd_panel_reset` can reset the LCD panel.
* :cpp:func:`esp_lcd_panel_init` performs a basic initialization of the panel. To perform more manufacture specific initialization, please go to :ref:`steps_add_manufacture_init`.
@@ -463,7 +463,7 @@ LCD Panel IO Operations
Steps to Add Manufacture Specific Initialization
-------------------------------------------------
The LCD controller drivers (e.g., st7789) in esp-idf only provide basic initialization in the :cpp:func:`esp_lcd_panel_init`, leaving the vast majority of settings to the default values. Some LCD modules needs to set a bunch of manufacture specific configurations before it can display normally. These configurations usually include gamma, power voltage and so on. If you want to add manufacture specific initialization, please follow the steps below:
The LCD controller drivers (e.g., st7789) in ESP-IDF only provide basic initialization in the :cpp:func:`esp_lcd_panel_init`, leaving the vast majority of settings to the default values. Some LCD modules needs to set a bunch of manufacture specific configurations before it can display normally. These configurations usually include gamma, power voltage and so on. If you want to add manufacture specific initialization, please follow the steps below:
.. code:: c