usb_pd/
callback.rs

1use {crate::pdo::PowerDataObject, defmt::Format, heapless::Vec};
2
3/// Type of the user's callback function
4pub type CallbackFn = &'static dyn Fn(Event) -> Option<Response>;
5
6/// Callback event types
7#[derive(Format)]
8pub enum Event {
9    /// Power delivery protocol has changed
10    ProtocolChanged,
11    /// Source capabilities have changed (immediately request power)
12    SourceCapabilitiesChanged(Vec<PowerDataObject, 8>),
13    /// Requested power has been accepted (but not ready yet)
14    PowerAccepted,
15    /// Requested power has been rejected
16    PowerRejected,
17    /// Requested power is now ready
18    PowerReady,
19}
20
21#[derive(Format)]
22pub enum Protocol {
23    /// No USB-PD communication, USB 2.0 5V only
24    _20,
25    /// USB-PD communication
26    PD,
27}
28
29#[derive(Format)]
30pub enum Response {
31    RequestPower {
32        /// Index of the desired PowerDataObject
33        index: usize,
34        current: u16,
35    },
36}