libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
lcd.c
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2014 Nikolay Merinov <nikolay.merinov@member.fsf.org>
5 *
6 * This library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
22
23void lcd_enable(void)
24{
26}
27
28void lcd_update(void)
29{
31}
32
34{
35 while ((LCD_SR & LCD_SR_ENS) == 0);
36}
37
39{
40 while ((LCD_SR & LCD_SR_RDY) == 0);
41}
42
44{
45 while ((LCD_SR & LCD_SR_UDR) != 0);
46}
47
49{
50 return ((LCD_SR & LCD_SR_ENS) != 0);
51}
52
54{
55 return ((LCD_SR & LCD_SR_RDY) != 0);
56}
57
59{
60 return ((LCD_SR & LCD_SR_UDR) == 0);
61}
62
63void lcd_set_contrast(uint8_t contrast)
64{
66 LCD_FCR |= contrast << LCD_FCR_CC_SHIFT;
67}
68
69void lcd_set_bias(uint8_t bias)
70{
72 LCD_CR |= bias << LCD_CR_BIAS_SHIFT;
73}
74
75void lcd_set_duty(uint8_t duty)
76{
78 LCD_CR |= duty << LCD_CR_DUTY_SHIFT;
79}
80
81void lcd_set_prescaler(uint8_t ps)
82{
85}
86
87void lcd_set_divider(uint8_t div)
88{
90 LCD_FCR |= div << LCD_FCR_DIV_SHIFT;
91}
92
94{
96}
97
99{
100 LCD_CR &= ~LCD_CR_MUX_SEG;
101}
102
103void lcd_set_refresh_frequency(uint32_t frequency)
104{
105 uint32_t duty, lcd_clock;
108 duty = 1;
109 break;
110 case LCD_CR_DUTY_1_2:
111 duty = 2;
112 break;
113 case LCD_CR_DUTY_1_3:
114 duty = 3;
115 break;
116 case LCD_CR_DUTY_1_4:
117 duty = 4;
118 break;
119 case LCD_CR_DUTY_1_8:
120 duty = 8;
121 break;
122 default:
123 /* Incorrect duty */
124 return;
125 }
126
129 lcd_clock = 32786;
130 break;
132 lcd_clock = 37000;
133 break;
135 /* no current method of determining clock and divider! */
136 return;
137 default:
138 /* RCC Clock not selected */
139 return;
140 }
141
142 /* PS * DIV = lcd_clock/(duty * freq) */
143 uint32_t ps_mul_div = lcd_clock / (duty * frequency);
144
145 int div, ps = 0;
146 while (ps_mul_div > 32) {
147 ps_mul_div >>= 1;
148 ps++;
149 }
150 div = ps_mul_div - 16;
151
153 lcd_set_divider(div);
154}
void lcd_disable_segment_multiplexing(void)
Definition: lcd.c:98
int lcd_is_enabled(void)
Definition: lcd.c:48
void lcd_set_prescaler(uint8_t ps)
Definition: lcd.c:81
void lcd_set_divider(uint8_t div)
Definition: lcd.c:87
#define LCD_FCR_CC_SHIFT
Definition: lcd.h:121
#define LCD_FCR_DIV_SHIFT
Definition: lcd.h:150
void lcd_enable_segment_multiplexing(void)
Definition: lcd.c:93
#define LCD_FCR_CC_MASK
Definition: lcd.h:122
#define LCD_SR_ENS
Definition: lcd.h:189
#define LCD_SR_UDR
Definition: lcd.h:191
#define LCD_FCR_PS_SHIFT
Definition: lcd.h:169
int lcd_is_step_up_ready(void)
Definition: lcd.c:53
#define LCD_CR_LCDEN
Definition: lcd.h:75
#define LCD_CR_DUTY_1_4
Definition: lcd.h:83
#define LCD_CR_DUTY_1_2
Definition: lcd.h:81
#define LCD_CR_BIAS_SHIFT
Definition: lcd.h:86
#define LCD_FCR_PS_MASK
Definition: lcd.h:170
void lcd_set_duty(uint8_t duty)
Definition: lcd.c:75
#define LCD_CR_MUX_SEG
Definition: lcd.h:92
void lcd_set_refresh_frequency(uint32_t frequency)
Definition: lcd.c:103
#define LCD_CR_DUTY_1_3
Definition: lcd.h:82
#define LCD_CR_DUTY_SHIFT
Definition: lcd.h:78
#define LCD_CR_DUTY_STATIC
Definition: lcd.h:80
void lcd_wait_for_lcd_enabled(void)
Definition: lcd.c:33
#define LCD_FCR_DIV_MASK
Definition: lcd.h:151
void lcd_set_bias(uint8_t bias)
Definition: lcd.c:69
void lcd_enable(void)
Definition: lcd.c:23
int lcd_is_for_update_ready(void)
Definition: lcd.c:58
void lcd_update(void)
Definition: lcd.c:28
#define LCD_CR_DUTY_MASK
Definition: lcd.h:79
#define LCD_SR_RDY
Definition: lcd.h:193
void lcd_wait_for_step_up_ready(void)
Definition: lcd.c:38
void lcd_wait_for_update_ready(void)
Definition: lcd.c:43
#define LCD_CR_BIAS_MASK
Definition: lcd.h:87
#define LCD_CR_DUTY_1_8
Definition: lcd.h:84
void lcd_set_contrast(uint8_t contrast)
Definition: lcd.c:63
#define LCD_SR
Status register.
Definition: lcd.h:48
#define LCD_CR
Control register.
Definition: lcd.h:44
#define LCD_FCR
Frame control register.
Definition: lcd.h:46
#define RCC_CSR_RTCSEL_SHIFT
Definition: l1/rcc.h:428
#define RCC_CSR_RTCSEL_LSI
Definition: l1/rcc.h:432
#define RCC_CSR_RTCSEL_HSE
Definition: l1/rcc.h:433
#define RCC_CSR
Definition: l1/rcc.h:68
#define RCC_CSR_RTCSEL_MASK
Definition: l1/rcc.h:429
#define RCC_CSR_RTCSEL_LSE
Definition: l1/rcc.h:431