fsl_flexio_camera.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_FLEXIO_CAMERA_H_
  9. #define _FSL_FLEXIO_CAMERA_H_
  10. #include "fsl_common.h"
  11. #include "fsl_flexio.h"
  12. /*!
  13. * @addtogroup flexio_camera
  14. * @{
  15. */
  16. /*******************************************************************************
  17. * Definitions
  18. ******************************************************************************/
  19. /*! @name Driver version */
  20. /*@{*/
  21. /*! @brief FlexIO Camera driver version 2.1.3. */
  22. #define FSL_FLEXIO_CAMERA_DRIVER_VERSION (MAKE_VERSION(2, 1, 3))
  23. /*@}*/
  24. /*! @brief Define the Camera CPI interface is constantly 8-bit width. */
  25. #define FLEXIO_CAMERA_PARALLEL_DATA_WIDTH (8U)
  26. /*! @brief Error codes for the Camera driver. */
  27. enum
  28. {
  29. kStatus_FLEXIO_CAMERA_RxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 0), /*!< Receiver is busy. */
  30. kStatus_FLEXIO_CAMERA_RxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_CAMERA, 1), /*!< Camera receiver is idle. */
  31. };
  32. /*! @brief Define FlexIO Camera status mask. */
  33. enum _flexio_camera_status_flags
  34. {
  35. kFLEXIO_CAMERA_RxDataRegFullFlag = 0x1U, /*!< Receive buffer full flag. */
  36. kFLEXIO_CAMERA_RxErrorFlag = 0x2U, /*!< Receive buffer error flag. */
  37. };
  38. /*!
  39. * @brief Define structure of configuring the FlexIO Camera device.
  40. */
  41. typedef struct _flexio_camera_type
  42. {
  43. FLEXIO_Type *flexioBase; /*!< FlexIO module base address. */
  44. uint32_t datPinStartIdx; /*!< First data pin (D0) index for flexio_camera.
  45. Then the successive following FLEXIO_CAMERA_DATA_WIDTH-1 pins
  46. are used as D1-D7.*/
  47. uint32_t pclkPinIdx; /*!< Pixel clock pin (PCLK) index for flexio_camera. */
  48. uint32_t hrefPinIdx; /*!< Horizontal sync pin (HREF) index for flexio_camera. */
  49. uint32_t shifterStartIdx; /*!< First shifter index used for flexio_camera data FIFO. */
  50. uint32_t shifterCount; /*!< The count of shifters that are used as flexio_camera data FIFO. */
  51. uint32_t timerIdx; /*!< Timer index used for flexio_camera in FlexIO. */
  52. } FLEXIO_CAMERA_Type;
  53. /*! @brief Define FlexIO Camera user configuration structure. */
  54. typedef struct _flexio_camera_config
  55. {
  56. bool enablecamera; /*!< Enable/disable FlexIO Camera TX & RX. */
  57. bool enableInDoze; /*!< Enable/disable FlexIO operation in doze mode*/
  58. bool enableInDebug; /*!< Enable/disable FlexIO operation in debug mode*/
  59. bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers,
  60. fast access requires the FlexIO clock to be at least
  61. twice the frequency of the bus clock. */
  62. } flexio_camera_config_t;
  63. /*! @brief Define FlexIO Camera transfer structure. */
  64. typedef struct _flexio_camera_transfer
  65. {
  66. uint32_t dataAddress; /*!< Transfer buffer*/
  67. uint32_t dataNum; /*!< Transfer num*/
  68. } flexio_camera_transfer_t;
  69. /*******************************************************************************
  70. * API
  71. ******************************************************************************/
  72. #if defined(__cplusplus)
  73. extern "C" {
  74. #endif /*_cplusplus*/
  75. /*!
  76. * @name Initialization and configuration
  77. * @{
  78. */
  79. /*!
  80. * @brief Ungates the FlexIO clock, resets the FlexIO module, and configures the FlexIO Camera.
  81. *
  82. * @param base Pointer to FLEXIO_CAMERA_Type structure
  83. * @param config Pointer to flexio_camera_config_t structure
  84. */
  85. void FLEXIO_CAMERA_Init(FLEXIO_CAMERA_Type *base, const flexio_camera_config_t *config);
  86. /*!
  87. * @brief Resets the FLEXIO_CAMERA shifer and timer config.
  88. *
  89. * @note After calling this API, call FLEXO_CAMERA_Init to use the FlexIO Camera module.
  90. *
  91. * @param base Pointer to FLEXIO_CAMERA_Type structure
  92. */
  93. void FLEXIO_CAMERA_Deinit(FLEXIO_CAMERA_Type *base);
  94. /*!
  95. * @brief Gets the default configuration to configure the FlexIO Camera. The configuration
  96. * can be used directly for calling the FLEXIO_CAMERA_Init().
  97. * Example:
  98. @code
  99. flexio_camera_config_t config;
  100. FLEXIO_CAMERA_GetDefaultConfig(&userConfig);
  101. @endcode
  102. * @param config Pointer to the flexio_camera_config_t structure
  103. */
  104. void FLEXIO_CAMERA_GetDefaultConfig(flexio_camera_config_t *config);
  105. /*!
  106. * @brief Enables/disables the FlexIO Camera module operation.
  107. *
  108. * @param base Pointer to the FLEXIO_CAMERA_Type
  109. * @param enable True to enable, false does not have any effect.
  110. */
  111. static inline void FLEXIO_CAMERA_Enable(FLEXIO_CAMERA_Type *base, bool enable)
  112. {
  113. if (enable)
  114. {
  115. base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
  116. }
  117. }
  118. /*! @} */
  119. /*!
  120. * @name Status
  121. * @{
  122. */
  123. /*!
  124. * @brief Gets the FlexIO Camera status flags.
  125. *
  126. * @param base Pointer to FLEXIO_CAMERA_Type structure
  127. * @return FlexIO shifter status flags
  128. * @arg FLEXIO_SHIFTSTAT_SSF_MASK
  129. * @arg 0
  130. */
  131. uint32_t FLEXIO_CAMERA_GetStatusFlags(FLEXIO_CAMERA_Type *base);
  132. /*!
  133. * @brief Clears the receive buffer full flag manually.
  134. *
  135. * @param base Pointer to the device.
  136. * @param mask status flag
  137. * The parameter can be any combination of the following values:
  138. * @arg kFLEXIO_CAMERA_RxDataRegFullFlag
  139. * @arg kFLEXIO_CAMERA_RxErrorFlag
  140. */
  141. void FLEXIO_CAMERA_ClearStatusFlags(FLEXIO_CAMERA_Type *base, uint32_t mask);
  142. /* @} */
  143. /*!
  144. * @name Interrupts
  145. * @{
  146. */
  147. /*!
  148. * @brief Switches on the interrupt for receive buffer full event.
  149. *
  150. * @param base Pointer to the device.
  151. */
  152. void FLEXIO_CAMERA_EnableInterrupt(FLEXIO_CAMERA_Type *base);
  153. /*!
  154. * @brief Switches off the interrupt for receive buffer full event.
  155. *
  156. * @param base Pointer to the device.
  157. *
  158. */
  159. void FLEXIO_CAMERA_DisableInterrupt(FLEXIO_CAMERA_Type *base);
  160. /*! @} */
  161. /*!
  162. * @name DMA support
  163. * @{
  164. */
  165. /*!
  166. * @brief Enables/disables the FlexIO Camera receive DMA.
  167. *
  168. * @param base Pointer to FLEXIO_CAMERA_Type structure
  169. * @param enable True to enable, false to disable.
  170. *
  171. * The FlexIO Camera mode can't work without the DMA or eDMA support,
  172. * Usually, it needs at least two DMA or eDMA channels, one for transferring data from
  173. * Camera, such as 0V7670 to FlexIO buffer, another is for transferring data from FlexIO
  174. * buffer to LCD.
  175. *
  176. */
  177. static inline void FLEXIO_CAMERA_EnableRxDMA(FLEXIO_CAMERA_Type *base, bool enable)
  178. {
  179. FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL << base->shifterStartIdx, enable);
  180. }
  181. /*!
  182. * @brief Gets the data from the receive buffer.
  183. *
  184. * @param base Pointer to the device.
  185. * @return data Pointer to the buffer that keeps the data with count of base->shifterCount .
  186. */
  187. static inline uint32_t FLEXIO_CAMERA_GetRxBufferAddress(FLEXIO_CAMERA_Type *base)
  188. {
  189. return FLEXIO_GetShifterBufferAddress(base->flexioBase, kFLEXIO_ShifterBuffer, (uint8_t)base->shifterStartIdx);
  190. }
  191. /*! @} */
  192. #if defined(__cplusplus)
  193. }
  194. #endif /*_cplusplus*/
  195. /*@}*/
  196. #endif /*_FSL_FLEXIO_CAMERA_H_*/