early-access version 3262
This commit is contained in:
@@ -68,6 +68,69 @@ DriverResult IrsProtocol::DisableIrs() {
|
||||
return result;
|
||||
}
|
||||
|
||||
DriverResult IrsProtocol::SetIrsConfig(IrsMode mode, IrsResolution format) {
|
||||
irs_mode = mode;
|
||||
switch (format) {
|
||||
case IrsResolution::Size320x240:
|
||||
resolution_code = IrsResolutionCode::Size320x240;
|
||||
fragments = IrsFragments::Size320x240;
|
||||
resolution = IrsResolution::Size320x240;
|
||||
break;
|
||||
case IrsResolution::Size160x120:
|
||||
resolution_code = IrsResolutionCode::Size160x120;
|
||||
fragments = IrsFragments::Size160x120;
|
||||
resolution = IrsResolution::Size160x120;
|
||||
break;
|
||||
case IrsResolution::Size80x60:
|
||||
resolution_code = IrsResolutionCode::Size80x60;
|
||||
fragments = IrsFragments::Size80x60;
|
||||
resolution = IrsResolution::Size80x60;
|
||||
break;
|
||||
case IrsResolution::Size20x15:
|
||||
resolution_code = IrsResolutionCode::Size20x15;
|
||||
fragments = IrsFragments::Size20x15;
|
||||
resolution = IrsResolution::Size20x15;
|
||||
break;
|
||||
case IrsResolution::Size40x30:
|
||||
default:
|
||||
resolution_code = IrsResolutionCode::Size40x30;
|
||||
fragments = IrsFragments::Size40x30;
|
||||
resolution = IrsResolution::Size40x30;
|
||||
break;
|
||||
}
|
||||
|
||||
// Restart feature
|
||||
if (is_enabled) {
|
||||
DisableIrs();
|
||||
return EnableIrs();
|
||||
}
|
||||
|
||||
return DriverResult::Success;
|
||||
}
|
||||
|
||||
DriverResult IrsProtocol::RequestImage(std::span<u8> buffer) {
|
||||
const u8 next_packet_fragment =
|
||||
static_cast<u8>((packet_fragment + 1) % (static_cast<u8>(fragments) + 1));
|
||||
|
||||
if (buffer[0] == 0x31 && buffer[49] == 0x03) {
|
||||
u8 new_packet_fragment = buffer[52];
|
||||
if (new_packet_fragment == next_packet_fragment) {
|
||||
packet_fragment = next_packet_fragment;
|
||||
memcpy(buf_image.data() + (300 * packet_fragment), buffer.data() + 59, 300);
|
||||
|
||||
return RequestFrame(packet_fragment);
|
||||
}
|
||||
|
||||
if (new_packet_fragment == packet_fragment) {
|
||||
return RequestFrame(packet_fragment);
|
||||
}
|
||||
|
||||
return ResendFrame(next_packet_fragment);
|
||||
}
|
||||
|
||||
return RequestFrame(packet_fragment);
|
||||
}
|
||||
|
||||
DriverResult IrsProtocol::ConfigureIrs() {
|
||||
LOG_DEBUG(Input, "Configure IRS");
|
||||
constexpr std::size_t max_tries = 28;
|
||||
@@ -78,11 +141,12 @@ DriverResult IrsProtocol::ConfigureIrs() {
|
||||
.command = MCUCommand::ConfigureIR,
|
||||
.sub_command = MCUSubCommand::SetDeviceMode,
|
||||
.irs_mode = IrsMode::ImageTransfer,
|
||||
.number_of_fragments = 0x3,
|
||||
.number_of_fragments = fragments,
|
||||
.mcu_major_version = 0x0500,
|
||||
.mcu_minor_version = 0x1800,
|
||||
.crc = {},
|
||||
};
|
||||
buf_image.resize((static_cast<u8>(fragments) + 1) * 300);
|
||||
|
||||
std::vector<u8> request_data(sizeof(IrsConfigure));
|
||||
memcpy(request_data.data(), &irs_configuration, sizeof(IrsConfigure));
|
||||
@@ -102,7 +166,7 @@ DriverResult IrsProtocol::ConfigureIrs() {
|
||||
}
|
||||
|
||||
DriverResult IrsProtocol::WriteRegistersStep1() {
|
||||
LOG_DEBUG(Input, "Configure IRS");
|
||||
LOG_DEBUG(Input, "WriteRegistersStep1");
|
||||
DriverResult result{DriverResult::Success};
|
||||
constexpr std::size_t max_tries = 28;
|
||||
std::vector<u8> output;
|
||||
@@ -114,15 +178,15 @@ DriverResult IrsProtocol::WriteRegistersStep1() {
|
||||
.number_of_registers = 0x9,
|
||||
.registers =
|
||||
{
|
||||
IrsRegister{0x2e00, resolution},
|
||||
{0x3001, static_cast<u8>(exposure & 0xff)},
|
||||
{0x3101, static_cast<u8>(exposure >> 8)},
|
||||
{0x3201, 0x00},
|
||||
{0x1000, leds},
|
||||
{0x2e01, static_cast<u8>((digital_gain & 0x0f) << 4)},
|
||||
{0x2f01, static_cast<u8>((digital_gain & 0xf0) >> 4)},
|
||||
{0x0e00, ex_light_filter},
|
||||
{0x4301, 0xc8},
|
||||
IrsRegister{IrRegistersAddress::Resolution, static_cast<u8>(resolution_code)},
|
||||
{IrRegistersAddress::ExposureLSB, static_cast<u8>(exposure & 0xff)},
|
||||
{IrRegistersAddress::ExposureMSB, static_cast<u8>(exposure >> 8)},
|
||||
{IrRegistersAddress::ExposureTime, 0x00},
|
||||
{IrRegistersAddress::Leds, static_cast<u8>(leds)},
|
||||
{IrRegistersAddress::DigitalGainLSB, static_cast<u8>((digital_gain & 0x0f) << 4)},
|
||||
{IrRegistersAddress::DigitalGainMSB, static_cast<u8>((digital_gain & 0xf0) >> 4)},
|
||||
{IrRegistersAddress::LedFilter, static_cast<u8>(led_filter)},
|
||||
{IrRegistersAddress::WhitePixelThreshold, 0xc8},
|
||||
},
|
||||
.crc = {},
|
||||
};
|
||||
@@ -162,7 +226,7 @@ DriverResult IrsProtocol::WriteRegistersStep1() {
|
||||
}
|
||||
|
||||
DriverResult IrsProtocol::WriteRegistersStep2() {
|
||||
LOG_DEBUG(Input, "Configure IRS");
|
||||
LOG_DEBUG(Input, "WriteRegistersStep2");
|
||||
constexpr std::size_t max_tries = 28;
|
||||
std::vector<u8> output;
|
||||
std::size_t tries = 0;
|
||||
@@ -173,14 +237,15 @@ DriverResult IrsProtocol::WriteRegistersStep2() {
|
||||
.number_of_registers = 0x8,
|
||||
.registers =
|
||||
{
|
||||
IrsRegister{0x1100, static_cast<u8>(led_intensity >> 8)},
|
||||
{0x1200, static_cast<u8>(led_intensity & 0xff)},
|
||||
{0x2d00, image_flip},
|
||||
{0x6701, static_cast<u8>((denoise >> 16) & 0xff)},
|
||||
{0x6801, static_cast<u8>((denoise >> 8) & 0xff)},
|
||||
{0x6901, static_cast<u8>(denoise & 0xff)},
|
||||
{0x0400, 0x2d},
|
||||
{0x0700, 0x01},
|
||||
IrsRegister{IrRegistersAddress::LedIntensitiyMSB,
|
||||
static_cast<u8>(led_intensity >> 8)},
|
||||
{IrRegistersAddress::LedIntensitiyLSB, static_cast<u8>(led_intensity & 0xff)},
|
||||
{IrRegistersAddress::ImageFlip, static_cast<u8>(image_flip)},
|
||||
{IrRegistersAddress::DenoiseSmoothing, static_cast<u8>((denoise >> 16) & 0xff)},
|
||||
{IrRegistersAddress::DenoiseEdge, static_cast<u8>((denoise >> 8) & 0xff)},
|
||||
{IrRegistersAddress::DenoiseColor, static_cast<u8>(denoise & 0xff)},
|
||||
{IrRegistersAddress::UpdateTime, 0x2d},
|
||||
{IrRegistersAddress::FinalizeConfig, 0x01},
|
||||
},
|
||||
.crc = {},
|
||||
};
|
||||
@@ -202,6 +267,32 @@ DriverResult IrsProtocol::WriteRegistersStep2() {
|
||||
return DriverResult::Success;
|
||||
}
|
||||
|
||||
DriverResult IrsProtocol::RequestFrame(u8 frame) {
|
||||
std::array<u8, 38> mcu_request{};
|
||||
mcu_request[3] = frame;
|
||||
mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36);
|
||||
mcu_request[37] = 0xFF;
|
||||
return SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request);
|
||||
}
|
||||
|
||||
DriverResult IrsProtocol::ResendFrame(u8 frame) {
|
||||
std::array<u8, 38> mcu_request{};
|
||||
mcu_request[1] = 0x1;
|
||||
mcu_request[2] = frame;
|
||||
mcu_request[3] = 0x0;
|
||||
mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36);
|
||||
mcu_request[37] = 0xFF;
|
||||
return SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request);
|
||||
}
|
||||
|
||||
std::vector<u8> IrsProtocol::GetImage() const {
|
||||
return buf_image;
|
||||
}
|
||||
|
||||
IrsResolution IrsProtocol::GetIrsFormat() const {
|
||||
return resolution;
|
||||
}
|
||||
|
||||
bool IrsProtocol::IsEnabled() const {
|
||||
return is_enabled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user