From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-gpio@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [libgpiod][PATCH 12/16] bindings: cxx: add line_config.set_output_values()
Date: Fri, 13 Jan 2023 22:52:06 +0100 [thread overview]
Message-ID: <20230113215210.616812-13-brgl@bgdev.pl> (raw)
In-Reply-To: <20230113215210.616812-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Extend line_config to expose a new method - set_output_values() - which
wraps the new C function for setting multiple output values at once.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
bindings/cxx/gpiodcxx/line-config.hpp | 7 ++++
bindings/cxx/internal.hpp | 1 +
bindings/cxx/line-config.cpp | 15 +++++++
bindings/cxx/line-settings.cpp | 5 +++
bindings/cxx/tests/tests-line-config.cpp | 51 ++++++++++++++++++++++++
5 files changed, 79 insertions(+)
diff --git a/bindings/cxx/gpiodcxx/line-config.hpp b/bindings/cxx/gpiodcxx/line-config.hpp
index a917913..b76fdff 100644
--- a/bindings/cxx/gpiodcxx/line-config.hpp
+++ b/bindings/cxx/gpiodcxx/line-config.hpp
@@ -76,6 +76,13 @@ public:
*/
line_config& add_line_settings(const line::offsets& offsets, const line_settings& settings);
+ /**
+ * @brief Set output values for a number of lines.
+ * @param values Buffer containing the output values.
+ * @return Reference to self.
+ */
+ line_config& set_output_values(const line::values& values);
+
/**
* @brief Get a mapping of offsets to line settings stored by this
* object.
diff --git a/bindings/cxx/internal.hpp b/bindings/cxx/internal.hpp
index 6aceac1..8322e12 100644
--- a/bindings/cxx/internal.hpp
+++ b/bindings/cxx/internal.hpp
@@ -31,6 +31,7 @@ map_enum_c_to_cxx(c_enum_type value, const ::std::map<c_enum_type, cxx_enum_type
}
void throw_from_errno(const ::std::string& what);
+::gpiod_line_value map_output_value(line::value value);
template<class T, void F(T*)> struct deleter
{
diff --git a/bindings/cxx/line-config.cpp b/bindings/cxx/line-config.cpp
index 3ec99f0..233ba33 100644
--- a/bindings/cxx/line-config.cpp
+++ b/bindings/cxx/line-config.cpp
@@ -100,6 +100,21 @@ GPIOD_CXX_API line_config& line_config::add_line_settings(const line::offsets& o
return *this;
}
+GPIOD_CXX_API line_config& line_config::set_output_values(const line::values& values)
+{
+ ::std::vector<::gpiod_line_value> mapped_values(values.size());
+
+ for (unsigned int i = 0; i < values.size(); i++)
+ mapped_values[i] = map_output_value(values[i]);
+
+ auto ret = ::gpiod_line_config_set_output_values(this->_m_priv->config.get(),
+ mapped_values.data(), mapped_values.size());
+ if (ret)
+ throw_from_errno("unable to set output values");
+
+ return *this;
+}
+
GPIOD_CXX_API ::std::map<line::offset, line_settings> line_config::get_line_settings() const
{
::std::size_t num_offsets = ::gpiod_line_config_get_num_configured_offsets(
diff --git a/bindings/cxx/line-settings.cpp b/bindings/cxx/line-settings.cpp
index 32f21a3..2159062 100644
--- a/bindings/cxx/line-settings.cpp
+++ b/bindings/cxx/line-settings.cpp
@@ -139,6 +139,11 @@ cxx_enum_type get_mapped_value(::gpiod_line_settings* settings,
} /* namespace */
+::gpiod_line_value map_output_value(line::value value)
+{
+ return do_map_value(value, value_mapping);
+}
+
line_settings::impl::impl()
: settings(make_line_settings())
{
diff --git a/bindings/cxx/tests/tests-line-config.cpp b/bindings/cxx/tests/tests-line-config.cpp
index 5fa0f94..5e439a1 100644
--- a/bindings/cxx/tests/tests-line-config.cpp
+++ b/bindings/cxx/tests/tests-line-config.cpp
@@ -4,12 +4,17 @@
#include <catch2/catch.hpp>
#include <gpiod.hpp>
+#include "gpiosim.hpp"
#include "helpers.hpp"
+using ::gpiosim::make_sim;
using namespace ::std::chrono_literals;
using direction = ::gpiod::line::direction;
using drive = ::gpiod::line::drive;
using edge = ::gpiod::line::edge;
+using simval = ::gpiosim::chip::value;
+using value = ::gpiod::line::value;
+using values = ::gpiod::line::values;
namespace {
@@ -72,6 +77,52 @@ TEST_CASE("line_config can be reset", "[line-config]")
REQUIRE(cfg.get_line_settings().size() == 0);
}
+TEST_CASE("output values can be set globally", "[line-config]")
+{
+ const values vals = { value::ACTIVE, value::INACTIVE, value::ACTIVE, value::INACTIVE };
+
+ auto sim = make_sim()
+ .set_num_lines(4)
+ .build();
+
+ ::gpiod::line_config cfg;
+
+ SECTION("request with globally set output values")
+ {
+ cfg
+ .add_line_settings(
+ {0, 1, 2, 3},
+ ::gpiod::line_settings().set_direction(direction::OUTPUT)
+ )
+ .set_output_values(vals);
+
+ auto request = ::gpiod::chip(sim.dev_path())
+ .prepare_request()
+ .set_line_config(cfg)
+ .do_request();
+
+ REQUIRE(sim.get_value(0) == simval::ACTIVE);
+ REQUIRE(sim.get_value(1) == simval::INACTIVE);
+ REQUIRE(sim.get_value(2) == simval::ACTIVE);
+ REQUIRE(sim.get_value(3) == simval::INACTIVE);
+ }
+
+ SECTION("read back global output values")
+ {
+ cfg
+ .add_line_settings(
+ {0, 1, 2, 3},
+ ::gpiod::line_settings()
+ .set_direction(direction::OUTPUT)
+ .set_output_value(value::ACTIVE)
+ )
+ .set_output_values(vals);
+
+ auto settings = cfg.get_line_settings()[1];
+ REQUIRE(settings.output_value() == value::INACTIVE);
+ }
+}
+
TEST_CASE("line_config stream insertion operator works", "[line-config]")
{
::gpiod::line_config cfg;
--
2.37.2
next prev parent reply other threads:[~2023-01-13 21:52 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 21:51 [libgpiod][PATCH 00/16] treewide: continue beating libgpiod v2 into shape for an upcoming release Bartosz Golaszewski
2023-01-13 21:51 ` [libgpiod][PATCH 01/16] README: update for libgpiod v2 Bartosz Golaszewski
2023-01-14 11:14 ` Andy Shevchenko
2023-01-13 21:51 ` [libgpiod][PATCH 02/16] tests: avoid shadowing local variables with common names in macros Bartosz Golaszewski
2023-01-14 11:16 ` Andy Shevchenko
2023-01-13 21:51 ` [libgpiod][PATCH 03/16] build: unify the coding style of source files lists in Makefiles Bartosz Golaszewski
2023-01-13 21:51 ` [libgpiod][PATCH 04/16] treewide: unify gpiod_line_config/request_get_offsets() functions Bartosz Golaszewski
2023-01-16 0:14 ` Kent Gibson
2023-01-16 21:37 ` Bartosz Golaszewski
2023-01-16 23:39 ` Kent Gibson
2023-01-16 5:52 ` Viresh Kumar
2023-01-16 21:39 ` Bartosz Golaszewski
2023-01-17 5:44 ` Viresh Kumar
2023-01-18 20:51 ` Bartosz Golaszewski
2023-01-19 5:15 ` Viresh Kumar
2023-01-23 8:24 ` Viresh Kumar
2023-01-23 8:31 ` Bartosz Golaszewski
2023-01-23 13:58 ` Bartosz Golaszewski
2023-01-24 6:44 ` Viresh Kumar
2023-01-13 21:51 ` [libgpiod][PATCH 05/16] doc: update docs for libgpiod v2 Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 06/16] bindings: cxx: prepend all C symbols with the scope resolution operator Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 07/16] bindings: cxx: allow to copy line_settings Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 08/16] tests: fix the line config reset test case Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 09/16] tests: add a helper for reading back line settings from line config Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 10/16] core: provide gpiod_line_config_set_output_values() Bartosz Golaszewski
2023-01-16 0:15 ` Kent Gibson
2023-01-16 22:23 ` Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 11/16] gpioset: use gpiod_line_config_set_output_values() Bartosz Golaszewski
2023-01-13 21:52 ` Bartosz Golaszewski [this message]
2023-01-14 11:20 ` [libgpiod][PATCH 12/16] bindings: cxx: add line_config.set_output_values() Andy Shevchenko
2023-01-13 21:52 ` [libgpiod][PATCH 13/16] bindings: python: provide line_config.set_output_values() Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 14/16] bindings: rust: make request_config optional in Chip.request_lines() Bartosz Golaszewski
2023-01-16 5:55 ` Viresh Kumar
2023-01-13 21:52 ` [libgpiod][PATCH 15/16] bindings: rust: make mutators return &mut self Bartosz Golaszewski
2023-01-16 6:02 ` Viresh Kumar
2023-01-16 8:42 ` Bartosz Golaszewski
2023-01-16 9:40 ` Viresh Kumar
2023-01-16 12:57 ` Bartosz Golaszewski
2023-01-17 5:19 ` Viresh Kumar
2023-01-13 21:52 ` [libgpiod][PATCH 16/16] bindings: rust: provide line_config.set_output_values() Bartosz Golaszewski
2023-01-16 6:09 ` Viresh Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230113215210.616812-13-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).