Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyvb committed Apr 12, 2024
1 parent 37dfa74 commit 1d7c5f1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.0] - 2024-04-12

### Added
- Endpoint allocation support in EmulatedUsbBus
- Polling of all endpoints in EmulatedUsbBus
- Transfers for endpoints other than EP0
- Support of UsbClass implementations with a lifetime parameter

### Changed
- with_usb() function moved into UsbDeviceCtx trait
- Arguments and/or return type of some read/write functions

## [0.1.0] - 2024-04-06

First version.

[Unreleased]: https://github.com/vitalyvb/usbd-class-tester/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/vitalyvb/usbd-class-tester/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/vitalyvb/usbd-class-tester/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/vitalyvb/usbd-class-tester/releases/tag/v0.1.0
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ was done via plain `u8` arrays only.
### Supported operations

* IN and OUT EP0 control transfers
* Transfers on other endpoints (e.g. Interrupt)

### Not supported operations

Almost everything else, including but not limited to:

* Endpoints other than EP0 in `EmulatedUsbBus::poll()`
* Endpoint allocation in `EmulatedUsbBus::alloc_ep()`
* Reset
* Suspend and Resume
* Interrupt transfers
* Bulk transfers
* Iso transfers
* ...
Expand Down Expand Up @@ -77,7 +75,8 @@ impl<B: UsbBus> UsbClass<B> for TestUsbClass {}

// Context to create a testable instance of `TestUsbClass`
struct TestCtx {}
impl UsbDeviceCtx<EmulatedUsbBus, TestUsbClass> for TestCtx {
impl UsbDeviceCtx for TestCtx {
type C<'c> = TestUsbClass;
fn create_class<'a>(
&mut self,
alloc: &'a UsbBusAllocator<EmulatedUsbBus>,
Expand All @@ -88,11 +87,12 @@ impl UsbDeviceCtx<EmulatedUsbBus, TestUsbClass> for TestCtx {

#[test]
fn test_interface_get_status() {
with_usb(TestCtx {}, |mut cls, mut dev| {
let st = dev.interface_get_status(&mut cls, 0).expect("status");
assert_eq!(st, 0);
})
.expect("with_usb");
TestCtx {}
.with_usb(|mut cls, mut dev| {
let st = dev.interface_get_status(&mut cls, 0).expect("status");
assert_eq!(st, 0);
})
.expect("with_usb");
}
```

26 changes: 21 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::test_attr_in_doctest)]
#![warn(missing_docs)]
//!
//! A library for running tests of `usb-device` classes on
//! developer's system natively.
Expand Down Expand Up @@ -87,11 +88,12 @@
//!
//! #[test]
//! fn test_interface_get_status() {
//! with_usb(TestCtx {}, |mut cls, mut dev| {
//! let st = dev.interface_get_status(&mut cls, 0).expect("status");
//! assert_eq!(st, 0);
//! })
//! .expect("with_usb");
//! TestCtx {}
//! .with_usb(|mut cls, mut dev| {
//! let st = dev.interface_get_status(&mut cls, 0).expect("status");
//! assert_eq!(st, 0);
//! })
//! .expect("with_usb");
//! }
//! ```
//!
Expand All @@ -113,6 +115,7 @@ use bus::*;
mod usbdata;
use usbdata::*;

/// Prelude
pub mod prelude {
pub use crate::bus::EmulatedUsbBus;
pub use crate::usbdata::{CtrRequestType, SetupPacket};
Expand Down Expand Up @@ -186,9 +189,15 @@ pub enum AnyUsbError {
UserDefinedString(String),
}

/// Holds results for endpoint read/write operations
#[derive(Debug, Default)]
pub struct RWRes {
/// If there was a read operation returns number of data bytes
/// that were read.
pub read: Option<usize>,
/// If there was a write operation returns number of data bytes
/// that were written.
/// Setup packet is not included.
pub wrote: Option<usize>,
}

Expand All @@ -198,6 +207,7 @@ impl RWRes {
}
}

/// Result for crate operations.
pub type AnyResult<T> = core::result::Result<T, AnyUsbError>;

/// A context for the test, provides some
Expand Down Expand Up @@ -424,6 +434,9 @@ where
self.ep_raw(d, 0, Some(&setup_bytes), data, out)
}

/// Perform Endpoint Device-to-host data transfer
/// on a given endpoint index `ep_index` of a
/// maximum size `length`.
pub fn ep_read(
&mut self,
cls: &mut C,
Expand All @@ -442,6 +455,9 @@ where
}
}

/// Perform Endpoint Host-to-device data transfer
/// on a given endpoint index `ep_index` and
/// with `data`.
pub fn ep_write(
&mut self,
cls: &mut C,
Expand Down
1 change: 1 addition & 0 deletions src/usbdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub struct SetupPacket {
}

impl SetupPacket {
/// Create new SetupPacket
pub fn new(reqt: CtrRequestType, req: u8, value: u16, index: u16, length: u16) -> Self {
SetupPacket {
bm_request_type: reqt,
Expand Down

0 comments on commit 1d7c5f1

Please sign in to comment.