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