lowlevel.h 2.6 KB

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