Skip to main content

Crate usb_pd_profiles

Crate usb_pd_profiles 

Source
Expand description

Compute USB Power Delivery profiles and the wattage a device actually receives.

A charger’s advertised wattage is a ceiling, not a promise. Three independent limits sit between the wall and the battery — the source profile set, the cable current rating, and the device’s own maximum — and the smallest one wins.

§Example

use usb_pd_profiles::{negotiate, split_budget};

// 65W charger, 30W phone, plain 3A cable — the phone is the limit
let r = negotiate(65.0, 30.0, 3.0);
assert_eq!(r.limited_by, "device");

// Same charger, a 65W laptop, still a 3A cable — now the cable is the limit,
// because 3A tops out at 60W (20V x 3A) and 5A e-marking is required above that
assert_eq!(negotiate(65.0, 65.0, 3.0).limited_by, "cable");
assert_eq!(negotiate(65.0, 65.0, 5.0).limited_by, "device");

// One 65W budget shared by a laptop and a phone
assert_eq!(split_budget(65.0, &[65.0, 20.0]), vec![65.0, 0.0]);

§Why the numbers differ from the box

  • Cable e-marker — a plain USB-C cable is rated 3A, capping the link at 60W regardless of what charger and device negotiated. Above 60W a 5A e-marked cable is required, and nothing on the jacket tells you which one you are holding.
  • Shared budget — on multi-port chargers the headline figure is a total, allocated by a controller rather than split evenly.
  • Device ceiling — a phone that tops out at 20W requests that profile and ignores the rest, so a higher-rated charger buys it nothing.

Structs§

Outcome
Result of a negotiation, including which component limited the outcome.
Profile
A single negotiated power profile.

Constants§

DEFAULT_CABLE_AMPS
Current ceiling (amps) for a cable without an e-marker chip.
EMARKED_CABLE_AMPS
Current ceiling (amps) for a 5A e-marked cable.
PD_VOLTAGES
Fixed supply voltages defined by the USB Power Delivery specification.
SPR_MAX_VOLTS
Highest voltage available in Standard Power Range (SPR).

Functions§

negotiate
Resolve delivered wattage and identify the limiting component.
profiles_over_cable
Profiles actually reachable through a given cable.
source_profiles
Fixed PD profiles a source of the given rating can advertise.
split_budget
Allocate a shared multi-port budget, highest demand claiming first.