test

Dependents:   Datarecorder2

Files at this revision

API Documentation at this revision

Comitter:
joschaihl
Date:
Sun May 28 11:16:02 2017 +0000
Commit message:
Library for logging on STM32F7 DISCO

Changed in this revision

lcd_log.cpp Show annotated file Show diff for this revision Revisions of this file
lcd_log.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a9366f354506 lcd_log.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcd_log.cpp	Sun May 28 11:16:02 2017 +0000
@@ -0,0 +1,378 @@
+#include  <stdio.h>
+#include  "lcd_log.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;
+
+FunctionalState LCD_CacheBuffer_yptr_invert;
+FunctionalState LCD_ScrollActive;
+FunctionalState LCD_Lock;
+FunctionalState LCD_Scrolled;
+uint16_t LCD_ScrollBackStep;
+/**
+  * @brief  Initializes the LCD Log module 
+  * @param  None
+  * @retval None
+  */
+
+void LCD_LOG_Init ( void)
+{
+  /* Deinit LCD cache */
+  LCD_LOG_DeInit();
+  
+  /* Clear the LCD */
+  BSP_LCD_Clear(LCD_LOG_BACKGROUND_COLOR);  
+}
+
+/**
+  * @brief DeInitializes the LCD Log module. 
+  * @param  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 on the LCD screen 
+  * @param  header: pointer to the string to be displayed
+  * @retval None
+  */
+void LCD_LOG_SetHeader (uint8_t *header)
+{
+  /* Set the LCD Font */
+  BSP_LCD_SetFont (&LCD_LOG_HEADER_FONT);
+
+  BSP_LCD_SetTextColor(LCD_LOG_SOLID_BACKGROUND_COLOR);
+  BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), LCD_LOG_HEADER_FONT.Height);
+  
+  /* Set the LCD Text Color */
+  BSP_LCD_SetTextColor(LCD_LOG_SOLID_TEXT_COLOR);
+  BSP_LCD_SetBackColor(LCD_LOG_SOLID_BACKGROUND_COLOR);
+
+  BSP_LCD_DisplayStringAt(0, 0, header, CENTER_MODE);
+
+  BSP_LCD_SetBackColor(LCD_LOG_BACKGROUND_COLOR);
+  BSP_LCD_SetTextColor(LCD_LOG_TEXT_COLOR);
+  BSP_LCD_SetFont (&LCD_LOG_TEXT_FONT);
+}
+
+/**
+  * @brief  Display the application footer on the LCD screen 
+  * @param  footer: pointer to the string to be displayed
+  * @retval None
+  */
+void LCD_LOG_SetFooter(uint8_t *footer)
+{
+  /* Set the LCD Font */
+  BSP_LCD_SetFont (&LCD_LOG_FOOTER_FONT);
+
+  BSP_LCD_SetTextColor(LCD_LOG_SOLID_BACKGROUND_COLOR);
+  BSP_LCD_FillRect(0, BSP_LCD_GetYSize() - LCD_LOG_FOOTER_FONT.Height - 4, BSP_LCD_GetXSize(), LCD_LOG_FOOTER_FONT.Height + 4);
+  
+  /* Set the LCD Text Color */
+  BSP_LCD_SetTextColor(LCD_LOG_SOLID_TEXT_COLOR);
+  BSP_LCD_SetBackColor(LCD_LOG_SOLID_BACKGROUND_COLOR);
+
+  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - LCD_LOG_FOOTER_FONT.Height, footer, CENTER_MODE);
+
+  BSP_LCD_SetBackColor(LCD_LOG_BACKGROUND_COLOR);
+  BSP_LCD_SetTextColor(LCD_LOG_TEXT_COLOR);
+  BSP_LCD_SetFont (&LCD_LOG_TEXT_FONT);
+}
+
+/**
+  * @brief  Clear the Text Zone 
+  * @param  None 
+  * @retval None
+  */
+void LCD_LOG_ClearTextZone(void)
+{
+  uint8_t i=0;
+  
+  for (i= 0 ; i < YWINDOW_SIZE; i++)
+  {
+    BSP_LCD_ClearStringLine(i + YWINDOW_MIN);
+  }
+  
+  LCD_LOG_DeInit();
+}
+
+/**
+  * @brief  Redirect the printf to the LCD
+  * @param  c: character to be displayed
+  * @param  f: output file pointer
+  * @retval None
+ */
+LCD_LOG_PUTCHAR
+{
+  
+  sFONT *cFont = BSP_LCD_GetFont();
+  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 < (BSP_LCD_GetXSize()) /cFont->Width ) &&  ( ch != '\n'))
+    {
+      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 < (BSP_LCD_GetXSize()) /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')
+      {
+        LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = (uint16_t)ch;
+      }
+      
+    }
+  }
+  return ch;
+}
+  
+/**
+  * @brief  Update the text area display
+  * @param  None
+  * @retval None
+  */
+void LCD_LOG_UpdateDisplay (void)
+{
+  uint8_t cnt = 0 ;
+  uint16_t length = 0 ;
+  uint16_t ptr = 0, index = 0;
+  
+  if((LCD_CacheBuffer_yptr_bottom  < (YWINDOW_SIZE -1)) && 
+     (LCD_CacheBuffer_yptr_bottom  >= LCD_CacheBuffer_yptr_top))
+  {
+    BSP_LCD_SetTextColor(LCD_CacheBuffer[cnt + LCD_CacheBuffer_yptr_bottom].color);
+    BSP_LCD_DisplayStringAtLine ((YWINDOW_MIN + LCD_CacheBuffer_yptr_bottom),
+                           (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 ;
+      
+      BSP_LCD_SetTextColor(LCD_CacheBuffer[index].color);
+      BSP_LCD_DisplayStringAtLine ((cnt + YWINDOW_MIN), 
+                             (uint8_t *)(LCD_CacheBuffer[index].line));
+      
+    }
+  }
+  
+}
+
+#if( LCD_SCROLL_ENABLED == 1)
+/**
+  * @brief  Display previous text frame
+  * @param  None
+  * @retval Status
+  */
+ErrorStatus LCD_LOG_ScrollBack(void)
+{
+    
+  if(LCD_ScrollActive == DISABLE)
+  {
+    
+    LCD_CacheBuffer_yptr_bottom_bak = LCD_CacheBuffer_yptr_bottom;
+    LCD_CacheBuffer_yptr_top_bak    = LCD_CacheBuffer_yptr_top;
+    
+    
+    if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top) 
+    {
+      
+      if ((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) <=  YWINDOW_SIZE)
+      {
+        LCD_Lock = DISABLE;
+        return ERROR;
+      }
+    }
+    LCD_ScrollActive = ENABLE;
+    
+    if((LCD_CacheBuffer_yptr_bottom  > LCD_CacheBuffer_yptr_top)&&
+       (LCD_Scrolled == DISABLE ))
+    {
+      LCD_CacheBuffer_yptr_bottom--;
+      LCD_Scrolled = ENABLE;
+    }
+    
+  }
+  
+  if(LCD_ScrollActive == ENABLE)
+  {
+    LCD_Lock = ENABLE;
+    
+    if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top) 
+    {
+      
+      if((LCD_CacheBuffer_yptr_bottom  - LCD_CacheBuffer_yptr_top) <  YWINDOW_SIZE )
+      {
+        LCD_Lock = DISABLE;
+        return ERROR;
+      }
+      
+      LCD_CacheBuffer_yptr_bottom --;
+    }
+    else if(LCD_CacheBuffer_yptr_bottom <= LCD_CacheBuffer_yptr_top)
+    {
+      
+      if((LCD_CACHE_DEPTH  - LCD_CacheBuffer_yptr_top + LCD_CacheBuffer_yptr_bottom) < YWINDOW_SIZE)
+      {
+        LCD_Lock = DISABLE;
+        return ERROR;
+      }
+      LCD_CacheBuffer_yptr_bottom --;
+      
+      if(LCD_CacheBuffer_yptr_bottom == 0xFFFF)
+      {
+        LCD_CacheBuffer_yptr_bottom = LCD_CACHE_DEPTH - 2;
+      }
+    }
+    LCD_ScrollBackStep++;
+    LCD_LOG_UpdateDisplay();
+    LCD_Lock = DISABLE;
+  }
+  return SUCCESS;
+}
+
+/**
+  * @brief  Display next text frame
+  * @param  None
+  * @retval Status
+  */
+ErrorStatus LCD_LOG_ScrollForward(void)
+{
+  
+  if(LCD_ScrollBackStep != 0)
+  {
+    if(LCD_ScrollActive == DISABLE)
+    {
+      
+      LCD_CacheBuffer_yptr_bottom_bak = LCD_CacheBuffer_yptr_bottom;
+      LCD_CacheBuffer_yptr_top_bak    = LCD_CacheBuffer_yptr_top;
+      
+      if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top) 
+      {
+        
+        if ((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) <=  YWINDOW_SIZE)
+        {
+          LCD_Lock = DISABLE;
+          return ERROR;
+        }
+      }
+      LCD_ScrollActive = ENABLE;
+      
+      if((LCD_CacheBuffer_yptr_bottom  > LCD_CacheBuffer_yptr_top)&&
+         (LCD_Scrolled == DISABLE ))
+      {
+        LCD_CacheBuffer_yptr_bottom--;
+        LCD_Scrolled = ENABLE;
+      }
+      
+    }
+    
+    if(LCD_ScrollActive == ENABLE)
+    {
+      LCD_Lock = ENABLE;
+      LCD_ScrollBackStep--;
+      
+      if(++LCD_CacheBuffer_yptr_bottom == LCD_CACHE_DEPTH)
+      {
+        LCD_CacheBuffer_yptr_bottom = 0;
+      }
+      
+      LCD_LOG_UpdateDisplay();
+      LCD_Lock = DISABLE;
+      
+    } 
+    return SUCCESS;
+  }
+  else // LCD_ScrollBackStep == 0 
+  {
+    LCD_Lock = DISABLE;
+    return ERROR;
+  }  
+}
+#endif /* LCD_SCROLL_ENABLED */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r a9366f354506 lcd_log.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcd_log.h	Sun May 28 11:16:02 2017 +0000
@@ -0,0 +1,88 @@
+#ifndef  __LCD_LOG_H__
+#define  __LCD_LOG_H__
+
+#include "stm32f769i_discovery_lcd.h" /* replace 'stm32xxx' with your EVAL board name, ex: stm324x9i_eval_lcd.h */
+#include <stdio.h>
+
+#define PEACH ((uint32_t) 0xFFf2c6a4)
+#define ZINNWALDITE_BROWN ((uint32_t) 0xff270104)
+
+/* Comment the line below to disable the scroll back and forward features */
+#define     LCD_SCROLL_ENABLED      1 
+
+/* Define the Fonts  */
+#define     LCD_LOG_HEADER_FONT                   Font20
+#define     LCD_LOG_FOOTER_FONT                   Font20
+#define     LCD_LOG_TEXT_FONT                     Font20
+            
+/* Define the LCD LOG Color  */
+#define     LCD_LOG_BACKGROUND_COLOR              PEACH
+#define     LCD_LOG_TEXT_COLOR                    ZINNWALDITE_BROWN
+
+#define     LCD_LOG_SOLID_BACKGROUND_COLOR        LCD_COLOR_BLUE
+#define     LCD_LOG_SOLID_TEXT_COLOR              LCD_COLOR_WHITE
+
+/* Define the cache depth */
+#define     CACHE_SIZE              200
+#define     YWINDOW_SIZE            22
+
+
+#define LCD_LOG_PUTCHAR int std::fputc(int ch, FILE *f)
+
+#define     LCD_CACHE_DEPTH     (YWINDOW_SIZE + CACHE_SIZE)
+
+/* Define the display window settings */
+#define     YWINDOW_MIN         1
+ 
+typedef struct _LCD_LOG_line
+{
+  uint8_t  line[128];
+  uint32_t color;
+
+}LCD_LOG_line;
+
+/**
+  * @}
+  */ 
+
+/** @defgroup LCD_LOG_Exported_Macros
+  * @{
+  */ 
+#define  LCD_ErrLog(...)    do { \
+                                 LCD_LineColor = LCD_COLOR_RED;\
+                                 printf("ERROR: ") ;\
+                                 printf(__VA_ARGS__);\
+                                 LCD_LineColor = LCD_LOG_DEFAULT_COLOR;\
+                               }while (0)
+
+#define  LCD_UsrLog(...)    do { \
+                                 LCD_LineColor = LCD_LOG_TEXT_COLOR;\
+                                 printf(__VA_ARGS__);\
+                               } while (0)
+
+
+#define  LCD_DbgLog(...)    do { \
+                                 LCD_LineColor = LCD_COLOR_CYAN;\
+                                 printf(__VA_ARGS__);\
+                                 LCD_LineColor = LCD_LOG_DEFAULT_COLOR;\
+                               }while (0)
+
+extern uint32_t LCD_LineColor;
+
+void LCD_LOG_Init(void);
+void LCD_LOG_DeInit(void);
+void LCD_LOG_SetHeader(uint8_t *Title);
+void LCD_LOG_SetFooter(uint8_t *Status);
+void LCD_LOG_ClearTextZone(void);
+void LCD_LOG_UpdateDisplay (void);
+
+#if (LCD_SCROLL_ENABLED == 1)
+ ErrorStatus LCD_LOG_ScrollBack(void);
+ ErrorStatus LCD_LOG_ScrollForward(void);
+#endif
+
+//#define LCD_LOG_PUTCHAR int __io_putchar(int ch)
+//#define LCD_LOG_PUTCHAR int fputc(int ch, FILE *f)
+
+
+#endif /* __LCD_LOG_H__ */