Commit f32f093f252138d722826e514b94676ab811d73f

Con Kolivas 2014-01-05T16:06:35

Add a helper function for getting all mcp2210 gpio settings.

diff --git a/driver-bitfury.h b/driver-bitfury.h
index c5cb9ba..2621e50 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -31,10 +31,6 @@ extern int opt_bxf_temp_target;
 
 #define NF1_SPIBUF_SIZE 16384
 
-struct mcp_settings {
-	unsigned int bitrate, icsv, acsv, cstdd, ldbtcsd, sdbd, bpst, spimode;
-};
-
 struct bitfury_info {
 	struct cgpu_info *base_cgpu;
 	struct thr_info *thr;
diff --git a/mcp2210.c b/mcp2210.c
index 9a085de..41842c8 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -63,6 +63,28 @@ bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd)
 	return true;
 }
 
+bool mcp2210_get_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp)
+{
+	char buf[MCP2210_BUFFER_LENGTH];
+	int i;
+
+	memset(buf, 0, MCP2210_BUFFER_LENGTH);
+	buf[0] = MCP2210_GET_GPIO_SETTING;
+	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOSETTING))
+		return false;
+
+	for (i = 0; i < 8; i++) {
+		mcp->designation.pin[i] = !!(buf[4 + i]);
+		mcp->value.pin[i] = !!(buf[13] & (0x01u << i));
+		mcp->direction.pin[i] = !!(buf[15] & (0x01u << i));
+	}
+	mcp->designation.pin[8] = !!(buf[12]);
+	mcp->value.pin[8] = buf[14] & 0x01u;
+	mcp->direction.pin[8] = buf[16] & 0x01u;
+
+	return true;
+}
+
 /* Get all the pin designations and store them in a gpio_pin struct */
 bool mcp2210_get_gpio_pindes(struct cgpu_info *cgpu, struct gpio_pin *gp)
 {
diff --git a/mcp2210.h b/mcp2210.h
index 04c80c9..cbbe298 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -42,7 +42,15 @@ struct gpio_pin {
 	int pin[9];
 };
 
+struct mcp_settings {
+	struct gpio_pin designation;
+	struct gpio_pin value;
+	struct gpio_pin direction;
+	unsigned int bitrate, icsv, acsv, cstdd, ldbtcsd, sdbd, bpst, spimode;
+};
+
 bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd);
+bool mcp2210_get_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp);
 bool mcp2210_get_gpio_pindes(struct cgpu_info *cgpu, struct gpio_pin *gp);
 bool mcp2210_get_gpio_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp);
 bool mcp2210_get_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp);