fsl_flexio_camera.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #include "fsl_flexio_camera.h"
  35. /* Component ID definition, used by tools. */
  36. #ifndef FSL_COMPONENT_ID
  37. #define FSL_COMPONENT_ID "platform.drivers.flexio_camera"
  38. #endif
  39. /*******************************************************************************
  40. * Prototypes
  41. ******************************************************************************/
  42. /*******************************************************************************
  43. * Variables
  44. ******************************************************************************/
  45. /*******************************************************************************
  46. * Codes
  47. ******************************************************************************/
  48. static uint32_t FLEXIO_CAMERA_GetInstance(FLEXIO_CAMERA_Type *base)
  49. {
  50. return FLEXIO_GetInstance(base->flexioBase);
  51. }
  52. void FLEXIO_CAMERA_GetDefaultConfig(flexio_camera_config_t *config)
  53. {
  54. assert(config);
  55. config->enablecamera = false;
  56. config->enableInDoze = false;
  57. config->enableInDebug = false;
  58. config->enableFastAccess = false;
  59. }
  60. void FLEXIO_CAMERA_Init(FLEXIO_CAMERA_Type *base, const flexio_camera_config_t *config)
  61. {
  62. assert(base && config);
  63. volatile uint32_t i = 0;
  64. volatile uint32_t controlVal = 0;
  65. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  66. /* Ungate flexio clock. */
  67. CLOCK_EnableClock(s_flexioClocks[FLEXIO_CAMERA_GetInstance(base)]);
  68. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  69. flexio_shifter_config_t shifterConfig;
  70. flexio_timer_config_t timerConfig;
  71. /* Clear the shifterConfig & timerConfig struct. */
  72. memset(&shifterConfig, 0, sizeof(shifterConfig));
  73. memset(&timerConfig, 0, sizeof(timerConfig));
  74. /* Configure flexio camera */
  75. controlVal = base->flexioBase->CTRL;
  76. controlVal &=
  77. ~(FLEXIO_CTRL_DOZEN_MASK | FLEXIO_CTRL_DBGE_MASK | FLEXIO_CTRL_FASTACC_MASK | FLEXIO_CTRL_FLEXEN_MASK);
  78. controlVal |= (FLEXIO_CTRL_DBGE(config->enableInDebug) | FLEXIO_CTRL_FASTACC(config->enableFastAccess) |
  79. FLEXIO_CTRL_FLEXEN(config->enablecamera));
  80. if (!config->enableInDoze)
  81. {
  82. controlVal |= FLEXIO_CTRL_DOZEN_MASK;
  83. }
  84. base->flexioBase->CTRL = controlVal;
  85. /* FLEXIO_CAMERA shifter config */
  86. shifterConfig.timerSelect = base->timerIdx;
  87. shifterConfig.timerPolarity = kFLEXIO_ShifterTimerPolarityOnPositive;
  88. shifterConfig.pinConfig = kFLEXIO_PinConfigOutputDisabled;
  89. shifterConfig.pinSelect = base->datPinStartIdx;
  90. shifterConfig.pinPolarity = kFLEXIO_PinActiveHigh;
  91. shifterConfig.shifterMode = kFLEXIO_ShifterModeReceive;
  92. shifterConfig.parallelWidth = FLEXIO_CAMERA_PARALLEL_DATA_WIDTH - 1U;
  93. shifterConfig.inputSource = kFLEXIO_ShifterInputFromNextShifterOutput;
  94. shifterConfig.shifterStop = kFLEXIO_ShifterStopBitDisable;
  95. shifterConfig.shifterStart = kFLEXIO_ShifterStartBitDisabledLoadDataOnEnable;
  96. /* Configure the shifters as FIFO buffer. */
  97. for (i = base->shifterStartIdx; i < (base->shifterStartIdx + base->shifterCount - 1U); i++)
  98. {
  99. FLEXIO_SetShifterConfig(base->flexioBase, i, &shifterConfig);
  100. }
  101. shifterConfig.inputSource = kFLEXIO_ShifterInputFromPin;
  102. FLEXIO_SetShifterConfig(base->flexioBase, i, &shifterConfig);
  103. /* FLEXIO_CAMERA timer config, the PCLK's clk is source of timer to drive the shifter, the HREF is the selecting
  104. * signal for available data. */
  105. timerConfig.triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_PININPUT(base->hrefPinIdx);
  106. timerConfig.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveHigh;
  107. timerConfig.triggerSource = kFLEXIO_TimerTriggerSourceInternal;
  108. timerConfig.pinConfig = kFLEXIO_PinConfigOutputDisabled;
  109. timerConfig.pinSelect = base->pclkPinIdx;
  110. timerConfig.pinPolarity = kFLEXIO_PinActiveHigh;
  111. timerConfig.timerMode = kFLEXIO_TimerModeSingle16Bit;
  112. timerConfig.timerOutput = kFLEXIO_TimerOutputZeroNotAffectedByReset;
  113. timerConfig.timerDecrement = kFLEXIO_TimerDecSrcOnPinInputShiftPinInput;
  114. timerConfig.timerReset = kFLEXIO_TimerResetOnTimerTriggerRisingEdge;
  115. timerConfig.timerDisable = kFLEXIO_TimerDisableOnTriggerFallingEdge;
  116. timerConfig.timerEnable = kFLEXIO_TimerEnableOnTriggerRisingEdge;
  117. timerConfig.timerStop = kFLEXIO_TimerStopBitDisabled;
  118. timerConfig.timerStart = kFLEXIO_TimerStartBitDisabled;
  119. timerConfig.timerCompare = 8U * base->shifterCount - 1U;
  120. FLEXIO_SetTimerConfig(base->flexioBase, base->timerIdx, &timerConfig);
  121. /* Clear flags. */
  122. FLEXIO_ClearShifterErrorFlags(base->flexioBase, ((1U << (base->shifterCount)) - 1U) << (base->shifterStartIdx));
  123. FLEXIO_ClearTimerStatusFlags(base->flexioBase, 1U << (base->timerIdx));
  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 = (1U << base->shifterStartIdx);
  134. /* Clear the timer flag. */
  135. base->flexioBase->TIMSTAT = (1U << base->timerIdx);
  136. }
  137. uint32_t FLEXIO_CAMERA_GetStatusFlags(FLEXIO_CAMERA_Type *base)
  138. {
  139. uint32_t status = 0;
  140. status = ((FLEXIO_GetShifterStatusFlags(base->flexioBase) >> (base->shifterStartIdx)) &
  141. ((1U << (base->shifterCount)) - 1U));
  142. return status;
  143. }
  144. void FLEXIO_CAMERA_ClearStatusFlags(FLEXIO_CAMERA_Type *base, uint32_t mask)
  145. {
  146. if (mask & kFLEXIO_CAMERA_RxDataRegFullFlag)
  147. {
  148. FLEXIO_ClearShifterStatusFlags(base->flexioBase, ((1U << (base->shifterCount)) - 1U)
  149. << (base->shifterStartIdx));
  150. }
  151. if (mask & kFLEXIO_CAMERA_RxErrorFlag)
  152. { /* Clear error flags if they are asserted to make sure the buffer would be available. */
  153. FLEXIO_ClearShifterErrorFlags(base->flexioBase, ((1U << (base->shifterCount)) - 1U) << (base->shifterStartIdx));
  154. }
  155. }
  156. void FLEXIO_CAMERA_EnableInterrupt(FLEXIO_CAMERA_Type *base)
  157. {
  158. FLEXIO_EnableShifterStatusInterrupts(base->flexioBase, 1U << (base->shifterStartIdx));
  159. }
  160. void FLEXIO_CAMERA_DisableInterrupt(FLEXIO_CAMERA_Type *base)
  161. {
  162. FLEXIO_DisableShifterStatusInterrupts(base->flexioBase, 1U << (base->shifterStartIdx));
  163. }