From patchwork Fri Apr 3 14:53:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 3372 Return-Path: Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0000760104 for ; Fri, 3 Apr 2020 16:53:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="jPF57lsi"; dkim-atps=neutral Received: by mail-wr1-x443.google.com with SMTP id t7so8829487wrw.12 for ; Fri, 03 Apr 2020 07:53:29 -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=fVXwuWn8rco3gELfJEAjuRoUPX3Va//Kq1kEXfngX2M=; b=jPF57lsiAeKM8eQWgtbq1kUqkC/xeIyYHlXenfOxpp+QAxBTFxghqXKEKN0haoYrdt 8yTrCN/p+0Gn4HfywgBdpT9q8zNxl+5ohpN1Jb7iMOd+htK0ZCLhytWfD64QBvCHYCaZ 5zDkDBZSmstv2oXQK7mGmJRDR9aVjIiDV0GVISya6cSSbleOjQh96fTcUigObc2U7Axv nipFnw3IxA/6FKRCdsl6R4vWlpGhzK58Py4bfI9rMy9yQU9mUMbfr4dqR+9tvEbSxQlt RgZUs9Q+dLW98RUGgRFpGDcJGxiwIl6zRvMeUs6IVpKienlfUKTJfTq+zj0emwf5w3vA 5b3Q== 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=fVXwuWn8rco3gELfJEAjuRoUPX3Va//Kq1kEXfngX2M=; b=fDtuXpDwKnpTnyG9foI06yfdUECZXLWzeJ+KWqc1e5OHHEuv9zRvuSQeoT8S8yyRG3 prqBnafLFeatw4OxHWU1lVscqtz8iNg8t2L+ojgmVz1XZajnMbjKIYXTOaVPm+WXDMLb t5NsALjlokWAQ4loCG8omQE/jJ92F6maJ9/3Fyic+IxrHHgmlOcW3Map0/BnuomGkJbh zqONu8TLYoPTYEFeWXd0iglLsDWjbXoAv0GrdEw2gCpj/shxJ/luYngS8rvU4XOk8sp7 LABFLh+o7gFRL4yRndII594G3jBf+bc/HLeg4ZdG+lZt1kIKj6WBkjxuvous9exF2aQ7 YKhQ== X-Gm-Message-State: AGi0PubWwKI31DqZITi+eWNXRA/E437fJRQwlQD0QXzjclAki3U7jzUt G+ULmc7HMfN6BrnOCJp45oLnBTEFwsNlPg== X-Google-Smtp-Source: APiQypLkh9yXfP/V76KqOl02uds6pJJY9YdsvZ4ZcfO619lMqEn05LWpgye5ZrBN2wGEI9xd90FP7w== X-Received: by 2002:a5d:4ac8:: with SMTP id y8mr8946516wrs.233.1585925609530; Fri, 03 Apr 2020 07:53:29 -0700 (PDT) Received: from naushir-VirtualBox.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id u5sm13559469wrp.81.2020.04.03.07.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 07:53:28 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Apr 2020 15:53:02 +0100 Message-Id: <20200403145305.10288-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200403145305.10288-1-naush@raspberrypi.com> References: <20200403145305.10288-1-naush@raspberrypi.com> Subject: [libcamera-devel] [PATCH v3 2/5] 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: Fri, 03 Apr 2020 14:53:30 -0000 The ExposureTime 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 AnalogueGain 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 --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index d7df95e4..9d589f69 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -253,9 +253,22 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request) controls.set(V4L2_CID_SATURATION, value); } else if (id == controls::ExposureTime) { controls.set(V4L2_CID_EXPOSURE_AUTO, static_cast(1)); - controls.set(V4L2_CID_EXPOSURE_ABSOLUTE, value); + /* + * controls::ExposureTime is in units of 1 us, and UVC + * expects V4L2_CID_EXPOSURE_ABSOLUTE in units of 100 us. + */ + controls.set(V4L2_CID_EXPOSURE_ABSOLUTE, + value.get() / 100); } else if (id == controls::AnalogueGain) { - controls.set(V4L2_CID_GAIN, value); + /* + * controls::AnalogueGain is specified as an absolute + * multiplier for all RGB samples. Map this multiplier + * in a linear way such that 1.0 -> default gain + * of the V4L2_CID_GAIN control on the uvcvideo device. + */ + const ControlInfo &gainInfo = controls.infoMap()->at(V4L2_CID_GAIN); + int32_t gain = value.get() * gainInfo.def().get(); + controls.set(V4L2_CID_GAIN, gain); } }