nu_cap.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /**************************************************************************//**
  2. * @file cap.h
  3. * @version V1.00
  4. * $Revision: 2 $
  5. * $Date: 15/06/12 8:48a $
  6. * @brief N9H30 CAP driver header file
  7. *
  8. * @note
  9. * SPDX-License-Identifier: Apache-2.0
  10. * Copyright (C) 2015 Nuvoton Technology Corp. All rights reserved.
  11. *****************************************************************************/
  12. #ifndef __NU_CAP_H__
  13. #define __NU_CAP_H__
  14. // #include header file
  15. #ifdef __cplusplus
  16. extern "C"
  17. {
  18. #endif
  19. /** @addtogroup N9H30_Device_Driver N9H30 Device Driver
  20. @{
  21. */
  22. /** @addtogroup N9H30_CAP_Driver CAP Driver
  23. @{
  24. */
  25. /** @addtogroup N9H30_CAP_EXPORTED_CONSTANTS CAP Exported Constants
  26. @{
  27. */
  28. /* Define data type (struct, union? */
  29. // #define Constant
  30. #include "N9H30.h"
  31. #include "nu_sys.h"
  32. /*---------------------------------------------------------------------------------------------------------*/
  33. /* CAP_CTL constant definitions */
  34. /*---------------------------------------------------------------------------------------------------------*/
  35. #define CAPEN BIT0 /*!< Interrupt enable for VPE operations */
  36. #define ADDRSW BIT3 /*!< Packet Buffer Address Switch */
  37. #define PLNEN BIT5 /*!< Planar Output Enable */
  38. #define PKTEN BIT6 /*!< Packet Output Enable */
  39. #define SHUTTER BIT16 /*!< Image Capture Interface Automatically Disable The Capture Inteface After A Frame Had Been Captured */
  40. #define UPDATE BIT20 /*!< Update Register At New Frame */
  41. #define VPRST BIT24 /*!< Capture Interface Reset */
  42. /*---------------------------------------------------------------------------------------------------------*/
  43. /* CAP_PAR constant definitions */
  44. /*---------------------------------------------------------------------------------------------------------*/
  45. #define INFMT BIT0 /*!< Sensor Input Data Format */
  46. #define SENTYPE BIT1 /*!< Sensor Input Type */
  47. #define INDATORD (BIT2|BIT3) /*!< Sensor Input Data Order */
  48. #define OUTFMT (BIT4|BIT5) /*!< Image Data Format Output To System Memory */
  49. #define RANGE BIT6 /*!< Scale Input YUV CCIR601 Color Range To Full Range */
  50. #define PLNFMT BIT7 /*!< Planar Output YUV Format */
  51. #define PCLKP BIT8 /*!< Sensor Pixel Clock Polarity */
  52. #define HSP BIT9 /*!< Sensor Hsync Polarity */
  53. #define VSP BIT10 /*!< Sensor Vsync Polarity */
  54. #define COLORCTL (BIT11|BIT12) /*!< Special COLORCTL Processing */
  55. #define FBB BIT18 /*!< Field By Blank */
  56. /*---------------------------------------------------------------------------------------------------------*/
  57. /* CAP_INT constant definitions */
  58. /*---------------------------------------------------------------------------------------------------------*/
  59. #define MDIEN BIT20 /*!< Motion Detection Output Finish Interrupt Enable */
  60. #define ADDRMIEN BIT19 /*!< Address Match Interrupt Enable */
  61. #define MEIEN BIT17 /*!< System Memory Error Interrupt Enable */
  62. #define VIEN BIT16 /*!< Video Frame End Interrupt Enable */
  63. #define MDINTF BIT4 /*!< Motion Detection Output Finish Interrupt */
  64. #define ADDRMINTF BIT3 /*!< Memory Address Match Interrupt */
  65. #define MEINTF BIT1 /*!< Bus Master Transfer Error Interrupt */
  66. #define VINTF BIT0 /*!< Video Frame End Interrupt */
  67. /*---------------------------------------------------------------------------------------------------------*/
  68. /* CAP_MD constant definitions */
  69. /*---------------------------------------------------------------------------------------------------------*/
  70. #define MDEN BIT0 /*!< Motion Detection Enable */
  71. #define MDBS BIT8 /*!< Motion Detection Block Size */
  72. #define MDSM BIT9 /*!< Motion Detection Save Mode */
  73. #define MDDF (BIT10|BIT11) /*!< Motion Detection Detect Frequency */
  74. #define MDTHR (BIT16|BIT17|BIT18|BIT19|BIT20) /*!< Motion Detection Differential Threshold */
  75. /*---------------------------------------------------------------------------------------------------------*/
  76. /* CAP_CWSP constant definitions */
  77. /*---------------------------------------------------------------------------------------------------------*/
  78. #define CWSADDRH (0xFFF<<0) /*!<Cropping Window Horizontal Starting Address */
  79. #define CWSADDRV (0xFFF<<16) /*!<Cropping Window Vertical Starting Address */
  80. /*---------------------------------------------------------------------------------------------------------*/
  81. /* CAP_CWS constant definitions */
  82. /*---------------------------------------------------------------------------------------------------------*/
  83. #define CWW (0xFFF<<0) /*!< Cropping Window Horizontal Starting Address */
  84. #define CWH (0xFFF<<16) /*!< Cropping Window Vertical Starting Address */
  85. /*---------------------------------------------------------------------------------------------------------*/
  86. /* CAP_PKTSL constant definitions */
  87. /*---------------------------------------------------------------------------------------------------------*/
  88. #define PKTSHML (0xFFul<< 0) /*!< Packet Scaling Horizontal Factor M (Lower 8-Bit) */
  89. #define PKTSHNL (0xFFul<< 8) /*!< Packet Scaling Horizontal Factor N (Lower 8-Bit) */
  90. #define PKTSVML (0xFFul<<16) /*!< Packet Scaling Vertical Factor M (Lower 8-Bit) */
  91. #define PKTSVNL (0xFFul<<24) /*!< Packet Scaling Vertical Factor N (Lower 8-Bit) */
  92. /*---------------------------------------------------------------------------------------------------------*/
  93. /* CAP_PLNSL constant definitions */
  94. /*---------------------------------------------------------------------------------------------------------*/
  95. #define PLNSHML (0xFFul<< 0) /*!< Planar Scaling Horizontal Factor M (Lower 8-Bit) */
  96. #define PLNSHNL (0xFFul<< 8) /*!< Planar Scaling Horizontal Factor N (Lower 8-Bit) */
  97. #define PLNSVML (0xFFul<<16) /*!< Planar Scaling Vertical Factor M (Lower 8-Bit) */
  98. #define PLNSVNL (0xFFul<<24) /*!< Planar Scaling Vertical Factor N (Lower 8-Bit) */
  99. /*---------------------------------------------------------------------------------------------------------*/
  100. /* CAP_PKTSM constant definitions */
  101. /*---------------------------------------------------------------------------------------------------------*/
  102. #define PKTSHMH (0xFFul<< 0) /*!< Packet Scaling Horizontal Factor M (Higher 8-Bit) */
  103. #define PKTSHNH (0xFFul<< 8) /*!< Packet Scaling Horizontal Factor N (Higher 8-Bit) */
  104. #define PKTSVMH (0xFFul<<16) /*!< Packet Scaling Vertical Factor M (Higher 8-Bit) */
  105. #define PKTSVNH (0xFFul<<24) /*!< Packet Scaling Vertical Factor N (Higher 8-Bit) */
  106. /*---------------------------------------------------------------------------------------------------------*/
  107. /* CAP_PLNSM constant definitions */
  108. /*---------------------------------------------------------------------------------------------------------*/
  109. #define PLNSHMH (0xFFul<< 0) /*!< Planar Scaling Horizontal Factor M (Higher 8-Bit) */
  110. #define PLNSHNH (0xFFul<< 8) /*!< Planar Scaling Horizontal Factor N (Higher 8-Bit) */
  111. #define PLNSVMH (0xFFul<<16) /*!< Planar Scaling Vertical Factor M (Higher 8-Bit) */
  112. #define PLNSVNH (0xFFul<<24) /*!< Planar Scaling Vertical Factor N (Higher 8-Bit) */
  113. /*---------------------------------------------------------------------------------------------------------*/
  114. /* CAP_FRCTL constant definitions */
  115. /*---------------------------------------------------------------------------------------------------------*/
  116. #define FRM (0x3Ful<<0) /*!< Scaling Frame Rate Factor M */
  117. #define FRN (0x3Ful<<8) /*!< Scaling Frame Rate Factor N */
  118. /*---------------------------------------------------------------------------------------------------------*/
  119. /* CAP_STRIDE constant definitions */
  120. /*---------------------------------------------------------------------------------------------------------*/
  121. #define PKTSTRIDE (0x3FFFul<<0) /*!< Packet Frame Output Pixel Stride Width */
  122. #define PLNSTRIDE (0x3FFFul<<16) /*!< Planar Frame Output Pixel Stride Width */
  123. #define VIN_ERR_ID 0xFFFF1000 /*!< CAP library ID */
  124. //Error message
  125. // E_CAP_INVALID_INT Invalid interrupt
  126. // E_CAP_INVALID_BUF Invalid buffer
  127. // E_CAP_INVALID_PIPE Invalid pipe
  128. // E_CAP_INVALID_COLOR_MODE Invalid color mode
  129. #define E_CAP_INVALID_INT (VIN_ERR_ID | 0x01) /*!< CAP invalid interrupt */
  130. #define E_CAP_INVALID_BUF (VIN_ERR_ID | 0x02) /*!< CAP invalid buffer */
  131. #define E_CAP_INVALID_PIPE (VIN_ERR_ID | 0x03) /*!< CAP invalid pipe */
  132. #define E_CAP_INVALID_COLOR_MODE (VIN_ERR_ID | 0x04) /*!< CAP invalid color mode */
  133. #define E_CAP_WRONG_COLOR_PARAMETER (VIN_ERR_ID | 0x05) /*!< CAP worng color parameter */
  134. /// @cond HIDDEN_SYMBOLS
  135. typedef void (*PFN_CAP_CALLBACK)(UINT8 u8PacketBufID, UINT8 u8PlanarBufID, UINT8 u8FrameRate);
  136. /// @endcond HIDDEN_SYMBOLS
  137. /** \brief Structure type of E_CAP_INT_TYPE
  138. */
  139. typedef enum
  140. {
  141. eCAP_MDINTF = 0x100000, /*!< Motion detection output finish interrupt */
  142. eCAP_ADDRMINTF = 0x80000, /*!< Memory address match interrupt */
  143. eCAP_MEINTF = 0x20000, /*!< Bus master transfer error interrupt */
  144. eCAP_VINTF = 0x10000 /*!< Video frame end interrupt */
  145. } E_CAP_INT_TYPE;
  146. /** \brief Structure type of E_CAP_PIPE
  147. */
  148. typedef enum
  149. {
  150. eCAP_BOTH_PIPE_DISABLE = 0, /*!< Planar output disable and planar output disable */
  151. eCAP_PLANAR = 1, /*!< Planar output enable */
  152. eCAP_PACKET = 2, /*!< Packet output enable */
  153. eCAP_BOTH_PIPE_ENABLE = 3 /*!< Planar output enable and planar output enable */
  154. } E_CAP_PIPE;
  155. /** \brief Structure type of E_CAP_BUFFER
  156. */
  157. typedef enum
  158. {
  159. eCAP_BUF0 = 0, /*!< System memory packet/planar base Address 0/Y */
  160. eCAP_BUF1, /*!< System memory packet/planar base Address 1/U */
  161. eCAP_BUF2 /*!< System memory packet/planar base Address 2/V */
  162. } E_CAP_BUFFER;
  163. /** \brief Structure type of E_CAP_ORDER
  164. */
  165. typedef enum
  166. {
  167. eCAP_IN_YUYV = 0, /*!< Sensor input data (Byte 0 1 2 3) is Y0 U0 Y1 V0 */
  168. eCAP_IN_YVYU, /*!< Sensor input data (Byte 0 1 2 3) is Y0 V0 Y1 U0 */
  169. eCAP_IN_UYVY, /*!< Sensor input data (Byte 0 1 2 3) is U0 Y0 V0 Y1 */
  170. eCAP_IN_VYUY, /*!< Sensor input data (Byte 0 1 2 3) is V0 Y0 U0 Y1 */
  171. } E_CAP_ORDER;
  172. /** \brief Structure type of E_CAP_IN_FORMAT
  173. */
  174. typedef enum
  175. {
  176. eCAP_IN_YUV422 = 0, /*!< Sensor input data format is YUV222 */
  177. eCAP_IN_RGB565 /*!< Sensor input data format is RGB565 */
  178. } E_CAP_IN_FORMAT;
  179. /** \brief Structure type of E_CAP_OUT_FORMAT
  180. */
  181. typedef enum
  182. {
  183. eCAP_OUT_YUV422 = 0, /*!< Image data format is YUV422 */
  184. eCAP_OUT_ONLY_Y, /*!< Image data format is Only output Y */
  185. eCAP_OUT_RGB555, /*!< Image data format is RGB555 */
  186. eCAP_OUT_RGB565 /*!< Image data format is RGB565 */
  187. } E_CAP_OUT_FORMAT;
  188. /** \brief Structure type of E_CAP_PLANAR_FORMAT
  189. */
  190. typedef enum
  191. {
  192. eCAP_PLANAR_YUV422 = 0, /*!< Planar output YUV format is YUV422 */
  193. eCAP_PLANAR_YUV420, /*!< Planar output YUV format is YUV420 */
  194. } E_CAP_PLANAR_FORMAT;
  195. /** \brief Structure type of E_CAP_TYPE
  196. */
  197. typedef enum
  198. {
  199. eCAP_TYPE_CCIR601 = 0, /*!< Sensor input type is CCIR601 */
  200. eCAP_TYPE_CCIR656 /*!< Sensor input type is CCIR656 */
  201. } E_CAP_TYPE;
  202. /** \brief Structure type of E_CAP_SNR_SRC
  203. */
  204. typedef enum
  205. {
  206. eCAP_SNR_APLL = 2, /*!< CAP clock source is APLL */
  207. eCAP_SNR_UPLL = 3 /*!< CAP clock source is UPLL */
  208. } E_CAP_SNR_SRC;
  209. /** \brief Structure type of E_CAP_CEF
  210. */
  211. typedef enum
  212. {
  213. eCAP_CEF_NORMAL = 0, /*!< Image Processing is normal color */
  214. eCAP_CEF_SEPIA = 1, /*!< Image Processing is sepia effect */
  215. eCAP_CEF_NEGATIVE = 2, /*!< Image Processing is negative picture. */
  216. eCAP_CEF_POSTERIZE = 3 /*!< Image Processing is posterize image */
  217. } E_CAP_CEF;
  218. /*@}*/ /* end of group N9H30_CAP_EXPORTED_CONSTANTS */
  219. /** @addtogroup N9H30_CAP_EXPORTED_FUNCTIONS CAP Exported Functions
  220. @{
  221. */
  222. /// @cond HIDDEN_SYMBOLS
  223. typedef struct
  224. {
  225. void (*Init)(BOOL bIsEnableSnrClock, E_CAP_SNR_SRC eSnrSrc, UINT32 u32SensorFreqKHz);
  226. INT32(*Open)(UINT32 u32SensorFreqKHz);
  227. void (*Close)(void);
  228. void (*SetPipeEnable)(BOOL bEngEnable, E_CAP_PIPE ePipeEnable);
  229. void (*SetPlanarFormat)(E_CAP_PLANAR_FORMAT ePlanarFmt);
  230. void (*SetCropWinSize)(UINT32 u32height, UINT32 u32width);
  231. void (*SetCropWinStartAddr)(UINT32 u32VerticalStart, UINT32 u32HorizontalStart);
  232. void (*SetStride)(UINT32 u16packetstride, UINT32 u32planarstride);
  233. void (*GetStride)(PUINT32 pu32PacketStride, PUINT32 pu32PlanarStride);
  234. INT32(*EnableInt)(E_CAP_INT_TYPE eIntType);
  235. INT32(*DisableInt)(E_CAP_INT_TYPE eIntType);
  236. INT32(*InstallCallback)(E_CAP_INT_TYPE eIntType, PFN_CAP_CALLBACK pfnCallback, PFN_CAP_CALLBACK *pfnOldCallback);
  237. INT32(*SetBaseStartAddress)(E_CAP_PIPE ePipe, E_CAP_BUFFER eBuf, UINT32 u32BaseStartAddr);
  238. void (*SetOperationMode)(BOOL bIsOneSutterMode);
  239. BOOL (*GetOperationMode)(void);
  240. void (*SetPacketFrameBufferControl)(BOOL bFrameSwitch);
  241. void (*SetSensorPolarity)(BOOL bVsync, BOOL bHsync, BOOL bPixelClk);
  242. INT32(*SetColorEffectParameter)(UINT8 u8YComp, UINT8 u8UComp, UINT8 u8VComp);
  243. void (*SetDataFormatAndOrder)(E_CAP_ORDER eInputOrder, E_CAP_IN_FORMAT eInputFormat, E_CAP_OUT_FORMAT eOutputFormat);
  244. void (*SetMotionDet)(BOOL bEnable, BOOL bBlockSize, BOOL bSaveMode);
  245. void (*SetMotionDetEx)(UINT32 u32DetFreq, UINT32 u32Threshold, UINT32 u32OutBuffer, UINT32 u32LumBuffer);
  246. void (*SetStandardCCIR656)(BOOL);
  247. void (*SetShadowRegister)(void);
  248. } CAPDEV_T;
  249. /// @endcond HIDDEN_SYMBOLS
  250. /*@}*/ /* end of group N9H30_CAP_EXPORTED_FUNCTIONS */
  251. /*@}*/ /* end of group N9H30_CAP_Driver */
  252. /*@}*/ /* end of group N9H30_Device_Driver */
  253. #ifdef __cplusplus
  254. }
  255. #endif
  256. #endif