Skip to content

Commit

Permalink
Merge pull request #9 from sjoerdsimons/more-debugging
Browse files Browse the repository at this point in the history
usb-pd: Derive Debug and Format where applicable
  • Loading branch information
fmckeogh committed May 4, 2024
2 parents a44209d + 8bdef93 commit 3b9b70e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions usb-pd/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use {
};

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Header(pub u16): FromRaw, IntoRaw {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct Header(pub u16): Debug, FromRaw, IntoRaw {
pub extended: bool @ 15,
pub num_objects: u8 [get usize] @ 12..=14,
pub message_id: u8 @ 9..=11,
Expand Down Expand Up @@ -38,7 +38,7 @@ impl Header {
}
}

#[derive(Format)]
#[derive(Debug, Format)]
pub enum SpecificationRevision {
R1_0,
R2_0,
Expand Down Expand Up @@ -66,13 +66,13 @@ impl From<SpecificationRevision> for u8 {
}
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Format)]
pub enum MessageType {
Control(ControlMessageType),
Data(DataMessageType),
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Format)]
pub enum ControlMessageType {
GoodCRC = 0b0_0001,
GotoMin = 0b0_0010,
Expand Down Expand Up @@ -133,7 +133,7 @@ impl From<u8> for ControlMessageType {
}
}

#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Format)]
pub enum DataMessageType {
SourceCapabilities = 0b0_0001,
Request = 0b0_0010,
Expand Down
4 changes: 2 additions & 2 deletions usb-pd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl core::ops::Not for CcPin {
}
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum PowerRole {
Source,
Sink,
Expand All @@ -48,7 +48,7 @@ impl From<PowerRole> for bool {
}
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum DataRole {
Ufp,
Dfp,
Expand Down
2 changes: 1 addition & 1 deletion usb-pd/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
heapless::Vec,
};

#[derive(Clone, Format)]
#[derive(Debug, Clone, Format)]
pub enum Message {
Accept,
Reject,
Expand Down
38 changes: 19 additions & 19 deletions usb-pd/src/pdo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
proc_bitfield::bitfield,
};

#[derive(Clone, Copy, Format)]
#[derive(Clone, Copy, Debug, Format)]
pub enum PowerDataObject {
FixedSupply(FixedSupply),
Battery(Battery),
Expand All @@ -14,14 +14,14 @@ pub enum PowerDataObject {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct PowerDataObjectRaw(pub u32): FromRaw, IntoRaw {
pub struct PowerDataObjectRaw(pub u32): Debug, FromRaw, IntoRaw {
pub kind: u8 @ 30..=31,
}
}

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct FixedSupply(pub u32): FromRaw, IntoRaw {
pub struct FixedSupply(pub u32): Debug, FromRaw, IntoRaw {
/// Fixed supply
pub kind: u8 @ 30..=31,
/// Dual-role power
Expand Down Expand Up @@ -49,7 +49,7 @@ bitfield! {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct Battery(pub u32): FromRaw, IntoRaw {
pub struct Battery(pub u32): Debug, FromRaw, IntoRaw {
/// Battery
pub kind: u8 @ 30..=31,
/// Maximum Voltage in 50mV units
Expand All @@ -63,7 +63,7 @@ bitfield! {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct VariableSupply(pub u32): FromRaw, IntoRaw {
pub struct VariableSupply(pub u32): Debug, FromRaw, IntoRaw {
/// Variable supply (non-battery)
pub kind: u8 @ 30..=31,
/// Maximum Voltage in 50mV units
Expand All @@ -75,15 +75,15 @@ bitfield! {
}
}

#[derive(Clone, Copy, Format)]
#[derive(Clone, Copy, Debug, Format)]
pub enum AugmentedPowerDataObject {
SPR(SPRProgrammablePowerSupply),
EPR(EPRAdjustableVoltageSupply),
}

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct AugmentedPowerDataObjectRaw(pub u32): FromRaw, IntoRaw {
pub struct AugmentedPowerDataObjectRaw(pub u32): Debug, FromRaw, IntoRaw {
/// Augmented power data object
pub kind: u8 @ 30..=31,
pub supply: u8 @ 28..=29,
Expand All @@ -93,7 +93,7 @@ bitfield! {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct SPRProgrammablePowerSupply(pub u32): FromRaw, IntoRaw {
pub struct SPRProgrammablePowerSupply(pub u32): Debug, FromRaw, IntoRaw {
/// Augmented power data object
pub kind: u8 @ 30..=31,
/// SPR programmable power supply
Expand All @@ -110,7 +110,7 @@ bitfield! {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct EPRAdjustableVoltageSupply(pub u32): FromRaw, IntoRaw {
pub struct EPRAdjustableVoltageSupply(pub u32): Debug, FromRaw, IntoRaw {
/// Augmented power data object
pub kind: u8 @ 30..=31,
/// EPR adjustable voltage supply
Expand All @@ -127,7 +127,7 @@ bitfield! {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct FixedVariableRequestDataObject(pub u32): FromRaw, IntoRaw {
pub struct FixedVariableRequestDataObject(pub u32): Debug, FromRaw, IntoRaw {
/// Valid range 1..=14
pub object_position: u8 @ 28..=31,
pub giveback_flag: bool @ 27,
Expand All @@ -147,7 +147,7 @@ impl FixedVariableRequestDataObject {
}
}

#[derive(Clone, Copy, Format)]
#[derive(Clone, Copy, Debug, Format)]
pub enum VDMCommandType {
InitiatorREQ,
ResponderACK,
Expand Down Expand Up @@ -179,7 +179,7 @@ impl From<u8> for VDMCommandType {
}
}

#[derive(Clone, Copy, Format)]
#[derive(Clone, Copy, Debug, Format)]
pub enum VDMCommand {
DiscoverIdentity,
DiscoverSVIDS,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl From<u8> for VDMCommand {
}
}

#[derive(Clone, Copy, Format)]
#[derive(Clone, Copy, Debug, Format)]
pub enum VDMType {
Unstructured,
Structured,
Expand All @@ -246,15 +246,15 @@ impl From<bool> for VDMType {
}
}

#[derive(Clone, Copy, Format)]
#[derive(Clone, Copy, Debug, Format)]
pub enum VDMHeader {
Structured(VDMHeaderStructured),
Unstructured(VDMHeaderUnstructured),
}

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct VDMHeaderRaw(pub u32): FromRaw, IntoRaw {
pub struct VDMHeaderRaw(pub u32): Debug, FromRaw, IntoRaw {
/// VDM Standard or Vendor ID
pub standard_or_vid: u16 @ 16..=31,
/// VDM Type (Unstructured/Structured)
Expand All @@ -270,7 +270,7 @@ impl VDMHeaderRaw {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct VDMHeaderStructured(pub u32): FromRaw, IntoRaw {
pub struct VDMHeaderStructured(pub u32): Debug, FromRaw, IntoRaw {
/// VDM Standard or Vendor ID
pub standard_or_vid: u16 @ 16..=31,
/// VDM Type (Unstructured/Structured)
Expand All @@ -294,7 +294,7 @@ impl VDMHeaderStructured {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct VDMHeaderUnstructured(pub u32): FromRaw, IntoRaw {
pub struct VDMHeaderUnstructured(pub u32): Debug, FromRaw, IntoRaw {
/// VDM Standard or Vendor ID
pub standard_or_vid: u16 @ 16..=31,
/// VDM Type (Unstructured/Structured)
Expand All @@ -312,7 +312,7 @@ impl VDMHeaderUnstructured {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct VDMIdentityHeader(pub u32): FromRaw, IntoRaw {
pub struct VDMIdentityHeader(pub u32): Debug, FromRaw, IntoRaw {
/// Host data capable
pub host_data: bool @ 31,
/// Device data capable
Expand All @@ -338,7 +338,7 @@ impl VDMIdentityHeader {

bitfield! {
#[derive(Clone, Copy, PartialEq, Eq, Format)]
pub struct DisplayPortCapabilities(pub u32): FromRaw, IntoRaw {
pub struct DisplayPortCapabilities(pub u32): Debug, FromRaw, IntoRaw {
/// UFP_D Pin Assignments Supported
pub ufp_d_pin_assignments: u8 @ 16..=23,
/// DFP_D Pin Assignments Supported
Expand Down

0 comments on commit 3b9b70e

Please sign in to comment.