1mod connection;
2mod error;
3mod i2c_impl;
4mod protocol;
5
6#[cfg(all(test, feature = "hw-tests"))]
7mod hw_tests;
8
9pub(crate) use connection::Connection;
10
11pub use error::*;
12pub use i2c_impl::*;
13pub use rusb;
14
15use rusb::{Device, GlobalContext, UsbContext};
16
17pub fn is_supported_device<T: UsbContext>(dev: &Device<T>) -> bool {
18 let desc = match dev.device_descriptor() {
19 Err(_) => return false,
20 Ok(x) => x,
21 };
22 for (vid, pid) in protocol::KNOWN_VENDOR_PRODUCT_IDS {
23 if desc.vendor_id() == vid && desc.product_id() == pid {
24 return true;
25 }
26 }
27 false
28}
29
30pub fn devices() -> Vec<Device<GlobalContext>> {
31 match rusb::devices() {
32 Err(_) => vec![],
33 Ok(devs) => devs.iter().filter(is_supported_device).collect(),
34 }
35}