Browse Source

lowlevel: Keep track of the claimed devid and debuglog every found device

Luke Dashjr 12 years ago
parent
commit
789c1b7735
6 changed files with 29 additions and 3 deletions
  1. 11 3
      fpgautils.c
  2. 2 0
      fpgautils.h
  3. 1 0
      ft232r.c
  4. 11 0
      lowlevel.c
  5. 1 0
      lowlevel.h
  6. 3 0
      mcp2210.c

+ 11 - 3
fpgautils.c

@@ -830,11 +830,19 @@ struct device_drv *bfg_claim_serial(struct device_drv * const api, const bool ve
 	return bfg_claim_any(api, (verbose ? devpath : NULL), devs);
 }
 
-struct device_drv *bfg_claim_usb(struct device_drv * const api, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr)
+char *bfg_make_devid_usb(const uint8_t usbbus, const uint8_t usbaddr)
 {
-	char devpath[12];
+	char * const devpath = malloc(12);
 	sprintf(devpath, "usb:%03u:%03u", (unsigned)usbbus, (unsigned)usbaddr);
-	return bfg_claim_any(api, verbose ? "" : NULL, devpath);
+	return devpath;
+}
+
+struct device_drv *bfg_claim_usb(struct device_drv * const api, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr)
+{
+	char * const devpath = bfg_make_devid_usb(usbbus, usbaddr);
+	struct device_drv * const rv = bfg_claim_any(api, verbose ? "" : NULL, devpath);
+	free(devpath);
+	return rv;
 }
 
 #ifdef HAVE_LIBUSB

+ 2 - 0
fpgautils.h

@@ -33,7 +33,9 @@ extern struct device_drv *bfg_claim_any2(struct device_drv *, const char *verbos
 extern struct device_drv *bfg_claim_serial(struct device_drv * const, const bool verbose, const char * const devpath);
 #define serial_claim(devpath, drv)    bfg_claim_serial(drv, false, devpath)
 #define serial_claim_v(devpath, drv)  bfg_claim_serial(drv, true , devpath)
+extern char *bfg_make_devid_usb(uint8_t usbbus, uint8_t usbaddr);
 extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr);
+#define bfg_make_devid_libusb(dev)  bfg_make_devid_usb(libusb_get_bus_number(dev), libusb_get_device_address(dev))
 #define bfg_claim_libusb(api, verbose, dev)  bfg_claim_usb(api, verbose, libusb_get_bus_number(dev), libusb_get_device_address(dev))
 #define bfg_claim_hid(api, verbose, path)  bfg_claim_any2(api, (verbose)?"":NULL, "hid", path)
 

+ 1 - 0
ft232r.c

@@ -91,6 +91,7 @@ struct lowlevel_device_info *ft232r_devinfo_scan()
 		info = malloc(sizeof(struct lowlevel_device_info));
 		*info = (struct lowlevel_device_info){
 			.lowl = &lowl_ft232r,
+			.devid = bfg_make_devid_libusb(list[i]),
 			.lowl_data = libusb_ref_device(list[i]),
 		};
 		

+ 11 - 0
lowlevel.c

@@ -14,6 +14,7 @@
 
 #include <utlist.h>
 
+#include "logging.h"
 #include "lowlevel.h"
 
 static struct lowlevel_device_info *devinfo_list;
@@ -26,6 +27,7 @@ void lowlevel_devinfo_free(struct lowlevel_device_info * const info)
 	free(info->product);
 	free(info->serial);
 	free(info->path);
+	free(info->devid);
 	free(info);
 }
 
@@ -58,6 +60,15 @@ void lowlevel_scan()
 	devinfo_mid_list = lowl_mcp2210.devinfo_scan();
 	LL_CONCAT(devinfo_list, devinfo_mid_list);
 #endif
+	
+	LL_FOREACH(devinfo_list, devinfo_mid_list)
+	{
+		applog(LOG_DEBUG, "%s: Found %s (path=%s, manuf=%s, prod=%s, serial=%s)",
+		       __func__,
+		       devinfo_mid_list->devid,
+		       devinfo_mid_list->path,
+		       devinfo_mid_list->manufacturer, devinfo_mid_list->product, devinfo_mid_list->serial);
+	}
 }
 
 int _lowlevel_detect(lowl_found_devinfo_func_t cb, const char *serial, const char **product_needles)

+ 1 - 0
lowlevel.h

@@ -17,6 +17,7 @@ struct lowlevel_device_info {
 	char *product;
 	char *serial;
 	char *path;
+	char *devid;
 	
 	struct lowlevel_driver *lowl;
 	void *lowl_data;

+ 3 - 0
mcp2210.c

@@ -174,9 +174,12 @@ struct lowlevel_device_info *mcp2210_devinfo_scan()
 	LL_FOREACH(hid_enum, hid_item)
 	{
 		info = malloc(sizeof(struct lowlevel_device_info));
+		char * const devid = malloc(4 + strlen(hid_item->path) + 1);
+		sprintf(devid, "hid:%s", hid_item->path);
 		*info = (struct lowlevel_device_info){
 			.lowl = &lowl_mcp2210,
 			.path = strdup(hid_item->path),
+			.devid = devid,
 			.manufacturer = wcs2str_dup(hid_item->manufacturer_string),
 			.product = wcs2str_dup(hid_item->product_string),
 			.serial  = wcs2str_dup(hid_item->serial_number),