Skip to content

Commit

Permalink
usb hwm api used also for mipi
Browse files Browse the repository at this point in the history
  • Loading branch information
remibettan committed Jul 21, 2022
1 parent db22646 commit 182fd92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 52 deletions.
12 changes: 6 additions & 6 deletions src/linux/backend-v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ???
Expand All @@ -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)
Expand Down Expand Up @@ -2232,14 +2233,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;
}
Expand Down
61 changes: 15 additions & 46 deletions src/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,54 +120,23 @@ std::vector<uint8_t> librealsense::command_transfer_over_xu::send_receive(const
std::dec << data.size() << " exceeds permitted limit " << HW_MONITOR_BUFFER_SIZE);
}

if (!_is_mipi)
{
std::vector<uint8_t> 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<int>(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<int>(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<uint32_t*>(result.data() + HW_MONITOR_DATA_SIZE_OFFSET)) + SIZE_OF_HW_MONITOR_HEADER;
result.resize(data_size);
}
return result;
}
else
std::vector<uint8_t> 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<int>(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<uint8_t> 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<int>(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<int>(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<uint32_t*>(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<int>(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<uint32_t*>(result.data() + HW_MONITOR_DATA_SIZE_OFFSET)) + SIZE_OF_HW_MONITOR_HEADER;
result.resize(data_size);
}
return result;
});
}

Expand Down

0 comments on commit 182fd92

Please sign in to comment.