Skip to content

Commit a329b2a

Browse files
committed
ci(cam): add csi_0v5647 test and runner
1 parent 031ee36 commit a329b2a

File tree

8 files changed

+185
-2
lines changed

8 files changed

+185
-2
lines changed

components/esp_driver_cam/test_apps/csi/main/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ if(CONFIG_SOC_MIPI_CSI_SUPPORTED)
44
list(APPEND srcs "test_csi_driver.c")
55
endif()
66

7+
if(CONFIG_CAMERA_OV5647)
8+
list(APPEND srcs "test_csi_ov5647.c")
9+
endif()
10+
711
set(priv_requires
812
unity
913
esp_driver_cam
1014
esp_psram
15+
sensor_init
1116
)
1217

1318
idf_component_register(SRCS ${srcs}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dependencies:
2+
espressif/esp_cam_sensor: ">=0.5.*"
3+
sensor_init:
4+
path: ${IDF_PATH}/examples/peripherals/camera/common_components/sensor_init

components/esp_driver_cam/test_apps/csi/main/test_app_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "esp_heap_caps.h"
1010
#include "sdkconfig.h"
1111

12-
#define TEST_MEMORY_LEAK_THRESHOLD (400)
12+
#define TEST_MEMORY_LEAK_THRESHOLD (500)
1313

1414
void setUp(void)
1515
{
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <stdio.h>
7+
#include "sdkconfig.h"
8+
#include "freertos/FreeRTOS.h"
9+
#include "unity.h"
10+
#include "esp_cam_ctlr_csi.h"
11+
#include "esp_cam_ctlr.h"
12+
#include "esp_ldo_regulator.h"
13+
#include "sdkconfig.h"
14+
#include "driver/isp.h"
15+
#include "example_sensor_init.h"
16+
#include "esp_private/esp_cache_private.h"
17+
18+
#define TEST_USED_LDO_CHAN_ID 3
19+
#define TEST_USED_LDO_VOLTAGE_MV 2500
20+
21+
#define TEST_RGB565_BITS_PER_PIXEL 16
22+
#define TEST_MIPI_CSI_LANE_BITRATE_MBPS 200
23+
24+
#define TEST_MIPI_CSI_CAM_SCCB_SCL_IO 8
25+
#define TEST_MIPI_CSI_CAM_SCCB_SDA_IO 7
26+
27+
#define TEST_MIPI_DSI_DISP_HRES 800
28+
#define TEST_MIPI_DSI_DISP_VRES 1280
29+
#define TEST_MIPI_CSI_DISP_HRES 800
30+
#define TEST_MIPI_CSI_DISP_VRES 640
31+
32+
#define TEST_CAM_FORMAT "MIPI_2lane_24Minput_RAW8_800x640_50fps"
33+
34+
static int new_buffer_count = 0;
35+
static int trans_finished_count = 0;
36+
37+
static bool IRAM_ATTR camera_get_new_buffer(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data)
38+
{
39+
esp_cam_ctlr_trans_t *new_trans = (esp_cam_ctlr_trans_t *)user_data;
40+
trans->buffer = new_trans->buffer;
41+
trans->buflen = new_trans->buflen;
42+
new_buffer_count++;
43+
return false;
44+
}
45+
46+
static bool IRAM_ATTR camera_trans_finished(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data)
47+
{
48+
trans_finished_count++;
49+
return false;
50+
}
51+
52+
TEST_CASE("TEST esp_cam on ov5647", "[csi][camera][ov5647]")
53+
{
54+
size_t frame_buffer_size = TEST_MIPI_CSI_DISP_HRES *
55+
TEST_MIPI_DSI_DISP_VRES *
56+
TEST_RGB565_BITS_PER_PIXEL / 8;
57+
58+
//mipi ldo
59+
esp_ldo_channel_handle_t ldo_mipi_phy = NULL;
60+
esp_ldo_channel_config_t ldo_config = {
61+
.chan_id = TEST_USED_LDO_CHAN_ID,
62+
.voltage_mv = TEST_USED_LDO_VOLTAGE_MV,
63+
};
64+
TEST_ESP_OK(esp_ldo_acquire_channel(&ldo_config, &ldo_mipi_phy));
65+
66+
size_t frame_buffer_alignment = 0;
67+
TEST_ESP_OK(esp_cache_get_alignment(0, &frame_buffer_alignment));
68+
void *frame_buffer = heap_caps_aligned_calloc(frame_buffer_alignment, 1, frame_buffer_size,
69+
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
70+
71+
esp_cam_ctlr_trans_t trans_data = {
72+
.buffer = frame_buffer,
73+
.buflen = frame_buffer_size,
74+
};
75+
76+
//--------Camera Sensor and SCCB Init-----------//
77+
example_sensor_handle_t sensor_handle = {
78+
.sccb_handle = NULL,
79+
.i2c_bus_handle = NULL,
80+
};
81+
example_sensor_config_t sensor_config = {
82+
.i2c_port_num = I2C_NUM_0,
83+
.i2c_sda_io_num = TEST_MIPI_CSI_CAM_SCCB_SDA_IO,
84+
.i2c_scl_io_num = TEST_MIPI_CSI_CAM_SCCB_SCL_IO,
85+
.port = ESP_CAM_SENSOR_MIPI_CSI,
86+
.format_name = TEST_CAM_FORMAT,
87+
};
88+
example_sensor_init(&sensor_config, &sensor_handle);
89+
90+
//---------------CSI Init------------------//
91+
esp_cam_ctlr_csi_config_t csi_config = {
92+
.ctlr_id = 0,
93+
.h_res = TEST_MIPI_CSI_DISP_HRES,
94+
.v_res = TEST_MIPI_CSI_DISP_VRES,
95+
.lane_bit_rate_mbps = TEST_MIPI_CSI_LANE_BITRATE_MBPS,
96+
.input_data_color_type = CAM_CTLR_COLOR_RAW8,
97+
.output_data_color_type = CAM_CTLR_COLOR_RGB565,
98+
.data_lane_num = 2,
99+
.byte_swap_en = false,
100+
.queue_items = 1,
101+
};
102+
esp_cam_ctlr_handle_t cam_handle = NULL;
103+
TEST_ESP_OK(esp_cam_new_csi_ctlr(&csi_config, &cam_handle));
104+
105+
esp_cam_ctlr_evt_cbs_t cbs = {
106+
.on_get_new_trans = camera_get_new_buffer,
107+
.on_trans_finished = camera_trans_finished,
108+
};
109+
TEST_ESP_OK(esp_cam_ctlr_register_event_callbacks(cam_handle, &cbs, &trans_data));
110+
111+
TEST_ESP_OK(esp_cam_ctlr_enable(cam_handle));
112+
113+
//---------------ISP Init------------------//
114+
isp_proc_handle_t isp_proc = NULL;
115+
esp_isp_processor_cfg_t isp_config = {
116+
.clk_hz = 80 * 1000 * 1000,
117+
.input_data_source = ISP_INPUT_DATA_SOURCE_CSI,
118+
.input_data_color_type = ISP_COLOR_RAW8,
119+
.output_data_color_type = ISP_COLOR_RGB565,
120+
.has_line_start_packet = false,
121+
.has_line_end_packet = false,
122+
.h_res = TEST_MIPI_CSI_DISP_HRES,
123+
.v_res = TEST_MIPI_CSI_DISP_VRES,
124+
};
125+
TEST_ESP_OK(esp_isp_new_processor(&isp_config, &isp_proc));
126+
127+
TEST_ESP_OK(esp_isp_enable(isp_proc));
128+
TEST_ESP_OK(esp_cam_ctlr_start(cam_handle));
129+
TEST_ESP_OK(esp_cam_ctlr_receive(cam_handle, &trans_data, ESP_CAM_CTLR_MAX_DELAY));
130+
vTaskDelay(100 / portTICK_PERIOD_MS);
131+
TEST_ESP_OK(esp_cam_ctlr_stop(cam_handle));
132+
133+
TEST_ASSERT_GREATER_THAN(2, new_buffer_count);
134+
TEST_ASSERT_GREATER_THAN(2, trans_finished_count);
135+
136+
TEST_ESP_OK(esp_cam_ctlr_disable(cam_handle));
137+
TEST_ESP_OK(esp_cam_ctlr_del(cam_handle));
138+
139+
TEST_ESP_OK(esp_isp_disable(isp_proc));
140+
TEST_ESP_OK(esp_isp_del_processor(isp_proc));
141+
142+
TEST_ESP_OK(esp_ldo_release_channel(ldo_mipi_phy));
143+
144+
example_sensor_deinit(sensor_handle);
145+
146+
heap_caps_free(frame_buffer);
147+
}

components/esp_driver_cam/test_apps/csi/pytest_csi.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66

77

88
@pytest.mark.generic
9+
@pytest.mark.parametrize(
10+
'config',
11+
['cache_safe', 'release'],
12+
indirect=True,
13+
)
914
@idf_parametrize('target', ['esp32p4'], indirect=['target'])
10-
def test_csi(dut: Dut) -> None:
15+
def test_csi_driver(case_tester) -> None: # type: ignore
16+
for case in case_tester.test_menu:
17+
if 'TEST esp_cam on ov5647' in case.name:
18+
continue
19+
case_tester.run_normal_case(case=case, reset=True)
20+
21+
22+
@pytest.mark.camera
23+
@pytest.mark.ov5647
24+
@pytest.mark.parametrize(
25+
'config',
26+
['cache_safe', 'release'],
27+
indirect=True,
28+
)
29+
@idf_parametrize('target', ['esp32p4'], indirect=['target'])
30+
def test_csi_camera(dut: Dut) -> None:
1131
dut.run_all_single_board_cases()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
2+
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
3+
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y

components/esp_driver_cam/test_apps/csi/sdkconfig.defaults.esp32p4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ CONFIG_IDF_TARGET="esp32p4"
33
CONFIG_SPIRAM=y
44
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
55
CONFIG_SPIRAM_SPEED_200M=y
6+
7+
CONFIG_CAMERA_OV5647=y

tools/ci/idf_pytest/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
'flash_4mb': 'C2 runners with 4 MB flash',
127127
'jtag_re_enable': 'Runner to re-enable jtag which is softly disabled by burning bit SOFT_DIS_JTAG on eFuse',
128128
'es8311': 'Development board that carries es8311 codec',
129+
'camera': 'Runner with camera',
130+
'ov5647': 'Runner with camera ov5647',
129131
# multi-dut markers
130132
'multi_dut_modbus_rs485': 'a pair of runners connected by RS485 bus',
131133
'ieee802154': 'ieee802154 related tests should run on ieee802154 runners.',

0 commit comments

Comments
 (0)