Ensure cargo fmt is run accross everything (#399)

I have fmt'd all the things!

- [x] Changelog updated / no changelog update needed
This commit is contained in:
Gwilym Inzani 2023-03-23 23:11:19 +00:00 committed by GitHub
commit aea8547f97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 106 additions and 47 deletions

View file

@ -28,9 +28,7 @@ impl FromStr for Colour {
fn from_str(colour: &str) -> Result<Self, Self::Err> {
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();

View file

@ -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));
}
}
}

View file

@ -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 {}
}

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "clippy"]
components = ["rust-src", "clippy", "rustfmt"]

View file

@ -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<u16> = 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;

View file

@ -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<u8> = 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, &sector, 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)?;

View file

@ -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

View file

@ -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.

View file

@ -81,7 +81,10 @@ impl<T> Mutex<T> {
/// 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<T> Mutex<T> {
/// Returns a guard for this lock or `None` if there is another lock active.
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>> {
if self.raw.raw_lock() {
Some(MutexGuard { underlying: self, ptr: self.data.get() })
Some(MutexGuard {
underlying: self,
ptr: self.data.get(),
})
} else {
None
}

View file

@ -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<MediaInfo> = 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;

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "clippy"]
components = ["rust-src", "clippy", "rustfmt"]

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "clippy"]
components = ["rust-src", "clippy", "rustfmt"]

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "clippy"]
components = ["rust-src", "clippy", "rustfmt"]

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "clippy"]
components = ["rust-src", "clippy", "rustfmt"]

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "clippy"]
components = ["rust-src", "clippy", "rustfmt"]

View file

@ -34,6 +34,13 @@ _build_docs crate:
clean:
just _all-crates _clean
fmt:
just _all-crates _fmt
just _fmt tools
fmt-check:
just _all-crates _fmt-check
just _fmt-check tools
run-example example:
just _build-example "{{example}}"
mgba-qt "$CARGO_TARGET_DIR/thumbv4t-none-eabi/debug/examples/{{example}}"
@ -52,7 +59,7 @@ check-linker-script-consistency:
find -type f -name gba.ld -print0 | xargs -0 -n1 cmp -- agb/gba.ld
find -type f -name gba_mb.ld -print0 | xargs -0 -n1 cmp -- agb/gba_mb.ld
ci: check-linker-script-consistency build-debug clippy test build-release test-release doctest-agb build-roms build-book check-docs
ci: check-linker-script-consistency build-debug clippy fmt-check test build-release test-release doctest-agb build-roms build-book check-docs
build-roms:
just _build-rom "examples/the-purple-night" "PURPLENIGHT"
@ -94,7 +101,7 @@ _build-rom folder name:
TARGET_FOLDER="${CARGO_TARGET_DIR:-$GAME_FOLDER/target}"
GBA_FILE="$TARGET_FOLDER/$GAME_NAME.gba"
(cd "$GAME_FOLDER" && cargo build --release --target thumbv4t-none-eabi && cargo clippy --release --target thumbv4t-none-eabi -- {{CLIPPY_ARGUMENTS}})
(cd "$GAME_FOLDER" && cargo build --release --target thumbv4t-none-eabi && cargo clippy --release --target thumbv4t-none-eabi -- {{CLIPPY_ARGUMENTS}} && cargo fmt --all -- --check)
mkdir -p examples/target/examples
@ -127,6 +134,10 @@ _clippy crate:
(cd "{{crate}}" && cargo clippy --examples --tests -- {{CLIPPY_ARGUMENTS}})
_clean crate:
(cd "{{crate}}" && cargo clean)
_fmt crate:
(cd "{{crate}}" && cargo fmt --all)
_fmt-check crate:
(cd "{{crate}}" && cargo fmt --all -- --check)
_build-example example:
(cd agb && cargo build "--example={{example}}")

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src", "clippy"]
components = ["rust-src", "clippy", "rustfmt"]