5 #include <avr/interrupt.h>
6 #include <util/delay.h>
11 * IR decoding, connected to PCINT0
12 * enable/disable with switch on PCINT1
13 * some of the buttons multiplexed on ADC0
17 uint16_t evq[EVQ_SIZE];
18 volatile int evq_wr, evq_rd;
20 #define LOGNUM(x) EVLOG(EV_DEBUG, (x))
22 #define EVLOG(ev, data) \
24 if(ev != EV_DEBUG || dbgmode) { \
25 evq[evq_wr] = ((uint16_t)(ev) << 8) | (data); \
26 evq_wr = (evq_wr + 1) & (EVQ_SIZE - 1); \
27 if(evq_wr == evq_rd) { \
28 evq_rd = (evq_rd + 1) & (EVQ_SIZE - 1); \
33 /* serial input buffer */
34 static char input[64];
35 static unsigned char inp_cidx;
37 static unsigned char data[16];
39 static uint16_t dump_addr;
40 static int dump_count;
43 static void proc_cmd(char *input);
44 static void printstat(void);
45 static void printdump(void);
52 /* tri-state everything and disable pullups */
53 DDRB = 1; /* B0: activity LED */
54 DDRC = 0; /* I2C pins as inputs */
65 printf("TV i2c hack\n");
74 if(c == '\r' || c == '\n') {
79 } else if(inp_cidx < sizeof input - 1) {
80 input[inp_cidx++] = c;
84 /* read from queue and send over the serial port */
87 if(evq_wr != evq_rd) {
89 evq_rd = (evq_rd + 1) & (EVQ_SIZE - 1);
94 unsigned char ev = val >> 8;
95 printf("%02x: %02x\n", ev, val & 0xff);
101 static void proc_cmd(char *input)
105 if(strcmp(input, "dbg") == 0) {
109 } else if(strcmp(input, "nodbg") == 0) {
110 printf("OK nodbg\n");
113 } else if(strcmp(input, "av") == 0) {
116 /* AV switch (22): 0 0 SVO CMB1 CMB0 INA INB 0 */
118 i2c_write(0x8a, 0x22, data, 1);
121 } else if(strcmp(input, "rgb") == 0) {
124 /* Control 0 (2a): 0 IE2 RBL AKB CL3 CL2 CL1 CL0
125 * Control 1 (2b): 0 0 0 0 0 0 YUV HBL
129 i2c_write(0x8a, 0x2a, data, 1);
131 i2c_write(0x8a, 0x2b, data + 1, 1);
133 } else if(memcmp(input, "vol ", 4) == 0) {
134 int vol = atoi(input + 4);
135 if(vol < 1 || vol > 63) {
136 printf("ERR vol (%s)\n", input + 4);
139 i2c_write(0x8a, 0x1f, data, 1);
140 printf("OK volume: %d\n", vol);
143 } else if(memcmp(input, "sat", 3) == 0) {
145 data[0] = atoi(input + 3);
146 if(data[0] <= 0 || data[0] > 0x3f) {
149 i2c_write(0x8a, 0x1c, data, 1);
150 i2c_async(i2c_hold); /* hold I2C when done */
152 } else if(strcmp(input, "rel") == 0) {
153 printf("OK release\n");
156 } else if(strcmp(input, "status") == 0) {
157 i2c_read(0x8a, 0, data, 3);
158 i2c_async(printstat);
160 } else if(memcmp(input, "rd ", 3) == 0) {
161 dump_addr = strtol(input + 3, &endp, 16);
163 if(endp > input + 3 && dump_addr >= 0 && dump_addr < 2048) {
165 i2c_read(0xa0 | ((dump_addr >> 7) & 0xe), dump_addr & 0xff, data, 1);
166 i2c_async(printdump);
168 printf("ERR address: %s\n", input + 3);
171 } else if(memcmp(input, "dump ", 5) == 0) {
172 dump_addr = strtol(input + 5, &endp, 16);
174 if(endp > input + 5 && dump_addr >= 0 && dump_addr < 2048) {
177 i2c_read(0xa0 | ((dump_addr >> 7) & 0xe), dump_addr & 0xff, data, 16);
178 i2c_async(printdump);
180 printf("ERR address: %s\n", input + 5);
183 } else if(strcmp(input, "abort") == 0) {
188 printf("ERR command (%s)\n", input);
192 static void printstat(void)
194 printf("OK status: %02x %02x %02x\n", (unsigned int)data[0],
195 (unsigned int)data[1], (unsigned int)data[2]);
198 static void printdump(void)
201 while(dump_count > 0) {
202 printf("OK %03x:", dump_addr);
203 for(i=0; i<16; i++) {
204 if(i == 8) putchar(' ');
206 if(--dump_count >= 0) {
207 printf(" %02x", data[i]);