Skip to content

Conversation

@dingari
Copy link

@dingari dingari commented Dec 5, 2025

This is required on (at least) macOS, as the usb_reset method will fail while there are interfaces claimed.

This should fix #6

Relies on dfu-rs/dfu-core#31

@cecton
Copy link
Member

cecton commented Dec 9, 2025

@sjoerdsimons is this PR okay for you?

Notable changes:

  • added nix files (useful for some, doesn't hurt)
  • adapted the code to drop the interface after the usb_reset()

@sjoerdsimons
Copy link
Collaborator

I'd rather not include the nix files; I don't use nix, so that'll just go unmaintained.. I don't think crates should have distro specific configuration in them as that's a very slippery slope.

As it stands this commit still makes dfu-nusb use a forked dfu-core, so that should be dropped before merging. Also should do a semver bump as the api is changed.

The code i'd need to further review (as always end of the year is hectic, so i'm slow).. But from a quick look the change to the usb_reset signature seems awkward, simply taking self would end up a lot more elegant (and a much smaller delta).

@sjoerdsimons
Copy link
Collaborator

@cecton btw just quickly looking at dfu-core ; looks like 0.9.2 is a semver break (changing the type of arguments); That should have been 0.10 instead

@dingari
Copy link
Author

dingari commented Dec 9, 2025

Totally understand wrt to the nix devshell. I always meant to remove them before PR-ing. I'll fixup the commit and re-push.

As it stands this commit still makes dfu-nusb use a forked dfu-core, so that should be dropped before merging.

Oh, yeah! Totally. I'll wait for a new dfu-core semver bump and fix that.

Also should do a semver bump as the api is changed.

I figured a maintainer would do that before issuing a new release?

@dingari
Copy link
Author

dingari commented Dec 9, 2025

But from a quick look the change to the usb_reset signature seems awkward, simply taking self would end up a lot more elegant (and a much smaller delta).

Sure, I'll be happy to make that change to dfu-core (consuming self), and updating this PR to reflect that.

@dingari
Copy link
Author

dingari commented Dec 10, 2025

@sjoerdsimons making usb_reset consume self just shifts the partial-move into the DfuASync / DfuSync impls. As download calls usb_reset.

error[E0507]: cannot move out of `self.io` which is behind a mutable reference
   --> /Users/genki/development/dfu-core/src/asynchronous.rs:239:21
    |
239 |                     self.io.usb_reset().await?;
    |                     ^^^^^^^ ----------- `self.io` moved due to this method call
    |                     |
    |                     move occurs because `self.io` has type `IO`, which does not implement the `Copy` trait
    |
note: `DfuAsyncIo::usb_reset` takes ownership of the receiver `self`, which moves `self.io`
   --> /Users/genki/development/dfu-core/src/asynchronous.rs:40:18
    |
40  |     fn usb_reset(self) -> impl Future<Output = Result<Self::Reset, Self::Error>> + Send;
    |                  ^^^^
help: if `IO` implemented `Clone`, you could clone the value
   --> /Users/genki/development/dfu-core/src/asynchronous.rs:157:6
    |
157 | impl<IO, E> DfuASync<IO, E>
    |      ^^ consider constraining this type parameter with `Clone`
...
239 |                     self.io.usb_reset().await?;
    |                     ------- you could clone this value

error[E0507]: cannot move out of `self.io` which is behind a mutable reference
   --> /Users/genki/development/dfu-core/src/sync.rs:173:21
    |
173 |                     self.io.usb_reset()?;
    |                     ^^^^^^^ ----------- `self.io` moved due to this method call
    |                     |
    |                     move occurs because `self.io` has type `IO`, which does not implement the `Copy` trait
    |
note: `DfuIo::usb_reset` takes ownership of the receiver `self`, which moves `self.io`
   --> /Users/genki/development/dfu-core/src/lib.rs:107:18
    |
107 |     fn usb_reset(self) -> Result<Self::Reset, Self::Error>;
    |                  ^^^^
help: if `IO` implemented `Clone`, you could clone the value
   --> /Users/genki/development/dfu-core/src/sync.rs:95:6
    |
95  | impl<IO, E> DfuSync<IO, E>
    |      ^^ consider constraining this type parameter with `Clone`
...
173 |                     self.io.usb_reset()?;
    |                     ------- you could clone this value

For more information about this error, try `rustc --explain E0507`.
error: could not compile `dfu-core` (lib) due to 2 previous errors

So, honestly, I think the way this PR does it is just OK. I could move the interface-unwrapping in a fn to avoid code duplication.

@dingari dingari marked this pull request as draft December 10, 2025 10:28
@cecton
Copy link
Member

cecton commented Dec 10, 2025

Oops you're right

It's yanked and I released 0.10.

@cecton
Copy link
Member

cecton commented Dec 10, 2025

@sjoerdsimons making usb_reset consume self just shifts the partial-move into the DfuASync / DfuSync impls. As download calls usb_reset.

Ah yes that was the issue. Using a state machine has its limitations. The IO object must stay alive.

@dingari dingari marked this pull request as ready for review December 10, 2025 14:49
@cecton
Copy link
Member

cecton commented Dec 15, 2025

Seems all good to me. Only waiting on @sjoerdsimons feedback 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does usb_reset actually work?

3 participants