Skip to content

Commit 53a250b

Browse files
committed
Merge branch 'feat/p4_eco5_ccm' into 'master'
ISP: support ccm on P4 eco5 Closes IDF-13934 See merge request espressif/esp-idf!42004
2 parents 22cae61 + 2948683 commit 53a250b

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

components/esp_driver_isp/include/driver/isp_ccm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
*
2121
*/
2222
typedef struct {
23-
float matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION]; /*!< The color correction matrix in float, range (-4.0, 4.0) */
23+
float matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION]; /*!< The color correction matrix in float*/
2424
bool saturation; /*!< Whether to use saturation when the float data in the matrix is out of the range,
2525
* For example, if one of the matrix data is 5.0,
2626
* When saturation is true, and final value will be limited to 4.0, and won't rise error

components/esp_driver_isp/src/isp_ccm.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -21,6 +21,17 @@ esp_err_t esp_isp_ccm_configure(isp_proc_handle_t proc, const esp_isp_ccm_config
2121
{
2222
ESP_RETURN_ON_FALSE(proc && ccm_cfg, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
2323

24+
// Check matrix values are within valid range
25+
float max_range = (1 << ISP_LL_CCM_MATRIX_INT_BITS);
26+
float min_range = -(1 << ISP_LL_CCM_MATRIX_INT_BITS);
27+
for (int i = 0; i < ISP_CCM_DIMENSION; i++) {
28+
for (int j = 0; j < ISP_CCM_DIMENSION; j++) {
29+
float value = ccm_cfg->matrix[i][j];
30+
ESP_RETURN_ON_FALSE(value >= min_range && value <= max_range, ESP_ERR_INVALID_ARG, TAG,
31+
"Matrix[%d][%d] value %f is out of range [%f, %f]", i, j, value, min_range, max_range);
32+
}
33+
}
34+
2435
bool ret = true;
2536
portENTER_CRITICAL(&proc->spinlock);
2637
isp_ll_ccm_set_clk_ctrl_mode(proc->hal.hw, ISP_LL_PIPELINE_CLK_CTRL_AUTO);

components/hal/esp32p4/include/hal/isp_ll.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "hal/assert.h"
1313
#include "hal/config.h"
1414
#include "hal/hal_utils.h"
15+
#include "hal/config.h"
1516
#include "hal/isp_types.h"
1617
#include "hal/color_types.h"
1718
#include "soc/isp_struct.h"
@@ -123,8 +124,13 @@ extern "C" {
123124
/*---------------------------------------------------------------
124125
CCM
125126
---------------------------------------------------------------*/
127+
#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
128+
#define ISP_LL_CCM_MATRIX_INT_BITS (4)
129+
#define ISP_LL_CCM_MATRIX_FRAC_BITS (8)
130+
#else
126131
#define ISP_LL_CCM_MATRIX_INT_BITS (2)
127132
#define ISP_LL_CCM_MATRIX_FRAC_BITS (10)
133+
#endif
128134
#define ISP_LL_CCM_MATRIX_TOT_BITS (ISP_LL_CCM_MATRIX_INT_BITS + ISP_LL_CCM_MATRIX_FRAC_BITS + 1) // including one sign bit
129135

130136
typedef union {

examples/peripherals/isp/multi_pipelines/main/isp_dsi_main.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ void app_main(void)
274274
}
275275

276276
ESP_ERROR_CHECK(esp_cam_ctlr_enable(handle));
277-
//---------------ISP Init------------------//
277+
/*---------------------------------------------------------------
278+
ISP Init
279+
---------------------------------------------------------------*/
278280
isp_proc_handle_t isp_proc = NULL;
279281
esp_isp_processor_cfg_t isp_config = {
280282
.clk_hz = 80 * 1000 * 1000,
@@ -289,6 +291,9 @@ void app_main(void)
289291
ESP_ERROR_CHECK(esp_isp_new_processor(&isp_config, &isp_proc));
290292
ESP_ERROR_CHECK(esp_isp_enable(isp_proc));
291293

294+
/*---------------------------------------------------------------
295+
BF
296+
---------------------------------------------------------------*/
292297
esp_isp_bf_config_t bf_config = {
293298
.denoising_level = 5,
294299
.padding_mode = ISP_BF_EDGE_PADDING_MODE_SRND_DATA,
@@ -303,6 +308,9 @@ void app_main(void)
303308
ESP_ERROR_CHECK(esp_isp_bf_configure(isp_proc, &bf_config));
304309
ESP_ERROR_CHECK(esp_isp_bf_enable(isp_proc));
305310

311+
/*---------------------------------------------------------------
312+
BLC
313+
---------------------------------------------------------------*/
306314
#if CONFIG_ESP32P4_REV_MIN_FULL >= 300
307315
/**
308316
* This piece of BLC code is to show how to use the BLC related APIs.
@@ -346,6 +354,9 @@ void app_main(void)
346354
ESP_ERROR_CHECK(esp_isp_blc_set_correction_offset(isp_proc, &blc_offset));
347355
#endif
348356

357+
/*---------------------------------------------------------------
358+
DEMOSAIC
359+
---------------------------------------------------------------*/
349360
esp_isp_demosaic_config_t demosaic_config = {
350361
.grad_ratio = {
351362
.integer = 2,
@@ -355,13 +366,48 @@ void app_main(void)
355366
ESP_ERROR_CHECK(esp_isp_demosaic_configure(isp_proc, &demosaic_config));
356367
ESP_ERROR_CHECK(esp_isp_demosaic_enable(isp_proc));
357368

369+
/*---------------------------------------------------------------
370+
CCM
371+
---------------------------------------------------------------*/
372+
/**
373+
* CCM is used for color correction and white balance adjustment.
374+
* It should be configured after demosaic and before gamma correction.
375+
*
376+
* The matrix format is:
377+
* [R_out] [RR RG RB] [R_in]
378+
* [G_out] = [GR GG GB] [G_in]
379+
* [B_out] [BR BG BB] [B_in]
380+
*
381+
* For ESP32P4 ECO5:
382+
* - Matrix coefficients range: ±15.996 (4-bit integer + 8-bit fraction)
383+
* - For earlier versions: ±3.999 (2-bit integer + 10-bit fraction)
384+
*/
385+
esp_isp_ccm_config_t ccm_config = {
386+
.matrix = {
387+
// Default identity matrix (no color correction)
388+
{1.0, 0.0, 0.0}, // R channel: R = 1.0*R + 0.0*G + 0.0*B
389+
{0.0, 1.0, 0.0}, // G channel: G = 0.0*R + 1.0*G + 0.0*B
390+
{0.0, 0.0, 1.0} // B channel: B = 0.0*R + 0.0*G + 1.0*B
391+
},
392+
.saturation = false // Don't use saturation for out-of-range values
393+
};
394+
395+
ESP_ERROR_CHECK(esp_isp_ccm_configure(isp_proc, &ccm_config));
396+
ESP_ERROR_CHECK(esp_isp_ccm_enable(isp_proc));
397+
398+
/*---------------------------------------------------------------
399+
GAMMA
400+
---------------------------------------------------------------*/
358401
isp_gamma_curve_points_t pts = {};
359402
ESP_ERROR_CHECK(esp_isp_gamma_fill_curve_points(s_gamma_correction_curve, &pts));
360403
ESP_ERROR_CHECK(esp_isp_gamma_configure(isp_proc, COLOR_COMPONENT_R, &pts));
361404
ESP_ERROR_CHECK(esp_isp_gamma_configure(isp_proc, COLOR_COMPONENT_G, &pts));
362405
ESP_ERROR_CHECK(esp_isp_gamma_configure(isp_proc, COLOR_COMPONENT_B, &pts));
363406
ESP_ERROR_CHECK(esp_isp_gamma_enable(isp_proc));
364407

408+
/*---------------------------------------------------------------
409+
SHARPEN
410+
---------------------------------------------------------------*/
365411
esp_isp_sharpen_config_t sharpen_config = {
366412
.h_freq_coeff = {
367413
.integer = 2,
@@ -385,6 +431,9 @@ void app_main(void)
385431
ESP_ERROR_CHECK(esp_isp_sharpen_configure(isp_proc, &sharpen_config));
386432
ESP_ERROR_CHECK(esp_isp_sharpen_enable(isp_proc));
387433

434+
/*---------------------------------------------------------------
435+
COLOR
436+
---------------------------------------------------------------*/
388437
esp_isp_color_config_t color_config = {
389438
.color_contrast = {
390439
.integer = 1,
@@ -401,6 +450,9 @@ void app_main(void)
401450
ESP_ERROR_CHECK(esp_isp_color_enable(isp_proc));
402451

403452
#if CONFIG_ESP32P4_REV_MIN_FULL >= 100
453+
/*---------------------------------------------------------------
454+
LSC
455+
---------------------------------------------------------------*/
404456
esp_isp_lsc_gain_array_t gain_array = {};
405457
esp_isp_lsc_config_t lsc_config = {
406458
.gain_array = &gain_array,

0 commit comments

Comments
 (0)