lcd.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* most of this is taken from the file */
  2. /* hal/powerpc/cogent/current/src/hal_diag.c in the */
  3. /* Cygnus eCos source. Here is the copyright notice: */
  4. /* */
  5. /*============================================================================= */
  6. /* */
  7. /* hal_diag.c */
  8. /* */
  9. /* HAL diagnostic output code */
  10. /* */
  11. /*============================================================================= */
  12. /*####COPYRIGHTBEGIN#### */
  13. /* */
  14. /* ------------------------------------------- */
  15. /* The contents of this file are subject to the Cygnus eCos Public License */
  16. /* Version 1.0 (the "License"); you may not use this file except in */
  17. /* compliance with the License. You may obtain a copy of the License at */
  18. /* http://sourceware.cygnus.com/ecos */
  19. /* */
  20. /* Software distributed under the License is distributed on an "AS IS" */
  21. /* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the */
  22. /* License for the specific language governing rights and limitations under */
  23. /* the License. */
  24. /* */
  25. /* The Original Code is eCos - Embedded Cygnus Operating System, released */
  26. /* September 30, 1998. */
  27. /* */
  28. /* The Initial Developer of the Original Code is Cygnus. Portions created */
  29. /* by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. */
  30. /* ------------------------------------------- */
  31. /* */
  32. /*####COPYRIGHTEND#### */
  33. /*============================================================================= */
  34. /*#####DESCRIPTIONBEGIN#### */
  35. /* */
  36. /* Author(s): nickg, jskov */
  37. /* Contributors: nickg, jskov */
  38. /* Date: 1999-03-23 */
  39. /* Purpose: HAL diagnostic output */
  40. /* Description: Implementations of HAL diagnostic output support. */
  41. /* */
  42. /*####DESCRIPTIONEND#### */
  43. /* */
  44. /*============================================================================= */
  45. /*----------------------------------------------------------------------------- */
  46. /* Cogent board specific LCD code */
  47. #include <common.h>
  48. #include <stdarg.h>
  49. #include <board/cogent/lcd.h>
  50. static char lines[2][LCD_LINE_LENGTH+1];
  51. static int curline;
  52. static int linepos;
  53. static int heartbeat_active;
  54. /* make the next two strings exactly LCD_LINE_LENGTH (16) chars long */
  55. /* pad to the right with spaces if necessary */
  56. static char init_line0[LCD_LINE_LENGTH+1] = "U-Boot Cogent ";
  57. static char init_line1[LCD_LINE_LENGTH+1] = "mjj, 11 Aug 2000";
  58. static inline unsigned char
  59. lcd_read_status(cma_mb_lcd *clp)
  60. {
  61. /* read the Busy Status Register */
  62. return (cma_mb_reg_read(&clp->lcd_bsr));
  63. }
  64. static inline void
  65. lcd_wait_not_busy(cma_mb_lcd *clp)
  66. {
  67. /*
  68. * wait for not busy
  69. * Note: It seems that the LCD isn't quite ready to process commands
  70. * when it clears the BUSY flag. Reading the status address an extra
  71. * time seems to give it enough breathing room.
  72. */
  73. while (lcd_read_status(clp) & LCD_STAT_BUSY)
  74. ;
  75. (void)lcd_read_status(clp);
  76. }
  77. static inline void
  78. lcd_write_command(cma_mb_lcd *clp, unsigned char cmd)
  79. {
  80. lcd_wait_not_busy(clp);
  81. /* write the Command Register */
  82. cma_mb_reg_write(&clp->lcd_cmd, cmd);
  83. }
  84. static inline void
  85. lcd_write_data(cma_mb_lcd *clp, unsigned char data)
  86. {
  87. lcd_wait_not_busy(clp);
  88. /* write the Current Character Register */
  89. cma_mb_reg_write(&clp->lcd_ccr, data);
  90. }
  91. static inline void
  92. lcd_dis(int addr, char *string)
  93. {
  94. cma_mb_lcd *clp = (cma_mb_lcd *)CMA_MB_LCD_BASE;
  95. int pos, linelen;
  96. linelen = LCD_LINE_LENGTH;
  97. if (heartbeat_active && addr == LCD_LINE0)
  98. linelen--;
  99. lcd_write_command(clp, LCD_CMD_ADD + addr);
  100. for (pos = 0; *string != '\0' && pos < linelen; pos++)
  101. lcd_write_data(clp, *string++);
  102. }
  103. void
  104. lcd_init(void)
  105. {
  106. cma_mb_lcd *clp = (cma_mb_lcd *)CMA_MB_LCD_BASE;
  107. int i;
  108. /* configure the lcd for 8 bits/char, 2 lines and 5x7 dot matrix */
  109. lcd_write_command(clp, LCD_CMD_MODE);
  110. /* turn the LCD display on */
  111. lcd_write_command(clp, LCD_CMD_DON);
  112. curline = 0;
  113. linepos = 0;
  114. for (i = 0; i < LCD_LINE_LENGTH; i++) {
  115. lines[0][i] = init_line0[i];
  116. lines[1][i] = init_line1[i];
  117. }
  118. lines[0][LCD_LINE_LENGTH] = lines[1][LCD_LINE_LENGTH] = 0;
  119. lcd_dis(LCD_LINE0, lines[0]);
  120. lcd_dis(LCD_LINE1, lines[1]);
  121. printf("HD44780 2 line x %d char display\n", LCD_LINE_LENGTH);
  122. }
  123. void
  124. lcd_write_char(const char c)
  125. {
  126. int i, linelen;
  127. /* ignore CR */
  128. if (c == '\r')
  129. return;
  130. linelen = LCD_LINE_LENGTH;
  131. if (heartbeat_active && curline == 0)
  132. linelen--;
  133. if (c == '\n') {
  134. lcd_dis(LCD_LINE0, &lines[curline^1][0]);
  135. lcd_dis(LCD_LINE1, &lines[curline][0]);
  136. /* Do a line feed */
  137. curline ^= 1;
  138. linelen = LCD_LINE_LENGTH;
  139. if (heartbeat_active && curline == 0)
  140. linelen--;
  141. linepos = 0;
  142. for (i = 0; i < linelen; i++)
  143. lines[curline][i] = ' ';
  144. return;
  145. }
  146. /* Only allow to be output if there is room on the LCD line */
  147. if (linepos < linelen)
  148. lines[curline][linepos++] = c;
  149. }
  150. void
  151. lcd_flush(void)
  152. {
  153. lcd_dis(LCD_LINE1, &lines[curline][0]);
  154. }
  155. void
  156. lcd_write_string(const char *s)
  157. {
  158. char *p;
  159. for (p = (char *)s; *p != '\0'; p++)
  160. lcd_write_char(*p);
  161. }
  162. void
  163. lcd_printf(const char *fmt, ...)
  164. {
  165. va_list args;
  166. char buf[CONFIG_SYS_PBSIZE];
  167. va_start(args, fmt);
  168. (void)vsprintf(buf, fmt, args);
  169. va_end(args);
  170. lcd_write_string(buf);
  171. }
  172. void
  173. lcd_heartbeat(void)
  174. {
  175. cma_mb_lcd *clp = (cma_mb_lcd *)CMA_MB_LCD_BASE;
  176. #if 0
  177. static char rotchars[] = { '|', '/', '-', '\\' };
  178. #else
  179. /* HD44780 Rom Code A00 has no backslash */
  180. static char rotchars[] = { '|', '/', '-', '\315' };
  181. #endif
  182. static int rotator_index = 0;
  183. heartbeat_active = 1;
  184. /* write the address */
  185. lcd_write_command(clp, LCD_CMD_ADD + LCD_LINE0 + (LCD_LINE_LENGTH - 1));
  186. /* write the next char in the sequence */
  187. lcd_write_data(clp, rotchars[rotator_index]);
  188. if (++rotator_index >= (sizeof rotchars / sizeof rotchars[0]))
  189. rotator_index = 0;
  190. }
  191. #ifdef CONFIG_SHOW_ACTIVITY
  192. void board_show_activity (ulong timestamp)
  193. {
  194. #ifdef CONFIG_STATUS_LED
  195. if ((timestamp % (CONFIG_SYS_HZ / 2) == 0)
  196. lcd_heartbeat ();
  197. #endif
  198. }
  199. void show_activity(int arg)
  200. {
  201. }
  202. #endif