diff --git a/Source/Core/Common/BitUtils.h b/Source/Core/Common/BitUtils.h index 8b1b196c24..2f7f0c5f9a 100644 --- a/Source/Core/Common/BitUtils.h +++ b/Source/Core/Common/BitUtils.h @@ -7,11 +7,13 @@ #include #include #include -#include #include #include +#include #include +#include "Common/CommonTypes.h" + namespace Common { /// @@ -240,4 +242,19 @@ T ExpandValue(T value, size_t left_shift_amount) return (value << left_shift_amount) | (T(-ExtractBit<0>(value)) >> (BitSize() - left_shift_amount)); } + +template +requires(std::is_trivially_copyable_v) +constexpr auto AsU8Span(const T& obj) +{ + return std::span{reinterpret_cast(std::addressof(obj)), sizeof(obj)}; +} + +template +requires(std::is_trivially_copyable_v) +constexpr auto AsWritableU8Span(T& obj) +{ + return std::span{reinterpret_cast(std::addressof(obj)), sizeof(obj)}; +} + } // namespace Common diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index 79cc6ccfed..b5a9d030a1 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -13,6 +13,7 @@ #include +#include "Common/BitUtils.h" #include "Common/ChunkFile.h" #include "Common/Network.h" #include "Common/StringUtil.h" @@ -35,14 +36,6 @@ struct HCICommandPayload hci_cmd_hdr_t header{Opcode, sizeof(CommandType)}; CommandType command{}; }; - -template -requires(std::is_trivially_copyable_v) -constexpr auto AsU8Span(const T& obj) -{ - return std::span{reinterpret_cast(std::addressof(obj)), sizeof(obj)}; -} - } // namespace namespace IOS::HLE @@ -295,7 +288,7 @@ auto BluetoothRealDevice::ProcessHCIEvent(BufferType buffer) -> BufferType payload.command.latency = 10000; payload.command.delay_variation = 0xffffffff; - m_lib_usb_bt_adapter->SendControlTransfer(AsU8Span(payload)); + m_lib_usb_bt_adapter->SendControlTransfer(Common::AsU8Span(payload)); } else if (event == HCI_EVENT_QOS_SETUP_COMPL) { @@ -402,7 +395,7 @@ void BluetoothRealDevice::TriggerSyncButtonHeldEvent() void BluetoothRealDevice::SendHCIResetCommand() { INFO_LOG_FMT(IOS_WIIMOTE, "SendHCIResetCommand"); - m_lib_usb_bt_adapter->SendControlTransfer(AsU8Span(hci_cmd_hdr_t{HCI_CMD_RESET, 0})); + m_lib_usb_bt_adapter->SendControlTransfer(Common::AsU8Span(hci_cmd_hdr_t{HCI_CMD_RESET, 0})); } void BluetoothRealDevice::SendHCIDeleteLinkKeyCommand() @@ -413,7 +406,7 @@ void BluetoothRealDevice::SendHCIDeleteLinkKeyCommand() payload.command.bdaddr = {}; payload.command.delete_all = 0x01; - m_lib_usb_bt_adapter->SendControlTransfer(AsU8Span(payload)); + m_lib_usb_bt_adapter->SendControlTransfer(Common::AsU8Span(payload)); } bool BluetoothRealDevice::SendHCIStoreLinkKeyCommand() @@ -450,7 +443,7 @@ bool BluetoothRealDevice::SendHCIStoreLinkKeyCommand() for (auto& [bdaddr, linkkey] : m_link_keys | std::views::take(num_link_keys)) payload.link_keys[index++] = {bdaddr, linkkey}; - m_lib_usb_bt_adapter->SendControlTransfer(AsU8Span(payload).first(payload_size)); + m_lib_usb_bt_adapter->SendControlTransfer(Common::AsU8Span(payload).first(payload_size)); return true; }