summaryrefslogtreecommitdiff
path: root/src/input_common/helpers/joycon_protocol/generic_functions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/generic_functions.cpp')
-rw-r--r--src/input_common/helpers/joycon_protocol/generic_functions.cpp54
1 files changed, 16 insertions, 38 deletions
diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.cpp b/src/input_common/helpers/joycon_protocol/generic_functions.cpp
index cbd9ff4f8..52bb8b61a 100644
--- a/src/input_common/helpers/joycon_protocol/generic_functions.cpp
+++ b/src/input_common/helpers/joycon_protocol/generic_functions.cpp
@@ -10,22 +10,18 @@ GenericProtocol::GenericProtocol(std::shared_ptr<JoyconHandle> handle)
10 : JoyconCommonProtocol(std::move(handle)) {} 10 : JoyconCommonProtocol(std::move(handle)) {}
11 11
12DriverResult GenericProtocol::EnablePassiveMode() { 12DriverResult GenericProtocol::EnablePassiveMode() {
13 SetBlocking(); 13 ScopedSetBlocking sb(this);
14 const auto result = SetReportMode(ReportMode::SIMPLE_HID_MODE); 14 return SetReportMode(ReportMode::SIMPLE_HID_MODE);
15 SetNonBlocking();
16 return result;
17} 15}
18 16
19DriverResult GenericProtocol::EnableActiveMode() { 17DriverResult GenericProtocol::EnableActiveMode() {
20 SetBlocking(); 18 ScopedSetBlocking sb(this);
21 const auto result = SetReportMode(ReportMode::STANDARD_FULL_60HZ); 19 return SetReportMode(ReportMode::STANDARD_FULL_60HZ);
22 SetNonBlocking();
23 return result;
24} 20}
25 21
26DriverResult GenericProtocol::GetDeviceInfo(DeviceInfo& device_info) { 22DriverResult GenericProtocol::GetDeviceInfo(DeviceInfo& device_info) {
23 ScopedSetBlocking sb(this);
27 std::vector<u8> output; 24 std::vector<u8> output;
28 SetBlocking();
29 25
30 const auto result = SendSubCommand(SubCommand::REQ_DEV_INFO, {}, output); 26 const auto result = SendSubCommand(SubCommand::REQ_DEV_INFO, {}, output);
31 27
@@ -34,7 +30,6 @@ DriverResult GenericProtocol::GetDeviceInfo(DeviceInfo& device_info) {
34 memcpy(&device_info, output.data(), sizeof(DeviceInfo)); 30 memcpy(&device_info, output.data(), sizeof(DeviceInfo));
35 } 31 }
36 32
37 SetNonBlocking();
38 return result; 33 return result;
39} 34}
40 35
@@ -43,36 +38,30 @@ DriverResult GenericProtocol::GetControllerType(ControllerType& controller_type)
43} 38}
44 39
45DriverResult GenericProtocol::EnableImu(bool enable) { 40DriverResult GenericProtocol::EnableImu(bool enable) {
41 ScopedSetBlocking sb(this);
46 const std::array<u8, 1> buffer{static_cast<u8>(enable ? 1 : 0)}; 42 const std::array<u8, 1> buffer{static_cast<u8>(enable ? 1 : 0)};
47 std::vector<u8> output; 43 return SendSubCommand(SubCommand::ENABLE_IMU, buffer);
48 SetBlocking();
49 const auto result = SendSubCommand(SubCommand::ENABLE_IMU, buffer, output);
50 SetNonBlocking();
51 return result;
52} 44}
53 45
54DriverResult GenericProtocol::SetImuConfig(GyroSensitivity gsen, GyroPerformance gfrec, 46DriverResult GenericProtocol::SetImuConfig(GyroSensitivity gsen, GyroPerformance gfrec,
55 AccelerometerSensitivity asen, 47 AccelerometerSensitivity asen,
56 AccelerometerPerformance afrec) { 48 AccelerometerPerformance afrec) {
49 ScopedSetBlocking sb(this);
57 const std::array<u8, 4> buffer{static_cast<u8>(gsen), static_cast<u8>(asen), 50 const std::array<u8, 4> buffer{static_cast<u8>(gsen), static_cast<u8>(asen),
58 static_cast<u8>(gfrec), static_cast<u8>(afrec)}; 51 static_cast<u8>(gfrec), static_cast<u8>(afrec)};
59 std::vector<u8> output; 52 return SendSubCommand(SubCommand::SET_IMU_SENSITIVITY, buffer);
60 SetBlocking();
61 const auto result = SendSubCommand(SubCommand::SET_IMU_SENSITIVITY, buffer, output);
62 SetNonBlocking();
63 return result;
64} 53}
65 54
66DriverResult GenericProtocol::GetBattery(u32& battery_level) { 55DriverResult GenericProtocol::GetBattery(u32& battery_level) {
56 // This function is meant to request the high resolution battery status
67 battery_level = 0; 57 battery_level = 0;
68 return DriverResult::NotSupported; 58 return DriverResult::NotSupported;
69} 59}
70 60
71DriverResult GenericProtocol::GetColor(Color& color) { 61DriverResult GenericProtocol::GetColor(Color& color) {
62 ScopedSetBlocking sb(this);
72 std::vector<u8> buffer; 63 std::vector<u8> buffer;
73 SetBlocking();
74 const auto result = ReadSPI(CalAddr::COLOR_DATA, 12, buffer); 64 const auto result = ReadSPI(CalAddr::COLOR_DATA, 12, buffer);
75 SetNonBlocking();
76 65
77 color = {}; 66 color = {};
78 if (result == DriverResult::Success) { 67 if (result == DriverResult::Success) {
@@ -86,10 +75,9 @@ DriverResult GenericProtocol::GetColor(Color& color) {
86} 75}
87 76
88DriverResult GenericProtocol::GetSerialNumber(SerialNumber& serial_number) { 77DriverResult GenericProtocol::GetSerialNumber(SerialNumber& serial_number) {
78 ScopedSetBlocking sb(this);
89 std::vector<u8> buffer; 79 std::vector<u8> buffer;
90 SetBlocking();
91 const auto result = ReadSPI(CalAddr::SERIAL_NUMBER, 16, buffer); 80 const auto result = ReadSPI(CalAddr::SERIAL_NUMBER, 16, buffer);
92 SetNonBlocking();
93 81
94 serial_number = {}; 82 serial_number = {};
95 if (result == DriverResult::Success) { 83 if (result == DriverResult::Success) {
@@ -115,14 +103,9 @@ DriverResult GenericProtocol::GetVersionNumber(FirmwareVersion& version) {
115} 103}
116 104
117DriverResult GenericProtocol::SetHomeLight() { 105DriverResult GenericProtocol::SetHomeLight() {
106 ScopedSetBlocking sb(this);
118 static constexpr std::array<u8, 3> buffer{0x0f, 0xf0, 0x00}; 107 static constexpr std::array<u8, 3> buffer{0x0f, 0xf0, 0x00};
119 std::vector<u8> output; 108 return SendSubCommand(SubCommand::SET_HOME_LIGHT, buffer);
120 SetBlocking();
121
122 const auto result = SendSubCommand(SubCommand::SET_HOME_LIGHT, buffer, output);
123
124 SetNonBlocking();
125 return result;
126} 109}
127 110
128DriverResult GenericProtocol::SetLedBusy() { 111DriverResult GenericProtocol::SetLedBusy() {
@@ -130,14 +113,9 @@ DriverResult GenericProtocol::SetLedBusy() {
130} 113}
131 114
132DriverResult GenericProtocol::SetLedPattern(u8 leds) { 115DriverResult GenericProtocol::SetLedPattern(u8 leds) {
116 ScopedSetBlocking sb(this);
133 const std::array<u8, 1> buffer{leds}; 117 const std::array<u8, 1> buffer{leds};
134 std::vector<u8> output; 118 return SendSubCommand(SubCommand::SET_PLAYER_LIGHTS, buffer);
135 SetBlocking();
136
137 const auto result = SendSubCommand(SubCommand::SET_PLAYER_LIGHTS, buffer, output);
138
139 SetNonBlocking();
140 return result;
141} 119}
142 120
143DriverResult GenericProtocol::SetLedBlinkPattern(u8 leds) { 121DriverResult GenericProtocol::SetLedBlinkPattern(u8 leds) {