Create a generic mcp2210 send_rcv 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
diff --git a/mcp2210.c b/mcp2210.c
index 2edf4d2..0d4ae5c 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -6,4 +6,33 @@
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
+#include "miner.h"
+#include "usbutils.h"
+#include "mcp2210.h"
+bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds send_cmd,
+ enum usb_cmds recv_cmd)
+{
+ int amount, err;
+
+ if (unlikely(cgpu->usbinfo.nodev))
+ return false;
+
+ err = usb_write(cgpu, buf, MCP2210_BUFFER_LENGTH, &amount, send_cmd);
+ if (err || amount != MCP2210_BUFFER_LENGTH) {
+ applog(LOG_WARNING, "%s %d: Error %d sending %s sent %d of %d",
+ cgpu->drv->name, cgpu->device_id, err, usb_cmdname(send_cmd),
+ amount, MCP2210_BUFFER_LENGTH);
+ return false;
+ }
+
+ err = usb_read(cgpu, buf, MCP2210_BUFFER_LENGTH, &amount, recv_cmd);
+ if (err || amount != MCP2210_BUFFER_LENGTH) {
+ applog(LOG_WARNING, "%s %d: Error %d receiving %s received %d of %d",
+ cgpu->drv->name, cgpu->device_id, err, usb_cmdname(recv_cmd),
+ amount, MCP2210_BUFFER_LENGTH);
+ return false;
+ }
+
+ return true;
+}
diff --git a/mcp2210.h b/mcp2210.h
index 53d2a34..937a978 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -29,4 +29,6 @@
#define MCP2210_SPI_TRANSFER_ERROR_NA 0xF7 // SPI not available due to external owner
#define MCP2210_SPI_TRANSFER_ERROR_IP 0xF8 // SPI not available due to transfer in progress
+bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds send_cmd,
+ enum usb_cmds recv_cmd);
#endif /* MCP2210_H */