Browse Source

lowlevel: Promote path to a normal element for devices to simplify things a bit

Luke Dashjr 12 years ago
parent
commit
671896dccd
5 changed files with 8 additions and 20 deletions
  1. 2 1
      driver-nanofury.c
  2. 3 1
      lowlevel.c
  3. 1 0
      lowlevel.h
  4. 2 16
      mcp2210.c
  5. 0 2
      mcp2210.h

+ 2 - 1
driver-nanofury.c

@@ -14,6 +14,7 @@
 
 #include "deviceapi.h"
 #include "driver-bitfury.h"
+#include "fpgautils.h"
 #include "libbitfury.h"
 #include "logging.h"
 #include "lowlevel.h"
@@ -189,7 +190,7 @@ bool nanofury_foundlowl(struct lowlevel_device_info * const info)
 	nanofury_device_off(mcp);
 	mcp2210_close(mcp);
 	
-	if (bfg_claim_mcp2210(&nanofury_drv, true, info))
+	if (bfg_claim_hid(&nanofury_drv, true, info->path))
 		return false;
 	
 	struct cgpu_info *cgpu;

+ 3 - 1
lowlevel.c

@@ -20,9 +20,11 @@ static struct lowlevel_device_info *devinfo_list;
 
 void lowlevel_devinfo_free(struct lowlevel_device_info * const info)
 {
-	info->lowl->devinfo_free(info);
+	if (info->lowl->devinfo_free)
+		info->lowl->devinfo_free(info);
 	free(info->product);
 	free(info->serial);
+	free(info->path);
 	free(info);
 }
 

+ 1 - 0
lowlevel.h

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

+ 2 - 16
mcp2210.c

@@ -30,7 +30,6 @@ typedef HMODULE dlh_t;
 #include <hidapi.h>
 #include <utlist.h>
 
-#include "fpgautils.h"
 #include "logging.h"
 #include "lowlevel.h"
 #include "miner.h"
@@ -135,12 +134,6 @@ bool hidapi_load_library()
 	return false;
 }
 
-static
-void mcp2210_devinfo_free(struct lowlevel_device_info * const info)
-{
-	free(info->lowl_data);
-}
-
 static
 char *wcs2str_dup(wchar_t *ws)
 {
@@ -183,7 +176,7 @@ struct lowlevel_device_info *mcp2210_devinfo_scan()
 		info = malloc(sizeof(struct lowlevel_device_info));
 		*info = (struct lowlevel_device_info){
 			.lowl = &lowl_mcp2210,
-			.lowl_data = strdup(hid_item->path),
+			.path = strdup(hid_item->path),
 			.product = wcs2str_dup(hid_item->product_string),
 			.serial  = wcs2str_dup(hid_item->serial_number),
 		};
@@ -207,12 +200,6 @@ struct mcp2210_device {
 	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
 bool mcp2210_io(hid_device * const hid, uint8_t * const cmd, uint8_t * const buf)
 {
@@ -249,7 +236,7 @@ bool mcp2210_get_configs(struct mcp2210_device * const h)
 struct mcp2210_device *mcp2210_open(struct lowlevel_device_info *info)
 {
 	struct mcp2210_device *h;
-	char * const path = info->lowl_data;
+	char * const path = info->path;
 	hid_device * const hid = hid_open_path(path);
 	
 	if (unlikely(!hid))
@@ -462,5 +449,4 @@ enum mcp2210_gpio_value mcp2210_get_gpio_input(struct mcp2210_device * const h,
 
 struct lowlevel_driver lowl_mcp2210 = {
 	.devinfo_scan = mcp2210_devinfo_scan,
-	.devinfo_free = mcp2210_devinfo_free,
 };

+ 0 - 2
mcp2210.h

@@ -16,8 +16,6 @@ enum mcp2210_gpio_value {
 
 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 void mcp2210_close(struct mcp2210_device *);