Skip to content

Commit

Permalink
Fixes the PCI-port bug on Raspberry Pi 4 (#113)
Browse files Browse the repository at this point in the history
* Fixes the PCI-port bug on Raspberry Pi 4

The Bug is caused by the Fact that the USB controller is connected to
the CPU via PCI, which was not the case on the Raspberry Pi 3.
Because of this, the BUS_ID reported by libudev is PCI. However, if it
is an actual USB device, there will be fields containing the neccessary
information to generate a UsbPortInfo. This patch checks whether all
those fields are available, if the BUS_ID is Pci, and if so uses them to
populate an UsbPortInfo and return a SerialPortType::UsbPort

* removes some logging code I accidentally left in there

* fixes mistake in feature gated code

* updates Changelog

* oops
  • Loading branch information
KnorrFG authored Jul 27, 2023
1 parent 3cdc1a5 commit 9d95e5c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ project adheres to [Semantic Versioning](https://semver.org/).
### Added
### Changed
### Fixed
* Fixes a bug on the Raspberry Pi 4, which results in USB-devices being detected as PCI-devices.
[#113](https://github.com/serialport/serialport-rs/pull/113)

### Removed

## [4.2.1] - 2023-05-21
Expand Down
30 changes: 29 additions & 1 deletion src/posix/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,35 @@ fn port_type(d: &libudev::Device) -> Result<SerialPortType> {
.ok(),
}))
}
Some("pci") => Ok(SerialPortType::PciPort),
Some("pci") => {
let usb_properties = vec![
d.property_value("ID_USB_VENDOR_ID"),
d.property_value("ID_USB_MODEL_ID"),
d.property_value("ID_USB_VENDOR"),
d.property_value("ID_USB_MODEL"),
d.property_value("ID_USB_SERIAL_SHORT"),
]
.into_iter()
.collect::<Option<Vec<_>>>();
if usb_properties.is_some() {
Ok(SerialPortType::UsbPort(UsbPortInfo {
vid: udev_hex_property_as_int(d, "ID_USB_VENDOR_ID", &u16::from_str_radix)?,
pid: udev_hex_property_as_int(d, "ID_USB_MODEL_ID", &u16::from_str_radix)?,
serial_number: udev_property_as_string(d, "ID_USB_SERIAL_SHORT"),
manufacturer: udev_property_as_string(d, "ID_USB_VENDOR"),
product: udev_property_as_string(d, "ID_USB_MODEL"),
#[cfg(feature = "usbportinfo-interface")]
interface: udev_hex_property_as_int(
d,
"ID_USB_INTERFACE_NUM",
&u8::from_str_radix,
)
.ok(),
}))
} else {
Ok(SerialPortType::PciPort)
}
}
_ => Ok(SerialPortType::Unknown),
}
}
Expand Down

0 comments on commit 9d95e5c

Please sign in to comment.