Add helper functions for getting and setting mcp2210 gpio pin designations.
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 83 84 85 86 87 88 89 90 91 92 93
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);