Merge branch 'doc/isp_bf_dvp_programming_guide' into 'master'

isp: bf dvp programming guide

Closes IDF-10091 and IDF-10092

See merge request espressif/esp-idf!31361
pull/14033/head
Armando (Dou Yiwen) 2024-06-12 14:13:11 +08:00
commit cd1ec8426c
7 zmienionych plików z 122 dodań i 50 usunięć

Wyświetl plik

@ -42,6 +42,7 @@ typedef struct {
/**
* @brief New ESP CAM ISP DVP controller
*
* @param[in] isp_proc Processor handle
* @param[in] ctlr_config ISP DVP controller configurations
* @param[out] ret_handle Returned ESP CAM controller handle
*

Wyświetl plik

@ -8,6 +8,7 @@ set(includes "include")
set(priv_requires heap spi_flash esp_mm)
if(${target} STREQUAL "esp32")
list(APPEND priv_requires bootloader_support)
# [refactor-todo]: requires "driver" for `spicommon_periph_claim`
list(APPEND priv_requires driver)
endif()
@ -47,7 +48,6 @@ endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${includes}
REQUIRES bootloader_support
PRIV_REQUIRES ${priv_requires}
LDFRAGMENTS linker.lf)

Wyświetl plik

@ -44,6 +44,24 @@
#define MMU_FLASH_MASK (~(CONFIG_MMU_PAGE_SIZE - 1))
/**
* @brief Image process driver
*/
struct image_process_driver_s {
/**
* @brief Process segments
*
* @param[in] data image meta data
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG: invalid argument
* - ESP_ERR_INVALID_STATE: invalid state
*/
esp_err_t (*process_segments)(esp_image_metadata_t *data);
};
const static char *TAG = "image_process";
static uint32_t s_current_read_mapping = UINT32_MAX;

Wyświetl plik

@ -10,7 +10,6 @@
#include <stddef.h>
#include <string.h>
#include "esp_err.h"
#include "esp_image_format.h"
#ifdef __cplusplus
extern "C" {
@ -21,24 +20,6 @@ extern "C" {
*/
typedef struct image_process_driver_s image_process_driver_t;
/**
* @brief Image process driver
*/
struct image_process_driver_s {
/**
* @brief Process segments
*
* @param[in] data image meta data
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG: invalid argument
* - ESP_ERR_INVALID_STATE: invalid state
*/
esp_err_t (*process_segments)(esp_image_metadata_t *data);
};
/**
* @brief Image process flow
* @note This API first reads the image header, then process the segments from the image header.

Wyświetl plik

@ -16,6 +16,7 @@ INPUT += \
$(PROJECT_PATH)/components/esp_driver_cam/include/esp_cam_ctlr.h \
$(PROJECT_PATH)/components/esp_driver_cam/include/esp_cam_ctlr_types.h \
$(PROJECT_PATH)/components/esp_driver_cam/csi/include/esp_cam_ctlr_csi.h \
$(PROJECT_PATH)/components/esp_driver_cam/isp_dvp/include/esp_cam_ctlr_isp_dvp.h \
$(PROJECT_PATH)/components/hal/include/hal/jpeg_types.h \
$(PROJECT_PATH)/components/hal/include/hal/ppa_types.h \
$(PROJECT_PATH)/components/esp_driver_jpeg/include/driver/jpeg_types.h \
@ -24,6 +25,7 @@ INPUT += \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_af.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_awb.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_ccm.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_bf.h \
$(PROJECT_PATH)/components/esp_driver_jpeg/include/driver/jpeg_decode.h \
$(PROJECT_PATH)/components/esp_driver_jpeg/include/driver/jpeg_encode.h \
$(PROJECT_PATH)/components/esp_driver_ppa/include/driver/ppa.h \

Wyświetl plik

@ -32,10 +32,10 @@ Functional Overview
Resource Allocation
^^^^^^^^^^^^^^^^^^^
.. only:: SOC_MIPI_CSI_SUPPORTED
Install Camera Controller Driver
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Install Camera Controller Driver
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. only:: SOC_MIPI_CSI_SUPPORTED
A Camera Controller Driver can be implemented by the CSI peripheral, which requires the configuration that specified by :cpp:type:`esp_cam_ctlr_csi_config_t`.
@ -57,6 +57,41 @@ Resource Allocation
esp_cam_ctlr_handle_t handle = NULL;
ESP_ERROR_CHECK(esp_cam_new_csi_ctlr(&csi_config, &handle));
.. only:: SOC_ISP_DVP_SUPPORTED
A Camera Controller Driver can be implemented by the ISP DVP peripheral, which requires the configuration that specified by :cpp:type:`esp_cam_ctlr_isp_dvp_cfg_t`.
If the configurations in :cpp:type:`esp_cam_ctlr_isp_dvp_cfg_t` is specified, users can call :cpp:func:`esp_cam_new_isp_dvp_ctlr` to allocate and initialize a ISP DVP camera controller handle. This function will return an ISP DVP camera controller handle if it runs correctly. You can take following code as reference.
Before calling :cpp:func:`esp_cam_new_isp_dvp_ctlr`, you should also call :cpp:func:`esp_isp_new_processor` to create an ISP handle.
.. code:: c
isp_proc_handle_t isp_proc = NULL;
esp_isp_processor_cfg_t isp_config = {
.clk_hz = 120 * 1000 * 1000,
.input_data_source = ISP_INPUT_DATA_SOURCE_DVP,
.input_data_color_type = ISP_COLOR_RAW8,
.output_data_color_type = ISP_COLOR_RGB565,
.has_line_start_packet = false,
.has_line_end_packet = false,
.h_res = MIPI_CSI_DISP_HSIZE,
.v_res = MIPI_CSI_DISP_VSIZE,
};
ESP_ERROR_CHECK(esp_isp_new_processor(&isp_config, &isp_proc));
esp_cam_ctlr_isp_dvp_cfg_t dvp_ctlr_config = {
.data_width = 8,
.data_io = {53, 54, 52, 0, 1, 45, 46, 47, -1, -1, -1, -1, -1, -1, -1, -1},
.pclk_io = 21,
.hsync_io = 5,
.vsync_io = 23,
.de_io = 22,
.io_flags.vsync_invert = 1,
.queue_items = 10,
};
ESP_ERROR_CHECK(esp_cam_new_isp_dvp_ctlr(isp_proc, &dvp_ctlr_config, &cam_handle));
Uninstall Camera Controller Driver
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -127,15 +162,25 @@ After the Camera Controller Driver starts receiving, it can generate a specific
Thread Safety
^^^^^^^^^^^^^
The factory function :cpp:func:`esp_cam_new_csi_ctlr` and :cpp:func:`esp_cam_ctlr_del` are guaranteed to be thread safe by the driver, which means, user can call them from different RTOS tasks without protection by extra locks.
The factory functions:
.. list::
:SOC_MIPI_CSI_SUPPORTED: - :cpp:func:`esp_cam_new_csi_ctlr`
:SOC_ISP_DVP_SUPPORTED: - :cpp:func:`esp_cam_new_isp_dvp_ctlr`
- :cpp:func:`esp_cam_ctlr_del`
are guaranteed to be thread safe by the driver, which means, user can call them from different RTOS tasks without protection by extra locks.
.. _cam-kconfig-options:
Kconfig Options
^^^^^^^^^^^^^^^
- :ref:`CONFIG_CAM_CTLR_MIPI_CSI_ISR_IRAM_SAFE` controls whether the default ISR handler should be masked when the cache is disabled
The following kconfig options the behavior of the interrupt handler when cache is disabled:
.. list::
:SOC_MIPI_CSI_SUPPORTED: - :ref:`CONFIG_CAM_CTLR_MIPI_CSI_ISR_IRAM_SAFE`, see `IRAM SAFE <#cam-iram-safe>`__ for more details.
:SOC_ISP_DVP_SUPPORTED: - :ref:`CONFIG_CAM_CTLR_ISP_DVP_ISR_IRAM_SAFE`, see `IRAM SAFE <#cam-iram-safe>`__ for more details.
.. _cam-iram-safe:
@ -144,7 +189,13 @@ IRAM Safe
By default, the CSI interrupt will be deferred when the cache is disabled because of writing or erasing the flash.
There is a Kconfig option :ref:`CONFIG_CAM_CTLR_MIPI_CSI_ISR_IRAM_SAFE` that:
There are Kconfig options
.. list::
:SOC_MIPI_CSI_SUPPORTED: - :ref:`CONFIG_CAM_CTLR_MIPI_CSI_ISR_IRAM_SAFE`
:SOC_ISP_DVP_SUPPORTED: - :ref:`CONFIG_CAM_CTLR_ISP_DVP_ISR_IRAM_SAFE`
that
- Enables the interrupt being serviced even when the cache is disabled
- Places all functions that used by the ISR into IRAM
@ -158,3 +209,4 @@ API Reference
.. include-build-file:: inc/esp_cam_ctlr.inc
.. include-build-file:: inc/esp_cam_ctlr_types.inc
.. include-build-file:: inc/esp_cam_ctlr_csi.inc
.. include-build-file:: inc/esp_cam_ctlr_isp_dvp.inc

Wyświetl plik

@ -15,9 +15,9 @@ Terminology
- RAW: Unprocessed data directly output from an image sensor, typically divided into R, Gr, Gb, and B four channels classified into RAW8, RAW10, RAW12, etc., based on bit width
- RGB: Colored image format composed of red, green, and blue colors classified into RGB888, RGB565, etc., based on the bit width of each color
- YUV: Colored image format composed of luminance and chrominance classified into YUV444, YUV422, YUV420, etc., based on the data arrangement
- BF: Bayer Domain Filter
- AF: Auto-focus
- AWB: Auto-white balance
- BF: Bayer noise filter
- CCM: Color correction matrix
ISP Pipeline
@ -61,6 +61,7 @@ The ISP driver offers following services:
- `Enable and disable ISP processor <#isp-enable-disable>`__ - covers how to enable and disable an ISP processor.
- `Get AF statistics in one shot or continuous way <#isp-af-statistics>`__ - covers how to get AF statistics one-shot or continuously.
- `Get AWB statistics in one shot or continuous way <#isp-awb-statistics>`__ - covers how to get AWB white patches statistics one-shot or continuously.
- `Enable BF function <#isp_bf>`__ - covers how to enable and configure BF function.
- `Configure CCM <#isp-ccm-config>`__ - covers how to config the Color Correction Matrix.
- `Register callback <#isp-callback>`__ - covers how to hook user specific code to ISP driver event callback function.
- `Thread Safety <#isp-thread-safety>`__ - lists which APIs are guaranteed to be thread safe by the driver.
@ -83,10 +84,7 @@ If the configurations in :cpp:type:`esp_isp_processor_cfg_t` is specified, users
esp_isp_processor_cfg_t isp_config = {
.clk_src = ISP_CLK_SRC_DEFAULT,
.clk_hz = 80 * 1000 * 1000,
.input_data_source = ISP_INPUT_DATA_SOURCE_CSI,
.input_data_color_type = ISP_COLOR_RAW8,
.output_data_color_type = ISP_COLOR_RGB565,
...
};
isp_proc_handle_t isp_proc = NULL;
@ -127,15 +125,7 @@ If an :cpp:type:`esp_isp_awb_config_t` configuration is specified, you can call
/* The AWB configuration, please refer to the API comment for how to tune these parameters */
esp_isp_awb_config_t awb_config = {
.sample_point = ISP_AWB_SAMPLE_POINT_AFTER_CCM,
.window = {
.top_left = {.x = image_width * 0.2, .y = image_height * 0.2},
.btm_right = {.x = image_width * 0.8, .y = image_height * 0.8},
},
.white_patch = {
.luminance = {.min = 0, .max = 220 * 3},
.red_green_ratio = {.min = 0.0f, .max = 3.999f},
.blue_green_ratio = {.min = 0.0f, .max = 3.999f},
},
...
};
ESP_ERROR_CHECK(esp_isp_new_awb_controller(isp_proc, &awb_config, &awb_ctlr));
@ -270,15 +260,7 @@ Note that if you want to use the continuous statistics, you need to register the
/* The AWB configuration, please refer to the API comment for how to tune these parameters */
esp_isp_awb_config_t awb_config = {
.sample_point = ISP_AWB_SAMPLE_POINT_AFTER_CCM,
.window = {
.top_left = {.x = image_width * 0.2, .y = image_height * 0.2},
.btm_right = {.x = image_width * 0.8, .y = image_height * 0.8},
},
.white_patch = {
.luminance = {.min = 0, .max = 220 * 3},
.red_green_ratio = {.min = 0.0f, .max = 3.999f},
.blue_green_ratio = {.min = 0.0f, .max = 3.999f},
},
...
};
isp_awb_stat_result_t stat_res = {};
/* Create the awb controller */
@ -307,6 +289,31 @@ Note that if you want to use the continuous statistics, you need to register the
/* Delete the awb controller and free the resources */
ESP_ERROR_CHECK(esp_isp_del_awb_controller(awb_ctlr));
.. _isp_bf:
ISP BF Processor
----------------
This pipeline is used for doing image input denoising under bayer mode.
Calling :cpp:func:`esp_isp_bf_configure` to configure BF function, you can take following code as reference.
.. code:: c
esp_isp_bf_config_t bf_config = {
.denoising_level = 5,
...
};
ESP_ERROR_CHECK(esp_isp_bf_configure(isp_proc, &bf_config));
ESP_ERROR_CHECK(esp_isp_bf_enable(isp_proc));
:cpp:member:`esp_isp_bf_config_t::bf_template` is used for bayer denoise. You can set the :cpp:member:`esp_isp_bf_config_t::bf_template` with a Gaussian filter template or an average filter template.
After calling :cpp:func:`esp_isp_bf_configure`, you need to enable the ISP BF processor, by calling :cpp:func:`esp_isp_bf_enable`. This function:
* Switches the driver state from **init** to **enable**.
Calling :cpp:func:`esp_isp_bf_disable` does the opposite, that is, put the driver back to the **init** state.
.. _isp-ccm-config:
Configure CCM
@ -314,7 +321,17 @@ Configure CCM
Color Correction Matrix can scale the color ratio of RGB888 pixels. It can be used for adjusting the image color via some algorithms, for example, used for white balance by inputting the AWB computed result, or used as a Filter with some filter algorithms.
To adjust the color correction matrix, you can refer to the following code:
To adjust the color correction matrix, here is the formula:
::
[ R' ] [ RR RG RB ] [ R ]
[ G' ] = [ GR GG GB ] * [ G ]
[ B' ] [ BR BG BB ] [ B ]
, and you can refer to the following code:
.. code-block:: c
@ -327,6 +344,7 @@ To adjust the color correction matrix, you can refer to the following code:
0.0, 0.0, 1.0
},
.saturation = false,
...
};
ESP_ERROR_CHECK(esp_isp_ccm_configure(isp_proc, &ccm_cfg));
// The configured CCM will be applied to the image once the CCM module is enabled