From patchwork Mon Mar 9 12:33:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 3060 Return-Path: Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7592762923 for ; Mon, 9 Mar 2020 13:35:34 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id z15so10901969wrl.1 for ; Mon, 09 Mar 2020 05:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u1yajr8e8eccRLaXgFLXKas9XBf/N6Equw89ky49Kg8=; b=OKj2/idrQBZH1DiyjOm880IUsNkGy9IGYlpH8gbzcCtEXhhMSmjEamZScuvMLlonVR zICIEJHZrWGsPopJpiW3y0+Q0iZdIa0tAL39FMlUW5IMhbIQ4zZ+1iQbYu5W0ZOh6laK RQbWAm0pGf32VRNJalDYK2ZuF1fdls3vIFZpThU3NBv5/uDR+VhsYWNfHM0W0XmuTslL /5OHYFDJLpZeUotN+sXUbxoxOaHgjOfNYLIgIdIxdXR+IzSgWWO7bSheQk8N005FvHr4 3MrB44KZ8Uel6AbSKJ8hc/80xW6GEC9KSaN1J9+tfY/Efne0ef3QcToVheaM7VxeZP93 A8Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u1yajr8e8eccRLaXgFLXKas9XBf/N6Equw89ky49Kg8=; b=Q/bdAYs+GMGuUOYoycXKIUbB4nbGACtM4Db3ZABzklKotsd2cB6caZEO42FdKIMKbG SWJVJn4Xhok6Y+uk8p/BRWppr3AD1kBI3HZm9ncEdM5ndH9crWUOeG1gwRaEbY3LaS/5 CvnZnMfU6AopOJhNicQIkuy6x2NpnVYxrq9VUF+o9d66z4phIWro/MO/ho+tWlbrijf7 ZVYIrVCtwB3gNRPjmIuxaJEK/7khZPNgZeBh8EsSRMBWJ9z/+enE0vMqLfeMjMsCque2 aXEgZ25C5JPTfGvzg72BjGnH5EBzFpyF1xIFj+VwRJn+FwAjhAz10XCCsE+DhBASRFbi ssFg== X-Gm-Message-State: ANhLgQ03YLuivakGaH0/Vkdm8sWrFBIXQ6GaMQhjaofoN5J+ptKjvnE4 Q0hRdA53h0FX3yKQ+dJRQnv01JcnFSOBUQ== X-Google-Smtp-Source: ADFU+vsWzkZAlBsoTkxADBdpOkoR1xj+p0yzgRMF6FsnwbXKshmjfPhL9RkYG/+cfvCagERg5o00PQ== X-Received: by 2002:a5d:62c9:: with SMTP id o9mr21611183wrv.2.1583757334027; Mon, 09 Mar 2020 05:35:34 -0700 (PDT) Received: from naushir-VirtualBox.pitowers.org (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id z135sm25693827wmc.20.2020.03.09.05.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 05:35:33 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 9 Mar 2020 12:33:15 +0000 Message-Id: <20200309123319.630-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200309123319.630-1-naush@raspberrypi.com> References: <20200309123319.630-1-naush@raspberrypi.com> Subject: [libcamera-devel] [PATCH v2 2/6] libcamera: uvcvideo: Update exposure/gain ctrls set with new units 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-List-Received-Date: Mon, 09 Mar 2020 12:35:34 -0000 The ManualExposure control now uses units of 1 micro-second, and UVC uses units of 100 micro-seconds. Correctly map the values before setting V4L2_CID_EXPOSURE_ABSOLUTE on the V4L2 device. The ManualGain control now uses floats to allow fractional gain values. Since UVC has no explicit gain units, map the default gain value to 1.0 and linearly map to the requested value. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/uvcvideo.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 29afb121..aff86803 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -245,9 +245,22 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request) controls.set(V4L2_CID_SATURATION, value); } else if (id == controls::ManualExposure) { controls.set(V4L2_CID_EXPOSURE_AUTO, static_cast(1)); - controls.set(V4L2_CID_EXPOSURE_ABSOLUTE, value); + /* + * controls::ManualExposure is in units of 1 us, and UVC + * expects V4L2_CID_EXPOSURE_ABSOLUTE in units of 100 us. + * So divide by 100 when setting the control. + */ + controls.set(V4L2_CID_EXPOSURE_ABSOLUTE, value.get() / 100); } else if (id == controls::ManualGain) { - controls.set(V4L2_CID_GAIN, value); + /* + * controls::ManualGain is specified as an absolute float value. + * Map this in a linear way such that 1.0 -> default gain + * of the V4L2_CID_GAIN control. + */ + ControlRange gainInfo = controls.infoMap()->at(V4L2_CID_GAIN); + float requestGain = value.get(); + int32_t gain = requestGain * gainInfo.def().get(); + controls.set(V4L2_CID_GAIN, gain); } }