Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/Hid/HidCommon.h
5698 views
1
#pragma once
2
3
#include "Common/CommonWindows.h"
4
#include "Windows/Hid/HidInputDevice.h"
5
6
constexpr u8 LED_R = 0x05;
7
constexpr u8 LED_G = 0x10;
8
constexpr u8 LED_B = 0x40;
9
10
enum HidStickAxis : u32 {
11
HID_STICK_LX = 0,
12
HID_STICK_LY = 1,
13
HID_STICK_RX = 2,
14
HID_STICK_RY = 3,
15
};
16
17
enum HidTriggerAxis : u32 {
18
HID_TRIGGER_L2 = 0,
19
HID_TRIGGER_R2 = 1,
20
};
21
22
bool WriteReport(HANDLE handle, const u8 *data, size_t size);
23
24
template<class T>
25
inline bool WriteReport(HANDLE handle, const T &report) {
26
return WriteReport(handle, (const u8 *)&report, sizeof(T));
27
}
28
29
// Standard CRC32 Update function. Used for DualSense bluetooth messages.
30
constexpr inline uint32_t UpdateCRC32(uint32_t crc, const uint8_t* data, size_t len) {
31
for (size_t i = 0; i < len; i++) {
32
crc ^= data[i];
33
for (int j = 0; j < 8; j++) {
34
crc = (crc >> 1) ^ (0xEDB88320 & (-(int32_t)(crc & 1)));
35
}
36
}
37
return crc;
38
}
39
40
// The specific "Sony Bluetooth" CRC32
41
constexpr inline uint32_t ComputeDualSenseBTCRC(const uint8_t* buffer, size_t len) {
42
constexpr uint8_t btHeader = 0xA2;
43
44
// Step 1: Initialize with 0xFFFFFFFF and process the "Hidden" BT header
45
constexpr uint32_t headerCRC = UpdateCRC32(0xFFFFFFFF, &btHeader, 1);
46
47
// Step 2: Continue the calculation with the actual Report ID and Data
48
const uint32_t crc = UpdateCRC32(headerCRC, buffer, len);
49
50
// Step 3: Final XOR (the ~ in C#)
51
return ~crc;
52
}
53
54