[libcamera-devel,v3,3/3] ipa: rpi: Set lens position to hyperfocal on startup
diff mbox series

Message ID 20230605091406.31757-4-naush@raspberrypi.com
State Accepted
Headers show
Series
  • Default lens behaviour
Related show

Commit Message

Naushir Patuck June 5, 2023, 9:14 a.m. UTC
On the first ipa->configure() call, set the lens position (if a lens is
present) to the default position. Typically this would be the hyperfocal
position based on the tuning data.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/ipa/rpi/common/ipa_base.cpp | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Laurent Pinchart June 6, 2023, 3:22 p.m. UTC | #1
Hi Naush,

Thank you for the patch.

On Mon, Jun 05, 2023 at 10:14:06AM +0100, Naushir Patuck via libcamera-devel wrote:
> On the first ipa->configure() call, set the lens position (if a lens is
> present) to the default position. Typically this would be the hyperfocal
> position based on the tuning data.
> 
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> ---
>  src/ipa/rpi/common/ipa_base.cpp | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp
> index 599ad146a863..dbb95311ba51 100644
> --- a/src/ipa/rpi/common/ipa_base.cpp
> +++ b/src/ipa/rpi/common/ipa_base.cpp
> @@ -199,6 +199,23 @@ int32_t IpaBase::configure(const IPACameraSensorInfo &sensorInfo, const ConfigPa
>  		agcStatus.shutterTime = defaultExposureTime;
>  		agcStatus.analogueGain = defaultAnalogueGain;
>  		applyAGC(&agcStatus, ctrls);
> +
> +		/* Set the lens to the default (typically hyperfocal) position on first start. */

I'll reflow the commit message.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +		if (lensPresent_) {
> +			RPiController::AfAlgorithm *af =
> +				dynamic_cast<RPiController::AfAlgorithm *>(controller_.getAlgorithm("af"));
> +
> +			if (af) {
> +				float defaultPos =
> +					ipaAfControls.at(&controls::LensPosition).def().get<float>();
> +				ControlList lensCtrl(lensCtrls_);
> +				int32_t hwpos;
> +
> +				af->setLensPosition(defaultPos, &hwpos);
> +				lensCtrl.set(V4L2_CID_FOCUS_ABSOLUTE, hwpos);
> +				result->lensControls = std::move(lensCtrl);
> +			}
> +		}
>  	}
>  
>  	result->sensorControls = std::move(ctrls);

Patch
diff mbox series

diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp
index 599ad146a863..dbb95311ba51 100644
--- a/src/ipa/rpi/common/ipa_base.cpp
+++ b/src/ipa/rpi/common/ipa_base.cpp
@@ -199,6 +199,23 @@  int32_t IpaBase::configure(const IPACameraSensorInfo &sensorInfo, const ConfigPa
 		agcStatus.shutterTime = defaultExposureTime;
 		agcStatus.analogueGain = defaultAnalogueGain;
 		applyAGC(&agcStatus, ctrls);
+
+		/* Set the lens to the default (typically hyperfocal) position on first start. */
+		if (lensPresent_) {
+			RPiController::AfAlgorithm *af =
+				dynamic_cast<RPiController::AfAlgorithm *>(controller_.getAlgorithm("af"));
+
+			if (af) {
+				float defaultPos =
+					ipaAfControls.at(&controls::LensPosition).def().get<float>();
+				ControlList lensCtrl(lensCtrls_);
+				int32_t hwpos;
+
+				af->setLensPosition(defaultPos, &hwpos);
+				lensCtrl.set(V4L2_CID_FOCUS_ABSOLUTE, hwpos);
+				result->lensControls = std::move(lensCtrl);
+			}
+		}
 	}
 
 	result->sensorControls = std::move(ctrls);