<div dir="ltr"><div dir="ltr">Hi David,<div><br></div><div>Thanks for the work!</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 26 Jan 2023 at 13:46, David Plowman via libcamera-devel <<a href="mailto:libcamera-devel@lists.libcamera.org">libcamera-devel@lists.libcamera.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We handle the flicker modes by passing the correct period to the<br>
AEC/AGC algorithm which already contains the necessary code. The<br>
"Auto" mode is currently unsupported.<br>
<br>
Signed-off-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
 src/ipa/raspberrypi/raspberrypi.cpp | 80 +++++++++++++++++++++++++++++<br>
 1 file changed, 80 insertions(+)<br>
<br>
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp<br>
index 5f7397e2..477d72ba 100644<br>
--- a/src/ipa/raspberrypi/raspberrypi.cpp<br>
+++ b/src/ipa/raspberrypi/raspberrypi.cpp<br>
@@ -86,6 +86,8 @@ static const ControlInfoMap::Map ipaControls{<br>
        { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) },<br>
        { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) },<br>
        { &controls::ExposureValue, ControlInfo(-8.0f, 8.0f, 0.0f) },<br>
+       { &controls::AeFlickerMode, ControlInfo(controls::AeFlickerModeValues) },<br>
+       { &controls::AeFlickerPeriod, ControlInfo(0, 1000000) },<br>
        { &controls::AwbEnable, ControlInfo(false, true) },<br>
        { &controls::ColourGains, ControlInfo(0.0f, 32.0f) },<br>
        { &controls::AwbMode, ControlInfo(controls::AwbModeValues) },<br>
@@ -218,6 +220,12 @@ private:<br>
<br>
        /* Maximum gain code for the sensor. */<br>
        uint32_t maxSensorGainCode_;<br>
+<br>
+       /* The current state of flicker avoidance. */<br>
+       struct FlickerState {<br>
+               int32_t mode;<br>
+               Duration period;<br>
+       } flickerState_;<br>
 };<br>
<br>
 int IPARPi::init(const IPASettings &settings, bool lensPresent, IPAInitResult *result)<br>
@@ -946,6 +954,78 @@ void IPARPi::queueRequest(const ControlList &controls)<br>
                        break;<br>
                }<br>
<br>
+               case controls::AE_FLICKER_MODE: {<br>
+                       RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(<br>
+                               controller_.getAlgorithm("agc"));<br>
+                       if (!agc) {<br>
+                               LOG(IPARPI, Warning)<br>
+                                       << "Could not set AE_FLICKER_MODE - no AGC algorithm";<br>
+                               break;<br>
+                       }<br>
+<br>
+                       int32_t mode = ctrl.second.get<int32_t>();<br>
+                       bool modeValid = true;<br>
+<br>
+                       switch (mode) {<br>
+                       case controls::FlickerOff: {<br>
+                               agc->setFlickerPeriod(0us);<br>
+<br>
+                               break;<br>
+                       }<br>
+<br>
+                       case controls::FlickerFreq50Hz: {<br>
+                               agc->setFlickerPeriod(10000 * 1.0us);<br>
+<br>
+                               break;<br>
+                       }<br>
+<br>
+                       case controls::FlickerFreq60Hz: {<br>
+                               agc->setFlickerPeriod(8333.333 * 1.0us);<br>
+<br>
+                               break;<br>
+                       }<br>
+<br>
+                       case controls::FlickerCustom: {<br>
+                               agc->setFlickerPeriod(flickerState_.period);<br>
+<br>
+                               break;<br>
+                       }<br>
+<br>
+                       default:<br>
+                               LOG(IPARPI, Error) << "Flicker mode " << mode << " is not supported";<br>
+                               modeValid = false;<br>
+<br>
+                               break;<br>
+                       }<br>
+<br>
+                       if (modeValid)<br>
+                               flickerState_.mode = mode;<br>
+<br>
+                       break;<br>
+               }<br>
+<br>
+               case controls::AE_FLICKER_PERIOD: {<br>
+                       RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(<br>
+                               controller_.getAlgorithm("agc"));<br>
+                       if (!agc) {<br>
+                               LOG(IPARPI, Warning)<br>
+                                       << "Could not set AE_FLICKER_PERIOD - no AGC algorithm";<br>
+                               break;<br>
+                       }<br>
+<br>
+                       uint32_t period = ctrl.second.get<int32_t>();<br>
+                       flickerState_.period = period * 1.0us;<br>
+<br>
+                       /*<br>
+                        * We note that it makes no difference if the mode gets set to "custom"<br>
+                        * first, and the period updated after, or vice versa.<br>
+                        */<br>
+                       if (flickerState_.mode == controls::FlickerCustom)<br>
+                               agc->setFlickerPeriod(flickerState_.period);<br>
+<br>
+                       break;<br>
+               }<br>
+<br>
                case controls::AWB_ENABLE: {<br>
                        RPiController::AwbAlgorithm *awb = dynamic_cast<RPiController::AwbAlgorithm *>(<br>
                                controller_.getAlgorithm("awb"));<br>
-- <br>
2.30.2<br>
<br>
</blockquote></div></div>