From c0ec98a6b90bb55e838f2cff272503ee55db456a Mon Sep 17 00:00:00 2001 From: Daniel Semkowicz via libcamera-devel Date: Tue, 28 Jun 2022 11:06:56 +0200 Subject: libcamera: rkisp1: Control the lens from IPA Check if lens are available and have ability to control the focus. Connect IPA setLensControls() signal to the pipeline slot that controls the lens. If lens are valid, allow changing the focus from IPA by emitting signal to the pipeline. Signed-off-by: Daniel Semkowicz --- src/ipa/rkisp1/ipa_context.h | 4 ++++ src/ipa/rkisp1/rkisp1.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'src/ipa/rkisp1') diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index f387cace..4b199048 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -41,6 +41,10 @@ struct IPASessionConfiguration { }; struct IPAFrameContext { + struct { + uint32_t focus; + } af; + struct { uint32_t exposure; double gain; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 33642094..01bb54fb 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -65,6 +66,8 @@ protected: std::string logPrefix() const override; private: + bool validateLensControls(const ControlInfoMap &lensControls); + void setControls(unsigned int frame); void prepareMetadata(unsigned int frame, unsigned int aeState); @@ -72,6 +75,7 @@ private: std::map mappedBuffers_; ControlInfoMap sensorCtrls_; + std::optional lensCtrls_; /* Camera sensor controls. */ bool autoExposure_; @@ -192,6 +196,14 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, return -EINVAL; } + auto lensControls = entityControls.find(1); + if (lensControls != entityControls.end()) { + if (validateLensControls(lensControls->second)) + lensCtrls_ = lensControls->second; + else + LOG(IPARkISP1, Error) << "Lens control validation failed."; + } + autoExposure_ = true; int32_t minExposure = itExp->second.min().get(); @@ -235,6 +247,23 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, return 0; } +bool IPARkISP1::validateLensControls(const ControlInfoMap &lensControls) +{ + static const uint32_t ctrls[] = { + V4L2_CID_FOCUS_ABSOLUTE, + }; + + for (auto c : ctrls) { + if (lensControls.find(c) == lensControls.end()) { + LOG(IPARkISP1, Error) << "Unable to find lens control " + << utils::hex(c); + return false; + } + } + + return true; +} + void IPARkISP1::mapBuffers(const std::vector &buffers) { for (const IPABuffer &buffer : buffers) { @@ -319,6 +348,13 @@ void IPARkISP1::setControls(unsigned int frame) ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain)); setSensorControls.emit(frame, ctrls); + + if (lensCtrls_) { + ControlList lensCtrls(*lensCtrls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, + static_cast(context_.frameContext.af.focus)); + setLensControls.emit(lensCtrls); + } } void IPARkISP1::prepareMetadata(unsigned int frame, unsigned int aeState) -- cgit v1.2.1