aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb-dfu/src/dfu.rs
diff options
context:
space:
mode:
authorGerhard de Clercq <[email protected]>2025-05-14 09:52:46 +0200
committerGerhard de Clercq <[email protected]>2025-05-14 09:52:46 +0200
commitd4d10bad0bc2f2bbfbad116fb07e27eea4ac5af2 (patch)
tree111676a87f0e9b5aeb83733ed87663909fcec952 /embassy-usb-dfu/src/dfu.rs
parent46e25cbc5ff62e24f86574d7ae5d872aa0c2595d (diff)
[embassy-usb-dfu] accept closure to customise DFU function
This provides a more generic interface for users to customise the DFU function instead of restricting customisation to DFU headers.
Diffstat (limited to 'embassy-usb-dfu/src/dfu.rs')
-rw-r--r--embassy-usb-dfu/src/dfu.rs21
1 files changed, 6 insertions, 15 deletions
diff --git a/embassy-usb-dfu/src/dfu.rs b/embassy-usb-dfu/src/dfu.rs
index 43a35637d..0f39d906b 100644
--- a/embassy-usb-dfu/src/dfu.rs
+++ b/embassy-usb-dfu/src/dfu.rs
@@ -1,7 +1,7 @@
1use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterError}; 1use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterError};
2use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType}; 2use embassy_usb::control::{InResponse, OutResponse, Recipient, RequestType};
3use embassy_usb::driver::Driver; 3use embassy_usb::driver::Driver;
4use embassy_usb::{msos, Builder, Handler}; 4use embassy_usb::{Builder, FunctionBuilder, Handler};
5use embedded_storage::nor_flash::{NorFlash, NorFlashErrorKind}; 5use embedded_storage::nor_flash::{NorFlash, NorFlashErrorKind};
6 6
7use crate::consts::{ 7use crate::consts::{
@@ -186,22 +186,13 @@ impl<'d, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize> Ha
186pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize>( 186pub fn usb_dfu<'d, D: Driver<'d>, DFU: NorFlash, STATE: NorFlash, RST: Reset, const BLOCK_SIZE: usize>(
187 builder: &mut Builder<'d, D>, 187 builder: &mut Builder<'d, D>,
188 handler: &'d mut Control<'d, DFU, STATE, RST, BLOCK_SIZE>, 188 handler: &'d mut Control<'d, DFU, STATE, RST, BLOCK_SIZE>,
189 winusb_guids: Option<&'d [&str]>, 189 func_modifier: impl Fn(&mut FunctionBuilder<'_, 'd, D>),
190) { 190) {
191 let mut func = builder.function(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU); 191 let mut func = builder.function(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU);
192 if let Some(winusb_guids) = winusb_guids { 192
193 // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows. 193 // Here we give users the opportunity to add their own function level MSOS headers for instance.
194 // Otherwise users need to do this manually using a tool like Zadig. 194 // This is useful when DFU functionality is part of a composite USB device.
195 // 195 func_modifier(&mut func);
196 // Adding them here on the function level appears to only be needed for compositive devices.
197 // In addition to being on the function level, they should also be added to the device level.
198 //
199 func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", ""));
200 func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new(
201 "DeviceInterfaceGUIDs",
202 msos::PropertyData::RegMultiSz(winusb_guids),
203 ));
204 }
205 196
206 let mut iface = func.interface(); 197 let mut iface = func.interface();
207 let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, None); 198 let mut alt = iface.alt_setting(USB_CLASS_APPN_SPEC, APPN_SPEC_SUBCLASS_DFU, DFU_PROTOCOL_DFU, None);