1 /**************************************************************************//**
2  * @file     ccap.h
3  * @version  V3.00
4  * @brief    M460 Series CCAP Driver Header File
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
8  ******************************************************************************/
9 #ifndef __CCAP_H__
10 #define __CCAP_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 /** @addtogroup Standard_Driver Standard Driver
18   @{
19 */
20 
21 /** @addtogroup CCAP_Driver CCAP Driver
22   @{
23 */
24 
25 /** @addtogroup CCAP_EXPORTED_CONSTANTS CCAP Exported Constants
26   @{
27 */
28 
29 /*---------------------------------------------------------------------------------------------------------*/
30 /* CTL constant definitions                                                                                */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define CCAP_CTL_CCAPEN     (1ul<<CCAP_CTL_CCAPEN_Pos)    /*!< CCAP CTL setting for enabling Camera Capture Interface  \hideinitializer */
33 #define CCAP_CTL_PKTEN      (1ul<<CCAP_CTL_PKTEN_Pos)     /*!< CCAP CTL setting for enabling packet output mode  \hideinitializer */
34 #define CCAP_CTL_SHUTTER    (1ul<<CCAP_CTL_SHUTTER_Pos)   /*!< CCAP CTL setting for enabling shutter mode  \hideinitializer */
35 #define CCAP_CTL_UPDATE     (1ul<<CCAP_CTL_UPDATE_Pos)    /*!< CCAP CTL setting for enabling update register at new frame  \hideinitializer */
36 #define CCAP_CTL_RESET      (1ul<<CCAP_CTL_VPRST_Pos)     /*!< CCAP CTL setting for capture reset  \hideinitializer */
37 #define CCAP_CTL_MY8_MY4    (0ul<<CCAP_CTL_MY8_MY4_Pos)   /*!< CCAP CTL setting for 4-bit data I/O interface with Mono \hideinitializer */
38 #define CCAP_CTL_MY8_MY8    (1ul<<CCAP_CTL_MY8_MY4_Pos)   /*!< CCAP CTL setting for 8-bit data I/O interface with Mono  \hideinitializer */
39 
40 /*---------------------------------------------------------------------------------------------------------*/
41 /* PAR constant definitions                                                                                */
42 /*---------------------------------------------------------------------------------------------------------*/
43 #define CCAP_PAR_INFMT_YUV422 (0ul<<CCAP_PAR_INFMT_Pos)         /*!< CCAP PAR setting for Sensor Input Data YUV422 Format   \hideinitializer */
44 #define CCAP_PAR_INFMT_RGB565 (1ul<<CCAP_PAR_INFMT_Pos)         /*!< CCAP PAR setting for Sensor Input Data RGB565 Format   \hideinitializer */
45 
46 #define CCAP_PAR_SENTYPE_CCIR601  (0ul<<CCAP_PAR_SENTYPE_Pos)   /*!< CCAP PAR setting for Sensor Input CCIR601 Type   \hideinitializer */
47 #define CCAP_PAR_SENTYPE_CCIR656  (1ul<<CCAP_PAR_SENTYPE_Pos)   /*!< CCAP PAR setting for Sensor Input CCIR656 Type   \hideinitializer */
48 
49 #define CCAP_PAR_INDATORD_YUYV   (0x0ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, YUYV  \hideinitializer */
50 #define CCAP_PAR_INDATORD_YVYU   (0x1ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, YVYU  \hideinitializer */
51 #define CCAP_PAR_INDATORD_UYVY   (0x2ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, UYVY  \hideinitializer */
52 #define CCAP_PAR_INDATORD_VYUY   (0x3ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, VYUY  \hideinitializer */
53 
54 #define CCAP_PAR_INDATORD_RGGB   (0x0ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, 0byte: R[0:4] G[5:8], 1byte G[0:2] R[3:8]  \hideinitializer */
55 #define CCAP_PAR_INDATORD_BGGR   (0x1ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, 0byte: b[0:4] G[5:8], 1byte G[0:2] R[3:8]  \hideinitializer */
56 #define CCAP_PAR_INDATORD_GBRG   (0x2ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, 0byte: G[0:3] G[4:8], 1byte G[0:4] G[5:8]  \hideinitializer */
57 #define CCAP_PAR_INDATORD_GRBG   (0x3ul<<CCAP_PAR_INDATORD_Pos)       /*!< CCAP PAR setting for Sensor Input Data Order, 0byte: G[0:3] G[4:8], 1byte G[0:4] G[5:8]  \hideinitializer */
58 
59 #define CCAP_PAR_OUTFMT_YUV422 (0x0ul<<CCAP_PAR_OUTFMT_Pos)     /*!< CCAP PAR setting for Image Data YUV422 Format Output to System Memory  \hideinitializer */
60 #define CCAP_PAR_OUTFMT_ONLY_Y (0x1ul<<CCAP_PAR_OUTFMT_Pos)     /*!< CCAP PAR setting for Image Data ONLY_Y Format Output to System Memory  \hideinitializer */
61 #define CCAP_PAR_OUTFMT_RGB555 (0x2ul<<CCAP_PAR_OUTFMT_Pos)     /*!< CCAP PAR setting for Image Data RGB555 Format Output to System Memory  \hideinitializer */
62 #define CCAP_PAR_OUTFMT_RGB565 (0x3ul<<CCAP_PAR_OUTFMT_Pos)     /*!< CCAP PAR setting for Image Data RGB565 Format Output to System Memory  \hideinitializer */
63 
64 #define CCAP_PAR_VSP_LOW      (0x0ul<<CCAP_PAR_VSP_Pos)         /*!< CCAP PAR setting for Sensor Vsync Polarity  \hideinitializer */
65 #define CCAP_PAR_VSP_HIGH     (0x1ul<<CCAP_PAR_VSP_Pos)         /*!< CCAP PAR setting for Sensor Vsync Polarity  \hideinitializer */
66 #define CCAP_PAR_HSP_LOW      (0x0ul<<CCAP_PAR_HSP_Pos)         /*!< CCAP PAR setting for Sensor Hsync Polarity  \hideinitializer */
67 #define CCAP_PAR_HSP_HIGH     (0x1ul<<CCAP_PAR_HSP_Pos)         /*!< CCAP PAR setting for Sensor Hsync Polarity  \hideinitializer */
68 #define CCAP_PAR_PCLKP_LOW    (0x0ul<<CCAP_PAR_PCLKP_Pos)       /*!< CCAP PAR setting for Sensor Pixel Clock Polarity  \hideinitializer */
69 #define CCAP_PAR_PCLKP_HIGH   (0x1ul<<CCAP_PAR_PCLKP_Pos)       /*!< CCAP PAR setting for Sensor Pixel Clock Polarity  \hideinitializer */
70 
71 /*---------------------------------------------------------------------------------------------------------*/
72 /* INT constant definitions                                                                                */
73 /*---------------------------------------------------------------------------------------------------------*/
74 #define CCAP_INT_VIEN_ENABLE        (0x1ul<<CCAP_INT_VIEN_Pos)        /*!< VININT setting for Video Frame End Interrupt enable  \hideinitializer */
75 #define CCAP_INT_MEIEN_ENABLE       (0x1ul<<CCAP_INT_MEIEN_Pos)       /*!< VININT setting for Bus Master Transfer Error Interrupt enable  \hideinitializer */
76 #define CCAP_INT_ADDRMIEN_ENABLE    (0x1ul<<CCAP_INT_ADDRMIEN_Pos)    /*!< VININT setting for Memory Address Match Interrupt enable  \hideinitializer */
77 
78 /*---------------------------------------------------------------------------------------------------------*/
79 /* CCAP Define Error Code                                                                                  */
80 /*---------------------------------------------------------------------------------------------------------*/
81 #define CCAP_OK             ( 0L)   /*!< CCAP operation OK */
82 #define CCAP_ERR_FAIL       (-1L)   /*!< CCAP operation failed */
83 #define CCAP_ERR_TIMEOUT    (-2L)   /*!< CCAP operation abort due to timeout error */
84 
85 
86 /*@}*/ /* end of group CCAP_EXPORTED_CONSTANTS */
87 
88 /** @addtogroup CCAP_EXPORTED_FUNCTIONS CCAP Exported Functions
89   @{
90 */
91 
92 /**
93  * @brief     Is CCAP module stopped
94  *
95  * @param     None
96  *
97  * @retval    0   CCAP module is enabled
98  * @retval    1   CCAP module is disabled(stopped)
99  *
100  * @details   Check Camera Capture Interface module Enable or Disable(stopped)
101  *  \hideinitializer
102  */
103 #define CCAP_IS_STOPPED()  ((CCAP->CTL & CCAP_CTL_CCAPEN_Msk)?0:1)
104 
105 /**
106  * @brief     Clear CCAP flag
107  *
108  * @param[in] u32IntMask interrupt flags settings. It could be
109  *                   - \ref CCAP_INT_VINTF_Msk
110  *                   - \ref CCAP_INT_MEINTF_Msk
111  *                   - \ref CCAP_INT_ADDRMINTF_Msk
112  *                   - \ref CCAP_INT_MDINTF_Msk
113  *
114  * @return    None
115  *
116  * @details   Clear Camera Capture Interface interrupt flag
117  *  \hideinitializer
118  */
119 #define CCAP_CLR_INT_FLAG(u32IntMask) (CCAP->INT |= (u32IntMask))
120 
121 /**
122  * @brief     Get CCAP Interrupt status
123  *
124  * @param     None
125  *
126  * @return    CCAP Interrupt Register
127  *
128  * @details   Get Camera Capture Interface interrupt status.
129  * \hideinitializer
130  */
131 #define CCAP_GET_INT_STS() (CCAP->INT)
132 
133 
134 void CCAP_Open(uint32_t u32InFormat, uint32_t u32OutFormat);
135 void CCAP_SetCroppingWindow(uint32_t u32VStart, uint32_t u32HStart, uint32_t u32Height, uint32_t u32Width);
136 void CCAP_SetPacketBuf(uint32_t u32Address);
137 void CCAP_Close(void);
138 void CCAP_EnableInt(uint32_t u32IntMask);
139 void CCAP_DisableInt(uint32_t u32IntMask);
140 void CCAP_Start(void);
141 int32_t CCAP_Stop(uint32_t u32FrameComplete);
142 void CCAP_SetPacketScaling(uint32_t u32VNumerator, uint32_t u32VDenominator, uint32_t u32HNumerator, uint32_t u32HDenominator);
143 void CCAP_SetPacketStride(uint32_t u32Stride);
144 void CCAP_EnableMono(uint32_t u32Interface);
145 void CCAP_DisableMono(void);
146 void CCAP_EnableLumaYOne(uint32_t u32th);
147 void CCAP_DisableLumaYOne(void);
148 
149 /*@}*/ /* end of group CCAP_EXPORTED_FUNCTIONS */
150 
151 /*@}*/ /* end of group CCAP_Driver */
152 
153 /*@}*/ /* end of group Standard_Driver */
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif //__CCAP_H__
160