Provide helper functions for setting all pins and dirs on mcp2210
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
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