selftest.ino 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. #include <EEPROM.h>
  2. #include <SPI.h>
  3. #include <GD2.h>
  4. #define GD3 ft8xx_model
  5. #define UART_SPEED 115200
  6. #include "selftest_assets.h"
  7. #define SCREEN_ADDR 0x30000UL
  8. byte x, y;
  9. static void log(const char*s)
  10. {
  11. while (*s) {
  12. char c = *s++;
  13. #ifndef RASPBERRY_PI
  14. Serial.write(c);
  15. #endif
  16. if (c == '\n') {
  17. x = 0;
  18. y++;
  19. } else {
  20. uint32_t dst = SCREEN_ADDR + (((x + (y * 48)) << 1));
  21. GD.wr16(dst, 0x0f00 | c);
  22. x++;
  23. }
  24. };
  25. }
  26. void setup()
  27. {
  28. Serial.begin(UART_SPEED);
  29. Serial.println("---- GAMEDUINO 2/3 SELFTEST ----");
  30. }
  31. static void ramp(int y, uint32_t color)
  32. {
  33. GD.ScissorSize(400, 8);
  34. GD.ScissorXY(40, y);
  35. GD.cmd_gradient(40, 0, 0x000000, 440, 0, color);
  36. }
  37. void testcard(int pass, const char *message)
  38. {
  39. // GD.ClearColorRGB(0x204060);
  40. GD.get_inputs();
  41. GD.Clear();
  42. GD.cmd_text(GD.w / 2, 12, 28, OPT_CENTER,
  43. GD3 ? "Gameduino3 Self test" :
  44. "Gameduino2 Self test");
  45. GD.cmd_text(GD.w - 2, 12, 27, OPT_CENTERY | OPT_RIGHTX,
  46. GD2_VERSION);
  47. int y;
  48. y = PIXELS(50);
  49. GD.Begin(POINTS);
  50. for (int i = 0; i < 6; i++) {
  51. byte l = 4 << i;
  52. int x = map(1 + i, 0, 7, 0, PIXELS(GD.w));
  53. GD.PointSize(280);
  54. GD.ColorRGB(0xffffff);
  55. GD.Vertex2f(x, y);
  56. GD.PointSize(240);
  57. GD.ColorRGB(l, l, l);
  58. GD.Vertex2f(x, y);
  59. }
  60. y += 30;
  61. ramp(y, 0xff0000); y += 12;
  62. ramp(y, 0x00ff00); y += 12;
  63. ramp(y, 0x0000ff); y += 12;
  64. ramp(y, 0xffffff); y += 12;
  65. GD.RestoreContext();
  66. // GD.Begin(BITMAPS);
  67. // GD.Vertex2ii(0, 272 - (8 * 16), 1, 0);
  68. // GD.Vertex2ii(480 - LENA_WIDTH, 272 - LENA_WIDTH, 0, 0);
  69. if (pass == -1)
  70. GD.ColorRGB(0x808000);
  71. else
  72. GD.ColorRGB(pass ? 0x40ff40 : 0xff4040);
  73. GD.cmd_text(GD.w / 2, 180, 31, OPT_CENTER, message);
  74. GD.ColorRGB(0xffffff);
  75. GD.Begin(LINES);
  76. GD.Vertex2f(PIXELS(GD.inputs.x), PIXELS(0));
  77. GD.Vertex2f(PIXELS(GD.inputs.x), PIXELS(GD.h));
  78. GD.Vertex2f(PIXELS(0), PIXELS(GD.inputs.y));
  79. GD.Vertex2f(PIXELS(GD.w), PIXELS(GD.inputs.y));
  80. GD.swap();
  81. GD.finish();
  82. }
  83. #define SCREENTEST(NAME) \
  84. do { \
  85. Serial.println(#NAME); \
  86. testcard(-1, #NAME); \
  87. r = test_##NAME(); \
  88. const char* msg = r ? (#NAME ": pass") : (#NAME ": FAIL"); \
  89. Serial.println(msg); \
  90. testcard(r, msg); \
  91. while (!r) ; \
  92. } while (0)
  93. int test_ident()
  94. {
  95. byte id = GD.rd(REG_ID);
  96. if (id != 0x7c) {
  97. Serial.println(id, HEX);
  98. return 0;
  99. }
  100. return 1;
  101. }
  102. int test_clock()
  103. {
  104. int SPEEDUP = 8;
  105. GD.rd32(REG_CLOCK); // warm-up
  106. delay(10);
  107. long t1 = GD.rd32(REG_CLOCK);
  108. delay(1000 / SPEEDUP);
  109. long t2 = GD.rd32(REG_CLOCK);
  110. float measured = float(t2 - t1);
  111. // measured should be 48e6, within 2%
  112. float expected = (GD3 ? 60e6 : 48e6) / SPEEDUP;
  113. Serial.println(measured, DEC);
  114. Serial.println(expected, DEC);
  115. float diff = measured - expected;
  116. float percent = fabs(100 * (diff / expected));
  117. return percent < 5.0;
  118. }
  119. int test_tune()
  120. {
  121. GD.tune();
  122. return 1;
  123. }
  124. static byte test_RAM(void)
  125. {
  126. uint32_t a;
  127. for (a = 0; a < 0x40000U; a += 947)
  128. GD.wr(a, a);
  129. for (a = 0; a < 0x40000U; a += 947)
  130. if (GD.rd(a) != (a & 0xff))
  131. return 0;
  132. return 1;
  133. }
  134. static byte test_PWM(void)
  135. {
  136. for (int i = 128; i >= 0; i--) {
  137. GD.wr(REG_PWM_DUTY, i);
  138. delay(2);
  139. }
  140. GD.wr(REG_PWM_DUTY, 128);
  141. return 1;
  142. }
  143. static byte test_storage(void)
  144. {
  145. GD.storage();
  146. return test_ident();
  147. }
  148. static byte test_SDcard(void)
  149. {
  150. for (byte i = 0; i < 2; i++) {
  151. GD.safeload("selftest.gd2");
  152. uint32_t pcrc = GD.cmd_memcrc(0, ASSETS_END);
  153. GD.finish();
  154. uint32_t crc = GD.rd32(pcrc);
  155. if (crc != KITTEN_CRC)
  156. return 0;
  157. }
  158. return 1;
  159. }
  160. static void collect(int &rx, int &ry, int &rz)
  161. {
  162. uint16_t ax = 0, ay = 0, az = 0;
  163. for (byte i = 32; i; i--) {
  164. int x = 0, y = 0, z = 0;
  165. #ifdef A2
  166. x = analogRead(A2);
  167. #endif
  168. #ifdef A1
  169. y = analogRead(A1);
  170. #endif
  171. #ifdef A0
  172. z = analogRead(A0);
  173. #endif
  174. ax += x;
  175. ay += y;
  176. az += z;
  177. }
  178. rx = ax >> 5;
  179. ry = ay >> 5;
  180. rz = az >> 5;
  181. }
  182. static byte test_accel2(void)
  183. {
  184. while (1) {
  185. GD.finish();
  186. if ((millis() % 2000) < 1000)
  187. GD.wr(REG_GPIO, 0x80);
  188. else
  189. GD.wr(REG_GPIO, 0x81);
  190. int x, y, z;
  191. collect(x, y, z);
  192. GD.Clear();
  193. GD.cmd_number(0, 40, 26, 3, x);
  194. GD.cmd_slider(50, 40, 400, 10, 0, x, 512);
  195. GD.cmd_number(0, 70, 26, 3, y);
  196. GD.cmd_slider(50, 70, 400, 10, 0, y, 512);
  197. GD.cmd_number(0, 100, 26, 3, GD.rd(REG_GPIO));
  198. GD.cmd_slider(50, 100, 400, 10, 0, z, 512);
  199. GD.swap();
  200. }
  201. return 1;
  202. }
  203. static byte test_accel(void)
  204. {
  205. int x0, y0, z0;
  206. int x1, y1, z1;
  207. GD.wr(REG_GPIO, 0x80);
  208. collect(x0, y0, z0);
  209. delay(100);
  210. GD.wr(REG_GPIO, 0x81);
  211. delay(100);
  212. collect(x1, y1, z1);
  213. Serial.print(x0); Serial.print(" "); Serial.print(y0); Serial.print(" "); Serial.println(z0);
  214. Serial.print(x1); Serial.print(" "); Serial.print(y1); Serial.print(" "); Serial.println(z1);
  215. // if ((x0 > x1) || (y0 > y1) || (z0 > z1)) return 0;
  216. int d;
  217. d = abs(x0 - x1);
  218. if ((d < 30) || (120 < d))
  219. return 0;
  220. d = abs(y0 - y1);
  221. if ((d < 30) || (120 < d))
  222. return 0;
  223. d = abs(z0 - z1);
  224. if ((d < 50) || (200 < d))
  225. return 0;
  226. z0 %= 37;
  227. while (z0--)
  228. GD.random();
  229. return 1;
  230. }
  231. static void play(uint16_t n)
  232. {
  233. GD.wr16(REG_SOUND, n);
  234. GD.wr(REG_PLAY, 1);
  235. }
  236. static void play_wait(uint16_t n)
  237. {
  238. play(n);
  239. while (GD.rd(REG_PLAY))
  240. ;
  241. }
  242. static byte test_touch(void)
  243. {
  244. if (!GD3) {
  245. GD.self_calibrate();
  246. // write the new calibration back to EEPROM
  247. #if !defined(RASPBERRY_PI) && !defined(__DUE__)
  248. for (int i = 0; i < 24; i++)
  249. EEPROM.write(1 + i, GD.rd(REG_TOUCH_TRANSFORM_A + i));
  250. #endif
  251. }
  252. byte hit = 0;
  253. while (hit != 0x0f) {
  254. GD.finish();
  255. byte tag = GD.rd(REG_TOUCH_TAG);
  256. if ((1 <= tag) && (tag <= 4)) {
  257. play(0x50);
  258. hit |= (1 << (tag - 1));
  259. }
  260. if (tag == 77)
  261. return 0;
  262. GD.ClearTag(77);
  263. GD.Clear();
  264. GD.PointSize(20 * 16);
  265. GD.Begin(POINTS);
  266. for (byte i = 1; i <= 4; i++) {
  267. if (hit & (1 << (i - 1))) {
  268. GD.ColorRGB(0x00ff00);
  269. GD.Tag(0xff);
  270. } else {
  271. GD.ColorRGB(0x808080);
  272. GD.Tag(i);
  273. }
  274. switch (i) {
  275. case 1: GD.Vertex2ii(20, 20, 0, 0); break;
  276. case 2: GD.Vertex2ii(460, 20, 0, 0); break;
  277. case 3: GD.Vertex2ii(20, 250, 0, 0); break;
  278. case 4: GD.Vertex2ii(460, 250, 0, 0); break;
  279. }
  280. }
  281. GD.random(); // scramble PRN state for later
  282. GD.swap();
  283. }
  284. return 1;
  285. }
  286. static const PROGMEM uint32_t digits[11] = {
  287. DIGIT_0,
  288. DIGIT_1,
  289. DIGIT_2,
  290. DIGIT_3,
  291. DIGIT_4,
  292. DIGIT_5,
  293. DIGIT_6,
  294. DIGIT_7,
  295. DIGIT_8,
  296. DIGIT_9,
  297. DIGIT_9 + DIGIT_9_LENGTH
  298. };
  299. static void saydigit(byte n)
  300. {
  301. GD.wr32(REG_PLAYBACK_FREQ, 8000);
  302. GD.wr32(REG_PLAYBACK_FORMAT, ADPCM_SAMPLES);
  303. uint32_t dstart = pgm_read_dword(digits + n);
  304. uint32_t dend = pgm_read_dword(digits + n + 1);
  305. GD.wr32(REG_PLAYBACK_START, dstart);
  306. GD.wr32(REG_PLAYBACK_LENGTH, dend - dstart);
  307. GD.wr(REG_PLAYBACK_PLAY, 1);
  308. }
  309. static void blank(int n)
  310. {
  311. for (int i = 0; i < n; i++) {
  312. GD.get_inputs();
  313. GD.cmd_gradient(0, 0, 0xb0b0a0, 0, 272, 0x404040);
  314. GD.swap();
  315. }
  316. }
  317. static byte getkey()
  318. {
  319. byte prev_tag;
  320. do {
  321. prev_tag = GD.inputs.tag;
  322. GD.get_inputs();
  323. if (GD.inputs.x & 1)
  324. GD.random();
  325. GD.cmd_gradient(0, 0, 0xb0b0a0, 0, 272, 0x404040);
  326. for (int i = 0; i < 9; i++) {
  327. byte digit = i + 1;
  328. int x = 120 + 80 * (i % 3);
  329. int y = 20 + 80 * (i / 3);
  330. GD.Tag(digit);
  331. char msg[2] = { '0' + digit, 0 };
  332. GD.cmd_fgcolor((digit == GD.inputs.tag) ? 0xc08000 : 0x003870);
  333. GD.cmd_button(x, y, 70, 70, 31, 0, msg);
  334. }
  335. GD.swap();
  336. } while (!((GD.inputs.tag == 0) && (1 <= prev_tag) && (prev_tag <= 9)));
  337. return prev_tag;
  338. }
  339. static byte test_audio(void)
  340. {
  341. // Stir up the PRN
  342. for (int i = micros() % 97; i; i--)
  343. GD.random();
  344. blank(20);
  345. for (int i = 0; i < 3; i++) {
  346. byte d = 1 + GD.random(9);
  347. saydigit(d);
  348. blank(12);
  349. if (getkey() != d)
  350. return 0;
  351. }
  352. return 1;
  353. }
  354. static struct {
  355. byte t, note;
  356. } pacman[] = {
  357. { 0, 71 },
  358. { 2, 83 },
  359. { 4, 78 },
  360. { 6, 75 },
  361. { 8, 83 },
  362. { 9, 78 },
  363. { 12, 75 },
  364. { 16, 72 },
  365. { 18, 84 },
  366. { 20, 79 },
  367. { 22, 76 },
  368. { 24, 84 },
  369. { 25, 79 },
  370. { 28, 76 },
  371. { 32, 71 },
  372. { 34, 83 },
  373. { 36, 78 },
  374. { 38, 75 },
  375. { 40, 83 },
  376. { 41, 78 },
  377. { 44, 75 },
  378. { 48, 75 },
  379. { 49, 76 },
  380. { 50, 77 },
  381. { 52, 77 },
  382. { 53, 78 },
  383. { 54, 79 },
  384. { 56, 79 },
  385. { 57, 80 },
  386. { 58, 81 },
  387. { 60, 83 },
  388. { 255, 255 }
  389. };
  390. static const uint8_t GD3_43__init[128] = {
  391. 255, 255, 1, 1, 26, 255, 255, 255, 12, 32, 48, 0, 4, 0, 0, 0, 0, 135,
  392. 147, 3, 26, 255, 255, 255, 80, 33, 48, 0, 24, 0, 0, 0, 46, 46, 46, 46,
  393. 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
  394. 46, 46, 46, 34, 255, 255, 255, 88, 32, 48, 0, 120, 156, 99, 100, 96,
  395. 96, 216, 198, 200, 192, 0, 68, 12, 204, 12, 16, 26, 132, 217, 128, 24,
  396. 0, 17, 207, 0, 197, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255,
  397. 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0,
  398. 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255
  399. };
  400. static const uint8_t GD3_7__init[128] = {
  401. 255, 255, 1, 1, 26, 255, 255, 255, 12, 32, 48, 0, 4, 0, 0, 0, 0, 39,
  402. 134, 3, 26, 255, 255, 255, 80, 33, 48, 0, 24, 0, 0, 0, 46, 46, 46, 46,
  403. 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
  404. 46, 46, 46, 34, 255, 255, 255, 44, 32, 48, 0, 120, 156, 59, 201, 204,
  405. 192, 16, 193, 192, 192, 160, 0, 164, 65, 192, 0, 136, 89, 152, 128,
  406. 124, 32, 253, 128, 17, 34, 6, 149, 98, 0, 113, 183, 49, 66, 104, 100,
  407. 49, 160, 114, 6, 0, 164, 38, 3, 65, 0, 0, 0, 0, 255, 255, 255, 0, 255,
  408. 255, 255, 0, 255, 255, 255, 0, 255, 255, 255
  409. };
  410. static const uint8_t GD3_VGA__init[128] = {
  411. 255, 255, 1, 2, 26, 255, 255, 255, 12, 32, 48, 0, 4, 0, 0, 0, 64, 210,
  412. 223, 3, 26, 255, 255, 255, 148, 32, 48, 0, 4, 0, 0, 0, 16, 0, 0, 0,
  413. 34, 255, 255, 255, 44, 32, 48, 0, 120, 156, 115, 96, 101, 96, 208, 96,
  414. 100, 96, 96, 96, 97, 0, 131, 14, 32, 86, 99, 102, 96, 80, 6, 113, 152,
  415. 33, 98, 108, 12, 248, 1, 72, 59, 0, 77, 136, 1, 81, 0, 0, 0, 255, 255,
  416. 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255,
  417. 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0,
  418. 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255
  419. };
  420. #define FREQUENCY_OFFSET 16
  421. #define CALIBRATION_OFFSET 32
  422. uint8_t gpio, gpio_dir;
  423. void set_SDA(byte n)
  424. {
  425. GD.wr(REG_GPIO_DIR, gpio_dir | (0x03 - n)); // Drive SCL, SDA low
  426. }
  427. void set_SCL(byte n)
  428. {
  429. GD.wr(REG_GPIO, gpio | (n << 1));
  430. }
  431. int get_SDA(void)
  432. {
  433. return GD.rd(REG_GPIO) & 1;
  434. }
  435. void i2c_start(void)
  436. {
  437. set_SDA(1);
  438. set_SCL(1);
  439. set_SDA(0);
  440. set_SCL(0);
  441. }
  442. void i2c_stop(void)
  443. {
  444. set_SDA(0);
  445. set_SCL(1);
  446. set_SDA(1);
  447. set_SCL(1);
  448. }
  449. int i2c_rx1()
  450. {
  451. set_SDA(1);
  452. set_SCL(1);
  453. byte r = get_SDA();
  454. set_SCL(0);
  455. return r;
  456. }
  457. void i2c_tx1(byte b)
  458. {
  459. set_SDA(b);
  460. set_SCL(1);
  461. set_SCL(0);
  462. }
  463. int i2c_tx(byte x)
  464. {
  465. for (int i = 7; i >= 0; i--)
  466. i2c_tx1(1 & (x >> i));
  467. return i2c_rx1();
  468. }
  469. int i2c_rx(int nak)
  470. {
  471. byte r = 0;
  472. for (byte i = 0; i < 8; i++)
  473. r = (r << 1) | i2c_rx1();
  474. i2c_tx1(nak);
  475. return r;
  476. }
  477. void i2c_begin(void)
  478. {
  479. gpio = GD.rd(REG_GPIO) & ~3;
  480. gpio_dir = GD.rd(REG_GPIO_DIR) & ~3;
  481. // 2-wire software reset
  482. i2c_start();
  483. i2c_rx(1);
  484. i2c_start();
  485. i2c_stop();
  486. }
  487. #define ADDR 0xa0
  488. void ram_write(const uint8_t *v)
  489. {
  490. for (byte i = 0; i < 128; i += 8) {
  491. i2c_start();
  492. i2c_tx(ADDR);
  493. i2c_tx(i);
  494. for (byte j = 0; j < 8; j++)
  495. i2c_tx(*v++);
  496. i2c_stop();
  497. delay(6);
  498. }
  499. }
  500. byte ram_read(byte a)
  501. {
  502. i2c_start();
  503. i2c_tx(ADDR);
  504. i2c_tx(a);
  505. i2c_start();
  506. i2c_tx(ADDR | 1);
  507. byte r = i2c_rx(1);
  508. i2c_stop();
  509. return r;
  510. }
  511. void ramdump(void)
  512. {
  513. for (int i = 0; i < 128; i++) {
  514. byte v = ram_read(i);
  515. Serial.print(i, HEX);
  516. Serial.print(" ");
  517. Serial.println(v, HEX);
  518. }
  519. }
  520. void ram_get(byte *v)
  521. {
  522. i2c_start();
  523. i2c_tx(ADDR);
  524. i2c_tx(0);
  525. i2c_start();
  526. i2c_tx(ADDR | 1);
  527. for (int i = 0; i < 128; i++) {
  528. *v++ = i2c_rx(i == 127);
  529. // Serial.println(v[-1], DEC);
  530. }
  531. i2c_stop();
  532. }
  533. static void load_flash(uint8_t *config)
  534. {
  535. byte b[128];
  536. i2c_begin();
  537. ram_write(config);
  538. ram_get(b);
  539. int diff = memcmp(config, b, 128);
  540. if (diff != 0) {
  541. Serial.println("Flash fault");
  542. GD.Clear();
  543. GD.cmd_text(GD.w / 2, GD.h / 2, 30, OPT_CENTERX, "Flash fault");
  544. GD.swap();
  545. for (;;);
  546. }
  547. Serial.println("Flash verified OK");
  548. GD.begin(0);
  549. }
  550. static void setup_flash()
  551. {
  552. GD.begin(0);
  553. if (GD3) {
  554. uint8_t stage[128];
  555. memcpy(stage, GD3_43__init, 128);
  556. load_flash(stage);
  557. GD.self_calibrate();
  558. GD.finish();
  559. for (int i = 0; i < 24; i++)
  560. stage[CALIBRATION_OFFSET + i] = GD.rd(REG_TOUCH_TRANSFORM_A + i);
  561. load_flash(stage);
  562. }
  563. }
  564. void loop()
  565. {
  566. if (EEPROM.read(0) == 0x7c)
  567. EEPROM.write(0, 0xff);
  568. setup_flash();
  569. GD.begin(0);
  570. x = y = 0;
  571. testcard(1, "Starting tests");
  572. GD.finish();
  573. Serial.println("Starting self-test");
  574. byte r, pass = 1;
  575. {
  576. SCREENTEST(ident);
  577. if (!GD3)
  578. SCREENTEST(tune);
  579. SCREENTEST(clock);
  580. SCREENTEST(RAM);
  581. SCREENTEST(PWM);
  582. SCREENTEST(storage);
  583. SCREENTEST(SDcard);
  584. if (0)
  585. SCREENTEST(accel);
  586. if (1) {
  587. SCREENTEST(touch);
  588. SCREENTEST(audio);
  589. }
  590. {
  591. int i = 0, t = 0;
  592. for (;;) {
  593. testcard(1, "* ALL PASS *");
  594. if (t == 4 * pacman[i].t)
  595. GD.play(HARP, pacman[i++].note - 12);
  596. if (++t == 256) {
  597. t = 0;
  598. i = 0;
  599. }
  600. }
  601. }
  602. }
  603. if (pass) {
  604. char msg[60];
  605. log("All tests passed\n");
  606. long seconds = millis() / 1000;
  607. int minutes = seconds / 60;
  608. sprintf(msg, "%d minutes", minutes);
  609. log(msg);
  610. } else {
  611. for (;;)
  612. ;
  613. }
  614. delay(5000);
  615. }