From patchwork Thu Nov 2 18:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 19190 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 D0DCFBDCBD for ; Thu, 2 Nov 2023 18:09:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1637361DC8; Thu, 2 Nov 2023 19:09:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698948562; bh=pzy5bsBdearxhieNhlomrSnF8RdembIdhV56ewSSqZQ=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=a/gtc3Nfl4MMXCGbMhzknjWbnf4ybqVx5CUQ7P0CJ/wfuS7tAbLQZk9OrK3WMwFZG dWACb48NFiE+cGo9AwZaoqJQ0GUoaL11mZJLqXvROgDurLfQzS4e04Q6BZkda5BrIc 4O4E9yLy0TmvCXx5k472mLZYbmx2HZScMC4OJC1AidrFG+JxpRRqzYUYeeUfqgmEK0 HonTAtuv8NES+V12m8f3rT4rUt7su98dfPiR8L1oEed65KGWKF2NTod4KPMWQzuxlI ZeO6+n1s3DYtzgjBiA2npwjFesdfkAdVWvjeFCz1Jqc4szvsvZ0y+5cjbQLsC0Pc0x hfS+Iuj1thMyQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB27E61DC6 for ; Thu, 2 Nov 2023 19:09:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="vaMLyARd"; dkim-atps=neutral Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 43F14C58; Thu, 2 Nov 2023 19:09:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698948542; bh=pzy5bsBdearxhieNhlomrSnF8RdembIdhV56ewSSqZQ=; h=From:To:Cc:Subject:Date:From; b=vaMLyARdw1REdbLTZ/FhCvEy2ZMLxgmEAZSSZv0dQPwBfs3xtQ1t2Ho3Ynqz5nkm7 gdUB05DlVkQdbVmsECT5ZAA0aFfXKqt+v5KHhPgX6E6JDXOGEyLbyBdHG18YMfP/Gj +xbCJys2FxWo2E/I/Vnf8uTdL+Zv0o0f1GysNvOc= To: libcamera devel Date: Thu, 2 Nov 2023 18:09:16 +0000 Message-Id: <20231102180916.3575006-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: ipa: Add IMX335 support 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: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide support for the Sony IMX335 in both libipa and RaspberryPi IPA modules. Signed-off-by: Kieran Bingham --- src/ipa/libipa/camera_sensor_helper.cpp | 23 ++++++ src/ipa/rpi/cam_helper/cam_helper_imx335.cpp | 74 ++++++++++++++++++++ src/ipa/rpi/cam_helper/meson.build | 1 + src/libcamera/camera_sensor_properties.cpp | 4 ++ 4 files changed, 102 insertions(+) create mode 100644 src/ipa/rpi/cam_helper/cam_helper_imx335.cpp diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index f0ecc3830115..ddab5af6eac2 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -444,6 +444,29 @@ class CameraSensorHelperImx327 : public CameraSensorHelperImx290 }; REGISTER_CAMERA_SENSOR_HELPER("imx327", CameraSensorHelperImx327) +class CameraSensorHelperImx335 : public CameraSensorHelper +{ +public: + uint32_t gainCode(double gain) const override; + double gain(uint32_t gainCode) const override; +private: + static constexpr uint32_t maxGainCode_ = 240; +}; + +uint32_t CameraSensorHelperImx335::gainCode(double gain) const +{ + uint32_t code = 10 * std::log10(gain) * 10 / 3; + + return std::min(code, maxGainCode_); +} + +double CameraSensorHelperImx335::gain(uint32_t gainCode) const +{ + return std::pow(10.0, gainCode / (10 * 10 / 3)); +} + +REGISTER_CAMERA_SENSOR_HELPER("imx335", CameraSensorHelperImx335) + class CameraSensorHelperImx477 : public CameraSensorHelper { public: diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx335.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx335.cpp new file mode 100644 index 000000000000..659c69d6b6c7 --- /dev/null +++ b/src/ipa/rpi/cam_helper/cam_helper_imx335.cpp @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2023, Ideas on Board Oy. + * + * cam_helper_imx335.cpp - camera information for the Sony IMX335 sensor + */ + +#include + +#include "cam_helper.h" +#include "math.h" + +using namespace RPiController; + +class CamHelperImx335 : public CamHelper +{ +public: + CamHelperImx335(); + uint32_t gainCode(double gain) const override; + double gain(uint32_t gainCode) const override; + void getDelays(int &exposureDelay, int &gainDelay, + int &vblankDelay, int &hblankDelay) const override; + unsigned int hideFramesModeSwitch() const override; + +private: + /* + * Smallest difference between the frame length and integration time, + * in units of lines. + */ + static constexpr int frameIntegrationDiff = 4; + static constexpr uint32_t maxGainCode = 240; +}; + +/* + * IMX335 Metadata isn't yet supported. + */ + +CamHelperImx335::CamHelperImx335() + : CamHelper({}, frameIntegrationDiff) +{ +} + +uint32_t CamHelperImx335::gainCode(double gain) const +{ + uint32_t code = 10 * std::log10(gain) * 10 / 3; + return std::min(code, maxGainCode); +} + +double CamHelperImx335::gain(uint32_t gainCode) const +{ + return std::pow(10.0, gainCode / (10 * 10 / 3)); +} + +void CamHelperImx335::getDelays(int &exposureDelay, int &gainDelay, + int &vblankDelay, int &hblankDelay) const +{ + exposureDelay = 2; + gainDelay = 2; + vblankDelay = 2; + hblankDelay = 2; +} + +unsigned int CamHelperImx335::hideFramesModeSwitch() const +{ + /* One bad frame can be expected after a mode switch. */ + return 1; +} + +static CamHelper *create() +{ + return new CamHelperImx335(); +} + +static RegisterCamHelper reg("imx335", &create); diff --git a/src/ipa/rpi/cam_helper/meson.build b/src/ipa/rpi/cam_helper/meson.build index bdf2db8eb742..17c25cb0e4a6 100644 --- a/src/ipa/rpi/cam_helper/meson.build +++ b/src/ipa/rpi/cam_helper/meson.build @@ -6,6 +6,7 @@ rpi_ipa_cam_helper_sources = files([ 'cam_helper_imx219.cpp', 'cam_helper_imx290.cpp', 'cam_helper_imx296.cpp', + 'cam_helper_imx335.cpp', 'cam_helper_imx477.cpp', 'cam_helper_imx519.cpp', 'cam_helper_imx708.cpp', diff --git a/src/libcamera/camera_sensor_properties.cpp b/src/libcamera/camera_sensor_properties.cpp index 27d6799a2686..dc76051fa349 100644 --- a/src/libcamera/camera_sensor_properties.cpp +++ b/src/libcamera/camera_sensor_properties.cpp @@ -111,6 +111,10 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen .unitCellSize = { 2900, 2900 }, .testPatternModes = {}, } }, + { "imx335", { + .unitCellSize = { 2000, 2000 }, + .testPatternModes = {}, + } }, { "imx477", { .unitCellSize = { 1550, 1550 }, .testPatternModes = {},