lowlevel.h 3.0 KB

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