Compare commits
1 Commits
tera
...
ring_proto
Author | SHA1 | Date | |
---|---|---|---|
0495a13e31 |
@ -281,10 +281,10 @@ static_assert(sizeof(ProcessorState) == 0xE20, "ProcessorState is an invalid siz
|
||||
|
||||
// This is nn::irsensor::detail::DeviceFormat
|
||||
struct DeviceFormat {
|
||||
Core::IrSensor::IrCameraStatus camera_status{Core::IrSensor::IrCameraStatus::Available};
|
||||
Core::IrSensor::IrCameraStatus camera_status{Core::IrSensor::IrCameraStatus::Unconnected};
|
||||
Core::IrSensor::IrCameraInternalStatus camera_internal_status{
|
||||
Core::IrSensor::IrCameraInternalStatus::Stopped};
|
||||
Core::IrSensor::IrSensorMode mode{Core::IrSensor::IrSensorMode::ImageTransferProcessor};
|
||||
Core::IrSensor::IrCameraInternalStatus::Ready};
|
||||
Core::IrSensor::IrSensorMode mode{Core::IrSensor::IrSensorMode::None};
|
||||
ProcessorState state{};
|
||||
};
|
||||
static_assert(sizeof(DeviceFormat) == 0xE30, "DeviceFormat is an invalid size");
|
||||
|
@ -296,7 +296,7 @@ void IRS::RunTeraPluginProcessor(HLERequestContext& ctx) {
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle);
|
||||
MakeProcessorWithCoreContext<TeraPluginProcessor>(parameters.camera_handle, device);
|
||||
MakeProcessor<TeraPluginProcessor>(parameters.camera_handle, device);
|
||||
auto& image_transfer_processor =
|
||||
GetProcessor<TeraPluginProcessor>(parameters.camera_handle);
|
||||
image_transfer_processor.SetConfig(parameters.processor_config);
|
||||
|
@ -1,103 +1,29 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hid/emulated_controller.h"
|
||||
#include "core/hid/hid_core.h"
|
||||
#include "core/hle/service/hid/irsensor/tera_plugin_processor.h"
|
||||
|
||||
namespace Service::IRS {
|
||||
TeraPluginProcessor::TeraPluginProcessor(Core::HID::HIDCore& hid_core_,
|
||||
Core::IrSensor::DeviceFormat& device_format,
|
||||
std::size_t npad_index)
|
||||
: device{device_format} {
|
||||
npad_device = hid_core_.GetEmulatedControllerByIndex(npad_index);
|
||||
|
||||
TeraPluginProcessor::TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format)
|
||||
: device(device_format) {
|
||||
device.mode = Core::IrSensor::IrSensorMode::TeraPluginProcessor;
|
||||
device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected;
|
||||
device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped;
|
||||
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<TeraSharedMemory*>(&device_format.state.processor_raw_data));
|
||||
|
||||
Core::HID::ControllerUpdateCallback engine_callback{
|
||||
.on_change = [this](Core::HID::ControllerTriggerType type) { OnControllerUpdate(type); },
|
||||
.is_npad_service = true,
|
||||
};
|
||||
callback_key = npad_device->SetCallback(engine_callback);
|
||||
}
|
||||
|
||||
TeraPluginProcessor::~TeraPluginProcessor() {
|
||||
npad_device->DeleteCallback(callback_key);
|
||||
};
|
||||
TeraPluginProcessor::~TeraPluginProcessor() = default;
|
||||
|
||||
void TeraPluginProcessor::StartProcessor() {
|
||||
device.camera_status = Core::IrSensor::IrCameraStatus::Available;
|
||||
device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Ready;
|
||||
}
|
||||
void TeraPluginProcessor::StartProcessor() {}
|
||||
|
||||
void TeraPluginProcessor::SuspendProcessor() {}
|
||||
|
||||
void TeraPluginProcessor::StopProcessor() {}
|
||||
|
||||
void TeraPluginProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType type) {
|
||||
if (type != Core::HID::ControllerTriggerType::IrSensor) {
|
||||
return;
|
||||
}
|
||||
|
||||
next_state = {};
|
||||
const auto camera_data = npad_device->GetCamera();
|
||||
auto filtered_image = camera_data.data;
|
||||
|
||||
memcpy(next_state.data.data(), filtered_image.data(), GetDataSize(format));
|
||||
|
||||
// These 4 bytes seem to control the brightness of a image
|
||||
next_state.data[0] = 1;
|
||||
next_state.data[1] = 2;
|
||||
next_state.data[2] = 0xde;
|
||||
next_state.data[3] = 0x07;
|
||||
|
||||
// Data from HW
|
||||
/* next_state.data = {
|
||||
0x01, 0x02, 0xde, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x48, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x13, 0x13, 0x00, 0x00, 0x06, 0x00, 0xc0, 0x28,
|
||||
0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x3c, 0x00, 0x05, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x20, 0xa8, 0x09, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04,
|
||||
0x12, 0x41, 0x00, 0x00, 0x13, 0x86, 0x02, 0x00, 0x00, 0x00, 0x1e, 0xc0, 0x02, 0x00, 0x00, 0x00,
|
||||
0x40, 0x0f, 0x00, 0x00, 0x00, 0x30, 0xcd, 0x34, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x10, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x00, 0x00, 0x80, 0xf3, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x36, 0x08, 0x04, 0x60, 0x02, 0x00, 0x76, 0x80, 0x09, 0x00, 0x00, 0x88, 0xd1,
|
||||
0x20, 0x00, 0x00, 0x00, 0x65, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x28, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x40, 0x01, 0x68, 0x00, 0x00, 0x00,
|
||||
0x80, 0xf2, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x04, 0x80, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x06, 0x00,
|
||||
0x00, 0x00, 0x04, 0xa0, 0x57, 0x02, 0x04, 0x40, 0x51, 0x02, 0x00, 0x40, 0xc1, 0x01, 0x00, 0x50,
|
||||
0x86, 0x02, 0x00, 0x50, 0x0d, 0x04, 0x00, 0xb0, 0x05, 0x00, 0x00, 0x50, 0x04, 0x00, 0x00, 0xb0,
|
||||
0x09, 0x00, 0x00, 0xb0, 0x01, 0xc0, 0x06, 0xc0, 0x0e, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x20,
|
||||
0x01, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x20, 0x05, 0x00, 0x00, 0x80,
|
||||
0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x86, 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00,
|
||||
};*/
|
||||
next_state.sampling_number = camera_data.sample;
|
||||
next_state.timestamp = next_state.sampling_number + 131;
|
||||
next_state.ambient_noise_level = Core::IrSensor::CameraAmbientNoiseLevel::Low;
|
||||
|
||||
shared_memory->tera_lifo.WriteNextEntry(next_state);
|
||||
|
||||
if (!IsProcessorActive()) {
|
||||
StartProcessor();
|
||||
}
|
||||
}
|
||||
void TeraPluginProcessor::SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config) {
|
||||
current_config.mode = config.mode;
|
||||
current_config.unknown_1 = config.unknown_1;
|
||||
current_config.unknown_2 = config.unknown_2;
|
||||
current_config.unknown_3 = config.unknown_3;
|
||||
|
||||
LOG_ERROR(Service_IRS, "{} {} {} {}", config.mode, config.unknown_1, config.unknown_2,
|
||||
config.unknown_3);
|
||||
npad_device->SetCameraFormat(format);
|
||||
}
|
||||
|
||||
} // namespace Service::IRS
|
||||
|
@ -3,21 +3,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/irs_types.h"
|
||||
#include "core/hle/service/hid/irs_ring_lifo.h"
|
||||
#include "core/hle/service/hid/irsensor/processor_base.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedController;
|
||||
} // namespace Core::HID
|
||||
|
||||
namespace Service::IRS {
|
||||
class TeraPluginProcessor final : public ProcessorBase {
|
||||
public:
|
||||
explicit TeraPluginProcessor(Core::HID::HIDCore& hid_core_,
|
||||
Core::IrSensor::DeviceFormat& device_format,
|
||||
std::size_t npad_index);
|
||||
explicit TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format);
|
||||
~TeraPluginProcessor() override;
|
||||
|
||||
// Called when the processor is initialized
|
||||
@ -33,10 +27,6 @@ public:
|
||||
void SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config);
|
||||
|
||||
private:
|
||||
static constexpr auto format = Core::IrSensor::ImageTransferProcessorFormat::Size20x15;
|
||||
static constexpr std::size_t width = 40;
|
||||
static constexpr std::size_t height = 30;
|
||||
|
||||
// This is nn::irsensor::TeraPluginProcessorConfig
|
||||
struct TeraPluginProcessorConfig {
|
||||
u8 mode;
|
||||
@ -56,22 +46,8 @@ private:
|
||||
static_assert(sizeof(TeraPluginProcessorState) == 0x140,
|
||||
"TeraPluginProcessorState is an invalid size");
|
||||
|
||||
struct TeraSharedMemory {
|
||||
Service::IRS::Lifo<TeraPluginProcessorState, 6> tera_lifo;
|
||||
static_assert(sizeof(tera_lifo) == 0x790, "tera_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x1A4);
|
||||
};
|
||||
static_assert(sizeof(TeraSharedMemory) == 0xE20, "TeraSharedMemory is an invalid size");
|
||||
|
||||
void OnControllerUpdate(Core::HID::ControllerTriggerType type);
|
||||
|
||||
TeraSharedMemory* shared_memory = nullptr;
|
||||
TeraPluginProcessorState next_state{};
|
||||
|
||||
TeraPluginProcessorConfig current_config{};
|
||||
Core::IrSensor::DeviceFormat& device;
|
||||
Core::HID::EmulatedController* npad_device;
|
||||
int callback_key{};
|
||||
};
|
||||
|
||||
} // namespace Service::IRS
|
||||
|
@ -388,6 +388,32 @@ enum class ExternalDeviceId : u16 {
|
||||
Starlink = 0x2800,
|
||||
};
|
||||
|
||||
// Most missing command names are leftovers from other firmware versions
|
||||
enum class RingConCommand : u32 {
|
||||
GetFirmwareVersion = 0x00020000,
|
||||
ReadId = 0x00020100,
|
||||
JoyPolling = 0x00020101,
|
||||
Unknown1 = 0x00020104,
|
||||
c20105 = 0x00020105,
|
||||
Unknown2 = 0x00020204,
|
||||
Unknown3 = 0x00020304,
|
||||
Unknown4 = 0x00020404,
|
||||
ReadUnkCal = 0x00020504,
|
||||
ReadFactoryCal = 0x00020A04,
|
||||
Unknown5 = 0x00021104,
|
||||
Unknown6 = 0x00021204,
|
||||
Unknown7 = 0x00021304,
|
||||
ReadUserCal = 0x00021A04,
|
||||
ReadRepCount = 0x00023104,
|
||||
ReadTotalPushCount = 0x00023204,
|
||||
ResetRepCount = 0x04013104,
|
||||
Unknown8 = 0x04011104,
|
||||
Unknown9 = 0x04011204,
|
||||
Unknown10 = 0x04011304,
|
||||
SaveCalData = 0x10011A04,
|
||||
Error = 0xFFFFFFFF,
|
||||
};
|
||||
|
||||
enum class DriverResult {
|
||||
Success,
|
||||
WrongReply,
|
||||
@ -687,6 +713,57 @@ struct RingStatus {
|
||||
s16 min_value;
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct RingCommandData {
|
||||
u8 data_type;
|
||||
RingConCommand command;
|
||||
};
|
||||
static_assert(sizeof(RingCommandData) == 0x5, "RingCommandData is an invalid size");
|
||||
#pragma pack(pop)
|
||||
|
||||
struct RingFactoryCalibration {
|
||||
s32_le os_max;
|
||||
s32_le hk_max;
|
||||
s32_le zero_min;
|
||||
s32_le zero_max;
|
||||
};
|
||||
static_assert(sizeof(RingFactoryCalibration) == 0x10, "RingFactoryCalibration is an invalid size");
|
||||
|
||||
struct RingCalibrationValue {
|
||||
s16 value;
|
||||
u16 crc;
|
||||
};
|
||||
static_assert(sizeof(RingCalibrationValue) == 0x4, "RingCalibrationValue is an invalid size");
|
||||
|
||||
struct RingUserCalibration {
|
||||
RingCalibrationValue os_max;
|
||||
RingCalibrationValue hk_max;
|
||||
RingCalibrationValue zero;
|
||||
};
|
||||
static_assert(sizeof(RingUserCalibration) == 0xC, "RingUserCalibration is an invalid size");
|
||||
|
||||
struct RingReadId {
|
||||
u16 id_l_x0;
|
||||
u16 id_l_x0_2;
|
||||
u16 id_l_x4;
|
||||
u16 id_h_x0;
|
||||
u16 id_h_x0_2;
|
||||
u16 id_h_x4;
|
||||
};
|
||||
static_assert(sizeof(RingReadId) == 0xC, "RingReadId is an invalid size");
|
||||
|
||||
struct RingCommandReply {
|
||||
DriverResult result;
|
||||
RingConCommand command;
|
||||
FirmwareVersion firmware;
|
||||
RingFactoryCalibration factory_calibration;
|
||||
RingUserCalibration user_calibration;
|
||||
RingReadId read_id;
|
||||
u8 c20105;
|
||||
u8 total_push_count;
|
||||
u8 total_rep_count;
|
||||
};
|
||||
|
||||
struct VibrationPacket {
|
||||
OutputReport output_report;
|
||||
u8 packet_counter;
|
||||
|
@ -108,6 +108,65 @@ DriverResult RingConProtocol::ConfigureRing() {
|
||||
return SendSubCommand(SubCommand::ENABLE_EXTERNAL_POLLING, ringcon_data);
|
||||
}
|
||||
|
||||
|
||||
DriverResult RingConProtocol::SendCommand(RingConCommand command) {
|
||||
SubCommandResponce output{};
|
||||
RingCommandData data{
|
||||
.data_type = 0x04, // This seems to be always 4 for this command
|
||||
.command = command,
|
||||
};
|
||||
RingCommandReply reply{
|
||||
.result = DriverResult::Success,
|
||||
.command = command,
|
||||
};
|
||||
|
||||
std::array<u8, sizeof(RingCommandData)> raw_data{};
|
||||
memcpy(raw_data.data(), &data, sizeof(RingCommandData));
|
||||
const DriverResult result = SendSubCommand(SubCommand::SET_EXTERNAL_CONFIG, raw_data, output);
|
||||
|
||||
if (result != DriverResult::Success) {
|
||||
reply.result = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
switch (command) {
|
||||
case RingConCommand::GetFirmwareVersion:
|
||||
memcpy(&reply.firmware, output.command_data.data() + 6, sizeof(FirmwareVersion));
|
||||
break;
|
||||
case RingConCommand::ReadId:
|
||||
memcpy(&reply.read_id, output.command_data.data() + 6,
|
||||
sizeof(RingReadId));
|
||||
break;
|
||||
case RingConCommand::c20105:
|
||||
reply.c20105 = output.command_data[6];
|
||||
break;
|
||||
case RingConCommand::ReadUnkCal:
|
||||
break;
|
||||
case RingConCommand::ReadFactoryCal:
|
||||
memcpy(&reply.factory_calibration, output.command_data.data() + 6,
|
||||
sizeof(RingFactoryCalibration));
|
||||
break;
|
||||
case RingConCommand::ReadUserCal:
|
||||
memcpy(&reply.user_calibration, output.command_data.data() + 6, sizeof(RingUserCalibration));
|
||||
break;
|
||||
case RingConCommand::ReadRepCount:
|
||||
reply.total_rep_count = output.command_data[6];
|
||||
break;
|
||||
case RingConCommand::ReadTotalPushCount:
|
||||
reply.total_push_count = output.command_data[6];
|
||||
break;
|
||||
case RingConCommand::ResetRepCount:
|
||||
break;
|
||||
case RingConCommand::SaveCalData:
|
||||
break;
|
||||
default:
|
||||
reply.result = DriverResult::NotSupported;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool RingConProtocol::IsEnabled() const {
|
||||
return is_enabled;
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ public:
|
||||
|
||||
DriverResult StartRingconPolling();
|
||||
|
||||
// Hidbus can send individual commands to the ring each one with an unique reply
|
||||
DriverResult SendCommand(RingConCommand command);
|
||||
|
||||
bool IsEnabled() const;
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user