lowlevel.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. extern void lowlevel_devinfo_semicpy(struct lowlevel_device_info *dst, const struct lowlevel_device_info *src);
  43. extern void lowlevel_devinfo_free(struct lowlevel_device_info *);
  44. #ifdef USE_X6500
  45. extern struct lowlevel_driver lowl_ft232r;
  46. #endif
  47. #ifdef NEED_BFG_LOWL_HID
  48. extern struct lowlevel_driver lowl_hid;
  49. #endif
  50. #ifdef USE_NANOFURY
  51. extern struct lowlevel_driver lowl_mcp2210;
  52. #endif
  53. #ifdef HAVE_LIBUSB
  54. extern struct lowlevel_driver lowl_usb;
  55. #else
  56. // Dummy definition for the various "don't warn if just a lower-level interface" checks
  57. static struct lowlevel_driver lowl_usb;
  58. #endif
  59. #ifdef HAVE_FPGAUTILS
  60. extern struct lowlevel_driver lowl_vcom;
  61. #endif
  62. #endif