gd32f3x0_cec.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*!
  2. \file gd32f3x0_cec.h
  3. \brief definitions for the CEC
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #ifdef GD32F350
  10. #ifndef GD32F3X0_CEC_H
  11. #define GD32F3X0_CEC_H
  12. #include "gd32f3x0.h"
  13. /* CEC definitions */
  14. #define CEC CEC_BASE /*!< CEC base address */
  15. /* registers definitions */
  16. #define CEC_CTL REG32(CEC + 0x00U) /*!< CEC control register */
  17. #define CEC_CFG REG32(CEC + 0x04U) /*!< CEC configuration register */
  18. #define CEC_TDATA REG32(CEC + 0x08U) /*!< CEC transmit data register */
  19. #define CEC_RDATA REG32(CEC + 0x0CU) /*!< CEC receive data register */
  20. #define CEC_INTF REG32(CEC + 0x10U) /*!< CEC interrupt flag Register */
  21. #define CEC_INTEN REG32(CEC + 0x14U) /*!< CEC interrupt enable register */
  22. /* bits definitions */
  23. /* CEC_CTL */
  24. #define CEC_CTL_CECEN BIT(0) /*!< enable or disable HDMI-CEC controller bit */
  25. #define CEC_CTL_STAOM BIT(1) /*!< start of sending a message. */
  26. #define CEC_CTL_ENDOM BIT(2) /*!< ENDOM bit value in the next frame in Tx mode */
  27. /* CEC_CFG */
  28. #define CEC_CFG_SFT BITS(0,2) /*!< signal free time */
  29. #define CEC_CFG_RTOL BIT(3) /*!< reception bit timing tolerance */
  30. #define CEC_CFG_BRES BIT(4) /*!< whether stop receive message when detected BRE */
  31. #define CEC_CFG_BREG BIT(5) /*!< generate Error-bit when detected BRE in singlecast */
  32. #define CEC_CFG_BPLEG BIT(6) /*!< generate Error-bit when detected BPLE in singlecast */
  33. #define CEC_CFG_BCNG BIT(7) /*!< do not generate Error-bit in broadcast message */
  34. #define CEC_CFG_SFTOPT BIT(8) /*!< the SFT start option bit */
  35. #define CEC_CFG_OWN_ADDRESS BITS(16,30) /*!< own address */
  36. #define CEC_CFG_LMEN BIT(31) /*!< listen mode enable bit */
  37. /* CEC_TDATA */
  38. #define CEC_TDATA_TDATA BITS(0,7) /*!< Tx data register */
  39. /* CEC_RDATA */
  40. #define CEC_RDATA_RDATA BITS(0,7) /*!< Rx data register */
  41. /* CEC_INTF */
  42. #define CEC_INTF_BR BIT(0) /*!< Rx-byte data received */
  43. #define CEC_INTF_REND BIT(1) /*!< end of reception */
  44. #define CEC_INTF_RO BIT(2) /*!< Rx overrun */
  45. #define CEC_INTF_BRE BIT(3) /*!< bit rising error */
  46. #define CEC_INTF_BPSE BIT(4) /*!< short bit period error */
  47. #define CEC_INTF_BPLE BIT(5) /*!< long bit period error */
  48. #define CEC_INTF_RAE BIT(6) /*!< Rx ACK error */
  49. #define CEC_INTF_ARBF BIT(7) /*!< arbitration fail */
  50. #define CEC_INTF_TBR BIT(8) /*!< Tx-byte data request */
  51. #define CEC_INTF_TEND BIT(9) /*!< transmission successfully end */
  52. #define CEC_INTF_TU BIT(10) /*!< Tx data buffer underrun */
  53. #define CEC_INTF_TERR BIT(11) /*!< Tx-error */
  54. #define CEC_INTF_TAERR BIT(12) /*!< Tx ACK error flag */
  55. /* CEC_INTEN */
  56. #define CEC_INTEN_BRIE BIT(0) /*!< BR interrupt enable */
  57. #define CEC_INTEN_RENDIE BIT(1) /*!< REND interrupt enable */
  58. #define CEC_INTEN_ROIE BIT(2) /*!< RO interrupt enable */
  59. #define CEC_INTEN_BREIE BIT(3) /*!< BRE interrupt enable. */
  60. #define CEC_INTEN_BPSEIE BIT(4) /*!< BPSE interrupt enable */
  61. #define CEC_INTEN_BPLEIE BIT(5) /*!< BPLE interrupt enable. */
  62. #define CEC_INTEN_RAEIE BIT(6) /*!< RAE interrupt enable */
  63. #define CEC_INTEN_ARBFIE BIT(7) /*!< ARBF interrupt enable */
  64. #define CEC_INTEN_TBRIE BIT(8) /*!< TBR interrupt enable */
  65. #define CEC_INTEN_TENDIE BIT(9) /*!< TEND interrupt enable */
  66. #define CEC_INTEN_TUIE BIT(10) /*!< TU interrupt enable */
  67. #define CEC_INTEN_TERRIE BIT(11) /*!< TE interrupt enable */
  68. #define CEC_INTEN_TAERRIE BIT(12) /*!< TAE interrupt enable */
  69. /* constants definitions */
  70. /* signal free time */
  71. #define CFG_SFT(regval) (BITS(0, 2) & ((regval) << 0U))
  72. #define CEC_SFT_PROTOCOL_PERIOD CFG_SFT(0) /*!< the signal free time will perform as HDMI-CEC protocol description */
  73. #define CEC_SFT_1POINT5_PERIOD CFG_SFT(1) /*!< 1.5 nominal data bit periods */
  74. #define CEC_SFT_2POINT5_PERIOD CFG_SFT(2) /*!< 2.5 nominal data bit periods */
  75. #define CEC_SFT_3POINT5_PERIOD CFG_SFT(3) /*!< 3.5 nominal data bit periods */
  76. #define CEC_SFT_4POINT5_PERIOD CFG_SFT(4) /*!< 4.5 nominal data bit periods */
  77. #define CEC_SFT_5POINT5_PERIOD CFG_SFT(5) /*!< 5.5 nominal data bit periods */
  78. #define CEC_SFT_6POINT5_PERIOD CFG_SFT(6) /*!< 6.5 nominal data bit periods */
  79. #define CEC_SFT_7POINT5_PERIOD CFG_SFT(7) /*!< 7.5 nominal data bit periods */
  80. /* signal free time start option */
  81. #define CEC_SFT_START_STAOM ((uint32_t)0x00000000U) /*!< signal free time counter starts counting when STAOM is asserted */
  82. #define CEC_SFT_START_LAST CEC_CFG_SFTOPT /*!< signal free time counter starts automatically after transmission/reception end */
  83. /* own address */
  84. #define CEC_OWN_ADDRESS_CLEAR ((uint32_t)0x00000000U) /*!< own address is cleared */
  85. #define CEC_OWN_ADDRESS0 BIT(16) /*!< own address is 0 */
  86. #define CEC_OWN_ADDRESS1 BIT(17) /*!< own address is 1 */
  87. #define CEC_OWN_ADDRESS2 BIT(18) /*!< own address is 2 */
  88. #define CEC_OWN_ADDRESS3 BIT(19) /*!< own address is 3 */
  89. #define CEC_OWN_ADDRESS4 BIT(20) /*!< own address is 4 */
  90. #define CEC_OWN_ADDRESS5 BIT(21) /*!< own address is 5 */
  91. #define CEC_OWN_ADDRESS6 BIT(22) /*!< own address is 6 */
  92. #define CEC_OWN_ADDRESS7 BIT(23) /*!< own address is 7 */
  93. #define CEC_OWN_ADDRESS8 BIT(24) /*!< own address is 8 */
  94. #define CEC_OWN_ADDRESS9 BIT(25) /*!< own address is 9 */
  95. #define CEC_OWN_ADDRESS10 BIT(26) /*!< own address is 10 */
  96. #define CEC_OWN_ADDRESS11 BIT(27) /*!< own address is 11 */
  97. #define CEC_OWN_ADDRESS12 BIT(28) /*!< own address is 12 */
  98. #define CEC_OWN_ADDRESS13 BIT(29) /*!< own address is 13 */
  99. #define CEC_OWN_ADDRESS14 BIT(30) /*!< own address is 14 */
  100. /* error-bit generate */
  101. #define CEC_BROADCAST_ERROR_BIT_ON ((uint32_t)0x00000000U) /*!< generate Error-bit in broadcast */
  102. #define CEC_BROADCAST_ERROR_BIT_OFF CEC_CFG_BCNG /*!< do not generate Error-bit in broadcast */
  103. #define CEC_LONG_PERIOD_ERROR_BIT_OFF ((uint32_t)0x00000000U) /*!< generate Error-bit on long bit period error */
  104. #define CEC_LONG_PERIOD_ERROR_BIT_ON CEC_CFG_BPLEG /*!< do not generate Error-bit on long bit period error */
  105. #define CEC_RISING_PERIOD_ERROR_BIT_OFF ((uint32_t)0x00000000U) /*!< generate Error-bit on bit rising error */
  106. #define CEC_RISING_PERIOD_ERROR_BIT_ON CEC_CFG_BREG /*!< do not generate Error-bit on bit rising error */
  107. /* whether stop receive message when detected bit rising error */
  108. #define CEC_STOP_RISING_ERROR_BIT_ON ((uint32_t)0x00000000U) /*!< stop reception when detected bit rising error */
  109. #define CEC_STOP_RISING_ERROR_BIT_OFF ((uint32_t)0x00000001U) /*!< do not stop reception when detected bit rising error */
  110. /* flag bits */
  111. #define CEC_FLAG_BR CEC_INTF_BR /*!< RX-byte data received */
  112. #define CEC_FLAG_REND CEC_INTF_REND /*!< end of reception */
  113. #define CEC_FLAG_RO CEC_INTF_RO /*!< RX overrun */
  114. #define CEC_FLAG_BRE CEC_INTF_BRE /*!< bit rising error */
  115. #define CEC_FLAG_BPSE CEC_INTF_BPSE /*!< short bit period error */
  116. #define CEC_FLAG_BPLE CEC_INTF_BPLE /*!< long bit period error */
  117. #define CEC_FLAG_RAE CEC_INTF_RAE /*!< RX ACK error */
  118. #define CEC_FLAG_ARBF CEC_INTF_ARBF /*!< arbitration lost */
  119. #define CEC_FLAG_TBR CEC_INTF_TBR /*!< TX-byte data request */
  120. #define CEC_FLAG_TEND CEC_INTF_TEND /*!< transmission successfully end */
  121. #define CEC_FLAG_TU CEC_INTF_TU /*!< TX data buffer underrun */
  122. #define CEC_FLAG_TERR CEC_INTF_TERR /*!< TX-error */
  123. #define CEC_FLAG_TAERR CEC_INTF_TAERR /*!< TX ACK error flag */
  124. /* interrupt flag bits */
  125. #define CEC_INT_FLAG_BR CEC_INTF_BR /*!< RX-byte data received */
  126. #define CEC_INT_FLAG_REND CEC_INTF_REND /*!< end of reception */
  127. #define CEC_INT_FLAG_RO CEC_INTF_RO /*!< RX overrun */
  128. #define CEC_INT_FLAG_BRE CEC_INTF_BRE /*!< bit rising error */
  129. #define CEC_INT_FLAG_BPSE CEC_INTF_BPSE /*!< short bit period error */
  130. #define CEC_INT_FLAG_BPLE CEC_INTF_BPLE /*!< long bit period error */
  131. #define CEC_INT_FLAG_RAE CEC_INTF_RAE /*!< RX ACK error */
  132. #define CEC_INT_FLAG_ARBF CEC_INTF_ARBF /*!< arbitration lost */
  133. #define CEC_INT_FLAG_TBR CEC_INTF_TBR /*!< TX-byte data request */
  134. #define CEC_INT_FLAG_TEND CEC_INTF_TEND /*!< transmission successfully end */
  135. #define CEC_INT_FLAG_TU CEC_INTF_TU /*!< TX data buffer underrun */
  136. #define CEC_INT_FLAG_TERR CEC_INTF_TERR /*!< TX-error */
  137. #define CEC_INT_FLAG_TAERR CEC_INTF_TAERR /*!< TX ACK error flag */
  138. /* interrupt enable bits */
  139. #define CEC_INT_BR CEC_INTEN_BRIE /*!< RBR interrupt enable */
  140. #define CEC_INT_REND CEC_INTEN_RENDIE /*!< REND interrupt enable */
  141. #define CEC_INT_RO CEC_INTEN_ROIE /*!< RO interrupt enable */
  142. #define CEC_INT_BRE CEC_INTEN_BREIE /*!< RBRE interrupt enable. */
  143. #define CEC_INT_BPSE CEC_INTEN_BPSEIE /*!< RSBPE interrupt enable */
  144. #define CEC_INT_BPLE CEC_INTEN_BPLEIE /*!< RLBPE interrupt enable. */
  145. #define CEC_INT_RAE CEC_INTEN_RAEIE /*!< RAE interrupt enable */
  146. #define CEC_INT_ARBF CEC_INTEN_ARBFIE /*!< ALRLST interrupt enable */
  147. #define CEC_INT_TBR CEC_INTEN_TBRIE /*!< TBR interrupt enable */
  148. #define CEC_INT_TEND CEC_INTEN_TENDIE /*!< TEND interrupt enable */
  149. #define CEC_INT_TU CEC_INTEN_TUIE /*!< TU interrupt enable */
  150. #define CEC_INT_TERR CEC_INTEN_TERRIE /*!< TE interrupt enable */
  151. #define CEC_INT_TAERR CEC_INTEN_TAERRIE /*!< TAE interrupt enable */
  152. /* function declarations */
  153. /* reset HDMI-CEC controller */
  154. void cec_deinit(void);
  155. /* configure signal free time,the signal free time counter start option,own address */
  156. void cec_init(uint32_t sftmopt, uint32_t sft, uint32_t address);
  157. /* configure generate Error-bit, whether stop receive message when detected bit rising error */
  158. void cec_error_config(uint32_t broadcast, uint32_t singlecast_lbpe, uint32_t singlecast_bre, uint32_t rxbrestp);
  159. /* enable HDMI-CEC controller */
  160. void cec_enable(void);
  161. /* disable HDMI-CEC controller */
  162. void cec_disable(void);
  163. /* start CEC message transmission */
  164. void cec_transmission_start(void);
  165. /* end CEC message transmission */
  166. void cec_transmission_end(void);
  167. /* enable CEC listen mode */
  168. void cec_listen_mode_enable(void);
  169. /* disable CEC listen mode */
  170. void cec_listen_mode_disable(void);
  171. /* configure and clear own address */
  172. void cec_own_address_config(uint32_t address);
  173. /* configure signal free time and the signal free time counter start option */
  174. void cec_sft_config(uint32_t sftmopt,uint32_t sft);
  175. /* configure generate Error-bit when detected some abnormal situation or not */
  176. void cec_generate_errorbit_config(uint32_t broadcast, uint32_t singlecast_lbpe, uint32_t singlecast_bre);
  177. /* whether stop receive message when detected bit rising error */
  178. void cec_stop_receive_bre_config(uint32_t rxbrestp);
  179. /* enable reception bit timing tolerance */
  180. void cec_reception_tolerance_enable(void);
  181. /* disable reception bit timing tolerance */
  182. void cec_reception_tolerance_disable(void);
  183. /* send a data by the CEC peripheral */
  184. void cec_data_send(uint8_t data);
  185. /* receive a data by the CEC peripheral */
  186. uint8_t cec_data_receive(void);
  187. /* clear CEC int flag and status */
  188. FlagStatus cec_interrupt_flag_get(uint32_t flag);
  189. /* clear CEC flag */
  190. void cec_interrupt_flag_clear(uint32_t flag);
  191. /* enable interrupt */
  192. void cec_interrupt_enable(uint32_t flag);
  193. /* disable interrupt */
  194. void cec_interrupt_disable(uint32_t flag);
  195. /* get CEC status */
  196. FlagStatus cec_flag_get(uint32_t flag);
  197. /* clear CEC status */
  198. void cec_flag_clear(uint32_t flag);
  199. #endif /* GD32F3X0_CEC_H */
  200. #endif /* GD32F350 */