diff --git a/agb-image-converter/src/colour.rs b/agb-image-converter/src/colour.rs index e607cad..26c64f6 100644 --- a/agb-image-converter/src/colour.rs +++ b/agb-image-converter/src/colour.rs @@ -28,9 +28,7 @@ impl FromStr for Colour { fn from_str(colour: &str) -> Result { if colour.len() != 6 { - return Err(format!( - "Expected colour to be 6 characters, got {colour}" - )); + return Err(format!("Expected colour to be 6 characters, got {colour}")); } let r = u8::from_str_radix(&colour[0..2], 16).unwrap(); diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 03800d5..257a53b 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -385,8 +385,7 @@ fn add_image_to_tile_data( for j in inner_y * 8..inner_y * 8 + 8 { for i in inner_x * 8..inner_x * 8 + 8 { let colour = image.colour(x * tile_size + i, y * tile_size + j); - tile_data - .push(palette.colour_index(colour)); + tile_data.push(palette.colour_index(colour)); } } } diff --git a/agb/examples/output.rs b/agb/examples/output.rs index 0869f38..93b8595 100644 --- a/agb/examples/output.rs +++ b/agb/examples/output.rs @@ -6,13 +6,10 @@ use agb::sync::Static; #[agb::entry] fn main(_gba: agb::Gba) -> ! { let count = Static::new(0); - let _a = agb::interrupt::add_interrupt_handler( - agb::interrupt::Interrupt::VBlank, - |_| { - let cur_count = count.read(); - agb::println!("Hello, world, frame = {}", cur_count); - count.write(cur_count + 1); - }, - ); + let _a = agb::interrupt::add_interrupt_handler(agb::interrupt::Interrupt::VBlank, |_| { + let cur_count = count.read(); + agb::println!("Hello, world, frame = {}", cur_count); + count.write(cur_count + 1); + }); loop {} } diff --git a/agb/src/dma.rs b/agb/src/dma.rs index 1bf1b0b..7e92ede 100644 --- a/agb/src/dma.rs +++ b/agb/src/dma.rs @@ -49,4 +49,4 @@ pub(crate) fn dma3_exclusive(f: impl FnOnce() -> R) -> R { // returns the return value ret }) -} \ No newline at end of file +} diff --git a/agb/src/save/eeprom.rs b/agb/src/save/eeprom.rs index 6511b20..08eaa53 100644 --- a/agb/src/save/eeprom.rs +++ b/agb/src/save/eeprom.rs @@ -3,8 +3,8 @@ //! EEPROM requires using DMA to issue commands for both reading and writing. use crate::memory_mapped::MemoryMapped; -use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess}; use crate::save::utils::Timeout; +use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess}; use core::cmp; const PORT: MemoryMapped = unsafe { MemoryMapped::new(0x0DFFFF00) }; @@ -41,7 +41,10 @@ union BufferContents { } impl BufferData { fn new() -> Self { - BufferData { idx: 0, data: BufferContents { uninit: () } } + BufferData { + idx: 0, + data: BufferContents { uninit: () }, + } } /// Writes a bit to the output buffer. @@ -120,7 +123,10 @@ impl EepromProperties { /// Writes a sector directly. #[allow(clippy::needless_range_loop)] fn write_sector_raw( - &self, word: usize, block: &[u8], timeout: &mut Timeout, + &self, + word: usize, + block: &[u8], + timeout: &mut Timeout, ) -> Result<(), Error> { // Write sector command. The command is a one bit, followed by a // zero bit, followed by the address, followed by 64 bits of data. @@ -150,7 +156,11 @@ impl EepromProperties { /// Writes a sector to the EEPROM, keeping any current contents outside the /// buffer's range. fn write_sector_safe( - &self, word: usize, data: &[u8], start: usize, timeout: &mut Timeout, + &self, + word: usize, + data: &[u8], + start: usize, + timeout: &mut Timeout, ) -> Result<(), Error> { let mut buf = self.read_sector(word); buf[start..start + data.len()].copy_from_slice(data); @@ -159,7 +169,11 @@ impl EepromProperties { /// Writes a sector to the EEPROM. fn write_sector( - &self, word: usize, data: &[u8], start: usize, timeout: &mut Timeout, + &self, + word: usize, + data: &[u8], + start: usize, + timeout: &mut Timeout, ) -> Result<(), Error> { if data.len() == 8 && start == 0 { self.write_sector_raw(word, data, timeout) @@ -219,8 +233,14 @@ impl EepromProperties { Ok(()) } } -const PROPS_512B: EepromProperties = EepromProperties { addr_bits: 6, byte_len: 512 }; -const PROPS_8K: EepromProperties = EepromProperties { addr_bits: 14, byte_len: 8 * 1024 }; +const PROPS_512B: EepromProperties = EepromProperties { + addr_bits: 6, + byte_len: 512, +}; +const PROPS_8K: EepromProperties = EepromProperties { + addr_bits: 14, + byte_len: 8 * 1024, +}; /// The [`RawSaveAccess`] used for 512 byte EEPROM. pub struct Eeprom512B; diff --git a/agb/src/save/flash.rs b/agb/src/save/flash.rs index 28b21e5..b160048 100644 --- a/agb/src/save/flash.rs +++ b/agb/src/save/flash.rs @@ -6,11 +6,11 @@ // TODO: Setup cartridge read timings for faster Flash access. use crate::memory_mapped::{MemoryMapped, MemoryMapped1DArray}; -use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess}; use crate::save::asm_utils::*; +use crate::save::utils::Timeout; +use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess}; use crate::sync::{InitOnce, Static}; use core::cmp; -use crate::save::utils::Timeout; // Volatile address ports for flash const FLASH_PORT_BANK: MemoryMapped = unsafe { MemoryMapped::new(0x0E000000) }; @@ -314,7 +314,11 @@ impl ChipInfo { /// Waits for a timeout, or an operation to complete. fn wait_for_timeout( - &self, offset: usize, val: u8, ms: u16, timeout: &mut Timeout, + &self, + offset: usize, + val: u8, + ms: u16, + timeout: &mut Timeout, ) -> Result<(), Error> { timeout.start(); let offset = 0x0E000000 + offset; @@ -371,7 +375,10 @@ impl ChipInfo { /// Erases and writes an entire 128b sector on Atmel devices. #[allow(clippy::needless_range_loop)] fn write_atmel_sector_raw( - &self, offset: usize, buf: &[u8], timeout: &mut Timeout, + &self, + offset: usize, + buf: &[u8], + timeout: &mut Timeout, ) -> Result<(), Error> { crate::interrupt::free(|_| { issue_flash_command(CMD_WRITE); @@ -387,12 +394,19 @@ impl ChipInfo { /// case of non-sector aligned writes. #[inline(never)] // avoid allocating the 128 byte buffer for no reason. fn write_atmel_sector_safe( - &self, offset: usize, buf: &[u8], start: usize, timeout: &mut Timeout, + &self, + offset: usize, + buf: &[u8], + start: usize, + timeout: &mut Timeout, ) -> Result<(), Error> { let mut sector = [0u8; 128]; self.read_buffer(offset, &mut sector[0..start])?; sector[start..start + buf.len()].copy_from_slice(buf); - self.read_buffer(offset + start + buf.len(), &mut sector[start + buf.len()..128])?; + self.read_buffer( + offset + start + buf.len(), + &mut sector[start + buf.len()..128], + )?; self.write_atmel_sector_raw(offset, §or, timeout) } @@ -401,7 +415,11 @@ impl ChipInfo { /// /// This avoids allocating stack if there is no need to. fn write_atmel_sector( - &self, offset: usize, buf: &[u8], start: usize, timeout: &mut Timeout, + &self, + offset: usize, + buf: &[u8], + start: usize, + timeout: &mut Timeout, ) -> Result<(), Error> { if start == 0 && buf.len() == 128 { self.write_atmel_sector_raw(offset, buf, timeout) @@ -433,7 +451,10 @@ impl RawSaveAccess for FlashAccess { } fn prepare_write( - &self, sector: usize, count: usize, timeout: &mut Timeout, + &self, + sector: usize, + count: usize, + timeout: &mut Timeout, ) -> Result<(), Error> { let chip = cached_chip_info()?; chip.check_sector_len(sector, count)?; diff --git a/agb/src/save/sram.rs b/agb/src/save/sram.rs index 614b751..2a7c798 100644 --- a/agb/src/save/sram.rs +++ b/agb/src/save/sram.rs @@ -3,9 +3,9 @@ //! SRAM acts as ordinary memory mapped into the memory space, and as such //! is accessed using normal memory read/write commands. -use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess}; use crate::save::asm_utils::*; use crate::save::utils::Timeout; +use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess}; const SRAM_SIZE: usize = 32 * 1024; // 32 KiB diff --git a/agb/src/save/utils.rs b/agb/src/save/utils.rs index b94cb3f..ea12ee2 100644 --- a/agb/src/save/utils.rs +++ b/agb/src/save/utils.rs @@ -2,7 +2,7 @@ use super::Error; use crate::sync::{RawMutex, RawMutexGuard}; -use crate::timer::{Timer, Divider}; +use crate::timer::{Divider, Timer}; /// A timeout type used to prevent hardware errors in save media from hanging /// the game. diff --git a/agb/src/sync/locks.rs b/agb/src/sync/locks.rs index a1a0cf3..fdb7033 100644 --- a/agb/src/sync/locks.rs +++ b/agb/src/sync/locks.rs @@ -81,7 +81,10 @@ impl Mutex { /// Creates a new lock containing a given value. #[must_use] pub const fn new(t: T) -> Self { - Mutex { raw: RawMutex::new(), data: UnsafeCell::new(t) } + Mutex { + raw: RawMutex::new(), + data: UnsafeCell::new(t), + } } /// Returns a guard for this lock, or panics if there is another lock active. @@ -92,7 +95,10 @@ impl Mutex { /// Returns a guard for this lock or `None` if there is another lock active. pub fn try_lock(&self) -> Option> { if self.raw.raw_lock() { - Some(MutexGuard { underlying: self, ptr: self.data.get() }) + Some(MutexGuard { + underlying: self, + ptr: self.data.get(), + }) } else { None } diff --git a/agb/tests/save_test_common/mod.rs b/agb/tests/save_test_common/mod.rs index d3f823c..3f7c204 100644 --- a/agb/tests/save_test_common/mod.rs +++ b/agb/tests/save_test_common/mod.rs @@ -1,6 +1,6 @@ -use core::cmp; use agb::save::{Error, MediaInfo}; use agb::sync::InitOnce; +use core::cmp; fn init_sram(gba: &mut agb::Gba) -> &'static MediaInfo { static ONCE: InitOnce = InitOnce::new(); @@ -31,7 +31,11 @@ const MAX_BLOCK_SIZE: usize = 4 * 1024; #[allow(clippy::needless_range_loop)] fn do_test( - gba: &mut agb::Gba, seed: Rng, offset: usize, len: usize, block_size: usize, + gba: &mut agb::Gba, + seed: Rng, + offset: usize, + len: usize, + block_size: usize, ) -> Result<(), Error> { let mut buffer = [0; MAX_BLOCK_SIZE]; @@ -61,9 +65,12 @@ fn do_test( for i in 0..cur_len { let cur_byte = rng.next_u8(); assert_eq!( - buffer[i], cur_byte, + buffer[i], + cur_byte, "Read does not match earlier write: {} != {} @ 0x{:05x}", - buffer[i], cur_byte, current + i, + buffer[i], + cur_byte, + current + i, ); } current += cur_len; @@ -102,4 +109,4 @@ fn test_partial_writes(gba: &mut agb::Gba) { do_test(gba, Rng(i * 10000), rand_offset, rand_length, block_size) .expect("Test encountered error"); } -} \ No newline at end of file +}