hw-test.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * hw-test - test some of the hardware inputs
  3. *
  4. * Copyright (c) 2009 Openmoko Inc.
  5. *
  6. * Authors Christopher Hall <hsw@openmoko.com>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #define APPLICATION_TITLE "Key Test"
  22. #define APPLICATION_TITLE2 "LCD Test"
  23. #include <stdbool.h>
  24. #include "application.h"
  25. #include "lcd.h"
  26. #define DELAY 1000
  27. void key_test(void);
  28. void lcd_test(void);
  29. static bool lcd_items(void);
  30. // this must be the first executable code as the loader executes from the first program address
  31. ReturnType hardware_test(int block, int status)
  32. {
  33. APPLICATION_INITIALISE();
  34. {
  35. switch (status) {
  36. case 0:
  37. key_test();
  38. break;
  39. case 1:
  40. lcd_test();
  41. break;
  42. }
  43. }
  44. APPLICATION_FINALISE(0, 0);
  45. }
  46. void key_test(void)
  47. {
  48. unsigned int state = 0xffff; // impossible key state
  49. print("press buttons on keypad. [any serial input to exit]\n");
  50. while (!console_input_available()) {
  51. unsigned int keys = REG_P6_P6D & 0x07;
  52. if (keys != state) {
  53. state = keys;
  54. print("keys = 0x");
  55. print_byte(REG_P6_P6D & 0x07);
  56. if (0 != (keys & 0x02)) {
  57. print(" random");
  58. } else {
  59. print(" ");
  60. }
  61. if (0 != (keys & 0x04)) {
  62. print(" history");
  63. } else {
  64. print(" ");
  65. }
  66. if (0 != (keys & 0x01)) {
  67. print(" search");
  68. } else {
  69. print(" ");
  70. }
  71. print("\n");
  72. }
  73. }
  74. (void)console_input_char();
  75. }
  76. void lcd_test(void)
  77. {
  78. print("lcd test\n");
  79. print("LCD_VRAM = ");
  80. print_hex(LCD_VRAM);
  81. print_char('\n');
  82. print("LCD_HEIGHT_LINES = ");
  83. print_uint(LCD_HEIGHT_LINES);
  84. print_char('\n');
  85. print("LCD_WIDTH_PIXELS = ");
  86. print_uint(LCD_WIDTH_PIXELS);
  87. print_char('\n');
  88. print("LCD_WIDTH_BYTES = ");
  89. print_uint(LCD_WIDTH_BYTES);
  90. print_char('\n');
  91. print("VRAM_HEIGHT_LINES = ");
  92. print_uint(LCD_VRAM_HEIGHT_LINES);
  93. print_char('\n');
  94. print("VRAM_WIDTH_PIXELS = ");
  95. print_uint(LCD_VRAM_WIDTH_PIXELS);
  96. print_char('\n');
  97. print("VRAM_WIDTH_BYTES = ");
  98. print_uint(LCD_VRAM_WIDTH_BYTES);
  99. print_char('\n');
  100. LCD_initialise();
  101. do {
  102. print("loop (space->pause/resume, enter -> exit)\n");
  103. } while (lcd_items());
  104. }
  105. static bool pause(const char *prompt, int millisec)
  106. {
  107. int i = 0;
  108. print(prompt);
  109. for (i = 0; i < millisec; ++i) {
  110. delay_us(1000);
  111. if (console_input_available()) {
  112. char c = 0;
  113. c = console_input_char();
  114. if ('\r' == c || '\n' == c) {
  115. return true;
  116. }
  117. c = console_input_char();
  118. if ('\r' == c || '\n' == c) {
  119. return true;
  120. }
  121. break;
  122. }
  123. }
  124. return false;
  125. }
  126. static void fill(uint8_t value)
  127. {
  128. int x = 0;
  129. int y = 0;
  130. uint8_t *fb = (uint8_t*)LCD_VRAM;
  131. for (y = 0; y < LCD_HEIGHT_LINES; ++y) {
  132. for (x = 0; x < LCD_VRAM_WIDTH_BYTES; ++x) {
  133. *fb++ = value;
  134. }
  135. }
  136. }
  137. static void stripe(uint8_t value, uint8_t fill)
  138. {
  139. int x = 0;
  140. int y = 0;
  141. uint8_t *fb = (uint8_t*)LCD_VRAM;
  142. for (y = 0; y < LCD_HEIGHT_LINES; ++y) {
  143. for (x = 0; x < LCD_VRAM_WIDTH_BYTES; ++x) {
  144. *fb++ = (0 == (y & (1 << 5))) ? value : fill;
  145. }
  146. }
  147. }
  148. #if 0
  149. static void display_image(uint8_t toggle)
  150. {
  151. int x = 0;
  152. const uint8_t *src = image_data;
  153. uint8_t *fb = (uint8_t*)LCD_VRAM;
  154. int l = 0;
  155. fill(toggle);
  156. for (l = 0; l < sizeof(image_data); ++l) {
  157. fb[x] = toggle ^ *src++;
  158. ++x;
  159. if (LCD_WIDTH_BYTES <= x) {
  160. x = 0;
  161. fb += LCD_VRAM_WIDTH_BYTES;
  162. }
  163. }
  164. }
  165. #endif
  166. static bool lcd_items(void)
  167. {
  168. fill(0);
  169. if (pause("00 ", DELAY)) {
  170. return false;
  171. }
  172. fill(0xff);
  173. if (pause("ff ", DELAY)) {
  174. return false;
  175. }
  176. fill(0x55);
  177. if (pause("55 ", DELAY)) {
  178. return false;
  179. }
  180. fill(0x44);
  181. if (pause("44 ", DELAY)) {
  182. return false;
  183. }
  184. fill(0xf7);
  185. if (pause("f7 ", DELAY)) {
  186. return false;
  187. }
  188. print_char('\n');
  189. print("stripe(00) ");
  190. stripe(0xff, 0x00);
  191. if (pause("ff ", DELAY)) {
  192. return false;
  193. }
  194. stripe(0x01, 0x00);
  195. if (pause("01 ", DELAY)) {
  196. return false;
  197. }
  198. print_char('\n');
  199. print("stripe(ff) ");
  200. stripe(0x00, 0xff);
  201. if (pause("00 ", DELAY)) {
  202. return false;
  203. }
  204. stripe(0xee, 0xff);
  205. if (pause("7f ", DELAY)) {
  206. return false;
  207. }
  208. print_char('\n');
  209. #if 0
  210. display_image(0x00);
  211. if (pause("image(00)", DELAY)) {
  212. return false;
  213. }
  214. print_char('\n');
  215. display_image(0xff);
  216. if (pause("image(ff)", DELAY)) {
  217. return false;
  218. }
  219. print_char('\n');
  220. #endif
  221. return true;
  222. }