Skip to content

Commit

Permalink
feat(camera): supported camera related example using sc2336 and ek79007
Browse files Browse the repository at this point in the history
Closes #14517
  • Loading branch information
Icarus113 committed Sep 19, 2024
1 parent 01613ca commit c48a47c
Show file tree
Hide file tree
Showing 24 changed files with 357 additions and 213 deletions.
20 changes: 14 additions & 6 deletions examples/peripherals/camera/camera_dsi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Overview

This example demonstrates how to use the esp_driver_cam component to capture camera sensor signals and display it via DSI interface.
This example demonstrates how to use the esp_driver_cam component to capture camera sensor signals and display it via DSI interface. This example will auto-detect camera sensors via [ESP camera sensor driver](https://components.espressif.com/components/espressif/esp_cam_sensor/versions/0.5.3) and capture camera sensor signals via CSI interface and display it via DSI interface.

## Usage

Expand All @@ -15,12 +15,19 @@ The subsections below give only absolutely necessary information. For full steps

### Hardware Required

This example requires:

- OV5647 camera sensor
- ILI9881C LCD screen
- OV5647 or SC2336 camera sensor, or other camera sensors
- EK79007 or ILI9881C LCD screen
- ESP32P4 devkit

**Note:** OV5647 has its own ISP functions, whereas SC2336 is a camera sensor without ISP functions. You can use the ESP on-chip ISP functions to tune the image together with the sensor ISP functions, if the image quality is not as expected.

**Note:** For EK79007 you will need to connect following pins:
- 5V - 5V
- GND - GND
- RST_LCD - 3V3

You can also connect camera sensors and LCD screens from other vendors to the ESP chip, you can find corresponding camera or LCD drivers from [ESP Component Registry](https://components.espressif.com), or design your own customized drivers.


GND GND
┌────────────────────────────────────────────────┐ ┌─────────────────────────────────────────────────────────┐
Expand All @@ -40,7 +47,7 @@ This example requires:
│ ├──────────────────────┤ │ DSI DATA 1N │ │
│ │ │ ├───────────────────────────┤ │
│ │ CSI DATA 1N │ ESP32-P4 │ │ │
OV5647 ├──────────────────────┤ │ DSI CLK N │ ILI9881C
Camera ├──────────────────────┤ │ DSI CLK N │ LCD Screen
│ │ │ ├───────────────────────────┤ │
│ │ CSI CLK N │ │ │ │
│ ├──────────────────────┤ │ DSI CLK P │ │
Expand Down Expand Up @@ -97,6 +104,7 @@ idf.py menuconfig

```
Set CONFIG_CAMERA_OV5647 to y
Set CONFIG_CAMERA_SC2336 to y
```


Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
menu "Example DSI Configuration"

choice EXAMPLE_LCD_PATTERN
prompt "Select MIPI LCD model"
default EXAMPLE_LCD_PATTERN_EK79007
help
Select LCD controller model.

config EXAMPLE_LCD_PATTERN_EK79007
bool "EK79007"
config EXAMPLE_LCD_PATTERN_ILI9881C
bool "ILI9881C"
endchoice

choice EXAMPLE_MIPI_DSI_DISP_HRES
bool "Set MIPI CSI horizontal resolution"
default EXAMPLE_MIPI_DSI_DISP_HRES_800 if EXAMPLE_LCD_PATTERN_ILI9881C
default EXAMPLE_MIPI_DSI_DISP_HRES_1024 if EXAMPLE_LCD_PATTERN_EK79007
default EXAMPLE_MIPI_DSI_DISP_HRES_800

config EXAMPLE_MIPI_DSI_DISP_HRES_800
bool "800"
config EXAMPLE_MIPI_DSI_DISP_HRES_1024
bool "1024"
endchoice

config EXAMPLE_MIPI_DSI_DISP_HRES
int
default 800 if EXAMPLE_MIPI_DSI_DISP_HRES_800
default 1024 if EXAMPLE_MIPI_DSI_DISP_HRES_1024

choice EXAMPLE_MIPI_DSI_DISP_VRES
bool "Set MIPI CSI vertical resolution"
default EXAMPLE_MIPI_DSI_DISP_VRES_1280 if EXAMPLE_LCD_PATTERN_ILI9881C
default EXAMPLE_MIPI_DSI_DISP_VRES_600 if EXAMPLE_LCD_PATTERN_EK79007
default EXAMPLE_MIPI_DSI_DISP_VRES_1280

config EXAMPLE_MIPI_DSI_DISP_VRES_600
bool "600"
config EXAMPLE_MIPI_DSI_DISP_VRES_1280
bool "1280"
endchoice

config EXAMPLE_MIPI_DSI_DISP_VRES
int
default 600 if EXAMPLE_MIPI_DSI_DISP_VRES_600
default 1280 if EXAMPLE_MIPI_DSI_DISP_VRES_1280
endmenu
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,33 @@
#include "esp_log.h"
#include "esp_lcd_mipi_dsi.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_ili9881c.h"
#include "esp_lcd_ek79007.h"
#include "example_dsi_init.h"
#include "example_dsi_init_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)
void example_dsi_resource_alloc(esp_lcd_dsi_bus_handle_t *mipi_dsi_bus, esp_lcd_panel_io_handle_t *mipi_dbi_io, 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_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_ERROR_CHECK(esp_lcd_new_panel_io_dbi(*mipi_dsi_bus, &dbi_config, mipi_dbi_io));

esp_lcd_dpi_panel_config_t dpi_config = {
.dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT,
.dpi_clock_freq_mhz = 80,
.dpi_clock_freq_mhz = EXAMPLE_MIPI_DSI_DPI_CLK_MHZ,
.virtual_channel = 0,
.pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB565,
.video_timing = {
Expand All @@ -56,21 +48,56 @@ void example_dsi_resource_alloc(esp_lcd_panel_handle_t *ili9881c_ctrl_panel, esp
.vsync_front_porch = EXAMPLE_MIPI_DSI_IMAGE_VFP,
},
};
ESP_ERROR_CHECK(esp_lcd_new_panel_dpi(mipi_dsi_bus, &dpi_config, mipi_dpi_panel));

#if CONFIG_EXAMPLE_LCD_PATTERN_ILI9881C
ili9881c_vendor_config_t vendor_config = {
.mipi_config = {
.dsi_bus = *mipi_dsi_bus,
.dpi_config = &dpi_config,
.lane_num = 2,
},
};
esp_lcd_panel_dev_config_t lcd_dev_config = {
.reset_gpio_num = -1,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
.bits_per_pixel = 16,
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9881c(*mipi_dbi_io, &lcd_dev_config, mipi_dpi_panel));
#elif CONFIG_EXAMPLE_LCD_PATTERN_EK79007
ek79007_vendor_config_t vendor_config = {
.mipi_config = {
.dsi_bus = *mipi_dsi_bus,
.dpi_config = &dpi_config,
},
};
esp_lcd_panel_dev_config_t lcd_dev_config = {
.reset_gpio_num = -1,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
.bits_per_pixel = 16,
.vendor_config = &vendor_config,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_ek79007(*mipi_dbi_io, &lcd_dev_config, mipi_dpi_panel));
#endif

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)
void example_dpi_panel_reset(esp_lcd_panel_handle_t mipi_dpi_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));
//---------------DPI Panel Reset------------------//
ESP_ERROR_CHECK(esp_lcd_panel_reset(mipi_dpi_panel));
}

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));
}

void example_dsi_resource_destroy(esp_lcd_dsi_bus_handle_t mipi_dsi_bus, esp_lcd_panel_io_handle_t mipi_dbi_io, esp_lcd_panel_handle_t mipi_dpi_panel)
{
ESP_ERROR_CHECK(esp_lcd_panel_del(mipi_dpi_panel));
ESP_ERROR_CHECK(esp_lcd_panel_io_del(mipi_dbi_io));
ESP_ERROR_CHECK(esp_lcd_del_dsi_bus(mipi_dsi_bus));
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dependencies:
esp_lcd_ili9881c: "~0.2.0"
esp_lcd_ili9881c: "^1.0.0"
esp_lcd_ek79007: "^1.0.0"
idf:
version: ">=5.3.0"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "esp_lcd_mipi_dsi.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_ili9881c.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -17,18 +16,19 @@ extern "C" {
/**
* @brief DSI init function
*
* @param[out] ili9881c_ctrl_panel ILI9881C panel handle
* @param[out] mipi_dsi_bus MIPI DSI bus handle
* @param[out] mipi_dbi_io MIPI DBI io 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);
void example_dsi_resource_alloc(esp_lcd_dsi_bus_handle_t *mipi_dsi_bus, esp_lcd_panel_io_handle_t *mipi_dbi_io, esp_lcd_panel_handle_t *mipi_dpi_panel, void **frame_buffer);

/**
* @brief DSI ILI9881C panel init function
* @brief DPI panel reset function
*
* @param[in] ili9881c_ctrl_panel ILI9881C panel handle
* @param[in] mipi_dpi_panel MIPI DPI panel handle
*/
void example_dsi_ili9881c_panel_init(esp_lcd_panel_handle_t ili9881c_ctrl_panel);
void example_dpi_panel_reset(esp_lcd_panel_handle_t mipi_dpi_panel);

/**
* @brief DPI panel init function
Expand All @@ -37,6 +37,15 @@ void example_dsi_ili9881c_panel_init(esp_lcd_panel_handle_t ili9881c_ctrl_panel)
*/
void example_dpi_panel_init(esp_lcd_panel_handle_t mipi_dpi_panel);

/**
* @brief Destroy DSI related resources
*
* @param[in] mipi_dsi_bus MIPI DSI bus handle
* @param[in] mipi_dbi_io MIPI DBI io handle
* @param[in] mipi_dpi_panel MIPI DPI panel handle
*/
void example_dsi_resource_destroy(esp_lcd_dsi_bus_handle_t mipi_dsi_bus, esp_lcd_panel_io_handle_t mipi_dbi_io, esp_lcd_panel_handle_t mipi_dpi_panel);

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@

#pragma once

#include "sdkconfig.h"

#ifdef __cplusplus
extern "C" {
#endif

#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
#if CONFIG_EXAMPLE_LCD_PATTERN_ILI9881C
// FPS = 80000000/(40+140+40+800)/(4+16+16+1280) = 60Hz
#define EXAMPLE_MIPI_DSI_DPI_CLK_MHZ 80
#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
#elif CONFIG_EXAMPLE_LCD_PATTERN_EK79007
// FPS = 48000000/(10+120+120+1024)/(1+20+10+600) = 60Hz
#define EXAMPLE_MIPI_DSI_DPI_CLK_MHZ 48
#define EXAMPLE_MIPI_DSI_IMAGE_HSYNC 10
#define EXAMPLE_MIPI_DSI_IMAGE_HBP 120
#define EXAMPLE_MIPI_DSI_IMAGE_HFP 120
#define EXAMPLE_MIPI_DSI_IMAGE_VSYNC 1
#define EXAMPLE_MIPI_DSI_IMAGE_VBP 20
#define EXAMPLE_MIPI_DSI_IMAGE_VFP 10
#endif

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "example_sensor_init.c"
INCLUDE_DIRS "include"
)
Loading

0 comments on commit c48a47c

Please sign in to comment.