Skip to content

Commit

Permalink
Merge pull request #134 from rust-embedded-community/fix-warnings
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
eldruin authored Jun 6, 2024
2 parents 44b63de + 6b1ef4c commit ee72ddc
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
4 changes: 3 additions & 1 deletion examples/readme_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,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)?;
Expand Down
88 changes: 44 additions & 44 deletions src/sdcard/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions tests/open_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -126,7 +126,7 @@ where
fn num_blocks(&self) -> Result<BlockCount, Self::Error> {
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");
}
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit ee72ddc

Please sign in to comment.