From patchwork Thu Jan 26 13:45:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18199 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 672D3BDC71 for ; Thu, 26 Jan 2023 13:46:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 96104625EB; Thu, 26 Jan 2023 14:46:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1674740768; bh=uC9Wltj2m2gSKP/fun7dbaUcLSWVuEKVtB40k/yyRfA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QVhPzCZMmaGVpf5Dff7+j6DqJwxLsaIfgbqzZW3nz7um2vJMLwLbIPqwb+Pph/CIj Ls9YuYtc4jKClreeXHSk6U6wAmm1Op6nBzyS7u9tQb0CvZ+qrWIIOAofNdXQfL8F8D 2wh6dOhCwAR4kLlX3HTGBpJ4Pcy/Tdj3dy3sW6uK5ZVgNAhJf8Hsf7s96hiDUQgqH6 PBKWkgD12lDTyfEnZ8C9gALLBxTgBC/g7SEvdZUg3a8Wrc/fhqP5WDPzH0s2WX+rW2 gLLddp+TPvbXAz7HQTMR8x8p+/2ElYd2WeVYrLeR9c4/RSms+AvVWy2o5aoFn/bI4J ZI4wFSAu9qF2Q== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B79D461EFB for ; Thu, 26 Jan 2023 14:46:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="kvXQgABF"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id m14so1362446wrg.13 for ; Thu, 26 Jan 2023 05:46:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T0St15xM0OQiiLGtya1glBR/W5nvGUy3/1PW9Rvrxyk=; b=kvXQgABF03g1ka1Re+FW+WDBHyVgz9AAqLR9W9QnKRNlnEj6c8UbaiI2tFIJrx4IoB T6ljccde4N2OXrzDxNBldYVmeUBZOieJTGDAMj5DB6AbnkA6fhSB/JRn2RDqvGHqEEDu X0SGSZ9geAOXhHC+tgGNeTpCLvOnKjYj4jFphqpE02YMhm866PHy+zC/aT9O39UvlA4T 7xM0T9VVyZEmhujJtUdDMVcY/W0CwTq/MF0qr/7kwImTw0cYRUQPUfqCDFjV0x9TUuyT JAKfo+cHIvY/3tx3toLFNezkW6LOaaDTPME/1Au21VP2+mGpcgGY6MDAjVg3WTxV1Ond 09MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T0St15xM0OQiiLGtya1glBR/W5nvGUy3/1PW9Rvrxyk=; b=7ewfJy4gfoFcJUiGEq7gb4ejTidQj+YMvuGLaLqQbXvo9b9VBh+KO54/OKeMrGk75W yF1flSHxpjRZDfC472/p3qU+kR1T+L2upp5Ng8nF95I1p3KZxIfvetpaPMqI2q16c5/C 9axDTpNdxxu7LYIdhditJNHFEpVhnkwNgOA6lLDySMzK/BfFOBK3HmAF6NeILgq2MeVr tICfjhE9Hk4WlnssBYA0QM7GjcwQhv4P9AzweXNruNafupGIHswQHFaXIgqMd5pgdTu+ M2iV5YIsjQgHQtgCmkl2l55b+S0VhOzso94tRSZBhSnbmBnUu/WiKceJGtxhZjiyyBID KuRQ== X-Gm-Message-State: AO0yUKXYEEA0ZI/Ct7jE6LWVA4MCs6Q//rJ5UNp8Qc1raKkB0lZsSzaw nJN+ZdGY2xcLztlJj1QHArNq4IL8tnOVVLhY X-Google-Smtp-Source: AK7set9py7eNzR4hklTGPP1A2bLEOQbKfG34afTnz8wW3OVbvNiEOHfskMMgFaCJ2LefvmvKqnuhXQ== X-Received: by 2002:a5d:4c41:0:b0:2bf:b3c5:cf54 with SMTP id n1-20020a5d4c41000000b002bfb3c5cf54mr7218345wrt.60.1674740765165; Thu, 26 Jan 2023 05:46:05 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id m2-20020a056000180200b002bfb5618ee7sm1370567wrh.91.2023.01.26.05.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 05:46:04 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Jan 2023 13:45:59 +0000 Message-Id: <20230126134559.3323-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230126134559.3323-1-david.plowman@raspberrypi.com> References: <20230126134559.3323-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] ipa: raspberrypi: Handle AEC/AGC flicker controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" We handle the flicker modes by passing the correct period to the AEC/AGC algorithm which already contains the necessary code. The "Auto" mode is currently unsupported. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- src/ipa/raspberrypi/raspberrypi.cpp | 80 +++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 5f7397e2..477d72ba 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -86,6 +86,8 @@ static const ControlInfoMap::Map ipaControls{ { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) }, { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) }, { &controls::ExposureValue, ControlInfo(-8.0f, 8.0f, 0.0f) }, + { &controls::AeFlickerMode, ControlInfo(controls::AeFlickerModeValues) }, + { &controls::AeFlickerPeriod, ControlInfo(0, 1000000) }, { &controls::AwbEnable, ControlInfo(false, true) }, { &controls::ColourGains, ControlInfo(0.0f, 32.0f) }, { &controls::AwbMode, ControlInfo(controls::AwbModeValues) }, @@ -218,6 +220,12 @@ private: /* Maximum gain code for the sensor. */ uint32_t maxSensorGainCode_; + + /* The current state of flicker avoidance. */ + struct FlickerState { + int32_t mode; + Duration period; + } flickerState_; }; int IPARPi::init(const IPASettings &settings, bool lensPresent, IPAInitResult *result) @@ -946,6 +954,78 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::AE_FLICKER_MODE: { + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.getAlgorithm("agc")); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_FLICKER_MODE - no AGC algorithm"; + break; + } + + int32_t mode = ctrl.second.get(); + bool modeValid = true; + + switch (mode) { + case controls::FlickerOff: { + agc->setFlickerPeriod(0us); + + break; + } + + case controls::FlickerFreq50Hz: { + agc->setFlickerPeriod(10000 * 1.0us); + + break; + } + + case controls::FlickerFreq60Hz: { + agc->setFlickerPeriod(8333.333 * 1.0us); + + break; + } + + case controls::FlickerCustom: { + agc->setFlickerPeriod(flickerState_.period); + + break; + } + + default: + LOG(IPARPI, Error) << "Flicker mode " << mode << " is not supported"; + modeValid = false; + + break; + } + + if (modeValid) + flickerState_.mode = mode; + + break; + } + + case controls::AE_FLICKER_PERIOD: { + RPiController::AgcAlgorithm *agc = dynamic_cast( + controller_.getAlgorithm("agc")); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set AE_FLICKER_PERIOD - no AGC algorithm"; + break; + } + + uint32_t period = ctrl.second.get(); + flickerState_.period = period * 1.0us; + + /* + * We note that it makes no difference if the mode gets set to "custom" + * first, and the period updated after, or vice versa. + */ + if (flickerState_.mode == controls::FlickerCustom) + agc->setFlickerPeriod(flickerState_.period); + + break; + } + case controls::AWB_ENABLE: { RPiController::AwbAlgorithm *awb = dynamic_cast( controller_.getAlgorithm("awb"));