File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
5
5
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6
6
7
+ ## [ Unreleased]
8
+ ### Added
9
+ - Added a ` with_device ` method to access device-specific features, such as the EEPROM.
10
+
7
11
## [ 0.23.0] - 2025-03-09
8
12
### Changed
9
13
- Changed the SPI traits to be implemented on the ` SpiDevice ` struct, instead of a reference to the struct.
Original file line number Diff line number Diff line change @@ -391,6 +391,35 @@ where
391
391
E : std:: error:: Error ,
392
392
Error < E > : From < E > ,
393
393
{
394
+ /// Executes the closure with the device.
395
+ ///
396
+ /// Useful for accessing EEPROM, or other device-specific functionality.
397
+ ///
398
+ /// # Example
399
+ ///
400
+ /// ```no_run
401
+ /// use ftdi_embedded_hal as hal;
402
+ /// # #[cfg(feature = "libftd2xx")]
403
+ /// use hal::libftd2xx::FtdiEeprom;
404
+ ///
405
+ /// # #[cfg(feature = "libftd2xx")]
406
+ /// # {
407
+ /// let device = libftd2xx::Ft2232h::with_description("Dual RS232-HS A")?;
408
+ /// let mut hal = hal::FtHal::init_default(device)?;
409
+ /// let serial_number: String =
410
+ /// hal.with_device(|d| d.eeprom_read().map(|(_, strings)| strings.serial_number()))?;
411
+ /// # }
412
+ /// # Ok::<(), std::boxed::Box<dyn std::error::Error>>(())
413
+ /// ```
414
+ pub fn with_device < T , F > ( & mut self , mut f : F ) -> T
415
+ where
416
+ F : FnMut ( & mut Device ) -> T ,
417
+ {
418
+ let mut inner = self . mtx . lock ( ) . expect ( "Failed to aquire FTDI mutex" ) ;
419
+ let result: T = f ( & mut inner. ft ) ;
420
+ result
421
+ }
422
+
394
423
/// Aquire the SPI peripheral for the FT232H.
395
424
///
396
425
/// Pin assignments:
You can’t perform that action at this time.
0 commit comments