Skip to content

Commit

Permalink
Merge pull request #115 from rust3ds/fix/channel-mutability
Browse files Browse the repository at this point in the history
Fix mutability requirements
  • Loading branch information
Meziu committed Apr 17, 2023
2 parents 0201731 + 6c0fce0 commit 94a453e
Show file tree
Hide file tree
Showing 48 changed files with 423 additions and 409 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @rust3ds/active
46 changes: 46 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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: 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: ${{ inputs.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...
args: >-
--git https://github.com/rust3ds/cargo-3ds
--rev 78a652fdfb01e2614a792d1a56b10c980ee1dae9
- 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
56 changes: 32 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,41 +24,24 @@ 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
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/actions/setup
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: 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
Expand All @@ -68,5 +53,28 @@ 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
container: devkitpro/devkitarm
steps:
- name: Checkout branch
uses: actions/checkout@v2

- uses: ./.github/actions/setup
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

# TODO: it would be nice to actually build 3dsx for examples/tests, etc.
# and run it somehow, but exactly how remains to be seen.
2 changes: 1 addition & 1 deletion ctru-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 6 additions & 10 deletions ctru-rs/examples/audio-filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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;

Expand Down Expand Up @@ -68,12 +68,12 @@ 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);

let channel_zero = ndsp.channel(0).unwrap();
let mut channel_zero = ndsp.channel(0).unwrap();
channel_zero.set_interpolation(InterpolationType::Linear);
channel_zero.set_sample_rate(SAMPLE_RATE as f32);
channel_zero.set_format(AudioFormat::PCM16Stereo);
Expand Down Expand Up @@ -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();
}
Expand Down
11 changes: 4 additions & 7 deletions ctru-rs/examples/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use ctru::prelude::*;
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let 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");
Expand Down Expand Up @@ -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();
}
}
32 changes: 14 additions & 18 deletions ctru-rs/examples/camera-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ 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 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 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;

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;
Expand Down Expand Up @@ -86,15 +85,12 @@ fn main() {
cam.play_shutter_sound(ShutterSound::Normal)
.expect("Failed to play shutter sound");

rotate_image_to_screen(
&buf,
gfx.top_screen.borrow_mut().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();
top_screen.swap_buffers();

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
Expand Down
18 changes: 8 additions & 10 deletions ctru-rs/examples/file-explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ use std::path::{Path, PathBuf};
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let 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, &hid, &gfx).run();
FileExplorer::new(&apt, &mut hid, &gfx).run();
}

struct FileExplorer<'a> {
apt: &'a Apt,
hid: &'a Hid,
hid: &'a mut Hid,
gfx: &'a Gfx,
console: Console<'a>,
path: PathBuf,
Expand All @@ -32,10 +32,10 @@ struct FileExplorer<'a> {
}

impl<'a> FileExplorer<'a> {
fn init(apt: &'a Apt, hid: &'a 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,
Expand Down Expand Up @@ -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();
}
}
Expand Down
10 changes: 4 additions & 6 deletions ctru-rs/examples/futures-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
Expand Down Expand Up @@ -68,8 +68,6 @@ fn main() {
frame_count = 0;
}

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
10 changes: 4 additions & 6 deletions ctru-rs/examples/futures-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
Expand Down Expand Up @@ -63,8 +63,6 @@ fn main() {
break;
}

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
13 changes: 6 additions & 7 deletions ctru-rs/examples/gfx-3d-mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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).");

Expand Down Expand Up @@ -61,9 +61,8 @@ fn main() {
buf.copy_from(IMAGE.as_ptr(), IMAGE.len());
}

// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
left.flush_buffer();
left.swap_buffers();

//Wait for VBlank
gfx.wait_for_vblank();
Expand Down
Loading

0 comments on commit 94a453e

Please sign in to comment.