wm_lcd.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**************************************************************************//**
  2. * @file wm_lcd.c
  3. * @author
  4. * @version
  5. * @date
  6. * @brief
  7. *
  8. * Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
  9. *****************************************************************************/
  10. #include "wm_osal.h"
  11. #include "wm_lcd.h"
  12. #include "wm_io.h"
  13. #include "wm_pmu.h"
  14. #define RTC_CLK (32000UL)
  15. /**
  16. * @brief Initialize LCD Frame Counter
  17. * @param[in] freq LCD reference refresh frequency in Hz that will be used
  18. */
  19. void tls_lcd_fresh_ratio(uint8_t com_num, uint16_t freq)
  20. {
  21. if (freq == 0)
  22. {
  23. freq = 60;
  24. }
  25. LCD->FRAMECNT = RTC_CLK/freq/com_num;
  26. }
  27. /**
  28. * @brief
  29. * Turn on or clear a segment
  30. *
  31. * @param[in] com
  32. * Which COM line to update
  33. *
  34. * @param[in] bit
  35. * Bit index of which field to change
  36. *
  37. * @param[in] enable
  38. * When one will set segment, when zero will clear segment
  39. */
  40. void tls_lcd_seg_set(int com, int bit, int on_off)
  41. {
  42. tls_bitband_write(HR_LCD_COM0_SEG+com*4, bit, on_off);
  43. }
  44. /**
  45. * @brief
  46. * select the voltage of LCD module
  47. *
  48. */
  49. void tls_lcd_vlcd_sel(LCD_VlcdDef vlcd)
  50. {
  51. LCD->CTRL &= ~LCD_VLCD_MASK;
  52. LCD->CTRL |= vlcd;
  53. }
  54. /**
  55. * @brief
  56. * set the duty of LCD module
  57. *
  58. */
  59. void tls_lcd_duty_set(LCD_DutyDef duty)
  60. {
  61. LCD->CTRL &= ~LCD_DUTY_MASK;
  62. LCD->CTRL |= duty;
  63. }
  64. /**
  65. * @brief
  66. * set the bias of LCD module
  67. *
  68. */
  69. void tls_lcd_bias_set(LCD_BiasDef bias)
  70. {
  71. LCD->CTRL &= ~LCD_BIAS_MASK;
  72. LCD->CTRL |= bias;
  73. }
  74. /**
  75. * @brief
  76. * initialize the lcd module
  77. *
  78. */
  79. void tls_lcd_init(tls_lcd_options_t *opts)
  80. {
  81. LCD->CTRL = 0;
  82. LCD->CTRL = opts->bias | opts->duty | opts->vlcd | (1 << 12);
  83. tls_lcd_fresh_ratio(opts->com_number, opts->fresh_rate);
  84. TLS_LCD_ENABLE(opts->enable);
  85. TLS_LCD_POWERDOWM(1);
  86. }
  87. /**
  88. *******************************************************
  89. * TEST CODE IS BELOW
  90. *******************************************************
  91. */
  92. void lcd_test(void)
  93. {
  94. int i,j;
  95. tls_lcd_options_t lcd_opts = {
  96. true,
  97. BIAS_ONEFOURTH,
  98. DUTY_ONEEIGHTH,
  99. VLCD31,
  100. 8,
  101. 60,
  102. };
  103. /* COM 0-3 */
  104. tls_io_cfg_set(WM_IO_PB_25, WM_IO_OPTION6);
  105. tls_io_cfg_set(WM_IO_PB_21, WM_IO_OPTION6);
  106. tls_io_cfg_set(WM_IO_PB_22, WM_IO_OPTION6);
  107. tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION6);
  108. /* SEG 0-5 */
  109. tls_io_cfg_set(WM_IO_PB_23, WM_IO_OPTION6);
  110. tls_io_cfg_set(WM_IO_PB_26, WM_IO_OPTION6);
  111. tls_io_cfg_set(WM_IO_PB_24, WM_IO_OPTION6);
  112. tls_io_cfg_set(WM_IO_PA_07, WM_IO_OPTION6);
  113. tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION6);
  114. tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION6);
  115. tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD);
  116. /*enable output valid*/
  117. tls_reg_write32(HR_LCD_COM_EN, 0xF);
  118. tls_reg_write32(HR_LCD_SEG_EN, 0x3F);
  119. tls_lcd_init(&lcd_opts);
  120. while(1)
  121. {
  122. #if 1
  123. for(i=0; i<4; i++)
  124. {
  125. for(j=0; j<9; j++)
  126. {
  127. tls_lcd_seg_set(i, j, 1);
  128. tls_os_time_delay(500);
  129. printf("%d %d %d\n", i, j, 1);
  130. }
  131. }
  132. for(i=0; i<4; i++)
  133. {
  134. for(j=0; j<9; j++)
  135. {
  136. tls_lcd_seg_set(i, j, 0);
  137. tls_os_time_delay(500);
  138. printf("%d %d %d\n", i, j, 0);
  139. }
  140. }
  141. #else
  142. for(i=0; i<40; i++)
  143. {
  144. lcdDisplaySegment(i, 1);
  145. tls_os_time_delay(HZ/2);
  146. }
  147. for(i=0; i<40; i++)
  148. {
  149. lcdDisplaySegment(i, 0);
  150. tls_os_time_delay(HZ/2);
  151. }
  152. #endif
  153. }
  154. }