1 #ifndef _BFLB_CSI_H
2 #define _BFLB_CSI_H
3 
4 #include "bflb_core.h"
5 
6 /** @addtogroup LHAL
7   * @{
8   */
9 
10 /** @addtogroup CSI
11   * @{
12   */
13 
14 /** @defgroup CSI_LANE_NUMBER CSI lane number definition
15   * @{
16   */
17 #define CSI_LANE_NUMBER_1 0
18 #define CSI_LANE_NUMBER_2 1
19 /**
20   * @}
21   */
22 
23 /** @defgroup CSI_INTSTS CSI interrupt status definition
24   * @{
25   */
26 #define CSI_INTSTS_GENERIC_PACKET        (1 << 0)
27 #define CSI_INTSTS_LANE_MERGE_ERROR      (1 << 1)
28 #define CSI_INTSTS_ECC_ERROR             (1 << 2)
29 #define CSI_INTSTS_CRC_ERROR             (1 << 3)
30 #define CSI_INTSTS_PHY_HS_SOT_ERROR      (1 << 4)
31 #define CSI_INTSTS_PHY_HS_SOT_SYNC_ERROR (1 << 5)
32 /**
33   * @}
34   */
35 
36 /** @defgroup CSI_INTMASK CSI interrupt mask definition
37   * @{
38   */
39 #define CSI_INTMASK_GENERIC_PACKET        (1 << 0)
40 #define CSI_INTMASK_LANE_MERGE_ERROR      (1 << 1)
41 #define CSI_INTMASK_ECC_ERROR             (1 << 2)
42 #define CSI_INTMASK_CRC_ERROR             (1 << 3)
43 #define CSI_INTMASK_PHY_HS_SOT_ERROR      (1 << 4)
44 #define CSI_INTMASK_PHY_HS_SOT_SYNC_ERROR (1 << 5)
45 /**
46   * @}
47   */
48 
49 /** @defgroup CSI_INTCLR CSI interrupt clear definition
50   * @{
51   */
52 #define CSI_INTCLR_GENERIC_PACKET        (1 << 0)
53 #define CSI_INTCLR_LANE_MERGE_ERROR      (1 << 1)
54 #define CSI_INTCLR_ECC_ERROR             (1 << 2)
55 #define CSI_INTCLR_CRC_ERROR             (1 << 3)
56 #define CSI_INTCLR_PHY_HS_SOT_ERROR      (1 << 4)
57 #define CSI_INTCLR_PHY_HS_SOT_SYNC_ERROR (1 << 5)
58 /**
59   * @}
60   */
61 
62 /**
63  * @brief CSI configuration structure
64  *
65  * @param lane_number   CSI lane number, use @ref CSI_LANE_NUMBER
66  * @param tx_clk_escape CSI tx clock in escape mode
67  * @param data_rate     CSI data rate
68  */
69 struct bflb_csi_config_s {
70     uint8_t lane_number;
71     uint32_t tx_clk_escape;
72     uint32_t data_rate;
73 };
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 /**
80  * @brief Initialize csi.
81  *
82  * @param [in] dev device handle
83  * @param [in] config pointer to csi configure structure
84  */
85 void bflb_csi_init(struct bflb_device_s *dev, const struct bflb_csi_config_s *config);
86 
87 /**
88  * @brief Enable csi.
89  *
90  * @param [in] dev device handle
91  */
92 void bflb_csi_start(struct bflb_device_s *dev);
93 
94 /**
95  * @brief Disable csi.
96  *
97  * @param [in] dev device handle
98  */
99 void bflb_csi_stop(struct bflb_device_s *dev);
100 
101 /**
102  * @brief Set threshold of line buffer, data will be sent to following module when threshold reached.
103  *
104  * @param [in] dev device handle
105  * @param [in] resolution_x number of columns
106  * @param [in] pixel_clock pixel clock
107  * @param [in] dsp_clock dsp clock
108  */
109 void bflb_csi_set_line_threshold(struct bflb_device_s *dev, uint16_t resolution_x, uint32_t pixel_clock, uint32_t dsp_clock);
110 
111 /**
112  * @brief Mask or unmask csi interrupt.
113  *
114  * @param [in] dev device handle
115  * @param [in] int_type csi interrupt mask type, use @ref CSI_INTMASK
116  * @param [in] mask mask or unmask
117  */
118 void bflb_csi_int_mask(struct bflb_device_s *dev, uint32_t int_type, bool mask);
119 
120 /**
121  * @brief Clear csi interrupt.
122  *
123  * @param [in] dev device handle
124  * @param [in] int_type csi interrupt clear type, use @ref CSI_INTCLR
125  */
126 void bflb_csi_int_clear(struct bflb_device_s *dev, uint32_t int_type);
127 
128 /**
129  * @brief Get csi interrupt status.
130  *
131  * @param [in] dev device handle
132  * @return Interrupt status
133  */
134 uint32_t bflb_csi_get_intstatus(struct bflb_device_s *dev);
135 
136 /**
137  * @brief Control csi feature.
138  *
139  * @param [in] dev device handle
140  * @param [in] cmd feature command
141  * @param [in] arg user data
142  * @return A negated errno value on failure
143  */
144 int bflb_csi_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 /**
151   * @}
152   */
153 
154 /**
155   * @}
156   */
157 
158 #endif
159