Commit 1a9c558a38c65edb1a51e0946967dc2f9c71d45c

Con Kolivas 2014-01-03T17:31:54

Add helper functions for getting and setting mcp2210 gpio pin designations.

diff --git a/mcp2210.c b/mcp2210.c
index cb846af..06d62ba 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -43,7 +43,24 @@ bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd)
 	return true;
 }
 
-/* Get all the pinvals */
+/* 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)
+{
+	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 < 9; i++)
+		gp->pin[i] = buf[4 + i];
+	return true;
+}
+
+
+/* Get all the pin vals and store them in a gpio_pin struct */
 bool mcp2210_get_gpio_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp)
 {
 	char buf[MCP2210_BUFFER_LENGTH];
@@ -79,6 +96,35 @@ bool mcp2210_get_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp)
 	return true;
 }
 
+/* Get the designation of one pin */
+bool mcp2210_get_gpio_pin(struct cgpu_info *cgpu, int pin, int *des)
+{
+	struct gpio_pin gp;
+
+	if (!mcp2210_get_gpio_pindes(cgpu, &gp))
+		return false;
+
+	*des = gp.pin[pin];
+	return true;
+}
+
+/* Set the designation of one pin */
+bool mcp2210_set_gpio_pindes(struct cgpu_info *cgpu, int pin, int des)
+{
+	char buf[MCP2210_BUFFER_LENGTH];
+
+	/* Copy the current values */
+	memset(buf, 0, MCP2210_BUFFER_LENGTH);
+	buf[0] = MCP2210_GET_GPIO_SETTING;
+	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOSETTING))
+		return false;
+
+	buf[4 + pin] = des;
+	memset(buf + 18, 0, 45);
+	buf[0] = MCP2210_SET_GPIO_SETTING;
+	return (mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOSETTING));
+}
+
 /* Get one pinval */
 bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val)
 {
diff --git a/mcp2210.h b/mcp2210.h
index df04c91..cdf7eb0 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -12,6 +12,10 @@
 
 #define MCP2210_BUFFER_LENGTH		64
 
+#define MCP2210_PIN_GPIO		0x0
+#define MCP2210_PIN_CS			0x1
+#define MCP2210_PIN_DEDICATED		0x2
+
 #define MCP2210_GPIO_PIN_LOW		0
 #define MCP2210_GPIO_PIN_HIGH		1
 
@@ -37,8 +41,11 @@ struct gpio_pin {
 };
 
 bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd);
+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);
+bool mcp2210_get_gpio_pin(struct cgpu_info *cgpu, int pin, int *des);
+bool mcp2210_set_gpio_pindes(struct cgpu_info *cgpu, int pin, int des);
 bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val);
 bool mcp2210_set_gpio_pinval(struct cgpu_info *cgpu, int pin, int val);
 bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir);