From 75d70df29476db056304a59c2e7a1a683653bd3d Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 6 Apr 2026 22:53:00 -0600 Subject: [PATCH] WIP: get Heltec V3 working --- src/discovery.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/discovery.rs b/src/discovery.rs index f5392a8..0ce8d8d 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -13,18 +13,41 @@ pub const USB_VID: u16 = 0x1209; /// DongLoRa USB Product ID. 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. /// +/// 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. pub fn find_port() -> Option { 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 .into_iter() .find(|p| { matches!( &p.port_type, 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)