gd32f1x0_slcd.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*!
  2. \file gd32f1x0_slcd.h
  3. \brief definitions for the SLCD
  4. \version 2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
  5. \version 2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
  6. \version 2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
  7. \version 2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
  8. \version 2019-11-20, V3.2.0, firmware update for GD32F1x0(x=3,5,7,9)
  9. */
  10. /*
  11. Copyright (c) 2019, GigaDevice Semiconductor Inc.
  12. Redistribution and use in source and binary forms, with or without modification,
  13. are permitted provided that the following conditions are met:
  14. 1. Redistributions of source code must retain the above copyright notice, this
  15. list of conditions and the following disclaimer.
  16. 2. Redistributions in binary form must reproduce the above copyright notice,
  17. this list of conditions and the following disclaimer in the documentation
  18. and/or other materials provided with the distribution.
  19. 3. Neither the name of the copyright holder nor the names of its contributors
  20. may be used to endorse or promote products derived from this software without
  21. specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  26. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  31. OF SUCH DAMAGE.
  32. */
  33. #ifdef GD32F170_190
  34. #ifndef GD32F1X0_SLCD_H
  35. #define GD32F1X0_SLCD_H
  36. #include "gd32f1x0.h"
  37. /* SLCD definitions */
  38. #define SLCD SLCD_BASE
  39. /* registers definitions */
  40. #define SLCD_CTL REG32(SLCD + 0x00000000U) /*!< SLCD controller register */
  41. #define SLCD_CFG REG32(SLCD + 0x00000004U) /*!< SLCD configuration register */
  42. #define SLCD_STAT REG32(SLCD + 0x00000008U) /*!< SLCD status flag register */
  43. #define SLCD_STATC REG32(SLCD + 0x0000000CU) /*!< SLCD status flag clear register */
  44. #define SLCD_DATA0 REG32(SLCD + 0x00000014U) /*!< SLCD display data register 0 */
  45. #define SLCD_DATA1 REG32(SLCD + 0x0000001CU) /*!< SLCD display data register 1 */
  46. #define SLCD_DATA2 REG32(SLCD + 0x00000024U) /*!< SLCD display data register 2 */
  47. #define SLCD_DATA3 REG32(SLCD + 0x0000002CU) /*!< SLCD display data register 3 */
  48. #define SLCD_DATA4 REG32(SLCD + 0x00000034U) /*!< SLCD display data register 4 */
  49. #define SLCD_DATA5 REG32(SLCD + 0x0000003CU) /*!< SLCD display data register 5 */
  50. #define SLCD_DATA6 REG32(SLCD + 0x00000044U) /*!< SLCD display data register 6 */
  51. #define SLCD_DATA7 REG32(SLCD + 0x0000004CU) /*!< SLCD display data register 7 */
  52. /* bits definitions */
  53. /* SLCD_CTL */
  54. #define SLCD_CTL_SLCDON BIT(0) /*!< SLCD controller start */
  55. #define SLCD_CTL_VSRC BIT(1) /*!< SLCD Voltage source */
  56. #define SLCD_CTL_DUTY BITS(2,4) /*!< duty select */
  57. #define SLCD_CTL_BIAS BITS(5,6) /*!< SLCD bias voltage select */
  58. #define SLCD_CTL_COMS BIT(7) /*!< regular channel start flag */
  59. /* SLCD_CFG */
  60. #define SLCD_CFG_HDEN BIT(0) /*!< high drive enable */
  61. #define SLCD_CFG_SOFIE BIT(1) /*!< start of frame interrupt enable */
  62. #define SLCD_CFG_UPDIE BIT(3) /*!< SLCD update done interrupt enable */
  63. #define SLCD_CFG_PULSE BITS(4,6) /*!< pulse on duration */
  64. #define SLCD_CFG_DTD BITS(7,9) /*!< dead time duration */
  65. #define SLCD_CFG_CONR BITS(10,12) /*!< contrast ratio */
  66. #define SLCD_CFG_BLKDIV BITS(13,15) /*!< blink frequency divider */
  67. #define SLCD_CFG_BLKMOD BITS(16,17) /*!< blink mode */
  68. #define SLCD_CFG_DIV BITS(18,21) /*!< SLCD clock divider */
  69. #define SLCD_CFG_PSC BITS(22,25) /*!< SLCD clock prescaler */
  70. /* SLCD_STAT */
  71. #define SLCD_STAT_ONF BIT(0) /*!< SLCD controller on flag */
  72. #define SLCD_STAT_SOF BIT(1) /*!< start of frame flag */
  73. #define SLCD_STAT_UPRF BIT(2) /*!< SLCD data update request flag */
  74. #define SLCD_STAT_UPDF BIT(3) /*!< update data done flag */
  75. #define SLCD_STAT_VRDYF BIT(4) /*!< SLCD voltage ready flag */
  76. #define SLCD_STAT_SYNF BIT(5) /*!< SLCD register synchronization flag */
  77. /* SLCD_STATC */
  78. #define SLCD_STATC_SOFC BIT(1) /*!< start of frame flag clear */
  79. #define SLCD_STATC_UPDC BIT(3) /*!< SLCD data update done clear bit */
  80. /* SLCD_DATAx */
  81. #define SLCD_DATAx_DATA BITS(0,31) /*!< each bit corresponds to one segment to display */
  82. /* constants definitions */
  83. /* status flag */
  84. #define SLCD_FLAG_ON SLCD_STAT_ONF /*!< SLCD controller on flag */
  85. #define SLCD_FLAG_SOF SLCD_STAT_SOF /*!< start of frame flag */
  86. #define SLCD_FLAG_UPR SLCD_STAT_UPRF /*!< SLCD data update request flag */
  87. #define SLCD_FLAG_UPD SLCD_STAT_UPDF /*!< update data done flag */
  88. #define SLCD_FLAG_VRDY SLCD_STAT_VRDYF /*!< SLCD voltage ready flag */
  89. #define SLCD_FLAG_SYN SLCD_STAT_SYNF /*!< SLCD register synchronization flag */
  90. /* interrupt flag */
  91. #define SLCD_INT_FLAG_SOF ((uint8_t)0x00U) /*!< start of frame interrupt */
  92. #define SLCD_INT_FLAG_UPD ((uint8_t)0x01U) /*!< update data done interrupt */
  93. /* interrupt source */
  94. #define SLCD_INT_SOF ((uint8_t)0x00U) /*!< start of frame interrupt */
  95. #define SLCD_INT_UPD ((uint8_t)0x01U) /*!< update data done interrupt */
  96. /* voltage source definitions */
  97. #define SLCD_VOLTAGE_INTERNAL ((uint8_t)0x00U) /*!< SLCD internal voltage source */
  98. #define SLCD_VOLTAGE_EXTERNAL ((uint8_t)0x01U) /*!< SLCD external voltage source */
  99. /*data register number */
  100. typedef enum
  101. {
  102. SLCD_DATA_REG0, /*!< SLCD display data register 0 */
  103. SLCD_DATA_REG1, /*!< SLCD display data register 1 */
  104. SLCD_DATA_REG2, /*!< SLCD display data register 2 */
  105. SLCD_DATA_REG3, /*!< SLCD display data register 3 */
  106. SLCD_DATA_REG4, /*!< SLCD display data register 4 */
  107. SLCD_DATA_REG5, /*!< SLCD display data register 5 */
  108. SLCD_DATA_REG6, /*!< SLCD display data register 6 */
  109. SLCD_DATA_REG7, /*!< SLCD display data register 7 */
  110. }slcd_data_register_enum;
  111. /* SLCD data register */
  112. #define SLCD_DATA0_7(number) REG32((SLCD) + 0x14U + (number) * 0x08U)
  113. /* bias voltage definitions */
  114. #define CTL_BIAS(regval) (BITS(5,6) & ((uint32_t)(regval) << 5U))
  115. #define SLCD_BIAS_1_4 CTL_BIAS(0) /*!< 1/4 voltage bias */
  116. #define SLCD_BIAS_1_2 CTL_BIAS(1) /*!< 1/2 voltage bias */
  117. #define SLCD_BIAS_1_3 CTL_BIAS(2) /*!< 1/3 voltage bias */
  118. /* duty select definitions */
  119. #define CTL_DUTY(regval) (BITS(2,4) & ((uint32_t)(regval) << 2U))
  120. #define SLCD_DUTY_STATIC CTL_DUTY(0) /*!< static dutycycle */
  121. #define SLCD_DUTY_1_2 CTL_DUTY(1) /*!< 1/2 dutycycle */
  122. #define SLCD_DUTY_1_3 CTL_DUTY(2) /*!< 1/3 dutycycle */
  123. #define SLCD_DUTY_1_4 CTL_DUTY(3) /*!< 1/4 dutycycle */
  124. #define SLCD_DUTY_1_6 CTL_DUTY(5) /*!< 1/6 dutycycle */
  125. #define SLCD_DUTY_1_8 CTL_DUTY(4) /*!< 1/8 dutycycle */
  126. /* SLCD clock prescaler */
  127. #define CFG_PRE(regval) (BITS(22,25) & ((uint32_t)(regval) << 22U))
  128. #define SLCD_PRESCALER_1 CFG_PRE(0) /*!< PRE = 0 */
  129. #define SLCD_PRESCALER_2 CFG_PRE(1) /*!< PRE = 1 */
  130. #define SLCD_PRESCALER_4 CFG_PRE(2) /*!< PRE = 2 */
  131. #define SLCD_PRESCALER_8 CFG_PRE(3) /*!< PRE = 3 */
  132. #define SLCD_PRESCALER_16 CFG_PRE(4) /*!< PRE = 4 */
  133. #define SLCD_PRESCALER_32 CFG_PRE(5) /*!< PRE = 5 */
  134. #define SLCD_PRESCALER_64 CFG_PRE(6) /*!< PRE = 6 */
  135. #define SLCD_PRESCALER_128 CFG_PRE(7) /*!< PRE = 7 */
  136. #define SLCD_PRESCALER_256 CFG_PRE(8) /*!< PRE = 8 */
  137. #define SLCD_PRESCALER_512 CFG_PRE(9) /*!< PRE = 9 */
  138. #define SLCD_PRESCALER_1024 CFG_PRE(10) /*!< PRE = 10 */
  139. #define SLCD_PRESCALER_2048 CFG_PRE(11) /*!< PRE = 11 */
  140. #define SLCD_PRESCALER_4096 CFG_PRE(12) /*!< PRE = 12 */
  141. #define SLCD_PRESCALER_8192 CFG_PRE(13) /*!< PRE = 13 */
  142. #define SLCD_PRESCALER_16384 CFG_PRE(14) /*!< PRE = 14 */
  143. #define SLCD_PRESCALER_32768 CFG_PRE(15) /*!< PRE = 15 */
  144. /* SLCD clock divider */
  145. #define CFG_DIV(regval) (BITS(18,21) & ((uint32_t)(regval) << 18U))
  146. #define SLCD_DIVIDER_16 CFG_DIV(0) /*!< DIV = 16 */
  147. #define SLCD_DIVIDER_17 CFG_DIV(1) /*!< DIV = 17 */
  148. #define SLCD_DIVIDER_18 CFG_DIV(2) /*!< DIV = 18 */
  149. #define SLCD_DIVIDER_19 CFG_DIV(3) /*!< DIV = 19 */
  150. #define SLCD_DIVIDER_20 CFG_DIV(4) /*!< DIV = 20 */
  151. #define SLCD_DIVIDER_21 CFG_DIV(5) /*!< DIV = 21 */
  152. #define SLCD_DIVIDER_22 CFG_DIV(6) /*!< DIV = 22 */
  153. #define SLCD_DIVIDER_23 CFG_DIV(7) /*!< DIV = 23 */
  154. #define SLCD_DIVIDER_24 CFG_DIV(8) /*!< DIV = 24 */
  155. #define SLCD_DIVIDER_25 CFG_DIV(9) /*!< DIV = 25 */
  156. #define SLCD_DIVIDER_26 CFG_DIV(10) /*!< DIV = 26 */
  157. #define SLCD_DIVIDER_27 CFG_DIV(11) /*!< DIV = 27 */
  158. #define SLCD_DIVIDER_28 CFG_DIV(12) /*!< DIV = 28 */
  159. #define SLCD_DIVIDER_29 CFG_DIV(13) /*!< DIV = 29 */
  160. #define SLCD_DIVIDER_30 CFG_DIV(14) /*!< DIV = 30 */
  161. #define SLCD_DIVIDER_31 CFG_DIV(15) /*!< DIV = 31 */
  162. /* SLCD blink mode */
  163. #define CFG_BLKM(regval) (BITS(16,17) & ((uint32_t)(regval) << 16U))
  164. #define SLCD_BLINKMODE_OFF CFG_BLKM(0) /*!< blink disabled */
  165. #define SLCD_BLINKMODE_SEG0_COM0 CFG_BLKM(1) /*!< blink enabled on SEG[0], COM[0] */
  166. #define SLCD_BLINKMODE_SEG0_ALLCOM CFG_BLKM(2) /*!< blink enabled on SEG[0], all COM */
  167. #define SLCD_BLINKMODE_ALLSEG_ALLCOM CFG_BLKM(3) /*!< blink enabled on all SEG and all COM */
  168. /* SLCD blink frequency divider */
  169. #define CFG_BLKDIV(regval) (BITS(13,15) & ((uint32_t)(regval) << 13U))
  170. #define SLCD_BLINK_FREQUENCY_DIV8 CFG_BLKDIV(0) /*!< blink frequency = fSLCD/8 */
  171. #define SLCD_BLINK_FREQUENCY_DIV16 CFG_BLKDIV(1) /*!< blink frequency = fSLCD/16 */
  172. #define SLCD_BLINK_FREQUENCY_DIV32 CFG_BLKDIV(2) /*!< blink frequency = fSLCD/32 */
  173. #define SLCD_BLINK_FREQUENCY_DIV64 CFG_BLKDIV(3) /*!< blink frequency = fSLCD/64 */
  174. #define SLCD_BLINK_FREQUENCY_DIV128 CFG_BLKDIV(4) /*!< blink frequency = fSLCD/128 */
  175. #define SLCD_BLINK_FREQUENCY_DIV256 CFG_BLKDIV(5) /*!< blink frequency = fSLCD/256 */
  176. #define SLCD_BLINK_FREQUENCY_DIV512 CFG_BLKDIV(6) /*!< blink frequency = fSLCD/512 */
  177. #define SLCD_BLINK_FREQUENCY_DIV1024 CFG_BLKDIV(7) /*!< blink frequency = fSLCD/1024 */
  178. /* SLCD Contrast ratio */
  179. #define CFG_CONR(regval) (BITS(10,12) & ((uint32_t)(regval) << 10U))
  180. #define SLCD_CONTRAST_LEVEL_0 CFG_CONR(0) /*!< maximum SLCD Voltage = 2.60V */
  181. #define SLCD_CONTRAST_LEVEL_1 CFG_CONR(1) /*!< maximum SLCD Voltage = 2.73V */
  182. #define SLCD_CONTRAST_LEVEL_2 CFG_CONR(2) /*!< maximum SLCD Voltage = 2.86V */
  183. #define SLCD_CONTRAST_LEVEL_3 CFG_CONR(3) /*!< maximum SLCD Voltage = 2.99V */
  184. #define SLCD_CONTRAST_LEVEL_4 CFG_CONR(4) /*!< maximum SLCD Voltage = 3.12V */
  185. #define SLCD_CONTRAST_LEVEL_5 CFG_CONR(5) /*!< maximum SLCD Voltage = 3.25V */
  186. #define SLCD_CONTRAST_LEVEL_6 CFG_CONR(6) /*!< maximum SLCD Voltage = 3.38V */
  187. #define SLCD_CONTRAST_LEVEL_7 CFG_CONR(7) /*!< maximum SLCD Voltage = 3.51V */
  188. /* dead time duration */
  189. #define CFG_DD(regval) (BITS(7,9) & ((uint32_t)(regval) << 7U))
  190. #define SLCD_DEADTIME_PERIOD_0 CFG_DD(0) /*!< no dead time */
  191. #define SLCD_DEADTIME_PERIOD_1 CFG_DD(1) /*!< 1 phase inserted between couple of frame */
  192. #define SLCD_DEADTIME_PERIOD_2 CFG_DD(2) /*!< 2 phase inserted between couple of frame */
  193. #define SLCD_DEADTIME_PERIOD_3 CFG_DD(3) /*!< 3 phase inserted between couple of frame */
  194. #define SLCD_DEADTIME_PERIOD_4 CFG_DD(4) /*!< 4 phase inserted between couple of frame */
  195. #define SLCD_DEADTIME_PERIOD_5 CFG_DD(5) /*!< 5 phase inserted between couple of frame */
  196. #define SLCD_DEADTIME_PERIOD_6 CFG_DD(6) /*!< 6 phase inserted between couple of frame */
  197. #define SLCD_DEADTIME_PERIOD_7 CFG_DD(7) /*!< 7 phase inserted between couple of frame */
  198. /* pulse on duration */
  199. #define CFG_PULSE(regval) (BITS(4,6) & ((uint32_t)(regval) << 4U))
  200. #define SLCD_PULSEON_DURATION_0 CFG_PULSE(0) /*!< pulse on duration = 0 */
  201. #define SLCD_PULSEON_DURATION_1 CFG_PULSE(1) /*!< pulse on duration = 1*1/fPRE */
  202. #define SLCD_PULSEON_DURATION_2 CFG_PULSE(2) /*!< pulse on duration = 2*1/fPRE */
  203. #define SLCD_PULSEON_DURATION_3 CFG_PULSE(3) /*!< pulse on duration = 3*1/fPRE */
  204. #define SLCD_PULSEON_DURATION_4 CFG_PULSE(4) /*!< pulse on duration = 4*1/fPRE */
  205. #define SLCD_PULSEON_DURATION_5 CFG_PULSE(5) /*!< pulse on duration = 5*1/fPRE */
  206. #define SLCD_PULSEON_DURATION_6 CFG_PULSE(6) /*!< pulse on duration = 6*1/fPRE */
  207. #define SLCD_PULSEON_DURATION_7 CFG_PULSE(7) /*!< pulse on duration = 7*1/fPRE */
  208. /* function declarations */
  209. /* check the SLCD status flag */
  210. FlagStatus slcd_flag_get(uint8_t slcd_flag);
  211. /* check the SLCD interrupt flag */
  212. FlagStatus slcd_interrupt_flag_get(uint8_t slcd_interrupt);
  213. /* clear the SLCD flag */
  214. void slcd_flag_clear(uint8_t slcd_flag);
  215. /* clear the SLCD interrupt flag */
  216. void slcd_interrupt_flag_clear(uint8_t slcd_interrupt);
  217. /* the SLCD interrupt config */
  218. void slcd_interrupt_config(uint8_t slcd_interrupt,ControlStatus newvalue);
  219. /* SLCD bias voltage select */
  220. void slcd_bias_voltage_select(uint32_t bias_voltage);
  221. /* SLCD duty select */
  222. void slcd_duty_select(uint32_t duty);
  223. /* SLCD input clock config */
  224. void slcd_clock_config(uint32_t prescaler,uint32_t divider);
  225. /* SLCD blink mode config */
  226. void slcd_blink_mode_config(uint32_t mode,uint32_t blink_divider);
  227. /* SLCD contrast ratio config */
  228. void slcd_contrast_ratio_config(uint32_t contrast_ratio);
  229. /* SLCD dead time duration config */
  230. void slcd_dead_time_config(uint32_t dead_time);
  231. /* SLCD pulse on duration config */
  232. void slcd_pulse_on_duration_config(uint32_t duration);
  233. /* SLCD common/segment pad select */
  234. void slcd_com_seg_remap(ControlStatus newvalue);
  235. /* SLCD voltage source select */
  236. void slcd_voltage_source_select(uint8_t voltage_source);
  237. /* SLCD high drive enable */
  238. void slcd_high_drive_config(ControlStatus newvalue);
  239. /* SLCD data register write */
  240. void slcd_data_register_write(slcd_data_register_enum register_number, uint32_t data);
  241. /* SLCD data update request */
  242. void slcd_data_update_request(void);
  243. /* SLCD reset */
  244. void slcd_deinit(void);
  245. /* enable SLCD interface */
  246. void slcd_enable(void);
  247. /* disable SLCD interface */
  248. void slcd_disable(void);
  249. #endif /* GD32F1X0_SLCD_H */
  250. #endif /* GD32F170_190 */