lcd_log.c 7.9 KB

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