Skip to content

Commit

Permalink
Merge pull request #152 from sourcebox/dummy-bus
Browse files Browse the repository at this point in the history
Add a dummy usb bus implementation
  • Loading branch information
ryan-summers committed Jul 2, 2024
2 parents d824fea + e94f73c commit 87c9626
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,48 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

* `DummyUsbBus` without functionality to allow examples that actually compile (but not run).

### Changed

* [breaking] The control pipe is now provided in the `UsbDeviceBuilder` API to allow for user-provided control
pipes. This makes it so that control pipes have configurable sizing.

## [0.3.2] - 2024-03-06

### Added

* A new `log` feature can be enabled to provide logging and tracing information about the USB
interface.

### Changed

* [breaking] LangIDs no longer implement `TryFromPrimitive`. The minor version has not been bumped
as this was not intended to be used in the public API.
- If this is problematic, please open an issue in the main `usb-device` repository.
* If this is problematic, please open an issue in the main `usb-device` repository.
* Changed handling of EP0 state to eliminate unexpected issues with device enumeration

## [0.3.1] - 2023-11-15

### Added

* `BuilderError`, `LangID`, `StringDescriptors` now in `prelude`
* `LangID` now in `class_prelude`

### Changed

* Updated documentation, including example code

## [0.3.0] - 2023-11-13

### Fixed

* Fixed a defect where enumeration may fail due to timing-related issues ([#128](https://github.com/rust-embedded-community/usb-device/issues/128))

### Added

* New enums and allocators for Isochronous endpoints ([#60](https://github.com/rust-embedded-community/usb-device/pull/60)).
* Ability to select USB revision ([#116](https://github.com/rust-embedded-community/usb-device/pull/116)).
* Added support for alternate settings on interfaces ([#114](https://github.com/rust-embedded-community/usb-device/pull/114)).
Expand All @@ -46,22 +57,26 @@ as this was not intended to be used in the public API.
* `UsbDeviceBuilder` has a public `.extra_lang_ids()` method to specify LANGIDs besides ENGLISH_US(0x0409)

### Breaking

* Acess numeric form of `EndpointType` variants now require a `.to_bm_attributes()`. ([#60](https://github.com/rust-embedded-community/usb-device/pull/60))
* `DescriptorWriter::iad()` now requires a `Option<StringIndex>` to optionally specify a string for describing the function ([#121](https://github.com/rust-embedded-community/usb-device/pull/121))
* `.manufacturer()`, `.product()` and `.serial_number()` of `UsbDeviceBuilder` are now replaced with the `strings()` function that accepts a `StringDescriptor` list to allow multilanguage support ([#122](https://github.com/rust-embedded-community/usb-device/pull/122))
* Various methods of the `UsbDeviceBuilder` now return `Result<>` types instead of internally panicking.

### Changed

* `EndpointType` enum now has fields for isochronous synchronization and usage ([#60](https://github.com/rust-embedded-community/usb-device/pull/60)).
* `descriptor_type::STRING` of `fn get_descriptor()` will send the LANGIDs supported by device, and respond STRING Request with specified LANGID. ([#122](https://github.com/rust-embedded-community/usb-device/pull/122))
* `UsbError` is now copyable and comparable ([#127](https://github.com/rust-embedded-community/usb-device/pull/127))

## [0.2.9] - 2022-08-02

### Added

* Optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76)).

### Fixed

* Fixed an issue where USB devices were not enumerating on Windows ([#32](https://github.com/rust-embedded-community/usb-device/issues/82))
* Fixed Suspend state transition so it goes back to the previous state, not just Default ([#97](https://github.com/rust-embedded-community/usb-device/pull/97))

Expand Down
86 changes: 86 additions & 0 deletions src/dummy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#![allow(unused_variables)]

use crate::bus::UsbBus;

/// Dummy bus implementation with no functionality.
///
/// Examples can create an instance of this bus just to make them compile.
pub struct DummyUsbBus;

impl DummyUsbBus {
/// Creates a new `DummyUsbBus`.
pub fn new() -> Self {
Self
}
}

impl Default for DummyUsbBus {
fn default() -> Self {
Self::new()
}
}

impl UsbBus for DummyUsbBus {
fn alloc_ep(
&mut self,
ep_dir: crate::UsbDirection,
ep_addr: Option<crate::class_prelude::EndpointAddress>,
ep_type: crate::class_prelude::EndpointType,
max_packet_size: u16,
interval: u8,
) -> crate::Result<crate::class_prelude::EndpointAddress> {
unimplemented!()
}

fn enable(&mut self) {
unimplemented!()
}

fn force_reset(&self) -> crate::Result<()> {
unimplemented!()
}

fn is_stalled(&self, ep_addr: crate::class_prelude::EndpointAddress) -> bool {
unimplemented!()
}

fn poll(&self) -> crate::bus::PollResult {
unimplemented!()
}

fn read(
&self,
ep_addr: crate::class_prelude::EndpointAddress,
buf: &mut [u8],
) -> crate::Result<usize> {
unimplemented!()
}

fn reset(&self) {
unimplemented!()
}

fn resume(&self) {
unimplemented!()
}

fn set_device_address(&self, addr: u8) {
unimplemented!()
}

fn set_stalled(&self, ep_addr: crate::class_prelude::EndpointAddress, stalled: bool) {
unimplemented!()
}

fn suspend(&self) {
unimplemented!()
}

fn write(
&self,
ep_addr: crate::class_prelude::EndpointAddress,
buf: &[u8],
) -> crate::Result<usize> {
unimplemented!()
}
}
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ pub use descriptor::lang_id::LangID;
/// driver to be tested with the test_class_host example in this crate.
pub mod test_class;

/// Dummy bus with no functionality.
///
/// Examples can create an instance of this bus so they can be compile-checked.
/// Note that the lack of functionality does not allow to run the examples.
///
/// ```
/// use usb_device::dummy_bus::DummyUsbBus;
/// use usb_device::class_prelude::UsbBusAllocator;
///
/// let usb_bus = UsbBusAllocator::new(DummyUsbBus::new());
/// ```
pub mod dummy;

mod control_pipe;

mod device_builder;
Expand Down

0 comments on commit 87c9626

Please sign in to comment.