hc32_ll_dcu.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_dcu.h
  4. * @brief This file contains all the functions prototypes of the DCU(Data
  5. * Computing Unit) driver library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2022-12-31 CDT First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by XHSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32_LL_DCU_H__
  22. #define __HC32_LL_DCU_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_ll_def.h"
  32. #include "hc32f4xx.h"
  33. #include "hc32f4xx_conf.h"
  34. /**
  35. * @addtogroup LL_Driver
  36. * @{
  37. */
  38. /**
  39. * @addtogroup LL_DCU
  40. * @{
  41. */
  42. #if (LL_DCU_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup DCU_Global_Types DCU Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief DCU initialization structure definition
  52. */
  53. typedef struct {
  54. uint32_t u32Mode; /*!< Specifies DCU operation.
  55. This parameter can be a value of @ref DCU_Mode */
  56. uint32_t u32DataWidth; /*!< Specifies DCU data width.
  57. This parameter can be a value of @ref DCU_Data_Width */
  58. } stc_dcu_init_t;
  59. /**
  60. * @brief DCU wave output configure structure definition
  61. */
  62. typedef struct {
  63. uint32_t u32LowerLimit; /*!< Defines the wave lower limit of the wave amplitude.
  64. This parameter can be a value between Min_Data = 0 and Max_Data = 0xFFF */
  65. uint32_t u32UpperLimit; /*!< Defines the upper limit of the wave amplitude.
  66. This parameter can be a value between Min_Data = 0 and Max_Data = 0xFFF */
  67. uint32_t u32Step; /*!< Defines the increasing/decreasing step.
  68. This parameter can be a value between Min_Data = 0 and Max_Data = 0xFFF */
  69. } stc_dcu_wave_config_t;
  70. /**
  71. * @}
  72. */
  73. /*******************************************************************************
  74. * Global pre-processor symbols/macros ('#define')
  75. ******************************************************************************/
  76. /**
  77. * @defgroup DCU_Global_Macros DCU Global Macros
  78. * @{
  79. */
  80. /**
  81. * @defgroup DCU_Data_Width DCU Data Width
  82. * @{
  83. */
  84. #define DCU_DATA_WIDTH_8BIT (0UL) /*!< DCU data width: 8 bit */
  85. #define DCU_DATA_WIDTH_16BIT (DCU_CTL_DATASIZE_0) /*!< DCU data width: 16 bit */
  86. #define DCU_DATA_WIDTH_32BIT (DCU_CTL_DATASIZE_1) /*!< DCU data width: 32 bit */
  87. /**
  88. * @}
  89. */
  90. /**
  91. * @defgroup DCU_Compare_Trigger_Condition DCU Compare Trigger Condition
  92. * @{
  93. */
  94. #define DCU_CMP_TRIG_DATA0 (0UL) /*!< DCU compare triggered by DATA0 */
  95. #define DCU_CMP_TRIG_DATA0_DATA1_DATA2 (DCU_CTL_COMP_TRG) /*!< DCU compare triggered by DATA0 or DATA1 or DATA2 */
  96. /**
  97. * @}
  98. */
  99. /**
  100. * @defgroup DCU_Mode DCU Mode
  101. * @{
  102. */
  103. #define DCU_MD_INVD (0UL) /*!< DCU invalid */
  104. #define DCU_MD_ADD (1UL) /*!< DCU add operation */
  105. #define DCU_MD_SUB (2UL) /*!< DCU sub operation */
  106. #define DCU_MD_HW_ADD (3UL) /*!< DCU hardware trigger add */
  107. #define DCU_MD_HW_SUB (4UL) /*!< DCU hardware trigger sub */
  108. #define DCU_MD_CMP (5UL) /*!< DCU compare */
  109. #define DCU_MD_TRIANGLE_WAVE (8UL) /*!< DCU triangle wave output mode */
  110. #define DCU_MD_SAWTOOTH_WAVE_INC (9UL) /*!< DCU increasing sawtooth wave output mode */
  111. #define DCU_MD_SAWTOOTH_WAVE_DEC (10UL) /*!< DCU decreasing sawtooth wave output mode */
  112. /**
  113. * @}
  114. */
  115. /**
  116. * @defgroup DCU_Flag DCU Flag
  117. * @{
  118. */
  119. #define DCU_FLAG_CARRY (DCU_FLAG_FLAG_OP) /*!< DCU addition overflow or subtraction underflow flag */
  120. #define DCU_FLAG_DATA0_LT_DATA2 (DCU_FLAG_FLAG_LS2) /*!< DCU DATA0 < DATA2 flag */
  121. #define DCU_FLAG_DATA0_EQ_DATA2 (DCU_FLAG_FLAG_EQ2) /*!< DCU DATA0 = DATA2 flag */
  122. #define DCU_FLAG_DATA0_GT_DATA2 (DCU_FLAG_FLAG_GT2) /*!< DCU DATA0 > DATA2 flag */
  123. #define DCU_FLAG_DATA0_LT_DATA1 (DCU_FLAG_FLAG_LS1) /*!< DCU DATA0 < DATA1 flag */
  124. #define DCU_FLAG_DATA0_EQ_DATA1 (DCU_FLAG_FLAG_EQ1) /*!< DCU DATA0 = DATA1 flag */
  125. #define DCU_FLAG_DATA0_GT_DATA1 (DCU_FLAG_FLAG_GT1) /*!< DCU DATA0 > DATA1 flag */
  126. #define DCU_FLAG_SAWTOOTH_WAVE_RELOAD (DCU_FLAG_FLAG_RLD) /*!< DCU sawtooth wave mode reload interrupt */
  127. #define DCU_FLAG_TRIANGLE_WAVE_BOTTOM (DCU_FLAG_FLAG_BTM) /*!< DCU triangle wave mode bottom interrupt */
  128. #define DCU_FLAG_TRIANGLE_WAVE_TOP (DCU_FLAG_FLAG_TOP) /*!< DCU triangle wave mode top interrupt */
  129. #define DCU_FLAG_ALL (0x00000E7FUL)
  130. /**
  131. * @}
  132. */
  133. /**
  134. * @defgroup DCU_Category DCU Category
  135. * @{
  136. */
  137. #define DCU_CATEGORY_OP (0UL) /*!< DCU operation result(overflow/underflow) */
  138. #define DCU_CATEGORY_CMP_WIN (1UL) /*!< DCU comparison(window) */
  139. #define DCU_CATEGORY_CMP_NON_WIN (2UL) /*!< DCU comparison(non-window) */
  140. #define DCU_CATEGORY_WAVE (3UL) /*!< DCU wave mode(sawtooth/triangle wave) */
  141. /**
  142. * @}
  143. */
  144. /**
  145. * @defgroup DCU_Interrupt_Type DCU Interrupt Type
  146. * @{
  147. */
  148. /**
  149. * @defgroup DCU_Compare_Interrupt DCU Compare(Non-window) Interrupt
  150. * @note Interrupt type DCU_Compare_Interrupt is valid when only select DCU_CATEGORY_CMP_NON_WIN
  151. * @{
  152. */
  153. #define DCU_INT_CMP_DATA0_LT_DATA2 (DCU_INTEVTSEL_SEL_LS2) /*!< DCU DATA0 < DATA2 interrupt */
  154. #define DCU_INT_CMP_DATA0_EQ_DATA2 (DCU_INTEVTSEL_SEL_EQ2) /*!< DCU DATA0 = DATA2 interrupt */
  155. #define DCU_INT_CMP_DATA0_GT_DATA2 (DCU_INTEVTSEL_SEL_GT2) /*!< DCU DATA0 > DATA2 interrupt */
  156. #define DCU_INT_CMP_DATA0_LT_DATA1 (DCU_INTEVTSEL_SEL_LS1) /*!< DCU DATA0 < DATA1 interrupt */
  157. #define DCU_INT_CMP_DATA0_EQ_DATA1 (DCU_INTEVTSEL_SEL_EQ1) /*!< DCU DATA0 = DATA1 interrupt */
  158. #define DCU_INT_CMP_DATA0_GT_DATA1 (DCU_INTEVTSEL_SEL_GT1) /*!< DCU DATA0 > DATA1 interrupt */
  159. #define DCU_INT_CMP_NON_WIN_ALL (DCU_INT_CMP_DATA0_LT_DATA2 | \
  160. DCU_INT_CMP_DATA0_EQ_DATA2 | \
  161. DCU_INT_CMP_DATA0_GT_DATA2 | \
  162. DCU_INT_CMP_DATA0_LT_DATA1 | \
  163. DCU_INT_CMP_DATA0_EQ_DATA1 | \
  164. DCU_INT_CMP_DATA0_GT_DATA1)
  165. /**
  166. * @}
  167. */
  168. /**
  169. * @defgroup DCU_Window_Compare_Interrupt DCU Window Compare Interrupt
  170. * @note Interrupt type DCU_Window_Compare_Interrupt is valid when only select DCU_CATEGORY_CMP_WIN
  171. * @{
  172. */
  173. #define DCU_INT_CMP_WIN_INSIDE (DCU_INTEVTSEL_SEL_WIN_0) /*!< DCU comparison(DATA2 <= DATA0 <= DATA1) interrupt */
  174. #define DCU_INT_CMP_WIN_OUTSIDE (DCU_INTEVTSEL_SEL_WIN_1) /*!< DCU comparison(DATA0 < DATA2 & DATA0 > DATA1 ) interrupt */
  175. #define DCU_INT_CMP_WIN_ALL (DCU_INT_CMP_WIN_INSIDE | DCU_INT_CMP_WIN_OUTSIDE)
  176. /**
  177. * @}
  178. */
  179. /**
  180. * @defgroup DCU_Operation_Interrupt DCU Operation Interrupt
  181. * @note DCU_Window_Compare_Interrupt selection is valid when only select DCU_CATEGORY_OP
  182. * @{
  183. */
  184. #define DCU_INT_OP_CARRY (DCU_INTEVTSEL_SEL_OP) /*!< DCU addition overflow or subtraction underflow interrupt */
  185. /**
  186. * @}
  187. */
  188. /**
  189. * @defgroup DCU_Wave_Mode_Interrupt DCU Wave Mode Interrupt
  190. * @note Interrupt type DCU_Wave_Mode_Interrupt is valid when only select DCU_CATEGORY_WAVE
  191. * @{
  192. */
  193. #define DCU_INT_SAWTOOTH_WAVE_RELOAD (DCU_INTEVTSEL_SEL_RLD) /*!< DCU sawtooth wave mode reload interrupt */
  194. #define DCU_INT_TRIANGLE_WAVE_BOTTOM (DCU_INTEVTSEL_SEL_BTM) /*!< DCU triangle wave mode bottom interrupt */
  195. #define DCU_INT_TRIANGLE_WAVE_TOP (DCU_INTEVTSEL_SEL_TOP) /*!< DCU triangle wave mode top interrupt */
  196. #define DCU_INT_WAVE_MD_ALL (DCU_INT_TRIANGLE_WAVE_TOP | \
  197. DCU_INT_TRIANGLE_WAVE_BOTTOM | \
  198. DCU_INT_SAWTOOTH_WAVE_RELOAD)
  199. /**
  200. * @}
  201. */
  202. /**
  203. * @}
  204. */
  205. /**
  206. * @defgroup DCU_Data_Register_Index DCU Data Register Index
  207. * @{
  208. */
  209. #define DCU_DATA0_IDX (0UL) /*!< DCU DATA0 */
  210. #define DCU_DATA1_IDX (1UL) /*!< DCU DATA1 */
  211. #define DCU_DATA2_IDX (2UL) /*!< DCU DATA2 */
  212. /**
  213. * @}
  214. */
  215. /**
  216. * @}
  217. */
  218. /*******************************************************************************
  219. * Global variable definitions ('extern')
  220. ******************************************************************************/
  221. /*******************************************************************************
  222. Global function prototypes (definition in C source)
  223. ******************************************************************************/
  224. /**
  225. * @addtogroup DCU_Global_Functions
  226. * @{
  227. */
  228. /* Initialization and configuration functions */
  229. int32_t DCU_Init(CM_DCU_TypeDef *DCUx, const stc_dcu_init_t *pstcDcuInit);
  230. int32_t DCU_StructInit(stc_dcu_init_t *pstcDcuInit);
  231. int32_t DCU_DeInit(CM_DCU_TypeDef *DCUx);
  232. int32_t DCU_WaveConfig(CM_DCU_TypeDef *DCUx, const stc_dcu_wave_config_t *pstcWaveconfig);
  233. void DCU_SetMode(CM_DCU_TypeDef *DCUx, uint32_t u32Mode);
  234. void DCU_SetDataWidth(CM_DCU_TypeDef *DCUx, uint32_t u32DataWidth);
  235. void DCU_SetCompareCond(CM_DCU_TypeDef *DCUx, uint32_t u32Cond);
  236. /* Interrupt and flag management functions */
  237. en_flag_status_t DCU_GetStatus(const CM_DCU_TypeDef *DCUx, uint32_t u32Flag);
  238. void DCU_ClearStatus(CM_DCU_TypeDef *DCUx, uint32_t u32Flag);
  239. void DCU_GlobalIntCmd(CM_DCU_TypeDef *DCUx, en_functional_state_t enNewState);
  240. void DCU_IntCmd(CM_DCU_TypeDef *DCUx, uint32_t u32IntCategory, uint32_t u32IntType, en_functional_state_t enNewState);
  241. /* Read and write functions */
  242. uint8_t DCU_ReadData8(const CM_DCU_TypeDef *DCUx, uint32_t u32DataIndex);
  243. void DCU_WriteData8(CM_DCU_TypeDef *DCUx, uint32_t u32DataIndex, uint8_t u8Data);
  244. uint16_t DCU_ReadData16(const CM_DCU_TypeDef *DCUx, uint32_t u32DataIndex);
  245. void DCU_WriteData16(CM_DCU_TypeDef *DCUx, uint32_t u32DataIndex, uint16_t u16Data);
  246. uint32_t DCU_ReadData32(const CM_DCU_TypeDef *DCUx, uint32_t u32DataIndex);
  247. void DCU_WriteData32(CM_DCU_TypeDef *DCUx, uint32_t u32DataIndex, uint32_t u32Data);
  248. /**
  249. * @}
  250. */
  251. #endif /* LL_DCU_ENABLE */
  252. /**
  253. * @}
  254. */
  255. /**
  256. * @}
  257. */
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif /* __HC32_LL_DCU_H__ */
  262. /*******************************************************************************
  263. * EOF (not truncated)
  264. ******************************************************************************/