fsl_flexio_camera.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #include "fsl_flexio_camera.h"
  9. /* Component ID definition, used by tools. */
  10. #ifndef FSL_COMPONENT_ID
  11. #define FSL_COMPONENT_ID "platform.drivers.flexio_camera"
  12. #endif
  13. /*******************************************************************************
  14. * Prototypes
  15. ******************************************************************************/
  16. /*******************************************************************************
  17. * Variables
  18. ******************************************************************************/
  19. /*******************************************************************************
  20. * Codes
  21. ******************************************************************************/
  22. static uint32_t FLEXIO_CAMERA_GetInstance(FLEXIO_CAMERA_Type *base)
  23. {
  24. return FLEXIO_GetInstance(base->flexioBase);
  25. }
  26. /*!
  27. * brief Gets the default configuration to configure the FlexIO Camera. The configuration
  28. * can be used directly for calling the FLEXIO_CAMERA_Init().
  29. * Example:
  30. code
  31. flexio_camera_config_t config;
  32. FLEXIO_CAMERA_GetDefaultConfig(&userConfig);
  33. endcode
  34. * param config Pointer to the flexio_camera_config_t structure
  35. */
  36. void FLEXIO_CAMERA_GetDefaultConfig(flexio_camera_config_t *config)
  37. {
  38. assert(config != NULL);
  39. /* Initializes the configure structure to zero. */
  40. (void)memset(config, 0, sizeof(*config));
  41. config->enablecamera = false;
  42. config->enableInDoze = false;
  43. config->enableInDebug = false;
  44. config->enableFastAccess = false;
  45. }
  46. /*!
  47. * brief Ungates the FlexIO clock, resets the FlexIO module, and configures the FlexIO Camera.
  48. *
  49. * param base Pointer to FLEXIO_CAMERA_Type structure
  50. * param config Pointer to flexio_camera_config_t structure
  51. */
  52. void FLEXIO_CAMERA_Init(FLEXIO_CAMERA_Type *base, const flexio_camera_config_t *config)
  53. {
  54. assert((base != NULL) && (config != NULL));
  55. assert(base->shifterCount > 0U);
  56. uint32_t i = 0U;
  57. volatile uint32_t controlVal = 0U;
  58. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  59. /* Ungate flexio clock. */
  60. CLOCK_EnableClock(s_flexioClocks[FLEXIO_CAMERA_GetInstance(base)]);
  61. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  62. flexio_shifter_config_t shifterConfig;
  63. flexio_timer_config_t timerConfig;
  64. /* Clear the shifterConfig & timerConfig struct. */
  65. (void)memset(&shifterConfig, 0, sizeof(shifterConfig));
  66. (void)memset(&timerConfig, 0, sizeof(timerConfig));
  67. /* Configure flexio camera */
  68. controlVal = base->flexioBase->CTRL;
  69. controlVal &=
  70. ~(FLEXIO_CTRL_DOZEN_MASK | FLEXIO_CTRL_DBGE_MASK | FLEXIO_CTRL_FASTACC_MASK | FLEXIO_CTRL_FLEXEN_MASK);
  71. controlVal |= (FLEXIO_CTRL_DBGE(config->enableInDebug) | FLEXIO_CTRL_FASTACC(config->enableFastAccess) |
  72. FLEXIO_CTRL_FLEXEN(config->enablecamera));
  73. if (!config->enableInDoze)
  74. {
  75. controlVal |= FLEXIO_CTRL_DOZEN_MASK;
  76. }
  77. base->flexioBase->CTRL = controlVal;
  78. /* FLEXIO_CAMERA shifter config */
  79. shifterConfig.timerSelect = base->timerIdx;
  80. shifterConfig.timerPolarity = kFLEXIO_ShifterTimerPolarityOnPositive;
  81. shifterConfig.pinConfig = kFLEXIO_PinConfigOutputDisabled;
  82. shifterConfig.pinSelect = base->datPinStartIdx;
  83. shifterConfig.pinPolarity = kFLEXIO_PinActiveHigh;
  84. shifterConfig.shifterMode = kFLEXIO_ShifterModeReceive;
  85. shifterConfig.parallelWidth = FLEXIO_CAMERA_PARALLEL_DATA_WIDTH - 1U;
  86. shifterConfig.inputSource = kFLEXIO_ShifterInputFromNextShifterOutput;
  87. shifterConfig.shifterStop = kFLEXIO_ShifterStopBitDisable;
  88. shifterConfig.shifterStart = kFLEXIO_ShifterStartBitDisabledLoadDataOnEnable;
  89. /* Configure the shifters as FIFO buffer. */
  90. for (i = base->shifterStartIdx; i < (base->shifterStartIdx + base->shifterCount - 1U); i++)
  91. {
  92. FLEXIO_SetShifterConfig(base->flexioBase, (uint8_t)i, &shifterConfig);
  93. }
  94. shifterConfig.inputSource = kFLEXIO_ShifterInputFromPin;
  95. FLEXIO_SetShifterConfig(base->flexioBase, (uint8_t)i, &shifterConfig);
  96. /* FLEXIO_CAMERA timer config, the PCLK's clk is source of timer to drive the shifter, the HREF is the selecting
  97. * signal for available data. */
  98. timerConfig.triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_PININPUT(base->hrefPinIdx);
  99. timerConfig.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveHigh;
  100. timerConfig.triggerSource = kFLEXIO_TimerTriggerSourceInternal;
  101. timerConfig.pinConfig = kFLEXIO_PinConfigOutputDisabled;
  102. timerConfig.pinSelect = base->pclkPinIdx;
  103. timerConfig.pinPolarity = kFLEXIO_PinActiveHigh;
  104. timerConfig.timerMode = kFLEXIO_TimerModeSingle16Bit;
  105. timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
  106. timerConfig.timerDecrement = kFLEXIO_TimerDecSrcOnPinInputShiftPinInput;
  107. timerConfig.timerReset = kFLEXIO_TimerResetOnTimerTriggerRisingEdge;
  108. timerConfig.timerDisable = kFLEXIO_TimerDisableOnTriggerFallingEdge;
  109. timerConfig.timerEnable = kFLEXIO_TimerEnableOnTriggerRisingEdge;
  110. timerConfig.timerStop = kFLEXIO_TimerStopBitDisabled;
  111. timerConfig.timerStart = kFLEXIO_TimerStartBitDisabled;
  112. timerConfig.timerCompare = 8U * base->shifterCount - 1U;
  113. FLEXIO_SetTimerConfig(base->flexioBase, (uint8_t)base->timerIdx, &timerConfig);
  114. /* Clear flags. */
  115. FLEXIO_ClearShifterErrorFlags(base->flexioBase, (((1UL << (base->shifterCount)) - 1U) << (base->shifterStartIdx)));
  116. FLEXIO_ClearTimerStatusFlags(base->flexioBase, 1UL << (base->timerIdx));
  117. }
  118. /*!
  119. * brief Resets the FLEXIO_CAMERA shifer and timer config.
  120. *
  121. * note After calling this API, call FLEXO_CAMERA_Init to use the FlexIO Camera module.
  122. *
  123. * param base Pointer to FLEXIO_CAMERA_Type structure
  124. */
  125. void FLEXIO_CAMERA_Deinit(FLEXIO_CAMERA_Type *base)
  126. {
  127. base->flexioBase->SHIFTCFG[base->shifterStartIdx] = 0;
  128. base->flexioBase->SHIFTCTL[base->shifterStartIdx] = 0;
  129. base->flexioBase->TIMCFG[base->timerIdx] = 0;
  130. base->flexioBase->TIMCMP[base->timerIdx] = 0;
  131. base->flexioBase->TIMCTL[base->timerIdx] = 0;
  132. /* Clear the shifter flag. */
  133. base->flexioBase->SHIFTSTAT = (1UL << base->shifterStartIdx);
  134. /* Clear the timer flag. */
  135. base->flexioBase->TIMSTAT = (1UL << base->timerIdx);
  136. }
  137. /*!
  138. * brief Gets the FlexIO Camera status flags.
  139. *
  140. * param base Pointer to FLEXIO_CAMERA_Type structure
  141. * return FlexIO shifter status flags
  142. * arg FLEXIO_SHIFTSTAT_SSF_MASK
  143. * arg 0
  144. */
  145. uint32_t FLEXIO_CAMERA_GetStatusFlags(FLEXIO_CAMERA_Type *base)
  146. {
  147. uint32_t status = 0;
  148. status = ((FLEXIO_GetShifterStatusFlags(base->flexioBase) >> (base->shifterStartIdx)) &
  149. ((1U << (base->shifterCount)) - 1U));
  150. return status;
  151. }
  152. /*!
  153. * brief Clears the receive buffer full flag manually.
  154. *
  155. * param base Pointer to the device.
  156. * param mask status flag
  157. * The parameter can be any combination of the following values:
  158. * arg kFLEXIO_CAMERA_RxDataRegFullFlag
  159. * arg kFLEXIO_CAMERA_RxErrorFlag
  160. */
  161. void FLEXIO_CAMERA_ClearStatusFlags(FLEXIO_CAMERA_Type *base, uint32_t mask)
  162. {
  163. if ((mask & (uint32_t)kFLEXIO_CAMERA_RxDataRegFullFlag) != 0U)
  164. {
  165. FLEXIO_ClearShifterStatusFlags(base->flexioBase, ((1UL << (base->shifterCount)) - 1U)
  166. << (base->shifterStartIdx));
  167. }
  168. if ((mask & (uint32_t)kFLEXIO_CAMERA_RxErrorFlag) != 0U)
  169. { /* Clear error flags if they are asserted to make sure the buffer would be available. */
  170. FLEXIO_ClearShifterErrorFlags(base->flexioBase, ((1UL << (base->shifterCount)) - 1U)
  171. << (base->shifterStartIdx));
  172. }
  173. }
  174. /*!
  175. * brief Switches on the interrupt for receive buffer full event.
  176. *
  177. * param base Pointer to the device.
  178. */
  179. void FLEXIO_CAMERA_EnableInterrupt(FLEXIO_CAMERA_Type *base)
  180. {
  181. FLEXIO_EnableShifterStatusInterrupts(base->flexioBase, 1UL << (base->shifterStartIdx));
  182. }
  183. /*!
  184. * brief Switches off the interrupt for receive buffer full event.
  185. *
  186. * param base Pointer to the device.
  187. *
  188. */
  189. void FLEXIO_CAMERA_DisableInterrupt(FLEXIO_CAMERA_Type *base)
  190. {
  191. FLEXIO_DisableShifterStatusInterrupts(base->flexioBase, 1UL << (base->shifterStartIdx));
  192. }