[{"id":22419,"web_url":"https://patchwork.libcamera.org/comment/22419/","msgid":"<164807994355.1103026.7265636026533828231@Monstersaurus>","date":"2022-03-23T23:59:03","subject":"Re: [libcamera-devel] [RFC PATCH v2 4/4] ipa: raspberrypi: Control\n\tthe lens position","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Jean-Michel Hautbois via libcamera-devel (2022-03-23 16:01:45)\n> Now that the ancillary links are configured, we can use the CameraLens\n> class and control the VCM through the IPA.\n> For now, force a default value for the lens position, until the AF\n> algorithm is introduced.\n\nI think that needs updating, as there is an algorithm.\n\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n> v2: Change the need for lens control to be present\n> ---\n>  src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++-\n>  1 file changed, 41 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index cf4e6cab..ff302e37 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -30,6 +30,7 @@\n>  \n>  #include \"libcamera/internal/mapped_framebuffer.h\"\n>  \n> +#include \"af_status.h\"\n>  #include \"agc_algorithm.hpp\"\n>  #include \"agc_status.h\"\n>  #include \"alsc_status.h\"\n> @@ -110,6 +111,7 @@ private:\n>         void setMode(const IPACameraSensorInfo &sensorInfo);\n>         bool validateSensorControls();\n>         bool validateIspControls();\n> +       bool validateLensControls();\n>         void queueRequest(const ControlList &controls);\n>         void returnEmbeddedBuffer(unsigned int bufferId);\n>         void prepareISP(const ISPConfig &data);\n> @@ -134,6 +136,7 @@ private:\n>  \n>         ControlInfoMap sensorCtrls_;\n>         ControlInfoMap ispCtrls_;\n> +       ControlInfoMap lensCtrls_;\n>         ControlList libcameraMetadata_;\n>  \n>         /* Camera sensor params. */\n> @@ -344,7 +347,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n>                       const IPAConfig &ipaConfig,\n>                       ControlList *controls)\n>  {\n> -       if (entityControls.size() != 2) {\n> +       if (entityControls.size() < 2) {\n>                 LOG(IPARPI, Error) << \"No ISP or sensor controls found.\";\n>                 return -1;\n>         }\n> @@ -352,6 +355,14 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n>         sensorCtrls_ = entityControls.at(0);\n>         ispCtrls_ = entityControls.at(1);\n>  \n> +       /* Lens may not be present, don't make it an hard assumption. */\n> +       auto lensControl = entityControls.find(2);\n> +       if (lensControl != entityControls.end()) {\n> +               lensCtrls_ = lensControl->second;\n> +               if (!validateLensControls())\n> +                       LOG(IPARPI, Error) << \"Lens control validation failed.\";\n> +       }\n> +\n>         if (!validateSensorControls()) {\n>                 LOG(IPARPI, Error) << \"Sensor control validation failed.\";\n>                 return -1;\n> @@ -362,6 +373,10 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n>                 return -1;\n>         }\n>  \n> +       if (!validateLensControls()) {\n> +               LOG(IPARPI, Error) << \"Lens control validation failed.\";\n> +       }\n\nIs this validating lens controls twice ? Do we need this second call?\n\n\n> +\n>         maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get<int32_t>();\n>  \n>         /* Setup a metadata ControlList to output metadata. */\n> @@ -580,6 +595,23 @@ bool IPARPi::validateIspControls()\n>         return true;\n>  }\n>  \n> +bool IPARPi::validateLensControls()\n> +{\n> +       static const uint32_t ctrls[] = {\n> +               V4L2_CID_FOCUS_ABSOLUTE,\n> +       };\n> +\n> +       for (auto c : ctrls) {\n> +               if (lensCtrls_.find(c) == lensCtrls_.end()) {\n> +                       LOG(IPARPI, Error) << \"Unable to find lens control \"\n> +                                          << utils::hex(c);\n> +                       return false;\n> +               }\n> +       }\n> +\n> +       return true;\n> +}\n> +\n>  /*\n>   * Converting between enums (used in the libcamera API) and the names that\n>   * we use to identify different modes. Unfortunately, the conversion tables\n> @@ -1068,6 +1100,14 @@ void IPARPi::processStats(unsigned int bufferId)\n>  \n>                 setDelayedControls.emit(ctrls);\n>         }\n> +\n> +       struct AfStatus afStatus;\n> +       if (rpiMetadata_.Get(\"af.status\", afStatus) == 0) {\n> +               ControlList lensCtrls(lensCtrls_);\n> +               lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,\n> +                             static_cast<int32_t>(afStatus.focus));\n> +               setLensControls.emit(lensCtrls);\n> +       }\n>  }\n>  \n>  void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n> -- \n> 2.32.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C1723BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Mar 2022 23:59:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2C99F604C6;\n\tThu, 24 Mar 2022 00:59:08 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 37E81604C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Mar 2022 00:59:06 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C421712E9;\n\tThu, 24 Mar 2022 00:59:05 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648079948;\n\tbh=s/yyUPiOVsTVbRjj1nfE496K8bo6XVB3eovTvITQoH0=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=vFQby3sz3XsKvYZV36DHA7CotmBzYYQ7EBJqcJe+e6cd+xj3n9aPnoG7zDpMnyuuW\n\ti0/VD+dxujwMWGsVGMJM2LyI1/IYTSOsc2xw5I432sUdaOrCDBN8Wg7etkzt8N1ToG\n\tkFibPZhagnFvZjREFLEwJSKqzQO9LcMDcgvCsQfS+Jj/82ne/7P+zyB1KzmTc35+N4\n\tn1643indaHYGU+dt8Zqcs1yNu/EwtYqTjxAq3oaqxw9kwEdUSiS+ZujQc2DhgDpzON\n\tDodgwhquolQg1/3m5DS8w8+xuuOK1TVCr7GXEiCUELyPF5mbVAfxkpIN2uxkM2JqxN\n\tI/wYrOSw1C87Q==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648079945;\n\tbh=s/yyUPiOVsTVbRjj1nfE496K8bo6XVB3eovTvITQoH0=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=HnXmWKfosnPz5RNemS8Ebv2wiMDbLlgqSnzZiTboEHcNA9JOgKVo+Yn2MkrlF3PNl\n\tNE6G0EudfS51ocyOlkE7/XR4YewwzQf5BGrW2IVbTy1/NSAwxaW/wY+Tcshlu52fJP\n\tEzS4b2dIanIL6Z1P4DgYFl8A9axaP2SkyDVM0nyI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"HnXmWKfo\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220323160145.90606-5-jeanmichel.hautbois@ideasonboard.com>","References":"<20220323160145.90606-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220323160145.90606-5-jeanmichel.hautbois@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 23 Mar 2022 23:59:03 +0000","Message-ID":"<164807994355.1103026.7265636026533828231@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [RFC PATCH v2 4/4] ipa: raspberrypi: Control\n\tthe lens position","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":22422,"web_url":"https://patchwork.libcamera.org/comment/22422/","msgid":"<586405a9-dabf-e95f-99a9-00a1ab96c8b0@ideasonboard.com>","date":"2022-03-24T08:21:06","subject":"Re: [libcamera-devel] [RFC PATCH v2 4/4] ipa: raspberrypi: Control\n\tthe lens position","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"content":"Hi Kieran,\n\nOn 24/03/2022 00:59, Kieran Bingham wrote:\n> Quoting Jean-Michel Hautbois via libcamera-devel (2022-03-23 16:01:45)\n>> Now that the ancillary links are configured, we can use the CameraLens\n>> class and control the VCM through the IPA.\n>> For now, force a default value for the lens position, until the AF\n>> algorithm is introduced.\n> \n> I think that needs updating, as there is an algorithm.\n\nThe last sentence is indeed not needed.\n\n> \n>>\n>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n>> ---\n>> v2: Change the need for lens control to be present\n>> ---\n>>   src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++-\n>>   1 file changed, 41 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n>> index cf4e6cab..ff302e37 100644\n>> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n>> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n>> @@ -30,6 +30,7 @@\n>>   \n>>   #include \"libcamera/internal/mapped_framebuffer.h\"\n>>   \n>> +#include \"af_status.h\"\n>>   #include \"agc_algorithm.hpp\"\n>>   #include \"agc_status.h\"\n>>   #include \"alsc_status.h\"\n>> @@ -110,6 +111,7 @@ private:\n>>          void setMode(const IPACameraSensorInfo &sensorInfo);\n>>          bool validateSensorControls();\n>>          bool validateIspControls();\n>> +       bool validateLensControls();\n>>          void queueRequest(const ControlList &controls);\n>>          void returnEmbeddedBuffer(unsigned int bufferId);\n>>          void prepareISP(const ISPConfig &data);\n>> @@ -134,6 +136,7 @@ private:\n>>   \n>>          ControlInfoMap sensorCtrls_;\n>>          ControlInfoMap ispCtrls_;\n>> +       ControlInfoMap lensCtrls_;\n>>          ControlList libcameraMetadata_;\n>>   \n>>          /* Camera sensor params. */\n>> @@ -344,7 +347,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n>>                        const IPAConfig &ipaConfig,\n>>                        ControlList *controls)\n>>   {\n>> -       if (entityControls.size() != 2) {\n>> +       if (entityControls.size() < 2) {\n>>                  LOG(IPARPI, Error) << \"No ISP or sensor controls found.\";\n>>                  return -1;\n>>          }\n>> @@ -352,6 +355,14 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n>>          sensorCtrls_ = entityControls.at(0);\n>>          ispCtrls_ = entityControls.at(1);\n>>   \n>> +       /* Lens may not be present, don't make it an hard assumption. */\n>> +       auto lensControl = entityControls.find(2);\n>> +       if (lensControl != entityControls.end()) {\n>> +               lensCtrls_ = lensControl->second;\n>> +               if (!validateLensControls())\n>> +                       LOG(IPARPI, Error) << \"Lens control validation failed.\";\n>> +       }\n>> +\n>>          if (!validateSensorControls()) {\n>>                  LOG(IPARPI, Error) << \"Sensor control validation failed.\";\n>>                  return -1;\n>> @@ -362,6 +373,10 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n>>                  return -1;\n>>          }\n>>   \n>> +       if (!validateLensControls()) {\n>> +               LOG(IPARPI, Error) << \"Lens control validation failed.\";\n>> +       }\n> \n> Is this validating lens controls twice ? Do we need this second call?\n\nOh, yes, mixing two patches... now corrected, thanks !\n\n> \n> \n>> +\n>>          maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get<int32_t>();\n>>   \n>>          /* Setup a metadata ControlList to output metadata. */\n>> @@ -580,6 +595,23 @@ bool IPARPi::validateIspControls()\n>>          return true;\n>>   }\n>>   \n>> +bool IPARPi::validateLensControls()\n>> +{\n>> +       static const uint32_t ctrls[] = {\n>> +               V4L2_CID_FOCUS_ABSOLUTE,\n>> +       };\n>> +\n>> +       for (auto c : ctrls) {\n>> +               if (lensCtrls_.find(c) == lensCtrls_.end()) {\n>> +                       LOG(IPARPI, Error) << \"Unable to find lens control \"\n>> +                                          << utils::hex(c);\n>> +                       return false;\n>> +               }\n>> +       }\n>> +\n>> +       return true;\n>> +}\n>> +\n>>   /*\n>>    * Converting between enums (used in the libcamera API) and the names that\n>>    * we use to identify different modes. Unfortunately, the conversion tables\n>> @@ -1068,6 +1100,14 @@ void IPARPi::processStats(unsigned int bufferId)\n>>   \n>>                  setDelayedControls.emit(ctrls);\n>>          }\n>> +\n>> +       struct AfStatus afStatus;\n>> +       if (rpiMetadata_.Get(\"af.status\", afStatus) == 0) {\n>> +               ControlList lensCtrls(lensCtrls_);\n>> +               lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,\n>> +                             static_cast<int32_t>(afStatus.focus));\n>> +               setLensControls.emit(lensCtrls);\n>> +       }\n>>   }\n>>   \n>>   void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n>> -- \n>> 2.32.0\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 02D4BC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Mar 2022 08:21:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 17F95604C6;\n\tThu, 24 Mar 2022 09:21:12 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1D6B9601F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Mar 2022 09:21:10 +0100 (CET)","from [IPV6:2a01:e0a:169:7140:62c2:96e1:1c82:440d] (unknown\n\t[IPv6:2a01:e0a:169:7140:62c2:96e1:1c82:440d])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BAC64FEF;\n\tThu, 24 Mar 2022 09:21:09 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648110072;\n\tbh=nC0gQh5+nU0ecEtgcVhbNZCsxaj1bQP11tEwofgK6Nk=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=M4+75BktM+hTr9T+9cn1jiZvHCTOV9cZl5Jz9vgA1ZpRvHYl/nLGUDuXGmy5Hoy8Q\n\tsHahdteKMoOqSKlTPkwFN9lj9b/sm291FhC5oUSfH4nszWxLzdtAhnCdljqFDIx5NB\n\tnbyiaPBUU2sN+h2N4AR3cmXc9k8Gb1yzfItWXcDEitrNX4ZsmTvZfdRfkTZKs/yOko\n\tsk3IoWpckLKkWBX+8PMYRcIuw6EdutsrDxhugirBSTOyB9gYhlQU6r4jBo7cIpajCi\n\tBis6UoYe3DXWDcwsXlLS6NgNCTAW8bHBZL4ZJruhbdiB9Edku9mVk1BrVhvlfR2HPM\n\twya0OU5Xxfe3g==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648110069;\n\tbh=nC0gQh5+nU0ecEtgcVhbNZCsxaj1bQP11tEwofgK6Nk=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=dyXtNzbIjbKgjb7EB4NeWvaThZ91vTq9lxed97jEoAjTs0AO7P+7ParvvsIfvHiZg\n\tFYMtwvhaWJKxQKlHtQUWC2e+QVQK6XASz1aRuHyYFJHZw11UD9b3t+0Qzbsl5VHPtL\n\tl9K2PIlr7o0mt662gJMDp6nMo5erFYzWILx6lKFA="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"dyXtNzbI\"; dkim-atps=neutral","Message-ID":"<586405a9-dabf-e95f-99a9-00a1ab96c8b0@ideasonboard.com>","Date":"Thu, 24 Mar 2022 09:21:06 +0100","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.7.0","Content-Language":"en-US","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220323160145.90606-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220323160145.90606-5-jeanmichel.hautbois@ideasonboard.com>\n\t<164807994355.1103026.7265636026533828231@Monstersaurus>","In-Reply-To":"<164807994355.1103026.7265636026533828231@Monstersaurus>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [RFC PATCH v2 4/4] ipa: raspberrypi: Control\n\tthe lens position","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Jean-Michel Hautbois via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":22428,"web_url":"https://patchwork.libcamera.org/comment/22428/","msgid":"<CAEmqJPpv9+eT-=ZvimazjCGc6Gv6w1rKKjg9j_NZ0cpREy5uHQ@mail.gmail.com>","date":"2022-03-24T10:34:23","subject":"Re: [libcamera-devel] [RFC PATCH v2 4/4] ipa: raspberrypi: Control\n\tthe lens position","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Jean-Michel,\n\nThank you for your work.\n\nOn Wed, 23 Mar 2022 at 16:01, Jean-Michel Hautbois via libcamera-devel <\nlibcamera-devel@lists.libcamera.org> wrote:\n\n> Now that the ancillary links are configured, we can use the CameraLens\n> class and control the VCM through the IPA.\n> For now, force a default value for the lens position, until the AF\n> algorithm is introduced.\n>\n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n> v2: Change the need for lens control to be present\n> ---\n>  src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++-\n>  1 file changed, 41 insertions(+), 1 deletion(-)\n>\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp\n> b/src/ipa/raspberrypi/raspberrypi.cpp\n> index cf4e6cab..ff302e37 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -30,6 +30,7 @@\n>\n>  #include \"libcamera/internal/mapped_framebuffer.h\"\n>\n> +#include \"af_status.h\"\n>  #include \"agc_algorithm.hpp\"\n>  #include \"agc_status.h\"\n>  #include \"alsc_status.h\"\n> @@ -110,6 +111,7 @@ private:\n>         void setMode(const IPACameraSensorInfo &sensorInfo);\n>         bool validateSensorControls();\n>         bool validateIspControls();\n> +       bool validateLensControls();\n>         void queueRequest(const ControlList &controls);\n>         void returnEmbeddedBuffer(unsigned int bufferId);\n>         void prepareISP(const ISPConfig &data);\n> @@ -134,6 +136,7 @@ private:\n>\n>         ControlInfoMap sensorCtrls_;\n>         ControlInfoMap ispCtrls_;\n> +       ControlInfoMap lensCtrls_;\n>         ControlList libcameraMetadata_;\n>\n>         /* Camera sensor params. */\n> @@ -344,7 +347,7 @@ int IPARPi::configure(const IPACameraSensorInfo\n> &sensorInfo,\n>                       const IPAConfig &ipaConfig,\n>                       ControlList *controls)\n>  {\n> -       if (entityControls.size() != 2) {\n> +       if (entityControls.size() < 2) {\n>                 LOG(IPARPI, Error) << \"No ISP or sensor controls found.\";\n>                 return -1;\n>         }\n> @@ -352,6 +355,14 @@ int IPARPi::configure(const IPACameraSensorInfo\n> &sensorInfo,\n>         sensorCtrls_ = entityControls.at(0);\n>         ispCtrls_ = entityControls.at(1);\n>\n> +       /* Lens may not be present, don't make it an hard assumption. */\n> +       auto lensControl = entityControls.find(2);\n> +       if (lensControl != entityControls.end()) {\n> +               lensCtrls_ = lensControl->second;\n> +               if (!validateLensControls())\n> +                       LOG(IPARPI, Error) << \"Lens control validation\n> failed.\";\n> +       }\n> +\n>\n\nI wonder if we should be fetching the lens min/max/default values somewhere\nhere to pass to the algorithm?\n\n\n>         if (!validateSensorControls()) {\n>                 LOG(IPARPI, Error) << \"Sensor control validation failed.\";\n>                 return -1;\n> @@ -362,6 +373,10 @@ int IPARPi::configure(const IPACameraSensorInfo\n> &sensorInfo,\n>                 return -1;\n>         }\n>\n> +       if (!validateLensControls()) {\n> +               LOG(IPARPI, Error) << \"Lens control validation failed.\";\n> +       }\n> +\n>\n\nThis can be removed, the validation is done earlier.\n\nRegards,\nNaush\n\n\n\n>         maxSensorGainCode_ =\n> sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get<int32_t>();\n>\n>         /* Setup a metadata ControlList to output metadata. */\n> @@ -580,6 +595,23 @@ bool IPARPi::validateIspControls()\n>         return true;\n>  }\n>\n> +bool IPARPi::validateLensControls()\n> +{\n> +       static const uint32_t ctrls[] = {\n> +               V4L2_CID_FOCUS_ABSOLUTE,\n> +       };\n> +\n> +       for (auto c : ctrls) {\n> +               if (lensCtrls_.find(c) == lensCtrls_.end()) {\n> +                       LOG(IPARPI, Error) << \"Unable to find lens control\n> \"\n> +                                          << utils::hex(c);\n> +                       return false;\n> +               }\n> +       }\n> +\n> +       return true;\n> +}\n> +\n>  /*\n>   * Converting between enums (used in the libcamera API) and the names that\n>   * we use to identify different modes. Unfortunately, the conversion\n> tables\n> @@ -1068,6 +1100,14 @@ void IPARPi::processStats(unsigned int bufferId)\n>\n>                 setDelayedControls.emit(ctrls);\n>         }\n> +\n> +       struct AfStatus afStatus;\n> +       if (rpiMetadata_.Get(\"af.status\", afStatus) == 0) {\n> +               ControlList lensCtrls(lensCtrls_);\n> +               lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,\n> +                             static_cast<int32_t>(afStatus.focus));\n> +               setLensControls.emit(lensCtrls);\n> +       }\n>  }\n>\n>  void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList\n> &ctrls)\n> --\n> 2.32.0\n>\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 079ACBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Mar 2022 10:34:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4DBF4604DB;\n\tThu, 24 Mar 2022 11:34:43 +0100 (CET)","from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com\n\t[IPv6:2a00:1450:4864:20::22a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FD8C601F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Mar 2022 11:34:41 +0100 (CET)","by mail-lj1-x22a.google.com with SMTP id 17so5551834lji.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Mar 2022 03:34:41 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648118083;\n\tbh=+KSrMwHBWwD/r7jNqNOnt+Jpa/EPua2e+rFSGLL6eO0=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=WLNTR/pAz6+xo3bs5Hz1C/tSTQ2CLXQiok3aWgTtRi+B9laNKWaBbmbTYihfH0Y2X\n\t+AZMz2vUnRNCI6IF1ish/n91dMU7i0rloAdJb5U0bCgH60BX9qInqoIIrvWGLUjDdZ\n\tU3+CfvzAxs/7o/L6pErOE4sCQM4dgpuzN8i4RGexmZyH+We4HQHI4rtZztCv3v8MzI\n\tuXMCC4EKiO6wi1DmumDhEbPS4OSNn+6oEafoNZg1RVmP4zNr4/7J6L5Hx034Zls3/J\n\tmCJqbGK8cwrNSipAF7Je3dO2xiukTrIZWKFMFTAZn0/zS+fw7QoQe38IJkxJjVAMQR\n\tn+lNvbS+W1Ivg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=nY1PXXW7YalejcnhvowQpddDrhixegN2YKLikoR1kcg=;\n\tb=qRNiDwRJ1TX+A0MpJUpr+AzDn0wmv+P/kOkXUIqHUTGZ+hMd6Qe3ffnXu9H1mGCAyV\n\t9j5SQHfClYxcB2d2eKQY36LtnP1ujVBISDTEf6hV0INRo3neSdxKrmz8AN7JKMPIum93\n\tOzzn7CGr5GbY8QgfcMMSpklAAD/Q44NOhvPKjYIykLnlB9uMoLpkjrJCYr1KNJ25dnFj\n\te2BtKBXRMEIJNSmyifLqUt9zbaF2zJzNsp55Ffn0FErSIc/8m9PCHVNIH3D3Menb1rw5\n\ty1fNwuLzPOpeGA/r+N9JuAhI/G5C1pY8BbYo8Sgqj1zdzLFwsWAB2MzizJfqRa4Gl0+U\n\tP3LQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"qRNiDwRJ\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=nY1PXXW7YalejcnhvowQpddDrhixegN2YKLikoR1kcg=;\n\tb=0d94kt+5L/5Cl5CO7xzd8ftrSdK0GjdTIdfR358o+ld4UULvZ11RYruxR2/vzgtk1a\n\txmDUMjBrW6JI7/mBHi/Or8ph9dtyC0705I/lT6qjJYddKOxWtMdQX1/BMwY7/hnbbSez\n\t6W61ETXdZwJInJXAFLGg9rI886/ga/sx35TX9xvX5/za1yezVYv4yyg7RC0hfhlXfvXc\n\tAtJszj1OlWA6hjSR9ule5CKdp/K7hdxjJp6lrICUU4owzc23Ub9Z11w0RFpdQgC7N9KF\n\tOoYmAZAYS+lYIceCfNfb7bBxDuiwmHpo28uE/kPl0uCKFc6MiHR5CwMsa53yQ612XGe5\n\tXEJw==","X-Gm-Message-State":"AOAM531BFXoUX4tVB8RejZFA/wOBO+kHJ/2I58RZiOP/JDCWsaIVCZYQ\n\t2H4c78RmI++434mbrfAyeFFASjoZz3wgUPTXXW6AgQ==","X-Google-Smtp-Source":"ABdhPJxIZD7zYzFy4ac8DIl3kUBRh9J5ODQub+BQk546zpFkxi16w93sr7IWdfg1u5Vl3nYTlRBy3ARPlYcpK1wgO/s=","X-Received":"by 2002:a2e:b8cc:0:b0:249:a2b5:8e16 with SMTP id\n\ts12-20020a2eb8cc000000b00249a2b58e16mr3558633ljp.381.1648118079527;\n\tThu, 24 Mar 2022 03:34:39 -0700 (PDT)","MIME-Version":"1.0","References":"<20220323160145.90606-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20220323160145.90606-5-jeanmichel.hautbois@ideasonboard.com>","In-Reply-To":"<20220323160145.90606-5-jeanmichel.hautbois@ideasonboard.com>","Date":"Thu, 24 Mar 2022 10:34:23 +0000","Message-ID":"<CAEmqJPpv9+eT-=ZvimazjCGc6Gv6w1rKKjg9j_NZ0cpREy5uHQ@mail.gmail.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"000000000000adb97205daf464bd\"","Subject":"Re: [libcamera-devel] [RFC PATCH v2 4/4] ipa: raspberrypi: Control\n\tthe lens position","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]