From 158e6a5924be034fe0f66003d6148074b68a1920 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:12:40 -0400 Subject: [PATCH 01/33] Set up reusable workflow and add doctests --- .github/workflows/ci.yml | 50 +++++++++++++------------------------ .github/workflows/setup.yml | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/setup.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 102c704..fb4d218 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,10 +9,6 @@ on: - master workflow_dispatch: -env: - # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html - CARGO_UNSTABLE_SPARSE_REGISTRY: "true" - jobs: lint: strategy: @@ -25,38 +21,10 @@ jobs: # But if latest nightly fails, allow the workflow to continue continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest - container: devkitpro/devkitarm steps: - # https://github.com/nektos/act/issues/917#issuecomment-1074421318 - - if: ${{ env.ACT }} - name: Hack container for local development - run: | - curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - - sudo apt-get install -y nodejs - - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Setup default Rust toolchain - uses: actions-rs/toolchain@v1 + - uses: ./.github/workflows/setup.yml with: - components: clippy, rustfmt, rust-src - profile: minimal toolchain: ${{ matrix.toolchain }} - default: true - - - name: Install build tools for host - run: sudo apt-get update && sudo apt-get install -y build-essential - - - name: Install cargo-3ds - uses: actions-rs/cargo@v1 - with: - command: install - # TODO: this should probably just be a released version from crates.io - # once cargo-3ds gets published somewhere... - args: >- - --git https://github.com/rust3ds/cargo-3ds - --rev 7b70b6b26c4740b9a10ab85b832ee73c41142bbb - name: Check formatting run: cargo fmt --all --verbose -- --check @@ -68,5 +36,21 @@ jobs: # feature, but https://github.com/actions/runner/issues/2341 means we # can't have both that *and* colored output. + doctests: + strategy: + matrix: + toolchain: + - nightly-2023-01-13 + - nightly + continue-on-error: ${{ matrix.toolchain == 'nightly' }} + runs-on: ubuntu-latest + steps: + - uses: ./.github/workflows/setup.yml + with: + toolchain: ${{ matrix.toolchain }} + + - name: Build doc tests + run: cargo 3ds test --doc --verbose + # TODO: it would be nice to actually build 3dsx for examples/tests, etc. # and run it somehow, but exactly how remains to be seen. diff --git a/.github/workflows/setup.yml b/.github/workflows/setup.yml new file mode 100644 index 0000000..bfdc8de --- /dev/null +++ b/.github/workflows/setup.yml @@ -0,0 +1,48 @@ +name: Setup + +on: + workflow_call: + inputs: + toolchain: + required: true + type: string + +env: + # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + +jobs: + setup: + runs-on: ubuntu-latest + container: devkitpro/devkitarm + steps: + # https://github.com/nektos/act/issues/917#issuecomment-1074421318 + - if: ${{ env.ACT }} + name: Hack container for local development + run: | + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - + sudo apt-get install -y nodejs + + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Setup default Rust toolchain + # Use this helper + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy, rustfmt, rust-src + toolchain: ${{ matrix.toolchain }} + + - name: Install build tools for host + run: sudo apt-get update && sudo apt-get install -y build-essential + + - name: Install cargo-3ds + uses: actions-rs/cargo@v1 + with: + command: install + # TODO: this should probably just be a released version from crates.io + # once cargo-3ds gets published somewhere... + # also switch to hash once feature/doctests gets merged + args: >- + --git https://github.com/rust3ds/cargo-3ds + --rev feature/doctests From 6c6c09439953b2ed89e2047d45bd9330e51ec285 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:13:14 -0400 Subject: [PATCH 02/33] Fix build errors in FS examples --- ctru-rs/src/services/fs.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 45f9efb..058eb14 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -123,6 +123,9 @@ pub struct Archive { /// Create a new file and write bytes to it: /// /// ```no_run +/// # use std::error::Error; +/// # fn main() -> Result<(), Box> { +/// # /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// @@ -131,11 +134,17 @@ pub struct Archive { /// /// let mut file = File::create(&sdmc, "/foo.txt")?; /// file.write_all(b"Hello, world!")?; +/// # +/// # Ok(()) +/// # } /// ``` /// /// Read the contents of a file into a `String`:: /// /// ```no_run +/// # use std::error::Error; +/// # fn main() -> Result<(), Box> { +/// # /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// @@ -146,12 +155,18 @@ pub struct Archive { /// let mut contents = String::new(); /// file.read_to_string(&mut contents)?; /// assert_eq!(contents, "Hello, world!"); +/// # +/// # Ok(()) +/// # } /// ``` /// /// It can be more efficient to read the contents of a file with a buffered /// `Read`er. This can be accomplished with `BufReader`: /// /// ```no_run +/// # use std::error::Error; +/// # fn main() -> Result<(), Box> { +/// # /// use std::io::BufReader; /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; @@ -164,6 +179,9 @@ pub struct Archive { /// let mut contents = String::new(); /// buf_reader.read_to_string(&mut contents)?; /// assert_eq!(contents, "Hello, world!"); +/// # +/// # Ok(()) +/// # } /// ``` pub struct File { handle: u32, From 131a53582698c50c221a4226ffa6164e3c8c3d2e Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:13:43 -0400 Subject: [PATCH 03/33] Add basic CODEOWNERS file --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..0163641 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @rust3ds/active From cabd3acf1a49a1ba59df6b964fc7381c9d0b0d1a Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:22:20 -0400 Subject: [PATCH 04/33] Try using a composite action instead of workflow --- .github/actions/setup/action.yml | 45 ++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 10 +++++-- .github/workflows/setup.yml | 48 -------------------------------- 3 files changed, 53 insertions(+), 50 deletions(-) create mode 100644 .github/actions/setup/action.yml delete mode 100644 .github/workflows/setup.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..2f33006 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,45 @@ +name: Setup +description: Set up CI environment for Rust + 3DS development + +inputs: + toolchain: + description: The Rust toolchain to use for the steps + required: true + default: nightly + +runs: + using: composite + steps: + # https://github.com/nektos/act/issues/917#issuecomment-1074421318 + - if: ${{ env.ACT }} + shell: bash + name: Hack container for local development + run: | + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - + sudo apt-get install -y nodejs + + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Setup default Rust toolchain + # Use this helper action so we get matcher support + # https://github.com/actions-rust-lang/setup-rust-toolchain/pull/15 + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy, rustfmt, rust-src + toolchain: ${{ matrix.toolchain }} + + - name: Install build tools for host + shell: bash + run: sudo apt-get update && sudo apt-get install -y build-essential + + - name: Install cargo-3ds + uses: actions-rs/cargo@v1 + with: + command: install + # TODO: this should probably just be a released version from crates.io + # once cargo-3ds gets published somewhere... + # also switch to hash once feature/doctests gets merged + args: >- + --git https://github.com/rust3ds/cargo-3ds + --rev feature/doctests diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb4d218..7b44782 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,10 @@ on: - master workflow_dispatch: +env: + # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + jobs: lint: strategy: @@ -21,8 +25,9 @@ jobs: # But if latest nightly fails, allow the workflow to continue continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest + container: devkitpro/devkitarm steps: - - uses: ./.github/workflows/setup.yml + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} @@ -44,8 +49,9 @@ jobs: - nightly continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest + container: devkitpro/devkitarm steps: - - uses: ./.github/workflows/setup.yml + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} diff --git a/.github/workflows/setup.yml b/.github/workflows/setup.yml deleted file mode 100644 index bfdc8de..0000000 --- a/.github/workflows/setup.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Setup - -on: - workflow_call: - inputs: - toolchain: - required: true - type: string - -env: - # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html - CARGO_UNSTABLE_SPARSE_REGISTRY: "true" - -jobs: - setup: - runs-on: ubuntu-latest - container: devkitpro/devkitarm - steps: - # https://github.com/nektos/act/issues/917#issuecomment-1074421318 - - if: ${{ env.ACT }} - name: Hack container for local development - run: | - curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - - sudo apt-get install -y nodejs - - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Setup default Rust toolchain - # Use this helper - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - components: clippy, rustfmt, rust-src - toolchain: ${{ matrix.toolchain }} - - - name: Install build tools for host - run: sudo apt-get update && sudo apt-get install -y build-essential - - - name: Install cargo-3ds - uses: actions-rs/cargo@v1 - with: - command: install - # TODO: this should probably just be a released version from crates.io - # once cargo-3ds gets published somewhere... - # also switch to hash once feature/doctests gets merged - args: >- - --git https://github.com/rust3ds/cargo-3ds - --rev feature/doctests From 38d89bd170f0264e1b24502db411b5e46c1df8e6 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:25:07 -0400 Subject: [PATCH 05/33] Checkout branch before trying to use its code --- .github/actions/setup/action.yml | 5 +---- .github/workflows/ci.yml | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 2f33006..728dd02 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -18,16 +18,13 @@ runs: curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs - - name: Checkout branch - uses: actions/checkout@v2 - - name: Setup default Rust toolchain # Use this helper action so we get matcher support # https://github.com/actions-rust-lang/setup-rust-toolchain/pull/15 uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: clippy, rustfmt, rust-src - toolchain: ${{ matrix.toolchain }} + toolchain: ${{ inputs.toolchain }} - name: Install build tools for host shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b44782..b0bfc23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,9 @@ jobs: runs-on: ubuntu-latest container: devkitpro/devkitarm steps: + - name: Checkout branch + uses: actions/checkout@v2 + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} @@ -51,6 +54,9 @@ jobs: runs-on: ubuntu-latest container: devkitpro/devkitarm steps: + - name: Checkout branch + uses: actions/checkout@v2 + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} From 271dba9fd8959770e497928d8cc089e5cfb0879c Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:27:17 -0400 Subject: [PATCH 06/33] Fix hash for installing cargo-3ds --- .github/actions/setup/action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 728dd02..1833988 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -36,7 +36,8 @@ runs: command: install # TODO: this should probably just be a released version from crates.io # once cargo-3ds gets published somewhere... - # also switch to hash once feature/doctests gets merged + # + # also switch to master hash once feature/doctests gets merged args: >- --git https://github.com/rust3ds/cargo-3ds - --rev feature/doctests + --rev 5a06e64307499ffe681453e7d88d7ee986054eb7 From 336887aa180c8553e9a13b7f0fdb23c267291b1c Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:52:54 -0400 Subject: [PATCH 07/33] Clear -Dwarnings flag from toolchain --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0bfc23..8ff1525 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ on: env: # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + # actions-rust-lang/setup-rust-toolchain sets some default RUSTFLAGS + RUSTFLAGS: "" jobs: lint: @@ -22,6 +24,7 @@ jobs: - nightly-2023-01-13 # Check for breakage on latest nightly - nightly + # But if latest nightly fails, allow the workflow to continue continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest From 0f2add4c6d98d7b9353ef7d503b3afaadadf3994 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 14:01:02 -0400 Subject: [PATCH 08/33] Try to fix PATH for devkitarm tools --- .github/actions/setup/action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 1833988..30da46e 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -41,3 +41,8 @@ runs: args: >- --git https://github.com/rust3ds/cargo-3ds --rev 5a06e64307499ffe681453e7d88d7ee986054eb7 + + - name: Set PATH to include devkitARM + shell: bash + # For some reason devkitARM/bin is not part of the default PATH in the container + run: echo "${DEVKITARM}/bin" >> $GITHUB_PATH From c40cf5a94e13f202188a5cd708dc201194aa342f Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 14:14:56 -0400 Subject: [PATCH 09/33] Deduplicate warnings from lint vs build jobs --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ff1525..20a22ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,12 @@ jobs: with: toolchain: ${{ matrix.toolchain }} + - name: Hide duplicate warnings from lint job + if: ${{ matrix.toolchain == 'nightly' }} + run: | + echo "::remove-matcher owner=clippy::" + echo "::remove-matcher owner=rustfmt::" + - name: Check formatting run: cargo fmt --all --verbose -- --check @@ -64,6 +70,9 @@ jobs: with: toolchain: ${{ matrix.toolchain }} + - name: Hide duplicated warnings from lint job + run: echo "::remove-matcher owner=clippy::" + - name: Build doc tests run: cargo 3ds test --doc --verbose From 5ad6708bb64061a07d08beddceee90e05a0e4219 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 5 Apr 2023 20:35:13 +0200 Subject: [PATCH 10/33] Update for linker-fix-3ds rename --- ctru-rs/Cargo.toml | 2 +- ctru-rs/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ctru-rs/Cargo.toml b/ctru-rs/Cargo.toml index d8b095a..a7a160c 100644 --- a/ctru-rs/Cargo.toml +++ b/ctru-rs/Cargo.toml @@ -15,7 +15,7 @@ name = "ctru" cfg-if = "1.0" ctru-sys = { path = "../ctru-sys", version = "21.2" } const-zero = "0.1.0" -linker-fix-3ds = { git = "https://github.com/rust3ds/rust-linker-fix-3ds.git" } +shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" } pthread-3ds = { git = "https://github.com/rust3ds/pthread-3ds.git" } libc = "0.2.121" bitflags = "1.0.0" diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index e733d5a..5ead8b6 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -8,7 +8,7 @@ #![test_runner(test_runner::run)] // Nothing is imported from these crates but their inclusion here assures correct linking of the missing implementations. -extern crate linker_fix_3ds; +extern crate shim_3ds; extern crate pthread_3ds; #[no_mangle] From ca3a2de6a6cdf491dd05264bab6ad88e98821aec Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 5 Apr 2023 20:41:31 +0200 Subject: [PATCH 11/33] fmt --- ctru-rs/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 5ead8b6..1370097 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -8,8 +8,8 @@ #![test_runner(test_runner::run)] // Nothing is imported from these crates but their inclusion here assures correct linking of the missing implementations. -extern crate shim_3ds; extern crate pthread_3ds; +extern crate shim_3ds; #[no_mangle] #[cfg(feature = "big-stack")] From 8334221f521b76a34abc3c896ac0e95eee8f2d3d Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Sat, 8 Apr 2023 14:17:08 +0200 Subject: [PATCH 12/33] Compilation error when romfs can't be found --- ctru-rs/src/services/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index 6b9e115..ec554cb 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -34,6 +34,8 @@ cfg_if::cfg_if! { //! [package.metadata.cargo-3ds] //! romfs_dir = "romfs" //! ``` + + compile_error!("romfs feature is enabled but no romfs found!"); } } } From 78ba904ac0d1e3841e25ef98ea43719620ddde33 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Sat, 8 Apr 2023 15:04:42 +0200 Subject: [PATCH 13/33] fmt --- ctru-rs/src/services/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index ec554cb..c466f04 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -34,7 +34,7 @@ cfg_if::cfg_if! { //! [package.metadata.cargo-3ds] //! romfs_dir = "romfs" //! ``` - + compile_error!("romfs feature is enabled but no romfs found!"); } } From d3134f68f66870b492537e10dfe5fd6d3e1e372f Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Sat, 8 Apr 2023 20:20:01 +0200 Subject: [PATCH 14/33] Compilation error only if feature is set --- ctru-rs/src/services/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index c466f04..2c51d10 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -34,7 +34,9 @@ cfg_if::cfg_if! { //! [package.metadata.cargo-3ds] //! romfs_dir = "romfs" //! ``` - + + // If the feature is set, but no "romfs" directory was found: send an error during compilation. + #[cfg(feature = "romfs")] compile_error!("romfs feature is enabled but no romfs found!"); } } From 5a21920530fe6b829d09fead92e6234386957b2f Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Sat, 8 Apr 2023 20:21:38 +0200 Subject: [PATCH 15/33] fmt --- ctru-rs/src/services/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index 2c51d10..1d31dea 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -34,7 +34,7 @@ cfg_if::cfg_if! { //! [package.metadata.cargo-3ds] //! romfs_dir = "romfs" //! ``` - + // If the feature is set, but no "romfs" directory was found: send an error during compilation. #[cfg(feature = "romfs")] compile_error!("romfs feature is enabled but no romfs found!"); From 3a8b05054f1363b89d292c73d6a2e4585851203d Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Fri, 14 Apr 2023 14:50:45 -0400 Subject: [PATCH 16/33] Update cargo-3ds hash to latest --- .github/actions/setup/action.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 30da46e..a86d6f6 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -36,11 +36,9 @@ runs: command: install # TODO: this should probably just be a released version from crates.io # once cargo-3ds gets published somewhere... - # - # also switch to master hash once feature/doctests gets merged args: >- --git https://github.com/rust3ds/cargo-3ds - --rev 5a06e64307499ffe681453e7d88d7ee986054eb7 + --rev 78a652fdfb01e2614a792d1a56b10c980ee1dae9 - name: Set PATH to include devkitARM shell: bash From 7d70add8f317caea68e9ff3a64f17a3c150f3ef1 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Fri, 14 Apr 2023 15:08:37 -0400 Subject: [PATCH 17/33] Fix mutability issues after merge of master --- ctru-rs/src/services/fs.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 962e048..e3f45b0 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -103,7 +103,7 @@ pub struct Fs(()); /// ```no_run /// use ctru::services::fs::Fs; /// -/// let fs = Fs::init().unwrap(); +/// let mut fs = Fs::init().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap(); /// ``` pub struct Archive { @@ -129,10 +129,10 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::init()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// -/// let mut file = File::create(&sdmc, "/foo.txt")?; +/// let mut file = File::create(&mut sdmc, "/foo.txt")?; /// file.write_all(b"Hello, world!")?; /// # /// # Ok(()) @@ -148,8 +148,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::init()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// /// let mut file = File::open(&sdmc, "/foo.txt")?; /// let mut contents = String::new(); @@ -171,8 +171,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::init()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// /// let file = File::open(&sdmc, "/foo.txt")?; /// let mut buf_reader = BufReader::new(file); @@ -227,8 +227,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let fs = Fs::init().unwrap(); -/// let sdmc_archive = fs.sdmc().unwrap(); +/// let mut fs = Fs::init().unwrap(); +/// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .archive(&sdmc_archive) @@ -242,8 +242,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let fs = Fs::init().unwrap(); -/// let sdmc_archive = fs.sdmc().unwrap(); +/// let mut fs = Fs::init().unwrap(); +/// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .write(true) @@ -369,8 +369,8 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let fs = Fs::init().unwrap(); - /// let sdmc_archive = fs.sdmc().unwrap(); + /// let mut fs = Fs::init().unwrap(); + /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let mut f = File::open(&sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn open>(arch: &Archive, path: P) -> IoResult { @@ -398,9 +398,9 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let fs = Fs::init().unwrap(); - /// let sdmc_archive = fs.sdmc().unwrap(); - /// let mut f = File::create(&sdmc_archive, "/foo.txt").unwrap(); + /// let mut fs = Fs::init().unwrap(); + /// let mut sdmc_archive = fs.sdmc().unwrap(); + /// let mut f = File::create(&mut sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn create>(arch: &mut Archive, path: P) -> IoResult { OpenOptions::new() From ff08dd95456b3b6491bfcbe6475275ab1245d66c Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 09:59:55 +0200 Subject: [PATCH 18/33] Renamed init functions to new --- ctru-rs/examples/audio-filters.rs | 10 +++---- ctru-rs/examples/buttons.rs | 8 +++--- ctru-rs/examples/camera-image.rs | 10 +++---- ctru-rs/examples/file-explorer.rs | 14 +++++----- ctru-rs/examples/futures-basic.rs | 8 +++--- ctru-rs/examples/futures-tokio.rs | 8 +++--- ctru-rs/examples/gfx-3d-mode.rs | 8 +++--- ctru-rs/examples/gfx-wide-mode.rs | 10 +++---- ctru-rs/examples/graphics-bitmap.rs | 8 +++--- ctru-rs/examples/hashmaps.rs | 8 +++--- ctru-rs/examples/hello-both-screens.rs | 10 +++---- ctru-rs/examples/hello-world.rs | 8 +++--- ctru-rs/examples/linear-memory.rs | 8 +++--- ctru-rs/examples/mii-selector.rs | 10 +++---- ctru-rs/examples/network-sockets.rs | 10 +++---- ctru-rs/examples/output-3dslink.rs | 8 +++--- ctru-rs/examples/romfs.rs | 10 +++---- ctru-rs/examples/software-keyboard.rs | 10 +++---- ctru-rs/examples/system-configuration.rs | 10 +++---- ctru-rs/examples/thread-basic.rs | 8 +++--- ctru-rs/examples/thread-info.rs | 8 +++--- ctru-rs/examples/thread-locals.rs | 8 +++--- ctru-rs/examples/time-rtc.rs | 8 +++--- ctru-rs/examples/title-info.rs | 12 ++++----- ctru-rs/src/applets/mii_selector.rs | 4 +-- ctru-rs/src/applets/swkbd.rs | 4 +-- ctru-rs/src/console.rs | 2 +- ctru-rs/src/lib.rs | 2 +- ctru-rs/src/services/am.rs | 2 +- ctru-rs/src/services/apt.rs | 2 +- ctru-rs/src/services/cam.rs | 2 +- ctru-rs/src/services/cfgu.rs | 2 +- ctru-rs/src/services/fs.rs | 34 ++++++++++++------------ ctru-rs/src/services/gfx.rs | 6 ++--- ctru-rs/src/services/hid.rs | 2 +- ctru-rs/src/services/ndsp/mod.rs | 2 +- ctru-rs/src/services/romfs.rs | 4 +-- ctru-rs/src/services/soc.rs | 6 ++--- ctru-rs/src/services/sslc.rs | 2 +- ctru-rs/src/test_runner.rs | 8 +++--- 40 files changed, 152 insertions(+), 152 deletions(-) diff --git a/ctru-rs/examples/audio-filters.rs b/ctru-rs/examples/audio-filters.rs index 327ede4..e425793 100644 --- a/ctru-rs/examples/audio-filters.rs +++ b/ctru-rs/examples/audio-filters.rs @@ -37,10 +37,10 @@ fn fill_buffer(audio_data: &mut [u8], frequency: f32) { fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); let mut note: usize = 4; @@ -68,7 +68,7 @@ fn main() { let mut wave_info1 = Wave::new(audio_data1, AudioFormat::PCM16Stereo, false); let mut wave_info2 = Wave::new(audio_data2, AudioFormat::PCM16Stereo, false); - let mut ndsp = Ndsp::init().expect("Couldn't obtain NDSP controller"); + let mut ndsp = Ndsp::new().expect("Couldn't obtain NDSP controller"); // This line isn't needed since the default NDSP configuration already sets the output mode to `Stereo` ndsp.set_output_mode(OutputMode::Stereo); diff --git a/ctru-rs/examples/buttons.rs b/ctru-rs/examples/buttons.rs index 39f24d9..5645915 100644 --- a/ctru-rs/examples/buttons.rs +++ b/ctru-rs/examples/buttons.rs @@ -3,10 +3,10 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let apt = Apt::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let gfx = Gfx::init().unwrap(); - let console = Console::init(gfx.top_screen.borrow_mut()); + let apt = Apt::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let gfx = Gfx::new().unwrap(); + let console = Console::new(gfx.top_screen.borrow_mut()); println!("Hi there! Try pressing a button"); println!("\x1b[29;16HPress Start to exit"); diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 46a96d4..88526be 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -16,22 +16,22 @@ const WAIT_TIMEOUT: Duration = Duration::from_millis(300); fn main() { ctru::use_panic_handler(); - let apt = Apt::init().expect("Failed to initialize Apt service."); - let mut hid = Hid::init().expect("Failed to initialize Hid service."); - let gfx = Gfx::init().expect("Failed to initialize GFX service."); + let apt = Apt::new().expect("Failed to initialize Apt service."); + let mut hid = Hid::new().expect("Failed to initialize Hid service."); + let gfx = Gfx::new().expect("Failed to initialize GFX service."); gfx.top_screen.borrow_mut().set_double_buffering(true); gfx.top_screen .borrow_mut() .set_framebuffer_format(FramebufferFormat::Rgb565); gfx.bottom_screen.borrow_mut().set_double_buffering(false); - let _console = Console::init(gfx.bottom_screen.borrow_mut()); + let _console = Console::new(gfx.bottom_screen.borrow_mut()); let mut keys_down; println!("Initializing camera"); - let mut cam = Cam::init().expect("Failed to initialize CAM service."); + let mut cam = Cam::new().expect("Failed to initialize CAM service."); { let camera = &mut cam.outer_right_cam; diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 5b256c9..8a3d639 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -11,14 +11,14 @@ use std::path::{Path, PathBuf}; fn main() { ctru::use_panic_handler(); - let apt = Apt::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let gfx = Gfx::init().unwrap(); + let apt = Apt::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let gfx = Gfx::new().unwrap(); #[cfg(all(feature = "romfs", romfs_exists))] - let _romfs = ctru::services::romfs::RomFS::init().unwrap(); + let _romfs = ctru::services::romfs::RomFS::new().unwrap(); - FileExplorer::init(&apt, &mut hid, &gfx).run(); + FileExplorer::new(&apt, &mut hid, &gfx).run(); } struct FileExplorer<'a> { @@ -32,10 +32,10 @@ struct FileExplorer<'a> { } impl<'a> FileExplorer<'a> { - fn init(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self { + fn new(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self { let mut top_screen = gfx.top_screen.borrow_mut(); top_screen.set_wide_mode(true); - let console = Console::init(top_screen); + let console = Console::new(top_screen); FileExplorer { apt, diff --git a/ctru-rs/examples/futures-basic.rs b/ctru-rs/examples/futures-basic.rs index ee2e3be..cb6a804 100644 --- a/ctru-rs/examples/futures-basic.rs +++ b/ctru-rs/examples/futures-basic.rs @@ -15,10 +15,10 @@ use std::os::horizon::thread::BuilderExt; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); // Give ourselves up to 30% of the system core's time apt.set_app_cpu_time_limit(30) diff --git a/ctru-rs/examples/futures-tokio.rs b/ctru-rs/examples/futures-tokio.rs index cbb446d..e42e9e9 100644 --- a/ctru-rs/examples/futures-tokio.rs +++ b/ctru-rs/examples/futures-tokio.rs @@ -8,10 +8,10 @@ use std::time::Duration; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); // Give ourselves up to 30% of the system core's time apt.set_app_cpu_time_limit(30) diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index 13b4d3c..c5b194c 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -12,10 +12,10 @@ static ZERO: &[u8] = &[0; IMAGE.len()]; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.bottom_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.bottom_screen.borrow_mut()); println!("Press Start to exit.\nPress A to switch sides (be sure to have 3D mode enabled)."); diff --git a/ctru-rs/examples/gfx-wide-mode.rs b/ctru-rs/examples/gfx-wide-mode.rs index f781c89..53da6ea 100644 --- a/ctru-rs/examples/gfx-wide-mode.rs +++ b/ctru-rs/examples/gfx-wide-mode.rs @@ -3,10 +3,10 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let apt = Apt::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let gfx = Gfx::init().unwrap(); - let mut console = Console::init(gfx.top_screen.borrow_mut()); + let apt = Apt::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let gfx = Gfx::new().unwrap(); + let mut console = Console::new(gfx.top_screen.borrow_mut()); println!("Press A to enable/disable wide screen mode."); @@ -23,7 +23,7 @@ fn main() { let wide_mode = gfx.top_screen.borrow().is_wide(); gfx.top_screen.borrow_mut().set_wide_mode(!wide_mode); - console = Console::init(gfx.top_screen.borrow_mut()); + console = Console::new(gfx.top_screen.borrow_mut()); println!("Press A to enable/disable wide screen mode."); } diff --git a/ctru-rs/examples/graphics-bitmap.rs b/ctru-rs/examples/graphics-bitmap.rs index ebbf53e..55d4903 100644 --- a/ctru-rs/examples/graphics-bitmap.rs +++ b/ctru-rs/examples/graphics-bitmap.rs @@ -17,10 +17,10 @@ static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb"); fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); println!("\x1b[21;16HPress Start to exit."); diff --git a/ctru-rs/examples/hashmaps.rs b/ctru-rs/examples/hashmaps.rs index 87ad8be..e3726eb 100644 --- a/ctru-rs/examples/hashmaps.rs +++ b/ctru-rs/examples/hashmaps.rs @@ -8,10 +8,10 @@ fn main() { // HashMaps generate hashes thanks to the 3DS' cryptografically secure generator. // This generator is only active when activating the `PS` service. // This service is automatically initialized. - let apt = Apt::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let gfx = Gfx::init().unwrap(); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let apt = Apt::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let gfx = Gfx::new().unwrap(); + let _console = Console::new(gfx.top_screen.borrow_mut()); let mut map = std::collections::HashMap::new(); map.insert("A Key!", 102); diff --git a/ctru-rs/examples/hello-both-screens.rs b/ctru-rs/examples/hello-both-screens.rs index 7395967..fa2e16d 100644 --- a/ctru-rs/examples/hello-both-screens.rs +++ b/ctru-rs/examples/hello-both-screens.rs @@ -3,16 +3,16 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let apt = Apt::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let gfx = Gfx::init().unwrap(); + let apt = Apt::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let gfx = Gfx::new().unwrap(); // Start a console on the top screen - let top_screen = Console::init(gfx.top_screen.borrow_mut()); + let top_screen = Console::new(gfx.top_screen.borrow_mut()); // Start a console on the bottom screen. // The most recently initialized console will be active by default - let bottom_screen = Console::init(gfx.bottom_screen.borrow_mut()); + let bottom_screen = Console::new(gfx.bottom_screen.borrow_mut()); // Let's print on the top screen first top_screen.select(); diff --git a/ctru-rs/examples/hello-world.rs b/ctru-rs/examples/hello-world.rs index 697ec7c..345ee2e 100644 --- a/ctru-rs/examples/hello-world.rs +++ b/ctru-rs/examples/hello-world.rs @@ -5,10 +5,10 @@ use std::io::BufWriter; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); let out = b"Hello fellow Rustaceans, I'm on the Nintendo 3DS!"; let width = 24; diff --git a/ctru-rs/examples/linear-memory.rs b/ctru-rs/examples/linear-memory.rs index b3afced..2373941 100644 --- a/ctru-rs/examples/linear-memory.rs +++ b/ctru-rs/examples/linear-memory.rs @@ -6,10 +6,10 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); let linear_space_before = LinearAllocator::free_space(); diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index ef7d7d3..9ef86f6 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -4,12 +4,12 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); - let mut mii_selector = MiiSelector::init(); + let mut mii_selector = MiiSelector::new(); mii_selector.set_initial_index(3); mii_selector.blacklist_user_mii(0.into()); mii_selector.set_title("Great Mii Selector!"); diff --git a/ctru-rs/examples/network-sockets.rs b/ctru-rs/examples/network-sockets.rs index ca2d163..bbea510 100644 --- a/ctru-rs/examples/network-sockets.rs +++ b/ctru-rs/examples/network-sockets.rs @@ -7,14 +7,14 @@ use std::time::Duration; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().unwrap(); - let _console = Console::init(gfx.top_screen.borrow_mut()); - let mut hid = Hid::init().unwrap(); - let apt = Apt::init().unwrap(); + let gfx = Gfx::new().unwrap(); + let _console = Console::new(gfx.top_screen.borrow_mut()); + let mut hid = Hid::new().unwrap(); + let apt = Apt::new().unwrap(); println!("\nlibctru sockets demo\n"); - let soc = Soc::init().unwrap(); + let soc = Soc::new().unwrap(); let server = TcpListener::bind("0.0.0.0:80").unwrap(); server.set_nonblocking(true).unwrap(); diff --git a/ctru-rs/examples/output-3dslink.rs b/ctru-rs/examples/output-3dslink.rs index 1fe0c6a..5649e6e 100644 --- a/ctru-rs/examples/output-3dslink.rs +++ b/ctru-rs/examples/output-3dslink.rs @@ -13,11 +13,11 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); - let mut soc = Soc::init().expect("Couldn't obtain SOC controller"); + let mut soc = Soc::new().expect("Couldn't obtain SOC controller"); soc.redirect_to_3dslink(true, true) .expect("unable to redirect stdout/err to 3dslink server"); diff --git a/ctru-rs/examples/romfs.rs b/ctru-rs/examples/romfs.rs index c729c32..f92d81d 100644 --- a/ctru-rs/examples/romfs.rs +++ b/ctru-rs/examples/romfs.rs @@ -3,17 +3,17 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); cfg_if::cfg_if! { // Run this code if RomFS are wanted and available // This never fails as `ctru-rs` examples inherit all of the `ctru` features, // but it might if a normal user application wasn't setup correctly if #[cfg(all(feature = "romfs", romfs_exists))] { - let _romfs = ctru::services::romfs::RomFS::init().unwrap(); + let _romfs = ctru::services::romfs::RomFS::new().unwrap(); let f = std::fs::read_to_string("romfs:/test-file.txt").unwrap(); println!("Contents of test-file.txt: \n{f}\n"); diff --git a/ctru-rs/examples/software-keyboard.rs b/ctru-rs/examples/software-keyboard.rs index 954fdd0..77e877a 100644 --- a/ctru-rs/examples/software-keyboard.rs +++ b/ctru-rs/examples/software-keyboard.rs @@ -4,10 +4,10 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let apt = Apt::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let gfx = Gfx::init().unwrap(); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let apt = Apt::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let gfx = Gfx::new().unwrap(); + let _console = Console::new(gfx.top_screen.borrow_mut()); println!("Press A to enter some text or press Start to quit"); @@ -20,7 +20,7 @@ fn main() { if hid.keys_down().contains(KeyPad::A) { // Prepares a software keyboard with two buttons: One to cancel input and one - // to accept it. You can also use `Swkbd::init()` to launch the keyboard in different + // to accept it. You can also use `Swkbd::new()` to launch the keyboard in different // configurations. let mut keyboard = Swkbd::default(); diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index cd81a02..cb1e00f 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -4,11 +4,11 @@ use ctru::services::cfgu::Cfgu; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let cfgu = Cfgu::init().expect("Couldn't obtain CFGU controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let cfgu = Cfgu::new().expect("Couldn't obtain CFGU controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); println!("\x1b[0;0HRegion: {:?}", cfgu.region().unwrap()); println!("\x1b[10;0HLanguage: {:?}", cfgu.language().unwrap()); diff --git a/ctru-rs/examples/thread-basic.rs b/ctru-rs/examples/thread-basic.rs index 73be659..cc494f6 100644 --- a/ctru-rs/examples/thread-basic.rs +++ b/ctru-rs/examples/thread-basic.rs @@ -8,10 +8,10 @@ use std::time::Duration; fn main() { ctru::use_panic_handler(); - let apt = Apt::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let gfx = Gfx::init().unwrap(); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let apt = Apt::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let gfx = Gfx::new().unwrap(); + let _console = Console::new(gfx.top_screen.borrow_mut()); let prio = std::os::horizon::thread::current_priority(); println!("Main thread prio: {}\n", prio); diff --git a/ctru-rs/examples/thread-info.rs b/ctru-rs/examples/thread-info.rs index 968e858..9ab04fe 100644 --- a/ctru-rs/examples/thread-info.rs +++ b/ctru-rs/examples/thread-info.rs @@ -9,10 +9,10 @@ use std::os::horizon::thread::BuilderExt; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); // Give ourselves up to 30% of the system core's time apt.set_app_cpu_time_limit(30) diff --git a/ctru-rs/examples/thread-locals.rs b/ctru-rs/examples/thread-locals.rs index 09e2082..d2a5e3e 100644 --- a/ctru-rs/examples/thread-locals.rs +++ b/ctru-rs/examples/thread-locals.rs @@ -12,11 +12,11 @@ std::thread_local! { fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); gfx.top_screen.borrow_mut().set_wide_mode(true); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let _console = Console::new(gfx.top_screen.borrow_mut()); // Give ourselves up to 30% of the system core's time apt.set_app_cpu_time_limit(30) diff --git a/ctru-rs/examples/time-rtc.rs b/ctru-rs/examples/time-rtc.rs index 86db923..66c9a63 100644 --- a/ctru-rs/examples/time-rtc.rs +++ b/ctru-rs/examples/time-rtc.rs @@ -3,11 +3,11 @@ use ctru::prelude::*; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); - let _console = Console::init(gfx.top_screen.borrow_mut()); + let _console = Console::new(gfx.top_screen.borrow_mut()); print!("\x1b[30;16HPress Start to exit."); diff --git a/ctru-rs/examples/title-info.rs b/ctru-rs/examples/title-info.rs index a18534e..07ba9f4 100644 --- a/ctru-rs/examples/title-info.rs +++ b/ctru-rs/examples/title-info.rs @@ -5,12 +5,12 @@ use ctru::services::fs::FsMediaType; fn main() { ctru::use_panic_handler(); - let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let mut hid = Hid::init().expect("Couldn't obtain HID controller"); - let apt = Apt::init().expect("Couldn't obtain APT controller"); - let am = Am::init().expect("Couldn't obtain AM controller"); - let top_screen = Console::init(gfx.top_screen.borrow_mut()); - let bottom_screen = Console::init(gfx.bottom_screen.borrow_mut()); + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + let am = Am::new().expect("Couldn't obtain AM controller"); + let top_screen = Console::new(gfx.top_screen.borrow_mut()); + let bottom_screen = Console::new(gfx.bottom_screen.borrow_mut()); let sd_count = am .title_count(FsMediaType::Sd) diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index 8d289ee..69175a2 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -41,7 +41,7 @@ bitflags! { /// ``` /// use ctru::applets::mii_selector::MiiSelector; /// -/// let mut mii_selector = MiiSelector::init(); +/// let mut mii_selector = MiiSelector::new(); /// mii_selector.set_title("Example Mii selector"); /// /// let result = mii_selector.launch().unwrap(); @@ -68,7 +68,7 @@ pub enum MiiLaunchError { impl MiiSelector { /// Initializes a Mii Selector - pub fn init() -> Self { + pub fn new() -> Self { let mut config = Box::::default(); unsafe { ctru_sys::miiSelectorInit(config.as_mut()); diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 0af7dee..178a86e 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -89,7 +89,7 @@ bitflags! { impl Swkbd { /// Initializes a software keyboard of the specified type and the chosen number of buttons /// (from 1-3). - pub fn init(keyboard_type: Kind, num_buttons: i32) -> Self { + pub fn new(keyboard_type: Kind, num_buttons: i32) -> Self { unsafe { let mut state = Box::::default(); swkbdInit(state.as_mut(), keyboard_type.into(), num_buttons, -1); @@ -207,7 +207,7 @@ impl Swkbd { impl Default for Swkbd { fn default() -> Self { - Swkbd::init(Kind::Normal, 2) + Swkbd::new(Kind::Normal, 2) } } diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index c0a8765..73d3952 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -16,7 +16,7 @@ impl<'screen> Console<'screen> { /// Initialize a console on the chosen screen, overwriting whatever was on the screen /// previously (including other consoles). The new console is automatically selected for /// printing. - pub fn init(screen: RefMut<'screen, dyn Screen>) -> Self { + pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self { let mut context = Box::::default(); unsafe { consoleInit(screen.as_raw(), context.as_mut()) }; diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 504b66f..210d37f 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -54,7 +54,7 @@ fn panic_hook_setup() { if main_thread == std::thread::current().id() && console::Console::exists() { println!("\nPress SELECT to exit the software"); - match Hid::init() { + match Hid::new() { Ok(mut hid) => loop { hid.scan_input(); let keys = hid.keys_down(); diff --git a/ctru-rs/src/services/am.rs b/ctru-rs/src/services/am.rs index ada179e..6fcee8c 100644 --- a/ctru-rs/src/services/am.rs +++ b/ctru-rs/src/services/am.rs @@ -61,7 +61,7 @@ impl<'a> Title<'a> { pub struct Am(()); impl Am { - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { unsafe { ResultCode(ctru_sys::amInit())?; Ok(Am(())) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index aa1dd28..f7731be 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -3,7 +3,7 @@ use crate::error::ResultCode; pub struct Apt(()); impl Apt { - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { unsafe { ResultCode(ctru_sys::aptInit())?; Ok(Apt(())) diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 52ce926..261dbd3 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -770,7 +770,7 @@ impl Cam { /// This function will return an error if the service was unable to be initialized. /// Since this service requires no special or elevated permissions, errors are /// rare in practice. - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { unsafe { ResultCode(ctru_sys::camInit())?; Ok(Cam { diff --git a/ctru-rs/src/services/cfgu.rs b/ctru-rs/src/services/cfgu.rs index 3f268c7..90edf44 100644 --- a/ctru-rs/src/services/cfgu.rs +++ b/ctru-rs/src/services/cfgu.rs @@ -61,7 +61,7 @@ impl Cfgu { /// ctrulib services are reference counted, so this function may be called /// as many times as desired and the service will not exit until all /// instances of Cfgu drop out of scope. - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { ResultCode(unsafe { ctru_sys::cfguInit() })?; Ok(Cfgu(())) } diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index e3f45b0..e59b02b 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -103,7 +103,7 @@ pub struct Fs(()); /// ```no_run /// use ctru::services::fs::Fs; /// -/// let mut fs = Fs::init().unwrap(); +/// let fs = Fs::new().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap(); /// ``` pub struct Archive { @@ -129,8 +129,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::init()?; -/// let mut sdmc = fs.sdmc()?; +/// let fs = Fs::new()?; +/// let sdmc = fs.sdmc()?; /// /// let mut file = File::create(&mut sdmc, "/foo.txt")?; /// file.write_all(b"Hello, world!")?; @@ -148,8 +148,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::init()?; -/// let mut sdmc = fs.sdmc()?; +/// let fs = Fs::new()?; +/// let sdmc = fs.sdmc()?; /// /// let mut file = File::open(&sdmc, "/foo.txt")?; /// let mut contents = String::new(); @@ -171,8 +171,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::init()?; -/// let mut sdmc = fs.sdmc()?; +/// let fs = Fs::new()?; +/// let sdmc = fs.sdmc()?; /// /// let file = File::open(&sdmc, "/foo.txt")?; /// let mut buf_reader = BufReader::new(file); @@ -227,8 +227,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let mut fs = Fs::init().unwrap(); -/// let mut sdmc_archive = fs.sdmc().unwrap(); +/// let fs = Fs::new().unwrap(); +/// let sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .archive(&sdmc_archive) @@ -242,8 +242,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let mut fs = Fs::init().unwrap(); -/// let mut sdmc_archive = fs.sdmc().unwrap(); +/// let fs = Fs::new().unwrap(); +/// let sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .write(true) @@ -316,7 +316,7 @@ impl Fs { /// ctrulib services are reference counted, so this function may be called /// as many times as desired and the service will not exit until all /// instances of Fs drop out of scope. - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { unsafe { let r = ctru_sys::fsInit(); if r < 0 { @@ -369,8 +369,8 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let mut fs = Fs::init().unwrap(); - /// let mut sdmc_archive = fs.sdmc().unwrap(); + /// let fs = Fs::new().unwrap(); + /// let sdmc_archive = fs.sdmc().unwrap(); /// let mut f = File::open(&sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn open>(arch: &Archive, path: P) -> IoResult { @@ -398,9 +398,9 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let mut fs = Fs::init().unwrap(); - /// let mut sdmc_archive = fs.sdmc().unwrap(); - /// let mut f = File::create(&mut sdmc_archive, "/foo.txt").unwrap(); + /// let fs = Fs::new().unwrap(); + /// let sdmc_archive = fs.sdmc().unwrap(); + /// let mut f = File::create(&sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn create>(arch: &mut Archive, path: P) -> IoResult { OpenOptions::new() diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 40d4740..87be464 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -131,7 +131,7 @@ impl Gfx { /// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom /// screens /// - /// Use `Gfx::init()` instead of this function to initialize the module with default parameters + /// Use `Gfx::new()` instead of this function to initialize the module with default parameters pub fn with_formats( top_fb_fmt: FramebufferFormat, bottom_fb_fmt: FramebufferFormat, @@ -158,7 +158,7 @@ impl Gfx { /// Creates a new [Gfx] instance with default init values /// It's the same as calling: /// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)` - pub fn init() -> Result { + pub fn new() -> Result { Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) } @@ -294,6 +294,6 @@ mod tests { #[test] fn gfx_duplicate() { // We don't need to build a `Gfx` because the test runner has one already - assert!(matches!(Gfx::init(), Err(Error::ServiceAlreadyActive))); + assert!(matches!(Gfx::new(), Err(Error::ServiceAlreadyActive))); } } diff --git a/ctru-rs/src/services/hid.rs b/ctru-rs/src/services/hid.rs index 31dd4d9..9577f42 100644 --- a/ctru-rs/src/services/hid.rs +++ b/ctru-rs/src/services/hid.rs @@ -61,7 +61,7 @@ pub struct CirclePosition(ctru_sys::circlePosition); /// Since this service requires no special or elevated permissions, errors are /// rare in practice. impl Hid { - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { unsafe { ResultCode(ctru_sys::hidInit())?; Ok(Hid(())) diff --git a/ctru-rs/src/services/ndsp/mod.rs b/ctru-rs/src/services/ndsp/mod.rs index fa93cf6..3fff3b8 100644 --- a/ctru-rs/src/services/ndsp/mod.rs +++ b/ctru-rs/src/services/ndsp/mod.rs @@ -80,7 +80,7 @@ impl Ndsp { /// /// This function will return an error if an instance of the `Ndsp` struct already exists /// or if there are any issues during initialization. - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { let _service_handler = ServiceReference::new( &NDSP_ACTIVE, false, diff --git a/ctru-rs/src/services/romfs.rs b/ctru-rs/src/services/romfs.rs index fd022e8..49369a6 100644 --- a/ctru-rs/src/services/romfs.rs +++ b/ctru-rs/src/services/romfs.rs @@ -25,7 +25,7 @@ pub struct RomFS { static ROMFS_ACTIVE: Mutex = Mutex::new(0); impl RomFS { - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { let _service_handler = ServiceReference::new( &ROMFS_ACTIVE, true, @@ -50,7 +50,7 @@ mod tests { #[test] fn romfs_counter() { - let _romfs = RomFS::init().unwrap(); + let _romfs = RomFS::new().unwrap(); let value = *ROMFS_ACTIVE.lock().unwrap(); assert_eq!(value, 1); diff --git a/ctru-rs/src/services/soc.rs b/ctru-rs/src/services/soc.rs index c5df066..5b9c696 100644 --- a/ctru-rs/src/services/soc.rs +++ b/ctru-rs/src/services/soc.rs @@ -25,7 +25,7 @@ impl Soc { /// # Errors /// /// This function will return an error if the `Soc` service is already initialized - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { Self::init_with_buffer_size(0x100000) } @@ -107,8 +107,8 @@ mod tests { #[test] fn soc_duplicate() { - let _soc = Soc::init().unwrap(); + let _soc = Soc::new().unwrap(); - assert!(matches!(Soc::init(), Err(Error::ServiceAlreadyActive))) + assert!(matches!(Soc::new(), Err(Error::ServiceAlreadyActive))) } } diff --git a/ctru-rs/src/services/sslc.rs b/ctru-rs/src/services/sslc.rs index 99eb456..405fb9b 100644 --- a/ctru-rs/src/services/sslc.rs +++ b/ctru-rs/src/services/sslc.rs @@ -8,7 +8,7 @@ pub struct SslC(()); impl SslC { /// Initialize the service - pub fn init() -> crate::Result { + pub fn new() -> crate::Result { unsafe { ResultCode(ctru_sys::sslcInit(0))?; Ok(SslC(())) diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs index 6f157e3..713e0e6 100644 --- a/ctru-rs/src/test_runner.rs +++ b/ctru-rs/src/test_runner.rs @@ -12,13 +12,13 @@ use crate::prelude::*; /// runs all tests in series, "failing" on the first one to panic (really, the /// panic is just treated the same as any normal application panic). pub(crate) fn run(tests: &[&TestDescAndFn]) { - let gfx = Gfx::init().unwrap(); - let mut hid = Hid::init().unwrap(); - let apt = Apt::init().unwrap(); + let gfx = Gfx::new().unwrap(); + let mut hid = Hid::new().unwrap(); + let apt = Apt::new().unwrap(); let mut top_screen = gfx.top_screen.borrow_mut(); top_screen.set_wide_mode(true); - let _console = Console::init(top_screen); + let _console = Console::new(top_screen); let opts = TestOpts { force_run_in_process: true, From ae90fc3e6e8294b6bdf2caf3c21553f27332c4fe Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 11:22:23 +0200 Subject: [PATCH 19/33] Derive traits and Screen changes --- ctru-rs/examples/audio-filters.rs | 4 -- ctru-rs/examples/buttons.rs | 3 -- ctru-rs/examples/camera-image.rs | 17 ++++---- ctru-rs/examples/file-explorer.rs | 2 - ctru-rs/examples/futures-basic.rs | 2 - ctru-rs/examples/futures-tokio.rs | 2 - ctru-rs/examples/gfx-3d-mode.rs | 4 -- ctru-rs/examples/gfx-wide-mode.rs | 4 +- ctru-rs/examples/graphics-bitmap.rs | 4 +- ctru-rs/examples/hashmaps.rs | 2 - ctru-rs/examples/hello-both-screens.rs | 2 - ctru-rs/examples/hello-world.rs | 3 -- ctru-rs/examples/linear-memory.rs | 3 -- ctru-rs/examples/mii-selector.rs | 3 -- ctru-rs/examples/output-3dslink.rs | 3 -- ctru-rs/examples/romfs.rs | 3 -- ctru-rs/examples/software-keyboard.rs | 2 - ctru-rs/examples/system-configuration.rs | 3 -- ctru-rs/examples/thread-basic.rs | 2 - ctru-rs/examples/thread-info.rs | 4 +- ctru-rs/examples/thread-locals.rs | 2 - ctru-rs/examples/time-rtc.rs | 4 -- ctru-rs/examples/title-info.rs | 4 -- ctru-rs/src/applets/mii_selector.rs | 44 ++++++++++---------- ctru-rs/src/applets/swkbd.rs | 9 ++-- ctru-rs/src/console.rs | 4 ++ ctru-rs/src/services/am.rs | 1 + ctru-rs/src/services/cam.rs | 25 ++++++------ ctru-rs/src/services/cfgu.rs | 6 +-- ctru-rs/src/services/fs.rs | 14 +++---- ctru-rs/src/services/gfx.rs | 52 ++++++++++++------------ ctru-rs/src/services/gspgpu.rs | 4 +- ctru-rs/src/services/hid.rs | 3 +- ctru-rs/src/services/ndsp/mod.rs | 10 ++--- ctru-rs/src/services/ndsp/wave.rs | 2 +- ctru-rs/src/services/ps.rs | 4 +- ctru-rs/src/services/sslc.rs | 11 ----- ctru-rs/src/test_runner.rs | 2 - 38 files changed, 104 insertions(+), 169 deletions(-) diff --git a/ctru-rs/examples/audio-filters.rs b/ctru-rs/examples/audio-filters.rs index e425793..3ef76a6 100644 --- a/ctru-rs/examples/audio-filters.rs +++ b/ctru-rs/examples/audio-filters.rs @@ -154,10 +154,6 @@ fn main() { altern = !altern; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/examples/buttons.rs b/ctru-rs/examples/buttons.rs index 5645915..8bba6c7 100644 --- a/ctru-rs/examples/buttons.rs +++ b/ctru-rs/examples/buttons.rs @@ -63,9 +63,6 @@ fn main() { // Save our current key presses for the next frame old_keys = keys; - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 88526be..8f67b47 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -20,11 +20,10 @@ fn main() { let mut hid = Hid::new().expect("Failed to initialize Hid service."); let gfx = Gfx::new().expect("Failed to initialize GFX service."); - gfx.top_screen.borrow_mut().set_double_buffering(true); - gfx.top_screen - .borrow_mut() - .set_framebuffer_format(FramebufferFormat::Rgb565); - gfx.bottom_screen.borrow_mut().set_double_buffering(false); + let mut top_screen = gfx.top_screen.borrow_mut(); + top_screen.set_double_buffering(true); + top_screen.set_framebuffer_format(FramebufferFormat::Rgb565); + let _console = Console::new(gfx.bottom_screen.borrow_mut()); let mut keys_down; @@ -88,13 +87,15 @@ fn main() { rotate_image_to_screen( &buf, - gfx.top_screen.borrow_mut().raw_framebuffer().ptr, + top_screen.raw_framebuffer().ptr, WIDTH, HEIGHT, ); - gfx.flush_buffers(); - gfx.swap_buffers(); + // We will only flush the "camera" screen, since the other screen is handled by `Console` + top_screen.flush_buffer(); + top_screen.swap_buffers(); + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 8a3d639..6d30590 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -68,8 +68,6 @@ impl<'a> FileExplorer<'a> { self.get_input_and_run(Self::set_exact_path); } - self.gfx.flush_buffers(); - self.gfx.swap_buffers(); self.gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/futures-basic.rs b/ctru-rs/examples/futures-basic.rs index cb6a804..c41245c 100644 --- a/ctru-rs/examples/futures-basic.rs +++ b/ctru-rs/examples/futures-basic.rs @@ -68,8 +68,6 @@ fn main() { frame_count = 0; } - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/futures-tokio.rs b/ctru-rs/examples/futures-tokio.rs index e42e9e9..986e930 100644 --- a/ctru-rs/examples/futures-tokio.rs +++ b/ctru-rs/examples/futures-tokio.rs @@ -63,8 +63,6 @@ fn main() { break; } - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index c5b194c..8603a64 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -61,10 +61,6 @@ fn main() { buf.copy_from(IMAGE.as_ptr(), IMAGE.len()); } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/examples/gfx-wide-mode.rs b/ctru-rs/examples/gfx-wide-mode.rs index 53da6ea..0acf1b2 100644 --- a/ctru-rs/examples/gfx-wide-mode.rs +++ b/ctru-rs/examples/gfx-wide-mode.rs @@ -26,9 +26,7 @@ fn main() { console = Console::new(gfx.top_screen.borrow_mut()); println!("Press A to enable/disable wide screen mode."); } - - gfx.flush_buffers(); - gfx.swap_buffers(); + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/graphics-bitmap.rs b/ctru-rs/examples/graphics-bitmap.rs index 55d4903..4beacea 100644 --- a/ctru-rs/examples/graphics-bitmap.rs +++ b/ctru-rs/examples/graphics-bitmap.rs @@ -48,8 +48,8 @@ fn main() { } // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); + bottom_screen.flush_buffer(); + bottom_screen.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/hashmaps.rs b/ctru-rs/examples/hashmaps.rs index e3726eb..7d4d8c4 100644 --- a/ctru-rs/examples/hashmaps.rs +++ b/ctru-rs/examples/hashmaps.rs @@ -21,8 +21,6 @@ fn main() { println!("{map:#?}"); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/hello-both-screens.rs b/ctru-rs/examples/hello-both-screens.rs index fa2e16d..f2007f1 100644 --- a/ctru-rs/examples/hello-both-screens.rs +++ b/ctru-rs/examples/hello-both-screens.rs @@ -27,8 +27,6 @@ fn main() { println!("\x1b[29;16HPress Start to exit"); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/hello-world.rs b/ctru-rs/examples/hello-world.rs index 345ee2e..a92cb90 100644 --- a/ctru-rs/examples/hello-world.rs +++ b/ctru-rs/examples/hello-world.rs @@ -29,9 +29,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/linear-memory.rs b/ctru-rs/examples/linear-memory.rs index 2373941..e6c18dc 100644 --- a/ctru-rs/examples/linear-memory.rs +++ b/ctru-rs/examples/linear-memory.rs @@ -37,9 +37,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index 9ef86f6..d489e07 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -33,9 +33,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/output-3dslink.rs b/ctru-rs/examples/output-3dslink.rs index 5649e6e..8314efa 100644 --- a/ctru-rs/examples/output-3dslink.rs +++ b/ctru-rs/examples/output-3dslink.rs @@ -33,9 +33,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/romfs.rs b/ctru-rs/examples/romfs.rs index f92d81d..1138203 100644 --- a/ctru-rs/examples/romfs.rs +++ b/ctru-rs/examples/romfs.rs @@ -36,9 +36,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/software-keyboard.rs b/ctru-rs/examples/software-keyboard.rs index 77e877a..39b5549 100644 --- a/ctru-rs/examples/software-keyboard.rs +++ b/ctru-rs/examples/software-keyboard.rs @@ -12,8 +12,6 @@ fn main() { println!("Press A to enter some text or press Start to quit"); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index cb1e00f..001233d 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -22,9 +22,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/thread-basic.rs b/ctru-rs/examples/thread-basic.rs index cc494f6..33a8ea9 100644 --- a/ctru-rs/examples/thread-basic.rs +++ b/ctru-rs/examples/thread-basic.rs @@ -34,8 +34,6 @@ fn main() { } while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/thread-info.rs b/ctru-rs/examples/thread-info.rs index 9ab04fe..2316f16 100644 --- a/ctru-rs/examples/thread-info.rs +++ b/ctru-rs/examples/thread-info.rs @@ -44,9 +44,7 @@ fn main() { if hid.keys_down().contains(KeyPad::KEY_START) { break; } - - gfx.flush_buffers(); - gfx.swap_buffers(); + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/thread-locals.rs b/ctru-rs/examples/thread-locals.rs index d2a5e3e..80d8508 100644 --- a/ctru-rs/examples/thread-locals.rs +++ b/ctru-rs/examples/thread-locals.rs @@ -61,8 +61,6 @@ fn main() { break; } - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/time-rtc.rs b/ctru-rs/examples/time-rtc.rs index 66c9a63..377fd5c 100644 --- a/ctru-rs/examples/time-rtc.rs +++ b/ctru-rs/examples/time-rtc.rs @@ -36,10 +36,6 @@ fn main() { println!("\x1b[1;1H{hours:0>2}:{minutes:0>2}:{seconds:0>2}"); println!("{weekday} {month} {day} {year}"); - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/examples/title-info.rs b/ctru-rs/examples/title-info.rs index 07ba9f4..fee5cb6 100644 --- a/ctru-rs/examples/title-info.rs +++ b/ctru-rs/examples/title-info.rs @@ -106,10 +106,6 @@ fn main() { refresh = false; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index 69175a2..e7d0559 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -8,14 +8,14 @@ use std::ffi::CString; /// Index of a Mii used to configure some parameters of the Mii Selector /// Can be either a single index, or _all_ Miis -#[derive(Debug, Clone)] -pub enum MiiConfigIndex { +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub enum MiiIndex { Index(u32), All, } /// The type of a Mii with their respective data -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Eq, PartialEq)] pub enum MiiType { Guest { index: u32, name: String }, User, @@ -54,7 +54,7 @@ pub struct MiiSelector { /// Return value from a MiiSelector's launch #[non_exhaustive] #[derive(Clone, Debug)] -pub struct MiiSelectorReturn { +pub struct SelectionResult { pub mii_data: MiiData, pub is_mii_selected: bool, pub mii_type: MiiType, @@ -62,7 +62,7 @@ pub struct MiiSelectorReturn { /// Error type for the Mii selector #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum MiiLaunchError { +pub enum LaunchError { InvalidChecksum, } @@ -94,40 +94,40 @@ impl MiiSelector { } /// Whitelist a guest Mii - pub fn whitelist_guest_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn whitelist_guest_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, }; unsafe { ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), index) } } /// Blacklist a guest Mii - pub fn blacklist_guest_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn blacklist_guest_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, }; unsafe { ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), index) } } /// Whitelist a user Mii - pub fn whitelist_user_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn whitelist_user_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, }; unsafe { ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), index) } } /// Blacklist a user Mii - pub fn blacklist_user_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn blacklist_user_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, }; unsafe { ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), index) } @@ -143,24 +143,24 @@ impl MiiSelector { /// Launch the Mii Selector. /// Returns an error when the checksum of the Mii is invalid. - pub fn launch(&mut self) -> Result { + pub fn launch(&mut self) -> Result { let mut return_val = Box::::default(); unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) } if unsafe { ctru_sys::miiSelectorChecksumIsValid(return_val.as_mut()) } { Ok((*return_val).into()) } else { - Err(MiiLaunchError::InvalidChecksum) + Err(LaunchError::InvalidChecksum) } } } -impl From for MiiSelectorReturn { +impl From for SelectionResult { fn from(ret: ctru_sys::MiiSelectorReturn) -> Self { let raw_mii_data = ret.mii; let mut guest_mii_name = ret.guest_mii_name; - MiiSelectorReturn { + SelectionResult { mii_data: raw_mii_data.into(), is_mii_selected: ret.no_mii_selected == 0, mii_type: if ret.guest_mii_index != 0xFFFFFFFF { @@ -179,7 +179,7 @@ impl From for MiiSelectorReturn { } } -impl From for MiiConfigIndex { +impl From for MiiIndex { fn from(v: u32) -> Self { Self::Index(v) } diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 178a86e..8f4aab6 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -7,6 +7,7 @@ use std::iter::once; use std::str; /// An instance of the software keyboard. +#[derive(Clone)] pub struct Swkbd { state: Box, } @@ -18,7 +19,7 @@ pub struct Swkbd { /// Numpad is a number pad. /// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other /// systems it's the same as a Normal keyboard. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Kind { Normal = ctru_sys::SWKBD_TYPE_NORMAL, @@ -28,7 +29,7 @@ pub enum Kind { } /// Represents which button the user pressed to close the software keyboard. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Button { Left = ctru_sys::SWKBD_BUTTON_LEFT, @@ -37,7 +38,7 @@ pub enum Button { } /// Error type for the software keyboard. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(i32)] pub enum Error { InvalidInput = ctru_sys::SWKBD_INVALID_INPUT, @@ -51,7 +52,7 @@ pub enum Error { } /// Restrictions on keyboard input -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ValidInput { Anything = ctru_sys::SWKBD_ANYTHING, diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index 73d3952..1891492 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -16,6 +16,10 @@ impl<'screen> Console<'screen> { /// Initialize a console on the chosen screen, overwriting whatever was on the screen /// previously (including other consoles). The new console is automatically selected for /// printing. + /// + /// # Notes + /// + /// [Console] automatically takes care of flushing and swapping buffers for its screen when printing. pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self { let mut context = Box::::default(); diff --git a/ctru-rs/src/services/am.rs b/ctru-rs/src/services/am.rs index 6fcee8c..70bd151 100644 --- a/ctru-rs/src/services/am.rs +++ b/ctru-rs/src/services/am.rs @@ -6,6 +6,7 @@ use std::mem::MaybeUninit; #[derive(Copy, Clone, Debug)] #[repr(transparent)] pub struct TitleInfo(ctru_sys::AM_TitleEntry); + impl TitleInfo { pub fn id(&self) -> u64 { self.0.titleID diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 261dbd3..4a06421 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -21,7 +21,7 @@ pub struct Cam { } /// Flag to pass to [Camera::flip_image] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FlipMode { None = ctru_sys::FLIP_NONE, @@ -31,7 +31,7 @@ pub enum FlipMode { } /// Flag to pass to [Camera::set_view_size] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ViewSize { TopLCD = ctru_sys::SIZE_CTR_TOP_LCD, @@ -48,7 +48,7 @@ pub enum ViewSize { } /// Flag to pass to [Camera::set_frame_rate] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FrameRate { Fps15 = ctru_sys::FRAME_RATE_15, @@ -68,7 +68,7 @@ pub enum FrameRate { /// Flag to pass to [Camera::set_white_balance] or /// [Camera::set_white_balance_without_base_up] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum WhiteBalance { /// Normal @@ -86,7 +86,7 @@ pub enum WhiteBalance { } /// Flag to pass to [Camera::set_photo_mode] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum PhotoMode { Normal = ctru_sys::PHOTO_MODE_NORMAL, @@ -97,7 +97,7 @@ pub enum PhotoMode { } /// Flag to pass to [Camera::set_effect] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Effect { None = ctru_sys::EFFECT_NONE, @@ -109,7 +109,7 @@ pub enum Effect { } /// Flag to pass to [Camera::set_contrast] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Contrast { /// OFF @@ -121,7 +121,7 @@ pub enum Contrast { } /// Flag to pass to [Camera::set_lens_correction] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum LensCorrection { Off = ctru_sys::LENS_CORRECTION_DARK, @@ -130,7 +130,7 @@ pub enum LensCorrection { } /// Flag to pass to [Camera::set_output_format] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum OutputFormat { Yuv422 = ctru_sys::OUTPUT_YUV_422, @@ -138,7 +138,7 @@ pub enum OutputFormat { } /// Flag to pass to [Cam::play_shutter_sound] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ShutterSound { Normal = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL, @@ -169,6 +169,7 @@ impl TryFrom for FramebufferFormat { } /// Struct containing coordinates passed to [Camera::set_trimming_params]. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct TrimmingParams { x_start: i16, y_start: i16, @@ -193,11 +194,11 @@ impl TrimmingParams { } /// Represents data used by the camera to calibrate image quality -#[derive(Default)] +#[derive(Default, Clone, Copy, Debug)] pub struct ImageQualityCalibrationData(pub ctru_sys::CAMU_ImageQualityCalibrationData); /// Represents data used by the camera to calibrate image quality when using both outward cameras -#[derive(Default)] +#[derive(Default, Clone, Copy, Debug)] pub struct StereoCameraCalibrationData(pub ctru_sys::CAMU_StereoCameraCalibrationData); /// Represents the camera on the inside of the 3DS diff --git a/ctru-rs/src/services/cfgu.rs b/ctru-rs/src/services/cfgu.rs index 90edf44..62052eb 100644 --- a/ctru-rs/src/services/cfgu.rs +++ b/ctru-rs/src/services/cfgu.rs @@ -4,7 +4,7 @@ use crate::error::ResultCode; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Region { Japan = ctru_sys::CFG_REGION_JPN, @@ -16,7 +16,7 @@ pub enum Region { Taiwan = ctru_sys::CFG_REGION_TWN, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Language { Japanese = ctru_sys::CFG_LANGUAGE_JP, @@ -33,7 +33,7 @@ pub enum Language { TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum SystemModel { Model3DS = ctru_sys::CFG_MODEL_3DS, diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index e59b02b..ccc4267 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -23,17 +23,13 @@ bitflags! { const FS_OPEN_WRITE = 2; const FS_OPEN_CREATE = 4; } -} -bitflags! { #[derive(Default)] struct FsWrite: u32 { const FS_WRITE_FLUSH = 1; const FS_WRITE_UPDATE_TIME = 256; } -} - -bitflags! { + #[derive(Default)] struct FsAttribute: u32 { const FS_ATTRIBUTE_DIRECTORY = 1; @@ -43,7 +39,7 @@ bitflags! { } } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FsMediaType { Nand = ctru_sys::MEDIATYPE_NAND, @@ -51,7 +47,7 @@ pub enum FsMediaType { GameCard = ctru_sys::MEDIATYPE_GAME_CARD, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum PathType { Invalid = ctru_sys::PATH_INVALID, @@ -61,7 +57,7 @@ pub enum PathType { UTF16 = ctru_sys::PATH_UTF16, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ArchiveID { RomFS = ctru_sys::ARCHIVE_ROMFS, @@ -252,7 +248,7 @@ pub struct Metadata { /// .open("foo.txt") /// .unwrap(); /// ``` -#[derive(Clone, Default)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct OpenOptions { read: bool, write: bool, diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 87be464..a4c5c17 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -55,6 +55,23 @@ pub trait Screen: private::Sealed { unsafe { ctru_sys::gfxSetDoubleBuffering(self.as_raw(), enabled) } } + /// Swaps the video buffers. + /// + /// This should be used even if double buffering is disabled. + fn flush_buffer(&mut self) { + let framebuffer = self.raw_framebuffer(); + + // Flush the data array. `self.raw_framebuffer` should get the correct parameters for all kinds of screens + unsafe { ctru_sys::GSPGPU_FlushDataCache(framebuffer.ptr.cast(), (framebuffer.height * framebuffer.width).into()) }; + } + + /// Swaps the video buffers. + /// + /// This should be used even if double buffering is disabled. + fn swap_buffers(&mut self) { + unsafe { ctru_sys::gfxScreenSwapBuffers(self.side().into(), true) }; + } + /// Gets the framebuffer format fn framebuffer_format(&self) -> FramebufferFormat { unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into() @@ -103,7 +120,7 @@ pub struct RawFrameBuffer<'screen> { screen: PhantomData<&'screen mut dyn Screen>, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] /// Side of top screen framebuffer /// @@ -128,6 +145,13 @@ pub struct Gfx { static GFX_ACTIVE: Mutex = Mutex::new(0); impl Gfx { + /// Creates a new [Gfx] instance with default init values + /// It's the same as calling: + /// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)` + pub fn new() -> Result { + Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) + } + /// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom /// screens /// @@ -155,32 +179,6 @@ impl Gfx { }) } - /// Creates a new [Gfx] instance with default init values - /// It's the same as calling: - /// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)` - pub fn new() -> Result { - Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) - } - - /// Flushes the current framebuffers - pub fn flush_buffers(&self) { - unsafe { ctru_sys::gfxFlushBuffers() }; - } - - /// Swaps the framebuffers and sets the gsp state - /// - /// Use this function when working with software rendering - pub fn swap_buffers(&self) { - unsafe { ctru_sys::gfxSwapBuffers() }; - } - - /// Swaps the framebuffers without manipulating the gsp state - /// - /// Use this function when working with GPU rendering - pub fn swap_buffers_gpu(&self) { - unsafe { ctru_sys::gfxSwapBuffersGpu() }; - } - /// Waits for the vertical blank interrupt /// /// Use this to synchronize your application with the refresh rate of the LCD screens diff --git a/ctru-rs/src/services/gspgpu.rs b/ctru-rs/src/services/gspgpu.rs index 234c088..9f9219c 100644 --- a/ctru-rs/src/services/gspgpu.rs +++ b/ctru-rs/src/services/gspgpu.rs @@ -1,6 +1,6 @@ //! GSPGPU service -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Event { Psc0 = ctru_sys::GSPGPU_EVENT_PSC0, @@ -13,7 +13,7 @@ pub enum Event { } /// Framebuffer formats supported by the 3DS -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FramebufferFormat { /// RGBA8. 4 bytes per pixel diff --git a/ctru-rs/src/services/hid.rs b/ctru-rs/src/services/hid.rs index 9577f42..2db0d23 100644 --- a/ctru-rs/src/services/hid.rs +++ b/ctru-rs/src/services/hid.rs @@ -8,7 +8,6 @@ use crate::error::ResultCode; bitflags::bitflags! { /// A set of flags corresponding to the button and directional pad /// inputs on the 3DS - #[derive(Default)] pub struct KeyPad: u32 { const A = ctru_sys::KEY_A; const B = ctru_sys::KEY_B; @@ -48,9 +47,11 @@ bitflags::bitflags! { pub struct Hid(()); /// Represents user input to the touchscreen. +#[derive(Debug, Clone, Copy)] pub struct TouchPosition(ctru_sys::touchPosition); /// Represents the current position of the 3DS circle pad. +#[derive(Debug, Clone, Copy)] pub struct CirclePosition(ctru_sys::circlePosition); /// Initializes the HID service. diff --git a/ctru-rs/src/services/ndsp/mod.rs b/ctru-rs/src/services/ndsp/mod.rs index 3fff3b8..8f67b1b 100644 --- a/ctru-rs/src/services/ndsp/mod.rs +++ b/ctru-rs/src/services/ndsp/mod.rs @@ -14,7 +14,7 @@ use std::sync::Mutex; const NUMBER_OF_CHANNELS: u8 = 24; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum OutputMode { Mono = ctru_sys::NDSP_OUTPUT_MONO, @@ -22,7 +22,7 @@ pub enum OutputMode { Surround = ctru_sys::NDSP_OUTPUT_SURROUND, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum AudioFormat { PCM8Mono = ctru_sys::NDSP_FORMAT_MONO_PCM8, @@ -32,12 +32,12 @@ pub enum AudioFormat { } /// Representation of volume mix for a channel. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq)] pub struct AudioMix { raw: [f32; 12], } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum InterpolationType { Polyphase = ctru_sys::NDSP_INTERP_POLYPHASE, @@ -45,7 +45,7 @@ pub enum InterpolationType { None = ctru_sys::NDSP_INTERP_NONE, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum NdspError { /// Channel ID InvalidChannel(u8), diff --git a/ctru-rs/src/services/ndsp/wave.rs b/ctru-rs/src/services/ndsp/wave.rs index a47c113..feff4cd 100644 --- a/ctru-rs/src/services/ndsp/wave.rs +++ b/ctru-rs/src/services/ndsp/wave.rs @@ -11,7 +11,7 @@ pub struct Wave { played_on_channel: Option, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u8)] /// Enum representing the playback status of a [Wave]. pub enum WaveStatus { diff --git a/ctru-rs/src/services/ps.rs b/ctru-rs/src/services/ps.rs index a14f2c4..1d5bd69 100644 --- a/ctru-rs/src/services/ps.rs +++ b/ctru-rs/src/services/ps.rs @@ -6,6 +6,7 @@ use crate::error::ResultCode; use crate::Result; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum AESAlgorithm { CbcEnc = ctru_sys::PS_ALGORITHM_CBC_ENC, @@ -16,6 +17,7 @@ pub enum AESAlgorithm { CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum AESKeyType { Keyslot0D = ctru_sys::PS_KEYSLOT_0D, @@ -56,7 +58,7 @@ impl Ps { pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> { ResultCode(unsafe { - ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) + ctru_sys::PS_GenerateRandomBytes(out.as_mut_ptr().cast(), out.len()) })?; Ok(()) } diff --git a/ctru-rs/src/services/sslc.rs b/ctru-rs/src/services/sslc.rs index 405fb9b..341155f 100644 --- a/ctru-rs/src/services/sslc.rs +++ b/ctru-rs/src/services/sslc.rs @@ -14,17 +14,6 @@ impl SslC { Ok(SslC(())) } } - - /// Fill `buf` with `buf.len()` random bytes - pub fn generate_random_data(&self, buf: &mut [u8]) -> crate::Result<()> { - unsafe { - ResultCode(ctru_sys::sslcGenerateRandomData( - buf.as_ptr() as _, - buf.len() as u32, - ))?; - Ok(()) - } - } } impl Drop for SslC { diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs index 713e0e6..97aa5f4 100644 --- a/ctru-rs/src/test_runner.rs +++ b/ctru-rs/src/test_runner.rs @@ -39,8 +39,6 @@ pub(crate) fn run(tests: &[&TestDescAndFn]) { println!("Press START to exit."); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); From bc82d20a9d7b06ef261676b278d312d869165a7a Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 11:32:28 +0200 Subject: [PATCH 20/33] Use usize in RawFrameBuffer --- ctru-rs/examples/gfx-3d-mode.rs | 6 ++++++ ctru-rs/src/services/gfx.rs | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index 8603a64..d0f77b2 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -61,6 +61,12 @@ fn main() { buf.copy_from(IMAGE.as_ptr(), IMAGE.len()); } + left.flush_buffer(); + left.swap_buffers(); + + right.flush_buffer(); + right.swap_buffers(); + //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index a4c5c17..52638c2 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -34,15 +34,15 @@ pub trait Screen: private::Sealed { /// Note that the pointer of the framebuffer returned by this function can /// change after each call to this function if double buffering is enabled. fn raw_framebuffer(&mut self) -> RawFrameBuffer { - let mut width = 0; - let mut height = 0; + let mut width: u16 = 0; + let mut height: u16 = 0; let ptr = unsafe { ctru_sys::gfxGetFramebuffer(self.as_raw(), self.side().into(), &mut width, &mut height) }; RawFrameBuffer { ptr, - width, - height, + width: width.into(), + height: height.into(), screen: PhantomData, } } @@ -62,7 +62,7 @@ pub trait Screen: private::Sealed { let framebuffer = self.raw_framebuffer(); // Flush the data array. `self.raw_framebuffer` should get the correct parameters for all kinds of screens - unsafe { ctru_sys::GSPGPU_FlushDataCache(framebuffer.ptr.cast(), (framebuffer.height * framebuffer.width).into()) }; + unsafe { ctru_sys::GSPGPU_FlushDataCache(framebuffer.ptr.cast(), (framebuffer.height * framebuffer.width) as u32) }; } /// Swaps the video buffers. @@ -113,9 +113,9 @@ pub struct RawFrameBuffer<'screen> { /// Pointer to graphics data to be rendered. pub ptr: *mut u8, /// The width of the framebuffer in pixels. - pub width: u16, + pub width: usize, /// The height of the framebuffer in pixels. - pub height: u16, + pub height: usize, /// Keep a mutable reference to the Screen for which this framebuffer is tied. screen: PhantomData<&'screen mut dyn Screen>, } From 19349dbc834241c2f9e9a6571c3e9ff8a61e054a Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 11:46:08 +0200 Subject: [PATCH 21/33] Renamed SystemModel enum variants --- ctru-rs/src/services/cfgu.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ctru-rs/src/services/cfgu.rs b/ctru-rs/src/services/cfgu.rs index 62052eb..0c076a3 100644 --- a/ctru-rs/src/services/cfgu.rs +++ b/ctru-rs/src/services/cfgu.rs @@ -36,12 +36,12 @@ pub enum Language { #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum SystemModel { - Model3DS = ctru_sys::CFG_MODEL_3DS, - Model3DSXL = ctru_sys::CFG_MODEL_3DSXL, - ModelNew3DS = ctru_sys::CFG_MODEL_N3DS, - Model2DS = ctru_sys::CFG_MODEL_2DS, - ModelNew3DSXL = ctru_sys::CFG_MODEL_N3DSXL, - ModelNew2DSXL = ctru_sys::CFG_MODEL_N2DSXL, + N3DS = ctru_sys::CFG_MODEL_3DS, + N3DSXL = ctru_sys::CFG_MODEL_3DSXL, + NewN3DS = ctru_sys::CFG_MODEL_N3DS, + N2DS = ctru_sys::CFG_MODEL_2DS, + NewN3DSXL = ctru_sys::CFG_MODEL_N3DSXL, + NewN2DSXL = ctru_sys::CFG_MODEL_N2DSXL, } /// Represents the configuration service. No actions can be performed @@ -163,12 +163,12 @@ impl TryFrom for SystemModel { fn try_from(value: u8) -> Result { match value as u32 { - ctru_sys::CFG_MODEL_3DS => Ok(SystemModel::Model3DS), - ctru_sys::CFG_MODEL_3DSXL => Ok(SystemModel::Model3DSXL), - ctru_sys::CFG_MODEL_N3DS => Ok(SystemModel::ModelNew3DS), - ctru_sys::CFG_MODEL_2DS => Ok(SystemModel::Model2DS), - ctru_sys::CFG_MODEL_N3DSXL => Ok(SystemModel::ModelNew3DSXL), - ctru_sys::CFG_MODEL_N2DSXL => Ok(SystemModel::ModelNew2DSXL), + ctru_sys::CFG_MODEL_3DS => Ok(SystemModel::N3DS), + ctru_sys::CFG_MODEL_3DSXL => Ok(SystemModel::N3DSXL), + ctru_sys::CFG_MODEL_N3DS => Ok(SystemModel::NewN3DS), + ctru_sys::CFG_MODEL_2DS => Ok(SystemModel::N2DS), + ctru_sys::CFG_MODEL_N3DSXL => Ok(SystemModel::NewN3DSXL), + ctru_sys::CFG_MODEL_N2DSXL => Ok(SystemModel::NewN2DSXL), _ => Err(()), } } From 9eecd1796c6f1f4918641a57a6a0b54b0c27b8fe Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 11:48:58 +0200 Subject: [PATCH 22/33] Fmt and clippy --- ctru-rs/examples/camera-image.rs | 9 ++------- ctru-rs/examples/gfx-wide-mode.rs | 2 +- ctru-rs/examples/thread-info.rs | 2 +- ctru-rs/src/applets/mii_selector.rs | 6 ++++++ ctru-rs/src/console.rs | 4 ++-- ctru-rs/src/services/fs.rs | 2 +- ctru-rs/src/services/gfx.rs | 11 ++++++++--- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 8f67b47..dcc92ff 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -23,7 +23,7 @@ fn main() { let mut top_screen = gfx.top_screen.borrow_mut(); top_screen.set_double_buffering(true); top_screen.set_framebuffer_format(FramebufferFormat::Rgb565); - + let _console = Console::new(gfx.bottom_screen.borrow_mut()); let mut keys_down; @@ -85,12 +85,7 @@ fn main() { cam.play_shutter_sound(ShutterSound::Normal) .expect("Failed to play shutter sound"); - rotate_image_to_screen( - &buf, - top_screen.raw_framebuffer().ptr, - WIDTH, - HEIGHT, - ); + rotate_image_to_screen(&buf, top_screen.raw_framebuffer().ptr, WIDTH, HEIGHT); // We will only flush the "camera" screen, since the other screen is handled by `Console` top_screen.flush_buffer(); diff --git a/ctru-rs/examples/gfx-wide-mode.rs b/ctru-rs/examples/gfx-wide-mode.rs index 0acf1b2..8036538 100644 --- a/ctru-rs/examples/gfx-wide-mode.rs +++ b/ctru-rs/examples/gfx-wide-mode.rs @@ -26,7 +26,7 @@ fn main() { console = Console::new(gfx.top_screen.borrow_mut()); println!("Press A to enable/disable wide screen mode."); } - + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/thread-info.rs b/ctru-rs/examples/thread-info.rs index 2316f16..28297ac 100644 --- a/ctru-rs/examples/thread-info.rs +++ b/ctru-rs/examples/thread-info.rs @@ -44,7 +44,7 @@ fn main() { if hid.keys_down().contains(KeyPad::KEY_START) { break; } - + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index e7d0559..9d3b3ca 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -155,6 +155,12 @@ impl MiiSelector { } } +impl Default for MiiSelector { + fn default() -> Self { + Self::new() + } +} + impl From for SelectionResult { fn from(ret: ctru_sys::MiiSelectorReturn) -> Self { let raw_mii_data = ret.mii; diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index 1891492..e3ba62e 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -16,9 +16,9 @@ impl<'screen> Console<'screen> { /// Initialize a console on the chosen screen, overwriting whatever was on the screen /// previously (including other consoles). The new console is automatically selected for /// printing. - /// + /// /// # Notes - /// + /// /// [Console] automatically takes care of flushing and swapping buffers for its screen when printing. pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self { let mut context = Box::::default(); diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index ccc4267..3ad7506 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -29,7 +29,7 @@ bitflags! { const FS_WRITE_FLUSH = 1; const FS_WRITE_UPDATE_TIME = 256; } - + #[derive(Default)] struct FsAttribute: u32 { const FS_ATTRIBUTE_DIRECTORY = 1; diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 52638c2..1412bb7 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -56,17 +56,22 @@ pub trait Screen: private::Sealed { } /// Swaps the video buffers. - /// + /// /// This should be used even if double buffering is disabled. fn flush_buffer(&mut self) { let framebuffer = self.raw_framebuffer(); // Flush the data array. `self.raw_framebuffer` should get the correct parameters for all kinds of screens - unsafe { ctru_sys::GSPGPU_FlushDataCache(framebuffer.ptr.cast(), (framebuffer.height * framebuffer.width) as u32) }; + unsafe { + ctru_sys::GSPGPU_FlushDataCache( + framebuffer.ptr.cast(), + (framebuffer.height * framebuffer.width) as u32, + ) + }; } /// Swaps the video buffers. - /// + /// /// This should be used even if double buffering is disabled. fn swap_buffers(&mut self) { unsafe { ctru_sys::gfxScreenSwapBuffers(self.side().into(), true) }; From d3808d05afa60bba31e48cae6e236c4458cdec85 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 12:14:39 +0200 Subject: [PATCH 23/33] Undo double flush in example --- ctru-rs/examples/gfx-3d-mode.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index d0f77b2..5bd982f 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -64,9 +64,6 @@ fn main() { left.flush_buffer(); left.swap_buffers(); - right.flush_buffer(); - right.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } From fcdb18449b49b1db1311d676012bc1687d97a8f6 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Tue, 11 Apr 2023 12:58:02 +0200 Subject: [PATCH 24/33] Explicit DPAD nomenclature --- ctru-rs/src/services/hid.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ctru-rs/src/services/hid.rs b/ctru-rs/src/services/hid.rs index 2db0d23..79a649b 100644 --- a/ctru-rs/src/services/hid.rs +++ b/ctru-rs/src/services/hid.rs @@ -13,10 +13,10 @@ bitflags::bitflags! { const B = ctru_sys::KEY_B; const SELECT = ctru_sys::KEY_SELECT; const START = ctru_sys::KEY_START; - const DRIGHT = ctru_sys::KEY_DRIGHT; - const DLEFT = ctru_sys::KEY_DLEFT; - const DUP = ctru_sys::KEY_DUP; - const DDOWN = ctru_sys::KEY_DDOWN; + const DPAD_RIGHT = ctru_sys::KEY_DRIGHT; + const DPAD_LEFT = ctru_sys::KEY_DLEFT; + const DPAD_UP = ctru_sys::KEY_DUP; + const DPAD_DOWN = ctru_sys::KEY_DDOWN; const R = ctru_sys::KEY_R; const L = ctru_sys::KEY_L; const X = ctru_sys::KEY_X; @@ -33,10 +33,10 @@ bitflags::bitflags! { const CPAD_UP = ctru_sys::KEY_CPAD_UP; const CPAD_DOWN = ctru_sys::KEY_CPAD_DOWN; // Convenience catch-all for the dpad and cpad - const UP = KeyPad::DUP.bits() | KeyPad::CPAD_UP.bits(); - const DOWN = KeyPad::DDOWN.bits() | KeyPad::CPAD_DOWN.bits(); - const LEFT = KeyPad::DLEFT.bits() | KeyPad::CPAD_LEFT.bits(); - const RIGHT = KeyPad::DRIGHT.bits() | KeyPad::CPAD_RIGHT.bits(); + const UP = KeyPad::DPAD_UP.bits() | KeyPad::CPAD_UP.bits(); + const DOWN = KeyPad::DPAD_DOWN.bits() | KeyPad::CPAD_DOWN.bits(); + const LEFT = KeyPad::DPAD_LEFT.bits() | KeyPad::CPAD_LEFT.bits(); + const RIGHT = KeyPad::DPAD_RIGHT.bits() | KeyPad::CPAD_RIGHT.bits(); } } From 9a98f3233c284a85f70344a179e0bc05b71dccf9 Mon Sep 17 00:00:00 2001 From: Meziu <55318903+Meziu@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:21:14 +0200 Subject: [PATCH 25/33] Update flush_buffer docs Co-authored-by: Ian Chamberlain --- ctru-rs/src/services/gfx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 1412bb7..49dc6cd 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -55,7 +55,7 @@ pub trait Screen: private::Sealed { unsafe { ctru_sys::gfxSetDoubleBuffering(self.as_raw(), enabled) } } - /// Swaps the video buffers. + /// Flushes the video buffer for this screen. /// /// This should be used even if double buffering is disabled. fn flush_buffer(&mut self) { From d8af910ed5b64b3f094a292cf2a3999e8c59341e Mon Sep 17 00:00:00 2001 From: Meziu <55318903+Meziu@users.noreply.github.com> Date: Wed, 12 Apr 2023 11:39:34 +0200 Subject: [PATCH 26/33] Update gfx.rs --- ctru-rs/src/services/gfx.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 49dc6cd..9ac0a34 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -56,8 +56,6 @@ pub trait Screen: private::Sealed { } /// Flushes the video buffer for this screen. - /// - /// This should be used even if double buffering is disabled. fn flush_buffer(&mut self) { let framebuffer = self.raw_framebuffer(); From 3e349f8591dc30f643ce074f41f669a0d4d59ed4 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Fri, 14 Apr 2023 15:08:37 -0400 Subject: [PATCH 27/33] Fix mutability issues after merge of master --- ctru-rs/src/services/fs.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 3ad7506..670e561 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -99,7 +99,7 @@ pub struct Fs(()); /// ```no_run /// use ctru::services::fs::Fs; /// -/// let fs = Fs::new().unwrap(); +/// let mut fs = Fs::init().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap(); /// ``` pub struct Archive { @@ -125,8 +125,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::new()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// /// let mut file = File::create(&mut sdmc, "/foo.txt")?; /// file.write_all(b"Hello, world!")?; @@ -144,8 +144,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::new()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// /// let mut file = File::open(&sdmc, "/foo.txt")?; /// let mut contents = String::new(); @@ -167,8 +167,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::new()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// /// let file = File::open(&sdmc, "/foo.txt")?; /// let mut buf_reader = BufReader::new(file); @@ -223,8 +223,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let fs = Fs::new().unwrap(); -/// let sdmc_archive = fs.sdmc().unwrap(); +/// let mut fs = Fs::init().unwrap(); +/// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .archive(&sdmc_archive) @@ -238,8 +238,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let fs = Fs::new().unwrap(); -/// let sdmc_archive = fs.sdmc().unwrap(); +/// let mut fs = Fs::init().unwrap(); +/// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .write(true) @@ -365,8 +365,8 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let fs = Fs::new().unwrap(); - /// let sdmc_archive = fs.sdmc().unwrap(); + /// let mut fs = Fs::init().unwrap(); + /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let mut f = File::open(&sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn open>(arch: &Archive, path: P) -> IoResult { @@ -394,9 +394,9 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let fs = Fs::new().unwrap(); - /// let sdmc_archive = fs.sdmc().unwrap(); - /// let mut f = File::create(&sdmc_archive, "/foo.txt").unwrap(); + /// let mut fs = Fs::init().unwrap(); + /// let mut sdmc_archive = fs.sdmc().unwrap(); + /// let mut f = File::create(&mut sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn create>(arch: &mut Archive, path: P) -> IoResult { OpenOptions::new() From 9b95c883e94585b850687560dbaac921a9588942 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 09:59:55 +0200 Subject: [PATCH 28/33] Renamed init functions to new --- ctru-rs/src/services/fs.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 670e561..c5f9980 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -99,7 +99,7 @@ pub struct Fs(()); /// ```no_run /// use ctru::services::fs::Fs; /// -/// let mut fs = Fs::init().unwrap(); +/// let mut fs = Fs::new().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap(); /// ``` pub struct Archive { @@ -125,13 +125,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::init()?; +/// let mut fs = Fs::new()?; /// let mut sdmc = fs.sdmc()?; -/// -/// let mut file = File::create(&mut sdmc, "/foo.txt")?; -/// file.write_all(b"Hello, world!")?; -/// # -/// # Ok(()) /// # } /// ``` /// @@ -144,7 +139,7 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::init()?; +/// let mut fs = Fs::new()?; /// let mut sdmc = fs.sdmc()?; /// /// let mut file = File::open(&sdmc, "/foo.txt")?; @@ -167,7 +162,7 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::init()?; +/// let mut fs = Fs::new()?; /// let mut sdmc = fs.sdmc()?; /// /// let file = File::open(&sdmc, "/foo.txt")?; @@ -223,7 +218,7 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let mut fs = Fs::init().unwrap(); +/// let mut fs = Fs::new().unwrap(); /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) @@ -238,7 +233,7 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let mut fs = Fs::init().unwrap(); +/// let mut fs = Fs::new().unwrap(); /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) @@ -365,7 +360,7 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let mut fs = Fs::init().unwrap(); + /// let mut fs = Fs::new().unwrap(); /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let mut f = File::open(&sdmc_archive, "/foo.txt").unwrap(); /// ``` @@ -394,7 +389,7 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let mut fs = Fs::init().unwrap(); + /// let mut fs = Fs::new().unwrap(); /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let mut f = File::create(&mut sdmc_archive, "/foo.txt").unwrap(); /// ``` From c7e64372787aa76ec37c50d10c1327873f1cb814 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Mon, 17 Apr 2023 15:00:15 +0200 Subject: [PATCH 29/33] Rename N3DS to Old3DS --- ctru-rs/src/services/cfgu.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ctru-rs/src/services/cfgu.rs b/ctru-rs/src/services/cfgu.rs index 0c076a3..a9cc411 100644 --- a/ctru-rs/src/services/cfgu.rs +++ b/ctru-rs/src/services/cfgu.rs @@ -36,12 +36,12 @@ pub enum Language { #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum SystemModel { - N3DS = ctru_sys::CFG_MODEL_3DS, - N3DSXL = ctru_sys::CFG_MODEL_3DSXL, - NewN3DS = ctru_sys::CFG_MODEL_N3DS, - N2DS = ctru_sys::CFG_MODEL_2DS, - NewN3DSXL = ctru_sys::CFG_MODEL_N3DSXL, - NewN2DSXL = ctru_sys::CFG_MODEL_N2DSXL, + Old3DS = ctru_sys::CFG_MODEL_3DS, + Old3DSXL = ctru_sys::CFG_MODEL_3DSXL, + New3DS = ctru_sys::CFG_MODEL_N3DS, + Old2DS = ctru_sys::CFG_MODEL_2DS, + New3DSXL = ctru_sys::CFG_MODEL_N3DSXL, + New2DSXL = ctru_sys::CFG_MODEL_N2DSXL, } /// Represents the configuration service. No actions can be performed @@ -163,12 +163,12 @@ impl TryFrom for SystemModel { fn try_from(value: u8) -> Result { match value as u32 { - ctru_sys::CFG_MODEL_3DS => Ok(SystemModel::N3DS), - ctru_sys::CFG_MODEL_3DSXL => Ok(SystemModel::N3DSXL), - ctru_sys::CFG_MODEL_N3DS => Ok(SystemModel::NewN3DS), - ctru_sys::CFG_MODEL_2DS => Ok(SystemModel::N2DS), - ctru_sys::CFG_MODEL_N3DSXL => Ok(SystemModel::NewN3DSXL), - ctru_sys::CFG_MODEL_N2DSXL => Ok(SystemModel::NewN2DSXL), + ctru_sys::CFG_MODEL_3DS => Ok(SystemModel::Old3DS), + ctru_sys::CFG_MODEL_3DSXL => Ok(SystemModel::Old3DSXL), + ctru_sys::CFG_MODEL_N3DS => Ok(SystemModel::New3DS), + ctru_sys::CFG_MODEL_2DS => Ok(SystemModel::Old2DS), + ctru_sys::CFG_MODEL_N3DSXL => Ok(SystemModel::New3DSXL), + ctru_sys::CFG_MODEL_N2DSXL => Ok(SystemModel::New2DSXL), _ => Err(()), } } From 97fce222dca3a0277d75055200bf91eb9d14c91a Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Mon, 17 Apr 2023 15:03:50 +0200 Subject: [PATCH 30/33] Rename MiiIndex to Index --- ctru-rs/src/applets/mii_selector.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index 9d3b3ca..a6acd61 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -9,7 +9,7 @@ use std::ffi::CString; /// Index of a Mii used to configure some parameters of the Mii Selector /// Can be either a single index, or _all_ Miis #[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub enum MiiIndex { +pub enum Index { Index(u32), All, } @@ -94,40 +94,40 @@ impl MiiSelector { } /// Whitelist a guest Mii - pub fn whitelist_guest_mii(&mut self, mii_index: MiiIndex) { + pub fn whitelist_guest_mii(&mut self, mii_index: Index) { let index = match mii_index { - MiiIndex::Index(i) => i, - MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, + Index::Index(i) => i, + Index::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, }; unsafe { ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), index) } } /// Blacklist a guest Mii - pub fn blacklist_guest_mii(&mut self, mii_index: MiiIndex) { + pub fn blacklist_guest_mii(&mut self, mii_index: Index) { let index = match mii_index { - MiiIndex::Index(i) => i, - MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, + Index::Index(i) => i, + Index::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, }; unsafe { ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), index) } } /// Whitelist a user Mii - pub fn whitelist_user_mii(&mut self, mii_index: MiiIndex) { + pub fn whitelist_user_mii(&mut self, mii_index: Index) { let index = match mii_index { - MiiIndex::Index(i) => i, - MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, + Index::Index(i) => i, + Index::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, }; unsafe { ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), index) } } /// Blacklist a user Mii - pub fn blacklist_user_mii(&mut self, mii_index: MiiIndex) { + pub fn blacklist_user_mii(&mut self, mii_index: Index) { let index = match mii_index { - MiiIndex::Index(i) => i, - MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, + Index::Index(i) => i, + Index::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, }; unsafe { ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), index) } @@ -185,7 +185,7 @@ impl From for SelectionResult { } } -impl From for MiiIndex { +impl From for Index { fn from(v: u32) -> Self { Self::Index(v) } From 09d52eac36e89e7e70ca8f1ff816a93a344951c8 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Mon, 17 Apr 2023 15:42:06 +0200 Subject: [PATCH 31/33] Fix doctest fmt --- ctru-rs/src/services/fs.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index c5f9980..4c5ed20 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -99,7 +99,7 @@ pub struct Fs(()); /// ```no_run /// use ctru::services::fs::Fs; /// -/// let mut fs = Fs::new().unwrap(); +/// let mut fs = Fs::new().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap(); /// ``` pub struct Archive { @@ -125,7 +125,7 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::new()?; +/// let mut fs = Fs::new()?; /// let mut sdmc = fs.sdmc()?; /// # } /// ``` @@ -139,7 +139,7 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::new()?; +/// let mut fs = Fs::new()?; /// let mut sdmc = fs.sdmc()?; /// /// let mut file = File::open(&sdmc, "/foo.txt")?; @@ -162,7 +162,7 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let mut fs = Fs::new()?; +/// let mut fs = Fs::new()?; /// let mut sdmc = fs.sdmc()?; /// /// let file = File::open(&sdmc, "/foo.txt")?; @@ -218,7 +218,7 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let mut fs = Fs::new().unwrap(); +/// let mut fs = Fs::new().unwrap(); /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) @@ -233,7 +233,7 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let mut fs = Fs::new().unwrap(); +/// let mut fs = Fs::new().unwrap(); /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) From b47228fef1b7898d8814ad9a18ffe0e59a637d96 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Mon, 17 Apr 2023 15:45:31 +0200 Subject: [PATCH 32/33] Fix doctest --- ctru-rs/src/services/fs.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 4c5ed20..04e0c1e 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -127,6 +127,8 @@ pub struct Archive { /// /// let mut fs = Fs::new()?; /// let mut sdmc = fs.sdmc()?; +/// # +/// # Ok(()) /// # } /// ``` /// From eb8eaa506f57fdfa1b67adf654ccec83023e5f9d Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Tue, 2 May 2023 21:15:46 +0200 Subject: [PATCH 33/33] HID Touch and Circlepad refactor + new example --- ctru-rs/examples/touch-screen.rs | 49 +++++++++++++++++++++++++++ ctru-rs/src/services/hid.rs | 58 ++++++++++---------------------- 2 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 ctru-rs/examples/touch-screen.rs diff --git a/ctru-rs/examples/touch-screen.rs b/ctru-rs/examples/touch-screen.rs new file mode 100644 index 0000000..204f324 --- /dev/null +++ b/ctru-rs/examples/touch-screen.rs @@ -0,0 +1,49 @@ +use ctru::prelude::*; + +fn main() { + ctru::use_panic_handler(); + + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); + let apt = Apt::new().expect("Couldn't obtain APT controller"); + + let console = Console::new(gfx.top_screen.borrow_mut()); + + // We'll hold the previous touch position for comparison. + let mut old_touch: (u16, u16) = (0, 0); + + println!("\x1b[29;16HPress Start to exit"); + + while apt.main_loop() { + hid.scan_input(); + + if hid.keys_down().contains(KeyPad::START) { + break; + } + + // Get X and Y coordinates of the touch point. + // The touch screen is 320x240. + let touch: (u16, u16) = hid.touch_position(); + + // We only want to print the position when it's different + // from what it was on the previous frame + if touch != old_touch { + // Special case for when the user lifts the stylus/finger from the screen. + // This is done to avoid some screen tearing. + if touch == (0, 0) { + console.clear(); + + // Print again because we just cleared the screen + println!("\x1b[29;16HPress Start to exit"); + } + + // Move the cursor back to the top of the screen and print the coordinates + print!("\x1b[1;1HTouch Screen position: {:#?}", touch); + } + + // Save our current touch position for the next frame + old_touch = touch; + + gfx.wait_for_vblank(); + } +} diff --git a/ctru-rs/src/services/hid.rs b/ctru-rs/src/services/hid.rs index 79a649b..fa91657 100644 --- a/ctru-rs/src/services/hid.rs +++ b/ctru-rs/src/services/hid.rs @@ -46,14 +46,6 @@ bitflags::bitflags! { /// This service requires no special permissions to use. pub struct Hid(()); -/// Represents user input to the touchscreen. -#[derive(Debug, Clone, Copy)] -pub struct TouchPosition(ctru_sys::touchPosition); - -/// Represents the current position of the 3DS circle pad. -#[derive(Debug, Clone, Copy)] -pub struct CirclePosition(ctru_sys::circlePosition); - /// Initializes the HID service. /// /// # Errors @@ -102,47 +94,33 @@ impl Hid { KeyPad::from_bits_truncate(keys) } } -} - -impl Default for TouchPosition { - fn default() -> Self { - TouchPosition(ctru_sys::touchPosition { px: 0, py: 0 }) - } -} -impl TouchPosition { - /// Create a new TouchPosition instance. - pub fn new() -> Self { - Self::default() - } + /// Returns the current touch position in pixels (x, y). + /// + /// # Notes + /// + /// (0, 0) represents the top left corner of the screen. + pub fn touch_position(&mut self) -> (u16, u16) { + let mut res = ctru_sys::touchPosition { px: 0, py: 0 }; - /// Returns the current touch position in pixels. - pub fn get(&mut self) -> (u16, u16) { unsafe { - ctru_sys::hidTouchRead(&mut self.0); + ctru_sys::hidTouchRead(&mut res); } - (self.0.px, self.0.py) - } -} - -impl Default for CirclePosition { - fn default() -> Self { - CirclePosition(ctru_sys::circlePosition { dx: 0, dy: 0 }) + (res.px, res.py) } -} -impl CirclePosition { - /// Create a new CirclePosition instance. - pub fn new() -> Self { - Self::default() - } + /// Returns the current circle pad position in relative (x, y). + /// + /// # Notes + /// + /// (0, 0) represents the center of the circle pad. + pub fn circlepad_position(&mut self) -> (i16, i16) { + let mut res = ctru_sys::circlePosition { dx: 0, dy: 0 }; - /// Returns the current circle pad position in (x, y) form. - pub fn get(&mut self) -> (i16, i16) { unsafe { - ctru_sys::hidCircleRead(&mut self.0); + ctru_sys::hidCircleRead(&mut res); } - (self.0.dx, self.0.dy) + (res.dx, res.dy) } }