From 507d27a56ff221968c74280703b80c0c634a6bee Mon Sep 17 00:00:00 2001 From: Armando Date: Mon, 22 Apr 2024 17:20:53 +0800 Subject: [PATCH 1/3] example(camera): added new camera dsi example --- examples/peripherals/.build-test-rules.yml | 7 + .../camera/camera_dsi/CMakeLists.txt | 6 + .../peripherals/camera/camera_dsi/README.md | 139 +++++++++++ .../camera/camera_dsi/main/CMakeLists.txt | 4 + .../camera/camera_dsi/main/Kconfig.projbuild | 25 ++ .../camera/camera_dsi/main/camera_dsi_main.c | 221 ++++++++++++++++++ .../camera/camera_dsi/main/example_config.h | 36 +++ .../camera/camera_dsi/main/example_dsi_init.c | 79 +++++++ .../camera/camera_dsi/main/example_dsi_init.h | 38 +++ .../camera/camera_dsi/main/idf_component.yml | 5 + .../camera/camera_dsi/pytest_camera_dsi.py | 10 + .../camera/camera_dsi/sdkconfig.defaults | 4 + .../isp_af_schemes/src/isp_af_scheme_sa.c | 2 +- 13 files changed, 575 insertions(+), 1 deletion(-) create mode 100644 examples/peripherals/camera/camera_dsi/CMakeLists.txt create mode 100644 examples/peripherals/camera/camera_dsi/README.md create mode 100644 examples/peripherals/camera/camera_dsi/main/CMakeLists.txt create mode 100644 examples/peripherals/camera/camera_dsi/main/Kconfig.projbuild create mode 100644 examples/peripherals/camera/camera_dsi/main/camera_dsi_main.c create mode 100644 examples/peripherals/camera/camera_dsi/main/example_config.h create mode 100644 examples/peripherals/camera/camera_dsi/main/example_dsi_init.c create mode 100644 examples/peripherals/camera/camera_dsi/main/example_dsi_init.h create mode 100644 examples/peripherals/camera/camera_dsi/main/idf_component.yml create mode 100644 examples/peripherals/camera/camera_dsi/pytest_camera_dsi.py create mode 100644 examples/peripherals/camera/camera_dsi/sdkconfig.defaults diff --git a/examples/peripherals/.build-test-rules.yml b/examples/peripherals/.build-test-rules.yml index 174a6caafd..d5df607519 100644 --- a/examples/peripherals/.build-test-rules.yml +++ b/examples/peripherals/.build-test-rules.yml @@ -24,6 +24,13 @@ examples/peripherals/analog_comparator: - esp_driver_gpio - esp_driver_ana_cmpr +examples/peripherals/camera/camera_dsi: + disable: + - if: SOC_MIPI_CSI_SUPPORTED != 1 or SOC_MIPI_DSI_SUPPORTED != 1 + depends_components: + - esp_lcd + - esp_driver_cam + examples/peripherals/dac: disable: - if: SOC_DAC_SUPPORTED != 1 diff --git a/examples/peripherals/camera/camera_dsi/CMakeLists.txt b/examples/peripherals/camera/camera_dsi/CMakeLists.txt new file mode 100644 index 0000000000..69a158b554 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(camera_dsi) diff --git a/examples/peripherals/camera/camera_dsi/README.md b/examples/peripherals/camera/camera_dsi/README.md new file mode 100644 index 0000000000..76081356bd --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/README.md @@ -0,0 +1,139 @@ +| Supported Targets | ESP32-P4 | +| ----------------- | -------- | + + +# Camera display via DSI example + +## Overview + +This example demonstrates how to use the esp_driver_cam component to capture camera sensor signals and display it via DSI interface. + +## Usage + +The subsections below give only absolutely necessary information. For full steps to configure ESP-IDF and use it to build and run projects, see [ESP-IDF Getting Started](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#get-started). + + +### Hardware Required + +This example requires: + +- OV5647 camera sensor with VCM (Voice Coil Motor). The VCM used in this example is DW9714. +- ILI9881C LCD screen +- ESP32P4 devkit + + + GND GND + ┌────────────────────────────────────────────────┐ ┌─────────────────────────────────────────────────────────┐ + │ │ │ │ + │ │ │ │ + │ │ │ │ + │ │ │ │ + │ │ │ │ + │ │ │ │ + │ │ │ │ + │ │ │ │ + │ ┌───────────────┴─────────────┴──────────────────┐ │ + │ │ │ ┌──────────┴───────────┐ + │ │ │ DSI DATA 1P │ │ + │ │ ├───────────────────────────┤ │ + ┌───────────┴─────────┐ CSI DATA 1P │ │ │ │ + │ ├──────────────────────┤ │ DSI DATA 1N │ │ + │ │ │ ├───────────────────────────┤ │ + │ │ CSI DATA 1N │ ESP32-P4 │ │ │ + │ OV5647 ├──────────────────────┤ │ DSI CLK N │ ILI9881C │ + │ │ │ ├───────────────────────────┤ │ + │ │ CSI CLK N │ │ │ │ + │ ├──────────────────────┤ │ DSI CLK P │ │ + │ │ │ ├───────────────────────────┤ │ + │ │ CSI CLK P │ │ │ │ + │ ├──────────────────────┤ │ DSI DATA 0P │ │ + │ │ │ ├───────────────────────────┤ │ + │ │ CSI DATA 0P │ │ │ │ + │ ├──────────────────────┤ │ DSI DATA 0N │ │ + │ │ │ ├───────────────────────────┤ │ + │ │ CSI DATA 0N │ │ │ │ + │ ├──────────────────────┤ │ └──────────────────────┘ + │ │ │ │ + └───────┬──┬──────────┘ │ │ + │ │ I2C SCL │ │ + │ └─────────────────────────────────┤ │ + │ I2C SDA │ │ + └────────────────────────────────────┤ │ + └────────────────────────────────────────────────┘ + + +### Set Chip Target + +First of all, your target must be supported by both: + +- **By your ESP-IDF version**: For the full list of supported targets, run: + ``` + idf.py --list-targets + ``` +- **By this example**: For the full list of supported targets, refer to the supported targets table at the top of this README. + +After you make sure that your target is supported, go to your example project directory and [set the chip target](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/tools/idf-py.html#select-the-target-chip-set-target): + +``` +idf.py set-target +``` + +For example, to set esp32-P4 as the chip target, run: + +``` +idf.py set-target esp32p4 +``` + + +### Configure the Project + +For information about Kconfig options, see [Project Configuration](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/kconfig.html) > _Name of relevant section(s)_. + +To conveniently check or modify Kconfig options for this example in a project configuration menu, run: + +``` +idf.py menuconfig +``` + +``` +Set CONFIG_CAMERA_OV5647 to y +``` + + +### Build and Flash + +Execute the following command to build the project, flash it to your development board, and run the monitor tool to view the serial output: + +``` +idf.py build flash monitor +``` + +This command can be reduced to `idf.py flash monitor`. + +If the above command fails, check the log on the serial monitor which usually provides information on the possible cause of the issue. + +To exit the serial monitor, use `Ctrl` + `]`. + + +## Example Output + +If you see the following console output, your example should be running correctly: + +``` +I (1085) main_task: Calling app_main() +I (1095) ili9881c: ID1: 0x98, ID2: 0x81, ID3: 0x5c +I (1125) gpio: GPIO[31]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 +I (1125) gpio: GPIO[34]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 +I (1295) ov5647: Detected Camera sensor PID=0x5647 with index 0 +I (1305) cam_dsi: fmt[0].name:MIPI_2lane_24Minput_RAW8_800x1280_50fps +I (1305) cam_dsi: fmt[1].name:MIPI_2lane_24Minput_RAW8_800x640_50fps +I (1315) cam_dsi: fmt[2].name:MIPI_2lane_24Minput_RAW8_800x800_50fps +I (1355) cam_dsi: Format in use:MIPI_2lane_24Minput_RAW8_800x640_50fps +``` + + +## Reference + +- Link to the ESP-IDF feature's API reference, for example [ESP-IDF: Camera Controller Driver](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/camera_driver.html) +- [ESP-IDF Getting Started](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#get-started) +- [Project Configuration](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/kconfig.html) (Kconfig Options) diff --git a/examples/peripherals/camera/camera_dsi/main/CMakeLists.txt b/examples/peripherals/camera/camera_dsi/main/CMakeLists.txt new file mode 100644 index 0000000000..92fcf22747 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "camera_dsi_main.c" "example_dsi_init.c" + INCLUDE_DIRS "." + REQUIRES esp_mm esp_driver_isp esp_driver_cam esp_driver_i2c esp_lcd + ) diff --git a/examples/peripherals/camera/camera_dsi/main/Kconfig.projbuild b/examples/peripherals/camera/camera_dsi/main/Kconfig.projbuild new file mode 100644 index 0000000000..fdc0499452 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/main/Kconfig.projbuild @@ -0,0 +1,25 @@ +menu "Example Configuration" + config EXAMPLE_USED_LDO_CHAN_ID + int "example used LDO channel ID" + default 3 + help + Example used LDO channel ID, you may check datasheet to know more details. + + config EXAMPLE_USED_LDO_VOLTAGE_MV + int "example used LDO voltage in mV" + default 2500 + range 0 3300 + help + Example used LDO voltage, in mV + + choice EXAMPLE_MIPI_CSI_VRES + bool "Set MIPI CSI verticol resolution" + default EXAMPLE_MIPI_CSI_VRES_640 + + config EXAMPLE_MIPI_CSI_VRES_640 + bool "640" + config EXAMPLE_MIPI_CSI_VRES_1280 + bool "1280" + endchoice + +endmenu diff --git a/examples/peripherals/camera/camera_dsi/main/camera_dsi_main.c b/examples/peripherals/camera/camera_dsi/main/camera_dsi_main.c new file mode 100644 index 0000000000..dc9b3e8de2 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/main/camera_dsi_main.c @@ -0,0 +1,221 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include "esp_attr.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "esp_lcd_mipi_dsi.h" +#include "esp_lcd_panel_ops.h" +#include "esp_lcd_ili9881c.h" +#include "esp_ldo_regulator.h" +#include "esp_cache.h" +#include "driver/i2c_master.h" +#include "driver/isp.h" +#include "esp_cam_ctlr_csi.h" +#include "esp_cam_ctlr.h" +#include "esp_sccb_intf.h" +#include "esp_sccb_i2c.h" +#include "esp_cam_sensor.h" +#include "ov5647.h" +#include "example_dsi_init.h" +#include "example_config.h" + +static const char *TAG = "cam_dsi"; + +static bool s_camera_get_new_vb(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data); +static bool s_camera_get_finished_trans(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data); + +void app_main(void) +{ + esp_err_t ret = ESP_FAIL; + esp_lcd_panel_handle_t ili9881c_ctrl_panel = NULL; + esp_lcd_panel_handle_t mipi_dpi_panel = NULL; + void *frame_buffer = NULL; + size_t frame_buffer_size = 0; + + //mipi ldo + esp_ldo_channel_handle_t ldo_mipi_phy = NULL; + esp_ldo_channel_config_t ldo_mipi_phy_config = { + .chan_id = CONFIG_EXAMPLE_USED_LDO_CHAN_ID, + .voltage_mv = CONFIG_EXAMPLE_USED_LDO_VOLTAGE_MV, + }; + ESP_ERROR_CHECK(esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy)); + + /** + * @background + * Sensor use RAW8 + * ISP convert to RGB565 + */ + //---------------DSI Init------------------// + example_dsi_resource_alloc(&ili9881c_ctrl_panel, &mipi_dpi_panel, &frame_buffer); + + //---------------Necessary variable config------------------// + frame_buffer_size = EXAMPLE_MIPI_CSI_DISP_HSIZE * EXAMPLE_MIPI_DSI_IMAGE_VSIZE * EXAMPLE_RGB565_BITS_PER_PIXEL / 8; + + ESP_LOGD(TAG, "EXAMPLE_MIPI_CSI_DISP_HSIZE: %d, EXAMPLE_MIPI_DSI_IMAGE_VSIZE: %d, bits per pixel: %d", EXAMPLE_MIPI_CSI_DISP_HSIZE, EXAMPLE_MIPI_DSI_IMAGE_VSIZE, 8); + ESP_LOGD(TAG, "frame_buffer_size: %zu", frame_buffer_size); + ESP_LOGD(TAG, "frame_buffer: %p", frame_buffer); + + esp_cam_ctlr_trans_t new_trans = { + .buffer = frame_buffer, + .buflen = frame_buffer_size, + }; + + //---------------I2C Init------------------// + i2c_master_bus_config_t i2c_bus_conf = { + .clk_source = I2C_CLK_SRC_DEFAULT, + .sda_io_num = EXAMPLE_MIPI_SCCB_SDA_IO, + .scl_io_num = EXAMPLE_MIPI_SCCB_SCL_IO, + .i2c_port = I2C_NUM_0, + .flags.enable_internal_pullup = true, + }; + i2c_master_bus_handle_t bus_handle = NULL; + ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_conf, &bus_handle)); + + //---------------SCCB Init------------------// + esp_sccb_io_handle_t ov5647_io_handle = NULL; + sccb_i2c_config_t i2c_config = { + .scl_speed_hz = EXAMPLE_MIPI_SCCB_FREQ, + .device_address = EXAMPLE_OV5647_DEV_ADDR, + .dev_addr_length = I2C_ADDR_BIT_LEN_7, + }; + ESP_ERROR_CHECK(sccb_new_i2c_io(bus_handle, &i2c_config, &ov5647_io_handle)); + + //---------------CSI Init------------------// + esp_cam_ctlr_csi_config_t csi_config = { + .ctlr_id = 0, + .h_res = EXAMPLE_MIPI_CSI_DISP_HSIZE, +#if CONFIG_EXAMPLE_MIPI_CSI_VRES_640 + .v_res = EXAMPLE_MIPI_CSI_DISP_VSIZE_640P, +#else + .v_res = EXAMPLE_MIPI_CSI_DISP_VSIZE_1280P, +#endif + .lane_bit_rate_mbps = EXAMPLE_MIPI_CSI_LANE_BITRATE_MBPS, + .input_data_color_type = MIPI_CSI_COLOR_RAW8, + .output_data_color_type = MIPI_CSI_COLOR_RGB565, + .data_lane_num = 2, + .byte_swap_en = false, + .queue_items = 1, + }; + esp_cam_ctlr_handle_t cam_handle = NULL; + ret = esp_cam_new_csi_ctlr(&csi_config, &cam_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "csi init fail[%d]", ret); + return; + } + + esp_cam_ctlr_evt_cbs_t cbs = { + .on_get_new_trans = s_camera_get_new_vb, + .on_trans_finished = s_camera_get_finished_trans, + }; + if (esp_cam_ctlr_register_event_callbacks(cam_handle, &cbs, &new_trans) != ESP_OK) { + ESP_LOGE(TAG, "ops register fail"); + return; + } + + ESP_ERROR_CHECK(esp_cam_ctlr_enable(cam_handle)); + + //---------------ISP Init------------------// + isp_proc_handle_t isp_proc = NULL; + esp_isp_processor_cfg_t isp_config = { + .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, + .has_line_start_packet = false, + .has_line_end_packet = false, + .h_res = EXAMPLE_MIPI_CSI_DISP_HSIZE, +#if CONFIG_EXAMPLE_MIPI_CSI_VRES_640 + .v_res = EXAMPLE_MIPI_CSI_DISP_VSIZE_640P, +#else + .v_res = EXAMPLE_MIPI_CSI_DISP_VSIZE_1280P, +#endif + }; + ESP_ERROR_CHECK(esp_isp_new_processor(&isp_config, &isp_proc)); + ESP_ERROR_CHECK(esp_isp_enable(isp_proc)); + + //---------------DSI Panel Init------------------// + example_dsi_ili9881c_panel_init(ili9881c_ctrl_panel); + + //init to all white + memset(frame_buffer, 0xFF, frame_buffer_size); + esp_cache_msync((void *)frame_buffer, frame_buffer_size, ESP_CACHE_MSYNC_FLAG_DIR_C2M); + + if (esp_cam_ctlr_start(cam_handle) != ESP_OK) { + ESP_LOGE(TAG, "Driver start fail"); + return; + } + + esp_cam_sensor_config_t cam_config = { + .sccb_handle = ov5647_io_handle, + .reset_pin = -1, + .pwdn_pin = -1, + .xclk_pin = -1, + .sensor_port = ESP_CAM_SENSOR_MIPI_CSI, + }; + + esp_cam_sensor_device_t *cam = ov5647_detect(&cam_config); + if (!cam) { + ESP_LOGE(TAG, "failed to detect 5647"); + return; + } + + esp_cam_sensor_format_array_t cam_fmt_array = {0}; + esp_cam_sensor_query_format(cam, &cam_fmt_array); + const esp_cam_sensor_format_t *parray = cam_fmt_array.format_array; + for (int i = 0; i < cam_fmt_array.count; i++) { + ESP_LOGI(TAG, "fmt[%d].name:%s", i, parray[i].name); + } + + esp_cam_sensor_format_t *cam_cur_fmt = NULL; + for (int i = 0; i < cam_fmt_array.count; i++) { + +#if CONFIG_EXAMPLE_MIPI_CSI_VRES_640 + if (!strcmp(parray[i].name, "MIPI_2lane_24Minput_RAW8_800x640_50fps")) { + cam_cur_fmt = (esp_cam_sensor_format_t *) & (parray[i].name); + } +#else + if (!strcmp(parray[i].name, "MIPI_2lane_24Minput_RAW8_800x1280_50fps")) { + cam_cur_fmt = (esp_cam_sensor_format_t *) & (parray[i].name); + } +#endif + } + + ret = esp_cam_sensor_set_format(cam, (const esp_cam_sensor_format_t *) cam_cur_fmt); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Format set fail"); + } else { + ESP_LOGI(TAG, "Format in use:%s", cam_cur_fmt->name); + } + int enable_flag = 1; + // Set sensor output stream + ret = esp_cam_sensor_ioctl(cam, ESP_CAM_SENSOR_IOC_S_STREAM, &enable_flag); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Start stream fail"); + } + + example_dpi_panel_init(mipi_dpi_panel); + + while (1) { + ESP_ERROR_CHECK(esp_cam_ctlr_receive(cam_handle, &new_trans, ESP_CAM_CTLR_MAX_DELAY)); + } +} + +static bool s_camera_get_new_vb(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data) +{ + esp_cam_ctlr_trans_t new_trans = *(esp_cam_ctlr_trans_t *)user_data; + trans->buffer = new_trans.buffer; + trans->buflen = new_trans.buflen; + + return false; +} + +static bool s_camera_get_finished_trans(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data) +{ + return false; +} diff --git a/examples/peripherals/camera/camera_dsi/main/example_config.h b/examples/peripherals/camera/camera_dsi/main/example_config.h new file mode 100644 index 0000000000..fe6bbac88a --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/main/example_config.h @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#define EXAMPLE_RGB565_BITS_PER_PIXEL 16 +#define EXAMPLE_MIPI_SCCB_FREQ (100000) +#define EXAMPLE_MIPI_SCCB_SCL_IO (34) +#define EXAMPLE_MIPI_SCCB_SDA_IO (31) +#define EXAMPLE_MIPI_CSI_DISP_HSIZE 800 +#define EXAMPLE_MIPI_CSI_DISP_VSIZE_640P 640 +#define EXAMPLE_MIPI_CSI_DISP_VSIZE_1280P 1280 +#define EXAMPLE_MIPI_CSI_640P 1 +#define EXAMPLE_MIPI_IDI_CLOCK_RATE (50000000) +#define EXAMPLE_MIPI_CSI_LANE_BITRATE_MBPS 200 //line_rate = pclk * 4 + +#define EXAMPLE_MIPI_DSI_IMAGE_HSIZE 800 +#define EXAMPLE_MIPI_DSI_IMAGE_VSIZE 1280 +#define EXAMPLE_MIPI_DSI_IMAGE_HSYNC 40 +#define EXAMPLE_MIPI_DSI_IMAGE_HBP 140 +#define EXAMPLE_MIPI_DSI_IMAGE_HFP 40 +#define EXAMPLE_MIPI_DSI_IMAGE_VSYNC 4 +#define EXAMPLE_MIPI_DSI_IMAGE_VBP 16 +#define EXAMPLE_MIPI_DSI_IMAGE_VFP 16 + +#define EXAMPLE_OV5647_DEV_ADDR 0x36 +#ifdef __cplusplus +} +#endif diff --git a/examples/peripherals/camera/camera_dsi/main/example_dsi_init.c b/examples/peripherals/camera/camera_dsi/main/example_dsi_init.c new file mode 100644 index 0000000000..5291024f33 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/main/example_dsi_init.c @@ -0,0 +1,79 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include "esp_log.h" +#include "esp_heap_caps.h" +#include "esp_lcd_mipi_dsi.h" +#include "esp_lcd_panel_ops.h" +#include "esp_lcd_ili9881c.h" +#include "esp_ldo_regulator.h" +#include "esp_cache.h" +#include "example_dsi_init.h" +#include "example_config.h" + +void example_dsi_resource_alloc(esp_lcd_panel_handle_t *ili9881c_ctrl_panel, esp_lcd_panel_handle_t *mipi_dpi_panel, void **frame_buffer) +{ + esp_lcd_dsi_bus_handle_t mipi_dsi_bus = NULL; + esp_lcd_panel_io_handle_t mipi_dbi_io = NULL; + + //---------------DSI resource allocation------------------// + esp_lcd_dsi_bus_config_t bus_config = { + .bus_id = 0, + .num_data_lanes = 2, + .phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT, + .lane_bit_rate_mbps = 1000, // 1000 Mbps + }; + ESP_ERROR_CHECK(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus)); + + esp_lcd_dbi_io_config_t dbi_config = { + .virtual_channel = 0, + .lcd_cmd_bits = 8, + .lcd_param_bits = 8, + }; + ESP_ERROR_CHECK(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &mipi_dbi_io)); + + esp_lcd_panel_dev_config_t lcd_dev_config = { + .bits_per_pixel = 16, + .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, + .reset_gpio_num = -1, + }; + ESP_ERROR_CHECK(esp_lcd_new_panel_ili9881c(mipi_dbi_io, &lcd_dev_config, ili9881c_ctrl_panel)); + + esp_lcd_dpi_panel_config_t dpi_config = { + .dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT, + .dpi_clock_freq_mhz = 80, + .virtual_channel = 0, + .pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB565, + .video_timing = { + .h_size = EXAMPLE_MIPI_DSI_IMAGE_HSIZE, + .v_size = EXAMPLE_MIPI_DSI_IMAGE_VSIZE, + .hsync_back_porch = EXAMPLE_MIPI_DSI_IMAGE_HBP, + .hsync_pulse_width = EXAMPLE_MIPI_DSI_IMAGE_HSYNC, + .hsync_front_porch = EXAMPLE_MIPI_DSI_IMAGE_HFP, + .vsync_back_porch = EXAMPLE_MIPI_DSI_IMAGE_VBP, + .vsync_pulse_width = EXAMPLE_MIPI_DSI_IMAGE_VSYNC, + .vsync_front_porch = EXAMPLE_MIPI_DSI_IMAGE_VFP, + }, + }; + ESP_ERROR_CHECK(esp_lcd_new_panel_dpi(mipi_dsi_bus, &dpi_config, mipi_dpi_panel)); + ESP_ERROR_CHECK(esp_lcd_dpi_panel_get_frame_buffer(*mipi_dpi_panel, 1, frame_buffer)); +} + +void example_dsi_ili9881c_panel_init(esp_lcd_panel_handle_t ili9881c_ctrl_panel) +{ + //---------------DSI Panel Init------------------// + ESP_ERROR_CHECK(esp_lcd_panel_reset(ili9881c_ctrl_panel)); + ESP_ERROR_CHECK(esp_lcd_panel_init(ili9881c_ctrl_panel)); + // turn on display + ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(ili9881c_ctrl_panel, true)); +} + +void example_dpi_panel_init(esp_lcd_panel_handle_t mipi_dpi_panel) +{ + //---------------DPI Panel Init------------------// + ESP_ERROR_CHECK(esp_lcd_panel_init(mipi_dpi_panel)); +} diff --git a/examples/peripherals/camera/camera_dsi/main/example_dsi_init.h b/examples/peripherals/camera/camera_dsi/main/example_dsi_init.h new file mode 100644 index 0000000000..f2f4c1c597 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/main/example_dsi_init.h @@ -0,0 +1,38 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief DSI init function + * + * @param[out] ili9881c_ctrl_panel ILI9881C panel handle + * @param[out] mipi_dpi_panel MIPI DPI panel handle + * @param[out] frame_buffer frame buffer + */ +void example_dsi_resource_alloc(esp_lcd_panel_handle_t *ili9881c_ctrl_panel, esp_lcd_panel_handle_t *mipi_dpi_panel, void **frame_buffer); + +/** + * @brief DSI ILI9881C panel init function + * + * @param[in] ili9881c_ctrl_panel ILI9881C panel handle + */ +void example_dsi_ili9881c_panel_init(esp_lcd_panel_handle_t ili9881c_ctrl_panel); + +/** + * @brief DPI panel init function + * + * @param[in] mipi_dpi_panel MIPI DPI panel handle + */ +void example_dpi_panel_init(esp_lcd_panel_handle_t mipi_dpi_panel); + +#ifdef __cplusplus +} +#endif diff --git a/examples/peripherals/camera/camera_dsi/main/idf_component.yml b/examples/peripherals/camera/camera_dsi/main/idf_component.yml new file mode 100644 index 0000000000..16bbe27383 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/main/idf_component.yml @@ -0,0 +1,5 @@ +dependencies: + espressif/esp_cam_sensor: "^0.2.2" + espressif/esp_lcd_ili9881c: "*" + idf: + version: ">=5.3.0" diff --git a/examples/peripherals/camera/camera_dsi/pytest_camera_dsi.py b/examples/peripherals/camera/camera_dsi/pytest_camera_dsi.py new file mode 100644 index 0000000000..9c234e6217 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/pytest_camera_dsi.py @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32p4 +@pytest.mark.generic +def test_camera_dsi(dut: Dut) -> None: + dut.expect_exact('Calling app_main()') diff --git a/examples/peripherals/camera/camera_dsi/sdkconfig.defaults b/examples/peripherals/camera/camera_dsi/sdkconfig.defaults new file mode 100644 index 0000000000..7c4a698932 --- /dev/null +++ b/examples/peripherals/camera/camera_dsi/sdkconfig.defaults @@ -0,0 +1,4 @@ +CONFIG_SPIRAM=y +CONFIG_IDF_EXPERIMENTAL_FEATURES=y +CONFIG_SPIRAM_SPEED_200M=y +CONFIG_CAMERA_OV5647=y diff --git a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c index 516782695d..094ae4df46 100644 --- a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c +++ b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c @@ -136,7 +136,7 @@ static esp_err_t s_af_process(void *arg, int *out_definition_thresh, int *out_lu af_current_best = af_current; } - ESP_LOGV(TAG, "af_sum: %"PRId32", af_current: %"PRId32".%"PRId32, af_sum, (int)af_current, (int)((int)(af_current * 1000) % 1000)); + ESP_LOGV(TAG, "af_sum: %d, af_current: %d.%d", af_sum, (int)af_current, (int)((int)(af_current * 1000) % 1000)); } // second search From 359f3e146acde4ad9097adb36cbc496db69e747e Mon Sep 17 00:00:00 2001 From: Armando Date: Mon, 22 Apr 2024 17:21:31 +0800 Subject: [PATCH 2/3] fix(isp): fixed af environment detector lack of configuration issue --- components/esp_driver_isp/CMakeLists.txt | 1 + components/esp_driver_isp/src/isp_af.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/esp_driver_isp/CMakeLists.txt b/components/esp_driver_isp/CMakeLists.txt index b75c9bfc4a..7551a2a5a5 100644 --- a/components/esp_driver_isp/CMakeLists.txt +++ b/components/esp_driver_isp/CMakeLists.txt @@ -9,4 +9,5 @@ endif() idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${public_include} + PRIV_REQUIRES esp_driver_gpio ) diff --git a/components/esp_driver_isp/src/isp_af.c b/components/esp_driver_isp/src/isp_af.c index f2e0087a3d..5e7bb86bdb 100644 --- a/components/esp_driver_isp/src/isp_af.c +++ b/components/esp_driver_isp/src/isp_af.c @@ -174,6 +174,10 @@ esp_err_t esp_isp_af_controller_set_env_detector(isp_af_ctrlr_t af_ctrlr, const isp_ll_af_env_monitor_set_period(af_ctrlr->isp_proc->hal.hw, 0); isp_ll_clear_intr(af_ctrlr->isp_proc->hal.hw, ISP_LL_EVENT_AF_ENV); + isp_ll_af_env_monitor_set_mode(af_ctrlr->isp_proc->hal.hw, ISP_LL_AF_ENV_MONITOR_MODE_ABS); + isp_ll_af_env_monitor_set_period(af_ctrlr->isp_proc->hal.hw, af_ctrlr->config.interval); + isp_ll_enable_intr(af_ctrlr->isp_proc->hal.hw, ISP_LL_EVENT_AF_ENV, true); + return ESP_OK; } @@ -196,7 +200,7 @@ esp_err_t esp_isp_af_env_detector_register_event_callbacks(isp_af_ctrlr_t af_ctr return ESP_OK; } -esp_err_t esp_isp_af_env_detector_set_threshold(isp_af_ctrlr_t af_ctrlr, int definition_thresh, int luminance_thresh) +esp_err_t esp_isp_af_controller_set_env_detector_threshold(isp_af_ctrlr_t af_ctrlr, int definition_thresh, int luminance_thresh) { ESP_RETURN_ON_FALSE_ISR(af_ctrlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); ESP_RETURN_ON_FALSE_ISR(af_ctrlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "detector isn't in enable state"); From 3b567b7033bbeb597faac1dc33203eb67f464340 Mon Sep 17 00:00:00 2001 From: Armando Date: Mon, 22 Apr 2024 17:15:15 +0800 Subject: [PATCH 3/3] fix(csi): fixed wrong assert when there's new transaction --- components/esp_driver_cam/csi/src/esp_cam_ctlr_csi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/esp_driver_cam/csi/src/esp_cam_ctlr_csi.c b/components/esp_driver_cam/csi/src/esp_cam_ctlr_csi.c index 1136273da0..6c297f1b9c 100644 --- a/components/esp_driver_cam/csi/src/esp_cam_ctlr_csi.c +++ b/components/esp_driver_cam/csi/src/esp_cam_ctlr_csi.c @@ -300,6 +300,7 @@ static bool csi_dma_trans_done_callback(dw_gdma_channel_handle_t chan, const dw_ bool need_yield = false; BaseType_t high_task_woken = pdFALSE; csi_controller_t *ctlr = (csi_controller_t *)user_data; + bool has_new_trans = false; bool use_backup = false; dw_gdma_block_transfer_config_t csi_dma_transfer_config = {}; @@ -328,12 +329,14 @@ static bool csi_dma_trans_done_callback(dw_gdma_channel_handle_t chan, const dw_ use_backup = true; } else { csi_dma_transfer_config.dst.addr = (uint32_t)(new_trans.buffer); + has_new_trans = true; } } else if (xQueueReceiveFromISR(ctlr->trans_que, &new_trans, &high_task_woken) == pdTRUE) { if (!(new_trans.buffer) || new_trans.buflen < ctlr->fb_size_in_bytes) { use_backup = true; } else { csi_dma_transfer_config.dst.addr = (uint32_t)(new_trans.buffer); + has_new_trans = true; } } else if (!ctlr->bk_buffer_dis) { use_backup = true; @@ -344,7 +347,9 @@ static bool csi_dma_trans_done_callback(dw_gdma_channel_handle_t chan, const dw_ new_trans.buflen = ctlr->fb_size_in_bytes; ESP_EARLY_LOGD(TAG, "no new buffer or no long enough new buffer, use driver internal buffer"); csi_dma_transfer_config.dst.addr = (uint32_t)ctlr->backup_buffer; - } else { + } + + if (!has_new_trans) { assert(false && "no new buffer, and no driver internal buffer"); }