Skip to content

Commit 4787e92

Browse files
committed
Merge branch 'feat/isp_bf_feature_v5.3' into 'release/v5.3'
feat(isp): added isp bf driver (v5.3) See merge request espressif/esp-idf!31067
2 parents c9f8fc0 + cc48efc commit 4787e92

File tree

14 files changed

+336
-7
lines changed

14 files changed

+336
-7
lines changed

components/esp_driver_isp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ if(CONFIG_SOC_ISP_SUPPORTED)
77
"src/isp_af.c")
88
endif()
99

10+
if(CONFIG_SOC_ISP_BF_SUPPORTED)
11+
list(APPEND srcs "src/isp_bf.c")
12+
endif()
13+
1014
idf_component_register(SRCS ${srcs}
1115
INCLUDE_DIRS ${public_include}
1216
PRIV_REQUIRES esp_driver_gpio

components/esp_driver_isp/include/driver/isp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
#include "driver/isp_core.h"
1515
#include "driver/isp_af.h"
16+
#include "driver/isp_bf.h"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
#include "esp_err.h"
11+
#include "driver/isp_types.h"
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/**
18+
* @brief ISP BF configurations
19+
*/
20+
typedef struct {
21+
isp_bf_edge_padding_mode_t padding_mode; ///< BF edge padding mode
22+
uint8_t padding_data; ///< BF edge padding pixel data
23+
uint8_t bf_template[ISP_BF_TEMPLATE_X_NUMS][ISP_BF_TEMPLATE_Y_NUMS]; ///< BF template data
24+
uint8_t denoising_level; ///< BF denoising level, from 2 to 20, the bigger the better denoising performance, but the worse detailed
25+
uint8_t padding_line_tail_valid_start_pixel; ///< BF edge padding line tail valid start pixel, padding data will only be valid between the valid start pixel and the valid end pixel. Set both the start and end pixel to 0 to make all padding pixel valid
26+
uint8_t padding_line_tail_valid_end_pixel; ///< BF edge padding line tail valid end pixel, padding data will only be valid between the valid start pixel and the valid end pixel. Set both the start and end pixel to 0 to make all padding pixel valid
27+
} esp_isp_bf_config_t;
28+
29+
/**
30+
* @brief ISP BF configuration
31+
*
32+
* @note After calling this API, BF doesn't take into effect until `esp_isp_bf_enable` is called
33+
*
34+
* @param[in] proc Processor handle
35+
* @param[in] config BF configurations, set NULL to de-configure the ISP BF
36+
*
37+
* @return
38+
* - ESP_OK On success
39+
* - ESP_ERR_INVALID_STATE Not allowed to be called under current state
40+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid
41+
*/
42+
esp_err_t esp_isp_bf_configure(isp_proc_handle_t proc, const esp_isp_bf_config_t *config);
43+
44+
/**
45+
* @brief Enable ISP BF function
46+
*
47+
* @param[in] proc Processor handle
48+
*
49+
* @return
50+
* - ESP_OK On success
51+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
52+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
53+
*/
54+
esp_err_t esp_isp_bf_enable(isp_proc_handle_t proc);
55+
56+
/**
57+
* @brief Disable ISP BF function
58+
*
59+
* @param[in] proc Processor handle
60+
*
61+
* @return
62+
* - ESP_OK On success
63+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
64+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
65+
*/
66+
esp_err_t esp_isp_bf_disable(isp_proc_handle_t proc);
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <esp_types.h>
8+
#include <sys/lock.h>
9+
#include "sdkconfig.h"
10+
#include "esp_log.h"
11+
#include "esp_check.h"
12+
#include "esp_heap_caps.h"
13+
#include "freertos/FreeRTOS.h"
14+
#include "esp_clk_tree.h"
15+
#include "driver/isp_core.h"
16+
#include "driver/isp_bf.h"
17+
#include "esp_private/periph_ctrl.h"
18+
#include "esp_private/mipi_csi_share_hw_ctrl.h"
19+
#include "hal/hal_utils.h"
20+
#include "soc/mipi_csi_bridge_struct.h"
21+
#include "soc/isp_periph.h"
22+
#include "isp_internal.h"
23+
24+
static const char *TAG = "ISP_BF";
25+
26+
/*---------------------------------------------------------------
27+
BF
28+
---------------------------------------------------------------*/
29+
esp_err_t esp_isp_bf_configure(isp_proc_handle_t proc, const esp_isp_bf_config_t *config)
30+
{
31+
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
32+
ESP_RETURN_ON_FALSE(proc->bf_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "bf is enabled already");
33+
34+
if (config) {
35+
bool valid_padding_setting = (!config->padding_line_tail_valid_end_pixel && !config->padding_line_tail_valid_start_pixel) || (config->padding_line_tail_valid_end_pixel > config->padding_line_tail_valid_start_pixel);
36+
ESP_RETURN_ON_FALSE(valid_padding_setting, ESP_ERR_INVALID_ARG, TAG, "wrong padding line tail valid pixel setting");
37+
38+
isp_hal_bf_cfg_t bf_hal_cfg = {
39+
.denoising_level = config->denoising_level,
40+
.padding_mode = config->padding_mode,
41+
.padding_data = config->padding_data,
42+
.padding_line_tail_valid_start_pixel = config->padding_line_tail_valid_start_pixel,
43+
.padding_line_tail_valid_end_pixel = config->padding_line_tail_valid_end_pixel,
44+
};
45+
memcpy(bf_hal_cfg.bf_template, config->bf_template, ISP_BF_TEMPLATE_X_NUMS * ISP_BF_TEMPLATE_X_NUMS * sizeof(uint8_t));
46+
isp_hal_bf_config(&(proc->hal), &bf_hal_cfg);
47+
} else {
48+
isp_hal_bf_config(&(proc->hal), NULL);
49+
}
50+
51+
return ESP_OK;
52+
}
53+
54+
esp_err_t esp_isp_bf_enable(isp_proc_handle_t proc)
55+
{
56+
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
57+
ESP_RETURN_ON_FALSE(proc->bf_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "bf is enabled already");
58+
59+
isp_ll_bf_enable(proc->hal.hw, true);
60+
proc->bf_fsm = ISP_FSM_ENABLE;
61+
62+
return ESP_OK;
63+
}
64+
65+
esp_err_t esp_isp_bf_disable(isp_proc_handle_t proc)
66+
{
67+
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
68+
ESP_RETURN_ON_FALSE(proc->bf_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "bf isn't enabled yet");
69+
70+
isp_ll_bf_enable(proc->hal.hw, false);
71+
proc->bf_fsm = ISP_FSM_INIT;
72+
73+
return ESP_OK;
74+
}

components/esp_driver_isp/src/isp_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "freertos/FreeRTOS.h"
1414
#include "esp_clk_tree.h"
1515
#include "driver/isp_core.h"
16+
#include "driver/isp_bf.h"
1617
#include "esp_private/periph_ctrl.h"
1718
#include "esp_private/mipi_csi_share_hw_ctrl.h"
1819
#include "hal/hal_utils.h"

components/esp_driver_isp/src/isp_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ typedef struct isp_processor_t {
5757
portMUX_TYPE spinlock;
5858

5959
/* sub module contexts */
60-
isp_af_ctrlr_t af_ctlr[SOC_ISP_AF_CTLR_NUMS];
60+
isp_af_ctrlr_t af_ctlr[SOC_ISP_AF_CTLR_NUMS];
61+
isp_fsm_t bf_fsm;
6162
} isp_processor_t;
6263

6364
#ifdef __cplusplus

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

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ extern "C" {
6363
#define ISP_LL_EVENT_TAIL_IDI_FRAME (1<<27)
6464
#define ISP_LL_EVENT_HEADER_IDI_FRAME (1<<28)
6565

66-
#define ISP_LL_EVENT_ALL_MASK (0x1FFFFFFF)
67-
#define ISP_LL_EVENT_AF_MASK (ISP_LL_EVENT_AF_FDONE | ISP_LL_EVENT_AF_ENV)
66+
#define ISP_LL_EVENT_ALL_MASK (0x1FFFFFFF)
67+
#define ISP_LL_EVENT_AF_MASK (ISP_LL_EVENT_AF_FDONE | ISP_LL_EVENT_AF_ENV)
6868

6969
/*---------------------------------------------------------------
7070
AF
7171
---------------------------------------------------------------*/
72-
#define ISP_LL_AF_WINDOW_MAX_RANGE ((1<<12) - 1)
72+
#define ISP_LL_AF_WINDOW_MAX_RANGE ((1<<12) - 1)
7373

74+
/*---------------------------------------------------------------
75+
BF
76+
---------------------------------------------------------------*/
77+
#define ISP_LL_BF_DEFAULT_TEMPLATE_VAL 15
7478

7579
/**
7680
* @brief Env monitor mode
@@ -661,6 +665,82 @@ static inline void isp_ll_bf_enable(isp_dev_t *hw, bool enable)
661665
hw->cntl.bf_en = enable;
662666
}
663667

668+
/**
669+
* @brief Set ISP BF sigma value
670+
*
671+
* @param[in] hw Hardware instance address
672+
* @param[in] sigmal_val sigma value
673+
*/
674+
static inline void isp_ll_bf_set_sigma(isp_dev_t *hw, uint32_t sigma_val)
675+
{
676+
hw->bf_sigma.sigma = sigma_val;
677+
}
678+
679+
/**
680+
* @brief Set ISP BF padding mode
681+
*
682+
* @param[in] hw Hardware instance address
683+
* @param[in] padding_mode padding mode
684+
*/
685+
static inline void isp_ll_bf_set_padding_mode(isp_dev_t *hw, isp_bf_edge_padding_mode_t padding_mode)
686+
{
687+
hw->bf_matrix_ctrl.bf_padding_mode = padding_mode;
688+
}
689+
690+
/**
691+
* @brief Set ISP BF padding data
692+
*
693+
* @param[in] hw Hardware instance address
694+
* @param[in] padding_data padding data
695+
*/
696+
static inline void isp_ll_bf_set_padding_data(isp_dev_t *hw, uint32_t padding_data)
697+
{
698+
hw->bf_matrix_ctrl.bf_padding_data = padding_data;
699+
}
700+
701+
/**
702+
* @brief Set ISP BF tail pixen pulse tl
703+
*
704+
* @param[in] hw Hardware instance address
705+
* @param[in] start_pixel start pixel value
706+
*/
707+
static inline void isp_ll_bf_set_padding_line_tail_valid_start_pixel(isp_dev_t *hw, uint32_t start_pixel)
708+
{
709+
hw->bf_matrix_ctrl.bf_tail_pixen_pulse_tl = start_pixel;
710+
}
711+
712+
/**
713+
* @brief Set ISP BF tail pixen pulse th
714+
*
715+
* @param[in] hw Hardware instance address
716+
* @param[in] end_pixel end pixel value
717+
*/
718+
static inline void isp_ll_bf_set_padding_line_tail_valid_end_pixel(isp_dev_t *hw, uint32_t end_pixel)
719+
{
720+
hw->bf_matrix_ctrl.bf_tail_pixen_pulse_th = end_pixel;
721+
}
722+
723+
/**
724+
* @brief Set ISP BF template
725+
*
726+
* @param[in] hw Hardware instance address
727+
* @param[in] template_arr 2-d array for the template
728+
*/
729+
static inline void isp_ll_bf_set_template(isp_dev_t *hw, uint8_t template_arr[SOC_ISP_BF_TEMPLATE_X_NUMS][SOC_ISP_BF_TEMPLATE_Y_NUMS])
730+
{
731+
int cnt = 0;
732+
for (int i = 0; i < SOC_ISP_BF_TEMPLATE_X_NUMS; i++) {
733+
for (int j = 0; j < SOC_ISP_BF_TEMPLATE_Y_NUMS; j++) {
734+
if (i == 2 && j == 2) {
735+
break;
736+
}
737+
hw->bf_gau0.val = (hw->bf_gau0.val & ~(0xf << (28 - cnt * 4))) | ((template_arr[i][j] & 0xf) << (28 - cnt * 4));
738+
cnt++;
739+
}
740+
}
741+
742+
hw->bf_gau1.gau_template22 = template_arr[2][2];
743+
}
664744
/*---------------------------------------------------------------
665745
CCM
666746
---------------------------------------------------------------*/

components/hal/include/hal/isp_hal.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,26 @@
1919
extern "C" {
2020
#endif
2121

22+
/**
23+
* @brief BF configurations
24+
*/
25+
typedef struct {
26+
isp_bf_edge_padding_mode_t padding_mode; ///< BF edge padding mode
27+
uint8_t padding_data; ///< BF edge padding pixel data
28+
uint8_t bf_template[ISP_BF_TEMPLATE_X_NUMS][ISP_BF_TEMPLATE_Y_NUMS]; ///< BF template data
29+
uint8_t denoising_level; ///< BF denoising level, from 2 to 20, the bigger the better denoising performance, but the worse detailed
30+
uint8_t padding_line_tail_valid_start_pixel; ///< BF edge padding line tail valid start pixel
31+
uint8_t padding_line_tail_valid_end_pixel; ///< BF edge padding line tail valid end pixel
32+
} isp_hal_bf_cfg_t;
2233

2334
/**
24-
* Context that should be maintained by both the driver and the HAL
35+
* @brief Context that should be maintained by both the driver and the HAL
2536
*/
2637
typedef struct {
2738
void *hw; ///< Beginning address of the ISP registers
39+
40+
/* BF */
41+
isp_hal_bf_cfg_t bf_cfg; ///< BF configurations
2842
} isp_hal_context_t;
2943

3044
/**
@@ -61,6 +75,16 @@ void isp_hal_af_window_config(const isp_hal_context_t *hal, int window_id, const
6175
*/
6276
uint32_t isp_hal_check_clear_intr_event(const isp_hal_context_t *hal, uint32_t mask);
6377

78+
/*---------------------------------------------------------------
79+
BF
80+
---------------------------------------------------------------*/
81+
/**
82+
* @brief Configure ISP BF registers
83+
*
84+
* @param[in] hal Context of the HAL layer
85+
* @param[in] config BF config, set NULL to de-config the ISP BF
86+
*/
87+
void isp_hal_bf_config(isp_hal_context_t *hal, isp_hal_bf_cfg_t *config);
6488

6589
#ifdef __cplusplus
6690
}

components/hal/include/hal/isp_types.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ typedef struct {
7272
int luminance[ISP_AF_WINDOW_NUM]; ///< Luminance, it refers how luminant an image is
7373
} isp_af_result_t;
7474

75+
/*---------------------------------------------------------------
76+
BF
77+
---------------------------------------------------------------*/
78+
#if SOC_ISP_BF_SUPPORTED
79+
#define ISP_BF_TEMPLATE_X_NUMS SOC_ISP_BF_TEMPLATE_X_NUMS // BF template x field nums
80+
#define ISP_BF_TEMPLATE_Y_NUMS SOC_ISP_BF_TEMPLATE_Y_NUMS // BF template y field nums
81+
#else
82+
#define ISP_BF_TEMPLATE_X_NUMS 0
83+
#define ISP_BF_TEMPLATE_Y_NUMS 0
84+
#endif
85+
86+
/**
87+
* @brief ISP BF edge padding mode
88+
*/
89+
typedef enum {
90+
ISP_BF_EDGE_PADDING_MODE_SRND_DATA, ///< Fill BF edge padding data with surrounding pixel data
91+
ISP_BF_EDGE_PADDING_MODE_CUSTOM_DATA, ///< Fill BF edge padding data with custom pixel data
92+
} isp_bf_edge_padding_mode_t;
93+
7594
#ifdef __cplusplus
7695
}
7796
#endif

0 commit comments

Comments
 (0)