fsl_flexio_camera.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_FLEXIO_CAMERA_H_
  35. #define _FSL_FLEXIO_CAMERA_H_
  36. #include "fsl_common.h"
  37. #include "fsl_flexio.h"
  38. /*!
  39. * @addtogroup flexio_camera
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. /*! @brief FlexIO Camera driver version 2.1.2. */
  48. #define FSL_FLEXIO_CAMERA_DRIVER_VERSION (MAKE_VERSION(2, 1, 2))
  49. /*@}*/
  50. /*! @brief Define the Camera CPI interface is constantly 8-bit width. */
  51. #define FLEXIO_CAMERA_PARALLEL_DATA_WIDTH (8U)
  52. /*! @brief Error codes for the Camera driver. */
  53. enum _flexio_camera_status
  54. {
  55. kStatus_FLEXIO_CAMERA_RxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 0), /*!< Receiver is busy. */
  56. kStatus_FLEXIO_CAMERA_RxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 1), /*!< Camera receiver is idle. */
  57. };
  58. /*! @brief Define FlexIO Camera status mask. */
  59. enum _flexio_camera_status_flags
  60. {
  61. kFLEXIO_CAMERA_RxDataRegFullFlag = 0x1U, /*!< Receive buffer full flag. */
  62. kFLEXIO_CAMERA_RxErrorFlag = 0x2U, /*!< Receive buffer error flag. */
  63. };
  64. /*!
  65. * @brief Define structure of configuring the FlexIO Camera device.
  66. */
  67. typedef struct _flexio_camera_type
  68. {
  69. FLEXIO_Type *flexioBase; /*!< FlexIO module base address. */
  70. uint32_t datPinStartIdx; /*!< First data pin (D0) index for flexio_camera.
  71. Then the successive following FLEXIO_CAMERA_DATA_WIDTH-1 pins
  72. are used as D1-D7.*/
  73. uint32_t pclkPinIdx; /*!< Pixel clock pin (PCLK) index for flexio_camera. */
  74. uint32_t hrefPinIdx; /*!< Horizontal sync pin (HREF) index for flexio_camera. */
  75. uint32_t shifterStartIdx; /*!< First shifter index used for flexio_camera data FIFO. */
  76. uint32_t shifterCount; /*!< The count of shifters that are used as flexio_camera data FIFO. */
  77. uint32_t timerIdx; /*!< Timer index used for flexio_camera in FlexIO. */
  78. } FLEXIO_CAMERA_Type;
  79. /*! @brief Define FlexIO Camera user configuration structure. */
  80. typedef struct _flexio_camera_config
  81. {
  82. bool enablecamera; /*!< Enable/disable FlexIO Camera TX & RX. */
  83. bool enableInDoze; /*!< Enable/disable FlexIO operation in doze mode*/
  84. bool enableInDebug; /*!< Enable/disable FlexIO operation in debug mode*/
  85. bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers,
  86. fast access requires the FlexIO clock to be at least
  87. twice the frequency of the bus clock. */
  88. } flexio_camera_config_t;
  89. /*! @brief Define FlexIO Camera transfer structure. */
  90. typedef struct _flexio_camera_transfer
  91. {
  92. uint32_t dataAddress; /*!< Transfer buffer*/
  93. uint32_t dataNum; /*!< Transfer num*/
  94. } flexio_camera_transfer_t;
  95. /*******************************************************************************
  96. * API
  97. ******************************************************************************/
  98. #if defined(__cplusplus)
  99. extern "C" {
  100. #endif /*_cplusplus*/
  101. /*!
  102. * @name Initialization and configuration
  103. * @{
  104. */
  105. /*!
  106. * @brief Ungates the FlexIO clock, resets the FlexIO module, and configures the FlexIO Camera.
  107. *
  108. * @param base Pointer to FLEXIO_CAMERA_Type structure
  109. * @param config Pointer to flexio_camera_config_t structure
  110. */
  111. void FLEXIO_CAMERA_Init(FLEXIO_CAMERA_Type *base, const flexio_camera_config_t *config);
  112. /*!
  113. * @brief Resets the FLEXIO_CAMERA shifer and timer config.
  114. *
  115. * @note After calling this API, call FLEXO_CAMERA_Init to use the FlexIO Camera module.
  116. *
  117. * @param base Pointer to FLEXIO_CAMERA_Type structure
  118. */
  119. void FLEXIO_CAMERA_Deinit(FLEXIO_CAMERA_Type *base);
  120. /*!
  121. * @brief Gets the default configuration to configure the FlexIO Camera. The configuration
  122. * can be used directly for calling the FLEXIO_CAMERA_Init().
  123. * Example:
  124. @code
  125. flexio_camera_config_t config;
  126. FLEXIO_CAMERA_GetDefaultConfig(&userConfig);
  127. @endcode
  128. * @param config Pointer to the flexio_camera_config_t structure
  129. */
  130. void FLEXIO_CAMERA_GetDefaultConfig(flexio_camera_config_t *config);
  131. /*!
  132. * @brief Enables/disables the FlexIO Camera module operation.
  133. *
  134. * @param base Pointer to the FLEXIO_CAMERA_Type
  135. * @param enable True to enable, false does not have any effect.
  136. */
  137. static inline void FLEXIO_CAMERA_Enable(FLEXIO_CAMERA_Type *base, bool enable)
  138. {
  139. if (enable)
  140. {
  141. base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
  142. }
  143. }
  144. /*! @} */
  145. /*!
  146. * @name Status
  147. * @{
  148. */
  149. /*!
  150. * @brief Gets the FlexIO Camera status flags.
  151. *
  152. * @param base Pointer to FLEXIO_CAMERA_Type structure
  153. * @return FlexIO shifter status flags
  154. * @arg FLEXIO_SHIFTSTAT_SSF_MASK
  155. * @arg 0
  156. */
  157. uint32_t FLEXIO_CAMERA_GetStatusFlags(FLEXIO_CAMERA_Type *base);
  158. /*!
  159. * @brief Clears the receive buffer full flag manually.
  160. *
  161. * @param base Pointer to the device.
  162. * @param mask status flag
  163. * The parameter can be any combination of the following values:
  164. * @arg kFLEXIO_CAMERA_RxDataRegFullFlag
  165. * @arg kFLEXIO_CAMERA_RxErrorFlag
  166. */
  167. void FLEXIO_CAMERA_ClearStatusFlags(FLEXIO_CAMERA_Type *base, uint32_t mask);
  168. /* @} */
  169. /*!
  170. * @name Interrupts
  171. * @{
  172. */
  173. /*!
  174. * @brief Switches on the interrupt for receive buffer full event.
  175. *
  176. * @param base Pointer to the device.
  177. */
  178. void FLEXIO_CAMERA_EnableInterrupt(FLEXIO_CAMERA_Type *base);
  179. /*!
  180. * @brief Switches off the interrupt for receive buffer full event.
  181. *
  182. * @param base Pointer to the device.
  183. *
  184. */
  185. void FLEXIO_CAMERA_DisableInterrupt(FLEXIO_CAMERA_Type *base);
  186. /*! @} */
  187. /*!
  188. * @name DMA support
  189. * @{
  190. */
  191. /*!
  192. * @brief Enables/disables the FlexIO Camera receive DMA.
  193. *
  194. * @param base Pointer to FLEXIO_CAMERA_Type structure
  195. * @param enable True to enable, false to disable.
  196. *
  197. * The FlexIO Camera mode can't work without the DMA or eDMA support,
  198. * Usually, it needs at least two DMA or eDMA channels, one for transferring data from
  199. * Camera, such as 0V7670 to FlexIO buffer, another is for transferring data from FlexIO
  200. * buffer to LCD.
  201. *
  202. */
  203. static inline void FLEXIO_CAMERA_EnableRxDMA(FLEXIO_CAMERA_Type *base, bool enable)
  204. {
  205. FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1 << base->shifterStartIdx, enable);
  206. }
  207. /*!
  208. * @brief Gets the data from the receive buffer.
  209. *
  210. * @param base Pointer to the device.
  211. * @return data Pointer to the buffer that keeps the data with count of base->shifterCount .
  212. */
  213. static inline uint32_t FLEXIO_CAMERA_GetRxBufferAddress(FLEXIO_CAMERA_Type *base)
  214. {
  215. return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBuffer, base->shifterStartIdx);
  216. }
  217. /*! @} */
  218. #if defined(__cplusplus)
  219. }
  220. #endif /*_cplusplus*/
  221. /*@}*/
  222. #endif /*_FSL_FLEXIO_CAMERA_H_*/