lcd_log.c
7.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*!
\file lcd_log.c
\brief this file provides all the LCD Log firmware functions
\version 2017-02-10, V1.0.0, firmware for GD32F30x
\version 2018-10-10, V1.1.0, firmware for GD32F30x
\version 2018-12-25, V2.0.0, firmware for GD32F30x
*/
/*
Copyright (c) 2018, GigaDevice Semiconductor Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "lcd_log.h"
#include "usb_lcd_conf.h"
#include <stdio.h>
LCD_LOG_line LCD_CacheBuffer[LCD_CACHE_DEPTH];
uint32_t LCD_LineColor;
uint16_t LCD_CacheBuffer_xptr;
uint16_t LCD_CacheBuffer_yptr_top;
uint16_t LCD_CacheBuffer_yptr_bottom;
uint16_t LCD_CacheBuffer_yptr_top_bak;
uint16_t LCD_CacheBuffer_yptr_bottom_bak;
ControlStatus LCD_CacheBuffer_yptr_invert;
ControlStatus LCD_ScrollActive;
ControlStatus LCD_Lock;
ControlStatus LCD_Scrolled;
uint16_t LCD_ScrollBackStep;
/*!
\brief initialize the LCD Log module
\param[in] none
\param[out] none
\retval none
*/
void lcd_log_init (void)
{
lcd_log_deinit();
lcd_clear(LCD_COLOR_BLACK);
}
/*!
\brief de-initialize the LCD Log module
\param[in] none
\param[out] none
\retval none
*/
void lcd_log_deinit (void)
{
LCD_LineColor = LCD_LOG_TEXT_COLOR;
LCD_CacheBuffer_xptr = 0;
LCD_CacheBuffer_yptr_top = 0;
LCD_CacheBuffer_yptr_bottom = 0;
LCD_CacheBuffer_yptr_top_bak = 0;
LCD_CacheBuffer_yptr_bottom_bak = 0;
LCD_CacheBuffer_yptr_invert= ENABLE;
LCD_ScrollActive = DISABLE;
LCD_Lock = DISABLE;
LCD_Scrolled = DISABLE;
LCD_ScrollBackStep = 0;
}
/*!
\brief display the application header (title) on the LCD screen
\param[in] ptitle: pointer to the string to be displayed
\param[in] start_x: x location
\param[out] none
\retval none
*/
void lcd_log_header_set (uint8_t *ptitle, uint16_t start_x)
{
lcd_font_set(&font8x16);
lcd_text_color_set(LCD_COLOR_BLUE);
lcd_rectangle_fill(LCD_HEADER_X, LCD_HEADER_Y, LCD_FLAG_WIDTH, LCD_FLAG_HEIGHT);
lcd_background_color_set(LCD_COLOR_BLUE);
lcd_text_color_set(LCD_COLOR_RED);
lcd_vertical_string_display(LCD_HEADER_LINE, start_x, ptitle);
lcd_background_color_set(LCD_COLOR_BLACK);
}
/*!
\brief display the application footer (status) on the LCD screen
\param[in] pstatus: pointer to the string to be displayed
\param[in] start_x: x location
\param[out] none
\retval none
*/
void lcd_log_footer_set (uint8_t *pstatus, uint16_t start_x)
{
lcd_text_color_set(LCD_COLOR_BLUE);
lcd_rectangle_fill(LCD_FOOTER_X, LCD_FOOTER_Y, LCD_FLAG_WIDTH, LCD_FLAG_HEIGHT);
lcd_background_color_set(LCD_COLOR_BLUE);
lcd_text_color_set(LCD_COLOR_RED);
lcd_vertical_string_display(LCD_FOOTER_LINE, start_x, pstatus);
lcd_background_color_set(LCD_COLOR_BLACK);
}
/*!
\brief clear the text zone
\param[in] start_x, start_y, end_x, end_y: zone location
\param[out] none
\retval none
*/
void lcd_log_textzone_clear (uint16_t start_x,
uint16_t start_y,
uint16_t width,
uint16_t height)
{
lcd_rectangle_fill(start_x, start_y, width, height);
}
/*!
\brief redirect the printf to the LCD
\param[in] ch: character to be displayed
\param[in] f: output file pointer
\param[out] none
\retval none
*/
LCD_LOG_PUTCHAR
{
font_struct *cFont = lcd_font_get();
uint32_t idx;
if (LCD_Lock == DISABLE) {
if (LCD_ScrollActive == ENABLE) {
LCD_CacheBuffer_yptr_bottom = LCD_CacheBuffer_yptr_bottom_bak;
LCD_CacheBuffer_yptr_top = LCD_CacheBuffer_yptr_top_bak;
LCD_ScrollActive = DISABLE;
LCD_Scrolled = DISABLE;
LCD_ScrollBackStep = 0;
}
if ((LCD_CacheBuffer_xptr < LCD_FLAG_HEIGHT / cFont->width) && (ch != '\n')) {
if (ch != '\r') {
LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = (uint16_t)ch;
}
} else {
if (LCD_CacheBuffer_yptr_top >= LCD_CacheBuffer_yptr_bottom) {
if (LCD_CacheBuffer_yptr_invert == DISABLE) {
LCD_CacheBuffer_yptr_top++;
if (LCD_CacheBuffer_yptr_top == LCD_CACHE_DEPTH) {
LCD_CacheBuffer_yptr_top = 0;
}
} else {
LCD_CacheBuffer_yptr_invert= DISABLE;
}
}
for (idx = LCD_CacheBuffer_xptr; idx < LCD_FLAG_HEIGHT / cFont->width; idx++) {
LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = ' ';
}
LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].color = LCD_LineColor;
LCD_CacheBuffer_xptr = 0;
LCD_LOG_UpdateDisplay();
LCD_CacheBuffer_yptr_bottom ++;
if (LCD_CacheBuffer_yptr_bottom == LCD_CACHE_DEPTH) {
LCD_CacheBuffer_yptr_bottom = 0;
LCD_CacheBuffer_yptr_top = 1;
LCD_CacheBuffer_yptr_invert = ENABLE;
}
if ((ch != '\n') && (ch != '\r')) {
LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = (uint16_t)ch;
}
}
}
return ch;
}
/*!
\brief update the text area display
\param[in] none
\param[out] none
\retval none
*/
void LCD_LOG_UpdateDisplay (void)
{
uint8_t cnt = 0 ;
uint16_t length = 0 ;
uint16_t ptr = 0, index = 0;
font_struct *cFont = lcd_font_get();
if ((LCD_CacheBuffer_yptr_bottom < (YWINDOW_SIZE - 1)) && (LCD_CacheBuffer_yptr_bottom >= LCD_CacheBuffer_yptr_top)) {
lcd_text_color_set (LCD_CacheBuffer[cnt + LCD_CacheBuffer_yptr_bottom].color);
lcd_vertical_string_display ((YWINDOW_MIN + LCD_CacheBuffer_yptr_bottom) * cFont->height, 0, (uint8_t *)(LCD_CacheBuffer[cnt + LCD_CacheBuffer_yptr_bottom].line));
} else {
if (LCD_CacheBuffer_yptr_bottom < LCD_CacheBuffer_yptr_top) {
/* Virtual length for rolling */
length = LCD_CACHE_DEPTH + LCD_CacheBuffer_yptr_bottom ;
} else {
length = LCD_CacheBuffer_yptr_bottom;
}
ptr = length - YWINDOW_SIZE + 1;
for (cnt = 0; cnt < YWINDOW_SIZE; cnt ++) {
index = (cnt + ptr ) % LCD_CACHE_DEPTH;
lcd_text_color_set (LCD_CacheBuffer[index].color);
lcd_vertical_string_display ((cnt + YWINDOW_MIN) * cFont->height, 0, (uint8_t *)(LCD_CacheBuffer[index].line));
}
}
}