air105_dcmi.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __AIR105_DCMI_H
  22. #define __AIR105_DCMI_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "air105.h"
  28. /* Exported types ------------------------------------------------------------*/
  29. /**
  30. * @brief DCMI Init structure definition
  31. */
  32. typedef struct
  33. {
  34. uint16_t DCMI_CaptureMode; /*!< Specifies the Capture Mode: Continuous or Snapshot.
  35. This parameter can be a value of @ref DCMI_Capture_Mode */
  36. uint16_t DCMI_SynchroMode; /*!< Specifies the Synchronization Mode: Hardware or Embedded.
  37. This parameter can be a value of @ref DCMI_Synchronization_Mode */
  38. uint16_t DCMI_PCKPolarity; /*!< Specifies the Pixel clock polarity: Falling or Rising.
  39. This parameter can be a value of @ref DCMI_PIXCK_Polarity */
  40. uint16_t DCMI_VSPolarity; /*!< Specifies the Vertical synchronization polarity: High or Low.
  41. This parameter can be a value of @ref DCMI_VSYNC_Polarity */
  42. uint16_t DCMI_HSPolarity; /*!< Specifies the Horizontal synchronization polarity: High or Low.
  43. This parameter can be a value of @ref DCMI_HSYNC_Polarity */
  44. uint16_t DCMI_CaptureRate; /*!< Specifies the frequency of frame capture: All, 1/2 or 1/4.
  45. This parameter can be a value of @ref DCMI_Capture_Rate */
  46. uint16_t DCMI_ExtendedDataMode; /*!< Specifies the data width: 8-bit, 10-bit, 12-bit or 14-bit.
  47. This parameter can be a value of @ref DCMI_Extended_Data_Mode */
  48. uint32_t DCMI_ByteSelectMode; /*!< Specifies the Capture Select Byte Mode: Select All Bytes, 1 of 2, 1 of 4 or 2 of 4
  49. This parameter can be a value of @ref DCMI_ByteSelect_Mode */
  50. uint32_t DCMI_LineSelectMode; /*!< Specifies the Capture Select Line Mode: Select All Lines, Odd Line or Even Line
  51. This parameter can be a value of @ref DCMI_ByteLine_Mode */
  52. uint32_t DCMI_ClockDiv; /*!< Specifies the DCMI Slave Clock Div: 2~16 from HCLK
  53. This parameter can be a value of @ref DCMI_Clock_Div */
  54. } DCMI_InitTypeDef;
  55. /**
  56. * @brief DCMI CROP Init structure definition
  57. */
  58. typedef struct
  59. {
  60. uint16_t DCMI_VerticalStartLine; /*!< Specifies the Vertical start line count from which the image capture
  61. will start. This parameter can be a value between 0x00 and 0x1FFF */
  62. uint16_t DCMI_HorizontalOffsetCount; /*!< Specifies the number of pixel clocks to count before starting a capture.
  63. This parameter can be a value between 0x00 and 0x3FFF */
  64. uint16_t DCMI_VerticalLineCount; /*!< Specifies the number of lines to be captured from the starting point.
  65. This parameter can be a value between 0x00 and 0x3FFF */
  66. uint16_t DCMI_CaptureCount; /*!< Specifies the number of pixel clocks to be captured from the starting
  67. point on the same line.
  68. This parameter can be a value between 0x00 and 0x3FFF */
  69. } DCMI_CROPInitTypeDef;
  70. /**
  71. * @brief DCMI Embedded Synchronisation CODE Init structure definition
  72. */
  73. typedef struct
  74. {
  75. uint8_t DCMI_FrameStartCode; /*!< Specifies the code of the frame start delimiter. */
  76. uint8_t DCMI_LineStartCode; /*!< Specifies the code of the line start delimiter. */
  77. uint8_t DCMI_LineEndCode; /*!< Specifies the code of the line end delimiter. */
  78. uint8_t DCMI_FrameEndCode; /*!< Specifies the code of the frame end delimiter. */
  79. } DCMI_CodesInitTypeDef;
  80. /* Exported constants --------------------------------------------------------*/
  81. /** @defgroup DCMI_Exported_Constants
  82. * @{
  83. */
  84. /** @defgroup DCMI_Capture_Mode
  85. * @{
  86. */
  87. #define DCMI_CaptureMode_Continuous ((uint16_t)0x0000) /*!< The received data are transferred continuously
  88. into the destination memory through the DMA */
  89. #define DCMI_CaptureMode_SnapShot ((uint16_t)0x0002) /*!< Once activated, the interface waits for the start of
  90. frame and then transfers a single frame through the DMA */
  91. #define IS_DCMI_CAPTURE_MODE(MODE)(((MODE) == DCMI_CaptureMode_Continuous) || \
  92. ((MODE) == DCMI_CaptureMode_SnapShot))
  93. /**
  94. * @}
  95. */
  96. /** @defgroup DCMI_Synchronization_Mode
  97. * @{
  98. */
  99. #define DCMI_SynchroMode_Hardware ((uint16_t)0x0000) /*!< Hardware synchronization data capture (frame/line start/stop)
  100. is synchronized with the HSYNC/VSYNC signals */
  101. #define DCMI_SynchroMode_Embedded ((uint16_t)0x0010) /*!< Embedded synchronization data capture is synchronized with
  102. synchronization codes embedded in the data flow */
  103. #define IS_DCMI_SYNCHRO(MODE)(((MODE) == DCMI_SynchroMode_Hardware) || \
  104. ((MODE) == DCMI_SynchroMode_Embedded))
  105. /**
  106. * @}
  107. */
  108. /** @defgroup DCMI_PIXCK_Polarity
  109. * @{
  110. */
  111. #define DCMI_PCKPolarity_Falling ((uint16_t)0x0000) /*!< Pixel clock active on Falling edge */
  112. #define DCMI_PCKPolarity_Rising ((uint16_t)0x0020) /*!< Pixel clock active on Rising edge */
  113. #define IS_DCMI_PCKPOLARITY(POLARITY)(((POLARITY) == DCMI_PCKPolarity_Falling) || \
  114. ((POLARITY) == DCMI_PCKPolarity_Rising))
  115. /**
  116. * @}
  117. */
  118. /** @defgroup DCMI_VSYNC_Polarity
  119. * @{
  120. */
  121. #define DCMI_VSPolarity_Low ((uint16_t)0x0000) /*!< Vertical synchronization active Low */
  122. #define DCMI_VSPolarity_High ((uint16_t)0x0080) /*!< Vertical synchronization active High */
  123. #define IS_DCMI_VSPOLARITY(POLARITY)(((POLARITY) == DCMI_VSPolarity_Low) || \
  124. ((POLARITY) == DCMI_VSPolarity_High))
  125. /**
  126. * @}
  127. */
  128. /** @defgroup DCMI_HSYNC_Polarity
  129. * @{
  130. */
  131. #define DCMI_HSPolarity_Low ((uint16_t)0x0000) /*!< Horizontal synchronization active Low */
  132. #define DCMI_HSPolarity_High ((uint16_t)0x0040) /*!< Horizontal synchronization active High */
  133. #define IS_DCMI_HSPOLARITY(POLARITY)(((POLARITY) == DCMI_HSPolarity_Low) || \
  134. ((POLARITY) == DCMI_HSPolarity_High))
  135. /**
  136. * @}
  137. */
  138. /** @defgroup DCMI_Capture_Rate
  139. * @{
  140. */
  141. #define DCMI_CaptureRate_All_Frame ((uint16_t)0x0000) /*!< All frames are captured */
  142. #define DCMI_CaptureRate_1of2_Frame ((uint16_t)0x0100) /*!< Every alternate frame captured */
  143. #define DCMI_CaptureRate_1of4_Frame ((uint16_t)0x0200) /*!< One frame in 4 frames captured */
  144. #define IS_DCMI_CAPTURE_RATE(RATE) (((RATE) == DCMI_CaptureRate_All_Frame) || \
  145. ((RATE) == DCMI_CaptureRate_1of2_Frame) ||\
  146. ((RATE) == DCMI_CaptureRate_1of4_Frame))
  147. /** @defgroup DCMI_Clock_Div
  148. * @{
  149. */
  150. #define DCMI_Clock_Div2 ((uint32_t)0x00000000)
  151. #define DCMI_Clock_Div4 ((uint32_t)0x20000000)
  152. #define DCMI_Clock_Div6 ((uint32_t)0x40000000)
  153. #define DCMI_Clock_Div8 ((uint32_t)0x60000000)
  154. #define DCMI_Clock_Div10 ((uint32_t)0x80000000)
  155. #define DCMI_Clock_Div12 ((uint32_t)0xA0000000)
  156. #define DCMI_Clock_Div14 ((uint32_t)0xC0000000)
  157. #define DCMI_Clock_Div16 ((uint32_t)0xE0000000)
  158. #define IS_DCMI_CLOCK_DIV(DIV) (((DIV) == DCMI_Clock_Div2) ||\
  159. ((DIV) == DCMI_Clock_Div4) ||\
  160. ((DIV) == DCMI_Clock_Div6) ||\
  161. ((DIV) == DCMI_Clock_Div8) ||\
  162. ((DIV) == DCMI_Clock_Div10) ||\
  163. ((DIV) == DCMI_Clock_Div12) ||\
  164. ((DIV) == DCMI_Clock_Div14) ||\
  165. ((DIV) == DCMI_Clock_Div16))
  166. #define DCMI_Clock_Div_MSK ((uint32_t)0xE0000000)
  167. /**
  168. * @}
  169. */
  170. /** @defgroup DCMI_Extended_Data_Mode
  171. * @{
  172. */
  173. #define DCMI_ExtendedDataMode_8b ((uint16_t)0x0000) /*!< Interface captures 8-bit data on every pixel clock */
  174. #define DCMI_ExtendedDataMode_10b ((uint16_t)0x0400) /*!< Interface captures 10-bit data on every pixel clock */
  175. #define DCMI_ExtendedDataMode_12b ((uint16_t)0x0800) /*!< Interface captures 12-bit data on every pixel clock */
  176. #define DCMI_ExtendedDataMode_14b ((uint16_t)0x0C00) /*!< Interface captures 14-bit data on every pixel clock */
  177. #define IS_DCMI_EXTENDED_DATA(DATA) (((DATA) == DCMI_ExtendedDataMode_8b) || \
  178. ((DATA) == DCMI_ExtendedDataMode_10b) ||\
  179. ((DATA) == DCMI_ExtendedDataMode_12b) ||\
  180. ((DATA) == DCMI_ExtendedDataMode_14b))
  181. /** @defgroup DCMI_ByteSelectMode
  182. * @{
  183. */
  184. #define DCMI_ByteSelect_Mode_AllByte ((uint32_t)0x00000000)
  185. #define DCMI_ByteSelect_Mode_1of2_OddStart ((uint32_t)0x00010000)
  186. #define DCMI_ByteSelect_Mode_1of4_OddStart ((uint32_t)0x00020000)
  187. #define DCMI_ByteSelect_Mode_2of4_OddStart ((uint32_t)0x00030000)
  188. #define DCMI_ByteSelect_Mode_1of2_EvenStart ((uint32_t)0x00050000)
  189. #define DCMI_ByteSelect_Mode_1of4_EvenStart ((uint32_t)0x00060000)
  190. #define DCMI_ByteSelect_Mode_2of4_EvenStart ((uint32_t)0x00070000)
  191. #define IS_DCMI_BYTESELECT_MODE(MODE) (((MODE) == DCMI_ByteSelect_Mode_AllByte) ||\
  192. ((MODE) == DCMI_ByteSelect_Mode_1of2_OddStart) ||\
  193. ((MODE) == DCMI_ByteSelect_Mode_1of4_OddStart) ||\
  194. ((MODE) == DCMI_ByteSelect_Mode_2of4_OddStart) ||\
  195. ((MODE) == DCMI_ByteSelect_Mode_1of2_EvenStart) ||\
  196. ((MODE) == DCMI_ByteSelect_Mode_1of4_EvenStart) ||\
  197. ((MODE) == DCMI_ByteSelect_Mode_2of4_EvenStart))
  198. /** @defgroup DCMI_ByteSelectMode
  199. * @{
  200. */
  201. #define DCMI_LineSelect_Mode_AllLine ((uint32_t)0x00000000)
  202. #define DCMI_LineSelect_Mode_OddLine ((uint32_t)0x00080000)
  203. #define DCMI_LineSelect_Mode_EvenLine ((uint32_t)0x00180000)
  204. #define IS_DCMI_LINESELECT_MODE(MODE) (((MODE) == DCMI_LineSelect_Mode_AllLine) ||\
  205. ((MODE) == DCMI_LineSelect_Mode_OddLine) ||\
  206. ((MODE) == DCMI_LineSelect_Mode_EvenLine))
  207. /**
  208. * @}
  209. */
  210. /** @defgroup DCMI_DMA_Request_FIFO_Size
  211. * @{
  212. */
  213. #define DCMI_DMARequestFIFOSize_1Word ((uint32_t)0x20000000) /*!< DCMI FIFO����һ���־ͻ����һ��DMARequest*/
  214. #define DCMI_DMARequestFIFOSize_2Word ((uint32_t)0x40000000) /*!< DCMI FIFO���������־ͻ����һ��DMARequest*/
  215. #define DCMI_DMARequestFIFOSize_4Word ((uint32_t)0x80000000) /*!< DCMI FIFO�����ĸ��־ͻ����һ��DMARequest*/
  216. #define DCMI_DMARequestFIFOSize_MSK ((uint32_t)0xE0000000)
  217. #define IS_DCMI_DMAREQUESTFIFO_SIZE(SIZE) (((SIZE) == DCMI_DMARequestFIFOSize_1Word) ||\
  218. ((SIZE) == DCMI_DMARequestFIFOSize_2Word) ||\
  219. ((SIZE) == DCMI_DMARequestFIFOSize_4Word))
  220. /**
  221. * @}
  222. */
  223. /** @defgroup DCMI_interrupt_sources
  224. * @{
  225. */
  226. #define DCMI_IT_FRAME ((uint16_t)0x0001)
  227. #define DCMI_IT_OVF ((uint16_t)0x0002)
  228. #define DCMI_IT_ERR ((uint16_t)0x0004)
  229. #define DCMI_IT_VSYNC ((uint16_t)0x0008)
  230. #define DCMI_IT_LINE ((uint16_t)0x0010)
  231. #define IS_DCMI_CONFIG_IT(IT) ((((IT) & (uint16_t)0xFFE0) == 0x0000) && ((IT) != 0x0000))
  232. #define IS_DCMI_GET_IT(IT) (((IT) == DCMI_IT_FRAME) || \
  233. ((IT) == DCMI_IT_OVF) || \
  234. ((IT) == DCMI_IT_ERR) || \
  235. ((IT) == DCMI_IT_VSYNC) || \
  236. ((IT) == DCMI_IT_LINE))
  237. /**
  238. * @}
  239. */
  240. /** @defgroup DCMI_Flags
  241. * @{
  242. */
  243. /**
  244. * @brief DCMI SR register
  245. */
  246. #define DCMI_FLAG_HSYNC ((uint16_t)0x2001)
  247. #define DCMI_FLAG_VSYNC ((uint16_t)0x2002)
  248. #define DCMI_FLAG_FNE ((uint16_t)0x2004)
  249. /**
  250. * @brief DCMI RISR register
  251. */
  252. #define DCMI_FLAG_FRAMERI ((uint16_t)0x0001)
  253. #define DCMI_FLAG_OVFRI ((uint16_t)0x0002)
  254. #define DCMI_FLAG_ERRRI ((uint16_t)0x0004)
  255. #define DCMI_FLAG_VSYNCRI ((uint16_t)0x0008)
  256. #define DCMI_FLAG_LINERI ((uint16_t)0x0010)
  257. /**
  258. * @brief DCMI MISR register
  259. */
  260. #define DCMI_FLAG_FRAMEMI ((uint16_t)0x1001)
  261. #define DCMI_FLAG_OVFMI ((uint16_t)0x1002)
  262. #define DCMI_FLAG_ERRMI ((uint16_t)0x1004)
  263. #define DCMI_FLAG_VSYNCMI ((uint16_t)0x1008)
  264. #define DCMI_FLAG_LINEMI ((uint16_t)0x1010)
  265. #define IS_DCMI_GET_FLAG(FLAG) (((FLAG) == DCMI_FLAG_HSYNC) || \
  266. ((FLAG) == DCMI_FLAG_VSYNC) || \
  267. ((FLAG) == DCMI_FLAG_FNE) || \
  268. ((FLAG) == DCMI_FLAG_FRAMERI) || \
  269. ((FLAG) == DCMI_FLAG_OVFRI) || \
  270. ((FLAG) == DCMI_FLAG_ERRRI) || \
  271. ((FLAG) == DCMI_FLAG_VSYNCRI) || \
  272. ((FLAG) == DCMI_FLAG_LINERI) || \
  273. ((FLAG) == DCMI_FLAG_FRAMEMI) || \
  274. ((FLAG) == DCMI_FLAG_OVFMI) || \
  275. ((FLAG) == DCMI_FLAG_ERRMI) || \
  276. ((FLAG) == DCMI_FLAG_VSYNCMI) || \
  277. ((FLAG) == DCMI_FLAG_LINEMI))
  278. #define IS_DCMI_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFE0) == 0x0000) && ((FLAG) != 0x0000))
  279. /**
  280. * @brief set dcmi input from out signal
  281. */
  282. #define DCMI_FROM_OUT (0x1<<13)
  283. /* Function used to set the DCMI configuration to the default reset state ****/
  284. void DCMI_DeInit(void);
  285. /* Initialization and Configuration functions *********************************/
  286. void DCMI_Init(DCMI_InitTypeDef* DCMI_InitStruct);
  287. void DCMI_StructInit(DCMI_InitTypeDef* DCMI_InitStruct);
  288. void DCMI_CROPConfig(DCMI_CROPInitTypeDef* DCMI_CROPInitStruct);
  289. void DCMI_CROPCmd(FunctionalState NewState);
  290. void DCMI_JPEGCmd(FunctionalState NewState);
  291. void DCMI_SetDMARequsetFIFOSize(uint32_t NewFIFOSize);
  292. void DCMI_SetExtInput(void);
  293. /* Image capture functions ****************************************************/
  294. void DCMI_Cmd(FunctionalState NewState);
  295. void DCMI_CaptureCmd(FunctionalState NewState);
  296. uint32_t DCMI_ReadData(void);
  297. uint32_t DCMI_GetFIFODataWordNum(void);
  298. /* Interrupts and flags management functions **********************************/
  299. void DCMI_ITConfig(uint16_t DCMI_IT, FunctionalState NewState);
  300. FlagStatus DCMI_GetFlagStatus(uint16_t DCMI_FLAG);
  301. void DCMI_ClearFlag(uint16_t DCMI_FLAG);
  302. ITStatus DCMI_GetITStatus(uint16_t DCMI_IT);
  303. void DCMI_ClearITPendingBit(uint16_t DCMI_IT);
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307. #endif /*__AIR105_DCMI_H */