mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(csi): support csi input bit swap
This commit is contained in:
committed by
Armando (Dou Yiwen)
parent
f2635f98d9
commit
303da81075
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "hal/misc.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/hal_utils.h"
|
||||
#include "hal/config.h"
|
||||
#include "hal/mipi_csi_types.h"
|
||||
#include "hal/color_types.h"
|
||||
#include "hal/cam_ctlr_types.h"
|
||||
@@ -137,16 +138,199 @@ static inline void mipi_csi_brg_ll_set_dma_req_interval(csi_brg_dev_t *dev, uint
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the data endianness order in bytes
|
||||
* @brief Set the output data endianness order in bytes
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param byte_swap_en byte swap enable or not
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_byte_endian(csi_brg_dev_t *dev, bool byte_swap_en)
|
||||
static inline void mipi_csi_brg_ll_set_output_byte_endian(csi_brg_dev_t *dev, bool byte_swap_en)
|
||||
{
|
||||
dev->endian_mode.byte_endian_order = byte_swap_en;
|
||||
}
|
||||
|
||||
#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
|
||||
/**
|
||||
* @brief Set RGB element order for input color data
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param rgb_format RGB element order: 0=RGB, 1=BGR, 2=RBG, 3=BRG, 4=GRB, 5=GBR
|
||||
*
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_input_rgb_format(csi_brg_dev_t *dev, uint32_t rgb_format)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_rgb_format = rgb_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the color format for the input color data
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param color_format Camera controller color format
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_input_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
// Set format type
|
||||
if (color_format == CAM_CTLR_COLOR_RGB888) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 0;
|
||||
mipi_csi_brg_ll_set_input_rgb_format(dev, 0); // Default: RGB order
|
||||
} else if (color_format == CAM_CTLR_COLOR_RGB565) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 1;
|
||||
mipi_csi_brg_ll_set_input_rgb_format(dev, 0); // Default: RGB order
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV420) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 3;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_YVYU ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_YUYV ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_UYVY ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_VYUY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 2;
|
||||
// Set YUV422 packing order: YVYU=0, YUYV=1, VYUY=2, UYVY=3
|
||||
if (color_format == CAM_CTLR_COLOR_YUV422_YVYU) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 0;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_YUYV) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 1;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_VYUY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 2;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_UYVY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 3;
|
||||
}
|
||||
} else {
|
||||
HAL_ASSERT(false && "Unsupported input color format");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable color mode conversion output
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param en true to enable, false to disable
|
||||
*
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_enable_color_conversion(csi_brg_dev_t *dev, bool en)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_en = en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable color mode conversion bypass
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller regihost_cm_ctrlster base address
|
||||
* @param bypass true to bypass (input directly to output), false to enable conversion
|
||||
*
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_color_mode_bypass(csi_brg_dev_t *dev, bool bypass)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_bypass = bypass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the color format for the output color data
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param color_format Camera controller color format
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_output_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
if (color_format == CAM_CTLR_COLOR_RGB888) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 0;
|
||||
} else if (color_format == CAM_CTLR_COLOR_RGB565) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 1;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV420) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 3;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_YVYU ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_YUYV ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_UYVY ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_VYUY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 2;
|
||||
} else {
|
||||
HAL_ASSERT(false && "Unsupported output color format");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Set the 16-bit swap
|
||||
*
|
||||
* @note
|
||||
* [31:16] [15:0]
|
||||
* ->
|
||||
* [15:0] [31:16]
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param swap true to swap, false to not swap
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_16bit_swap(csi_brg_dev_t *dev, bool swap)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_16bit_swap = swap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the 8-bit swap
|
||||
*
|
||||
* @note
|
||||
* [31:24] [23:16] [15:8] [7:0]
|
||||
* ->
|
||||
* [7:0] [15:8] [23:16] [31:24]
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param swap true to swap, false to not swap
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_8bit_swap(csi_brg_dev_t *dev, bool swap)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_8bit_swap = swap;
|
||||
}
|
||||
|
||||
#else
|
||||
static inline void mipi_csi_brg_ll_set_input_rgb_format(csi_brg_dev_t *dev, uint32_t rgb_format)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)rgb_format;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_input_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)color_format;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_enable_color_conversion(csi_brg_dev_t *dev, bool en)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)en;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_color_mode_bypass(csi_brg_dev_t *dev, bool bypass)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)bypass;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_output_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)color_format;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_16bit_swap(csi_brg_dev_t *dev, bool swap)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)swap;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_8bit_swap(csi_brg_dev_t *dev, bool swap)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)swap;
|
||||
}
|
||||
|
||||
#endif // HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "hal/mipi_csi_brg_ll.h"
|
||||
#include "hal/mipi_csi_phy_ll.h"
|
||||
#include "hal/mipi_csi_host_ll.h"
|
||||
#include "hal/config.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -156,141 +155,6 @@ static inline void mipi_csi_ll_reset_host_clock(int group_id)
|
||||
mipi_csi_ll_reset_host_clock(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
|
||||
/**
|
||||
* @brief Set RGB element order for input color data
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param rgb_format RGB element order: 0=RGB, 1=BGR, 2=RBG, 3=BRG, 4=GRB, 5=GBR
|
||||
*
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_input_rgb_format(csi_brg_dev_t *dev, uint32_t rgb_format)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_rgb_format = rgb_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the color format for the input color data
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param color_format Camera controller color format
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_input_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
// Set format type
|
||||
if (color_format == CAM_CTLR_COLOR_RGB888) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 0;
|
||||
mipi_csi_brg_ll_set_input_rgb_format(dev, 0); // Default: RGB order
|
||||
} else if (color_format == CAM_CTLR_COLOR_RGB565) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 1;
|
||||
mipi_csi_brg_ll_set_input_rgb_format(dev, 0); // Default: RGB order
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV420) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 3;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_YVYU ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_YUYV ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_UYVY ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_VYUY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx = 2;
|
||||
// Set YUV422 packing order: YVYU=0, YUYV=1, VYUY=2, UYVY=3
|
||||
if (color_format == CAM_CTLR_COLOR_YUV422_YVYU) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 0;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_YUYV) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 1;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_VYUY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 2;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_UYVY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_rx_yuv422_format = 3;
|
||||
}
|
||||
} else {
|
||||
HAL_ASSERT(false && "Unsupported input color format");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable color mode conversion output
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param en true to enable, false to disable
|
||||
*
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_enable_color_conversion(csi_brg_dev_t *dev, bool en)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_en = en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable color mode conversion bypass
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller regihost_cm_ctrlster base address
|
||||
* @param bypass true to bypass (input directly to output), false to enable conversion
|
||||
*
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_color_mode_bypass(csi_brg_dev_t *dev, bool bypass)
|
||||
{
|
||||
dev->host_cm_ctrl.csi_host_cm_bypass = bypass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the color format for the output color data
|
||||
*
|
||||
* @param dev Pointer to the CSI bridge controller register base address
|
||||
* @param color_format Camera controller color format
|
||||
*/
|
||||
static inline void mipi_csi_brg_ll_set_output_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
if (color_format == CAM_CTLR_COLOR_RGB888) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 0;
|
||||
} else if (color_format == CAM_CTLR_COLOR_RGB565) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 1;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV420) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 3;
|
||||
} else if (color_format == CAM_CTLR_COLOR_YUV422_YVYU ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_YUYV ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_UYVY ||
|
||||
color_format == CAM_CTLR_COLOR_YUV422_VYUY) {
|
||||
dev->host_cm_ctrl.csi_host_cm_tx = 2;
|
||||
} else {
|
||||
HAL_ASSERT(false && "Unsupported output color format");
|
||||
}
|
||||
}
|
||||
#else
|
||||
static inline void mipi_csi_brg_ll_set_input_rgb_format(csi_brg_dev_t *dev, uint32_t rgb_format)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)rgb_format;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_input_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)color_format;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_enable_color_conversion(csi_brg_dev_t *dev, bool en)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)en;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_color_mode_bypass(csi_brg_dev_t *dev, bool bypass)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)bypass;
|
||||
}
|
||||
|
||||
static inline void mipi_csi_brg_ll_set_output_color_format(csi_brg_dev_t *dev, cam_ctlr_color_t color_format)
|
||||
{
|
||||
//for compatibility
|
||||
(void)dev;
|
||||
(void)color_format;
|
||||
}
|
||||
#endif // HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -73,5 +73,5 @@ void mipi_csi_hal_init(mipi_csi_hal_context_t *hal, const mipi_csi_hal_config_t
|
||||
mipi_csi_brg_ll_set_flow_ctl_buf_afull_thrd(hal->bridge_dev, 960);
|
||||
mipi_csi_brg_ll_set_data_type_min(hal->bridge_dev, 0x12);
|
||||
mipi_csi_brg_ll_set_data_type_max(hal->bridge_dev, 0x2f);
|
||||
mipi_csi_brg_ll_set_byte_endian(hal->bridge_dev, config->byte_swap_en);
|
||||
mipi_csi_brg_ll_set_output_byte_endian(hal->bridge_dev, config->byte_swap_en);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user