| 652 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2011 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emCORE.
|
|
|
7 |
//
|
|
|
8 |
// emCORE is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emCORE 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.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
| 558 |
theseven |
24 |
#include "emcoreapp.h"
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
struct wakeup eventwakeup;
|
|
|
28 |
int pos = 64;
|
| 559 |
theseven |
29 |
bool toggle[65];
|
| 558 |
theseven |
30 |
|
|
|
31 |
void handler(void* user, enum button_event eventtype, int which, int value)
|
|
|
32 |
{
|
|
|
33 |
bool action = false;
|
|
|
34 |
switch (eventtype)
|
|
|
35 |
{
|
|
|
36 |
case BUTTON_PRESS:
|
|
|
37 |
switch (which)
|
|
|
38 |
{
|
|
|
39 |
case 0:
|
| 559 |
theseven |
40 |
toggle[pos] = true;
|
| 558 |
theseven |
41 |
action = true;
|
|
|
42 |
break;
|
|
|
43 |
case 1:
|
|
|
44 |
pos++;
|
|
|
45 |
action = true;
|
|
|
46 |
break;
|
|
|
47 |
case 2:
|
|
|
48 |
pos--;
|
|
|
49 |
action = true;
|
|
|
50 |
break;
|
|
|
51 |
}
|
|
|
52 |
break;
|
|
|
53 |
case WHEEL_FORWARD:
|
|
|
54 |
pos++;
|
|
|
55 |
action = true;
|
|
|
56 |
break;
|
|
|
57 |
case WHEEL_BACKWARD:
|
|
|
58 |
pos--;
|
|
|
59 |
action = true;
|
|
|
60 |
break;
|
|
|
61 |
}
|
|
|
62 |
while (pos < 0) pos += 65;
|
|
|
63 |
while (pos > 65) pos -= 65;
|
|
|
64 |
if (action) wakeup_signal(&eventwakeup);
|
|
|
65 |
}
|
|
|
66 |
|
| 559 |
theseven |
67 |
static void renderline(void* framebuf, int width, int fontwidth,
|
|
|
68 |
int fontheight, int* state, int line)
|
| 558 |
theseven |
69 |
{
|
|
|
70 |
int i;
|
|
|
71 |
for (i = 0; i < 16; i++)
|
|
|
72 |
renderchar(framebuf, 2 + fontwidth * (i + i / 4), 2 + fontheight * (2 + line), width,
|
|
|
73 |
pos == i + line * 16 ? 0xffffffff : 0xff000000,
|
|
|
74 |
pos == i + line * 16 ? 0xff000000 : 0xffffffff,
|
|
|
75 |
*("01X" + state[i + line * 16]));
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
static void main()
|
|
|
79 |
{
|
|
|
80 |
int i, j;
|
|
|
81 |
char buf[9];
|
| 559 |
theseven |
82 |
int state[64];
|
|
|
83 |
for (i = 0; i < 65; i++) toggle[i] = false;
|
| 558 |
theseven |
84 |
for (i = 0; i < 64; i++) state[i] = clockgate_get_state(i);
|
|
|
85 |
uint32_t orig[2] = {0xffffffff, 0xffffffff};
|
|
|
86 |
uint32_t now[2];
|
|
|
87 |
for (i = 0; i < 2; i++)
|
|
|
88 |
for (j = 0; j < 32; j++)
|
|
|
89 |
if (state[i * 32 + j])
|
|
|
90 |
orig[i] &= ~(1 << j);
|
|
|
91 |
cprintf(3, "Initial state: %08X %08X\n", orig[0], orig[1]);
|
|
|
92 |
int fontwidth = get_font_width();
|
|
|
93 |
int fontheight = get_font_height();
|
|
|
94 |
int width = 19 * fontwidth + 4;
|
|
|
95 |
int height = 6 * fontheight + 4;
|
|
|
96 |
int xoffs = (lcd_get_width() - width) / 2;
|
|
|
97 |
int yoffs = (lcd_get_height() - height) / 2;
|
|
|
98 |
int framebufsize = width * height * 3;
|
|
|
99 |
void* framebuf = malloc(framebufsize);
|
|
|
100 |
if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
|
|
|
101 |
memset(framebuf, 0xff, framebufsize);
|
|
|
102 |
memset(framebuf, 0, width * 3);
|
|
|
103 |
memset(framebuf + (height - 1) * width * 3, 0, width * 3);
|
|
|
104 |
for (i = 0; i < height; i++)
|
|
|
105 |
{
|
|
|
106 |
char* ptr = (char*)framebuf + (i * width - 1) * 3;
|
|
|
107 |
for (j = 0; j < 6; j++) *ptr++ = 0;
|
|
|
108 |
}
|
|
|
109 |
wakeup_init(&eventwakeup);
|
|
|
110 |
wakeup_signal(&eventwakeup);
|
|
|
111 |
struct button_hook_entry* hook = button_register_handler(handler, NULL);
|
|
|
112 |
if (!hook) panicf(PANIC_KILLTHREAD, "Could not register button hook!");
|
| 559 |
theseven |
113 |
while (!toggle[64])
|
| 558 |
theseven |
114 |
{
|
| 559 |
theseven |
115 |
wakeup_wait(&eventwakeup, 500000);
|
| 558 |
theseven |
116 |
now[0] = 0xffffffff;
|
|
|
117 |
now[1] = 0xffffffff;
|
|
|
118 |
for (i = 0; i < 2; i++)
|
|
|
119 |
for (j = 0; j < 32; j++)
|
|
|
120 |
{
|
|
|
121 |
state[i * 32 + j] = clockgate_get_state(i * 32 + j);
|
| 559 |
theseven |
122 |
if (toggle[i * 32 + j])
|
|
|
123 |
{
|
|
|
124 |
toggle[i * 32 + j] = false;
|
|
|
125 |
bool newstate = !state[i * 32 + j];
|
|
|
126 |
clockgate_enable(i * 32 + j, newstate);
|
|
|
127 |
state[i * 32 + j] = clockgate_get_state(i * 32 + j);
|
|
|
128 |
if (state[i * 32 + j] != newstate) state[i * 32 + j] = 2;
|
|
|
129 |
}
|
| 558 |
theseven |
130 |
if (state[i * 32 + j]) now[i] &= ~(1 << j);
|
|
|
131 |
}
|
| 559 |
theseven |
132 |
for (i = 0; i < 4; i++) renderline(framebuf, width, fontwidth, fontheight, state, i);
|
| 558 |
theseven |
133 |
renderchar(framebuf, 2 + fontwidth * 18, 2, width, pos == 64 ? 0xffffffff : 0xff000000,
|
|
|
134 |
pos == 64 ? 0xff000000 : 0xffffffff, 'X');
|
|
|
135 |
snprintf(buf, sizeof(buf), "%08X", orig[0]);
|
|
|
136 |
rendertext(framebuf, 2, 2, width, 0xff000000, 0xffffffff, buf);
|
|
|
137 |
snprintf(buf, sizeof(buf), "%08X", orig[1]);
|
|
|
138 |
rendertext(framebuf, 2 + 9 * fontwidth, 2, width, 0xff000000, 0xffffffff, buf);
|
|
|
139 |
snprintf(buf, sizeof(buf), "%08X", now[0]);
|
|
|
140 |
rendertext(framebuf, 2, 2 + fontheight, width, 0xff000000, 0xffffffff, buf);
|
|
|
141 |
snprintf(buf, sizeof(buf), "%08X", now[1]);
|
|
|
142 |
rendertext(framebuf, 2 + 9 * fontwidth, 2 + fontheight, width,
|
|
|
143 |
0xff000000, 0xffffffff, buf);
|
|
|
144 |
displaylcd(xoffs, yoffs, width, height, framebuf, 0, 0, width);
|
|
|
145 |
}
|
|
|
146 |
button_unregister_handler(hook);
|
|
|
147 |
cprintf(3, "Final state: %08X %08X\n", now[0], now[1]);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
EMCORE_APP_HEADER("Clock gate hunter", main, 127)
|