2 * spiconsole - A simple interface to usbtinyisp to act as a 'console'
4 * Copyright (C) 2008 Matt Anderson, adapted from usbtiny.c from avrdude
6 * avrdude - A Downloader/Uploader for AVR device programmers
7 * Copyright (C) 2007 Dick Streefland, adapted for 5.4 by Limor Fried
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "usbtiny_def.h"
50 // Do ncurses init stuffs.
56 getmaxyx(stdscr
, row
, col
);
60 disp
= (char**) malloc(sizeof(char*) * row
);
62 for (ix
= 0; ix
< row
; ++ix
)
64 disp
[ix
] = (char*) malloc(sizeof(char) * (col
+1));
72 unsigned char input
[4] = { 0, 0, 0, 0 };
73 unsigned char output
[4];
77 while ((c
= getch()) && ix
< 4)
86 // Exchange 4 bytes with usbtiny.
87 usbtiny_spi(input
, output
);
89 // If we received bytes in return, write them out.
90 for (ix
= 0; ix
< 4; ++ix
)
92 if (output
[ix
] && isascii(output
[ix
])) {
93 if (output
[ix
] == '\n') posx
=col
;
95 sprintf(&disp
[row
-1][posx
++], "%c", output
[ix
]);
99 sprintf(&disp
[row
-1][posx
++], ".");
106 for(iy
= 0; iy
< row
- 1; ++iy
)
107 strcpy(disp
[iy
], disp
[iy
+1]);
109 disp
[row
-1][0] = '\0';
114 for (ix
= 0; ix
< row
; ++ix
)
115 mvprintw(ix
, 0, disp
[ix
]);
129 void do_printf_ui(void) {
132 uint8_t input
[4] = { 0, 0, 0, 0 };
139 while((c
= getchar()) && i
< 4)
149 usbtiny_spi(input
,output
);
151 for(uint8_t i
= 0; i
< sizeof(input
); i
++ ) {
152 if (output
[i
] && isascii(output
[i
]))
161 int main(int argc
, char **argv
)
163 // XXX: bitclock always default for now.
164 // any faster than this with 1Mhz avr clock and bit errors are too likely.
165 double bitclock
= 0.0002200;
169 /* Find and open usbtiny. */
172 // Check for bit-clock and tell the usbtiny to adjust itself
173 usbtiny_set_sck_period(bitclock
);
176 // Let the device wake up.
182 usb_control(USBTINY_POWERDOWN
, 0, 0); // Send USB control command to device