Skip to content

Commit f39533f

Browse files
committed
Add a dummy usb bus implementation
1 parent d824fea commit f39533f

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,48 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
* `DummyUsbBus` without functionality to allow examples that actually compile (but not run).
13+
1014
### Changed
15+
1116
* [breaking] The control pipe is now provided in the `UsbDeviceBuilder` API to allow for user-provided control
1217
pipes. This makes it so that control pipes have configurable sizing.
1318

1419
## [0.3.2] - 2024-03-06
1520

1621
### Added
22+
1723
* A new `log` feature can be enabled to provide logging and tracing information about the USB
1824
interface.
1925

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

2633
## [0.3.1] - 2023-11-15
2734

2835
### Added
36+
2937
* `BuilderError`, `LangID`, `StringDescriptors` now in `prelude`
3038
* `LangID` now in `class_prelude`
3139

3240
### Changed
41+
3342
* Updated documentation, including example code
3443

3544
## [0.3.0] - 2023-11-13
3645

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

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

4859
### Breaking
60+
4961
* Acess numeric form of `EndpointType` variants now require a `.to_bm_attributes()`. ([#60](https://github.com/rust-embedded-community/usb-device/pull/60))
5062
* `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))
5163
* `.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))
5264
* Various methods of the `UsbDeviceBuilder` now return `Result<>` types instead of internally panicking.
5365

5466
### Changed
67+
5568
* `EndpointType` enum now has fields for isochronous synchronization and usage ([#60](https://github.com/rust-embedded-community/usb-device/pull/60)).
5669
* `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))
5770
* `UsbError` is now copyable and comparable ([#127](https://github.com/rust-embedded-community/usb-device/pull/127))
5871

5972
## [0.2.9] - 2022-08-02
6073

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

6478
### Fixed
79+
6580
* Fixed an issue where USB devices were not enumerating on Windows ([#32](https://github.com/rust-embedded-community/usb-device/issues/82))
6681
* 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))
6782

src/dummy_bus.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#![allow(unused_variables)]
2+
3+
use crate::bus::UsbBus;
4+
5+
/// Dummy bus implementation with no functionality.
6+
///
7+
/// Examples can create an instance of this bus just to make them compile.
8+
pub struct DummyUsbBus;
9+
10+
impl DummyUsbBus {
11+
/// Creates a new `DummyUsbBus`.
12+
pub fn new() -> Self {
13+
Self
14+
}
15+
}
16+
17+
impl Default for DummyUsbBus {
18+
fn default() -> Self {
19+
Self::new()
20+
}
21+
}
22+
23+
impl UsbBus for DummyUsbBus {
24+
fn alloc_ep(
25+
&mut self,
26+
ep_dir: crate::UsbDirection,
27+
ep_addr: Option<crate::class_prelude::EndpointAddress>,
28+
ep_type: crate::class_prelude::EndpointType,
29+
max_packet_size: u16,
30+
interval: u8,
31+
) -> crate::Result<crate::class_prelude::EndpointAddress> {
32+
unimplemented!()
33+
}
34+
35+
fn enable(&mut self) {
36+
unimplemented!()
37+
}
38+
39+
fn force_reset(&self) -> crate::Result<()> {
40+
unimplemented!()
41+
}
42+
43+
fn is_stalled(&self, ep_addr: crate::class_prelude::EndpointAddress) -> bool {
44+
unimplemented!()
45+
}
46+
47+
fn poll(&self) -> crate::bus::PollResult {
48+
unimplemented!()
49+
}
50+
51+
fn read(
52+
&self,
53+
ep_addr: crate::class_prelude::EndpointAddress,
54+
buf: &mut [u8],
55+
) -> crate::Result<usize> {
56+
unimplemented!()
57+
}
58+
59+
fn reset(&self) {
60+
unimplemented!()
61+
}
62+
63+
fn resume(&self) {
64+
unimplemented!()
65+
}
66+
67+
fn set_device_address(&self, addr: u8) {
68+
unimplemented!()
69+
}
70+
71+
fn set_stalled(&self, ep_addr: crate::class_prelude::EndpointAddress, stalled: bool) {
72+
unimplemented!()
73+
}
74+
75+
fn suspend(&self) {
76+
unimplemented!()
77+
}
78+
79+
fn write(
80+
&self,
81+
ep_addr: crate::class_prelude::EndpointAddress,
82+
buf: &[u8],
83+
) -> crate::Result<usize> {
84+
unimplemented!()
85+
}
86+
}

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ pub use descriptor::lang_id::LangID;
184184
/// driver to be tested with the test_class_host example in this crate.
185185
pub mod test_class;
186186

187+
/// Dummy bus with no functionality.
188+
///
189+
/// Examples can create an instance of this bus so they can be compile-checked.
190+
/// Note that the lack of functionality does not allow to run the examples.
191+
///
192+
/// ```
193+
/// use usb_device::dummy_bus::DummyUsbBus;
194+
/// use usb_device::class_prelude::UsbBusAllocator;
195+
///
196+
/// let usb_bus = UsbBusAllocator::new(DummyUsbBus::new());
197+
/// ```
198+
pub mod dummy_bus;
199+
187200
mod control_pipe;
188201

189202
mod device_builder;

0 commit comments

Comments
 (0)