Implement an mcp2210 set spi transfer settings function.
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 416a43b..e821b84 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -227,3 +227,44 @@ bool mcp2210_spi_cancel(struct cgpu_info *cgpu)
buf[0] = MCP2210_SPI_CANCEL;
return mcp2210_send_recv(cgpu, buf, C_MCP_SPICANCEL);
}
+
+/* Abbreviations correspond to:
+ * IdleChipSelectValue, ActiveChipSelectValue, CSToDataDelay, LastDataByteToCSDelay,
+ * SubsequentDataByteDelay, BytesPerSPITransfer
+ */
+bool
+mcp2210_set_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int bitrate, unsigned int icsv,
+ unsigned int acsv, unsigned int cstdd, unsigned int ldbtcsd,
+ unsigned int sdbd, unsigned int bpst, unsigned int spimode)
+{
+ char buf[MCP2210_BUFFER_LENGTH];
+
+ memset(buf, 0, MCP2210_BUFFER_LENGTH);
+ buf[0] = MCP2210_SET_SPI_SETTING;
+
+ buf[4] = bitrate & 0xfful;
+ buf[5] = (bitrate & 0xff00ul) >> 8;
+ buf[6] = (bitrate & 0xff0000ul) >> 16;
+ buf[7] = (bitrate & 0xff000000ul) >> 24;
+
+ buf[8] = icsv & 0xff;
+ buf[9] = (icsv & 0x100) >> 8;
+
+ buf[10] = acsv & 0xff;
+ buf[11] = (acsv & 0x100) >> 8;
+
+ buf[12] = cstdd & 0xff;
+ buf[13] = (cstdd & 0xff00) >> 8;
+
+ buf[14] = ldbtcsd & 0xff;
+ buf[15] = (ldbtcsd & 0xff00) >> 8;
+
+ buf[16] = sdbd & 0xff;
+ buf[17] = (sdbd & 0xff00) >> 8;
+
+ buf[18] = bpst & 0xff;
+ buf[19] = (bpst & 0xff00) >> 8;
+
+ buf[20] = spimode;
+ return mcp2210_send_recv(cgpu, buf, C_MCP_SETSPISETTING);
+}
diff --git a/mcp2210.h b/mcp2210.h
index 563fdd3..69105f9 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -52,5 +52,9 @@ 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);
bool mcp2210_set_gpio_pindir(struct cgpu_info *cgpu, int pin, int dir);
bool mcp2210_spi_cancel(struct cgpu_info *cgpu);
+bool
+mcp2210_set_spi_transfer_settings(struct cgpu_info *cgpu, unsigned int bitrate, unsigned int icsv,
+ unsigned int acsv, unsigned int cstdd, unsigned int ldbtcsd,
+ unsigned int sdbd, unsigned int bpst, unsigned int spimode);
#endif /* MCP2210_H */