lowlevel.h 2.9 KB

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