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>,
Jack Winch <sunt.un.morcov@gmail.com>,
Helmut Grohne <helmut.grohne@intenta.de>,
Ben Hutchings <ben.hutchings@essensium.com>
Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [libgpiod][PATCH v2 2/3] API: extend the line request functionality
Date: Thu, 15 Jul 2021 22:10:00 +0200 [thread overview]
Message-ID: <20210715201001.23726-3-brgl@bgdev.pl> (raw)
In-Reply-To: <20210715201001.23726-1-brgl@bgdev.pl>
This adds new public functions for interacting with line request objects.
First we implement getters for the number of lines in a request and for
the array of offsets of requested lines. Next we rename the existing
gpiod_line_request_get/set_values() functions to
gpiod_line_request_get/set_values_subset() and add new functions that are
named gpiod_line_request_get/set_values() but allow to get/set the values
of all requested lines.
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
include/gpiod.h | 54 ++++++++++++++++++++++++++++++++++++++++------
lib/line-request.c | 50 +++++++++++++++++++++++++++++++++---------
tools/gpioget.c | 3 +--
3 files changed, 89 insertions(+), 18 deletions(-)
diff --git a/include/gpiod.h b/include/gpiod.h
index 8fc20ed..51e93be 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -814,6 +814,22 @@ gpiod_request_config_set_event_buffer_size(struct gpiod_request_config *config,
*/
void gpiod_line_request_release(struct gpiod_line_request *request);
+/**
+ * @brief Get the number of lines in this request.
+ * @param request Line request object.
+ * @return Number of requested lines.
+ */
+unsigned int gpiod_line_request_get_num_lines(struct gpiod_line_request *request);
+
+/**
+ * @brief Get the hardware offsets of lines in this request.
+ * @param request Line request object.
+ * @param offsets Array to store offsets in. Must hold at least the number of
+ * lines returned by ::gpiod_line_request_get_num_lines.
+ */
+void gpiod_line_request_get_offsets(struct gpiod_line_request *request,
+ unsigned int *offsets);
+
/**
* @brief Read the value of a single line associated with this request.
* @param request Line request object.
@@ -824,7 +840,7 @@ int gpiod_line_request_get_value(struct gpiod_line_request *request,
unsigned int offset);
/**
- * @brief Read values of lines associated with this request.
+ * @brief Read values of a subset of lines associated with this request.
* @param request GPIO line request.
* @param num_lines Number of lines for which to read values.
* @param offsets Array of offsets corresponding with the lines associated with
@@ -832,9 +848,23 @@ int gpiod_line_request_get_value(struct gpiod_line_request *request,
* @param values Array in which the values will be stored.
* @return 0 on success, -1 on failure.
*/
+int gpiod_line_request_get_values_subset(struct gpiod_line_request *request,
+ unsigned num_lines,
+ const unsigned int *offsets,
+ int *values);
+
+/**
+ * @brief Read values of all lines associated with this request.
+ * @param request GPIO line request.
+ * @param values Array in which the values will be stored. Must hold at least
+ * the number of lines returned by
+ * ::gpiod_line_request_get_num_lines. The index of each value
+ * will be associated with the offset at the same index in the
+ * offset array returned by ::gpiod_line_request_get_offsets.
+ * @return 0 on success, -1 on failure.
+ */
int gpiod_line_request_get_values(struct gpiod_line_request *request,
- unsigned num_lines,
- const unsigned int *offsets, int *values);
+ int *values);
/**
* @brief Set the value of a single line associated with this request.
@@ -846,7 +876,7 @@ int gpiod_line_request_set_value(struct gpiod_line_request *request,
unsigned int offset, int value);
/**
- * @brief Set values of lines associated with this line request.
+ * @brief Set values of a subset of lines associated with this line request.
* @param request GPIO line request.
* @param num_lines Number of lines for which to set values.
* @param offsets Array of offsets corresponding with the lines associated with
@@ -855,9 +885,21 @@ int gpiod_line_request_set_value(struct gpiod_line_request *request,
* correspond with the offsets in the previous argument.
* @return 0 on success, -1 on failure.
*/
+int gpiod_line_request_set_values_subset(struct gpiod_line_request *request,
+ unsigned int num_lines,
+ const unsigned int *offsets,
+ const int *values);
+
+/**
+ * @brief Set values of all lines associated with this request.
+ * @param request GPIO line request.
+ * @param values Array containing the values to set. Must hold at least the
+ * number of lines returned by ::gpiod_line_request_get_num_lines.
+ * The index of each value be associated with the offset at the
+ * same index in the offset array returned by
+ * ::gpiod_line_request_get_offsets.
+ */
int gpiod_line_request_set_values(struct gpiod_line_request *request,
- unsigned int num_lines,
- const unsigned int *offsets,
const int *values);
/**
diff --git a/lib/line-request.c b/lib/line-request.c
index 6cbb08a..8008b89 100644
--- a/lib/line-request.c
+++ b/lib/line-request.c
@@ -45,13 +45,27 @@ GPIOD_API void gpiod_line_request_release(struct gpiod_line_request *request)
free(request);
}
+GPIOD_API unsigned int
+gpiod_line_request_get_num_lines(struct gpiod_line_request *request)
+{
+ return request->num_lines;
+}
+
+GPIOD_API void
+gpiod_line_request_get_offsets(struct gpiod_line_request *request,
+ unsigned int *offsets)
+{
+ memcpy(offsets, request->offsets,
+ sizeof(*offsets) * request->num_lines);
+}
+
GPIOD_API int gpiod_line_request_get_value(struct gpiod_line_request *request,
unsigned int offset)
{
unsigned int ret;
int val;
- ret = gpiod_line_request_get_values(request, 1, &offset, &val);
+ ret = gpiod_line_request_get_values_subset(request, 1, &offset, &val);
if (ret)
return -1;
@@ -71,10 +85,10 @@ static int offset_to_bit(struct gpiod_line_request *request,
return -1;
}
-GPIOD_API int gpiod_line_request_get_values(struct gpiod_line_request *request,
- unsigned num_lines,
- const unsigned int *offsets,
- int *values)
+GPIOD_API int
+gpiod_line_request_get_values_subset(struct gpiod_line_request *request,
+ unsigned num_lines,
+ const unsigned int *offsets, int *values)
{
struct gpio_v2_line_values buf;
uint64_t mask = 0, bits = 0;
@@ -119,16 +133,25 @@ GPIOD_API int gpiod_line_request_get_values(struct gpiod_line_request *request,
return 0;
}
+GPIOD_API int gpiod_line_request_get_values(struct gpiod_line_request *request,
+ int *values)
+{
+ return gpiod_line_request_get_values_subset(request, request->num_lines,
+ request->offsets, values);
+}
+
GPIOD_API int gpiod_line_request_set_value(struct gpiod_line_request *request,
unsigned int offset, int value)
{
- return gpiod_line_request_set_values(request, 1, &offset, &value);
+ return gpiod_line_request_set_values_subset(request, 1,
+ &offset, &value);
}
-GPIOD_API int gpiod_line_request_set_values(struct gpiod_line_request *request,
- unsigned int num_lines,
- const unsigned int *offsets,
- const int *values)
+GPIOD_API int
+gpiod_line_request_set_values_subset(struct gpiod_line_request *request,
+ unsigned int num_lines,
+ const unsigned int *offsets,
+ const int *values)
{
struct gpio_v2_line_values buf;
uint64_t mask = 0, bits = 0;
@@ -153,6 +176,13 @@ GPIOD_API int gpiod_line_request_set_values(struct gpiod_line_request *request,
return ioctl(request->fd, GPIO_V2_LINE_SET_VALUES_IOCTL, &buf);
}
+GPIOD_API int gpiod_line_request_set_values(struct gpiod_line_request *request,
+ const int *values)
+{
+ return gpiod_line_request_set_values_subset(request, request->num_lines,
+ request->offsets, values);
+}
+
GPIOD_API int
gpiod_line_request_reconfigure_lines(struct gpiod_line_request *request,
struct gpiod_line_config *config)
diff --git a/tools/gpioget.c b/tools/gpioget.c
index e0c630d..afa2ccb 100644
--- a/tools/gpioget.c
+++ b/tools/gpioget.c
@@ -129,8 +129,7 @@ int main(int argc, char **argv)
if (!request)
die_perror("unable to request lines");
- ret = gpiod_line_request_get_values(request, num_lines,
- offsets, values);
+ ret = gpiod_line_request_get_values(request, values);
if (ret)
die_perror("unable to read GPIO line values");
--
2.30.1
next prev parent reply other threads:[~2021-07-15 20:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-15 20:09 [libgpiod][PATCH v2 0/3] libgpiod v2: C++ bindings Bartosz Golaszewski
2021-07-15 20:09 ` [libgpiod][PATCH v2 1/3] API: add a function for retrieving the capacity of edge event buffers Bartosz Golaszewski
2021-07-15 20:10 ` Bartosz Golaszewski [this message]
2021-07-15 20:10 ` [libgpiod][PATCH v2 3/3] bindings: cxx: implement C++ bindings for libgpiod v2.0 Bartosz Golaszewski
2021-07-15 22:18 ` Ben Hutchings
2021-07-16 7:44 ` Bartosz Golaszewski
2021-07-16 8:56 ` Bartosz Golaszewski
2021-07-16 13:24 ` Bartosz Golaszewski
2021-07-22 10:48 ` Jack Winch
2021-07-22 19:38 ` Bartosz Golaszewski
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=20210715201001.23726-3-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ben.hutchings@essensium.com \
--cc=helmut.grohne@intenta.de \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=sunt.un.morcov@gmail.com \
--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).