Commit 9fe4ec90ea8728e1952b9070e0ae9d4a0f5c605b

Con Kolivas 2014-01-05T09:06:19

Provide helper functions for setting all pins and dirs on mcp2210

diff --git a/mcp2210.c b/mcp2210.c
index 1e24675..9a085de 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -184,6 +184,28 @@ bool mcp2210_get_gpio_pinval(struct cgpu_info *cgpu, int pin, int *val)
 	return true;
 }
 
+/* Set all pinvals */
+bool mcp2210_set_gpio_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp)
+{
+	char buf[MCP2210_BUFFER_LENGTH];
+	int pin;
+
+	memset(buf, 0, MCP2210_BUFFER_LENGTH);
+	buf[0] = MCP2210_SET_GPIO_PIN_VAL;
+
+	for (pin = 0; pin < 8; pin++) {
+		if (gp->pin[pin])
+			buf[4] |= (0x01u << pin);
+		else
+			buf[4] &= ~(0x01u << pin);
+	}
+	if (gp->pin[pin])
+		buf[5] |= 0x01u;
+	else
+		buf[5] &= ~0x01u;
+	return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOPINVAL);
+}
+
 /* Set one pinval */
 bool mcp2210_set_gpio_pinval(struct cgpu_info *cgpu, int pin, int val)
 {
@@ -249,6 +271,28 @@ bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir)
 	return true;
 }
 
+/* Set all pindirs */
+bool mcp2210_set_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp)
+{
+	char buf[MCP2210_BUFFER_LENGTH];
+	int pin;
+
+	memset(buf, 0, MCP2210_BUFFER_LENGTH);
+	buf[0] = MCP2210_SET_GPIO_PIN_DIR;
+
+	for (pin = 0; pin < 8; pin++) {
+		if (gp->pin[pin])
+			buf[4] |= (0x01u << pin);
+		else
+			buf[4] &= ~(0x01u << pin);
+	}
+	if (gp->pin[pin])
+		buf[5] |= 0x01u;
+	else
+		buf[5] &= ~0x01u;
+	return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOPINDIR);
+}
+
 /* Set one pindir */
 bool mcp2210_set_gpio_pindir(struct cgpu_info *cgpu, int pin, int dir)
 {
diff --git a/mcp2210.h b/mcp2210.h
index 05afe65..04c80c9 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -50,10 +50,12 @@ bool mcp2210_get_gpio_pin(struct cgpu_info *cgpu, int pin, int *des);
 bool mcp2210_set_gpio_pin_designations(struct cgpu_info *cgpu, struct gpio_pin *gp);
 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_pinvals(struct cgpu_info *cgpu, struct gpio_pin *gp);
 bool mcp2210_set_gpio_pinval(struct cgpu_info *cgpu, int pin, int val);
 bool mcp2210_set_gpio_output(struct cgpu_info *cgpu, int pin, int val);
 bool mcp2210_set_gpio_input(struct cgpu_info *cgpu, int pin);
 bool mcp2210_get_gpio_pindir(struct cgpu_info *cgpu, int pin, int *dir);
+bool mcp2210_set_gpio_pindirs(struct cgpu_info *cgpu, struct gpio_pin *gp);
 bool mcp2210_set_gpio_pindir(struct cgpu_info *cgpu, int pin, int dir);
 bool mcp2210_spi_cancel(struct cgpu_info *cgpu);
 bool