From 7b5b876afba9b3543373b88ee4e910d7d6b840d7 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sat, 1 Jun 2024 20:32:55 +0100 Subject: [PATCH 1/2] Appease clippy. --- examples/readme_test.rs | 2 + src/sdcard/proto.rs | 88 ++++++++++++++++++++--------------------- tests/open_files.rs | 10 ++--- tests/utils/mod.rs | 6 +-- 4 files changed, 54 insertions(+), 52 deletions(-) diff --git a/examples/readme_test.rs b/examples/readme_test.rs index 153b758..2069694 100644 --- a/examples/readme_test.rs +++ b/examples/readme_test.rs @@ -3,6 +3,8 @@ //! We add enough stuff to make it compile, but it won't run because our fake //! SPI doesn't do any replies. +#![allow(dead_code)] + use core::cell::RefCell; use embedded_sdmmc::sdcard::DummyCsPin; diff --git a/src/sdcard/proto.rs b/src/sdcard/proto.rs index 6418574..68ae248 100644 --- a/src/sdcard/proto.rs +++ b/src/sdcard/proto.rs @@ -298,19 +298,19 @@ mod test { // Partial Blocks for Read Allowed: // 0b1 [Interpreted: Yes] - assert_eq!(EXAMPLE.read_partial_blocks(), true); + assert!(EXAMPLE.read_partial_blocks()); // Write Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.write_block_misalignment(), false); + assert!(!EXAMPLE.write_block_misalignment()); // Read Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.read_block_misalignment(), false); + assert!(!EXAMPLE.read_block_misalignment()); // DSR Implemented: indicates configurable driver stage integrated on // card 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.dsr_implemented(), false); + assert!(!EXAMPLE.dsr_implemented()); // Device Size: to calculate the card capacity excl. security area // ((device size + 1)*device size multiplier*max read data block @@ -339,7 +339,7 @@ mod test { // Erase Single Block Enabled: // 0x1 [Interpreted: Yes] - assert_eq!(EXAMPLE.erase_single_block_enabled(), true); + assert!(EXAMPLE.erase_single_block_enabled()); // Erase Sector Size: size of erasable sector in write blocks // 0x1f [Interpreted: 32 blocks] @@ -351,7 +351,7 @@ mod test { // Write Protect Group Enable: // 0x1 [Interpreted: Yes] - assert_eq!(EXAMPLE.write_protect_group_enable(), true); + assert!(EXAMPLE.write_protect_group_enable()); // Write Speed Factor: block program time as multiple of read access time // 0x4 [Interpreted: x16] @@ -363,23 +363,23 @@ mod test { // Partial Blocks for Write Allowed: // 0x0 [Interpreted: No] - assert_eq!(EXAMPLE.write_partial_blocks(), false); + assert!(!EXAMPLE.write_partial_blocks()); // File Format Group: // 0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT without Partition Table/Universal File Format/Other/Unknown] - assert_eq!(EXAMPLE.file_format_group_set(), false); + assert!(!EXAMPLE.file_format_group_set()); // Copy Flag: // 0b1 [Interpreted: Non-Original] - assert_eq!(EXAMPLE.copy_flag_set(), true); + assert!(EXAMPLE.copy_flag_set()); // Permanent Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.permanent_write_protection(), false); + assert!(!EXAMPLE.permanent_write_protection()); // Temporary Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.temporary_write_protection(), false); + assert!(!EXAMPLE.temporary_write_protection()); // File Format: // 0x0 [Interpreted: Hard Disk with Partition Table] @@ -424,19 +424,19 @@ mod test { // Partial Blocks for Read Allowed: // 0b1 [Interpreted: Yes] - assert_eq!(EXAMPLE.read_partial_blocks(), true); + assert!(EXAMPLE.read_partial_blocks()); // Write Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.write_block_misalignment(), false); + assert!(!EXAMPLE.write_block_misalignment()); // Read Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.read_block_misalignment(), false); + assert!(!EXAMPLE.read_block_misalignment()); // DSR Implemented: indicates configurable driver stage integrated on card // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.dsr_implemented(), false); + assert!(!EXAMPLE.dsr_implemented()); // Device Size: to calculate the card capacity excl. security area // ((device size + 1)*device size multiplier*max read data block @@ -465,7 +465,7 @@ mod test { // Erase Single Block Enabled: // 0x1 [Interpreted: Yes] - assert_eq!(EXAMPLE.erase_single_block_enabled(), true); + assert!(EXAMPLE.erase_single_block_enabled()); // Erase Sector Size: size of erasable sector in write blocks // 0x1f [Interpreted: 32 blocks] @@ -477,7 +477,7 @@ mod test { // Write Protect Group Enable: // 0x0 [Interpreted: No] - assert_eq!(EXAMPLE.write_protect_group_enable(), false); + assert!(!EXAMPLE.write_protect_group_enable()); // Write Speed Factor: block program time as multiple of read access time // 0x5 [Interpreted: x32] @@ -489,23 +489,23 @@ mod test { // Partial Blocks for Write Allowed: // 0x0 [Interpreted: No] - assert_eq!(EXAMPLE.write_partial_blocks(), false); + assert!(!EXAMPLE.write_partial_blocks()); // File Format Group: // 0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT without Partition Table/Universal File Format/Other/Unknown] - assert_eq!(EXAMPLE.file_format_group_set(), false); + assert!(!EXAMPLE.file_format_group_set()); // Copy Flag: // 0b0 [Interpreted: Original] - assert_eq!(EXAMPLE.copy_flag_set(), false); + assert!(!EXAMPLE.copy_flag_set()); // Permanent Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.permanent_write_protection(), false); + assert!(!EXAMPLE.permanent_write_protection()); // Temporary Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.temporary_write_protection(), false); + assert!(!EXAMPLE.temporary_write_protection()); // File Format: // 0x0 [Interpreted: Hard Disk with Partition Table] @@ -550,19 +550,19 @@ mod test { // Partial Blocks for Read Allowed: // 0b0 [Interpreted: Yes] - assert_eq!(EXAMPLE.read_partial_blocks(), false); + assert!(!EXAMPLE.read_partial_blocks()); // Write Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.write_block_misalignment(), false); + assert!(!EXAMPLE.write_block_misalignment()); // Read Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.read_block_misalignment(), false); + assert!(!EXAMPLE.read_block_misalignment()); // DSR Implemented: indicates configurable driver stage integrated on card // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.dsr_implemented(), false); + assert!(!EXAMPLE.dsr_implemented()); // Device Size: to calculate the card capacity excl. security area // ((device size + 1)* 512kbytes @@ -571,7 +571,7 @@ mod test { // Erase Single Block Enabled: // 0x1 [Interpreted: Yes] - assert_eq!(EXAMPLE.erase_single_block_enabled(), true); + assert!(EXAMPLE.erase_single_block_enabled()); // Erase Sector Size: size of erasable sector in write blocks // 0x7f [Interpreted: 128 blocks] @@ -583,7 +583,7 @@ mod test { // Write Protect Group Enable: // 0x0 [Interpreted: No] - assert_eq!(EXAMPLE.write_protect_group_enable(), false); + assert!(!EXAMPLE.write_protect_group_enable()); // Write Speed Factor: block program time as multiple of read access time // 0x2 [Interpreted: x4] @@ -595,23 +595,23 @@ mod test { // Partial Blocks for Write Allowed: // 0x0 [Interpreted: No] - assert_eq!(EXAMPLE.write_partial_blocks(), false); + assert!(!EXAMPLE.write_partial_blocks()); // File Format Group: // 0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT without Partition Table/Universal File Format/Other/Unknown] - assert_eq!(EXAMPLE.file_format_group_set(), false); + assert!(!EXAMPLE.file_format_group_set()); // Copy Flag: // 0b0 [Interpreted: Original] - assert_eq!(EXAMPLE.copy_flag_set(), false); + assert!(!EXAMPLE.copy_flag_set()); // Permanent Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.permanent_write_protection(), false); + assert!(!EXAMPLE.permanent_write_protection()); // Temporary Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.temporary_write_protection(), false); + assert!(!EXAMPLE.temporary_write_protection()); // File Format: // 0x0 [Interpreted: Hard Disk with Partition Table] @@ -656,19 +656,19 @@ mod test { // Partial Blocks for Read Allowed: // 0b0 [Interpreted: Yes] - assert_eq!(EXAMPLE.read_partial_blocks(), false); + assert!(!EXAMPLE.read_partial_blocks()); // Write Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.write_block_misalignment(), false); + assert!(!EXAMPLE.write_block_misalignment()); // Read Block Misalignment: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.read_block_misalignment(), false); + assert!(!EXAMPLE.read_block_misalignment()); // DSR Implemented: indicates configurable driver stage integrated on card // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.dsr_implemented(), false); + assert!(!EXAMPLE.dsr_implemented()); // Device Size: to calculate the card capacity excl. security area // ((device size + 1)* 512kbytes @@ -677,7 +677,7 @@ mod test { // Erase Single Block Enabled: // 0x1 [Interpreted: Yes] - assert_eq!(EXAMPLE.erase_single_block_enabled(), true); + assert!(EXAMPLE.erase_single_block_enabled()); // Erase Sector Size: size of erasable sector in write blocks // 0x7f [Interpreted: 128 blocks] @@ -689,7 +689,7 @@ mod test { // Write Protect Group Enable: // 0x0 [Interpreted: No] - assert_eq!(EXAMPLE.write_protect_group_enable(), false); + assert!(!EXAMPLE.write_protect_group_enable()); // Write Speed Factor: block program time as multiple of read access time // 0x2 [Interpreted: x4] @@ -701,23 +701,23 @@ mod test { // Partial Blocks for Write Allowed: // 0x0 [Interpreted: No] - assert_eq!(EXAMPLE.write_partial_blocks(), false); + assert!(!EXAMPLE.write_partial_blocks()); // File Format Group: // 0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT without Partition Table/Universal File Format/Other/Unknown] - assert_eq!(EXAMPLE.file_format_group_set(), false); + assert!(!EXAMPLE.file_format_group_set()); // Copy Flag: // 0b0 [Interpreted: Original] - assert_eq!(EXAMPLE.copy_flag_set(), false); + assert!(!EXAMPLE.copy_flag_set()); // Permanent Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.permanent_write_protection(), false); + assert!(!EXAMPLE.permanent_write_protection()); // Temporary Write Protection: // 0b0 [Interpreted: No] - assert_eq!(EXAMPLE.temporary_write_protection(), false); + assert!(!EXAMPLE.temporary_write_protection()); // File Format: // 0x0 [Interpreted: Hard Disk with Partition Table] diff --git a/tests/open_files.rs b/tests/open_files.rs index dcdaadf..10e2181 100644 --- a/tests/open_files.rs +++ b/tests/open_files.rs @@ -109,24 +109,24 @@ fn open_non_raw() { assert_eq!(len, 258); assert_eq!(f.length(), 258); f.seek_from_current(0).unwrap(); - assert_eq!(f.is_eof(), true); + assert!(f.is_eof()); assert_eq!(f.offset(), 258); assert!(matches!(f.seek_from_current(1), Err(Error::InvalidOffset))); f.seek_from_current(-258).unwrap(); - assert_eq!(f.is_eof(), false); + assert!(!f.is_eof()); assert_eq!(f.offset(), 0); f.seek_from_current(10).unwrap(); - assert_eq!(f.is_eof(), false); + assert!(!f.is_eof()); assert_eq!(f.offset(), 10); f.seek_from_end(0).unwrap(); - assert_eq!(f.is_eof(), true); + assert!(f.is_eof()); assert_eq!(f.offset(), 258); assert!(matches!( f.seek_from_current(-259), Err(Error::InvalidOffset) )); f.seek_from_start(25).unwrap(); - assert_eq!(f.is_eof(), false); + assert!(!f.is_eof()); assert_eq!(f.offset(), 25); drop(f); diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 9976975..9c371a4 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -8,7 +8,7 @@ use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; /// /// ```console /// $ fdisk ./disk.img -/// Disk: ./disk.img geometry: 520/32/63 [1048576 sectors] +/// Disk: ./disk.img geometry: 520/32/63 [1048576 sectors] /// Signature: 0xAA55 /// Starting Ending /// #: id cyl hd sec - cyl hd sec [ start - size] @@ -126,7 +126,7 @@ where fn num_blocks(&self) -> Result { let borrow = self.contents.borrow(); let contents: &[u8] = borrow.as_ref(); - let len_blocks = contents.len() as usize / embedded_sdmmc::Block::LEN; + let len_blocks = contents.len() / embedded_sdmmc::Block::LEN; if len_blocks > u32::MAX as usize { panic!("Test disk too large! Only 2**32 blocks allowed"); } @@ -155,7 +155,7 @@ pub struct TestTimeSource { impl embedded_sdmmc::TimeSource for TestTimeSource { fn get_timestamp(&self) -> embedded_sdmmc::Timestamp { - self.fixed.clone() + self.fixed } } From 6b1ef4c64e415b26dbb13f49add42bbfce45f959 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sat, 1 Jun 2024 20:33:48 +0100 Subject: [PATCH 2/2] Update README example Notes that converting a byte to a char is assuming the the file is ISO-8859-1 encoded. --- README.md | 2 +- examples/readme_test.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ba2918..9b881a2 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ let mut root_dir = volume0.open_root_dir()?; // Open a file called "MY_FILE.TXT" in the root directory // This mutably borrows the directory. let mut my_file = root_dir.open_file_in_dir("MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly)?; -// Print the contents of the file +// Print the contents of the file, assuming it's in ISO-8859-1 encoding while !my_file.is_eof() { let mut buffer = [0u8; 32]; let num_read = my_file.read(&mut buffer)?; diff --git a/examples/readme_test.rs b/examples/readme_test.rs index 2069694..ed4b146 100644 --- a/examples/readme_test.rs +++ b/examples/readme_test.rs @@ -120,7 +120,7 @@ fn main() -> Result<(), Error> { // Open a file called "MY_FILE.TXT" in the root directory // This mutably borrows the directory. let mut my_file = root_dir.open_file_in_dir("MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly)?; - // Print the contents of the file + // Print the contents of the file, assuming it's in ISO-8859-1 encoding while !my_file.is_eof() { let mut buffer = [0u8; 32]; let num_read = my_file.read(&mut buffer)?;