ao-tools: Make library support µPusb
authorKeith Packard <keithp@keithp.com>
Thu, 21 Mar 2013 06:22:37 +0000 (23:22 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 21 Mar 2013 06:22:37 +0000 (23:22 -0700)
Set baud rate to 9600, look for FTDI-style names

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/lib/cc-usb.c
ao-tools/lib/cc-usb.h
ao-tools/lib/cc-usbdev.c

index 9f07e6624d2c849f7469c07cbc80dc018648f383..f82752435d03c48126253541e8b5af8d5a653b63 100644 (file)
@@ -254,10 +254,10 @@ cc_usb_printf(struct cc_usb *cc, char *format, ...)
 }
 
 int
-cc_usb_getchar(struct cc_usb *cc)
+cc_usb_getchar_timeout(struct cc_usb *cc, int timeout)
 {
        while (cc->in_pos == cc->in_count) {
-               if (_cc_usb_sync(cc, 5000) < 0) {
+               if (_cc_usb_sync(cc, timeout) < 0) {
                        fprintf(stderr, "USB link timeout\n");
                        exit(1);
                }
@@ -265,6 +265,12 @@ cc_usb_getchar(struct cc_usb *cc)
        return cc->in_buf[cc->in_pos++];
 }
 
+int
+cc_usb_getchar(struct cc_usb *cc)
+{
+       return cc_usb_getchar_timeout(cc, 5000);
+}
+
 void
 cc_usb_getline(struct cc_usb *cc, char *line, int max)
 {
@@ -420,6 +426,8 @@ cc_usb_open(char *tty)
        tcgetattr(cc->fd, &termios);
        save_termios = termios;
        cfmakeraw(&termios);
+       cfsetospeed(&termios, B9600);
+       cfsetispeed(&termios, B9600);
        tcsetattr(cc->fd, TCSAFLUSH, &termios);
        cc_usb_printf(cc, "\nE 0\nm 0\n");
        do {
index e90e1195b100f34a5858bb8b6e2500609e66fe95..f11934560a917119a2b6a0d2377e23a412bf1cc5 100644 (file)
@@ -53,6 +53,9 @@ cc_usb_sync(struct cc_usb *cc);
 void
 cc_queue_read(struct cc_usb *cc, uint8_t *buf, int len);
 
+int
+cc_usb_getchar_timeout(struct cc_usb *cc, int timeout);
+
 int
 cc_usb_getchar(struct cc_usb *cc);
 
index a19e231c9fe724cd4b473d6f7ca3c6037acdd850..95bfa244b6a5f9dfe0fa567b992d02221e47f149 100644 (file)
@@ -132,11 +132,23 @@ usb_tty(char *sys)
                        /* Check for tty/ttyACMx style names
                         */
                        tty_dir = cc_fullname(endpoint_full, "tty");
-                       free(endpoint_full);
                        ntty = scandir(tty_dir, &namelist,
                                       dir_filter_tty,
                                       alphasort);
                        free (tty_dir);
+                       if (ntty > 0) {
+                               tty = cc_fullname("/dev", namelist[0]->d_name);
+                               free(endpoint_full);
+                               free(namelist);
+                               return tty;
+                       }
+
+                       /* Check for ttyACMx style names
+                        */
+                       ntty = scandir(endpoint_full, &namelist,
+                                      dir_filter_tty,
+                                      alphasort);
+                       free(endpoint_full);
                        if (ntty > 0) {
                                tty = cc_fullname("/dev", namelist[0]->d_name);
                                free(namelist);
@@ -197,6 +209,15 @@ dir_filter_dev(const struct dirent *d)
        return 1;
 }
 
+static int
+is_am(int idVendor, int idProduct) {
+       if (idVendor == 0xfffe)
+               return 1;
+       if (idVendor == 0x0403 && idProduct == 0x6015)
+               return 1;
+       return 0;
+}
+
 struct cc_usbdevs *
 cc_usbdevs_scan(void)
 {
@@ -220,7 +241,7 @@ cc_usbdevs_scan(void)
                dir = cc_fullname(USB_DEVICES, ents[e]->d_name);
                dev = usb_scan_device(dir);
                free(dir);
-               if (dev->idVendor == 0xfffe && dev->tty) {
+               if (is_am(dev->idVendor, dev->idProduct) && dev->tty) {
                        if (devs->dev)
                                devs->dev = realloc(devs->dev,
                                                    (devs->ndev + 1) * sizeof (struct usbdev *));