Commit d439fc754eac71a06b46def5bf7290d65a3c7d0e

Con Kolivas 2014-01-03T15:17:26

Create a generic gpio pin struct and add helpers for mcp get pin val and dirs.

diff --git a/mcp2210.c b/mcp2210.c
index 024f3d0..bacfbd5 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -42,3 +42,37 @@ bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd)
 	}
 	return true;
 }
+
+bool mcp2210_get_gpio_pinvals(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_PIN_VAL;
+	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOPINVAL))
+		return false;
+
+	for (i = 0; i < 8; i++)
+		gp->pin[i] = buf[4] & (0x01u << i);
+	gp->pin[8] = buf[5] & 0x01u;
+
+	return true;
+}
+
+bool mcp2210_get_gpio_pindirs(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_PIN_DIR;
+	if (!mcp2210_send_recv(cgpu, buf, C_MCP_GETGPIOPINDIR))
+		return false;
+
+	for (i = 0; i < 8; i++)
+		gp->pin[i] = buf[4] & (0x01u << i);
+	gp->pin[8] = buf[5] & 0x01u;
+
+	return true;
+}
diff --git a/mcp2210.h b/mcp2210.h
index e565baf..eabdaf5 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -12,6 +12,9 @@
 
 #define MCP2210_BUFFER_LENGTH		64
 
+#define MCP2210_GPIO_PIN_LOW		0
+#define MCP2210_GPIO_PIN_HIGH		1
+
 #define MCP2210_GPIO_OUTPUT		0
 #define MCP2210_GPIO_INPUT		1
 
@@ -29,6 +32,12 @@
 #define MCP2210_SPI_TRANSFER_ERROR_NA	0xF7	// SPI not available due to external owner
 #define MCP2210_SPI_TRANSFER_ERROR_IP	0xF8	// SPI not available due to transfer in progress
 
+struct gpio_pin {
+	int pin[9];
+};
+
 bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd);
+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);
 
 #endif /* MCP2210_H */
diff --git a/usbutils.h b/usbutils.h
index a694f2b..50e6aab 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -390,6 +390,8 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_MCP_GETGPIOSETTING, "MCPGetGPIOSetting") \
 	USB_ADD_COMMAND(C_MCP_SETGPIOSETTING, "MCPSetGPIOSetting") \
 	USB_ADD_COMMAND(C_MCP_GETGPIOPINVAL, "MCPGetGPIOPinVal") \
+	USB_ADD_COMMAND(C_MCP_SETGPIOPINVAL, "MCPSetGPIOPinVal") \
+	USB_ADD_COMMAND(C_MCP_GETGPIOPINDIR, "MCPGetGPIOPinDir") \
 	USB_ADD_COMMAND(C_MCP_SETGPIOPINDIR, "MCPSetGPIOPinDir") \
 	USB_ADD_COMMAND(C_MCP_SETSPISETTING, "MCPSetSPISetting") \
 	USB_ADD_COMMAND(C_MCP_GETSPISETTING, "MCPGetSPISetting") \