lowlevel.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef BFG_LOWLEVEL_H
  2. #define BFG_LOWLEVEL_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <pthread.h>
  6. #include <uthash.h>
  7. #include "miner.h"
  8. struct lowlevel_device_info;
  9. typedef bool (*lowl_found_devinfo_func_t)(struct lowlevel_device_info *, void *);
  10. struct lowlevel_driver {
  11. const char *dname;
  12. bool exclude_from_all;
  13. struct lowlevel_device_info *(*devinfo_scan)();
  14. void (*devinfo_free)(struct lowlevel_device_info *);
  15. };
  16. struct lowlevel_device_info {
  17. char *manufacturer;
  18. char *product;
  19. char *serial;
  20. char *path;
  21. char *devid;
  22. uint16_t vid;
  23. uint16_t pid;
  24. struct lowlevel_driver *lowl;
  25. void *lowl_data;
  26. struct lowlevel_device_info *next;
  27. struct lowlevel_device_info *same_devid_next;
  28. UT_hash_handle hh;
  29. pthread_t probe_pth;
  30. int ref;
  31. };
  32. extern char *bfg_make_devid_usb(uint8_t usbbus, uint8_t usbaddr);
  33. extern struct lowlevel_device_info *lowlevel_scan();
  34. extern bool _lowlevel_match_product(const struct lowlevel_device_info *, const char **);
  35. #define lowlevel_match_product(info, ...) \
  36. _lowlevel_match_product(info, (const char *[]){__VA_ARGS__, NULL})
  37. #define lowlevel_match_lowlproduct(info, matchlowl, ...) \
  38. (matchlowl == info->lowl && _lowlevel_match_product(info, (const char *[]){__VA_ARGS__, NULL}))
  39. extern bool lowlevel_match_id(const struct lowlevel_device_info *, const struct lowlevel_driver *, int32_t vid, int32_t pid);
  40. extern int _lowlevel_detect(lowl_found_devinfo_func_t, const char *serial, const char **product_needles, void *);
  41. #define lowlevel_detect(func, ...) _lowlevel_detect(func, NULL, (const char *[]){__VA_ARGS__, NULL}, NULL)
  42. #define lowlevel_detect_serial(func, serial) _lowlevel_detect(func, serial, (const char *[]){NULL}, NULL)
  43. extern int lowlevel_detect_id(lowl_found_devinfo_func_t, void *, const struct lowlevel_driver *, int32_t vid, int32_t pid);
  44. extern void lowlevel_scan_free();
  45. extern struct lowlevel_device_info *lowlevel_ref(const struct lowlevel_device_info *);
  46. #define lowlevel_claim(drv, verbose, info) \
  47. bfg_claim_any(drv, (verbose) ? ((info)->path ?: "") : NULL, (info)->devid)
  48. extern void lowlevel_devinfo_semicpy(struct lowlevel_device_info *dst, const struct lowlevel_device_info *src);
  49. extern void lowlevel_devinfo_free(struct lowlevel_device_info *);
  50. #ifdef NEED_BFG_LOWL_FTDI
  51. extern struct lowlevel_driver lowl_ft232r;
  52. #endif
  53. #ifdef NEED_BFG_LOWL_HID
  54. extern struct lowlevel_driver lowl_hid;
  55. #endif
  56. #ifdef USE_NANOFURY
  57. extern struct lowlevel_driver lowl_mcp2210;
  58. #endif
  59. #ifdef NEED_BFG_LOWL_PCI
  60. extern struct lowlevel_driver lowl_pci;
  61. #endif
  62. #ifdef HAVE_LIBUSB
  63. extern struct lowlevel_driver lowl_usb;
  64. #else
  65. // Dummy definition for the various "don't warn if just a lower-level interface" checks
  66. static __maybe_unused struct lowlevel_driver lowl_usb;
  67. #endif
  68. #ifdef NEED_BFG_LOWL_VCOM
  69. extern struct lowlevel_driver lowl_vcom;
  70. #endif
  71. extern struct device_drv *bfg_claim_any(struct device_drv *, const char *verbose, const char *devpath);
  72. extern struct device_drv *bfg_claim_any2(struct device_drv *, const char *verbose, const char *llname, const char *path);
  73. #endif