Browse Source

mcp2210: Implement mcp2210_close

Luke Dashjr 12 years ago
parent
commit
1fd76523ab
3 changed files with 14 additions and 4 deletions
  1. 4 4
      driver-nanofury.c
  2. 9 0
      mcp2210.c
  3. 1 0
      mcp2210.h

+ 4 - 4
driver-nanofury.c

@@ -183,11 +183,11 @@ bool nanofury_foundlowl(struct lowlevel_device_info * const info)
 	{
 		applog(LOG_WARNING, "%s: Matched \"%s\" serial \"%s\", but failed to detect nanofury",
 		       __func__, product, serial);
-		// TODO: mcp2210_close(mcp);
+		mcp2210_close(mcp);
 		return false;
 	}
 	nanofury_device_off(mcp);
-	// TODO: mcp2210_close(mcp);
+	mcp2210_close(mcp);
 	
 	// TODO: claim device
 	
@@ -241,7 +241,7 @@ bool nanofury_init(struct thr_info * const thr)
 	if (!nanofury_checkport(mcp))
 	{
 		applog(LOG_ERR, "%"PRIpreprv": checkport failed", cgpu->proc_repr);
-		// TODO: mcp2210_close(mcp);
+		mcp2210_close(mcp);
 		return false;
 	}
 	
@@ -253,7 +253,7 @@ bool nanofury_init(struct thr_info * const thr)
 		applog(LOG_ERR, "%"PRIpreprv": Failed to allocate spi_port and bitfury_device structures", cgpu->proc_repr);
 		free(port);
 		free(bitfury);
-		// TODO: mcp2210_close(mcp);
+		mcp2210_close(mcp);
 		return false;
 	}
 	

+ 9 - 0
mcp2210.c

@@ -47,6 +47,7 @@ typedef HMODULE dlh_t;
 struct hid_device_info HID_API_EXPORT *(*dlsym_hid_enumerate)(unsigned short, unsigned short);
 void HID_API_EXPORT (*dlsym_hid_free_enumeration)(struct hid_device_info *);
 hid_device * HID_API_EXPORT (*dlsym_hid_open_path)(const char *);
+void HID_API_EXPORT (*dlsym_hid_close)(hid_device *);
 int HID_API_EXPORT (*dlsym_hid_read)(hid_device *, unsigned char *, size_t);
 int HID_API_EXPORT (*dlsym_hid_write)(hid_device *, const unsigned char *, size_t);
 
@@ -82,6 +83,7 @@ bool hidapi_try_lib(const char * const dlname)
 	dlsym_hid_free_enumeration(hid_enum);
 	
 	LOAD_SYM(hid_open_path);
+	LOAD_SYM(hid_close);
 	LOAD_SYM(hid_read);
 	LOAD_SYM(hid_write);
 	
@@ -97,6 +99,7 @@ fail:
 #define hid_enumerate dlsym_hid_enumerate
 #define hid_free_enumeration dlsym_hid_free_enumeration
 #define hid_open_path dlsym_hid_open_path
+#define hid_close dlsym_hid_close
 #define hid_read dlsym_hid_read
 #define hid_write dlsym_hid_write
 
@@ -255,6 +258,12 @@ fail:
 	return NULL;
 }
 
+void mcp2210_close(struct mcp2210_device * const h)
+{
+	hid_close(h->hid);
+	free(h);
+}
+
 static
 bool mcp2210_set_cfg_spi(struct mcp2210_device * const h)
 {

+ 1 - 0
mcp2210.h

@@ -17,6 +17,7 @@ enum mcp2210_gpio_value {
 struct mcp2210_device;
 
 extern struct mcp2210_device *mcp2210_open(struct lowlevel_device_info *);
+extern void mcp2210_close(struct mcp2210_device *);
 
 extern bool mcp2210_configure_spi(struct mcp2210_device *, uint32_t bitrate, uint16_t idlechipsel, uint16_t activechipsel, uint16_t chipseltodatadelay, uint16_t lastbytetocsdelay, uint16_t midbytedelay);
 extern bool mcp2210_set_spimode(struct mcp2210_device *, uint8_t spimode);