1 /*
2  * Copyright (C) 2017-2019 Alibaba Group Holding Limited
3  */
4 /******************************************************************************
5  * @file     drv_mipi_csi_reader.h
6  * @brief    header file for mipi csi reader
7  * @version  V1.4
8  * @date     27. May 2019
9  ******************************************************************************/
10 
11 #ifndef _DRV_MIPI_CSI_READER_H_
12 #define _DRV_MIPI_CSI_READER_H_
13 
14 #include <drv/common.h>
15 #include <drv/mipi_csi.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /// definition for mipi_csi_reader handle.
22 typedef void *mipi_csi_reader_handle_t;
23 
24 /****** MIPI CSI READER Event *****/
25 typedef enum {
26     MIPI_CSI_READER_EVENT_RECEIVE_ERROR  = 0, ///< Receive data error
27     MIPI_CSI_READER_EVENT_FRAME_READY    = 1, ///< Receive data ready
28 } mipi_csi_reader_event_e;
29 
30 typedef enum {
31     MIPI_CSI_READER_NO_ERROR        = 0,    ///< No error
32     MIPI_CSI_READER_ERROR_CRC       = 1,    ///< occur CRC error
33     MIPI_CSI_READER_ERROR_PIXEL_NUM = 2,    ///< occur pixel number
34 } mipi_csi_reader_error_e;
35 
36 typedef struct {
37     mipi_csi_data_format_e format;       ///< frame format
38     uint32_t               height;       ///< frame height
39     uint32_t               width;        ///< frame width
40     uint8_t                **frame_list; ///< output frame address list
41     uint8_t                frame_count;  ///< frame count
42     uint8_t                mipi_id;      ///< the mipi id to connect
43 } mipi_csi_reader_config_t;
44 
45 typedef struct {
46     uint32_t               index;  ///< frame index
47     uint8_t                *addr;  ///< frame address
48     mipi_csi_data_format_e format; ///< frame format
49     uint32_t               height; ///< frame height
50     uint32_t               width;  ///< frame width
51     uint32_t               size;   ///< frame size
52 } mipi_csi_reader_frame_t;
53 
54 typedef void (*mipi_csi_reader_event_cb_t)(mipi_csi_reader_handle_t handle, mipi_csi_reader_event_e event, void *user_data); ///< Pointer to \ref mipi_csi_reader_event_cb_t : MIPI_CSI_READER Event call back.
55 
56 /**
57   \brief       Initialize mipi csi reader Interface. 1. Initializes the resources needed for the mipi csi reader interface 2.registers event callback function
58   \param[in]   idx mipi_csi_reader index
59   \param[in]   cb_event  event call back function \ref mipi_csi_reader_event_cb_t
60   \return      return mipi csi reader handle if success
61 */
62 mipi_csi_reader_handle_t csi_mipi_csi_reader_initialize(int32_t idx, mipi_csi_reader_event_cb_t cb_event, void *user_data);
63 
64 /**
65   \brief       De-initialize mipi csi reader Interface. stops operation and releases the software resources used by the interface
66   \param[in]   handle  mipi csi reader handle to operate.
67   \return      error code
68 */
69 int32_t csi_mipi_csi_reader_uninitialize(mipi_csi_reader_handle_t handle);
70 
71 /**
72   \brief       Config the mipi csi reader and start to work
73   \param[in]   handle  mipi csi reader handle to operate.
74   \param[in]   input   the config of mipi csi reader.
75   \return      error code
76 */
77 int32_t csi_mipi_csi_reader_start(mipi_csi_reader_handle_t handle, mipi_csi_reader_config_t *input);
78 
79 /**
80   \brief       Stop the mipi csi reader
81   \param[in]   handle  mipi csi reader handle to operate.
82   \return      error code
83 */
84 int32_t csi_mipi_csi_reader_stop(mipi_csi_reader_handle_t handle);
85 
86 /**
87   \brief       Hold the specific frame.
88   \param[in]   handle  mipi csi reader handle to operate.
89   \param[in]   frame  the frame to hold.
90   \return      error code.
91 */
92 int32_t csi_mipi_csi_reader_hold_frame(mipi_csi_reader_handle_t handle, uint8_t *frame);
93 
94 /**
95   \brief       Release the specific frame.
96   \param[in]   handle  mipi csi reader handle to operate.
97   \param[in]   frame  the frame to release.
98   \return      error code.
99 */
100 int32_t csi_mipi_csi_reader_release_frame(mipi_csi_reader_handle_t handle, uint8_t *frame);
101 
102 /**
103   \brief       Get the frame idx when frame ready.
104   \param[in]   handle  mipi csi reader handle to operate.
105   \param[out]  frame  the ready frame.
106   \return      error code.
107 */
108 int32_t csi_mipi_csi_reader_get_frame(mipi_csi_reader_handle_t handle, mipi_csi_reader_frame_t *frame);
109 
110 /**
111   \brief       When get frame error, output the error type.
112   \param[in]   handle  mipi csi reader handle to operate.
113   \param[out]  error  output the error type.
114   \param[out]  frame  output the error frame address, when *fram is NULL, it represent unkonw frame.
115   \return      error code.
116 */
117 int32_t csi_mipi_csi_reader_get_error_info(mipi_csi_reader_handle_t handle, mipi_csi_reader_error_e *error, uint8_t **frame);
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif /* _DRV_MIPI_CSI_READER_H_ */
123