WIP: get Heltec V3 working
This commit is contained in:
1 parent
b2e4bb0476
commit
75d70df294
1 file changed
+24
-1
+24
-1
@@ -13,18 +13,41 @@ pub const USB_VID: u16 = 0x1209;
|
|||||||
/// DongLoRa USB Product ID.
|
/// DongLoRa USB Product ID.
|
||||||
pub const USB_PID: u16 = 0x5741;
|
pub const USB_PID: u16 = 0x5741;
|
||||||
|
|
||||||
|
/// Known USB-UART bridge VID:PIDs found on some board revisions.
|
||||||
|
const BRIDGE_VID_PIDS: &[(u16, u16)] = &[
|
||||||
|
(0x10C4, 0xEA60), // CP2102 (Silicon Labs)
|
||||||
|
(0x1A86, 0x55D4), // CH9102
|
||||||
|
(0x1A86, 0x7523), // CH340
|
||||||
|
(0x0403, 0x6001), // FT232R (FTDI)
|
||||||
|
];
|
||||||
|
|
||||||
/// Find the DongLoRa serial port by USB VID:PID.
|
/// Find the DongLoRa serial port by USB VID:PID.
|
||||||
///
|
///
|
||||||
|
/// Checks for native USB CDC-ACM first (VID:PID 1209:5741), then falls
|
||||||
|
/// back to known USB-UART bridge chips found on some board revisions.
|
||||||
/// Returns the first matching port path, or `None` if no device is found.
|
/// Returns the first matching port path, or `None` if no device is found.
|
||||||
pub fn find_port() -> Option<String> {
|
pub fn find_port() -> Option<String> {
|
||||||
let ports = serialport::available_ports().ok()?;
|
let ports = serialport::available_ports().ok()?;
|
||||||
|
|
||||||
|
// Prefer native USB (our custom VID:PID)
|
||||||
|
if let Some(port) = ports.iter().find(|p| {
|
||||||
|
matches!(
|
||||||
|
&p.port_type,
|
||||||
|
serialport::SerialPortType::UsbPort(info)
|
||||||
|
if info.vid == USB_VID && info.pid == USB_PID
|
||||||
|
)
|
||||||
|
}) {
|
||||||
|
return Some(port.port_name.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to known USB-UART bridge chips
|
||||||
ports
|
ports
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|p| {
|
.find(|p| {
|
||||||
matches!(
|
matches!(
|
||||||
&p.port_type,
|
&p.port_type,
|
||||||
serialport::SerialPortType::UsbPort(info)
|
serialport::SerialPortType::UsbPort(info)
|
||||||
if info.vid == USB_VID && info.pid == USB_PID
|
if BRIDGE_VID_PIDS.contains(&(info.vid, info.pid))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.map(|p| p.port_name)
|
.map(|p| p.port_name)
|
||||||
|
|||||||
Reference in new issue
Block a user