From patchwork Fri Jun 9 15:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 691524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 668B4C7EE29 for ; Fri, 9 Jun 2023 15:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239790AbjFIPgh (ORCPT ); Fri, 9 Jun 2023 11:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbjFIPgg (ORCPT ); Fri, 9 Jun 2023 11:36:36 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 260C926B3 for ; Fri, 9 Jun 2023 08:36:36 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-655d1fc8ad8so1639910b3a.1 for ; Fri, 09 Jun 2023 08:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686324995; x=1688916995; 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=z4JwoUjoW61n1BPtqK+L/Xjku5hTO/xlFDRUU5TsXOI=; b=STu0+4dSpLe9Y9L6AxyDXFweOn5LyN4f8WpqM49WYzDjowHn91UH0pG8+F8h+EG26q SVie/4hDQ0YXDBWSOEflDlL2+RCtXBQk827vCizhLme53agwLFsH0ALj8xN5L/WGQ7wk Ti4trWc5l45nLfWHzgjw+cNtqH9P3QrbGMw/cfXx0iT+ZIP6Wt1O6YHbueB2XeYA5TjS 4QfW45Vu8Fjakuw4tspNrsIO/t9XpiiT9f47o7BN+QdhOJ6E7Xg0PidUj6rot8ZNM1Rp +HgGkg2ZIzYg0/bEt/wDGrdv+eVBVvlTE8Wx7vxcCVoy2ANcOeRYDDzsSrwYNTo+YYxN f9uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686324995; x=1688916995; 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=z4JwoUjoW61n1BPtqK+L/Xjku5hTO/xlFDRUU5TsXOI=; b=Pr/w7gESd/ZNzkpPLPF9mA4KW/Sdiz08Uq5Yur1OFZ8tzoen7zu8zet2E7MS94cZqc 3ULNNpjDwS/xU8erG+yLkjEnX745NBiSWYXvXLx74Gn3m00DuoK22eTun0w6YMMphe0U JNoKHBnnCEp8wW9oHUWp3yaojt0gu4lbNT/iAsIK3+Hs2vgE5OQFJh/WQ1/Kxpeeg0dj 8/zfgkbK2SsDK4h6rPAmxX1eH+lCrUefFuLfLCI00cYpMKvuxF+1sFog5zhRFRd1dkwP ubSQAtKULDQUoF0do7eWz0XIrK8IOGkimJ6i8PYVBo3ovW1oGH4OZJXGW58iy9CKqF/Z fLog== X-Gm-Message-State: AC+VfDzNSqlHahFzI9cpj4GWzkzmbs/EUrMRtnoQ7ZYvqL/Q9Pw1WUPT o2McSNzpLYtTineTIp6xSo4DD+E34xM= X-Google-Smtp-Source: ACHHUZ5zo7l2bTpWRHulfjYTcP3r03OGwRm7RN6REcxNiJi/iK6jvnhNcMcsYztpxQCZgM06ohYrMA== X-Received: by 2002:a05:6a20:9191:b0:111:1bd6:270b with SMTP id v17-20020a056a20919100b001111bd6270bmr1452197pzd.7.1686324995223; Fri, 09 Jun 2023 08:36:35 -0700 (PDT) Received: from sol.home.arpa (194-223-178-180.tpgi.com.au. [194.223.178.180]) by smtp.gmail.com with ESMTPSA id z11-20020a6552cb000000b0053051d50a48sm2850288pgp.79.2023.06.09.08.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 08:36:34 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod][PATCH 1/2] bindings: python: examples: fix potential glitch in gpioset.py Date: Fri, 9 Jun 2023 23:36:06 +0800 Message-Id: <20230609153607.133379-2-warthog618@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230609153607.133379-1-warthog618@gmail.com> References: <20230609153607.133379-1-warthog618@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org gpioset.py requests lines without setting their output value, and so sets them all inactive, and subsequently sets them to their requested value. This can result in glitches on lines which were active and are set active. As this is example code, it is also important to demonstrate that the output value can be set by the request itself. Request the lines with the correct output values set in the request itself. Signed-off-by: Kent Gibson --- bindings/python/examples/gpioset.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/python/examples/gpioset.py b/bindings/python/examples/gpioset.py index 372a9a8..b36b376 100755 --- a/bindings/python/examples/gpioset.py +++ b/bindings/python/examples/gpioset.py @@ -21,16 +21,16 @@ if __name__ == "__main__": x, y = arg.split("=") return (x, Value(int(y))) + def settings(v): + return gpiod.LineSettings(direction=Direction.OUTPUT, output_value=v) + lvs = [parse_value(arg) for arg in sys.argv[2:]] - lines = [x[0] for x in lvs] - values = dict(lvs) + config = dict([(l, settings(v)) for (l, v) in lvs]) request = gpiod.request_lines( path, consumer="gpioset.py", - config={tuple(lines): gpiod.LineSettings(direction=Direction.OUTPUT)}, + config=config, ) - vals = request.set_values(values) - input() From patchwork Fri Jun 9 15:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 691007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08A38C7EE29 for ; Fri, 9 Jun 2023 15:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240769AbjFIPgr (ORCPT ); Fri, 9 Jun 2023 11:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbjFIPgq (ORCPT ); Fri, 9 Jun 2023 11:36:46 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B68FD26B3 for ; Fri, 9 Jun 2023 08:36:45 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-656923b7c81so1579157b3a.1 for ; Fri, 09 Jun 2023 08:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686325005; x=1688917005; 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=a4gdY5eAeEAMcZcpE0/XkHyEn+nnmBJFSlt+DJlfOR0=; b=YHuDLq6JVRHWQiMHUyonVTfTRGfNLSfeghnV4H0hwUH+IQevLQiCU7UAXwilPpRKMy ritxCDHJPd4uUkeaIuuv1g++wVSsBPg7JAn4Q0Hxu33p4Qt4KYyPnlbmkHtR5v/LPIJQ RyaFTxWrs5iWKcQ5r0G6es9V5vOF5wkxzGHpc8h4fUlYqRia4lOkl6LYi9JADcIZxtWI yWYV07XcZzpsTBJz23HfBKyRthIoVikfbYWReia0bUP4FMPwUje+/KXUxHEVrBKpPJbR 73H7hFogwNsd7sZMCuyupqS1xldssiub62sJipgNuEerAKhPAAkTQqL+9iLp7x/7rvvZ wRaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686325005; x=1688917005; 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=a4gdY5eAeEAMcZcpE0/XkHyEn+nnmBJFSlt+DJlfOR0=; b=K7d2pMPLCX2mZej3AoIJza5jVXX5McT5K/cOKowwSLAn3QjYFPRZAS0al8n+zFwZKU SLIl15ju5JF9Wckute8g+6y8NuYqFrDbfSl1vMPW//KGfPd2P8aZJZI1EHRxlr/I/gM8 zKtSgotPBcirz1Ex1czoBnM8OqFsTuqD91WlBnGVJL0H3BzWuLISUEA8YcXko1nissB0 n0n9O/Kum2++c4MLzKRcHIL7MJ8FFB13w+6u/1vNq7kPGfizn6O2xsqv9eYwJZ3mu19r Dh+uOXrOSK7EN/I2R10GXdgtY0qWwGWJdNu+QeBdXtCIrfEw+kZecBQVR8mW8Fym5aag AR5g== X-Gm-Message-State: AC+VfDxzHC6dG/L3yZssNc39ojH9q+8XiwDedgYsjP4R5TtB4BV0PsIa OCNMmbWK6CeAvKgPvhimzAzhS8QH1ps= X-Google-Smtp-Source: ACHHUZ58ibqdG3kOfG2U8yiN2E6/8K9ZCAjYru8ImvjQOwXqCoLLM1xPerqvBBgYyx0vtIbz4e/xmQ== X-Received: by 2002:a05:6a20:8f0b:b0:117:4cb3:157c with SMTP id b11-20020a056a208f0b00b001174cb3157cmr1483917pzk.21.1686325005014; Fri, 09 Jun 2023 08:36:45 -0700 (PDT) Received: from sol.home.arpa (194-223-178-180.tpgi.com.au. [194.223.178.180]) by smtp.gmail.com with ESMTPSA id z11-20020a6552cb000000b0053051d50a48sm2850288pgp.79.2023.06.09.08.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 08:36:44 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod][PATCH 2/2] bindings: cxx: examples: fix potential glitch in gpiosetcxx Date: Fri, 9 Jun 2023 23:36:07 +0800 Message-Id: <20230609153607.133379-3-warthog618@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230609153607.133379-1-warthog618@gmail.com> References: <20230609153607.133379-1-warthog618@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org gpiosetcxx requests lines without setting their output value, and so sets them all inactive, and subsequently sets them to their requested value. This can result in glitches on lines which were active and are set active. As this is example code, it is also important to demonstrate that the output value can be set by the request itself. Request the lines with the correct output values set in the request itself. Signed-off-by: Kent Gibson --- bindings/cxx/examples/gpiosetcxx.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/bindings/cxx/examples/gpiosetcxx.cpp b/bindings/cxx/examples/gpiosetcxx.cpp index dde5379..ae35038 100644 --- a/bindings/cxx/examples/gpiosetcxx.cpp +++ b/bindings/cxx/examples/gpiosetcxx.cpp @@ -16,8 +16,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - ::gpiod::line::offsets offsets; - ::gpiod::line::values values; + auto builder = ::gpiod::chip(argv[1]).prepare_request(); + builder.set_consumer("gpiosetcxx"); for (int i = 2; i < argc; i++) { ::std::string arg(argv[i]); @@ -31,22 +31,17 @@ int main(int argc, char **argv) throw ::std::invalid_argument("invalid offset=value mapping: " + ::std::string(argv[i])); - offsets.push_back(::std::stoul(offset)); - values.push_back(::std::stoul(value) ? ::gpiod::line::value::ACTIVE : - ::gpiod::line::value::INACTIVE); - } - - auto request = ::gpiod::chip(argv[1]) - .prepare_request() - .set_consumer("gpiosetcxx") - .add_line_settings( - offsets, + ::gpiod::line::value v = ::std::stoul(value) ? + ::gpiod::line::value::ACTIVE : + ::gpiod::line::value::INACTIVE; + builder.add_line_settings( + ::std::stoul(offset), ::gpiod::line_settings() .set_direction(::gpiod::line::direction::OUTPUT) - ) - .do_request(); + .set_output_value(v)); + } - request.set_values(values); + auto request = builder.do_request(); ::std::cin.get();