mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-25 11:46:27 +00:00
Common: Move AsU8Span utility function from BTReal to Common/BitUtils.
This commit is contained in:
parent
45ba6ed6b1
commit
2b541361c6
2 changed files with 23 additions and 13 deletions
|
@ -7,11 +7,13 @@
|
|||
#include <bit>
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <span>
|
||||
#include <type_traits>
|
||||
|
||||
#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<T>() - left_shift_amount));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(std::is_trivially_copyable_v<T>)
|
||||
constexpr auto AsU8Span(const T& obj)
|
||||
{
|
||||
return std::span{reinterpret_cast<const u8*>(std::addressof(obj)), sizeof(obj)};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(std::is_trivially_copyable_v<T>)
|
||||
constexpr auto AsWritableU8Span(T& obj)
|
||||
{
|
||||
return std::span{reinterpret_cast<u8*>(std::addressof(obj)), sizeof(obj)};
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#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 <typename T>
|
||||
requires(std::is_trivially_copyable_v<T>)
|
||||
constexpr auto AsU8Span(const T& obj)
|
||||
{
|
||||
return std::span{reinterpret_cast<const u8*>(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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue