Skip to content

Commit

Permalink
Move vdo.rs, pdo.rs to messages/, move message.rs messages/mod.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwire authored and fmckeogh committed May 6, 2024
1 parent 17dac32 commit 0cb5821
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
9 changes: 6 additions & 3 deletions fusb302b/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use {
crate::{
registers::{
Control1, Control3, Mask1, MaskA, MaskB, Power, Register, Registers, Reset, Slice,
Switches0, Switches1,
Control0, Control1, Control3, Mask1, MaskA, MaskB, Power, Register, Registers, Reset,
Slice, Switches0, Switches1,
},
timeout::Timeout,
},
Expand All @@ -13,7 +13,7 @@ use {
embedded_hal_async::i2c::I2c,
usb_pd::{
header::{ControlMessageType, Header, MessageType},
message::Message,
messages::Message,
sink::{Driver as SinkDriver, DriverState},
token::Token,
CcPin,
Expand Down Expand Up @@ -126,6 +126,9 @@ impl<I2C: I2c> SinkDriver for Fusb302b<I2C> {
.set_mask_b(MaskB::default().with_m_gcrcsent(true))
.await;

self.registers
.set_control0(Control0::default().with_int_mask(false).with_host_cur(01))
.await;
self.state = State::Measuring { cc_pin: CcPin::CC1 };
self.message = None;
self.did_change_protocol = false;
Expand Down
4 changes: 1 addition & 3 deletions usb-pd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#![no_std]

pub mod header;
pub mod message;
pub mod pdo;
pub mod messages;
pub mod sink;
pub mod source;
pub mod token;
pub mod vdo;

#[derive(Clone, Copy, PartialEq, Eq)]
pub enum CcPin {
Expand Down
19 changes: 10 additions & 9 deletions usb-pd/src/message.rs → usb-pd/src/messages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
pub mod pdo;
pub mod vdo;

use {
crate::{
header::{ControlMessageType, DataMessageType, Header, MessageType},
pdo::{
AugmentedPowerDataObject, AugmentedPowerDataObjectRaw, Battery,
EPRAdjustableVoltageSupply, FixedSupply, PowerDataObject, PowerDataObjectRaw,
SPRProgrammablePowerSupply, VariableSupply,
},
vdo::{VDMHeader, VDMHeaderRaw, VDMHeaderStructured, VDMHeaderUnstructured, VDMType},
},
crate::header::{ControlMessageType, DataMessageType, Header, MessageType},
byteorder::{ByteOrder, LittleEndian},
defmt::{trace, warn, Format},
heapless::Vec,
pdo::{
AugmentedPowerDataObject, AugmentedPowerDataObjectRaw, Battery, EPRAdjustableVoltageSupply,
FixedSupply, PowerDataObject, PowerDataObjectRaw, SPRProgrammablePowerSupply,
VariableSupply,
},
vdo::{VDMHeader, VDMHeaderRaw, VDMHeaderStructured, VDMHeaderUnstructured, VDMType},
};

#[derive(Debug, Clone, Format)]
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions usb-pd/src/vdo.rs → usb-pd/src/messages/vdo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ impl VDMHeaderStructured {
}
}

impl Default for VDMHeaderStructured {
fn default() -> Self {
VDMHeaderStructured(0).with_vdm_type(VDMType::Structured)
}
}

#[derive(Clone, Copy, Format)]
pub enum VDMVersionMajor {
Version10,
Expand Down
14 changes: 8 additions & 6 deletions usb-pd/src/sink.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use {
crate::{
header::{DataMessageType, Header, SpecificationRevision},
message::Message,
pdo::{FixedVariableRequestDataObject, PowerDataObject},
vdo::{
CertStatVDO, ProductVDO, UFPTypeVDO, VDMCommand, VDMCommandType, VDMHeader,
VDMHeaderStructured, VDMIdentityHeader, VDMType, VDMVersionMajor, VDMVersionMinor,
messages::{
pdo::{FixedVariableRequestDataObject, PowerDataObject},
vdo::{
CertStatVDO, ProductVDO, UFPTypeVDO, VDMCommand, VDMCommandType, VDMHeader,
VDMHeaderStructured, VDMIdentityHeader, VDMType, VDMVersionMajor, VDMVersionMinor,
},
Message,
},
DataRole, PowerRole,
},
Expand Down Expand Up @@ -164,7 +166,7 @@ impl<DRIVER: Driver> Sink<DRIVER> {
.with_command_type(VDMCommandType::ResponderACK)
.with_object_position(0) // 0 Must be used for descover identity
.with_standard_or_vid(0xff00) // PD SID must be used with descover identity
.with_vdm_type(VDMType::Structured)
//.with_vdm_type(VDMType::Structured)
.with_vdm_version_major(VDMVersionMajor::Version2x.into())
.with_vdm_version_minor(VDMVersionMinor::Version20.into()),
);
Expand Down

0 comments on commit 0cb5821

Please sign in to comment.