From patchwork Wed Dec 4 10:52:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Scott X-Patchwork-Id: 22159 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 483E3BDB1C for ; Wed, 4 Dec 2024 10:52:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 24084660AD; Wed, 4 Dec 2024 11:52:53 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XJqabQTT"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EBB84618B5 for ; Wed, 4 Dec 2024 11:52:50 +0100 (CET) Received: from isaac-ThinkPad-T16-Gen-2.lan (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C5E9E6D6; Wed, 4 Dec 2024 11:52:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1733309542; bh=M2XHIdVNQacwasaCWQen2lIwg2f00tx+UGqMxTbTts4=; h=From:To:Cc:Subject:Date:From; b=XJqabQTTNhi2Smvv1m9LegCQ9OYScLS1yRvFNKGqBG+dhXbrI7Bg+7YLFIC9JWAIZ C9jQk9FmKAJkiLagAFYgT4GM+mNYPxsUX+jpPYhKgFxDzC5zBYOfmmK276TGNRHDZ4 v9gjiBR1rvKxRoMthDtZJf+FReiwOiaPc06Yua8I= From: Isaac Scott To: libcamera devel Cc: Isaac Scott Subject: [PATCH v1] libcamera: rpi: Add support for IMX258 Date: Wed, 4 Dec 2024 10:52:23 +0000 Message-ID: <20241204105223.45807-1-isaac.scott@ideasonboard.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add support for the IMX258 camera. This patch adds a minimal cam_helper implementation that allows the IMX258 sensor to be listed by cam, and subsequently be used remotely in tools such as Camshark. Based on the implementation of the IMX290's camera helper, adjusted to use the equation listed in the IMX258 datasheet used to calculate analogue gain. Signed-off-by: Isaac Scott --- src/ipa/rpi/cam_helper/cam_helper_imx258.cpp | 60 ++++++++++++++++++++ src/ipa/rpi/cam_helper/meson.build | 1 + 2 files changed, 61 insertions(+) create mode 100644 src/ipa/rpi/cam_helper/cam_helper_imx258.cpp diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx258.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx258.cpp new file mode 100644 index 00000000..12c0332a --- /dev/null +++ b/src/ipa/rpi/cam_helper/cam_helper_imx258.cpp @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2024 Ideas On Board Oy + * + * camera helper for imx258 sensor + * based on Raspberry Pi's imx290 helper + */ + +#include + +#include "cam_helper.h" + +using namespace RPiController; + +class CamHelperImx258 : public CamHelper +{ +public: + CamHelperImx258(); + 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; +private: + /* + * Smallest difference between the frame length and integration time, + * in units of lines. + */ + static constexpr int frameIntegrationDiff = 2; +}; + +CamHelperImx258::CamHelperImx258() + : CamHelper({}, frameIntegrationDiff) +{ +} + +uint32_t CamHelperImx258::gainCode(double gain) const +{ + return static_cast(512 - 512 / gain); +} + +double CamHelperImx258::gain(uint32_t gainCode) const +{ + return 512.0 / (512.0 - gainCode); +} + +void CamHelperImx258::getDelays(int &exposureDelay, int &gainDelay, + int &vblankDelay, int &hblankDelay) const +{ + exposureDelay = 2; + gainDelay = 2; + vblankDelay = 2; + hblankDelay = 2; +} + +static CamHelper *create() +{ + return new CamHelperImx258(); +} + +static RegisterCamHelper reg("imx258", &create); diff --git a/src/ipa/rpi/cam_helper/meson.build b/src/ipa/rpi/cam_helper/meson.build index 03e88fe0..a8245e42 100644 --- a/src/ipa/rpi/cam_helper/meson.build +++ b/src/ipa/rpi/cam_helper/meson.build @@ -4,6 +4,7 @@ rpi_ipa_cam_helper_sources = files([ 'cam_helper.cpp', 'cam_helper_ov5647.cpp', 'cam_helper_imx219.cpp', + 'cam_helper_imx258.cpp', 'cam_helper_imx283.cpp', 'cam_helper_imx290.cpp', 'cam_helper_imx296.cpp',