wm_lcd.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. }