hpm_gwc_drv.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_GWC_DRV_H
  8. #define HPM_GWC_DRV_H
  9. /**
  10. * @brief GWC APIs
  11. * @defgroup gwc_interface GWC driver APIs
  12. * @ingroup gwc_interfaces
  13. * @{
  14. */
  15. #include "hpm_common.h"
  16. #include "hpm_soc.h"
  17. #include "hpm_gwc_regs.h"
  18. /**
  19. * @brief gwc channel config
  20. *
  21. * @note area of channel do not overlap. in other words, eache pixel belongs to a single channel at most.
  22. */
  23. typedef struct gwc_ch_config {
  24. bool freeze; /*!< freeze the channel configuration except reference CRC32 value setting. */
  25. uint16_t start_col; /*!< start col is X of upper left corner. Range: 0 to 2^13-1. */
  26. uint16_t start_row; /*!< start row is Y of upper left corner. Range: 0 to 2^12-1. */
  27. uint16_t end_col; /*!< end col is X of lower right corner. Range: 0 to 2^13-1. */
  28. uint16_t end_row; /*!< end row is Y of lower right corner. Range: 0 to 2^12-1. */
  29. uint32_t ref_crc; /*!< Reference CRC32 value.*/
  30. } gwc_ch_config_t;
  31. /**
  32. * @brief gwc clk polarity
  33. */
  34. typedef enum gwc_clk_pol {
  35. gwc_clk_pol_normal = 0,
  36. gwc_clk_pol_invert
  37. } gwc_clk_pol_t;
  38. /**
  39. * @brief gwc config
  40. */
  41. typedef struct gwc_config {
  42. gwc_clk_pol_t clk_pol;
  43. } gwc_config_t;
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /**
  48. * @brief init the gwc
  49. *
  50. * @param[in] cfg GWC config @ref gwc_config_t
  51. */
  52. void gwc_get_default_config(gwc_config_t *cfg);
  53. /**
  54. * @brief init the gwc
  55. *
  56. * @param[in] ptr GWC base address
  57. * @param[in] cfg GWC config @ref gwc_config_t
  58. *
  59. * @note the function is called while gwc is disable only
  60. */
  61. void gwc_init(GWC_Type *ptr, gwc_config_t *cfg);
  62. /**
  63. * @brief enable the gwc
  64. *
  65. * @param[in] ptr GWC base address
  66. */
  67. void gwc_enable(GWC_Type *ptr);
  68. /**
  69. * @brief disable the gwc
  70. *
  71. * @param[in] ptr GWC base address
  72. */
  73. void gwc_disable(GWC_Type *ptr);
  74. /**
  75. * @brief enable interrupts
  76. *
  77. * @param[in] ptr GWC base address
  78. * @param[in] mask Mask of interrupt events that would be enabled
  79. * @ref GWC_IRQ_MASK_ERR_MASK_MASK
  80. * @ref GWC_IRQ_MASK_FUNC_MASK_MASK
  81. */
  82. static inline void gwc_enable_interrupt(GWC_Type *ptr, uint32_t mask)
  83. {
  84. ptr->IRQ_MASK &= ~mask;
  85. }
  86. /**
  87. * @brief disable interrupts.
  88. *
  89. * @param[in] ptr GWC base address
  90. * @param[in] mask mask of interrupt events that would be enabled.
  91. * @ref GWC_IRQ_MASK_ERR_MASK_MASK
  92. * @ref GWC_IRQ_MASK_FUNC_MASK_MASK
  93. */
  94. static inline void gwc_disable_interrupt(GWC_Type *ptr, uint32_t mask)
  95. {
  96. ptr->IRQ_MASK |= mask;
  97. }
  98. /**
  99. * @brief get gwc status flag
  100. *
  101. * @param[in] ptr GWC base address
  102. * @return gwc status
  103. */
  104. static inline uint32_t gwc_get_status(GWC_Type *ptr)
  105. {
  106. return ptr->IRQ_STS;
  107. }
  108. /**
  109. * @brief clear gwc status flag
  110. *
  111. * @param[in] ptr GWC base address
  112. * @param[in] mask logical OR'ed of GWC_IRQ_STS_XXX_STS_MASK
  113. */
  114. static inline void gwc_clear_status(GWC_Type *ptr, uint32_t mask)
  115. {
  116. ptr->IRQ_STS = mask;
  117. }
  118. /**
  119. * @brief disable change of interrupt masks
  120. *
  121. * Once this function is called, the interrupt enabled status could not be changed
  122. * until reset.
  123. *
  124. * @param[in] ptr GWC base address
  125. */
  126. void gwc_freeze_interrupt_control(GWC_Type *ptr);
  127. /**
  128. * @brief init gwc channel
  129. *
  130. * @param[in] ptr GWC base address
  131. * @param[in] ch_index channel index ref GWC_CHANNEL_CHn
  132. * @param[in] cfg config of gwc channel
  133. *
  134. * @note the function is called while gwc channel is disable only
  135. */
  136. void gwc_ch_init(GWC_Type *ptr, uint8_t ch_index, gwc_ch_config_t *cfg);
  137. /**
  138. * @brief enable gwc channel
  139. *
  140. * @param[in] ptr GWC base address
  141. * @param[in] ch_index channel index ref GWC_CHANNEL_CHn
  142. */
  143. static inline void gwc_ch_enable(GWC_Type *ptr, uint8_t ch_index)
  144. {
  145. assert(ch_index <= GWC_CHANNEL_CH15);
  146. ptr->CHANNEL[ch_index].CFG0 |= GWC_CHANNEL_CFG0_ENABLE_MASK;
  147. }
  148. /**
  149. * @brief disable gwc channel
  150. *
  151. * @param[in] ptr GWC base address
  152. * @param[in] ch_index channel index ref GWC_CHANNEL_CHn
  153. */
  154. static inline void gwc_ch_disable(GWC_Type *ptr, uint8_t ch_index)
  155. {
  156. assert(ch_index <= GWC_CHANNEL_CH15);
  157. ptr->CHANNEL[ch_index].CFG0 &= ~GWC_CHANNEL_CFG0_ENABLE_MASK;
  158. }
  159. /**
  160. * @brief get gwc channel calc crc
  161. *
  162. * @param[in] ptr GWC base address
  163. * @param[in] ch_index channel index ref GWC_CHANNEL_CHn
  164. */
  165. static inline uint32_t gwc_ch_get_crc(GWC_Type *ptr, uint8_t ch_index)
  166. {
  167. assert(ch_index <= GWC_CHANNEL_CH15);
  168. return ptr->CHANNEL[ch_index].CALCRC;
  169. }
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. /**
  174. * @}
  175. */
  176. #endif /* HPM_GWC_DRV_H */