From 595d7cc3a95fd90f4d08f31ace5cb72e5942ead1 Mon Sep 17 00:00:00 2001 From: Remi Bettan Date: Tue, 19 Jul 2022 18:45:09 +0300 Subject: [PATCH] usb hwm api used also for mipi --- src/linux/backend-v4l2.cpp | 16 +++++----- src/option.cpp | 61 ++++++++++---------------------------- 2 files changed, 24 insertions(+), 53 deletions(-) diff --git a/src/linux/backend-v4l2.cpp b/src/linux/backend-v4l2.cpp index c8195ca085..4a3793d7e2 100644 --- a/src/linux/backend-v4l2.cpp +++ b/src/linux/backend-v4l2.cpp @@ -74,7 +74,7 @@ constexpr uint32_t RS_CAMERA_CID_AE_SETPOINT_GET = (RS_CAMERA_CID_BAS constexpr uint32_t RS_CAMERA_CID_AE_SETPOINT_SET = (RS_CAMERA_CID_BASE+12); constexpr uint32_t RS_CAMERA_CID_ERB = (RS_CAMERA_CID_BASE+13); constexpr uint32_t RS_CAMERA_CID_EWB = (RS_CAMERA_CID_BASE+14); -constexpr uint32_t RS_CAMERA_CID_HWMC = (RS_CAMERA_CID_BASE+15); +constexpr uint32_t RS_CAMERA_CID_HWMC_LEGACY = (RS_CAMERA_CID_BASE+15); //const uint32_t RS_CAMERA_GENERIC_XU = (RS_CAMERA_CID_BASE+15); // RS_CAMERA_CID_HWMC duplicate?? constexpr uint32_t RS_CAMERA_CID_LASER_POWER_MODE = (RS_CAMERA_CID_BASE+16); // RS_CAMERA_CID_LASER_POWER duplicate ??? @@ -84,6 +84,7 @@ constexpr uint32_t RS_CAMERA_CID_EXPOSURE_MODE = (RS_CAMERA_CID_BAS constexpr uint32_t RS_CAMERA_CID_WHITE_BALANCE_MODE = (RS_CAMERA_CID_BASE+20); // Similar to RS_CAMERA_CID_EWB ?? constexpr uint32_t RS_CAMERA_CID_PRESET = (RS_CAMERA_CID_BASE+21); +constexpr uint32_t RS_CAMERA_CID_HWMC = (RS_CAMERA_CID_BASE+32); /* refe4rence for kernel 4.9 to be removed #define UVC_CID_GENERIC_XU (V4L2_CID_PRIVATE_BASE+15) @@ -2215,7 +2216,9 @@ namespace librealsense bool v4l_mipi_device::get_xu(const extension_unit& xu, uint8_t control, uint8_t* data, int size) const { - v4l2_ext_control xctrl{xu_to_cid(xu,control), uint32_t(size), 0, 0}; + uint32_t the_control = xu_to_cid(xu,control); + + v4l2_ext_control xctrl{the_control, uint32_t(size), 0, 0}; xctrl.p_u8 = data; v4l2_ext_controls ext {xctrl.id & 0xffff0000, 1, 0, 0, 0, &xctrl}; @@ -2232,14 +2235,13 @@ namespace librealsense continue; } - // TODO check if parsing for non-integer values D457 - //memcpy(data,(void*)(&ctrl.value),size); - if (control == RS_ENABLE_AUTO_EXPOSURE) xctrl.value = (V4L2_EXPOSURE_MANUAL == xctrl.value) ? 0 : 1; - // used to parse values that have size > 1 - memcpy(data,(void*)(&xctrl.value), size); + // used to parse the data when only a value is returned (e.g. laser power), + // and not a pointer to a buffer of data (e.g. gvd) + if (size < sizeof(__s64)) + memcpy(data,(void*)(&xctrl.value), size); return true; } diff --git a/src/option.cpp b/src/option.cpp index c75b220e05..92d16eb1ff 100644 --- a/src/option.cpp +++ b/src/option.cpp @@ -120,54 +120,23 @@ std::vector librealsense::command_transfer_over_xu::send_receive(const std::dec << data.size() << " exceeds permitted limit " << HW_MONITOR_BUFFER_SIZE); } - if (!_is_mipi) - { - std::vector transmit_buf(HW_MONITOR_BUFFER_SIZE, 0); - std::copy(data.begin(), data.end(), transmit_buf.begin()); - - if (!dev.set_xu(_xu, _ctrl, transmit_buf.data(), static_cast(transmit_buf.size()))) - throw invalid_value_exception(to_string() << "set_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno)); - - if (require_response) - { - result.resize(HW_MONITOR_BUFFER_SIZE); - if (!dev.get_xu(_xu, _ctrl, result.data(), static_cast(result.size()))) - throw invalid_value_exception(to_string() << "get_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno)); - - // Returned data size located in the last 4 bytes - auto data_size = *(reinterpret_cast(result.data() + HW_MONITOR_DATA_SIZE_OFFSET)) + SIZE_OF_HW_MONITOR_HEADER; - result.resize(data_size); - } - return result; - } - else + std::vector transmit_buf(HW_MONITOR_BUFFER_SIZE, 0); + std::copy(data.begin(), data.end(), transmit_buf.begin()); + + if (!dev.set_xu(_xu, _ctrl, transmit_buf.data(), static_cast(transmit_buf.size()))) + throw invalid_value_exception(to_string() << "set_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno)); + + if (require_response) { - // D457 - size of 1028 needed instead of 1024 (HW_MONITOR_BUFFER_SIZE) - std::vector transmit_buf(HW_MONITOR_BUFFER_SIZE + SIZE_OF_HW_MONITOR_HEADER, 0); - std::copy(data.begin(), data.end(), transmit_buf.begin()); - - if (!dev.set_xu(_xu, _ctrl, transmit_buf.data(), static_cast(transmit_buf.size()))) - throw invalid_value_exception(to_string() << "set_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno)); - - if (require_response) - { - result.resize(HW_MONITOR_BUFFER_SIZE); - if (!dev.get_xu(_xu, _ctrl, result.data(), static_cast(result.size()))) - throw invalid_value_exception(to_string() << "get_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno)); - - // Returned data size located in the last 4 bytes - auto data_size = *(reinterpret_cast(result.data() + HW_MONITOR_DATA_SIZE_OFFSET + SIZE_OF_HW_MONITOR_HEADER)) ; - result.resize(data_size); - - // D457 code - stepping over 24 bytes: - // 4 bytes: header and magic number - // 20 bytes: input command - // this code may be removed after some bug correction in the kernel code - result.insert(result.begin(),transmit_buf.begin() + 24,transmit_buf.begin() + 24 + data_size); - } - return result; - } + result.resize(HW_MONITOR_BUFFER_SIZE); + if (!dev.get_xu(_xu, _ctrl, result.data(), static_cast(result.size()))) + throw invalid_value_exception(to_string() << "get_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno)); + // Returned data size located in the last 4 bytes + auto data_size = *(reinterpret_cast(result.data() + HW_MONITOR_DATA_SIZE_OFFSET)) + SIZE_OF_HW_MONITOR_HEADER; + result.resize(data_size); + } + return result; }); }