Commit 24611bda5c29cff39e4ee4fc1e69a1f6ed520ba4

Con Kolivas 2014-01-05T16:17:53

Provide a helper function for setting all mcp2210 gpio settings.

diff --git a/mcp2210.c b/mcp2210.c
index 41842c8..1c776aa 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -74,17 +74,35 @@ bool mcp2210_get_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp)
 		return false;
 
 	for (i = 0; i < 8; i++) {
-		mcp->designation.pin[i] = !!(buf[4 + 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->designation.pin[8] = buf[12];
 	mcp->value.pin[8] = buf[14] & 0x01u;
 	mcp->direction.pin[8] = buf[16] & 0x01u;
 
 	return true;
 }
 
+bool mcp2210_set_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_SET_GPIO_SETTING;
+	for (i = 0; i < 8; i++) {
+		buf[4 + i] = mcp->designation.pin[i];
+		buf[13] |= mcp->value.pin[i] << i;
+		buf[15] |= mcp->direction.pin[i] << i;
+	}
+	buf[12] = mcp->designation.pin[8];
+	buf[14] = mcp->value.pin[8];
+	buf[16] = mcp->direction.pin[8];
+	return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOSETTING);
+}
+
 /* 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)
 {
@@ -97,7 +115,7 @@ bool mcp2210_get_gpio_pindes(struct cgpu_info *cgpu, struct gpio_pin *gp)
 		return false;
 
 	for (i = 0; i < 9; i++)
-		gp->pin[i] = !!(buf[4 + i]);
+		gp->pin[i] = buf[4 + i];
 	return true;
 }
 
diff --git a/mcp2210.h b/mcp2210.h
index cbbe298..a9fece2 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -51,6 +51,7 @@ struct mcp_settings {
 
 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_set_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);