Skip to content

Commit

Permalink
merge from spacewrench
Browse files Browse the repository at this point in the history
  • Loading branch information
WardCunningham committed Nov 26, 2011
2 parents 8b837b3 + b01b8f4 commit e97de21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions txtzyme.c
Expand Up @@ -32,14 +32,15 @@
#define LED_OFF (PORTD &= ~(1<<6)) #define LED_OFF (PORTD &= ~(1<<6))
#define LED_ON (PORTD |= (1<<6)) #define LED_ON (PORTD |= (1<<6))
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define BIGBUF 1024


void send_str(const char *s); void send_str(const char *s);
uint8_t recv_str(char *buf, uint8_t size); uint16_t recv_str(char *buf, uint16_t size);
void parse(const char *buf); void parse(const char *buf);


// Basic command interpreter for controlling port pins // Basic command interpreter for controlling port pins
int main(void) { int main(void) {
char buf[64]; char buf[BIGBUF];
uint8_t n; uint8_t n;


// set for 16 MHz clock, and turn on the LED // set for 16 MHz clock, and turn on the LED
Expand Down Expand Up @@ -74,7 +75,7 @@ int main(void) {
while (1) { while (1) {
// send_str(PSTR("> ")); // send_str(PSTR("> "));
n = recv_str(buf, sizeof(buf)); n = recv_str(buf, sizeof(buf));
if (n == 255) break; if (n == (uint16_t)(~0)) break;
// send_str(PSTR("\r\n")); // send_str(PSTR("\r\n"));
parse(buf); parse(buf);
} }
Expand Down Expand Up @@ -107,9 +108,9 @@ void send_num(const uint16_t num) {
// The return value is the number of characters received, or 255 if // The return value is the number of characters received, or 255 if
// the virtual serial connection was closed while waiting. // the virtual serial connection was closed while waiting.
// //
uint8_t recv_str(char *buf, uint8_t size) { uint16_t recv_str(char *buf, uint16_t size) {
int16_t r; int16_t r;
uint8_t count=0; uint16_t count=0;


while (count < (size-1)) { while (count < (size-1)) {
r = usb_serial_getchar(); r = usb_serial_getchar();
Expand All @@ -125,7 +126,7 @@ uint8_t recv_str(char *buf, uint8_t size) {
!(usb_serial_get_control() & USB_SERIAL_DTR)) { !(usb_serial_get_control() & USB_SERIAL_DTR)) {
// user no longer connected // user no longer connected
*buf = 0; *buf = 0;
return 255; return ~0;
} }
// just a normal timeout, keep waiting // just a normal timeout, keep waiting
} }
Expand All @@ -145,7 +146,7 @@ uint16_t x = 0;
void parse(const char *buf) { void parse(const char *buf) {
uint16_t count = 0; uint16_t count = 0;
last = TCNT1; last = TCNT1;
char *loop; const char *loop = 0;
char ch; char ch;
while ((ch = *buf++)) { while ((ch = *buf++)) {
switch (ch) { switch (ch) {
Expand Down Expand Up @@ -232,7 +233,7 @@ void parse(const char *buf) {
send_str(PSTR("\r\n")); send_str(PSTR("\r\n"));
break; break;
case 'h': case 'h':
send_str(PSTR("0-9<num>\tenter number\r\n<num>p\t\tprint number\r\n<num>a-f<pin>\tselect pin\r\n<pin>i<num>\tinput\r\n<pin><num>o\toutput\r\n<num>m\t\tmsec delay\r\n<num>u\t\tusec delay\r\n<num>U\t\tusec wait\r\n<num>{}\t\trepeat\r\nk<num>\t\tloop count\r\n_<words>_\tprint words\r\n<num>s<num>\tanalog sample\r\nv\t\tprint version\r\nh\t\tprint help\r\n<pin>t<num>\tpulse width\r\n")); send_str(PSTR("Txtzyme [+bigbuf]\r\n0-9<num>\tenter number\r\n<num>p\t\tprint number\r\n<num>a-f<pin>\tselect pin\r\n<pin>i<num>\tinput\r\n<pin><num>o\toutput\r\n<num>m\t\tmsec delay\r\n<num>u\t\tusec delay\r\n<num>{}\t\trepeat\r\nk<num>\t\tloop count\r\n_<words>_\tprint words\r\n<num>s<num>\tanalog sample\r\nv\t\tprint version\r\nh\t\tprint help\r\n<pin>t<num>\tpulse width\r\n"));
break; break;
case 't': case 't':
*(uint8_t *)(0x21 + port * 3) &= ~(1 << pin); // direction = input *(uint8_t *)(0x21 + port * 3) &= ~(1 << pin); // direction = input
Expand Down
4 changes: 2 additions & 2 deletions usb_serial.c
Expand Up @@ -40,8 +40,8 @@


// You can change these to give your code its own name. On Windows, // You can change these to give your code its own name. On Windows,
// these are only used before an INF file (driver install) is loaded. // these are only used before an INF file (driver install) is loaded.
#define STR_MANUFACTURER L"Your Name" #define STR_MANUFACTURER L"Ward Cunningham"
#define STR_PRODUCT L"USB Serial" #define STR_PRODUCT L"Txtzyme Interpreter"


// All USB serial devices are supposed to have a serial number // All USB serial devices are supposed to have a serial number
// (according to Microsoft). On windows, a new COM port is created // (according to Microsoft). On windows, a new COM port is created
Expand Down

0 comments on commit e97de21

Please sign in to comment.