driver-erupter.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2013 Luke Dashjr
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 3 of the License, or (at your option)
  7. * any later version. See COPYING for more details.
  8. */
  9. #include "fpgautils.h"
  10. #include "icarus-common.h"
  11. #define ERUPTER_IO_SPEED 115200
  12. #define ERUPTER_HASH_TIME 0.0000000029761
  13. extern struct device_drv erupter_drv;
  14. extern struct device_drv erupter_drv_emerald;
  15. static bool _erupter_detect_one(const char *devpath, struct device_drv *drv)
  16. {
  17. struct ICARUS_INFO *info = calloc(1, sizeof(struct ICARUS_INFO));
  18. if (unlikely(!info))
  19. quit(1, "Failed to malloc ICARUS_INFO");
  20. *info = (struct ICARUS_INFO){
  21. .baud = ERUPTER_IO_SPEED,
  22. .Hs = ERUPTER_HASH_TIME,
  23. .timing_mode = MODE_DEFAULT,
  24. };
  25. if (!icarus_detect_custom(devpath, drv, info)) {
  26. free(info);
  27. return false;
  28. }
  29. return true;
  30. }
  31. static bool erupter_emerald_detect_one(const char *devpath)
  32. {
  33. return _erupter_detect_one(devpath, &erupter_drv_emerald);
  34. }
  35. static bool erupter_detect_one(const char *devpath)
  36. {
  37. return _erupter_detect_one(devpath, &erupter_drv);
  38. }
  39. static int erupter_emerald_detect_auto(void)
  40. {
  41. return serial_autodetect(erupter_emerald_detect_one, "Block", "Erupter", "Emerald");
  42. }
  43. static int erupter_detect_auto(void)
  44. {
  45. return serial_autodetect(erupter_detect_one, "Block", "Erupter");
  46. }
  47. static void erupter_drv_init();
  48. static void erupter_detect()
  49. {
  50. erupter_drv_init();
  51. // Actual serial detection is handled by Icarus driver
  52. erupter_drv_emerald.dname = "eruptere"; // temporary, so erupter:all is treated as Sapphire
  53. serial_detect_auto_byname(&erupter_drv_emerald, erupter_emerald_detect_one, erupter_emerald_detect_auto);
  54. erupter_drv_emerald.dname = "erupter";
  55. serial_detect_auto_byname(&erupter_drv, erupter_detect_one, erupter_detect_auto);
  56. }
  57. static void erupter_drv_init()
  58. {
  59. erupter_drv = icarus_drv;
  60. erupter_drv.dname = "erupter";
  61. erupter_drv.name = "BES";
  62. erupter_drv.drv_detect = erupter_detect;
  63. erupter_drv_emerald = erupter_drv;
  64. erupter_drv_emerald.name = "BEE";
  65. }
  66. struct device_drv erupter_drv = {
  67. // Needed to get to erupter_drv_init at all
  68. .drv_detect = erupter_detect,
  69. };
  70. struct device_drv erupter_drv_emerald;