1 /*
2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 /**************************************************************************//**
17 * @file wm_lcd.c
18 * @author
19 * @version
20 * @date
21 * @brief
22 *
23 * Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
24 *****************************************************************************/
25 #include "wm_osal.h"
26 #include "wm_io.h"
27 #include "wm_pmu.h"
28 #include "wm_lcd.h"
29
30 #define RTC_CLK (32000UL)
31
32 /**
33 * @brief Initialize LCD Frame Counter
34 * @param[in] freq LCD reference refresh frequency in Hz that will be used
35 */
tls_lcd_fresh_ratio(uint8_t com_num,uint16_t freq)36 void tls_lcd_fresh_ratio(uint8_t com_num, uint16_t freq)
37 {
38 if (freq == 0) {
39 freq = 60;
40 }
41
42 if (com_num == 0) {
43 }
44 LCD->FRAMECNT = RTC_CLK/freq/com_num;
45 }
46
47 /**
48 * @brief
49 * Turn on or clear a segment
50 *
51 * @param[in] com
52 * Which COM line to update
53 *
54 * @param[in] bit
55 * Bit index of which field to change
56 *
57 * @param[in] enable
58 * When one will set segment, when zero will clear segment
59 */
tls_lcd_seg_set(int com,int bit,int on_off)60 void tls_lcd_seg_set(int com, int bit, int on_off)
61 {
62 tls_bitband_write(HR_LCD_COM0_SEG+com*4, bit, on_off);
63 }
64
65 /**
66 * @brief
67 * select the voltage of LCD module
68 *
69 */
tls_lcd_vlcd_sel(LCD_VlcdDef vlcd)70 void tls_lcd_vlcd_sel(LCD_VlcdDef vlcd)
71 {
72 LCD->CTRL &= ~LCD_VLCD_MASK;
73 LCD->CTRL |= vlcd;
74 }
75
76 /**
77 * @brief
78 * set the duty of LCD module
79 *
80 */
tls_lcd_duty_set(LCD_DutyDef duty)81 void tls_lcd_duty_set(LCD_DutyDef duty)
82 {
83 LCD->CTRL &= ~LCD_DUTY_MASK;
84 LCD->CTRL |= duty;
85 }
86
87 /**
88 * @brief
89 * set the bias of LCD module
90 *
91 */
tls_lcd_bias_set(LCD_BiasDef bias)92 void tls_lcd_bias_set(LCD_BiasDef bias)
93 {
94 LCD->CTRL &= ~LCD_BIAS_MASK;
95 LCD->CTRL |= bias;
96 }
97
98 /**
99 * @brief
100 * initialize the lcd module
101 *
102 */
tls_lcd_init(tls_lcd_options_t * opts)103 void tls_lcd_init(tls_lcd_options_t *opts)
104 {
105 LCD->CTRL = 0;
106 LCD->CTRL = opts->bias | opts->duty | opts->vlcd | (1 << 12);
107 tls_lcd_fresh_ratio(opts->com_number, opts->fresh_rate);
108 TLS_LCD_ENABLE(opts->enable);
109 TLS_LCD_POWERDOWM(1);
110 }
111
112 /**
113 *******************************************************
114 * TEST CODE IS BELOW
115 *******************************************************
116 */
117
lcd_test(void)118 void lcd_test(void)
119 {
120 int i, j;
121 tls_lcd_options_t lcd_opts = {
122 true,
123 BIAS_ONEFOURTH,
124 DUTY_ONEEIGHTH,
125 VLCD31,
126 8,
127 60,
128 };
129 /* COM 0-3 */
130 tls_io_cfg_set(WM_IO_PB_25, WM_IO_OPTION6);
131 tls_io_cfg_set(WM_IO_PB_21, WM_IO_OPTION6);
132 tls_io_cfg_set(WM_IO_PB_22, WM_IO_OPTION6);
133 tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION6);
134
135 /* SEG 0-5 */
136 tls_io_cfg_set(WM_IO_PB_23, WM_IO_OPTION6);
137 tls_io_cfg_set(WM_IO_PB_26, WM_IO_OPTION6);
138 tls_io_cfg_set(WM_IO_PB_24, WM_IO_OPTION6);
139 tls_io_cfg_set(WM_IO_PA_07, WM_IO_OPTION6);
140 tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION6);
141 tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION6);
142 tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD);
143
144 /* enable output valid */
145 tls_reg_write32(HR_LCD_COM_EN, 0xF);
146 tls_reg_write32(HR_LCD_SEG_EN, 0x3F);
147
148 tls_lcd_init(&lcd_opts);
149
150 while (1) {
151 #if 1
152 for (i=0; i<4; i++) {
153 for (j=0; j<9; j++) {
154 tls_lcd_seg_set(i, j, 1);
155 tls_os_time_delay(500);
156 printf("%d %d %d\n", i, j, 1);
157 }
158 }
159
160 for (i=0; i<4; i++) {
161 for (j=0; j<9; j++) {
162 tls_lcd_seg_set(i, j, 0);
163 tls_os_time_delay(500);
164 printf("%d %d %d\n", i, j, 0);
165 }
166 }
167 #else
168
169 for (i=0; i<40; i++) {
170 lcdDisplaySegment(i, 1);
171 tls_os_time_delay(HZ/2);
172 }
173 for (i=0; i<40; i++) {
174 lcdDisplaySegment(i, 0);
175 tls_os_time_delay(HZ/2);
176 }
177 #endif
178 }
179 }
180
181