Browse Source

mcp2210: Implement claim on HID paths

Luke Dashjr 12 years ago
parent
commit
2deec4bf2b
5 changed files with 24 additions and 1 deletions
  1. 1 0
      configure.ac
  2. 11 1
      fpgautils.c
  3. 3 0
      fpgautils.h
  4. 7 0
      mcp2210.c
  5. 2 0
      mcp2210.h

+ 1 - 0
configure.ac

@@ -611,6 +611,7 @@ elif test "x$bitfury" = "xyes"; then
 	fi
 	fi
 elif test "x$nanofury" = "xyes"; then
 elif test "x$nanofury" = "xyes"; then
 	AC_MSG_ERROR([You explicitly disabled Bitfury and explicitly enabled NanoFury])
 	AC_MSG_ERROR([You explicitly disabled Bitfury and explicitly enabled NanoFury])
+	need_fpgautils=yes
 else
 else
 	nanofury=no
 	nanofury=no
 fi
 fi

+ 11 - 1
fpgautils.c

@@ -505,7 +505,6 @@ struct _device_claim {
 	UT_hash_handle hh;
 	UT_hash_handle hh;
 };
 };
 
 
-static
 struct device_drv *bfg_claim_any(struct device_drv * const api, const char *verbose, const char * const devpath)
 struct device_drv *bfg_claim_any(struct device_drv * const api, const char *verbose, const char * const devpath)
 {
 {
 	static struct _device_claim *claims = NULL;
 	static struct _device_claim *claims = NULL;
@@ -543,6 +542,17 @@ struct device_drv *bfg_claim_any(struct device_drv * const api, const char *verb
 	return NULL;
 	return NULL;
 }
 }
 
 
+struct device_drv *bfg_claim_any2(struct device_drv * const api, const char * const verbose, const char * const llname, const char * const path)
+{
+	const size_t llnamesz = strlen(llname);
+	const size_t pathsz = strlen(path);
+	char devpath[llnamesz + 1 + pathsz + 1];
+	memcpy(devpath, llname, llnamesz);
+	devpath[llnamesz] = ':';
+	memcpy(&devpath[llnamesz+1], path, pathsz + 1);
+	return bfg_claim_any(api, verbose, devpath);
+}
+
 struct device_drv *bfg_claim_serial(struct device_drv * const api, const bool verbose, const char * const devpath)
 struct device_drv *bfg_claim_serial(struct device_drv * const api, const bool verbose, const char * const devpath)
 {
 {
 #ifndef WIN32
 #ifndef WIN32

+ 3 - 0
fpgautils.h

@@ -28,11 +28,14 @@ extern void clear_detectone_meta_info(void);
 extern int _serial_autodetect(detectone_func_t, ...);
 extern int _serial_autodetect(detectone_func_t, ...);
 #define serial_autodetect(...)  _serial_autodetect(__VA_ARGS__, NULL)
 #define serial_autodetect(...)  _serial_autodetect(__VA_ARGS__, NULL)
 
 
+extern struct device_drv *bfg_claim_any(struct device_drv *, const char *verbose, const char *devpath);
+extern struct device_drv *bfg_claim_any2(struct device_drv *, const char *verbose, const char *llname, const char *path);
 extern struct device_drv *bfg_claim_serial(struct device_drv * const, const bool verbose, const char * const devpath);
 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(devpath, drv)    bfg_claim_serial(drv, false, devpath)
 #define serial_claim_v(devpath, drv)  bfg_claim_serial(drv, true , devpath)
 #define serial_claim_v(devpath, drv)  bfg_claim_serial(drv, true , devpath)
 extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const 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_claim_libusb(api, verbose, dev)  bfg_claim_usb(api, verbose, 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)
 
 
 #ifdef HAVE_LIBUSB
 #ifdef HAVE_LIBUSB
 extern void cgpu_copy_libusb_strings(struct cgpu_info *, libusb_device *);
 extern void cgpu_copy_libusb_strings(struct cgpu_info *, libusb_device *);

+ 7 - 0
mcp2210.c

@@ -30,6 +30,7 @@ typedef HMODULE dlh_t;
 #include <hidapi.h>
 #include <hidapi.h>
 #include <utlist.h>
 #include <utlist.h>
 
 
+#include "fpgautils.h"
 #include "logging.h"
 #include "logging.h"
 #include "lowlevel.h"
 #include "lowlevel.h"
 #include "miner.h"
 #include "miner.h"
@@ -206,6 +207,12 @@ struct mcp2210_device {
 	uint8_t cfg_gpio[0xf];
 	uint8_t cfg_gpio[0xf];
 };
 };
 
 
+struct device_drv *bfg_claim_mcp2210(struct device_drv * const api, const bool verbose, const struct lowlevel_device_info * const info)
+{
+	const char * const path = info->lowl_data;
+	return bfg_claim_hid(api, verbose, path);
+}
+
 static
 static
 bool mcp2210_io(hid_device * const hid, uint8_t * const cmd, uint8_t * const buf)
 bool mcp2210_io(hid_device * const hid, uint8_t * const cmd, uint8_t * const buf)
 {
 {

+ 2 - 0
mcp2210.h

@@ -16,6 +16,8 @@ enum mcp2210_gpio_value {
 
 
 struct mcp2210_device;
 struct mcp2210_device;
 
 
+extern struct device_drv *bfg_claim_mcp2210(struct device_drv *, bool verbose, const struct lowlevel_device_info *);
+
 extern struct mcp2210_device *mcp2210_open(struct lowlevel_device_info *);
 extern struct mcp2210_device *mcp2210_open(struct lowlevel_device_info *);
 extern void mcp2210_close(struct mcp2210_device *);
 extern void mcp2210_close(struct mcp2210_device *);