Create a generic gpio pin struct and add helpers for mcp get pin val and dirs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
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") \