feat(hal):graudate the camera hal driver into a new component

This commit is contained in:
armando
2025-11-26 08:42:12 +08:00
parent ef0408cd4b
commit dfe4a6e5f7
34 changed files with 142 additions and 126 deletions
@@ -0,0 +1,56 @@
/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "soc/soc_caps.h"
#include "hal/color_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Camera Controller Color Type
*/
typedef enum {
CAM_CTLR_COLOR_RAW8 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW8), ///< RAW8
CAM_CTLR_COLOR_RAW10 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW10), ///< RAW10
CAM_CTLR_COLOR_RAW12 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW12), ///< RAW12
CAM_CTLR_COLOR_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), ///< RGB565
CAM_CTLR_COLOR_RGB666 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB666), ///< RGB666
CAM_CTLR_COLOR_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), ///< RGB888
CAM_CTLR_COLOR_YUV420 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV420), ///< YUV420
CAM_CTLR_COLOR_YUV422 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV422), ///< YUV422
CAM_CTLR_COLOR_GRAY4 = COLOR_TYPE_ID(COLOR_SPACE_GRAY, COLOR_PIXEL_GRAY4), ///< GRAY4
CAM_CTLR_COLOR_GRAY8 = COLOR_TYPE_ID(COLOR_SPACE_GRAY, COLOR_PIXEL_GRAY8), ///< GRAY8
} cam_ctlr_color_t;
/**
* @brief Camera Controller Data Width
*/
typedef enum {
CAM_CTLR_DATA_WIDTH_8 = 8, ///< 8-bit data width
CAM_CTLR_DATA_WIDTH_10 = 10, ///< 10-bit data width
CAM_CTLR_DATA_WIDTH_12 = 12, ////< 12-bit data width
CAM_CTLR_DATA_WIDTH_16 = 16, ///< 16-bit data width
} cam_ctlr_data_width_t;
/**
* @brief Camera Controller format conversion configuration
*/
typedef struct {
cam_ctlr_color_t src_format; /*!< Source format */
cam_ctlr_color_t dst_format; /*!< Destination format */
color_conv_std_rgb_yuv_t conv_std; /*!< Conversion standard */
uint32_t data_width; /*!< Data width in bits */
color_range_t input_range; /*!< Input color range */
color_range_t output_range; /*!< Output color range */
} cam_ctlr_format_conv_config_t;
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,93 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "hal/cam_types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct lcd_cam_dev_t cam_dev_t; // CAM SOC layer handle
/**
* @brief CAM hardware interface object data
*/
typedef struct cam_hal_context {
cam_dev_t *hw; /*!< Beginning address of the CAM peripheral registers. */
} cam_hal_context_t;
/**
* @brief CAM HAL driver configuration
*/
typedef struct cam_hal_config {
int port; /*!< CAM port */
uint32_t cam_data_width; /*!< CAM data width, 8 or 16 or 24 bit, default to 8 */
bool bit_swap_en; /*!< CAM enable bit swap */
bool byte_swap_en; /*!< CAM enable byte swap */
} cam_hal_config_t;
/**
* @brief Initialize CAM hardware
*
* @param hal CAM object data pointer
* @param config CAM configuration
*
* @return None
*/
void cam_hal_init(cam_hal_context_t *hal, const cam_hal_config_t *config);
/**
* @brief De-initialize CAM hardware
*
* @param hal CAM object data pointer
*
* @return None
*/
void cam_hal_deinit(cam_hal_context_t *hal);
/**
* @brief Start CAM to receive frame data
*
* @param hal CAM object data pointer
*
* @return None
*/
void cam_hal_start_streaming(cam_hal_context_t *hal);
/**
* @brief Stop CAM receiving frame data
*
* @param hal CAM object data pointer
*
* @return None
*/
void cam_hal_stop_streaming(cam_hal_context_t *hal);
/**
* @brief Configure color format conversion
*
* This function handles all types of color format conversions:
* - YUV to RGB conversion
* - RGB to YUV conversion
* - YUV to YUV conversion
*
* Color range support:
* - Full range: 0-255 for both RGB and YUV
* - Limited range: RGB 16-240, YUV Y:16-240, U-V:16-235
*
* @param hal CAM HAL context pointer
* @param config Color conversion configuration. If NULL, default config is used.
*/
void cam_hal_color_format_convert(cam_hal_context_t *hal,
const cam_ctlr_format_conv_config_t *config);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,38 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "soc/soc_caps.h"
#include "soc/periph_defs.h"
#if SOC_HAS(LCDCAM_CAM)
#include "hal/cam_ll.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if SOC_LCDCAM_CAM_SUPPORTED
typedef struct {
struct {
const shared_periph_module_t module;
const int irq_id;
const int data_sigs[CAM_LL_DATA_WIDTH_MAX];
const int hsync_sig;
const int vsync_sig;
const int pclk_sig;
const int de_sig;
const int clk_sig;
} buses[CAM_LL_PERIPH_NUM];
} cam_signal_conn_t;
extern const cam_signal_conn_t cam_periph_signals;
#endif // SOC_LCDCAM_CAM_SUPPORTED
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,26 @@
/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "soc/soc_caps.h"
#include "soc/clk_tree_defs.h"
#include "hal/color_types.h"
#include "hal/cam_ctlr_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#if SOC_LCDCAM_CAM_SUPPORTED
typedef soc_periph_cam_clk_src_t cam_clock_source_t; /*!< Clock source type of CAM */
#else
typedef int cam_clock_source_t; /*!< Default type */
#endif
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,59 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "hal/mipi_csi_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief MIPI CSI SOC layer representation of the host controller
*/
typedef struct csi_host_dev_t *mipi_csi_host_soc_handle_t;
/**
* @brief MIPI CSI SOC layer representation of the bridge controller
*/
typedef struct csi_brg_dev_t *mipi_csi_bridge_soc_handle_t;
/**
* @brief MIPI CSI HAL driver context
*/
typedef struct {
mipi_csi_host_soc_handle_t host_dev;
mipi_csi_bridge_soc_handle_t bridge_dev;
} mipi_csi_hal_context_t;
/**
* @brief MIPI CSI HAL driver configuration
*/
typedef struct {
uint8_t lanes_num; ///< Lane num
uint32_t frame_width; ///< Frame width
uint32_t frame_height; ///< Frame height
uint32_t in_bpp; ///< In bits per pixel
uint32_t out_bpp; ///< Out bits per pixel
bool byte_swap_en; ///< Enable byte swap
int lane_bit_rate_mbps; ///< Lane bit rate in Mbps
} mipi_csi_hal_config_t;
/**
* @brief MIPI CSI HAL layer initialization
*
* @param hal Pointer to the HAL driver context
* @param config Pointer to the HAL configuration
*/
void mipi_csi_hal_init(mipi_csi_hal_context_t *hal, const mipi_csi_hal_config_t *config);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,30 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief MIPI CSI PHY PLL frequency range
*/
typedef struct {
uint32_t start_mbps; /*!< Start frequency of the range (included) */
uint32_t end_mbps; /*!< End frequency of the range (included) */
uint8_t hs_freq_range_sel; /*!< HS operating frequency range selection */
} soc_mipi_csi_phy_pll_freq_range_t;
extern const soc_mipi_csi_phy_pll_freq_range_t soc_mipi_csi_phy_pll_ranges[];
extern const size_t num_of_soc_mipi_csi_phy_pll_ranges;
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,30 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_assert.h"
#include "soc/soc_caps.h"
#include "soc/clk_tree_defs.h"
#include "hal/color_types.h"
#include "hal/cam_ctlr_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#if SOC_MIPI_CSI_SUPPORTED
/**
* @brief MIPI CSI PHY clock source
*/
typedef soc_periph_mipi_csi_phy_clk_src_t mipi_csi_phy_clock_source_t;
#else
typedef int mipi_csi_phy_clock_source_t;
#endif // SOC_MIPI_CSI_SUPPORTED
#ifdef __cplusplus
}
#endif