Provide a helper function for setting all mcp2210 gpio settings.
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
diff --git a/mcp2210.c b/mcp2210.c
index 41842c8..1c776aa 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -74,17 +74,35 @@ bool mcp2210_get_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp)
return false;
for (i = 0; i < 8; i++) {
- mcp->designation.pin[i] = !!(buf[4 + i]);
+ mcp->designation.pin[i] = buf[4 + i];
mcp->value.pin[i] = !!(buf[13] & (0x01u << i));
mcp->direction.pin[i] = !!(buf[15] & (0x01u << i));
}
- mcp->designation.pin[8] = !!(buf[12]);
+ mcp->designation.pin[8] = buf[12];
mcp->value.pin[8] = buf[14] & 0x01u;
mcp->direction.pin[8] = buf[16] & 0x01u;
return true;
}
+bool mcp2210_set_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp)
+{
+ char buf[MCP2210_BUFFER_LENGTH];
+ int i;
+
+ memset(buf, 0, MCP2210_BUFFER_LENGTH);
+ buf[0] = MCP2210_SET_GPIO_SETTING;
+ for (i = 0; i < 8; i++) {
+ buf[4 + i] = mcp->designation.pin[i];
+ buf[13] |= mcp->value.pin[i] << i;
+ buf[15] |= mcp->direction.pin[i] << i;
+ }
+ buf[12] = mcp->designation.pin[8];
+ buf[14] = mcp->value.pin[8];
+ buf[16] = mcp->direction.pin[8];
+ return mcp2210_send_recv(cgpu, buf, C_MCP_SETGPIOSETTING);
+}
+
/* 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)
{
@@ -97,7 +115,7 @@ bool mcp2210_get_gpio_pindes(struct cgpu_info *cgpu, struct gpio_pin *gp)
return false;
for (i = 0; i < 9; i++)
- gp->pin[i] = !!(buf[4 + i]);
+ gp->pin[i] = buf[4 + i];
return true;
}
diff --git a/mcp2210.h b/mcp2210.h
index cbbe298..a9fece2 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -51,6 +51,7 @@ struct mcp_settings {
bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds cmd);
bool mcp2210_get_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp);
+bool mcp2210_set_gpio_settings(struct cgpu_info *cgpu, struct mcp_settings *mcp);
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);