Skip to content

Commit

Permalink
Move Speed type to usb crate and distinguish SplitSpeed.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Sep 10, 2024
1 parent 965d041 commit f5f7fbb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
13 changes: 2 additions & 11 deletions src/backend/cynthion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use futures_channel::oneshot;
use futures_lite::future::block_on;
use futures_util::future::FusedFuture;
use futures_util::{select_biased, FutureExt};
use num_enum::{FromPrimitive, IntoPrimitive};
use nusb::{
self,
transfer::{
Expand All @@ -24,6 +23,8 @@ use nusb::{
Interface
};

use crate::usb::Speed;

const VID: u16 = 0x1d50;
const PID: u16 = 0x615b;

Expand All @@ -36,16 +37,6 @@ const ENDPOINT: u8 = 0x81;
const READ_LEN: usize = 0x4000;
const NUM_TRANSFERS: usize = 4;

#[derive(Copy, Clone, FromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum Speed {
#[default]
High = 0,
Full = 1,
Low = 2,
Auto = 3,
}

impl Speed {
pub fn description(&self) -> &'static str {
use Speed::*;
Expand Down
2 changes: 1 addition & 1 deletion src/test_cynthion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::backend::cynthion::{
CynthionDevice,
CynthionUsability,
CynthionHandle,
Speed
};
use crate::capture::{
create_capture,
Expand All @@ -14,6 +13,7 @@ use crate::capture::{
};
use crate::decoder::Decoder;
use crate::file::{GenericSaver, PcapSaver};
use crate::usb::Speed;

use anyhow::{Context, Error, ensure};
use futures_lite::future::block_on;
Expand Down
3 changes: 2 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use crate::backend::cynthion::{
CynthionHandle,
CynthionStop,
CynthionUsability::*,
Speed};
};

use crate::capture::{
create_capture,
Expand Down Expand Up @@ -92,6 +92,7 @@ use crate::row_data::{
ToGenericRowData,
TrafficRowData,
DeviceRowData};
use crate::usb::Speed;
use crate::util::{fmt_count, fmt_size};
use crate::version::{version, version_info};

Expand Down
16 changes: 13 additions & 3 deletions src/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ fn crc5(mut input: u32, num_bits: u32) -> u8 {
(state ^ 0x1f) as u8
}

#[derive(Copy, Clone, FromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum Speed {
#[default]
High = 0,
Full = 1,
Low = 2,
Auto = 3,
}

#[allow(clippy::upper_case_acronyms)]
#[derive(Copy, Clone, Debug, Default, IntoPrimitive, FromPrimitive, PartialEq, Eq)]
#[repr(u8)]
Expand Down Expand Up @@ -247,7 +257,7 @@ pub enum StartComplete {
}

#[derive(Copy, Clone, Debug)]
pub enum Speed {
pub enum SplitSpeed {
Low,
Full,
}
Expand Down Expand Up @@ -291,8 +301,8 @@ impl SplitFields {
[packet[1], packet[2], packet[3], 0]))
}

pub fn speed(&self) -> Speed {
use Speed::*;
pub fn speed(&self) -> SplitSpeed {
use SplitSpeed::*;
if self.endpoint_type() == EndpointType::Isochronous {
Full
} else if self.start() {
Expand Down

0 comments on commit f5f7fbb

Please sign in to comment.