wm_lcd.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * @file wm_lcd.h
  3. *
  4. * @brief LCD Driver Module
  5. *
  6. * @author dave
  7. *
  8. * @copyright (c) 2014 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef __WM_LCD_H
  11. #define __WM_LCD_H
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "wm_regs.h"
  16. #include <stdbool.h>
  17. /**
  18. * @brief LCD Register Declaration
  19. *
  20. */
  21. typedef struct
  22. {
  23. /** Control Register */
  24. __IO uint32_t CTRL;
  25. /** Refresh Rate Prescaler Register */
  26. __IO uint32_t FRAMECNT;
  27. __IO uint32_t COM0;
  28. __IO uint32_t COM1;
  29. __IO uint32_t COM2;
  30. __IO uint32_t COM3;
  31. __IO uint32_t COM4;
  32. __IO uint32_t COM5;
  33. __IO uint32_t COM6;
  34. __IO uint32_t COM7;
  35. /** LCD COM Control Register */
  36. __IO uint32_t COM_EN;
  37. /** LCD SEG Control Register */
  38. __IO uint32_t SEG_EN;
  39. } LCD_T;
  40. /** LCD base pointer */
  41. #define LCD ((LCD_T *)HR_LCD_REG_BASE)
  42. typedef enum
  43. {
  44. /** Static (2 levels) */
  45. BIAS_STATIC = LCD_BIAS_STATIC,
  46. /** 1/2 Bias (3 levels) */
  47. BIAS_ONEHALF = LCD_BIAS_ONEHALF,
  48. /** 1/3 Bias (4 levels) */
  49. BIAS_ONETHIRD = LCD_BIAS_ONETHIRD,
  50. /** 1/4 Bias (4 levels) */
  51. BIAS_ONEFOURTH = LCD_BIAS_ONEFOURTH,
  52. } LCD_BiasDef;
  53. typedef enum
  54. {
  55. /** VLCD 2.7v */
  56. VLCD27 = LCD_VLCD_27,
  57. /** VLCD 2.9v */
  58. VLCD29 = LCD_VLCD_29,
  59. /** VLCD 3.1v */
  60. VLCD31 = LCD_VLCD_31,
  61. /** VLCD 3.3v */
  62. VLCD33 = LCD_VLCD_33,
  63. } LCD_VlcdDef;
  64. typedef enum
  65. {
  66. /** Static (segments can be multiplexed with LCD_COM[0]) */
  67. DUTY_STATIC = LCD_DUTY_STATIC,
  68. /** 1/2 Duty cycle (segments can be multiplexed with LCD_COM[0:1]) */
  69. DUTY_ONEHALF = LCD_DUTY_ONEHALF,
  70. /** 1/3 Duty cycle (segments can be multiplexed with LCD_COM[0:2]) */
  71. DUTY_ONETHIRD = LCD_DUTY_ONETHIRD,
  72. /** 1/4 Duty cycle (segments can be multiplexed with LCD_COM[0:3]) */
  73. DUTY_ONEFOURTH = LCD_DUTY_ONEFOURTH,
  74. /** 1/5 Duty cycle (segments can be multiplexed with LCD_COM[0:4]) */
  75. DUTY_ONEFIFTH = LCD_DUTY_ONEFIFTH,
  76. /** 1/6 Duty cycle (segments can be multiplexed with LCD_COM[0:5]) */
  77. DUTY_ONESIXTH = LCD_DUTY_ONESIXTH,
  78. /** 1/7 Duty cycle (segments can be multiplexed with LCD_COM[0:6]) */
  79. DUTY_ONESEVENTH = LCD_DUTY_ONESEVENTH,
  80. /** 1/8 Duty cycle (segments can be multiplexed with LCD_COM[0:7]) */
  81. DUTY_ONEEIGHTH = LCD_DUTY_ONEEIGHTH,
  82. } LCD_DutyDef;
  83. typedef struct tls_lcd_options
  84. {
  85. /** */
  86. bool enable;
  87. /** Bias configuration */
  88. LCD_BiasDef bias;
  89. /** Duty configuration */
  90. LCD_DutyDef duty;
  91. /** Vlcd configuration */
  92. LCD_VlcdDef vlcd;
  93. /** com number */
  94. uint8_t com_number;
  95. /** Fresh rate configuration */
  96. uint16_t fresh_rate;
  97. } tls_lcd_options_t;
  98. /**
  99. * @defgroup Driver_APIs Driver APIs
  100. * @brief Driver APIs
  101. */
  102. /**
  103. * @addtogroup Driver_APIs
  104. * @{
  105. */
  106. /**
  107. * @defgroup LCD_Driver_APIs LCD Driver APIs
  108. * @brief LCD driver APIs
  109. */
  110. /**
  111. * @addtogroup LCD_Driver_APIs
  112. * @{
  113. */
  114. /**
  115. * @brief Initialize LCD Frame Counter
  116. * @param[in] com_num Number of the com
  117. * @param[in] freq LCD reference refresh frequency in Hz that will be used
  118. */
  119. void tls_lcd_fresh_ratio(uint8_t com_num, uint16_t freq);
  120. /**
  121. * @brief initialize the LCD module
  122. *
  123. */
  124. void tls_lcd_init(tls_lcd_options_t *opts);
  125. /**
  126. * @brief Initialize LCD Frame Counter
  127. * @param[in] freq LCD reference refresh frequency in Hz that will be used
  128. *
  129. */
  130. void tls_lcd_fresh_rate(uint16_t freq);
  131. /**
  132. * @brief Turn on or clear a segment
  133. * @param[in] com Which COM line to update
  134. * @param[in] bit Bit index of which field to change
  135. * @param[in] enable When one will set segment, when zero will clear segment
  136. * @note Before this function be called, the module must have been intialized
  137. */
  138. void tls_lcd_seg_set(int com, int bit, int on_off);
  139. /**
  140. * @brief Select the voltage of LCD module
  141. * @param[in] vlcd This parameter can be one of the following values:
  142. * - \ref VLCD27
  143. * - \ref VLCD29
  144. * - \ref VLCD31
  145. * - \ref VLCD33
  146. */
  147. void tls_lcd_vlcd_sel(LCD_VlcdDef vlcd);
  148. /**
  149. * @brief Set the duty of LCD module
  150. * @param[in] duty This parameter can be one of the following values:
  151. * - \ref DUTY_STATIC
  152. * - \ref DUTY_ONEHALF
  153. * - \ref DUTY_ONETHIRD
  154. * - \ref DUTY_ONEFOURTH
  155. * - \ref DUTY_ONEFIFTH
  156. * - \ref DUTY_ONESIXTH
  157. * - \ref DUTY_ONESEVENTH
  158. * - \ref DUTY_ONEEIGHTH
  159. *
  160. */
  161. void tls_lcd_duty_set(LCD_DutyDef duty);
  162. /**
  163. * @brief Set the bias of LCD module
  164. * @param[in] duty This parameter can be one of the following values:
  165. * - \ref BIAS_STATIC
  166. * - \ref BIAS_ONEHALF
  167. * - \ref BIAS_ONETHIRD
  168. * - \ref BIAS_ONEFOURTH
  169. *
  170. */
  171. void tls_lcd_bias_set(LCD_BiasDef bias);
  172. /**
  173. * @brief Enable or disable clock of LCD module
  174. * @param[in] enable When one enable the clock of LCD module, when zero disable
  175. */
  176. #define TLS_LCD_CLK_ENABLE(enable) \
  177. do { \
  178. tls_bitband_write(HR_CLK_BASE_ADDR, HR_CLK_LCD_GATE_Pos, enable); \
  179. } while(0)
  180. /**
  181. * @brief Enable or disable the LCD module
  182. * @param[in] enable When one enable the LCD module, when zero disable
  183. *
  184. */
  185. #define TLS_LCD_ENABLE(enable) \
  186. do { \
  187. tls_bitband_write(HR_LCD_CR, LCD_CR_EN_Pos, enable); \
  188. } while(0)
  189. /**
  190. * @brief Enable or disable the LCD module
  191. * @param[in] enable When one close LCD module, when zero open the LCD module
  192. *
  193. */
  194. #define TLS_LCD_POWERDOWM(enable) \
  195. do { \
  196. tls_bitband_write(HR_LCD_CR, LCD_CR_PD_Pos, enable); \
  197. } while(0)
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @}
  203. */
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207. #endif
  208. /*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/