Index: apps/clockgatehunter/main.c |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 |
|
5 | 5 | struct wakeup eventwakeup;
|
6 | 6 | int pos = 64;
|
7 | | -int state[65];
|
| 7 | +bool toggle[65];
|
8 | 8 |
|
9 | 9 | void handler(void* user, enum button_event eventtype, int which, int value)
|
10 | 10 | {
|
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | switch (which)
|
16 | 16 | {
|
17 | 17 | case 0:
|
18 | | - state[pos] = !state[pos];
|
| 18 | + toggle[pos] = true;
|
19 | 19 | action = true;
|
20 | 20 | break;
|
21 | 21 | case 1:
|
— | — | @@ -41,7 +41,8 @@ |
42 | 42 | if (action) wakeup_signal(&eventwakeup);
|
43 | 43 | }
|
44 | 44 |
|
45 | | -static void renderline(void* framebuf, int width, int fontwidth, int fontheight, int line)
|
| 45 | +static void renderline(void* framebuf, int width, int fontwidth,
|
| 46 | + int fontheight, int* state, int line)
|
46 | 47 | {
|
47 | 48 | int i;
|
48 | 49 | for (i = 0; i < 16; i++)
|
— | — | @@ -55,8 +56,9 @@ |
56 | 57 | {
|
57 | 58 | int i, j;
|
58 | 59 | char buf[9];
|
| 60 | + int state[64];
|
| 61 | + for (i = 0; i < 65; i++) toggle[i] = false;
|
59 | 62 | for (i = 0; i < 64; i++) state[i] = clockgate_get_state(i);
|
60 | | - state[i] = false;
|
61 | 63 | uint32_t orig[2] = {0xffffffff, 0xffffffff};
|
62 | 64 | uint32_t now[2];
|
63 | 65 | for (i = 0; i < 2; i++)
|
— | — | @@ -85,21 +87,26 @@ |
86 | 88 | wakeup_signal(&eventwakeup);
|
87 | 89 | struct button_hook_entry* hook = button_register_handler(handler, NULL);
|
88 | 90 | if (!hook) panicf(PANIC_KILLTHREAD, "Could not register button hook!");
|
89 | | - while (true)
|
| 91 | + while (!toggle[64])
|
90 | 92 | {
|
91 | | - wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
|
| 93 | + wakeup_wait(&eventwakeup, 500000);
|
92 | 94 | now[0] = 0xffffffff;
|
93 | 95 | now[1] = 0xffffffff;
|
94 | 96 | for (i = 0; i < 2; i++)
|
95 | 97 | for (j = 0; j < 32; j++)
|
96 | 98 | {
|
97 | | - bool oldstate = state[i * 32 + j];
|
98 | | - clockgate_enable(i * 32 + j, oldstate);
|
99 | 99 | state[i * 32 + j] = clockgate_get_state(i * 32 + j);
|
100 | | - if (state[i * 32 + j] != oldstate) state[i * 32 + j] = 2;
|
| 100 | + if (toggle[i * 32 + j])
|
| 101 | + {
|
| 102 | + toggle[i * 32 + j] = false;
|
| 103 | + bool newstate = !state[i * 32 + j];
|
| 104 | + clockgate_enable(i * 32 + j, newstate);
|
| 105 | + state[i * 32 + j] = clockgate_get_state(i * 32 + j);
|
| 106 | + if (state[i * 32 + j] != newstate) state[i * 32 + j] = 2;
|
| 107 | + }
|
101 | 108 | if (state[i * 32 + j]) now[i] &= ~(1 << j);
|
102 | 109 | }
|
103 | | - for (i = 0; i < 4; i++) renderline(framebuf, width, fontwidth, fontheight, i);
|
| 110 | + for (i = 0; i < 4; i++) renderline(framebuf, width, fontwidth, fontheight, state, i);
|
104 | 111 | renderchar(framebuf, 2 + fontwidth * 18, 2, width, pos == 64 ? 0xffffffff : 0xff000000,
|
105 | 112 | pos == 64 ? 0xff000000 : 0xffffffff, 'X');
|
106 | 113 | snprintf(buf, sizeof(buf), "%08X", orig[0]);
|
— | — | @@ -112,7 +119,6 @@ |
113 | 120 | rendertext(framebuf, 2 + 9 * fontwidth, 2 + fontheight, width,
|
114 | 121 | 0xff000000, 0xffffffff, buf);
|
115 | 122 | displaylcd(xoffs, yoffs, width, height, framebuf, 0, 0, width);
|
116 | | - if (state[64]) break;
|
117 | 123 | }
|
118 | 124 | button_unregister_handler(hook);
|
119 | 125 | cprintf(3, "Final state: %08X %08X\n", now[0], now[1]);
|