[libcamera-devel,08/10] ipa: raspberrypi: Introduce AfTrigger control
diff mbox series

Message ID 20220613142853.98484-9-jeanmichel.hautbois@ideasonboard.com
State New
Headers show
Series
  • ipa: raspberrypi: Introduce an autofocus algorithm
Related show

Commit Message

Jean-Michel Hautbois June 13, 2022, 2:28 p.m. UTC
When the algorithm is in auto mode, it will start a new scan, and either
end in the AfStateFocused ot AfStateFailed state. The user may decide to
trigger a new scan, passing the AfTrigger control down to the pipeline
handler.

Implement a simple trigger operation in the IPA and call it from the
pipeline handler when the control is passed.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 include/libcamera/ipa/raspberrypi.h             |  1 +
 src/ipa/raspberrypi/controller/af_algorithm.hpp |  2 +-
 src/ipa/raspberrypi/controller/iob/af.cpp       | 12 ++++++++++--
 src/ipa/raspberrypi/controller/iob/af.h         |  2 +-
 src/ipa/raspberrypi/raspberrypi.cpp             | 14 ++++++++++++++
 5 files changed, 27 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h
index a7a15904..17c7de72 100644
--- a/include/libcamera/ipa/raspberrypi.h
+++ b/include/libcamera/ipa/raspberrypi.h
@@ -50,6 +50,7 @@  static const ControlInfoMap Controls({
 		{ &controls::AfState, ControlInfo(controls::AfStateValues) },
 		{ &controls::AfPause, ControlInfo(controls::AfPauseValues) },
 		{ &controls::AfPauseState, ControlInfo(controls::AfPauseStateValues) },
+		{ &controls::AfTrigger, ControlInfo(controls::AfTriggerValues) },
 	}, controls::controls);
 
 } /* namespace RPi */
diff --git a/src/ipa/raspberrypi/controller/af_algorithm.hpp b/src/ipa/raspberrypi/controller/af_algorithm.hpp
index ac34e3b6..925b2d03 100644
--- a/src/ipa/raspberrypi/controller/af_algorithm.hpp
+++ b/src/ipa/raspberrypi/controller/af_algorithm.hpp
@@ -19,7 +19,7 @@  public:
 	// An af algorithm must provide the following:
 	virtual void SetMode(const uint32_t &mode) = 0;
 	// start a cycle (in auto mode)
-	virtual void Trigger() = 0;
+	virtual void Trigger(const uint32_t &trigger) = 0;
 	// cancel a cycle (in auto mode)
 	virtual void Cancel() = 0;
 	// pause the continuous mode
diff --git a/src/ipa/raspberrypi/controller/iob/af.cpp b/src/ipa/raspberrypi/controller/iob/af.cpp
index 2efc12f5..1d9bc2bc 100644
--- a/src/ipa/raspberrypi/controller/iob/af.cpp
+++ b/src/ipa/raspberrypi/controller/iob/af.cpp
@@ -59,8 +59,16 @@  void Af::SetMode(const uint32_t &mode)
 	}
 }
 
-void Af::Trigger()
-{
+void Af::Trigger(const uint32_t &trigger)
+{
+	LOG(IoBAf, Debug) << "Trigger called in mode " << mode_
+			  << " with " << trigger;
+	if (mode_ == libcamera::controls::AfModeAuto) {
+		if (trigger == libcamera::controls::AfTriggerStart)
+			afReset();
+		else
+			status_.state = libcamera::controls::AfStateIdle;
+	}
 }
 
 void Af::Pause(const uint32_t &pause)
diff --git a/src/ipa/raspberrypi/controller/iob/af.h b/src/ipa/raspberrypi/controller/iob/af.h
index c4ab3574..12d7bbbd 100644
--- a/src/ipa/raspberrypi/controller/iob/af.h
+++ b/src/ipa/raspberrypi/controller/iob/af.h
@@ -24,7 +24,7 @@  public:
 	void Prepare(Metadata *image_metadata) override;
 	void Process(StatisticsPtr &stats, Metadata *image_metadata) override;
 	void SetMode(const uint32_t &mode) override;
-	void Trigger() override;
+	void Trigger(const uint32_t &trigger) override;
 	void Cancel() override;
 	void Pause(const uint32_t &pause) override;
 	void SetWindows(const libcamera::Rectangle &afWindows) override;
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 8c6f213f..673a2e79 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -986,6 +986,20 @@  void IPARPi::queueRequest(const ControlList &controls)
 			break;
 		}
 
+		case controls::AF_TRIGGER: {
+			RPiController::AfAlgorithm *af = dynamic_cast<RPiController::AfAlgorithm *>(
+				controller_.GetAlgorithm("iob.af"));
+			if (!af) {
+				LOG(IPARPI, Warning)
+					<< "Could not set AF_MODE - no AF algorithm";
+				break;
+			}
+
+			af->Trigger(ctrl.second.get<int32_t>());
+
+			break;
+		}
+
 		default:
 			LOG(IPARPI, Warning)
 				<< "Ctrl " << controls::controls.at(ctrl.first)->name()