Skip to content

Commit

Permalink
Merge pull request #13 from vitalyvb/usb-device-3
Browse files Browse the repository at this point in the history
Update to usb-device 0.3.1
  • Loading branch information
vitalyvb authored Jan 21, 2024
2 parents 6a7012b + 6e49bb1 commit 1190d72
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.4.0] - yyyy-mm-dd

### Breaking Changes
- `usb-device` dependency updated to 0.3.1. No API changes in `usbd-dfu`,
however, there may be type compatibility issues if anything else
depends on `usb-device` 0.2.x

### Changed
- Created CREDITS.md
- Updated README.md and copyright notice in LICENSE file
- Bump tests dependency stm32f1xx-hal to 0.10.0
- Remove dev-dependency on stm32f1xx-hal

## [0.3.1] - 2023-05-06

Expand Down Expand Up @@ -68,7 +75,8 @@ command ([#6](https://github.com/vitalyvb/usbd-dfu/pull/6))

First version.

[Unreleased]: https://github.com/vitalyvb/usbd-dfu/compare/v0.3.1...HEAD
[Unreleased]: https://github.com/vitalyvb/usbd-dfu/compare/v0.4.0...HEAD
[0.4.0]: https://github.com/vitalyvb/usbd-dfu/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/vitalyvb/usbd-dfu/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/vitalyvb/usbd-dfu/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/vitalyvb/usbd-dfu/compare/v0.1.1...v0.2.0
Expand Down
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "usbd-dfu"
description = "DFU protocol for a `usb-device` device."
version = "0.3.1"
version = "0.4.0"
authors = ["Vitalii Bursov <[email protected]>"]
edition = "2021"
readme = "README.md"
Expand All @@ -13,8 +13,4 @@ exclude = [
]

[dependencies.usb-device]
version = "0.2.9"

[dev-dependencies.stm32f1xx-hal]
version = "0.10.0"
features = ["rt", "stm32f103", "medium", "stm32-usbd"]
version = "0.3.1"
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ supporting DFU protocol, for example:

## License

This project is licensed under [MIT License](https://opensource.org/licenses/MIT) ([LICENSE](https://github.com/vitalyvb/usbd-dfu/blob/main/LICENSE)).
This project is licensed under [MIT License](https://opensource.org/licenses/MIT)
([LICENSE](https://github.com/vitalyvb/usbd-dfu/blob/main/LICENSE)).

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you shall be licensed as above,
without any additional terms or conditions.

## Example

Expand Down
8 changes: 3 additions & 5 deletions src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,8 @@ impl<B: UsbBus, M: DFUMemIO> UsbClass<B> for DFUClass<B, M> {
Ok(())
}

fn get_string(&self, index: StringIndex, lang_id: u16) -> Option<&str> {
if (lang_id == usb_device::descriptor::lang_id::ENGLISH_US || lang_id == 0)
&& (index == self.interface_string)
{
fn get_string(&self, index: StringIndex, lang_id: LangID) -> Option<&str> {
if index == self.interface_string && lang_id == LangID::EN_US {
return Some(M::MEM_INFO_STRING);
}
None
Expand Down Expand Up @@ -823,7 +821,7 @@ impl<B: UsbBus, M: DFUMemIO> DFUClass<B, M> {
} else {
self.status.new_state_ok(DFUState::DfuUploadIdle);
}
xfer.accept_with(&b).ok();
xfer.accept_with(b).ok();
return;
}
Err(e) => {
Expand Down
30 changes: 27 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
//! * [dfu-util](http://dfu-util.sourceforge.net/)
//! * others
//!
//! ## License
//!
//! This project is licensed under [MIT License](https://opensource.org/licenses/MIT)
//! ([LICENSE](https://github.com/vitalyvb/usbd-dfu/blob/main/LICENSE)).
//!
//! ### Contribution
//!
//! Unless you explicitly state otherwise, any contribution intentionally
//! submitted for inclusion in the work by you shall be licensed as above,
//! without any additional terms or conditions.
//!
//! ## Example
//!
Expand All @@ -66,11 +76,25 @@
//! use usb_device::prelude::*;
//! use usbd_dfu::*;
//! #
//! # use usb_device::prelude::*;
//! # use usb_device::bus::UsbBusAllocator;
//! # use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType};
//! #
//! # let usb_bus_alloc: UsbBusAllocator<UsbBus<Peripheral>> = unsafe { core::mem::MaybeUninit::<UsbBusAllocator<UsbBus<Peripheral>>>::uninit().assume_init() };
//! # pub struct DummyUsbBus { }
//! # impl usb_device::bus::UsbBus for DummyUsbBus {
//! # fn alloc_ep(&mut self, _: usb_device::UsbDirection, _: Option<usb_device::endpoint::EndpointAddress>,
//! # _: usb_device::endpoint::EndpointType, _: u16, _: u8) -> usb_device::Result<usb_device::endpoint::EndpointAddress> { todo!() }
//! # fn enable(&mut self) { todo!() }
//! # fn reset(&self) { todo!() }
//! # fn set_device_address(&self, _: u8) { todo!() }
//! # fn write(&self, _: usb_device::endpoint::EndpointAddress, _: &[u8]) -> usb_device::Result<usize> { todo!() }
//! # fn read(&self, _: usb_device::endpoint::EndpointAddress, _: &mut [u8]) -> usb_device::Result<usize> { todo!() }
//! # fn set_stalled(&self, _: usb_device::endpoint::EndpointAddress, _: bool) { todo!() }
//! # fn is_stalled(&self, _: usb_device::endpoint::EndpointAddress) -> bool { todo!() }
//! # fn suspend(&self) { todo!() }
//! # fn resume(&self) { todo!() }
//! # fn poll(&self) -> usb_device::bus::PollResult { todo!() }
//! # }
//! #
//! # let usb_bus_alloc: UsbBusAllocator<DummyUsbBus> = unsafe { core::mem::MaybeUninit::<UsbBusAllocator<DummyUsbBus>>::uninit().assume_init() };
//! # let mut usb_dev = UsbDeviceBuilder::new(&usb_bus_alloc, UsbVidPid(0, 0)).build();
//!
//! // DFUClass will use MyMem to actually read, erase or program the memory.
Expand Down
7 changes: 6 additions & 1 deletion tests/dfu_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,13 @@ fn test_get_configuration() {
]
);

// get string descriptor languages
len = transact(&mut dfu, &[0x80, 0x6, 0, 3, 0, 0, 0x80, 0], None, &mut buf).expect("len");
assert_eq!(len, 4);
assert_eq!(&buf[0..4], &[len as u8, 3u8, 9, 4]); // 0x409 = EN_US

// get string descriptor
len = transact(&mut dfu, &[0x80, 0x6, 4, 3, 0, 0, 0x80, 0], None, &mut buf).expect("len");
len = transact(&mut dfu, &[0x80, 0x6, 4, 3, 9, 4, 0x80, 0], None, &mut buf).expect("len");
assert_eq!(len, 2 + TestMem::MEM_INFO_STRING.len() * 2);
assert_eq!(&buf[0..2], &[len as u8, 3u8]);
let u16v: Vec<_> = buf[2..len]
Expand Down
10 changes: 7 additions & 3 deletions tests/mockusb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,17 @@ pub fn with_usb<T, M>(
let mut cls = maker.create(&alloc);

let mut usb_dev = UsbDeviceBuilder::new(&alloc, UsbVidPid(0x1234, 0x1234))
.manufacturer("Test")
.product("Test")
.serial_number("Test")
.strings(&[StringDescriptors::default()
.manufacturer("Test")
.product("Test")
.serial_number("Test")])
.unwrap()
.device_release(0x0200)
.self_powered(false)
.max_power(250)
.unwrap()
.max_packet_size_0(EP0_SIZE)
.unwrap()
.build();

usb_dev.poll(&mut [&mut cls]);
Expand Down

0 comments on commit 1190d72

Please sign in to comment.