n32g45x_dvp.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_dvp.c
  29. * @author Nations
  30. * @version v1.0.2
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #include "n32g45x_dvp.h"
  35. #include "n32g45x_rcc.h"
  36. /**
  37. * @brief Deinitializes the DVP peripheral registers to their default reset values.
  38. * @param None
  39. * @retval None
  40. */
  41. void DVP_ResetReg(void)
  42. {
  43. RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_DVP, ENABLE);
  44. RCC_EnableAPB2PeriphReset(RCC_APB2_PERIPH_DVP, DISABLE);
  45. }
  46. /**
  47. * @brief Initializes the DVP peripheral according to the specified
  48. * parameters in the DVP_InitStruct .
  49. * @param DVP_InitStruct pointer to a DVP_InitType structure
  50. * that contains the configuration information for the specified DVP
  51. * peripheral.
  52. * @retval None
  53. */
  54. void DVP_Init( DVP_InitType* DVP_InitStruct)
  55. {
  56. uint32_t tmpregister = 0x00;
  57. /* Check the parameters */
  58. assert_param(IS_DVP_LINE_CAPTURE(DVP_InitStruct->LineCapture));
  59. assert_param(IS_DVP_BYTE_CAPTURE(DVP_InitStruct->ByteCapture));
  60. assert_param(IS_DVP_DATA_INVERT(DVP_InitStruct->DataInvert));
  61. assert_param(IS_DVP_PIXEL_POLARITY(DVP_InitStruct->PixelClkPolarity));
  62. assert_param(IS_DVP_VSYNC_POLARITY(DVP_InitStruct->VsyncPolarity));
  63. assert_param(IS_DVP_HSYNC_POLARITY(DVP_InitStruct->HsyncPolarity));
  64. assert_param(IS_DVP_CAPTURE_MODE(DVP_InitStruct->CaptureMode));
  65. assert_param(IS_DVP_FIFOWATERMARK(DVP_InitStruct->FifoWatermark));
  66. /*---------------------------- DVP CTRL Configuration -----------------------*/
  67. tmpregister = 0;
  68. tmpregister |= DVP_InitStruct->LineCapture | DVP_InitStruct->ByteCapture
  69. | DVP_InitStruct->DataInvert | DVP_InitStruct->PixelClkPolarity
  70. | DVP_InitStruct->VsyncPolarity | DVP_InitStruct->HsyncPolarity
  71. | DVP_InitStruct->CaptureMode | DVP_InitStruct->FifoWatermark;
  72. DVP->CTRL = tmpregister;
  73. /*---------------------------- DVP WST Configuration -----------------------*/
  74. if (DVP_InitStruct->RowStart)
  75. DVP_InitStruct->RowStart--;
  76. if (DVP_InitStruct->ColumnStart)
  77. DVP_InitStruct->ColumnStart--;
  78. DVP->WST = ( (((uint32_t)(DVP_InitStruct->RowStart)) << DVP_WST_VST_SHIFT) \
  79. | (((uint32_t)(DVP_InitStruct->ColumnStart))<< DVP_WST_HST_SHIFT) );
  80. /*---------------------------- DVP WSIZE Configuration -----------------------*/
  81. DVP->WSIZE = ( (((uint32_t)(DVP_InitStruct->ImageHeight-1)) << DVP_WSIZE_VLINE_SHIFT) \
  82. | (((uint32_t)(DVP_InitStruct->ImageWidth-1)) << DVP_WSIZE_HCNT_SHIFT) );
  83. }
  84. /**
  85. * @brief Fills DVP_InitStruct member with its default value.
  86. * @param DVP_InitStruct pointer to a DVP_InitType structure
  87. * which will be initialized.
  88. * @retval None
  89. */
  90. void DVP_DafaultInitParam(DVP_InitType* DVP_InitStruct)
  91. {
  92. /* DVP_InitStruct members default value */
  93. DVP_InitStruct->FifoWatermark = DVP_WATER_MARK_1;
  94. DVP_InitStruct->LineCapture = DVP_LINE_CAPTURE_ALL;
  95. DVP_InitStruct->ByteCapture = DVP_BYTE_CAPTURE_ALL;
  96. DVP_InitStruct->DataInvert = DVP_DATA_NOTINVERT;
  97. DVP_InitStruct->PixelClkPolarity = DVP_PIXEL_POLARITY_FALLING;
  98. DVP_InitStruct->VsyncPolarity = DVP_VSYNC_POLARITY_LOW;
  99. DVP_InitStruct->HsyncPolarity = DVP_HSYNC_POLARITY_HIGH;
  100. DVP_InitStruct->CaptureMode = DVP_CAPTURE_MODE_SINGLE;
  101. DVP_InitStruct->RowStart = 0;
  102. DVP_InitStruct->ColumnStart = 0;
  103. DVP_InitStruct->ImageHeight = 240;
  104. DVP_InitStruct->ImageWidth = 320;
  105. }
  106. /**
  107. * @brief Enables or disables the DVP DMA interface.
  108. * @param Cmd New state of the DMA Request.
  109. * This parameter can be: ENABLE or DISABLE.
  110. * @retval None
  111. */
  112. void DVP_ConfigDma( FunctionalState Cmd)
  113. {
  114. /* Check the parameters */
  115. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  116. if (Cmd != DISABLE)
  117. {
  118. /* When DMA is enable, the FWM in CTRL1 should be set 1*/
  119. __DVP_SetFifoWatermark(DVP_WATER_MARK_1);
  120. __DVP_EnableDMA();
  121. }
  122. else
  123. {
  124. __DVP_DisableDMA();
  125. }
  126. }
  127. /**
  128. * @brief Get the data length in FIFO.
  129. * @param None.
  130. * @retval Current date length in FIFO
  131. */
  132. uint32_t DVP_GetFifoCount(void)
  133. {
  134. if (__FIFOIsNotEmpty())
  135. return ((DVP->STS & DVP_STS_FCNT_MASK)>>DVP_STS_FCNT_SHIFT);
  136. else
  137. return 0;
  138. }
  139. /**
  140. * @brief Software Reset FIFO
  141. * @param None.
  142. * @retval None.
  143. */
  144. void DVP_ResetFifo(void)
  145. {
  146. __DVP_StopCapture();
  147. DVP->CTRL |= DVP_FIFO_SOFT_RESET;
  148. while(DVP->CTRL & DVP_FIFO_SOFT_RESET);
  149. }