Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
lcd_log.cpp
00001 #include <stdio.h> 00002 #include "lcd_log.h" 00003 00004 00005 LCD_LOG_line LCD_CacheBuffer [LCD_CACHE_DEPTH]; 00006 uint32_t LCD_LineColor; 00007 uint16_t LCD_CacheBuffer_xptr; 00008 uint16_t LCD_CacheBuffer_yptr_top; 00009 uint16_t LCD_CacheBuffer_yptr_bottom; 00010 00011 uint16_t LCD_CacheBuffer_yptr_top_bak; 00012 uint16_t LCD_CacheBuffer_yptr_bottom_bak; 00013 00014 FunctionalState LCD_CacheBuffer_yptr_invert; 00015 FunctionalState LCD_ScrollActive; 00016 FunctionalState LCD_Lock; 00017 FunctionalState LCD_Scrolled; 00018 uint16_t LCD_ScrollBackStep; 00019 /** 00020 * @brief Initializes the LCD Log module 00021 * @param None 00022 * @retval None 00023 */ 00024 00025 void LCD_LOG_Init ( void) 00026 { 00027 /* Deinit LCD cache */ 00028 LCD_LOG_DeInit(); 00029 00030 /* Clear the LCD */ 00031 BSP_LCD_Clear(LCD_LOG_BACKGROUND_COLOR); 00032 } 00033 00034 /** 00035 * @brief DeInitializes the LCD Log module. 00036 * @param None 00037 * @retval None 00038 */ 00039 void LCD_LOG_DeInit(void) 00040 { 00041 LCD_LineColor = LCD_LOG_TEXT_COLOR; 00042 LCD_CacheBuffer_xptr = 0; 00043 LCD_CacheBuffer_yptr_top = 0; 00044 LCD_CacheBuffer_yptr_bottom = 0; 00045 00046 LCD_CacheBuffer_yptr_top_bak = 0; 00047 LCD_CacheBuffer_yptr_bottom_bak = 0; 00048 00049 LCD_CacheBuffer_yptr_invert= ENABLE; 00050 LCD_ScrollActive = DISABLE; 00051 LCD_Lock = DISABLE; 00052 LCD_Scrolled = DISABLE; 00053 LCD_ScrollBackStep = 0; 00054 } 00055 00056 /** 00057 * @brief Display the application header on the LCD screen 00058 * @param header: pointer to the string to be displayed 00059 * @retval None 00060 */ 00061 void LCD_LOG_SetHeader (uint8_t *header) 00062 { 00063 /* Set the LCD Font */ 00064 BSP_LCD_SetFont (&LCD_LOG_HEADER_FONT); 00065 00066 BSP_LCD_SetTextColor(LCD_LOG_SOLID_BACKGROUND_COLOR); 00067 BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), LCD_LOG_HEADER_FONT.Height); 00068 00069 /* Set the LCD Text Color */ 00070 BSP_LCD_SetTextColor(LCD_LOG_SOLID_TEXT_COLOR); 00071 BSP_LCD_SetBackColor(LCD_LOG_SOLID_BACKGROUND_COLOR); 00072 00073 BSP_LCD_DisplayStringAt(0, 0, header, CENTER_MODE); 00074 00075 BSP_LCD_SetBackColor(LCD_LOG_BACKGROUND_COLOR); 00076 BSP_LCD_SetTextColor(LCD_LOG_TEXT_COLOR); 00077 BSP_LCD_SetFont (&LCD_LOG_TEXT_FONT); 00078 } 00079 00080 /** 00081 * @brief Display the application footer on the LCD screen 00082 * @param footer: pointer to the string to be displayed 00083 * @retval None 00084 */ 00085 void LCD_LOG_SetFooter(uint8_t *footer) 00086 { 00087 /* Set the LCD Font */ 00088 BSP_LCD_SetFont (&LCD_LOG_FOOTER_FONT); 00089 00090 BSP_LCD_SetTextColor(LCD_LOG_SOLID_BACKGROUND_COLOR); 00091 BSP_LCD_FillRect(0, BSP_LCD_GetYSize() - LCD_LOG_FOOTER_FONT.Height - 4, BSP_LCD_GetXSize(), LCD_LOG_FOOTER_FONT.Height + 4); 00092 00093 /* Set the LCD Text Color */ 00094 BSP_LCD_SetTextColor(LCD_LOG_SOLID_TEXT_COLOR); 00095 BSP_LCD_SetBackColor(LCD_LOG_SOLID_BACKGROUND_COLOR); 00096 00097 BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - LCD_LOG_FOOTER_FONT.Height, footer, CENTER_MODE); 00098 00099 BSP_LCD_SetBackColor(LCD_LOG_BACKGROUND_COLOR); 00100 BSP_LCD_SetTextColor(LCD_LOG_TEXT_COLOR); 00101 BSP_LCD_SetFont (&LCD_LOG_TEXT_FONT); 00102 } 00103 00104 /** 00105 * @brief Clear the Text Zone 00106 * @param None 00107 * @retval None 00108 */ 00109 void LCD_LOG_ClearTextZone(void) 00110 { 00111 uint8_t i=0; 00112 00113 for (i= 0 ; i < YWINDOW_SIZE; i++) 00114 { 00115 BSP_LCD_ClearStringLine(i + YWINDOW_MIN); 00116 } 00117 00118 LCD_LOG_DeInit(); 00119 } 00120 00121 /** 00122 * @brief Redirect the printf to the LCD 00123 * @param c: character to be displayed 00124 * @param f: output file pointer 00125 * @retval None 00126 */ 00127 LCD_LOG_PUTCHAR 00128 { 00129 00130 sFONT *cFont = BSP_LCD_GetFont(); 00131 uint32_t idx; 00132 00133 if(LCD_Lock == DISABLE) 00134 { 00135 if(LCD_ScrollActive == ENABLE) 00136 { 00137 LCD_CacheBuffer_yptr_bottom = LCD_CacheBuffer_yptr_bottom_bak; 00138 LCD_CacheBuffer_yptr_top = LCD_CacheBuffer_yptr_top_bak; 00139 LCD_ScrollActive = DISABLE; 00140 LCD_Scrolled = DISABLE; 00141 LCD_ScrollBackStep = 0; 00142 00143 } 00144 00145 if(( LCD_CacheBuffer_xptr < (BSP_LCD_GetXSize()) /cFont->Width ) && ( ch != '\n')) 00146 { 00147 LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = (uint16_t)ch; 00148 } 00149 else 00150 { 00151 if(LCD_CacheBuffer_yptr_top >= LCD_CacheBuffer_yptr_bottom) 00152 { 00153 00154 if(LCD_CacheBuffer_yptr_invert == DISABLE) 00155 { 00156 LCD_CacheBuffer_yptr_top++; 00157 00158 if(LCD_CacheBuffer_yptr_top == LCD_CACHE_DEPTH) 00159 { 00160 LCD_CacheBuffer_yptr_top = 0; 00161 } 00162 } 00163 else 00164 { 00165 LCD_CacheBuffer_yptr_invert= DISABLE; 00166 } 00167 } 00168 00169 for(idx = LCD_CacheBuffer_xptr ; idx < (BSP_LCD_GetXSize()) /cFont->Width; idx++) 00170 { 00171 LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = ' '; 00172 } 00173 LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].color = LCD_LineColor; 00174 00175 LCD_CacheBuffer_xptr = 0; 00176 00177 LCD_LOG_UpdateDisplay (); 00178 00179 LCD_CacheBuffer_yptr_bottom ++; 00180 00181 if (LCD_CacheBuffer_yptr_bottom == LCD_CACHE_DEPTH) 00182 { 00183 LCD_CacheBuffer_yptr_bottom = 0; 00184 LCD_CacheBuffer_yptr_top = 1; 00185 LCD_CacheBuffer_yptr_invert = ENABLE; 00186 } 00187 00188 if( ch != '\n') 00189 { 00190 LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = (uint16_t)ch; 00191 } 00192 00193 } 00194 } 00195 return ch; 00196 } 00197 00198 /** 00199 * @brief Update the text area display 00200 * @param None 00201 * @retval None 00202 */ 00203 void LCD_LOG_UpdateDisplay (void) 00204 { 00205 uint8_t cnt = 0 ; 00206 uint16_t length = 0 ; 00207 uint16_t ptr = 0, index = 0; 00208 00209 if((LCD_CacheBuffer_yptr_bottom < (YWINDOW_SIZE -1)) && 00210 (LCD_CacheBuffer_yptr_bottom >= LCD_CacheBuffer_yptr_top)) 00211 { 00212 BSP_LCD_SetTextColor(LCD_CacheBuffer[cnt + LCD_CacheBuffer_yptr_bottom].color); 00213 BSP_LCD_DisplayStringAtLine ((YWINDOW_MIN + LCD_CacheBuffer_yptr_bottom), 00214 (uint8_t *)(LCD_CacheBuffer[cnt + LCD_CacheBuffer_yptr_bottom].line)); 00215 } 00216 else 00217 { 00218 00219 if(LCD_CacheBuffer_yptr_bottom < LCD_CacheBuffer_yptr_top) 00220 { 00221 /* Virtual length for rolling */ 00222 length = LCD_CACHE_DEPTH + LCD_CacheBuffer_yptr_bottom ; 00223 } 00224 else 00225 { 00226 length = LCD_CacheBuffer_yptr_bottom; 00227 } 00228 00229 ptr = length - YWINDOW_SIZE + 1; 00230 00231 for (cnt = 0 ; cnt < YWINDOW_SIZE ; cnt ++) 00232 { 00233 00234 index = (cnt + ptr )% LCD_CACHE_DEPTH ; 00235 00236 BSP_LCD_SetTextColor(LCD_CacheBuffer[index].color); 00237 BSP_LCD_DisplayStringAtLine ((cnt + YWINDOW_MIN), 00238 (uint8_t *)(LCD_CacheBuffer[index].line)); 00239 00240 } 00241 } 00242 00243 } 00244 00245 #if( LCD_SCROLL_ENABLED == 1) 00246 /** 00247 * @brief Display previous text frame 00248 * @param None 00249 * @retval Status 00250 */ 00251 ErrorStatus LCD_LOG_ScrollBack(void) 00252 { 00253 00254 if(LCD_ScrollActive == DISABLE) 00255 { 00256 00257 LCD_CacheBuffer_yptr_bottom_bak = LCD_CacheBuffer_yptr_bottom; 00258 LCD_CacheBuffer_yptr_top_bak = LCD_CacheBuffer_yptr_top; 00259 00260 00261 if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top) 00262 { 00263 00264 if ((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) <= YWINDOW_SIZE) 00265 { 00266 LCD_Lock = DISABLE; 00267 return ERROR; 00268 } 00269 } 00270 LCD_ScrollActive = ENABLE; 00271 00272 if((LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top)&& 00273 (LCD_Scrolled == DISABLE )) 00274 { 00275 LCD_CacheBuffer_yptr_bottom--; 00276 LCD_Scrolled = ENABLE; 00277 } 00278 00279 } 00280 00281 if(LCD_ScrollActive == ENABLE) 00282 { 00283 LCD_Lock = ENABLE; 00284 00285 if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top) 00286 { 00287 00288 if((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) < YWINDOW_SIZE ) 00289 { 00290 LCD_Lock = DISABLE; 00291 return ERROR; 00292 } 00293 00294 LCD_CacheBuffer_yptr_bottom --; 00295 } 00296 else if(LCD_CacheBuffer_yptr_bottom <= LCD_CacheBuffer_yptr_top) 00297 { 00298 00299 if((LCD_CACHE_DEPTH - LCD_CacheBuffer_yptr_top + LCD_CacheBuffer_yptr_bottom) < YWINDOW_SIZE) 00300 { 00301 LCD_Lock = DISABLE; 00302 return ERROR; 00303 } 00304 LCD_CacheBuffer_yptr_bottom --; 00305 00306 if(LCD_CacheBuffer_yptr_bottom == 0xFFFF) 00307 { 00308 LCD_CacheBuffer_yptr_bottom = LCD_CACHE_DEPTH - 2; 00309 } 00310 } 00311 LCD_ScrollBackStep++; 00312 LCD_LOG_UpdateDisplay(); 00313 LCD_Lock = DISABLE; 00314 } 00315 return SUCCESS; 00316 } 00317 00318 /** 00319 * @brief Display next text frame 00320 * @param None 00321 * @retval Status 00322 */ 00323 ErrorStatus LCD_LOG_ScrollForward(void) 00324 { 00325 00326 if(LCD_ScrollBackStep != 0) 00327 { 00328 if(LCD_ScrollActive == DISABLE) 00329 { 00330 00331 LCD_CacheBuffer_yptr_bottom_bak = LCD_CacheBuffer_yptr_bottom; 00332 LCD_CacheBuffer_yptr_top_bak = LCD_CacheBuffer_yptr_top; 00333 00334 if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top) 00335 { 00336 00337 if ((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) <= YWINDOW_SIZE) 00338 { 00339 LCD_Lock = DISABLE; 00340 return ERROR; 00341 } 00342 } 00343 LCD_ScrollActive = ENABLE; 00344 00345 if((LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top)&& 00346 (LCD_Scrolled == DISABLE )) 00347 { 00348 LCD_CacheBuffer_yptr_bottom--; 00349 LCD_Scrolled = ENABLE; 00350 } 00351 00352 } 00353 00354 if(LCD_ScrollActive == ENABLE) 00355 { 00356 LCD_Lock = ENABLE; 00357 LCD_ScrollBackStep--; 00358 00359 if(++LCD_CacheBuffer_yptr_bottom == LCD_CACHE_DEPTH) 00360 { 00361 LCD_CacheBuffer_yptr_bottom = 0; 00362 } 00363 00364 LCD_LOG_UpdateDisplay(); 00365 LCD_Lock = DISABLE; 00366 00367 } 00368 return SUCCESS; 00369 } 00370 else // LCD_ScrollBackStep == 0 00371 { 00372 LCD_Lock = DISABLE; 00373 return ERROR; 00374 } 00375 } 00376 #endif /* LCD_SCROLL_ENABLED */ 00377 00378 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Jul 22 2022 06:45:02 by
1.7.2