lowlevel.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. struct lowlevel_device_info;
  8. typedef bool (*lowl_found_devinfo_func_t)(struct lowlevel_device_info *, void *);
  9. struct lowlevel_driver {
  10. const char *dname;
  11. struct lowlevel_device_info *(*devinfo_scan)();
  12. void (*devinfo_free)(struct lowlevel_device_info *);
  13. };
  14. struct lowlevel_device_info {
  15. char *manufacturer;
  16. char *product;
  17. char *serial;
  18. char *path;
  19. char *devid;
  20. uint16_t vid;
  21. uint16_t pid;
  22. struct lowlevel_driver *lowl;
  23. void *lowl_data;
  24. struct lowlevel_device_info *next;
  25. UT_hash_handle hh;
  26. pthread_t probe_pth;
  27. int ref;
  28. };
  29. extern struct lowlevel_device_info *lowlevel_scan();
  30. extern bool _lowlevel_match_product(const struct lowlevel_device_info *, const char **);
  31. #define lowlevel_match_product(info, ...) \
  32. _lowlevel_match_product(info, (const char *[]){__VA_ARGS__, NULL})
  33. #define lowlevel_match_lowlproduct(info, matchlowl, ...) \
  34. (matchlowl == info->lowl && _lowlevel_match_product(info, (const char *[]){__VA_ARGS__, NULL}))
  35. extern bool lowlevel_match_id(const struct lowlevel_device_info *, const struct lowlevel_driver *, int32_t vid, int32_t pid);
  36. extern int _lowlevel_detect(lowl_found_devinfo_func_t, const char *serial, const char **product_needles, void *);
  37. #define lowlevel_detect(func, ...) _lowlevel_detect(func, NULL, (const char *[]){__VA_ARGS__, NULL}, NULL)
  38. #define lowlevel_detect_serial(func, serial) _lowlevel_detect(func, serial, (const char *[]){NULL}, NULL)
  39. extern int lowlevel_detect_id(lowl_found_devinfo_func_t, void *, const struct lowlevel_driver *, int32_t vid, int32_t pid);
  40. extern void lowlevel_scan_free();
  41. extern struct lowlevel_device_info *lowlevel_ref(const struct lowlevel_device_info *);
  42. #define lowlevel_claim(drv, verbose, info) \
  43. bfg_claim_any(drv, (verbose) ? ((info)->path ?: "") : NULL, (info)->devid)
  44. extern void lowlevel_devinfo_semicpy(struct lowlevel_device_info *dst, const struct lowlevel_device_info *src);
  45. extern void lowlevel_devinfo_free(struct lowlevel_device_info *);
  46. #ifdef USE_X6500
  47. extern struct lowlevel_driver lowl_ft232r;
  48. #endif
  49. #ifdef NEED_BFG_LOWL_HID
  50. extern struct lowlevel_driver lowl_hid;
  51. #endif
  52. #ifdef USE_NANOFURY
  53. extern struct lowlevel_driver lowl_mcp2210;
  54. #endif
  55. #ifdef HAVE_LIBUSB
  56. extern struct lowlevel_driver lowl_usb;
  57. #else
  58. // Dummy definition for the various "don't warn if just a lower-level interface" checks
  59. static struct lowlevel_driver lowl_usb;
  60. #endif
  61. #ifdef HAVE_FPGAUTILS
  62. extern struct lowlevel_driver lowl_vcom;
  63. #endif
  64. #endif