From 208a9171e43d9dc770eb222dc935defca0021f6f Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Tue, 26 Dec 2023 12:53:44 -0500 Subject: [PATCH] Add srv::make_ipc_header and use in ir_user --- ctru-rs/src/services/ir_user.rs | 15 ++++++++------- ctru-rs/src/services/srv.rs | 7 +++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ctru-rs/src/services/ir_user.rs b/ctru-rs/src/services/ir_user.rs index 67fa17d..051baec 100644 --- a/ctru-rs/src/services/ir_user.rs +++ b/ctru-rs/src/services/ir_user.rs @@ -11,6 +11,7 @@ #![doc(alias = "gamepad")] use crate::error::ResultCode; +use crate::services::srv::make_ipc_header; use crate::services::ServiceReference; use crate::Error; use ctru_sys::{Handle, MEMPERM_READ, MEMPERM_READWRITE}; @@ -39,13 +40,13 @@ struct IrUserState { } // ir:USER syscall command headers -const REQUIRE_CONNECTION_COMMAND_HEADER: u32 = 0x00060040; -const DISCONNECT_COMMAND_HEADER: u32 = 0x00090000; -const GET_RECEIVE_EVENT_COMMAND_HEADER: u32 = 0x000A0000; -const GET_CONNECTION_STATUS_EVENT_COMMAND_HEADER: u32 = 0x000C0000; -const SEND_IR_NOP_COMMAND_HEADER: u32 = 0x000D0042; -const INITIALIZE_IRNOP_SHARED_COMMAND_HEADER: u32 = 0x00180182; -const RELEASE_RECEIVED_DATA_COMMAND_HEADER: u32 = 0x00190040; +const REQUIRE_CONNECTION_COMMAND_HEADER: u32 = make_ipc_header(6, 1, 0); +const DISCONNECT_COMMAND_HEADER: u32 = make_ipc_header(9, 0, 0); +const GET_RECEIVE_EVENT_COMMAND_HEADER: u32 = make_ipc_header(10, 0, 0); +const GET_CONNECTION_STATUS_EVENT_COMMAND_HEADER: u32 = make_ipc_header(12, 0, 0); +const SEND_IR_NOP_COMMAND_HEADER: u32 = make_ipc_header(13, 1, 2); +const INITIALIZE_IRNOP_SHARED_COMMAND_HEADER: u32 = make_ipc_header(24, 6, 2); +const RELEASE_RECEIVED_DATA_COMMAND_HEADER: u32 = make_ipc_header(25, 1, 0); // Misc constants const SHARED_MEM_INFO_SECTIONS_SIZE: usize = 0x30; diff --git a/ctru-rs/src/services/srv.rs b/ctru-rs/src/services/srv.rs index 98b7282..c74eff2 100644 --- a/ctru-rs/src/services/srv.rs +++ b/ctru-rs/src/services/srv.rs @@ -28,3 +28,10 @@ impl HandleExt for Handle { Ok(()) } } + +/// Creates a command header to be used for IPC. This is a const fn version of [`ctru_sys::IPC_MakeHeader`]. +pub const fn make_ipc_header(command_id: u16, normal_params: u8, translate_params: u8) -> u32 { + ((command_id as u32) << 16) + | (((normal_params as u32) & 0x3F) << 6) + | ((translate_params as u32) & 0x3F) +}