Set gpio values in the one function with all values for nanofury.
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/driver-bitfury.c b/driver-bitfury.c
index 6d0f790..a38e666 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -486,27 +486,28 @@ static bool nf1_set_spi_settings(struct cgpu_info *bitfury, struct bitfury_info
static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
{
+ struct mcp_settings *mcp = &info->mcp;
char buf[MCP2210_BUFFER_LENGTH];
unsigned int length;
- struct gpio_pin gp;
bool ret = false;
int i, val;
- /* Set all pins to GPIO mode */
- for (i = 0; i < 9; i++)
- gp.pin[i] = MCP2210_PIN_GPIO;
- if (!mcp2210_set_gpio_pin_designations(bitfury, &gp))
- goto out;
+ mcp2210_get_gpio_settings(bitfury, mcp);
- /* Set all pins to input mode */
- for (i = 0; i < 9; i++)
- gp.pin[i] = MCP2210_GPIO_INPUT;
- if (!mcp2210_set_gpio_pindirs(bitfury, &gp))
+ for (i = 0; i < 9; i++) {
+ /* Set all pins to GPIO mode */
+ mcp->designation.pin[i] = MCP2210_PIN_GPIO;
+ /* Set all pins to input mode */
+ mcp->direction.pin[i] = MCP2210_GPIO_INPUT;
+ }
- /* Set LED and PWR pins to output and high */
- if (!mcp2210_set_gpio_output(bitfury, NF1_PIN_LED, MCP2210_GPIO_PIN_HIGH))
+ if (!mcp2210_set_gpio_settings(bitfury, mcp))
goto out;
- if (!mcp2210_set_gpio_output(bitfury, NF1_PIN_PWR_EN, MCP2210_GPIO_PIN_HIGH))
+
+ /* Set LED and PWR pins to output and high */
+ mcp->direction.pin[NF1_PIN_LED] = mcp->direction.pin[NF1_PIN_PWR_EN] = MCP2210_GPIO_OUTPUT;
+ mcp->value.pin[NF1_PIN_LED] = mcp->value.pin[NF1_PIN_PWR_EN] = MCP2210_GPIO_PIN_HIGH;
+ if (!mcp2210_set_gpio_settings(bitfury, mcp))
goto out;
if (opt_debug) {
diff --git a/mcp2210.c b/mcp2210.c
index 1c776aa..e08ba28 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -88,10 +88,18 @@ 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)
{
char buf[MCP2210_BUFFER_LENGTH];
+ uint8_t buf17;
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;
+ buf17 = buf[17];
+
+ memset(buf, 0, MCP2210_BUFFER_LENGTH);
buf[0] = MCP2210_SET_GPIO_SETTING;
+ buf[17] = buf17;
for (i = 0; i < 8; i++) {
buf[4 + i] = mcp->designation.pin[i];
buf[13] |= mcp->value.pin[i] << i;
diff --git a/mcp2210.h b/mcp2210.h
index a9fece2..d6c4553 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -39,7 +39,7 @@
#define MCP2210_SPI_TRANSFER_ERROR_IP 0xF8 // SPI not available due to transfer in progress
struct gpio_pin {
- int pin[9];
+ uint8_t pin[9];
};
struct mcp_settings {