Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ fn main() -> Result<()> {
);

// Set up the device
let mut rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
let rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
Ok(c) => c,
Err(e) => bail!("Couldn't set up device: {}", e.to_string()),
};
let mut qdl_dev = QdlDevice {
rw: rw_channel.as_mut(),
rw: rw_channel,
fh_cfg: FirehoseConfiguration {
hash_packets: args.hash_packets,
read_back_verify: args.read_back_verify,
Expand Down
29 changes: 22 additions & 7 deletions qdl/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,30 @@ pub trait QdlChan: Read + Write {
}

pub trait QdlReadWrite: Read + Write + Send + Sync {}
impl<T> QdlReadWrite for &mut T where T: QdlReadWrite {}
impl<T> QdlReadWrite for &mut T where T: QdlReadWrite + ?Sized {}

pub struct QdlDevice<'a> {
pub rw: &'a mut dyn QdlReadWrite,
pub struct QdlDevice<T>
where
T: QdlReadWrite + ?Sized,
{
pub rw: Box<T>,
pub fh_cfg: FirehoseConfiguration,
pub reset_on_drop: bool,
}

impl Read for QdlDevice<'_> {
impl<T> Read for QdlDevice<T>
where
T: QdlReadWrite + ?Sized,
{
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
self.rw.read(buf)
}
}

impl Write for QdlDevice<'_> {
impl<T> Write for QdlDevice<T>
where
T: QdlReadWrite + ?Sized,
{
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.rw.write(buf)
}
Expand All @@ -118,7 +127,10 @@ impl Write for QdlDevice<'_> {
}
}

impl QdlChan for QdlDevice<'_> {
impl<T> QdlChan for QdlDevice<T>
where
T: QdlReadWrite + ?Sized,
{
fn fh_config(&self) -> &FirehoseConfiguration {
&self.fh_cfg
}
Expand All @@ -128,7 +140,10 @@ impl QdlChan for QdlDevice<'_> {
}
}

impl Drop for QdlDevice<'_> {
impl<T> Drop for QdlDevice<T>
where
T: QdlReadWrite + ?Sized,
{
fn drop(&mut self) {
// Avoid having the board be stuck in EDL limbo in case of errors
// TODO: watch 'rawmode' and adjust accordingly
Expand Down
4 changes: 2 additions & 2 deletions qramdump/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ pub fn main() -> Result<()> {
None => QdlBackend::default(),
};

let mut rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
let rw_channel = match setup_target_device(backend, args.serial_no, args.dev_path) {
Ok(c) => c,
Err(e) => bail!("Couldn't set up device: {}", e.to_string()),
};

let mut qdl_dev = QdlDevice {
rw: rw_channel.as_mut(),
rw: rw_channel,
fh_cfg: FirehoseConfiguration::default(),
reset_on_drop: false,
};
Expand Down
Loading