From patchwork Fri Nov 15 14:43:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JbEdmQCC"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Mf13X1z9sP6 for ; Sat, 16 Nov 2019 01:44:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727730AbfKOOo3 (ORCPT ); Fri, 15 Nov 2019 09:44:29 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:38962 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727656AbfKOOo3 (ORCPT ); Fri, 15 Nov 2019 09:44:29 -0500 Received: by mail-pl1-f193.google.com with SMTP id o9so4804728plk.6 for ; Fri, 15 Nov 2019 06:44:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mvD88vYNW9HnvaEhfDiwyXuHVQ3vHAbyWxIkK5B1PWY=; b=JbEdmQCCnosYsvpePNldn6WuujZmGEVdlXV9wksphmNxo0/kGrSBAdjaH7FprJPhPA keIV7zCgfjbNjnaDgWXknLLagUrZ+H3vOst5llm6hE2g9bIki9Oq/3jBxTtEF8dbJMVC koKA7FfWRRM65JMzYWjNeo4IB2VfYRFo8MKMf720GkxvA9z4CXDVTNQdfyhjo2MTIhOV cUGqgHGVZdSfEI2Z8b+p5pPAvttLYsBclk0y2VINKzCdfF9LzqqZcSKLf9+/zVsj1rG+ l+1a5wGtc9I/T2i9PaW0RxJ0Q9i4s5ndqM7PNsVdjFAvfl2VgceVv5p/WUm6stEoZyg+ iCrQ== 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:mime-version:content-transfer-encoding; bh=mvD88vYNW9HnvaEhfDiwyXuHVQ3vHAbyWxIkK5B1PWY=; b=aiRffpujvwEQhljZ4CC1p9OkZcpQWpluvp22QbaUvf7No4yMYAYnyhGlwP3LDZsZfX ETlojvlY92oGCNbfSnGoA1z2ctux3lY5Or3wWvMBjhiNfJfLk/G3kQBm5hMvMIjF/FO5 1IKW5Usi7X/uYv8F1WKgPwwjyI8TO7oFIMLqfT5RgHwUT7C3j4qheftMbZD97MY2hiVo tOy3QE0Eo3YrJVyDXBn/jkMlnTVVi2Xnc4Y+h9WwQCtvfJUY2i+mhfGsGxUDPzqOH/ho frQxf1S/l2JMK+QkF7WRL7imueT8qMiW6dpsh/QcHUq2rucStRCupDISmmWxQ/LodLgx v/zA== X-Gm-Message-State: APjAAAU7VnKchNTYH9Se7ZBGwISKsqWdSkYpRdPiSMGZ3cULoLhvHzSq gDTHBtmQFnqf6/0ajPIjJwticaCwrWw= X-Google-Smtp-Source: APXvYqzgf09mTuEvHEM4FNAItMVoWVkLABW8SNoF3vCTCwQz6Yzt8kdm9tx1MmeGSmjs+UfyuQ0OBQ== X-Received: by 2002:a17:902:8d81:: with SMTP id v1mr12196844plo.289.1573829068580; Fri, 15 Nov 2019 06:44:28 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:44:28 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 01/19] core: move request flag to handle flag conversion into a separate function Date: Fri, 15 Nov 2019 22:43:37 +0800 Message-Id: <20191115144355.975-2-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Move common conversion code from line_request_values and line_request_event_single into a separate function to simplify adding additional flags. Signed-off-by: Kent Gibson --- lib/core.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/core.c b/lib/core.c index a04514e..f05e595 100644 --- a/lib/core.c +++ b/lib/core.c @@ -463,6 +463,20 @@ static bool line_bulk_all_free(struct gpiod_line_bulk *bulk) return true; } +static __u32 line_request_flag_to_gpio_handleflag(int flags) +{ + int hflags = 0; + + if (flags & GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN) + hflags |= GPIOHANDLE_REQUEST_OPEN_DRAIN; + if (flags & GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE) + hflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE; + if (flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW) + hflags |= GPIOHANDLE_REQUEST_ACTIVE_LOW; + + return hflags; +} + static int line_request_values(struct gpiod_line_bulk *bulk, const struct gpiod_line_request_config *config, const int *default_vals) @@ -488,19 +502,14 @@ static int line_request_values(struct gpiod_line_bulk *bulk, memset(&req, 0, sizeof(req)); - if (config->flags & GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN) - req.flags |= GPIOHANDLE_REQUEST_OPEN_DRAIN; - if (config->flags & GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE) - req.flags |= GPIOHANDLE_REQUEST_OPEN_SOURCE; - if (config->flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW) - req.flags |= GPIOHANDLE_REQUEST_ACTIVE_LOW; + req.lines = gpiod_line_bulk_num_lines(bulk); + req.flags = line_request_flag_to_gpio_handleflag(config->flags); if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_INPUT) req.flags |= GPIOHANDLE_REQUEST_INPUT; else if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT) req.flags |= GPIOHANDLE_REQUEST_OUTPUT; - req.lines = gpiod_line_bulk_num_lines(bulk); gpiod_line_bulk_foreach_line_off(bulk, line, i) { req.lineoffsets[i] = gpiod_line_offset(line); @@ -548,15 +557,9 @@ static int line_request_event_single(struct gpiod_line *line, sizeof(req.consumer_label) - 1); req.lineoffset = gpiod_line_offset(line); + req.handleflags = line_request_flag_to_gpio_handleflag(config->flags); req.handleflags |= GPIOHANDLE_REQUEST_INPUT; - if (config->flags & GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN) - req.handleflags |= GPIOHANDLE_REQUEST_OPEN_DRAIN; - if (config->flags & GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE) - req.handleflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE; - if (config->flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW) - req.handleflags |= GPIOHANDLE_REQUEST_ACTIVE_LOW; - if (config->request_type == GPIOD_LINE_REQUEST_EVENT_RISING_EDGE) req.eventflags |= GPIOEVENT_REQUEST_RISING_EDGE; else if (config->request_type == GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE) From patchwork Fri Nov 15 14:43:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fmDE8zib"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Mr75G0z9sP6 for ; Sat, 16 Nov 2019 01:44:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727732AbfKOOok (ORCPT ); Fri, 15 Nov 2019 09:44:40 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45505 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbfKOOoj (ORCPT ); Fri, 15 Nov 2019 09:44:39 -0500 Received: by mail-pf1-f195.google.com with SMTP id z4so6760645pfn.12 for ; Fri, 15 Nov 2019 06:44:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=waCp/q3sNstwWVQ04QXvStovpDKQWWhCzYX0OPeWLCE=; b=fmDE8zib/OnVto3Il5b26tL7O1PRjgZSX8tw/OsTvgGJANZfVvrcHEOA/jbI5cYL86 yK5THM1d5NEDD996HDZvXuoxObv3ZA962/0+APlsdzU5oae8xlQV/csRE6q765wGxa+x aeW0NycJ6+rmJYVKohG7OBCZeNLo522kBpolR0J0klXF/aryvKASBxY0td7FVWYRcjkU C9z+l7Z56ozZ/k2yCezL/0wtSODhn9S9nRCkSxua1uiGeRuCFI7vGQo8dOpSxyuyYb/K J5nfvB5v3QxQD/1M5Jwao15ENQe2wXKkuR+XhPLvDtxgelWd8oUtqOtSt6XUvGwsJknG 889A== 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:mime-version:content-transfer-encoding; bh=waCp/q3sNstwWVQ04QXvStovpDKQWWhCzYX0OPeWLCE=; b=cEktwgZTd+/pvWgm0JCMm8Hugv9hTn2+aPZqRW+DRD8u/4e2j28aVtEDbucACqP2ud i6o/iIeoE1YkYqh0qYRkYkbDdaDnhmmHT7ryCp7H6h4BvPnoqIZNQ4WSJHE/rJuKbJSt FxBti4ciO797kGdCSM6IhRWAwoFd7qjfTwMMP5eHR+Ga2RYQyvQ6QLjb+Gk2rILzPojo FbggeXChuZNH85XV1YB194XrwsFhNI42WUOH/trJlQ+3dl7zbrHe0T4n/sRzrTI/hnNM uKdrvn3oAIU1YgxwUAfZNmX70vdyCEaHo+N8ng4GXu1UdQm9/ptQTYdGraOWqzk0Uvvl +4Mg== X-Gm-Message-State: APjAAAUP9blJe7Wp8IFTF37g5raITtOSvAb/7pP7VOsBoAM8VkGwi+Q7 8jJ3gXoYGhjxdexRW0kzbW9FG1FJClg= X-Google-Smtp-Source: APXvYqwrW9E0mRb+xQUogjL4Jmxc+YtdaNZBIowkeRl0Dh5Q11cD8jgYK8SPCx7MF5ZAfVodiKi8zw== X-Received: by 2002:a63:7b5c:: with SMTP id k28mr17552224pgn.442.1573829078208; Fri, 15 Nov 2019 06:44:38 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:44:37 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 02/19] API: add support for bias flags Date: Fri, 15 Nov 2019 22:43:38 +0800 Message-Id: <20191115144355.975-3-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend the libgpiod API to support the bias flags recently added to the kernel GPIO uAPI. The core change is the addition of GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP and GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN flags to be passed into line_request functions, and the addition of gpiod_line_bias to return the bias state of lines. Extended variants of the ctxless functions that accept an active_low flag are added to also accept other flags. The variant names add a "_ext" suffix to the name of the original function. Based on initial work by Drew Fustini . Signed-off-by: Kent Gibson --- include/gpiod.h | 184 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/core.c | 32 ++++++--- lib/ctxless.c | 115 +++++++++++++++++++++++++++--- 3 files changed, 313 insertions(+), 18 deletions(-) diff --git a/include/gpiod.h b/include/gpiod.h index 9860ea8..0f01cab 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -84,6 +84,22 @@ struct gpiod_line_bulk; * the need to use the gpiod_* structures or to keep track of resources. */ +/** + * @brief Miscellaneous GPIO flags. + */ +enum { + GPIOD_CTXLESS_FLAG_OPEN_DRAIN = GPIOD_BIT(0), + /**< The line is an open-drain port. */ + GPIOD_CTXLESS_FLAG_OPEN_SOURCE = GPIOD_BIT(1), + /**< The line is an open-source port. */ + GPIOD_CTXLESS_FLAG_BIAS_DISABLE = GPIOD_BIT(2), + /**< The line has neither either pull-up nor pull-down resistor */ + GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN = GPIOD_BIT(3), + /**< The line has pull-down resistor enabled */ + GPIOD_CTXLESS_FLAG_BIAS_PULL_UP = GPIOD_BIT(4), + /**< The line has pull-up resistor enabled */ +}; + /** * @brief Read current value from a single GPIO line. * @param device Name, path, number or label of the gpiochip. @@ -95,6 +111,19 @@ struct gpiod_line_bulk; int gpiod_ctxless_get_value(const char *device, unsigned int offset, bool active_low, const char *consumer) GPIOD_API; +/** + * @brief Read current value from a single GPIO line. + * @param device Name, path, number or label of the gpiochip. + * @param offset Offset of the GPIO line. + * @param active_low The active state of this line - true if low. + * @param flags The flags for the line. + * @param consumer Name of the consumer. + * @return 0 or 1 (GPIO value) if the operation succeeds, -1 on error. + */ +int gpiod_ctxless_get_value_ext(const char *device, unsigned int offset, + bool active_low, int flags, + const char *consumer) GPIOD_API; + /** * @brief Read current values from a set of GPIO lines. * @param device Name, path, number or label of the gpiochip. @@ -110,6 +139,24 @@ int gpiod_ctxless_get_value_multiple(const char *device, unsigned int num_lines, bool active_low, const char *consumer) GPIOD_API; +/** + * @brief Read current values from a set of GPIO lines. + * @param device Name, path, number or label of the gpiochip. + * @param offsets Array of offsets of lines whose values should be read. + * @param values Buffer in which the values will be stored. + * @param num_lines Number of lines, must be > 0. + * @param active_low The active state of this line - true if low. + * @param flags The flags for the lines. + * @param consumer Name of the consumer. + * @return 0 if the operation succeeds, -1 on error. + */ +int gpiod_ctxless_get_value_multiple_ext(const char *device, + const unsigned int *offsets, + int *values, + unsigned int num_lines, + bool active_low, int flags, + const char *consumer) GPIOD_API; + /** * @brief Simple set value callback signature. */ @@ -133,6 +180,26 @@ int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value, gpiod_ctxless_set_value_cb cb, void *data) GPIOD_API; +/** + * @brief Set value of a single GPIO line. + * @param device Name, path, number or label of the gpiochip. + * @param offset The offset of the GPIO line. + * @param value New value (0 or 1). + * @param active_low The active state of this line - true if low. + * @param flags The flags for the line. + * @param consumer Name of the consumer. + * @param cb Optional callback function that will be called right after setting + * the value. Users can use this, for example, to pause the execution + * after toggling a GPIO. + * @param data Optional user data that will be passed to the callback function. + * @return 0 if the operation succeeds, -1 on error. + */ +int gpiod_ctxless_set_value_ext(const char *device, unsigned int offset, + int value, bool active_low, int flags, + const char *consumer, + gpiod_ctxless_set_value_cb cb, + void *data) GPIOD_API; + /** * @brief Set values of multiple GPIO lines. * @param device Name, path, number or label of the gpiochip. @@ -153,6 +220,29 @@ int gpiod_ctxless_set_value_multiple(const char *device, gpiod_ctxless_set_value_cb cb, void *data) GPIOD_API; +/** + * @brief Set values of multiple GPIO lines. + * @param device Name, path, number or label of the gpiochip. + * @param offsets Array of offsets of lines the values of which should be set. + * @param values Array of integers containing new values. + * @param num_lines Number of lines, must be > 0. + * @param active_low The active state of this line - true if low. + * @param flags The flags for the lines. + * @param consumer Name of the consumer. + * @param cb Optional callback function that will be called right after setting + * all values. Works the same as in ::gpiod_ctxless_set_value. + * @param data Optional user data that will be passed to the callback function. + * @return 0 if the operation succeeds, -1 on error. + */ +int gpiod_ctxless_set_value_multiple_ext(const char *device, + const unsigned int *offsets, + const int *values, + unsigned int num_lines, + bool active_low, int flags, + const char *consumer, + gpiod_ctxless_set_value_cb cb, + void *data) GPIOD_API; + /** * @brief Event types that the ctxless event monitor can wait for. */ @@ -327,6 +417,31 @@ int gpiod_ctxless_event_monitor(const char *device, int event_type, gpiod_ctxless_event_handle_cb event_cb, void *data) GPIOD_API; +/** + * @brief Wait for events on a single GPIO line. + * @param device Name, path, number or label of the gpiochip. + * @param event_type Type of events to listen for. + * @param offset GPIO line offset to monitor. + * @param active_low The active state of this line - true if low. + * @param flags The flags for the line. + * @param consumer Name of the consumer. + * @param timeout Maximum wait time for each iteration. + * @param poll_cb Callback function to call when waiting for events. + * @param event_cb Callback function to call for each line event. + * @param data User data passed to the callback. + * @return 0 if no errors were encountered, -1 if an error occurred. + * @note The way the ctxless event loop works is described in detail in + * ::gpiod_ctxless_event_monitor_multiple - this is just a wrapper aound + * this routine which calls it for a single GPIO line. + */ +int gpiod_ctxless_event_monitor_ext(const char *device, int event_type, + unsigned int offset, bool active_low, + int flags, const char *consumer, + const struct timespec *timeout, + gpiod_ctxless_event_poll_cb poll_cb, + gpiod_ctxless_event_handle_cb event_cb, + void *data) GPIOD_API; + /** * @brief Wait for events on multiple GPIO lines. * @param device Name, path, number or label of the gpiochip. @@ -366,6 +481,47 @@ int gpiod_ctxless_event_monitor_multiple( gpiod_ctxless_event_handle_cb event_cb, void *data) GPIOD_API; +/** + * @brief Wait for events on multiple GPIO lines. + * @param device Name, path, number or label of the gpiochip. + * @param event_type Type of events to listen for. + * @param offsets Array of GPIO line offsets to monitor. + * @param num_lines Number of lines to monitor. + * @param active_low The active state of this line - true if low. + * @param flags The flags for the lines. + * @param consumer Name of the consumer. + * @param timeout Maximum wait time for each iteration. + * @param poll_cb Callback function to call when waiting for events. Can + * be NULL. + * @param event_cb Callback function to call on event occurrence. + * @param data User data passed to the callback. + * @return 0 no errors were encountered, -1 if an error occurred. + * @note The poll callback can be NULL in which case the routine will fall + * back to a basic, ppoll() based callback. + * + * Internally this routine opens the GPIO chip, requests the set of lines for + * the type of events specified in the event_type parameter and calls the + * polling callback in a loop. The role of the polling callback is to detect + * input events on a set of file descriptors and notify the caller about the + * fds ready for reading. + * + * The ctxless event loop then reads each queued event from marked descriptors + * and calls the event callback. Both callbacks can stop the loop at any + * point. + * + * The poll_cb argument can be NULL in which case the function falls back to + * a default, ppoll() based callback. + */ +int gpiod_ctxless_event_monitor_multiple_ext( + const char *device, int event_type, + const unsigned int *offsets, + unsigned int num_lines, bool active_low, int flags, + const char *consumer, const struct timespec *timeout, + gpiod_ctxless_event_poll_cb poll_cb, + gpiod_ctxless_event_handle_cb event_cb, + void *data) GPIOD_API; + + /** * @brief Determine the chip name and line offset of a line with given name. * @param name The name of the GPIO line to lookup. @@ -658,6 +814,20 @@ enum { /**< The active state of a GPIO is active-low. */ }; +/** + * @brief Possible internal bias settings. + */ +enum { + GPIOD_LINE_BIAS_AS_IS = 1, + /**< The internal bias state is unknown. */ + GPIOD_LINE_BIAS_DISABLE, + /**< The internal bias is disabled. */ + GPIOD_LINE_BIAS_PULL_UP, + /**< The internal pull-up bias is enabled. */ + GPIOD_LINE_BIAS_PULL_DOWN, + /**< The internal pull-down bias is enabled. */ +}; + /** * @brief Read the GPIO line offset. * @param line GPIO line object. @@ -697,6 +867,14 @@ int gpiod_line_direction(struct gpiod_line *line) GPIOD_API; */ int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API; +/** + * @brief Read the GPIO line bias setting. + * @param line GPIO line object. + * @return Returns GPIOD_LINE_BIAS_PULL_UP, GPIOD_LINE_BIAS_PULL_DOWN, + * GPIOD_LINE_BIAS_DISABLE or GPIOD_LINE_BIAS_AS_IS. + */ +int gpiod_line_bias(struct gpiod_line *line) GPIOD_API; + /** * @brief Check if the line is currently in use. * @param line GPIO line object. @@ -792,6 +970,12 @@ enum { /**< The line is an open-source port. */ GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW = GPIOD_BIT(2), /**< The active state of the line is low (high is the default). */ + GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE = GPIOD_BIT(3), + /**< The line has neither either pull-up nor pull-down resistor */ + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN = GPIOD_BIT(4), + /**< The line has pull-down resistor enabled */ + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP = GPIOD_BIT(5), + /**< The line has pull-up resistor enabled */ }; /** diff --git a/lib/core.c b/lib/core.c index f05e595..9b7d88f 100644 --- a/lib/core.c +++ b/lib/core.c @@ -36,9 +36,7 @@ struct gpiod_line { unsigned int offset; int direction; int active_state; - bool used; - bool open_source; - bool open_drain; + __u32 flags; int state; bool needs_update; @@ -359,19 +357,31 @@ int gpiod_line_active_state(struct gpiod_line *line) return line->active_state; } +int gpiod_line_bias(struct gpiod_line *line) +{ + if (line->flags & GPIOLINE_FLAG_BIAS_DISABLE) + return GPIOD_LINE_BIAS_DISABLE; + if (line->flags & GPIOLINE_FLAG_BIAS_PULL_UP) + return GPIOD_LINE_BIAS_PULL_UP; + if (line->flags & GPIOLINE_FLAG_BIAS_PULL_DOWN) + return GPIOD_LINE_BIAS_PULL_DOWN; + + return GPIOD_LINE_BIAS_AS_IS; +} + bool gpiod_line_is_used(struct gpiod_line *line) { - return line->used; + return line->flags & GPIOLINE_FLAG_KERNEL; } bool gpiod_line_is_open_drain(struct gpiod_line *line) { - return line->open_drain; + return line->flags & GPIOLINE_FLAG_OPEN_DRAIN; } bool gpiod_line_is_open_source(struct gpiod_line *line) { - return line->open_source; + return line->flags & GPIOLINE_FLAG_OPEN_SOURCE; } bool gpiod_line_needs_update(struct gpiod_line *line) @@ -398,9 +408,7 @@ int gpiod_line_update(struct gpiod_line *line) ? GPIOD_LINE_ACTIVE_STATE_LOW : GPIOD_LINE_ACTIVE_STATE_HIGH; - line->used = info.flags & GPIOLINE_FLAG_KERNEL; - line->open_drain = info.flags & GPIOLINE_FLAG_OPEN_DRAIN; - line->open_source = info.flags & GPIOLINE_FLAG_OPEN_SOURCE; + line->flags = info.flags; strncpy(line->name, info.name, sizeof(line->name)); strncpy(line->consumer, info.consumer, sizeof(line->consumer)); @@ -473,6 +481,12 @@ static __u32 line_request_flag_to_gpio_handleflag(int flags) hflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE; if (flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW) hflags |= GPIOHANDLE_REQUEST_ACTIVE_LOW; + if (flags & GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE) + hflags |= GPIOHANDLE_REQUEST_BIAS_DISABLE; + if (flags & GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN) + hflags |= GPIOHANDLE_REQUEST_BIAS_PULL_DOWN; + if (flags & GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP) + hflags |= GPIOHANDLE_REQUEST_BIAS_PULL_UP; return hflags; } diff --git a/lib/ctxless.c b/lib/ctxless.c index ba85018..44f1872 100644 --- a/lib/ctxless.c +++ b/lib/ctxless.c @@ -14,6 +14,26 @@ #include #include +static int ctxless_flags_to_line_request_flags(bool active_low, int flags) +{ + int lflags = 0; + + if (active_low) + lflags |= GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW; + if (flags & GPIOD_CTXLESS_FLAG_OPEN_DRAIN) + lflags |= GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN; + if (flags & GPIOD_CTXLESS_FLAG_OPEN_SOURCE) + lflags |= GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE; + if (flags & GPIOD_CTXLESS_FLAG_BIAS_DISABLE) + lflags |= GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE; + if (flags & GPIOD_CTXLESS_FLAG_BIAS_PULL_UP) + lflags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP; + if (flags & GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN) + lflags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN; + + return lflags; +} + int gpiod_ctxless_get_value(const char *device, unsigned int offset, bool active_low, const char *consumer) { @@ -27,16 +47,45 @@ int gpiod_ctxless_get_value(const char *device, unsigned int offset, return value; } +int gpiod_ctxless_get_value_ext(const char *device, unsigned int offset, + bool active_low, int flags, + const char *consumer) +{ + int value, rv; + + rv = gpiod_ctxless_get_value_multiple_ext(device, &offset, &value, 1, + active_low, flags, consumer); + if (rv < 0) + return rv; + + return value; +} + int gpiod_ctxless_get_value_multiple(const char *device, const unsigned int *offsets, int *values, unsigned int num_lines, bool active_low, const char *consumer) +{ + int rv; + + rv = gpiod_ctxless_get_value_multiple_ext(device, offsets, values, + num_lines, active_low, 0, + consumer); + return rv; +} + +int gpiod_ctxless_get_value_multiple_ext(const char *device, + const unsigned int *offsets, + int *values, + unsigned int num_lines, + bool active_low, int flags, + const char *consumer) { struct gpiod_line_bulk bulk; struct gpiod_chip *chip; struct gpiod_line *line; unsigned int i; - int rv, flags; + int rv, lflags; if (!num_lines || num_lines > GPIOD_LINE_BULK_MAX_LINES) { errno = EINVAL; @@ -59,9 +108,8 @@ int gpiod_ctxless_get_value_multiple(const char *device, gpiod_line_bulk_add(&bulk, line); } - flags = active_low ? GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW : 0; - - rv = gpiod_line_request_bulk_input_flags(&bulk, consumer, flags); + lflags = ctxless_flags_to_line_request_flags(active_low, flags); + rv = gpiod_line_request_bulk_input_flags(&bulk, consumer, lflags); if (rv < 0) { gpiod_chip_close(chip); return -1; @@ -83,17 +131,39 @@ int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value, active_low, consumer, cb, data); } +int gpiod_ctxless_set_value_ext(const char *device, unsigned int offset, + int value, bool active_low, int flags, + const char *consumer, + gpiod_ctxless_set_value_cb cb, void *data) +{ + return gpiod_ctxless_set_value_multiple_ext(device, &offset, &value, + 1, active_low, flags, + consumer, cb, data); +} + int gpiod_ctxless_set_value_multiple(const char *device, const unsigned int *offsets, const int *values, unsigned int num_lines, bool active_low, const char *consumer, gpiod_ctxless_set_value_cb cb, void *data) +{ + return gpiod_ctxless_set_value_multiple_ext(device, offsets, values, + num_lines, active_low, + 0, consumer, cb, data); +} + +int gpiod_ctxless_set_value_multiple_ext( + const char *device, + const unsigned int *offsets, + const int *values, unsigned int num_lines, + bool active_low, int flags, const char *consumer, + gpiod_ctxless_set_value_cb cb, void *data) { struct gpiod_line_bulk bulk; struct gpiod_chip *chip; struct gpiod_line *line; unsigned int i; - int rv, flags; + int rv, lflags; if (!num_lines || num_lines > GPIOD_LINE_BULK_MAX_LINES) { errno = EINVAL; @@ -116,10 +186,9 @@ int gpiod_ctxless_set_value_multiple(const char *device, gpiod_line_bulk_add(&bulk, line); } - flags = active_low ? GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW : 0; - + lflags = ctxless_flags_to_line_request_flags(active_low, flags); rv = gpiod_line_request_bulk_output_flags(&bulk, consumer, - flags, values); + lflags, values); if (rv < 0) { gpiod_chip_close(chip); return -1; @@ -216,6 +285,19 @@ int gpiod_ctxless_event_monitor(const char *device, int event_type, poll_cb, event_cb, data); } +int gpiod_ctxless_event_monitor_ext(const char *device, int event_type, + unsigned int offset, bool active_low, + int flags, const char *consumer, + const struct timespec *timeout, + gpiod_ctxless_event_poll_cb poll_cb, + gpiod_ctxless_event_handle_cb event_cb, + void *data) +{ + return gpiod_ctxless_event_monitor_multiple_ext( + device, event_type, &offset, 1, active_low, + flags, consumer, timeout, poll_cb, event_cb, data); +} + int gpiod_ctxless_event_monitor_multiple( const char *device, int event_type, const unsigned int *offsets, @@ -225,6 +307,21 @@ int gpiod_ctxless_event_monitor_multiple( gpiod_ctxless_event_poll_cb poll_cb, gpiod_ctxless_event_handle_cb event_cb, void *data) +{ + return gpiod_ctxless_event_monitor_multiple_ext( + device, event_type, offsets, + num_lines, active_low, 0, consumer, timeout, + poll_cb, event_cb, data); +} + +int gpiod_ctxless_event_monitor_multiple_ext( + const char *device, int event_type, + const unsigned int *offsets, + unsigned int num_lines, bool active_low, int flags, + const char *consumer, const struct timespec *timeout, + gpiod_ctxless_event_poll_cb poll_cb, + gpiod_ctxless_event_handle_cb event_cb, + void *data) { struct gpiod_ctxless_event_poll_fd fds[GPIOD_LINE_BULK_MAX_LINES]; struct gpiod_line_request_config conf; @@ -259,7 +356,7 @@ int gpiod_ctxless_event_monitor_multiple( gpiod_line_bulk_add(&bulk, line); } - conf.flags = active_low ? GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW : 0; + conf.flags = ctxless_flags_to_line_request_flags(active_low, flags); conf.consumer = consumer; if (event_type == GPIOD_CTXLESS_EVENT_RISING_EDGE) { From patchwork Fri Nov 15 14:43:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZCH47zhu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Mx6ZlFz9sP6 for ; Sat, 16 Nov 2019 01:44:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727561AbfKOOop (ORCPT ); Fri, 15 Nov 2019 09:44:45 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41654 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbfKOOop (ORCPT ); Fri, 15 Nov 2019 09:44:45 -0500 Received: by mail-pl1-f196.google.com with SMTP id d29so4795161plj.8 for ; Fri, 15 Nov 2019 06:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YkiGHbSvQlu3pN7juLuHrz+s6lf9aoweXl5F5rXKzDM=; b=ZCH47zhuToHyK0gclPDaUSzuOgawXiNyCwFDudeNN2ZcQy+TSTwUpJJbuDOt5IEbTf BCP6Knr6KzesUSXzJ9zY2Xa8/4YZmKdipSp049bK963T5uUK6KizfWhsJA5ZqV3Cbx6K aetoV3yGNsM2EqQZtEJs2nMB4wBs36h/VacTchPYB7T4Z3S8FIoKMBfoj6UJqlivZ5EF hY3GF1pxynzfvG359Wy0aRgZVOIgUeRXj2gM2y0qM7kKN2PWWixhPMzlBzFzEiUX/LO4 6nYxrtPmT12GG1uT6o2GrsckyB424U/dJRWmO/wg7QGhYoCyo5khrWZL6gkdrLWAwFAc iyNQ== 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:mime-version:content-transfer-encoding; bh=YkiGHbSvQlu3pN7juLuHrz+s6lf9aoweXl5F5rXKzDM=; b=ivl70kP1lL0GSL4kls02TpYNxFcjRuTbU4jCZob252tNJyHNymjF00QhNfxUB/vRLz rOgHNnT5nbF/DOWW/0aH7fCcFxKX47vt4apcWcgCtwrMcBbPdEUJqjd0RBCJcLJFozWN 24VrCpL3ufcNnNuA2sbS3wZWnzd5TXmuDKkwHHk0veCMqSKkwYniFA+s2jlB8gTOKu+g hNOrX/XnGNUUDoSiizBU5/M6KfvDEkgsngG0v1qq+T9Dh6t4AQpDit30pLu0le4xE8Kx MdeSop6pobj/2vjEBi3dlnWf9NmumrU4cQMKbjLpOLnDb08ALRz7kBd12QxP08wEKGWI DcrA== X-Gm-Message-State: APjAAAUApbX5LOqA/A/38/yxsaUuB0ZAvD2r93zyPCJYLjflCm4E4H9n CdAs7gbXRJ8gSdTUDxiRRvKPFEye6uI= X-Google-Smtp-Source: APXvYqzTy6SyctLiur3DLqYqbyaC1JLxLbVdoAWzpdpuwijThqM97hNg6f12Mf59inD8oCKqZj4y8A== X-Received: by 2002:a17:902:6802:: with SMTP id h2mr15129561plk.135.1573829084287; Fri, 15 Nov 2019 06:44:44 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:44:43 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 03/19] core: fix misspelling of parameter Date: Fri, 15 Nov 2019 22:43:39 +0800 Message-Id: <20191115144355.975-4-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Trivial fix to bring gpiod_ctxless_event_monitor_multiple documentation into line with gpiod_ctxless_event_monitor_multiple_ext. Signed-off-by: Kent Gibson --- include/gpiod.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gpiod.h b/include/gpiod.h index 0f01cab..159d745 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -460,7 +460,7 @@ int gpiod_ctxless_event_monitor_ext(const char *device, int event_type, * back to a basic, ppoll() based callback. * * Internally this routine opens the GPIO chip, requests the set of lines for - * the type of events specified in the event_type paramter and calls the + * the type of events specified in the event_type parameter and calls the * polling callback in a loop. The role of the polling callback is to detect * input events on a set of file descriptors and notify the caller about the * fds ready for reading. From patchwork Fri Nov 15 14:43:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b7RPzPRu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1N315Qpz9sP6 for ; Sat, 16 Nov 2019 01:44:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727576AbfKOOou (ORCPT ); Fri, 15 Nov 2019 09:44:50 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43433 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbfKOOou (ORCPT ); Fri, 15 Nov 2019 09:44:50 -0500 Received: by mail-pl1-f193.google.com with SMTP id a18so4795426plm.10 for ; Fri, 15 Nov 2019 06:44:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SnaiY0S+/8nKSFFBV00qiyMZTLj4SC/M1Y1RlYUZJAg=; b=b7RPzPRuouPfe5Vz2cPz2cCuSMMOOXI3FRhXlTHrEccQiWzFeABGGTHgQyV96qEs6D IjHxSLZ6MDBXnQvD7TCNCbB9Htcg6/N4cflkuOK/88G+8w+j4ZF2LReMqAMnFYV49zOi 1s3zEq75quRWBOS8PNwKmlqAwv6WEPWhAAwujYDeuGExA6+buXuZBIBxS3Lj+7mQd5gs 7LLL0veyyaqsQp+sE4vR1Rr5x96h9nIjLT4OZp2XpuDng7DxRlpMrTlHswozFOX9zmYU 2iafUPbAOa++C5n4DFYj1vGIjC5MIFSEZudkMVALtQeK3GtKBGai/nnY7jyr8maHU6Gs TuJw== 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:mime-version:content-transfer-encoding; bh=SnaiY0S+/8nKSFFBV00qiyMZTLj4SC/M1Y1RlYUZJAg=; b=LSwjtdMg9a+tl1nu3OgePGukbdwhV/XQMEcHASKOYlq9ZQFe7qfkwhWaCVoVI4Xw5U rX0Xt2BEkh3eV/ZHx8VflarrxYwL/qibBH+WleaumJAzw4TH0gDQ1C3qllg5mIMWLenM HQx+uxDt6srKesEiJt/aMAy6k6b/NNUljsE16Oj5MxMSuIGun4m9V0iNmVCWCXyA+OAk jxJC5SP1dd4xPhvUHtJE4yYwzVmn/9pb3FZ1XcxVEQSQn6oDP3LKTKJc4FvmX6etpZMa +GwNhFu5PPwsVUMr3D0HFmwSyxhbAKjDhgug7nAT4d50ZjETAQK0QlbcBtiSEDEhN+xr SmXA== X-Gm-Message-State: APjAAAXsi/giJE8+Ltt/YRN//ICSDzyQq573otD9maID0RUiLkl/fV22 11IaGdwwLB5mN86Porp/0D8ZoTvXfD8= X-Google-Smtp-Source: APXvYqy3YGs3ScE8gJYWj6kFRyPUyRV7vRLkQqvgu3B/s105QHGGQ1VtEVTBhktqY0IPyDF6Lr6Fmw== X-Received: by 2002:a17:90a:7784:: with SMTP id v4mr20559928pjk.74.1573829089150; Fri, 15 Nov 2019 06:44:49 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:44:48 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 04/19] tests: add tests for bias flags Date: Fri, 15 Nov 2019 22:43:40 +0800 Message-Id: <20191115144355.975-5-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend test coverage over the bias flags, gpiod_line_bias and the extended ctxless functions. Also update existing tests to check bias flags where line state is checked. Signed-off-by: Kent Gibson --- tests/tests-ctxless.c | 64 +++++++++++++++++++++- tests/tests-event.c | 120 ++++++++++++++++++++++++++++++++++++++++++ tests/tests-line.c | 98 ++++++++++++++++++++++++++++++++++ 3 files changed, 280 insertions(+), 2 deletions(-) diff --git a/tests/tests-ctxless.c b/tests/tests-ctxless.c index c1e1ca6..da70587 100644 --- a/tests/tests-ctxless.c +++ b/tests/tests-ctxless.c @@ -26,11 +26,41 @@ GPIOD_TEST_CASE(get_value, 0, { 8 }) g_assert_cmpint(ret, ==, 1); } -static void set_value_check(gpointer data G_GNUC_UNUSED) +GPIOD_TEST_CASE(get_value_ext, 0, { 8 }) +{ + gint ret; + + ret = gpiod_ctxless_get_value_ext(gpiod_test_chip_name(0), 3, + false, GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN, + GPIOD_TEST_CONSUMER); + g_assert_cmpint(ret, ==, 0); + + ret = gpiod_ctxless_get_value_ext(gpiod_test_chip_name(0), 3, + false, GPIOD_CTXLESS_FLAG_BIAS_PULL_UP, + GPIOD_TEST_CONSUMER); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_ctxless_get_value_ext(gpiod_test_chip_name(0), 3, + true, GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN, + GPIOD_TEST_CONSUMER); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_ctxless_get_value_ext(gpiod_test_chip_name(0), 3, + true, GPIOD_CTXLESS_FLAG_BIAS_PULL_UP, + GPIOD_TEST_CONSUMER); + g_assert_cmpint(ret, ==, 0); +} + +static void set_value_check_hi(gpointer data G_GNUC_UNUSED) { g_assert_cmpint(gpiod_test_chip_get_value(0, 3), ==, 1); } +static void set_value_check_lo(gpointer data G_GNUC_UNUSED) +{ + g_assert_cmpint(gpiod_test_chip_get_value(0, 3), ==, 0); +} + GPIOD_TEST_CASE(set_value, 0, { 8 }) { gint ret; @@ -39,13 +69,43 @@ GPIOD_TEST_CASE(set_value, 0, { 8 }) ret = gpiod_ctxless_set_value(gpiod_test_chip_name(0), 3, 1, false, GPIOD_TEST_CONSUMER, - set_value_check, NULL); + set_value_check_hi, NULL); gpiod_test_return_if_failed(); g_assert_cmpint(ret, ==, 0); g_assert_cmpint(gpiod_test_chip_get_value(0, 3), ==, 0); } +GPIOD_TEST_CASE(set_value_ext, 0, { 8 }) +{ + gint ret; + + gpiod_test_chip_set_pull(0, 3, 0); + + ret = gpiod_ctxless_set_value_ext(gpiod_test_chip_name(0), 3, 1, + false, 0, GPIOD_TEST_CONSUMER, + set_value_check_hi, NULL); + gpiod_test_return_if_failed(); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 3), ==, 0); + + // test drive flags by checking that sets are caught by emulation + ret = gpiod_ctxless_set_value_ext(gpiod_test_chip_name(0), 3, 1, + false, GPIOD_CTXLESS_FLAG_OPEN_DRAIN, + GPIOD_TEST_CONSUMER, set_value_check_lo, NULL); + gpiod_test_return_if_failed(); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 3), ==, 0); + + gpiod_test_chip_set_pull(0, 3, 1); + ret = gpiod_ctxless_set_value_ext(gpiod_test_chip_name(0), 3, 0, + false, GPIOD_CTXLESS_FLAG_OPEN_SOURCE, + GPIOD_TEST_CONSUMER, set_value_check_hi, NULL); + gpiod_test_return_if_failed(); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 3), ==, 1); +} + static const guint get_value_multiple_offsets[] = { 1, 3, 4, 5, 6, 7, 8, 9, 13, 14 }; diff --git a/tests/tests-event.c b/tests/tests-event.c index 28b77ec..d425d1a 100644 --- a/tests/tests-event.c +++ b/tests/tests-event.c @@ -196,6 +196,126 @@ GPIOD_TEST_CASE(both_edges_active_low, 0, { 8 }) g_assert_cmpint(ev.event_type, ==, GPIOD_LINE_EVENT_RISING_EDGE); } +GPIOD_TEST_CASE(both_edges_bias_disable, 0, { 8 }) +{ + g_autoptr(GpiodTestEventThread) ev_thread = NULL; + g_autoptr(gpiod_chip_struct) chip = NULL; + struct timespec ts = { 1, 0 }; + struct gpiod_line_event ev; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 7); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_both_edges_events_flags(line, + GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE); + g_assert_cmpint(ret, ==, 0); + + ev_thread = gpiod_test_start_event_thread(0, 7, 100); + + ret = gpiod_line_event_wait(line, &ts); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_line_event_read(line, &ev); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(ev.event_type, ==, GPIOD_LINE_EVENT_RISING_EDGE); + + ret = gpiod_line_event_wait(line, &ts); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_line_event_read(line, &ev); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(ev.event_type, ==, GPIOD_LINE_EVENT_FALLING_EDGE); +} + +GPIOD_TEST_CASE(both_edges_bias_pull_down, 0, { 8 }) +{ + g_autoptr(GpiodTestEventThread) ev_thread = NULL; + g_autoptr(gpiod_chip_struct) chip = NULL; + struct timespec ts = { 1, 0 }; + struct gpiod_line_event ev; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 7); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_both_edges_events_flags(line, + GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN); + g_assert_cmpint(ret, ==, 0); + + ev_thread = gpiod_test_start_event_thread(0, 7, 100); + + ret = gpiod_line_event_wait(line, &ts); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_line_event_read(line, &ev); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(ev.event_type, ==, GPIOD_LINE_EVENT_RISING_EDGE); + + ret = gpiod_line_event_wait(line, &ts); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_line_event_read(line, &ev); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(ev.event_type, ==, GPIOD_LINE_EVENT_FALLING_EDGE); +} + +GPIOD_TEST_CASE(both_edges_bias_pull_up, 0, { 8 }) +{ + g_autoptr(GpiodTestEventThread) ev_thread = NULL; + g_autoptr(gpiod_chip_struct) chip = NULL; + struct timespec ts = { 1, 0 }; + struct gpiod_line_event ev; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 7); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_both_edges_events_flags(line, + GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP); + g_assert_cmpint(ret, ==, 0); + + ev_thread = gpiod_test_start_event_thread(0, 7, 100); + + ret = gpiod_line_event_wait(line, &ts); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_line_event_read(line, &ev); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(ev.event_type, ==, GPIOD_LINE_EVENT_FALLING_EDGE); + + ret = gpiod_line_event_wait(line, &ts); + g_assert_cmpint(ret, ==, 1); + + ret = gpiod_line_event_read(line, &ev); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(ev.event_type, ==, GPIOD_LINE_EVENT_RISING_EDGE); +} + GPIOD_TEST_CASE(falling_edge_active_low, 0, { 8 }) { g_autoptr(GpiodTestEventThread) ev_thread = NULL; diff --git a/tests/tests-line.c b/tests/tests-line.c index 4792211..b4bef1a 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -451,6 +451,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 }) g_assert_false(gpiod_line_is_used(line)); g_assert_false(gpiod_line_is_open_drain(line)); g_assert_false(gpiod_line_is_open_source(line)); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS); config.request_type = GPIOD_LINE_REQUEST_DIRECTION_OUTPUT; config.consumer = GPIOD_TEST_CONSUMER; @@ -462,6 +463,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 }) g_assert_true(gpiod_line_is_used(line)); g_assert_true(gpiod_line_is_open_drain(line)); g_assert_false(gpiod_line_is_open_source(line)); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_OUTPUT); @@ -475,8 +477,11 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 }) g_assert_true(gpiod_line_is_used(line)); g_assert_false(gpiod_line_is_open_drain(line)); g_assert_true(gpiod_line_is_open_source(line)); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_OUTPUT); + + gpiod_line_release(line); } GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 }) @@ -510,6 +515,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 }) g_assert_true(gpiod_line_is_used(line)); g_assert_true(gpiod_line_is_open_drain(line)); g_assert_false(gpiod_line_is_open_source(line)); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS); g_assert_cmpint(gpiod_line_active_state(line), ==, GPIOD_LINE_ACTIVE_STATE_LOW); g_assert_cmpint(gpiod_line_direction(line), ==, @@ -526,8 +532,59 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 }) g_assert_true(gpiod_line_is_used(line)); g_assert_false(gpiod_line_is_open_drain(line)); g_assert_true(gpiod_line_is_open_source(line)); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS); g_assert_cmpint(gpiod_line_active_state(line), ==, GPIOD_LINE_ACTIVE_STATE_LOW); + + gpiod_line_release(line); + + /* + * Verify that pull-up/down flags work together + * with active_low. + */ + + config.request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT; + config.flags = GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN | + GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW; + + ret = gpiod_line_request(line, &config, 0); + g_assert_cmpint(ret, ==, 0); + + g_assert_true(gpiod_line_is_used(line)); + g_assert_false(gpiod_line_is_open_drain(line)); + g_assert_false(gpiod_line_is_open_source(line)); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_DOWN); + g_assert_cmpint(gpiod_line_active_state(line), ==, + GPIOD_LINE_ACTIVE_STATE_LOW); + g_assert_cmpint(gpiod_line_direction(line), ==, + GPIOD_LINE_DIRECTION_INPUT); + + ret = gpiod_line_get_value(line); + g_assert_cmpint(ret, ==, 1); + g_assert_cmpint(errno, ==, 0); + + gpiod_line_release(line); + + config.flags = GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP | + GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW; + + ret = gpiod_line_request(line, &config, 0); + g_assert_cmpint(ret, ==, 0); + + g_assert_true(gpiod_line_is_used(line)); + g_assert_false(gpiod_line_is_open_drain(line)); + g_assert_false(gpiod_line_is_open_source(line)); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_UP); + g_assert_cmpint(gpiod_line_active_state(line), ==, + GPIOD_LINE_ACTIVE_STATE_LOW); + g_assert_cmpint(gpiod_line_direction(line), ==, + GPIOD_LINE_DIRECTION_INPUT); + + ret = gpiod_line_get_value(line); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(errno, ==, 0); + + gpiod_line_release(line); } GPIOD_TEST_CASE(open_source_open_drain_input_mode, 0, { 8 }) @@ -576,6 +633,47 @@ GPIOD_TEST_CASE(open_source_open_drain_simultaneously, 0, { 8 }) g_assert_cmpint(errno, ==, EINVAL); } +GPIOD_TEST_CASE(multiple_bias_flags, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 2); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_input_flags(line, GPIOD_TEST_CONSUMER, + GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE | + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN); + g_assert_cmpint(ret, ==, -1); + g_assert_cmpint(errno, ==, EINVAL); + + ret = gpiod_line_request_input_flags(line, GPIOD_TEST_CONSUMER, + GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE | + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP); + g_assert_cmpint(ret, ==, -1); + g_assert_cmpint(errno, ==, EINVAL); + + ret = gpiod_line_request_input_flags(line, GPIOD_TEST_CONSUMER, + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN | + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP); + g_assert_cmpint(ret, ==, -1); + g_assert_cmpint(errno, ==, EINVAL); + + ret = gpiod_line_request_input_flags(line, GPIOD_TEST_CONSUMER, + GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE | + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN | + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP); + g_assert_cmpint(ret, ==, -1); + g_assert_cmpint(errno, ==, EINVAL); +} + + /* Verify that the reference counting of the line fd handle works correctly. */ GPIOD_TEST_CASE(release_one_use_another, 0, { 8 }) { From patchwork Fri Nov 15 14:43:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A01PCWqB"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1N70sMzz9sP6 for ; Sat, 16 Nov 2019 01:44:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727577AbfKOOoy (ORCPT ); Fri, 15 Nov 2019 09:44:54 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42869 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbfKOOoy (ORCPT ); Fri, 15 Nov 2019 09:44:54 -0500 Received: by mail-pg1-f193.google.com with SMTP id q17so6108213pgt.9 for ; Fri, 15 Nov 2019 06:44:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NWFx3vvIX40wyYZAJG5zTznAtpZfnJmh/j1kpvQhfr0=; b=A01PCWqBBBSFvbC4JCMs5AZX7tZXuWzzbTlCqb/LkF7fDYZkWbecy06Ex/RqdrzyCs ISIjiIGNU2gc56cn/ZCKBtRg5jYhF4+z4vtkrLYzjzb0QP7gH7bX9ZlaSuJs+6iPLrrI yFkMpCgFJ0Mz8lIA0pmJdp9o7wTVOqBB6FomHhTyVveIU0E3SRN1/RjxPB+Whc81ziN5 Mhw6iveBHcYZlDpVifpRQUUslTmTWM7IpaoKA+zzWkY2lmt+5rkC2b/UbTJZoDRTt6XC 3c0HsDRxZs8vMJcLx2jjf8LOblUZYPA1oToKD/VEfBiuqqE9DeCIYZQXUqMy+qJfxswE nccw== 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:mime-version:content-transfer-encoding; bh=NWFx3vvIX40wyYZAJG5zTznAtpZfnJmh/j1kpvQhfr0=; b=VMSLN4sPrge2kZIWFnkyEUKPjCb/O4jmNGjn7qoy/JezFwcwG79tBDqPvBFegnV+aY 7oekeinnrCayf3DM0eAqzNOuEAOSHz4/3P/X7JgYOfC65LJ9tNClnuoOlwjb43Oe/yvQ KY+JSv7SbcKjinvEHTbTu+z/EdU/yQ+1KF1xdNS+9hprrB5Py9QjmiI19t/UHhHZooDr DoXVmZv3+5TrpG9o7DgybyD+5OnzN2tlFSOdeYk4qZYroyhIp17zB+Fgw3zQ1M8VKH7t ppGjKEolAADGid6DpQ7FxPJyKeeLWebt5dGZM83h13dzHlJw3vXmlQQPM2jLcs5r12bn Ra3Q== X-Gm-Message-State: APjAAAVBlga2E0sWvj0GhGNaeoLP6gL6NKUCrY+zcrGG+G/HrPUtpWxN I4zKGQEiWihgncZxLkHG0IZVW0Ln+Ok= X-Google-Smtp-Source: APXvYqyTH24LKAdMS2yNjrUikA6QDJ0z10P6CPbvv9Ov9QHjii0uVpLJcQGXcabIBexTcSTLFxNeDg== X-Received: by 2002:a63:154e:: with SMTP id 14mr16411912pgv.182.1573829093567; Fri, 15 Nov 2019 06:44:53 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:44:53 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 05/19] bindings: cxx: drop noexcept from direction and active_state Date: Fri, 15 Nov 2019 22:43:41 +0800 Message-Id: <20191115144355.975-6-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Both direction and active_state methods can throw and so should not be declared as noexcept. Signed-off-by: Kent Gibson --- bindings/cxx/gpiod.hpp | 4 ++-- bindings/cxx/line.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp index 13b4d5b..b5a9401 100644 --- a/bindings/cxx/gpiod.hpp +++ b/bindings/cxx/gpiod.hpp @@ -312,13 +312,13 @@ public: * @brief Get current direction of this line. * @return Current direction setting. */ - GPIOD_API int direction(void) const noexcept; + GPIOD_API int direction(void) const; /** * @brief Get current active state of this line. * @return Current active state setting. */ - GPIOD_API int active_state(void) const noexcept; + GPIOD_API int active_state(void) const; /** * @brief Check if this line is used by the kernel or other user space diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp index b698960..df6eada 100644 --- a/bindings/cxx/line.cpp +++ b/bindings/cxx/line.cpp @@ -49,7 +49,7 @@ unsigned int line::offset(void) const return consumer ? ::std::string(consumer) : ::std::string(); } -int line::direction(void) const noexcept +int line::direction(void) const { this->throw_if_null(); @@ -58,7 +58,7 @@ int line::direction(void) const noexcept return dir == GPIOD_LINE_DIRECTION_INPUT ? DIRECTION_INPUT : DIRECTION_OUTPUT; } -int line::active_state(void) const noexcept +int line::active_state(void) const { this->throw_if_null(); From patchwork Fri Nov 15 14:43:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="u5U/QZux"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1NC0ttXz9sP6 for ; Sat, 16 Nov 2019 01:44:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727590AbfKOOo6 (ORCPT ); Fri, 15 Nov 2019 09:44:58 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38634 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbfKOOo6 (ORCPT ); Fri, 15 Nov 2019 09:44:58 -0500 Received: by mail-pf1-f193.google.com with SMTP id c13so6785497pfp.5 for ; Fri, 15 Nov 2019 06:44:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZvwpS6dx4HzMyLNoM8rvn3UIuXUCh3TZTwo5Ge8pOiE=; b=u5U/QZuxOmATX5llsarwcKk1Z+ZoaPDGCwtcqMsULsepcuCDjkJca5fGHWxJ2X/fuj VyMc7N0el+h4YS7qdtSwjtQv+ZCDvHF8fKS7PrAq1Cd+ou96W5iqaoXgEUcWyGYOAKH5 PcS1Uq9RF1x7pJ153AMoRUuxU+h/Mm83gb3serP0koy/bUdLTKvji+wQZfJ5CRaGEFJE MyaLrmuAod6Sd8OTtZNwNGiiMUFhQTRtbPVWHY03pmai1Ql+adtFodVm6mqjN9GOlrCs D/hVaN7HtfqKOSilEu9Jvof54RhXsHlXL+vEabd7L6q9iUsaHbkuUulafegbQG/+a8on zmiw== 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:mime-version:content-transfer-encoding; bh=ZvwpS6dx4HzMyLNoM8rvn3UIuXUCh3TZTwo5Ge8pOiE=; b=s1n+YR/qoVegkCy7TSWTDGAiY+uDNvUjhnWJsuR3BE9SnErdcnPdqZ4zJ9xQkqGcn6 WqVdrIf2cE6N7II9H6EB8qFiRzL96jNbsfMcmG2hH1l8n4iWlZr8ztIfMMUkIfVUxcQg Myc4ysUj080T69FQoZJ1Bhwn9m7ap5MRzAvPOXBy4ATt19QMBLQWmw/vP776k+f0YtDB Q9noUfzCRNe/fya3BSx2kx9ciggs/E8/qVlxEFUWdggONcs4iIHWP14bkdSRe9Z+Tlr5 bwPkUx1cNPDVgWPwgOH+5e9r0Iftcma28nDuGy8cBYH/LPlfpNKg2igYw6BBIk+JCwIS ZOTQ== X-Gm-Message-State: APjAAAX1PSDJifHmdNc2mCPyzFnXhsrF7Tby60N8SqNtIUIF4QOZKvJ3 5bDTIL29+pZ/Rvv9z9BIfkPc64EY+YQ= X-Google-Smtp-Source: APXvYqyrxc/mf2e8C2YHyFRFcGneSrN+sjHkO7ejolgVAuAnqFkXTwGWeveHdRuChtpYeS77h6qEFg== X-Received: by 2002:a63:c406:: with SMTP id h6mr11202948pgd.213.1573829097422; Fri, 15 Nov 2019 06:44:57 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:44:57 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 06/19] bindings: cxx: initialise bitset with integer instead of string Date: Fri, 15 Nov 2019 22:43:42 +0800 Message-Id: <20191115144355.975-7-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Initialising bitsets with string is inefficient and confusing. Initialise them with the corresponding int instead. Signed-off-by: Kent Gibson --- bindings/cxx/line_bulk.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/cxx/line_bulk.cpp b/bindings/cxx/line_bulk.cpp index 8369930..c708c8b 100644 --- a/bindings/cxx/line_bulk.cpp +++ b/bindings/cxx/line_bulk.cpp @@ -11,9 +11,9 @@ namespace gpiod { -const ::std::bitset<32> line_request::FLAG_ACTIVE_LOW("001"); -const ::std::bitset<32> line_request::FLAG_OPEN_SOURCE("010"); -const ::std::bitset<32> line_request::FLAG_OPEN_DRAIN("100"); +const ::std::bitset<32> line_request::FLAG_ACTIVE_LOW(GPIOD_BIT(0)); +const ::std::bitset<32> line_request::FLAG_OPEN_SOURCE(GPIOD_BIT(1)); +const ::std::bitset<32> line_request::FLAG_OPEN_DRAIN(GPIOD_BIT(2)); namespace { From patchwork Fri Nov 15 14:43:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VZ9DsuCl"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1NH1qGwz9sP6 for ; Sat, 16 Nov 2019 01:45:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727556AbfKOOpC (ORCPT ); Fri, 15 Nov 2019 09:45:02 -0500 Received: from mail-pg1-f175.google.com ([209.85.215.175]:40192 "EHLO mail-pg1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOpC (ORCPT ); Fri, 15 Nov 2019 09:45:02 -0500 Received: by mail-pg1-f175.google.com with SMTP id 15so6114601pgt.7 for ; Fri, 15 Nov 2019 06:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uXrx5y2WL4cxWSJZuzUd3RqNYH2UrGCBMAG2mC95Yp4=; b=VZ9DsuClqAdtpSEe2D0+3vFD9mLr9eln7hbc0RrShlrcXRcAW+6TRNbRhQeLQcSMfx bz7WRHgJike6qCPb5aqWA38CdDFKodPkILfNVNzqFDbx0ZVaAHJtEsvkKoPGrPVyBxXB fTOyzHVbcdtCeJP4YIzT/wIaEwsiH9GJHlOlrnRJbg2P0yZYgpZqo/DyflYMh13asYTK vHjkvtJBy/55cLIj/4qeOuSC6z+qjbzu7Lpl516VUG8cgQjZwh7Pox8esEgzVeQBJ6a6 pByHBQrr2+HuNWRfUdGOchzTcOKld2xgYiQazaNlKanWOVIuwpWI6fD6gY+HHBeBFOPF Gagg== 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:mime-version:content-transfer-encoding; bh=uXrx5y2WL4cxWSJZuzUd3RqNYH2UrGCBMAG2mC95Yp4=; b=nPijDr63HKxEgVdAeyh0dC/9HCmGwQPWi+j7XktuY1EmRYPhh9tj9Rk2aC3lT7EElB RkwnLH1tEDvjICdnLxflpUQldQzZ19I50/8gzwzQfrzAJoBPtucJtP+PknCvj5wha1EW p6xHjc5HrbAIckwfVgNUecX93TAuSwQJQWkECxGJbZYzlJ0kRztlafmZoGi8CAZrtNYR qT5pxiD9H/KhIz5hGLdxVDhtIqxH7Q1yInlLJdoOLIT+JiW8cwTpMOzmpy2CpUMyBCZN 4WR6do1F2kb21nQvzUaCRbRwG14mJ15oWzcm/RR+RVknXBjdQ8hA1V4QjY4Gpvwke4yl CkyA== X-Gm-Message-State: APjAAAUMOJyNe9eWOy1eKLBgma8j4E2PsyIQWzyfl8VzRvCBBxUD/7Ei UCbhPSShiXf/kdzUB159MQEfhIcR64M= X-Google-Smtp-Source: APXvYqy6S7oa8q9mhqpGv12k0j2CwxtXIW0OHDeJz6xZlRfecHUUEvkWWiFVgP3RZa7SedCW5pgioA== X-Received: by 2002:a62:e914:: with SMTP id j20mr18215551pfh.245.1573829101276; Fri, 15 Nov 2019 06:45:01 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:00 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 07/19] bindings: cxx: add support for bias flags Date: Fri, 15 Nov 2019 22:43:43 +0800 Message-Id: <20191115144355.975-8-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add support for bias flags in line requests and returning the line bias setting via a bias accessor. Based on initial work by Drew Fustini . Signed-off-by: Kent Gibson --- bindings/cxx/gpiod.hpp | 26 ++++++++++++++++++++++++++ bindings/cxx/line.cpp | 19 +++++++++++++++++++ bindings/cxx/line_bulk.cpp | 6 ++++++ 3 files changed, 51 insertions(+) diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp index b5a9401..2b1a6ab 100644 --- a/bindings/cxx/gpiod.hpp +++ b/bindings/cxx/gpiod.hpp @@ -233,6 +233,12 @@ struct line_request /**< The line is an open-source port. */ GPIOD_API static const ::std::bitset<32> FLAG_OPEN_DRAIN; /**< The line is an open-drain port. */ + GPIOD_API static const ::std::bitset<32> FLAG_BIAS_DISABLE; + /**< The line has neither pull-up nor pull-down resistor enabled */ + GPIOD_API static const ::std::bitset<32> FLAG_BIAS_PULL_DOWN; + /**< The line has a configurable pull-down resistor enabled */ + GPIOD_API static const ::std::bitset<32> FLAG_BIAS_PULL_UP; + /**< The line has a configurable pull-up resistor enabled */ ::std::string consumer; /**< Consumer name to pass to the request. */ @@ -320,6 +326,12 @@ public: */ GPIOD_API int active_state(void) const; + /** + * @brief Get current bias of this line. + * @return Current bias setting. + */ + GPIOD_API int bias(void) const; + /** * @brief Check if this line is used by the kernel or other user space * process. @@ -456,6 +468,20 @@ public: /**< Line's active state is high. */ }; + /** + * @brief Possible bias settings. + */ + enum : int { + BIAS_AS_IS = 1, + /**< Line's bias state is unknown. */ + BIAS_DISABLE, + /**< Line's internal bias is disabled. */ + BIAS_PULL_UP, + /**< Line's internal pull-up bias is enabled. */ + BIAS_PULL_DOWN, + /**< Line's internal pull-down bias is enabled. */ + }; + private: line(::gpiod_line* line, const chip& owner); diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp index df6eada..dd6bb6a 100644 --- a/bindings/cxx/line.cpp +++ b/bindings/cxx/line.cpp @@ -67,6 +67,25 @@ int line::active_state(void) const return active == GPIOD_LINE_ACTIVE_STATE_HIGH ? ACTIVE_HIGH : ACTIVE_LOW; } +int line::bias(void) const +{ + this->throw_if_null(); + + int bias = ::gpiod_line_bias(this->_m_line); + + switch (bias) { + case GPIOD_LINE_BIAS_PULL_UP: + return BIAS_PULL_UP; + case GPIOD_LINE_BIAS_PULL_DOWN: + return BIAS_PULL_DOWN; + case GPIOD_LINE_BIAS_DISABLE: + return BIAS_DISABLE; + case GPIOD_LINE_BIAS_AS_IS: + default: + return BIAS_AS_IS; + } +} + bool line::is_used(void) const { this->throw_if_null(); diff --git a/bindings/cxx/line_bulk.cpp b/bindings/cxx/line_bulk.cpp index c708c8b..5f1cac4 100644 --- a/bindings/cxx/line_bulk.cpp +++ b/bindings/cxx/line_bulk.cpp @@ -14,6 +14,9 @@ namespace gpiod { const ::std::bitset<32> line_request::FLAG_ACTIVE_LOW(GPIOD_BIT(0)); const ::std::bitset<32> line_request::FLAG_OPEN_SOURCE(GPIOD_BIT(1)); const ::std::bitset<32> line_request::FLAG_OPEN_DRAIN(GPIOD_BIT(2)); +const ::std::bitset<32> line_request::FLAG_BIAS_DISABLE(GPIOD_BIT(3)); +const ::std::bitset<32> line_request::FLAG_BIAS_PULL_DOWN(GPIOD_BIT(4)); +const ::std::bitset<32> line_request::FLAG_BIAS_PULL_UP(GPIOD_BIT(5)); namespace { @@ -38,6 +41,9 @@ const ::std::map<::std::bitset<32>, int, bitset_cmp> reqflag_mapping = { { line_request::FLAG_ACTIVE_LOW, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW, }, { line_request::FLAG_OPEN_DRAIN, GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN, }, { line_request::FLAG_OPEN_SOURCE, GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE, }, + { line_request::FLAG_BIAS_DISABLE, GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE, }, + { line_request::FLAG_BIAS_PULL_DOWN, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN, }, + { line_request::FLAG_BIAS_PULL_UP, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP, }, }; } /* namespace */ From patchwork Fri Nov 15 14:43:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195684 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Vcvkt6DW"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1NM31FPz9sP6 for ; Sat, 16 Nov 2019 01:45:07 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727599AbfKOOpH (ORCPT ); Fri, 15 Nov 2019 09:45:07 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46322 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOpG (ORCPT ); Fri, 15 Nov 2019 09:45:06 -0500 Received: by mail-pg1-f193.google.com with SMTP id r18so6087413pgu.13 for ; Fri, 15 Nov 2019 06:45:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lJjxkFaNGMI/2BczVuIVgVpycDA94D2fnt8oPouRc0I=; b=Vcvkt6DWEvqZerkvfbpwzoJYHzSu4ECcJz37IPAehhxaODX7delYjAMf3Yztr2bflj BOi8RATLhV2jmWjjLPhW2LJauUv+2mcxyqb1+ewmqPDFcboLl14stSjDh6umFkr+N7To wyPOEbuN03IGRC6oqqys9CsWLy6rx11sAQcBzRTiC5JB6bZLHoXvHoKdORU+e3NgdkT3 avNkjY8DLD1e0r7FTdQv8vCeFzVtkHUXjD2n3/UGaVY3ogLVtJUakfy1+amedCN2pVaS psOIrrxUNim/IjgRdxCtLYP4zQRFMWwKbNlLQRqrqDw8IBWlPHUQfmQUhYMDyxvKVhTv tcUQ== 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:mime-version:content-transfer-encoding; bh=lJjxkFaNGMI/2BczVuIVgVpycDA94D2fnt8oPouRc0I=; b=Jqw7ieiFxGLR/qMaNubgasyAwezLiIm1QglvsB3pUiV0y0KVjbc5UvraX+jRzzx39g Z7YvBle5IVeV3s+WI3r8WNHYyyvs2JOpFIyMu4Ouvfn+1K1AcqxBA+8BAxT2uqbpK2Ue 2FDeYX7DMjWm6NdaI+z+grDo+bfK8AlgnZJ/bDgcOt6TlFUg1nO4QpP/WYfJri3fS6LI eQd2VWZefZKse0AIgFGYuePng/Je84Es+A5KVhmB1b94Gsttr810Abaq+tGF+bPuW8ZR cfS+eqlA0nWgDDrglOk6+sxvHNRhuRMocy35qOwbN2VS2naygjG7L1Hpbb/6yTc+H3CM u8wA== X-Gm-Message-State: APjAAAXl5PBzsK1XtKP8ESV6GKH2j1sZ2GbmzDXvVNj+V8hcb1VGKZzk Q+3hzCZyKmCLlhmvntE9UvelNJmjlD8= X-Google-Smtp-Source: APXvYqyzjY+bOvkG/o5eU+t1mq8DdpBjMxq3nQNnSDXr59OXII10VkJOPDL0EWsJAqr/jfk6IysTrQ== X-Received: by 2002:a63:f848:: with SMTP id v8mr16425664pgj.285.1573829105354; Fri, 15 Nov 2019 06:45:05 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:04 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 08/19] bindings: cxx: tests: add tests for bias flags Date: Fri, 15 Nov 2019 22:43:44 +0800 Message-Id: <20191115144355.975-9-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend test coverage over the bias flags in requests and the bias setting returned by line.bias(). Signed-off-by: Kent Gibson --- bindings/cxx/tests/tests-line.cpp | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/bindings/cxx/tests/tests-line.cpp b/bindings/cxx/tests/tests-line.cpp index 3ba2fc2..ef314b9 100644 --- a/bindings/cxx/tests/tests-line.cpp +++ b/bindings/cxx/tests/tests-line.cpp @@ -52,6 +52,9 @@ TEST_CASE("Line information can be correctly retrieved", "[line]") REQUIRE(line.consumer().empty()); REQUIRE_FALSE(line.is_requested()); REQUIRE_FALSE(line.is_used()); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS); } SECTION("exported line") @@ -68,6 +71,9 @@ TEST_CASE("Line information can be correctly retrieved", "[line]") REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); REQUIRE(line.is_requested()); REQUIRE(line.is_used()); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS); } SECTION("exported line with flags") @@ -88,6 +94,87 @@ TEST_CASE("Line information can be correctly retrieved", "[line]") REQUIRE(line.is_used()); REQUIRE(line.is_open_drain()); REQUIRE_FALSE(line.is_open_source()); + REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS); + } + + SECTION("exported open source line") + { + ::gpiod::line_request config; + + config.consumer = consumer.c_str(); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = ::gpiod::line_request::FLAG_OPEN_SOURCE; + line.request(config); + + REQUIRE(line.offset() == 4); + REQUIRE(line.name() == "gpio-mockup-A-4"); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); + REQUIRE(line.is_requested()); + REQUIRE(line.is_used()); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE(line.is_open_source()); + REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS); + } + + SECTION("exported bias disable line") + { + ::gpiod::line_request config; + + config.consumer = consumer.c_str(); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = ::gpiod::line_request::FLAG_BIAS_DISABLE; + line.request(config); + + REQUIRE(line.offset() == 4); + REQUIRE(line.name() == "gpio-mockup-A-4"); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); + REQUIRE(line.is_requested()); + REQUIRE(line.is_used()); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + REQUIRE(line.bias() == ::gpiod::line::BIAS_DISABLE); + } + + SECTION("exported pull-down line") + { + ::gpiod::line_request config; + + config.consumer = consumer.c_str(); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = ::gpiod::line_request::FLAG_BIAS_PULL_DOWN; + line.request(config); + + REQUIRE(line.offset() == 4); + REQUIRE(line.name() == "gpio-mockup-A-4"); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); + REQUIRE(line.is_requested()); + REQUIRE(line.is_used()); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + REQUIRE(line.bias() == ::gpiod::line::BIAS_PULL_DOWN); + } + + SECTION("exported pull-up line") + { + ::gpiod::line_request config; + + config.consumer = consumer.c_str(); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = ::gpiod::line_request::FLAG_BIAS_PULL_UP; + line.request(config); + + REQUIRE(line.offset() == 4); + REQUIRE(line.name() == "gpio-mockup-A-4"); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); + REQUIRE(line.is_requested()); + REQUIRE(line.is_used()); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + REQUIRE(line.bias() == ::gpiod::line::BIAS_PULL_UP); } SECTION("update line info") From patchwork Fri Nov 15 14:43:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="L3u+5Ul6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1NR2GpMz9sP6 for ; Sat, 16 Nov 2019 01:45:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727662AbfKOOpL (ORCPT ); Fri, 15 Nov 2019 09:45:11 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41721 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOpK (ORCPT ); Fri, 15 Nov 2019 09:45:10 -0500 Received: by mail-pl1-f195.google.com with SMTP id d29so4795913plj.8 for ; Fri, 15 Nov 2019 06:45:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mhy6RLeafK/iAD/QrQ/drYMOwu1/JmvZR9G9m8TgqdI=; b=L3u+5Ul6cPrXp8CLVzIfMhQbLC7tJrKxxkx3ka8lK8BXa4eiYQWlETnX0p48gMphQb iuoMqDhA4u/8gW3aCRknX0CU0QTphcYG3kuINeEOcetDrBBKjDVTa0H1Y2lduJIJNOIr mV2juGU2jrencb3AiiNnnLspNsPfs0DmWZ5k2zqI3CZQc4oUiIH5WB0B610FeKsTEInr Li2ZXRkgLIHAhZz9ScHlML7o3rBpnbpv18RRL88YToRKS+J+dIzXpLnqLIbuErol2IZx 9d/7DgZD0bkb+wBN4zqwfh8eWhNNmxjAtezLICRBfq5WGypN+BDhj82iylVucwaTqfpb xBIg== 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:mime-version:content-transfer-encoding; bh=Mhy6RLeafK/iAD/QrQ/drYMOwu1/JmvZR9G9m8TgqdI=; b=YGyG9CjLOQnsCZHqzYWdWLesZ5UTgOCF/uawSTK+mFWCSaz7r64u1WbWJp7KiPp4vF oHfQUZD8t66WabWDAvKQGYgwUfKarez5I6o3ZsPzs/vp8zXtKbJaCeDKnoq34oxaSKrd +0uBdGB+a6bNsMzQ8CFPQI12RpFmDOjCq4LR/ohG3Awf1T46hviUgR9EsUaFwhERO+mB Jmq8Qf254y+Qq0jl3m23v+V3lWYCvIOLdFmZeVhCVTSyaWq9TD8/444EDgtPPseo4gn4 NXJxt6tqql92SJ2rR7HhXPUApXGXgygiPYNNMhlPs+s6eWgMaCZM1Uu1yEboOzfOiVVq mzvA== X-Gm-Message-State: APjAAAXUXND6WLXYPp0ioX6NcAOR9jHznAGunVb2sZ2Wzt6LdnxhSD8f E3dmgejdVH7YBDTe7RpzO30H0R9XM5o= X-Google-Smtp-Source: APXvYqyz+l5L8Sc0Ih/sCjH80Bxdb9RIxtch4PmnE1vh9bjYsRPjLTA7nfH33sJF/InLqvVpZ/s62w== X-Received: by 2002:a17:902:650b:: with SMTP id b11mr8976523plk.60.1573829109061; Fri, 15 Nov 2019 06:45:09 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:08 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 09/19] bindings: python: add support for bias flags Date: Fri, 15 Nov 2019 22:43:45 +0800 Message-Id: <20191115144355.975-10-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add support for bias flags in line requests and returning the line bias setting via a bias accessor. Based on initial work by Drew Fustini . Signed-off-by: Kent Gibson --- bindings/python/gpiodmodule.c | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index d3c15ad..de8d6d1 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -60,6 +60,9 @@ enum { gpiod_LINE_REQ_FLAG_OPEN_DRAIN = GPIOD_BIT(0), gpiod_LINE_REQ_FLAG_OPEN_SOURCE = GPIOD_BIT(1), gpiod_LINE_REQ_FLAG_ACTIVE_LOW = GPIOD_BIT(2), + gpiod_LINE_REQ_FLAG_BIAS_DISABLE = GPIOD_BIT(3), + gpiod_LINE_REQ_FLAG_BIAS_PULL_DOWN = GPIOD_BIT(4), + gpiod_LINE_REQ_FLAG_BIAS_PULL_UP = GPIOD_BIT(5), }; enum { @@ -72,6 +75,13 @@ enum { gpiod_ACTIVE_LOW, }; +enum { + gpiod_BIAS_AS_IS = 1, + gpiod_BIAS_DISABLE, + gpiod_BIAS_PULL_UP, + gpiod_BIAS_PULL_DOWN, +}; + enum { gpiod_RISING_EDGE = 1, gpiod_FALLING_EDGE, @@ -358,6 +368,34 @@ static PyObject *gpiod_Line_active_state(gpiod_LineObject *self, return ret; } +PyDoc_STRVAR(gpiod_Line_bias_doc, +"bias() -> integer\n" +"\n" +"Get the bias setting of this GPIO line."); + +static PyObject *gpiod_Line_bias(gpiod_LineObject *self, + PyObject *Py_UNUSED(ignored)) +{ + int bias; + + if (gpiod_ChipIsClosed(self->owner)) + return NULL; + + bias = gpiod_line_bias(self->line); + + switch (bias) { + case GPIOD_LINE_BIAS_PULL_UP: + return Py_BuildValue("I", gpiod_BIAS_PULL_UP); + case GPIOD_LINE_BIAS_PULL_DOWN: + return Py_BuildValue("I", gpiod_BIAS_PULL_DOWN); + case GPIOD_LINE_BIAS_DISABLE: + return Py_BuildValue("I", gpiod_BIAS_DISABLE); + case GPIOD_LINE_BIAS_AS_IS: + default: + return Py_BuildValue("I", gpiod_BIAS_AS_IS); + } +} + PyDoc_STRVAR(gpiod_Line_is_used_doc, "is_used() -> boolean\n" "\n" @@ -752,6 +790,12 @@ static PyMethodDef gpiod_Line_methods[] = { .ml_flags = METH_NOARGS, .ml_doc = gpiod_Line_active_state_doc, }, + { + .ml_name = "bias", + .ml_meth = (PyCFunction)gpiod_Line_bias, + .ml_flags = METH_NOARGS, + .ml_doc = gpiod_Line_bias_doc, + }, { .ml_name = "is_used", .ml_meth = (PyCFunction)gpiod_Line_is_used, @@ -1030,6 +1074,12 @@ static void gpiod_MakeRequestConfig(struct gpiod_line_request_config *conf, conf->flags |= GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE; if (flags & gpiod_LINE_REQ_FLAG_ACTIVE_LOW) conf->flags |= GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW; + if (flags & gpiod_LINE_REQ_FLAG_BIAS_DISABLE) + conf->flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE; + if (flags & gpiod_LINE_REQ_FLAG_BIAS_PULL_DOWN) + conf->flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN; + if (flags & gpiod_LINE_REQ_FLAG_BIAS_PULL_UP) + conf->flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP; } PyDoc_STRVAR(gpiod_LineBulk_request_doc, @@ -2313,6 +2363,26 @@ static gpiod_ConstDescr gpiod_ConstList[] = { .name = "ACTIVE_LOW", .val = gpiod_ACTIVE_LOW, }, + { + .typeobj = &gpiod_LineType, + .name = "BIAS_AS_IS", + .val = gpiod_BIAS_AS_IS, + }, + { + .typeobj = &gpiod_LineType, + .name = "BIAS_DISABLE", + .val = gpiod_BIAS_DISABLE, + }, + { + .typeobj = &gpiod_LineType, + .name = "BIAS_PULL_UP", + .val = gpiod_BIAS_PULL_UP, + }, + { + .typeobj = &gpiod_LineType, + .name = "BIAS_PULL_DOWN", + .val = gpiod_BIAS_PULL_DOWN, + }, { .typeobj = &gpiod_LineEventType, .name = "RISING_EDGE", @@ -2381,6 +2451,18 @@ static gpiod_ModuleConst gpiod_ModuleConsts[] = { .name = "LINE_REQ_FLAG_ACTIVE_LOW", .value = gpiod_LINE_REQ_FLAG_ACTIVE_LOW, }, + { + .name = "LINE_REQ_FLAG_BIAS_DISABLE", + .value = gpiod_LINE_REQ_FLAG_BIAS_DISABLE, + }, + { + .name = "LINE_REQ_FLAG_BIAS_PULL_DOWN", + .value = gpiod_LINE_REQ_FLAG_BIAS_PULL_DOWN, + }, + { + .name = "LINE_REQ_FLAG_BIAS_PULL_UP", + .value = gpiod_LINE_REQ_FLAG_BIAS_PULL_UP, + }, { } }; From patchwork Fri Nov 15 14:43:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195686 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PlrEq7Be"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1NW1Yvmz9sP6 for ; Sat, 16 Nov 2019 01:45:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727673AbfKOOpO (ORCPT ); Fri, 15 Nov 2019 09:45:14 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38665 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOpO (ORCPT ); Fri, 15 Nov 2019 09:45:14 -0500 Received: by mail-pf1-f193.google.com with SMTP id c13so6785860pfp.5 for ; Fri, 15 Nov 2019 06:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S/HBD8d8BDWiXdFnRjwHb/de2FlPpTYAQz1J8zQ/lgw=; b=PlrEq7BeqaThqjnzQwshDi55euR/8W0XVR0HfwSfM0SWZpYSrYhR9jRTWoWXJJzEgm FlYNkuebdF87aUqFmq6Aer9pQ048DRDYRJhHPbnLi9NQNsCAa1kWirJbk5ix2Ud5nXO1 UNG+CDNEkHrFkIXJ2NFcWc0rrSRdoitVK8WdUBO85FNo/0bjSrtn/vdKycAXV8LRc6dD +RF8L7me1nl57C8BtRuPro+ftjQH0Bxgyt5TN6+vfzCCmoaRjoC8AyoGeVkSXVlzwv7w z75RIz2u+V7YChPmbxVcnPT95MJVWbknVuGkGQWAL9OjhkI6X/Jhjbkc+zyQujm4nfKU 0rXg== 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:mime-version:content-transfer-encoding; bh=S/HBD8d8BDWiXdFnRjwHb/de2FlPpTYAQz1J8zQ/lgw=; b=CN+Ya+54OFX2CQ9fKU0wn6caLzzAHMMKjElzVJtMvZ6oZOQb48L71DhFoLtTiDOIzJ g9UhQs6CYim1l8jORaCw+FvdnGZ5gv/rPMwvwgv5MO5I0XBE0QVm9b/CkIyz4KtOnFff CtGSTwjdABRaZG/WQY8ntr85ioBHVUCcD902WzCcd3G1UbK/VKSiPy5XtkM0dMnjijb0 mJUaFy0ltjnpJYO2U5tBypthE1F87zYzQMN/KIEMBrTZo0D7uaUpH/CEQanDNPXFDhPr 1zVFm1iK44DfJL9RJICoayMw4oMj1VKM1grkggvJBnd2FEGLs6L8Eqy30pEDXRJbSgL1 Qluw== X-Gm-Message-State: APjAAAXafqCAL81hm2Zyl94HvUZAFQBeJku5wkBsGKSFkpwXTV0PGoiB PEXbbP3ZKVrw50CPsXHCOSKNrUCyhdg= X-Google-Smtp-Source: APXvYqzr8K+Tmc6WyN50bQ9ulPuJcxXWXTr+C/VcpUELLiJiFTOyQOsiGZh8+L0xIvIFGOdcZXGCMg== X-Received: by 2002:a63:1402:: with SMTP id u2mr16645888pgl.391.1573829112890; Fri, 15 Nov 2019 06:45:12 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:12 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 10/19] bindings: python: tests: add tests for bias flags Date: Fri, 15 Nov 2019 22:43:46 +0800 Message-Id: <20191115144355.975-11-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend test coverage to cover the bias flags in requests and the bias setting returned by line.bias(). Signed-off-by: Kent Gibson --- bindings/python/tests/gpiod_py_test.py | 91 ++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/bindings/python/tests/gpiod_py_test.py b/bindings/python/tests/gpiod_py_test.py index ed31c8e..9330b43 100755 --- a/bindings/python/tests/gpiod_py_test.py +++ b/bindings/python/tests/gpiod_py_test.py @@ -306,6 +306,97 @@ class LineInfo(MockupTestCase): self.assertTrue(line.is_requested()) self.assertTrue(line.is_open_drain()) self.assertFalse(line.is_open_source()) + self.assertEqual(line.bias(), gpiod.Line.BIAS_AS_IS) + + def test_exported_open_drain_line(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(4) + flags = gpiod.LINE_REQ_FLAG_OPEN_DRAIN + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + flags=flags) + self.assertEqual(line.offset(), 4) + self.assertEqual(line.name(), 'gpio-mockup-A-4') + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH) + self.assertEqual(line.consumer(), default_consumer) + self.assertTrue(line.is_used()) + self.assertTrue(line.is_requested()) + self.assertTrue(line.is_open_drain()) + self.assertFalse(line.is_open_source()) + self.assertEqual(line.bias(), gpiod.Line.BIAS_AS_IS) + + def test_exported_open_source_line(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(4) + flags = gpiod.LINE_REQ_FLAG_OPEN_SOURCE + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + flags=flags) + self.assertEqual(line.offset(), 4) + self.assertEqual(line.name(), 'gpio-mockup-A-4') + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH) + self.assertEqual(line.consumer(), default_consumer) + self.assertTrue(line.is_used()) + self.assertTrue(line.is_requested()) + self.assertFalse(line.is_open_drain()) + self.assertTrue(line.is_open_source()) + self.assertEqual(line.bias(), gpiod.Line.BIAS_AS_IS) + + def test_exported_bias_disable_line(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(4) + flags = gpiod.LINE_REQ_FLAG_BIAS_DISABLE + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + flags=flags) + self.assertEqual(line.offset(), 4) + self.assertEqual(line.name(), 'gpio-mockup-A-4') + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH) + self.assertEqual(line.consumer(), default_consumer) + self.assertTrue(line.is_used()) + self.assertTrue(line.is_requested()) + self.assertFalse(line.is_open_drain()) + self.assertFalse(line.is_open_source()) + self.assertEqual(line.bias(), gpiod.Line.BIAS_DISABLE) + + def test_exported_bias_pull_down_line(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(4) + flags = gpiod.LINE_REQ_FLAG_BIAS_PULL_DOWN + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + flags=flags) + self.assertEqual(line.offset(), 4) + self.assertEqual(line.name(), 'gpio-mockup-A-4') + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH) + self.assertEqual(line.consumer(), default_consumer) + self.assertTrue(line.is_used()) + self.assertTrue(line.is_requested()) + self.assertFalse(line.is_open_drain()) + self.assertFalse(line.is_open_source()) + self.assertEqual(line.bias(), gpiod.Line.BIAS_PULL_DOWN) + + def test_exported_bias_pull_up_line(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(4) + flags = gpiod.LINE_REQ_FLAG_BIAS_PULL_UP + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + flags=flags) + self.assertEqual(line.offset(), 4) + self.assertEqual(line.name(), 'gpio-mockup-A-4') + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH) + self.assertEqual(line.consumer(), default_consumer) + self.assertTrue(line.is_used()) + self.assertTrue(line.is_requested()) + self.assertFalse(line.is_open_drain()) + self.assertFalse(line.is_open_source()) + self.assertEqual(line.bias(), gpiod.Line.BIAS_PULL_UP) def test_update_line_info(self): with gpiod.Chip(mockup.chip_name(0)) as chip: From patchwork Fri Nov 15 14:43:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195687 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="REAWzHHp"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Nb590Cz9sP6 for ; Sat, 16 Nov 2019 01:45:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727628AbfKOOpT (ORCPT ); Fri, 15 Nov 2019 09:45:19 -0500 Received: from mail-pg1-f169.google.com ([209.85.215.169]:46653 "EHLO mail-pg1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOpT (ORCPT ); Fri, 15 Nov 2019 09:45:19 -0500 Received: by mail-pg1-f169.google.com with SMTP id r18so6087705pgu.13 for ; Fri, 15 Nov 2019 06:45:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NVrPaEyoEe4sNOMv0b3KHLKiO/GE1MKLycW7wjCPVFI=; b=REAWzHHph/6+Byp5hxNGmNI8xdNzbSe8j+yXOkG9dWiNVvj2OsNDgpUtExsq1GpcXH aGtevpVhS0rGH7i9Eg/BIcw7TncusTWMhB/CPFrkzgGf/xIaQE1Lbv8gzRptQYN8UnQ0 Ty2jCfRXlTaWOeEXOEIEWy90tfPcTIo6oxVhP+CKEa7MmPYEzmD4HqV3TrrMJzVtJRDi ljdlWUVZjkSGfUgnBF3Mom2pVE1/FdYcOFvpDnQydIUycEpODmn9XAjKa1b7Gjw/Dl5G Zh+qbCXwJhh9dwWuBGWhaECi//sl2uT2HiZO4To+0TxT8GLG9TzC9AUt70MLyKZVtdSn SKNA== 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:mime-version:content-transfer-encoding; bh=NVrPaEyoEe4sNOMv0b3KHLKiO/GE1MKLycW7wjCPVFI=; b=aEQxSQ1PlZhhIRZH0bwhsUCP7amotTpjX3nC6JpgKUKSkuKqk8PiqA1AQQtWDMWJjX 0IgVQFNyPxf1rQRd5dDsN6VWjA/V0otC7QU8JcaQgkO86uCSRjJFxSWMoSCdGlV7e15x bsH8R/62d46eY3yTHNjq8w299xRJH80BjAcVB/AbmcFWOkKISKqIcreb8eqf0KosmHCr On08r5OEPKTyB3HKvlEb7xJp730Cx/JvXGkBuhXJWt/AZH1diKZDGcphgIU5NScuqaJ5 1lB+7d65KcOZMBKr3DvJfadV75jyQVbTsHEQiCAG1VZUegtnxBZ3ZhMsDHKryHMUDX27 vSqA== X-Gm-Message-State: APjAAAXHgJjIVBGlZdW/5+j2TO79jcETtKcDgi01uamvymsA1fOrCFLk 9JUBjUNi6lCJzWzaSofitzxp6qfROAU= X-Google-Smtp-Source: APXvYqz0fvUsXuYeYxC7QyMfcYPjSWkw/ek4ijhbJ0jd59O4AioPmg5IhF7s8HOtGb8WFz0pYWN8fg== X-Received: by 2002:a65:44ca:: with SMTP id g10mr16883607pgs.104.1573829117404; Fri, 15 Nov 2019 06:45:17 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:16 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 11/19] API: add support for SET_CONFIG Date: Fri, 15 Nov 2019 22:43:47 +0800 Message-Id: <20191115144355.975-12-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend the libgpiod API to support the setting line configuration using the GPIO GPIOHANDLE_SET_CONFIG_IOCTL uAPI ioctl. The core change is the addition of gpiod_line_set_config, which provides a low level wrapper around the ioctl. Additionally, higher level helper functions, gpiod_line_set_flags, gpiod_line_set_direction_input, and gpiod_line_set_direction_output provide slightly simplified APIs for common use cases. Bulk forms of all functions are also provided. Signed-off-by: Kent Gibson --- include/gpiod.h | 115 ++++++++++++++++++++++++++++ lib/core.c | 196 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 300 insertions(+), 11 deletions(-) diff --git a/include/gpiod.h b/include/gpiod.h index 159d745..4053fd2 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -1252,6 +1252,14 @@ void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) GPIOD_API; */ bool gpiod_line_is_requested(struct gpiod_line *line) GPIOD_API; +/** + * @brief Check if the calling user has ownership of this line for values, + * not events. + * @param line GPIO line object. + * @return True if given line was requested, false otherwise. + */ +bool gpiod_line_is_requested_values(struct gpiod_line *line) GPIOD_API; + /** * @brief Check if the calling user has neither requested ownership of this * line nor configured any event notifications. @@ -1311,6 +1319,113 @@ int gpiod_line_set_value(struct gpiod_line *line, int value) GPIOD_API; int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, const int *values) GPIOD_API; +/** + * @} + * + * @defgroup __line_config__ Setting line configuration + * @{ + */ + +/** + * @brief Update the configuration of a single GPIO line. + * @param line GPIO line object. + * @param direction Updated direction which may be one of + * GPIOD_LINE_REQUEST_DIRECTION_AS_IS, GPIOD_LINE_REQUEST_DIRECTION_INPUT, + * or GPIOD_LINE_REQUEST_DIRECTION_OUTPUT. + * @param flags Replacement flags. + * @param value The new output value for the line when direction is + * GPIOD_LINE_REQUEST_DIRECTION_OUTPUT. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + */ +int gpiod_line_set_config(struct gpiod_line *line, int direction, + int flags, int value) GPIOD_API; + +/** + * @brief Update the configuration of a set of GPIO lines. + * @param bulk Set of GPIO lines. + * @param direction Updated direction which may be one of + * GPIOD_LINE_REQUEST_DIRECTION_AS_IS, GPIOD_LINE_REQUEST_DIRECTION_INPUT, + * or GPIOD_LINE_REQUEST_DIRECTION_OUTPUT. + * @param flags Replacement flags. + * @param values An array holding line_bulk->num_lines new logical values + * for lines when direction is GPIOD_LINE_REQUEST_DIRECTION_OUTPUT. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + * + * If the lines were not previously requested together, the behavior is + * undefined. + */ +int gpiod_line_set_config_bulk(struct gpiod_line_bulk *bulk, + int direction, int flags, + const int *values) GPIOD_API; + + +/** + * @brief Update the configuration flags of a single GPIO line. + * @param line GPIO line object. + * @param flags Replacement flags. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + */ +int gpiod_line_set_flags(struct gpiod_line *line, int flags) GPIOD_API; + +/** + * @brief Update the configuration flags of a set of GPIO lines. + * @param bulk Set of GPIO lines. + * @param flags Replacement flags. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + * + * If the lines were not previously requested together, the behavior is + * undefined. + */ +int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk, + int flags) GPIOD_API; + +/** + * @brief Set the direction of a single GPIO line to input. + * @param line GPIO line object. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + */ +int gpiod_line_set_direction_input(struct gpiod_line *line) GPIOD_API; + +/** + * @brief Set the direction of a set of GPIO lines to input. + * @param bulk Set of GPIO lines. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + * + * If the lines were not previously requested together, the behavior is + * undefined. + */ +int gpiod_line_set_direction_bulk_input(struct gpiod_line_bulk *bulk + ) GPIOD_API; + +/** + * @brief Set the direction of a single GPIO line to output. + * @param line GPIO line object. + * @param value The logical value output on the line. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + */ +int gpiod_line_set_direction_output(struct gpiod_line *line, + int value) GPIOD_API; + +/** + * @brief Set the direction of a set of GPIO lines to output. + * @param bulk Set of GPIO lines. + * @values The logical value to output for each line. + * @return 0 is the operation succeeds. In case of an error this routine + * returns -1 and sets the last error number. + * + * If the lines were not previously requested together, the behavior is + * undefined. + */ +int gpiod_line_set_direction_bulk_output(struct gpiod_line_bulk *bulk, + const int *values) GPIOD_API; + /** * @} * diff --git a/lib/core.c b/lib/core.c index 9b7d88f..c42cda5 100644 --- a/lib/core.c +++ b/lib/core.c @@ -36,10 +36,13 @@ struct gpiod_line { unsigned int offset; int direction; int active_state; - __u32 flags; + int output_value; + __u32 lflags; + __u32 cflags; int state; bool needs_update; + bool as_is; struct gpiod_chip *chip; struct line_fd_handle *fd_handle; @@ -359,11 +362,11 @@ int gpiod_line_active_state(struct gpiod_line *line) int gpiod_line_bias(struct gpiod_line *line) { - if (line->flags & GPIOLINE_FLAG_BIAS_DISABLE) + if (line->lflags & GPIOLINE_FLAG_BIAS_DISABLE) return GPIOD_LINE_BIAS_DISABLE; - if (line->flags & GPIOLINE_FLAG_BIAS_PULL_UP) + if (line->lflags & GPIOLINE_FLAG_BIAS_PULL_UP) return GPIOD_LINE_BIAS_PULL_UP; - if (line->flags & GPIOLINE_FLAG_BIAS_PULL_DOWN) + if (line->lflags & GPIOLINE_FLAG_BIAS_PULL_DOWN) return GPIOD_LINE_BIAS_PULL_DOWN; return GPIOD_LINE_BIAS_AS_IS; @@ -371,17 +374,17 @@ int gpiod_line_bias(struct gpiod_line *line) bool gpiod_line_is_used(struct gpiod_line *line) { - return line->flags & GPIOLINE_FLAG_KERNEL; + return line->lflags & GPIOLINE_FLAG_KERNEL; } bool gpiod_line_is_open_drain(struct gpiod_line *line) { - return line->flags & GPIOLINE_FLAG_OPEN_DRAIN; + return line->lflags & GPIOLINE_FLAG_OPEN_DRAIN; } bool gpiod_line_is_open_source(struct gpiod_line *line) { - return line->flags & GPIOLINE_FLAG_OPEN_SOURCE; + return line->lflags & GPIOLINE_FLAG_OPEN_SOURCE; } bool gpiod_line_needs_update(struct gpiod_line *line) @@ -408,7 +411,7 @@ int gpiod_line_update(struct gpiod_line *line) ? GPIOD_LINE_ACTIVE_STATE_LOW : GPIOD_LINE_ACTIVE_STATE_HIGH; - line->flags = info.flags; + line->lflags = info.flags; strncpy(line->name, info.name, sizeof(line->name)); strncpy(line->consumer, info.consumer, sizeof(line->consumer)); @@ -457,6 +460,20 @@ static bool line_bulk_all_requested(struct gpiod_line_bulk *bulk) return true; } +static bool line_bulk_all_requested_values(struct gpiod_line_bulk *bulk) +{ + struct gpiod_line *line, **lineptr; + + gpiod_line_bulk_foreach_line(bulk, line, lineptr) { + if (!gpiod_line_is_requested_values(line)) { + errno = EPERM; + return false; + } + } + + return true; +} + static bool line_bulk_all_free(struct gpiod_line_bulk *bulk) { struct gpiod_line *line, **lineptr; @@ -471,6 +488,27 @@ static bool line_bulk_all_free(struct gpiod_line_bulk *bulk) return true; } +static bool line_request_direction_is_valid(int direction) +{ + if ((direction == GPIOD_LINE_REQUEST_DIRECTION_AS_IS) || + (direction == GPIOD_LINE_REQUEST_DIRECTION_INPUT) || + (direction == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT)) + return true; + + errno = EINVAL; + return false; +} + +static __u32 line_request_direction_to_gpio_handleflag(int direction) +{ + if (direction == GPIOD_LINE_REQUEST_DIRECTION_INPUT) + return GPIOHANDLE_REQUEST_INPUT; + if (direction == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT) + return GPIOHANDLE_REQUEST_OUTPUT; + + return 0; +} + static __u32 line_request_flag_to_gpio_handleflag(int flags) { int hflags = 0; @@ -495,7 +533,7 @@ static int line_request_values(struct gpiod_line_bulk *bulk, const struct gpiod_line_request_config *config, const int *default_vals) { - struct gpiod_line *line, **lineptr; + struct gpiod_line *line; struct line_fd_handle *line_fd; struct gpiohandle_request req; unsigned int i; @@ -524,7 +562,6 @@ static int line_request_values(struct gpiod_line_bulk *bulk, else if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT) req.flags |= GPIOHANDLE_REQUEST_OUTPUT; - gpiod_line_bulk_foreach_line_off(bulk, line, i) { req.lineoffsets[i] = gpiod_line_offset(line); if (config->request_type == @@ -548,8 +585,14 @@ static int line_request_values(struct gpiod_line_bulk *bulk, if (!line_fd) return -1; - gpiod_line_bulk_foreach_line(bulk, line, lineptr) { + gpiod_line_bulk_foreach_line_off(bulk, line, i) { line->state = LINE_REQUESTED_VALUES; + line->cflags = config->flags; + if (config->request_type == + GPIOD_LINE_REQUEST_DIRECTION_OUTPUT) + line->output_value = req.default_values[i]; + if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_AS_IS) + line->as_is = true; line_set_fd(line, line_fd); line_maybe_update(line); } @@ -590,6 +633,7 @@ static int line_request_event_single(struct gpiod_line *line, return -1; line->state = LINE_REQUESTED_EVENTS; + line->cflags = config->flags; line_set_fd(line, line_fd); line_maybe_update(line); @@ -688,6 +732,11 @@ bool gpiod_line_is_requested(struct gpiod_line *line) line->state == LINE_REQUESTED_EVENTS); } +bool gpiod_line_is_requested_values(struct gpiod_line *line) +{ + return (line->state == LINE_REQUESTED_VALUES); +} + bool gpiod_line_is_free(struct gpiod_line *line) { return line->state == LINE_FREE; @@ -766,9 +815,134 @@ int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, const int *values) if (rv < 0) return -1; + gpiod_line_bulk_foreach_line_off(bulk, line, i) + line->output_value = data.values[i]; + + return 0; +} + +int gpiod_line_set_config(struct gpiod_line *line, int direction, + int flags, int value) +{ + struct gpiod_line_bulk bulk; + + gpiod_line_bulk_init(&bulk); + gpiod_line_bulk_add(&bulk, line); + + return gpiod_line_set_config_bulk(&bulk, direction, flags, &value); +} + +int gpiod_line_set_config_bulk(struct gpiod_line_bulk *bulk, + int direction, int flags, + const int *values) +{ + struct gpiohandle_config hcfg; + struct gpiod_line *line; + unsigned int i; + int rv, fd; + bool as_is; + + if (!line_bulk_same_chip(bulk) || + !line_bulk_all_requested_values(bulk)) + return -1; + + if (!line_request_direction_is_valid(direction)) + return -1; + + memset(&hcfg, 0, sizeof(hcfg)); + + hcfg.flags = line_request_flag_to_gpio_handleflag(flags); + hcfg.flags |= line_request_direction_to_gpio_handleflag(direction); + if (direction == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT && values) { + for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) + hcfg.default_values[i] = (uint8_t)!!values[i]; + } + + line = gpiod_line_bulk_get_line(bulk, 0); + fd = line_get_fd(line); + + rv = ioctl(fd, GPIOHANDLE_SET_CONFIG_IOCTL, &hcfg); + if (rv < 0) + return -1; + + as_is = line->as_is && direction == GPIOD_LINE_REQUEST_DIRECTION_AS_IS; + gpiod_line_bulk_foreach_line_off(bulk, line, i) { + line->cflags = flags; + if (direction == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT) + line->output_value = hcfg.default_values[i]; + line->as_is = as_is; + line_maybe_update(line); + } return 0; } +int gpiod_line_set_flags(struct gpiod_line *line, int flags) +{ + struct gpiod_line_bulk bulk; + + gpiod_line_bulk_init(&bulk); + gpiod_line_bulk_add(&bulk, line); + + return gpiod_line_set_flags_bulk(&bulk, flags); +} + +int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk, int flags) +{ + struct gpiod_line *line; + int values[GPIOD_LINE_BULK_MAX_LINES]; + unsigned int i; + int direction; + + line = gpiod_line_bulk_get_line(bulk, 0); + if (line->as_is) { + errno = EPERM; + return -1; + } + if (line->direction == GPIOD_LINE_DIRECTION_OUTPUT) { + gpiod_line_bulk_foreach_line_off(bulk, line, i) { + values[i] = line->output_value; + } + direction = GPIOD_LINE_REQUEST_DIRECTION_OUTPUT; + } else + direction = GPIOD_LINE_REQUEST_DIRECTION_INPUT; + + return gpiod_line_set_config_bulk(bulk, direction, + flags, values); +} + +int gpiod_line_set_direction_input(struct gpiod_line *line) +{ + return gpiod_line_set_config(line, GPIOD_LINE_REQUEST_DIRECTION_INPUT, + line->cflags, 0); +} + +int gpiod_line_set_direction_bulk_input(struct gpiod_line_bulk *bulk) +{ + struct gpiod_line *line; + + line = gpiod_line_bulk_get_line(bulk, 0); + return gpiod_line_set_config_bulk(bulk, + GPIOD_LINE_REQUEST_DIRECTION_INPUT, + line->cflags, NULL); +} + +int gpiod_line_set_direction_output(struct gpiod_line *line, int value) +{ + return gpiod_line_set_config(line, GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, + line->cflags, value); +} + +int gpiod_line_set_direction_bulk_output(struct gpiod_line_bulk *bulk, + const int *values) +{ + struct gpiod_line *line; + + line = gpiod_line_bulk_get_line(bulk, 0); + return gpiod_line_set_config_bulk(bulk, + GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, + line->cflags, values); +} + int gpiod_line_event_wait(struct gpiod_line *line, const struct timespec *timeout) { From patchwork Fri Nov 15 14:43:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195688 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MzBKtwR9"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Ng4ySrz9sP6 for ; Sat, 16 Nov 2019 01:45:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727640AbfKOOpX (ORCPT ); Fri, 15 Nov 2019 09:45:23 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34352 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOpX (ORCPT ); Fri, 15 Nov 2019 09:45:23 -0500 Received: by mail-pl1-f193.google.com with SMTP id h13so4821996plr.1 for ; Fri, 15 Nov 2019 06:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dKqw8AqnZ4FydRAWSePLwNJGTiQsNXmFDlHLyyMMgLc=; b=MzBKtwR9R815dUOK4WK0FH3rn9NEgUpiLbiZQxmY0joFlbfkIQUcu4X+IEXhV9Km+Y 1p/sMtONzY3ZW4SyI7bDjNpCIErqUAmkGhifrlLNqwxgbHgQUKJ2HBljZajcwmdTv4ig IK2EoqJy8OiD3S4M1yMXXsAoaY0TqyoQCz6cgE6YnClrf/Bu8RihXIKZNMeaiJ2NIDSx vnSRvQnwUoL+GClGOlOnhc52NFXCbzWkcf67rJ9xGmT/nbQHYb9Jb1sbsTESW4bcYjX3 ApmdNTRaByV3BYPZhO8yAGm3MKzPkrGD5pcs5KGc1LvPb78k374DkPhu2e94HOII/DTt Ij6A== 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:mime-version:content-transfer-encoding; bh=dKqw8AqnZ4FydRAWSePLwNJGTiQsNXmFDlHLyyMMgLc=; b=d/jtT/QoBsLgGlQ2wtkUMGCfQuh7klvFOxcfxr9ihg05edM5yVBlVsx7/oNBz7PfRR cfxVLOYU9Fn3vQq2ZO+4rYzlKNxngZKkSBJ2+P5o0XILgmaiWPRoxgjnqFkzVDLJTGX/ ABDWl/suItOg9IjunDOY5mEss4JtIvbqf48I8srhNIAvrHTXhVFfgFNh7wQ9IB+0emqC R+qKM+qQ9fPOTcm/Sw5AynF/FXf3AXzQfkys5Af+q/hUryPEvav3nu/aHFlZ/7wVoLJ6 bzxCczl/2N8Pn9XflJMPsf0Qn1OgazpzmVirnj+YbdnR6YP+cJkShmOGNgARCz+Hb/uo 0ctA== X-Gm-Message-State: APjAAAW7I5cItXOJ+RVhduKl/nu4ZumnMM7/icKePejP/1/9IhdceVHd 8riZYzNnLiwZTSjMe2PrcIj/LyT47LU= X-Google-Smtp-Source: APXvYqxnAZo28UNF2yl6mOdhbBZQdVH9iMvnupyrL1i9uZmqPtNcuFgbkF2pkbuCjxdaqyxl4YSmtQ== X-Received: by 2002:a17:90a:2385:: with SMTP id g5mr20271571pje.117.1573829121403; Fri, 15 Nov 2019 06:45:21 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:20 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 12/19] tests: add tests for SET_CONFIG Date: Fri, 15 Nov 2019 22:43:48 +0800 Message-Id: <20191115144355.975-13-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend test coverage over the SET_CONFIG functions. Signed-off-by: Kent Gibson --- tests/tests-line.c | 371 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 370 insertions(+), 1 deletion(-) diff --git a/tests/tests-line.c b/tests/tests-line.c index b4bef1a..e74f90f 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -267,6 +267,7 @@ GPIOD_TEST_CASE(set_value, 0, { 8 }) ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0); g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); ret = gpiod_line_set_value(line, 1); g_assert_cmpint(ret, ==, 0); @@ -276,6 +277,352 @@ GPIOD_TEST_CASE(set_value, 0, { 8 }) g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); } +GPIOD_TEST_CASE(set_config_bulk_null_values, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line_bulk bulk = GPIOD_LINE_BULK_INITIALIZER; + struct gpiod_line *line0, *line1, *line2; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line0 = gpiod_chip_get_line(chip, 0); + line1 = gpiod_chip_get_line(chip, 1); + line2 = gpiod_chip_get_line(chip, 2); + + g_assert_nonnull(line0); + g_assert_nonnull(line1); + g_assert_nonnull(line2); + gpiod_test_return_if_failed(); + + gpiod_line_bulk_add(&bulk, line0); + gpiod_line_bulk_add(&bulk, line1); + gpiod_line_bulk_add(&bulk, line2); + + ret = gpiod_line_request_bulk_output(&bulk, GPIOD_TEST_CONSUMER, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_active_state(line0), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_line_active_state(line1), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_line_active_state(line2), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_config_bulk(&bulk, + GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, + GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW, NULL); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_active_state(line0), ==, + GPIOD_LINE_ACTIVE_STATE_LOW); + g_assert_cmpint(gpiod_line_active_state(line1), ==, + GPIOD_LINE_ACTIVE_STATE_LOW); + g_assert_cmpint(gpiod_line_active_state(line2), ==, + GPIOD_LINE_ACTIVE_STATE_LOW); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + ret = gpiod_line_set_config_bulk(&bulk, + GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, 0, NULL); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_active_state(line0), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_line_active_state(line1), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_line_active_state(line2), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); +} + +GPIOD_TEST_CASE(set_flags_active_state, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 2); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 1); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_active_state(line), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + ret = gpiod_line_set_flags(line, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_active_state(line), ==, + GPIOD_LINE_ACTIVE_STATE_LOW); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_flags(line, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_active_state(line), ==, + GPIOD_LINE_ACTIVE_STATE_HIGH); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); +} + +GPIOD_TEST_CASE(set_flags_bias, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 2); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS); + + ret = gpiod_line_set_flags(line, + GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_DISABLE); + + ret = gpiod_line_set_flags(line, + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_UP); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + ret = gpiod_line_set_flags(line, + GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_DOWN); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); +} + +GPIOD_TEST_CASE(set_flags_drive, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 2); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_is_open_drain(line), ==, false); + g_assert_cmpint(gpiod_line_is_open_source(line), ==, false); + + ret = gpiod_line_set_flags(line, + GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_is_open_drain(line), ==, true); + g_assert_cmpint(gpiod_line_is_open_source(line), ==, false); + + ret = gpiod_line_set_flags(line, + GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_is_open_drain(line), ==, false); + g_assert_cmpint(gpiod_line_is_open_source(line), ==, true); +} + +GPIOD_TEST_CASE(set_direction, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line *line; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 2); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_direction(line), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_direction_input(line); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_direction(line), ==, + GPIOD_LINE_DIRECTION_INPUT); + + ret = gpiod_line_set_direction_output(line, 1); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_direction(line), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); +} + +GPIOD_TEST_CASE(set_direction_bulk, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line_bulk bulk = GPIOD_LINE_BULK_INITIALIZER; + struct gpiod_line *line0, *line1, *line2; + int values[3]; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line0 = gpiod_chip_get_line(chip, 0); + line1 = gpiod_chip_get_line(chip, 1); + line2 = gpiod_chip_get_line(chip, 2); + + g_assert_nonnull(line0); + g_assert_nonnull(line1); + g_assert_nonnull(line2); + gpiod_test_return_if_failed(); + + gpiod_line_bulk_add(&bulk, line0); + gpiod_line_bulk_add(&bulk, line1); + gpiod_line_bulk_add(&bulk, line2); + + values[0] = 0; + values[1] = 1; + values[2] = 2; + + ret = gpiod_line_request_bulk_output(&bulk, + GPIOD_TEST_CONSUMER, values); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_direction(line0), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_line_direction(line1), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_line_direction(line2), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + ret = gpiod_line_set_direction_bulk_input(&bulk); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_direction(line0), ==, + GPIOD_LINE_DIRECTION_INPUT); + g_assert_cmpint(gpiod_line_direction(line1), ==, + GPIOD_LINE_DIRECTION_INPUT); + g_assert_cmpint(gpiod_line_direction(line2), ==, + GPIOD_LINE_DIRECTION_INPUT); + + values[0] = 2; + values[1] = 1; + values[2] = 0; + + ret = gpiod_line_set_direction_bulk_output(&bulk, values); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_direction(line0), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_line_direction(line1), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_line_direction(line2), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_direction_bulk_output(&bulk, NULL); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_line_direction(line0), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_line_direction(line1), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_line_direction(line2), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); +} + +GPIOD_TEST_CASE(output_value_caching, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line *line; + struct gpiod_line_bulk bulk; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line = gpiod_chip_get_line(chip, 2); + g_assert_nonnull(line); + gpiod_test_return_if_failed(); + + // check cached by request... + ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 1); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + // ...by checking cached value applied by set_flags + ret = gpiod_line_set_flags(line, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + // check cached by set_value + ret = gpiod_line_set_value(line, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_flags(line, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_value(line, 1); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + ret = gpiod_line_set_flags(line, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + // check cached by set_config + ret = gpiod_line_set_config(line, GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, + 0, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_flags(line, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + // check cached by set_value_bulk default + ret = gpiod_line_set_value(line, 1); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + gpiod_line_bulk_init(&bulk); + gpiod_line_bulk_add(&bulk, line); + ret = gpiod_line_set_value_bulk(&bulk, NULL); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_flags(line, 0); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); +} + + GPIOD_TEST_CASE(get_value_different_chips, 0, { 8, 8 }) { g_autoptr(gpiod_chip_struct) chipA = NULL; @@ -390,10 +737,11 @@ GPIOD_TEST_CASE(direction, 0, { 8 }) g_assert_nonnull(line); gpiod_test_return_if_failed(); - ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0); + ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 1); g_assert_cmpint(ret, ==, 0); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 5), ==, 1); gpiod_line_release(line); @@ -431,6 +779,27 @@ GPIOD_TEST_CASE(active_state, 0, { 8 }) g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_INPUT); + + gpiod_line_release(line); + + ret = gpiod_line_request_output_flags(line, GPIOD_TEST_CONSUMER, + GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW, 0); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(gpiod_line_direction(line), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 5), ==, 1); + + gpiod_line_release(line); + + ret = gpiod_line_request_output_flags(line, + GPIOD_TEST_CONSUMER, 0, 0); + g_assert_cmpint(ret, ==, 0); + + g_assert_cmpint(gpiod_line_direction(line), ==, + GPIOD_LINE_DIRECTION_OUTPUT); + g_assert_cmpint(gpiod_test_chip_get_value(0, 5), ==, 0); + } GPIOD_TEST_CASE(misc_flags, 0, { 8 }) From patchwork Fri Nov 15 14:43:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YjFc3Jg3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Nl0tM0z9sPF for ; Sat, 16 Nov 2019 01:45:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727526AbfKOOp0 (ORCPT ); Fri, 15 Nov 2019 09:45:26 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45972 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOp0 (ORCPT ); Fri, 15 Nov 2019 09:45:26 -0500 Received: by mail-pl1-f196.google.com with SMTP id w7so4791401plz.12 for ; Fri, 15 Nov 2019 06:45:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bfofL+PiRWgUcw39HkEVa/wtJpUahJncO0e6xxYnPIQ=; b=YjFc3Jg32GQPpYmcifYFqg9i3ISf9OjGt4+ezZdS2/tnjUyklxqhLxxs5ee6r4U8Br gNpYJDFtAqZQsLzXihlUOjQ/LSshwMOqniTU3F4te19eFf1STwLFsDb+ffFzOQJ9CWVm pdMfTEb30pyd/XTwvTvMU/OMzWNpUxhAUgMTPT785ptnPiGe+KfreimRXQ4NxHajmDhk 3UUBsMPN2gm3qJMRkIUy4Ivv3/OHQCgRjU7lJ3x6gpetEQiqn4NCGt2ICSQrjbtyL2/Z u3ywctaKoYMbvY4btVentwRNtA1xrRywiOZ/meU0yMW5Vbx3moMrWj7xUwolunzslOwc u8VQ== 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:mime-version:content-transfer-encoding; bh=bfofL+PiRWgUcw39HkEVa/wtJpUahJncO0e6xxYnPIQ=; b=WJ69vjlwAOHcGUeZ9U8LYSS4cXEBe4eCPtuditOM/ajkcnlDLic3/8IejAriK1qcOg QTwoOGEJoxXfAsLlWGGffcHSNmh/NoOIuldaSqAIQt9Zia9YwwVGMnizhg7M4542Qo/U a012iLAbrJTa6ige/YQtyu3TRNTgbTVj5zIA9j9jfv6qwn00L2qDTcG5RCDb8RTHGp8u KFz3gWJHaIA0xMv/Vkt3Tdqu0Cq47hrF6EzI52g4/2A/9EZBDh95TAndEti5Cj91a5PW 0XZeRr6xQJB0ATZS+wXhQnCPh5DOnRb1xiA+Xs3e7RaASt1fMjMsWB2hcJmZwTXweug0 5XQQ== X-Gm-Message-State: APjAAAU5oEb2qqaDE7AMZKkUuuyUdvgJMHWsKKUkABAPwpD/sV0pz3fM wnsOa9AI9+omcTdHNr+L/9U3Sl9MwCc= X-Google-Smtp-Source: APXvYqwkCMqd9/iyEOgmlY+2H/71VYZiBx0n8n30N417N+mZP7dw8O+NQnO2iFREb/ZwtQSFR6DmUQ== X-Received: by 2002:a17:902:b582:: with SMTP id a2mr15615123pls.103.1573829125479; Fri, 15 Nov 2019 06:45:25 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:25 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 13/19] core: allow gpiod_line_set_value_bulk to accept null values Date: Fri, 15 Nov 2019 22:43:49 +0800 Message-Id: <20191115144355.975-14-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Change gpiod_line_set_value_bulk to interpret a NULL values pointer as an array of zero, as per gpiod_line_request_bulk, gpiod_line_set_config_bulk, and gpiod_line_set_direction_bulk_output. The old behaviour was to segfault. Signed-off-by: Kent Gibson --- lib/core.c | 5 +++-- tests/tests-line.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/core.c b/lib/core.c index c42cda5..2e54def 100644 --- a/lib/core.c +++ b/lib/core.c @@ -805,8 +805,9 @@ int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, const int *values) memset(&data, 0, sizeof(data)); - for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) - data.values[i] = (uint8_t)!!values[i]; + if (values) + for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) + data.values[i] = (uint8_t)!!values[i]; line = gpiod_line_bulk_get_line(bulk, 0); fd = line_get_fd(line); diff --git a/tests/tests-line.c b/tests/tests-line.c index e74f90f..7d45603 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -277,6 +277,59 @@ GPIOD_TEST_CASE(set_value, 0, { 8 }) g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); } +GPIOD_TEST_CASE(set_value_bulk, 0, { 8 }) +{ + g_autoptr(gpiod_chip_struct) chip = NULL; + struct gpiod_line_bulk bulk = GPIOD_LINE_BULK_INITIALIZER; + struct gpiod_line *line0, *line1, *line2; + int values[3]; + gint ret; + + chip = gpiod_chip_open(gpiod_test_chip_path(0)); + g_assert_nonnull(chip); + gpiod_test_return_if_failed(); + + line0 = gpiod_chip_get_line(chip, 0); + line1 = gpiod_chip_get_line(chip, 1); + line2 = gpiod_chip_get_line(chip, 2); + + g_assert_nonnull(line0); + g_assert_nonnull(line1); + g_assert_nonnull(line2); + gpiod_test_return_if_failed(); + + gpiod_line_bulk_add(&bulk, line0); + gpiod_line_bulk_add(&bulk, line1); + gpiod_line_bulk_add(&bulk, line2); + + values[0] = 0; + values[1] = 1; + values[2] = 2; + + ret = gpiod_line_request_bulk_output(&bulk, + GPIOD_TEST_CONSUMER, values); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); + + values[0] = 2; + values[1] = 1; + values[2] = 0; + + ret = gpiod_line_set_value_bulk(&bulk, values); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 1); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); + + ret = gpiod_line_set_value_bulk(&bulk, NULL); + g_assert_cmpint(ret, ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0); + g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); +} + GPIOD_TEST_CASE(set_config_bulk_null_values, 0, { 8 }) { g_autoptr(gpiod_chip_struct) chip = NULL; From patchwork Fri Nov 15 14:43:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195690 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UecdGX1J"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Nq5VQTz9sP6 for ; Sat, 16 Nov 2019 01:45:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727539AbfKOOpb (ORCPT ); Fri, 15 Nov 2019 09:45:31 -0500 Received: from mail-pf1-f176.google.com ([209.85.210.176]:46855 "EHLO mail-pf1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbfKOOpb (ORCPT ); Fri, 15 Nov 2019 09:45:31 -0500 Received: by mail-pf1-f176.google.com with SMTP id 193so6756284pfc.13 for ; Fri, 15 Nov 2019 06:45:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RWuitDkia9SsUvX7hGwdFBd0vFJESPfawb8pD7EX6D8=; b=UecdGX1J0WslOGFqIlDFF/QfZLIFWFDsY/iW13P1o4rTH3SLf4PPO9Tnf22vzgoBUQ d2p99jrfYD9u/1qv/9IElCf2+jHVxQTVXht7xHKaefzf69pqze7x8zIbVlpdIU+AvcLi guYia/fxoV54B1Bm38hb4CpTpX+FXGr8WOgWTgdjbjQ1m9lRAbMQ2Ky469iVRj54rr/Y trHhwPHpVkFBjLQemFu95OpMK2kaZnG3WvhFC2X6YLq+0wF/PCWPb8Hhly7ExU3w2++O N0/PHZl3skjupCvpp9MaCiiKXqkdyvZrUInmmzp+c/VoxS3V0okwLrIOuGb/0QCF1q2y pnTA== 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:mime-version:content-transfer-encoding; bh=RWuitDkia9SsUvX7hGwdFBd0vFJESPfawb8pD7EX6D8=; b=XXZPrbEAkrdDyBcNWAN0SMij/PWeE9kFAIYdcgxHLtYg0IYNlV31yUOrQ5pgbIQvZH HVu7oAQyzJcIBfT8K35tsmLarCXEVsQMGNIOk2GTEHQtuBeLXQoQN+ln7o5HunZcqLqR fr7aeqfjG+GckvD8uGkZwVLFB9CJF3QRT74gsq0XBezkTBcEBCBT66OpF0/y5Y1jQAPK DHbhUi8CPAHBZSZ9p/+htqbBc0t0o6Jx6GM5lxq9abVFLTdbxudG75k90/s3Q2Le+rRt 6ZI5dIUduh3/NRzBXqr1wqQNpnxQ6HLDtfuktLdzJHnckdtG56blQLPHP0rafk5eU7RQ e68g== X-Gm-Message-State: APjAAAXPlQzfrlGJUuGvn3QWWgSJcPWLViFNHMYK9TPDzzHdulPh+sUD yXK0pajNTz8DJvWHK4g5x1kwmx6RHyo= X-Google-Smtp-Source: APXvYqzMRxCxm1+Ce/7AOXZXXu/U7u4LkfOSszDVrQEQNpOmLTLX8sKrJs1VgUFXlV/9JhUG2/OWiQ== X-Received: by 2002:a63:5d26:: with SMTP id r38mr17195247pgb.48.1573829129488; Fri, 15 Nov 2019 06:45:29 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:29 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 14/19] bindings: cxx: add support for SET_CONFIG Date: Fri, 15 Nov 2019 22:43:50 +0800 Message-Id: <20191115144355.975-15-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add methods to support setting line configuration. Signed-off-by: Kent Gibson --- bindings/cxx/gpiod.hpp | 55 +++++++++++++++++++++++++ bindings/cxx/line.cpp | 37 +++++++++++++++++ bindings/cxx/line_bulk.cpp | 83 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp index 2b1a6ab..dcae431 100644 --- a/bindings/cxx/gpiod.hpp +++ b/bindings/cxx/gpiod.hpp @@ -381,6 +381,32 @@ public: */ GPIOD_API void set_value(int val) const; + /** + * @brief Set configuration of this line. + * @param direction New direction. + * @param flags Replacement flags. + * @param value New value (0 or 1) - only matters for OUTPUT direction. + */ + GPIOD_API void set_config(int direction, ::std::bitset<32> flags, + int value = 0) const; + + /** + * @brief Set configuration flags of this line. + * @param flags Replacement flags. + */ + GPIOD_API void set_flags(::std::bitset<32> flags) const; + + /** + * @brief Change the direction this line to input. + */ + GPIOD_API void set_direction_input() const; + + /** + * @brief Change the direction this lines to output. + * @param value New value (0 or 1). + */ + GPIOD_API void set_direction_output(int value = 0) const; + /** * @brief Wait for an event on this line. * @param timeout Time to wait before returning if no event occurred. @@ -648,6 +674,35 @@ public: */ GPIOD_API void set_values(const ::std::vector& values) const; + /** + * @brief Set configuration of all lines held by this object. + * @param direction New direction. + * @param flags Replacement flags. + * @param values Vector of values to set. Must be the same size as the + * number of lines held by this line_bulk. + * Only relevant for output direction requests. + */ + GPIOD_API void set_config(int direction, ::std::bitset<32> flags, + const ::std::vector values = std::vector()) const; + + /** + * @brief Set configuration flags of all lines held by this object. + * @param flags Replacement flags. + */ + GPIOD_API void set_flags(::std::bitset<32> flags) const; + + /** + * @brief Change the direction all lines held by this object to input. + */ + GPIOD_API void set_direction_input() const; + + /** + * @brief Change the direction all lines held by this object to output. + * @param values Vector of values to set. Must be the same size as the + * number of lines held by this line_bulk. + */ + GPIOD_API void set_direction_output(const ::std::vector& values) const; + /** * @brief Poll the set of lines for line events. * @param timeout Number of nanoseconds to wait before returning an diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp index dd6bb6a..a688b5d 100644 --- a/bindings/cxx/line.cpp +++ b/bindings/cxx/line.cpp @@ -158,6 +158,43 @@ void line::set_value(int val) const bulk.set_values({ val }); } +void line::set_config(int direction, ::std::bitset<32> flags, + int value) const +{ + this->throw_if_null(); + + line_bulk bulk({ *this }); + + bulk.set_config(direction, flags, { value }); +} + +void line::set_flags(::std::bitset<32> flags) const +{ + this->throw_if_null(); + + line_bulk bulk({ *this }); + + bulk.set_flags(flags); +} + +void line::set_direction_input() const +{ + this->throw_if_null(); + + line_bulk bulk({ *this }); + + bulk.set_direction_input(); +} + +void line::set_direction_output(int value) const +{ + this->throw_if_null(); + + line_bulk bulk({ *this }); + + bulk.set_direction_output({ value }); +} + bool line::event_wait(const ::std::chrono::nanoseconds& timeout) const { this->throw_if_null(); diff --git a/bindings/cxx/line_bulk.cpp b/bindings/cxx/line_bulk.cpp index 5f1cac4..6f7d161 100644 --- a/bindings/cxx/line_bulk.cpp +++ b/bindings/cxx/line_bulk.cpp @@ -176,6 +176,89 @@ void line_bulk::set_values(const ::std::vector& values) const "error setting GPIO line values"); } +void line_bulk::set_config(int direction, ::std::bitset<32> flags, + const ::std::vector values) const +{ + this->throw_if_empty(); + + if (!values.empty() && this->_m_bulk.size() != values.size()) + throw ::std::invalid_argument("the number of default values must correspond with the number of lines"); + + ::gpiod_line_bulk bulk; + int rv, gflags; + + gflags = 0; + + for (auto& it: reqflag_mapping) { + if ((it.first & flags).to_ulong()) + gflags |= it.second; + } + + this->to_line_bulk(::std::addressof(bulk)); + + rv = ::gpiod_line_set_config_bulk(::std::addressof(bulk), direction, + gflags, values.data()); + if (rv) + throw ::std::system_error(errno, ::std::system_category(), + "error setting GPIO line config"); +} + +void line_bulk::set_flags(::std::bitset<32> flags) const +{ + this->throw_if_empty(); + + ::gpiod_line_bulk bulk; + int rv, gflags; + + this->to_line_bulk(::std::addressof(bulk)); + + gflags = 0; + + for (auto& it: reqflag_mapping) { + if ((it.first & flags).to_ulong()) + gflags |= it.second; + } + + rv = ::gpiod_line_set_flags_bulk(::std::addressof(bulk), gflags); + if (rv) + throw ::std::system_error(errno, ::std::system_category(), + "error setting GPIO line flags"); +} + +void line_bulk::set_direction_input() const +{ + this->throw_if_empty(); + + ::gpiod_line_bulk bulk; + int rv; + + this->to_line_bulk(::std::addressof(bulk)); + + rv = ::gpiod_line_set_direction_bulk_input(::std::addressof(bulk)); + if (rv) + throw ::std::system_error(errno, ::std::system_category(), + "error setting GPIO line direction to input"); +} + +void line_bulk::set_direction_output(const ::std::vector& values) const +{ + this->throw_if_empty(); + + if (values.size() != this->_m_bulk.size()) + throw ::std::invalid_argument("the size of values array must correspond with the number of lines"); + + ::gpiod_line_bulk bulk; + int rv; + + this->to_line_bulk(::std::addressof(bulk)); + + rv = ::gpiod_line_set_direction_bulk_output(::std::addressof(bulk), + values.data()); + if (rv) + throw ::std::system_error(errno, ::std::system_category(), + "error setting GPIO line direction to output"); +} + line_bulk line_bulk::event_wait(const ::std::chrono::nanoseconds& timeout) const { this->throw_if_empty(); From patchwork Fri Nov 15 14:43:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195691 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sFrvKX37"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Nw297Wz9sP6 for ; Sat, 16 Nov 2019 01:45:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727555AbfKOOpg (ORCPT ); Fri, 15 Nov 2019 09:45:36 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43082 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbfKOOpf (ORCPT ); Fri, 15 Nov 2019 09:45:35 -0500 Received: by mail-pg1-f195.google.com with SMTP id l24so6098126pgh.10 for ; Fri, 15 Nov 2019 06:45:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gk/j1mfXbfzocBq862+4vuKUi80sU4iTCYMixwTbe6E=; b=sFrvKX37mYhb81wrKODxDJEwemVrgSExPToXTUB+s9fDiod/1LpKlw0RmXwQd1uNgZ o+8oHf1YDTgzwpRDOjoFnGVf6E+QnwlnGC1t9hwl7GQarxFINXp0RU0lv2dUjILpcfnN 4QLC4DJPmzyPOmlL/plDUNE/5nltEIVDnFpAlBBivyKF6FX5SxLhsXHIT0Kx9Bd9Ck/i NrPDdvqZSFQ398s59oYAAA19wAMDe2WzRGkdzSMPfhItiWRzhHRmHIHDwf0kTiaZjh+Y 4DCTJUuJrd/ExBqua+PzztjvgKwgWYzXwcYLciqketNaavsHqPH3d8O3dvDekl80erht PI9A== 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:mime-version:content-transfer-encoding; bh=Gk/j1mfXbfzocBq862+4vuKUi80sU4iTCYMixwTbe6E=; b=Wc5BLFM5iIsXW9oD8FqOiyur7pps3FjsM83ImYX9S/n3YXyAK6xLDWUYnM6BjFsr+H RPFyIAcMIhemBu4JFNvWCZEWpwnv9/YUnYqIT0EfF243grKwZ2GqbXDN1Gc+C//Cnnbw 6LukFJVaJT2hhgXf0Ihxn2AsA0y6K0v3e6ytY+eb4atF05ZfIxjjxQjTrm4u0dvBtpEb 61eJPzyL1eXdQB46NcyFPcoePw9/gA7Mc17sSwZ3X98s2mkKa7JPL/g1PLQdaKNzQCdf //vSJW8TsJ7n1cQTBokCU/fpTkDI3wJE0caJ0gPTZxXjbE3JNYs9/laPUmrRDPyxD0CX cRbw== X-Gm-Message-State: APjAAAXuFhlxDz9wDzrnRyNag6+eepi+zgR+kNJr/po6r0OfGMpvV/P3 0mk+o7MuACQ7G4tBYGP2xBh+uO24lHc= X-Google-Smtp-Source: APXvYqxNVuXvfssicDxRDzIEUKc7rmLhXx4JOT77dn5k35pIGiYQJcXuPQU1T2jEUUklK386XBt41A== X-Received: by 2002:a63:3f04:: with SMTP id m4mr16814740pga.234.1573829133222; Fri, 15 Nov 2019 06:45:33 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:32 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 15/19] bindings: cxx: tests: add tests for SET_CONFIG methods Date: Fri, 15 Nov 2019 22:43:51 +0800 Message-Id: <20191115144355.975-16-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend test coverage over set_config, set_flags, set_direction_input, and set_direction_output methods. Signed-off-by: Kent Gibson --- bindings/cxx/tests/tests-line.cpp | 128 ++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/bindings/cxx/tests/tests-line.cpp b/bindings/cxx/tests/tests-line.cpp index ef314b9..f5b829d 100644 --- a/bindings/cxx/tests/tests-line.cpp +++ b/bindings/cxx/tests/tests-line.cpp @@ -324,6 +324,134 @@ TEST_CASE("Line values can be set and read", "[line]") } } +TEST_CASE("Line can be reconfigured", "[line]") +{ + mockup::probe_guard mockup_chips({ 8 }); + ::gpiod::chip chip(mockup::instance().chip_name(0)); + ::gpiod::line_request config; + + config.consumer = consumer.c_str(); + + SECTION("set config (single line, active-state)") + { + auto line = chip.get_line(3); + config.request_type = ::gpiod::line_request::DIRECTION_INPUT; + config.flags = 0; + line.request(config); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); + + line.set_config(::gpiod::line_request::DIRECTION_OUTPUT, + ::gpiod::line_request::FLAG_ACTIVE_LOW,1); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 0); + line.set_value(0); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 1); + + line.set_config(::gpiod::line_request::DIRECTION_OUTPUT, 0); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 0); + line.set_value(1); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 1); + } + + SECTION("set flags (single line, active-state)") + { + auto line = chip.get_line(3); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = 0; + line.request(config,1); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 1); + + line.set_flags(::gpiod::line_request::FLAG_ACTIVE_LOW); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 0); + + line.set_flags(0); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 1); + } + + SECTION("set flags (single line, drive)") + { + auto line = chip.get_line(3); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = 0; + line.request(config); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + + line.set_flags(::gpiod::line_request::FLAG_OPEN_DRAIN); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + + line.set_flags(::gpiod::line_request::FLAG_OPEN_SOURCE); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE(line.is_open_source()); + + line.set_flags(0); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + } + + SECTION("set flags (single line, bias)") + { + auto line = chip.get_line(3); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = 0; + line.request(config); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + + line.set_flags(::gpiod::line_request::FLAG_OPEN_DRAIN); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + + line.set_flags(::gpiod::line_request::FLAG_OPEN_SOURCE); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE(line.is_open_source()); + + line.set_flags(0); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE_FALSE(line.is_open_drain()); + REQUIRE_FALSE(line.is_open_source()); + } + + SECTION("set direction input (single line)") + { + auto line = chip.get_line(3); + config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT; + config.flags = 0; + line.request(config); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + line.set_direction_input(); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT); + } + + SECTION("set direction output (single line)") + { + auto line = chip.get_line(3); + config.request_type = ::gpiod::line_request::DIRECTION_INPUT; + config.flags = 0; + line.request(config); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT); + line.set_direction_output(1); + REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT); + REQUIRE(mockup::instance().chip_get_value(0, 3) == 1); + } +} + TEST_CASE("Exported line can be released", "[line]") { mockup::probe_guard mockup_chips({ 8 }); From patchwork Fri Nov 15 14:43:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WJaCdyYY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1Nz67JRz9sP6 for ; Sat, 16 Nov 2019 01:45:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbfKOOpj (ORCPT ); Fri, 15 Nov 2019 09:45:39 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33128 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbfKOOpj (ORCPT ); Fri, 15 Nov 2019 09:45:39 -0500 Received: by mail-pg1-f193.google.com with SMTP id h27so6138581pgn.0 for ; Fri, 15 Nov 2019 06:45:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yaaR9J54cdtTXyj4VzVmmFvTKs3522TV2tnIVWcVMGE=; b=WJaCdyYYf9cOGUVsdB/QZ8O+NAyR4UJlNtYALDcWtPBFCeB/6K/fZCdsugmeReeyNx Nd0qfjQ/cLtQRym+/gA5NmsdCpqfPB1bZfQbvzS8ofrfTQ6nYsOFNAGSRti7cYA5+dWs le7hpWWUqCHxLYpORaQ+882yzevFVF1RmrtMr29wpG/wU7GYPLqH1d3N/dEVbmLs2MQQ ocv5lDdZE9ThhsBxomxyTqS2NONU26kU1Ax3xrD/aFdOermBETVzf9RSU9fUDzI+9Kku CS2PHrDXGpx229iYvy3R2m6YfW9ILA1ItSuhR/z1iexmnRMYZMNhzAwPJSYZauXFroFe k6Xg== 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:mime-version:content-transfer-encoding; bh=yaaR9J54cdtTXyj4VzVmmFvTKs3522TV2tnIVWcVMGE=; b=GVvLxR8KOsQsb2dvz2EfuV4cHkmv3pq4o6eTgRvPkBmw7uXYLvQn9x4GMCbM/RcyZN rp27lCeYkyzYo0OXWi3/W7O7QKBgKZhrb1AUzHe8mgs4PVaKrHlXqH+N+fNmT4NKirws POlU2nhL4cp7fTt36Kt99NmYPk6vq3gkj6mSO0FhbSyY/hSlZAgDN+rNfeUKgSJxDOVr FmKS6ZdVVRESSQL7+EWoM7GdDIOAmQ2XEpmMpWvX0dn0S7aK6X8jfiHTpoxuBh2lnNxM zMOlyrR7p07xaJfs3sWnTzS591baKCmmbOYiIct3DY9kXE5F8RXdet2g6wGv6FcplQCA GxQg== X-Gm-Message-State: APjAAAWu4EPtRGaawa1eMnI5qErG68+USR/16WuV0mkRARHiRQa8gDge vLFModtvNi7qOxS7KEGl2j+SOByn6ls= X-Google-Smtp-Source: APXvYqwQ9HmRZgIc2JLSm0gCu+LsTwisQF66ISqNjw8jtTHeJEnjW2elp2my91c53c7ydmbgoZmgfQ== X-Received: by 2002:a63:dc45:: with SMTP id f5mr14192882pgj.250.1573829137151; Fri, 15 Nov 2019 06:45:37 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:36 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 16/19] bindings: python: add support for SET_CONFIG Date: Fri, 15 Nov 2019 22:43:52 +0800 Message-Id: <20191115144355.975-17-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add methods to support setting line configuration. Signed-off-by: Kent Gibson --- bindings/python/gpiodmodule.c | 381 +++++++++++++++++++++++++++++++++- 1 file changed, 379 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index de8d6d1..4949b14 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -585,14 +585,149 @@ static PyObject *gpiod_Line_set_value(gpiod_LineObject *self, PyObject *args) if (!bulk_obj) return NULL; - vals = Py_BuildValue("((O))", val); + vals = Py_BuildValue("(O)", val); if (!vals) { Py_DECREF(bulk_obj); return NULL; } ret = PyObject_CallMethod((PyObject *)bulk_obj, - "set_values", "O", vals); + "set_values", "(O)", vals); + Py_DECREF(bulk_obj); + Py_DECREF(vals); + + return ret; +} + +PyDoc_STRVAR(gpiod_Line_set_config_doc, +"set_config(direction,flags,value) -> None\n" +"\n" +"Set the configuration of this GPIO line.\n" +"\n" +" direction\n" +" New direction (integer)\n" +" flags\n" +" New flags (integer)\n" +" value\n" +" New value (integer)"); + +static PyObject *gpiod_Line_set_config(gpiod_LineObject *self, PyObject *args) +{ + gpiod_LineBulkObject *bulk_obj; + PyObject *dirn, *flags, *val, *vals, *ret; + int rv; + + val = NULL; + rv = PyArg_ParseTuple(args, "OO|O", &dirn, &flags, &val); + if (!rv) + return NULL; + + bulk_obj = gpiod_LineToLineBulk(self); + if (!bulk_obj) + return NULL; + + if (val) { + vals = Py_BuildValue("(O)", val); + if (!vals) { + Py_DECREF(bulk_obj); + return NULL; + } + ret = PyObject_CallMethod((PyObject *)bulk_obj, + "set_config", "OO(O)", dirn, flags, vals); + Py_DECREF(vals); + } else + ret = PyObject_CallMethod((PyObject *)bulk_obj, + "set_config", "OO", dirn, flags); + + Py_DECREF(bulk_obj); + + return ret; +} + +PyDoc_STRVAR(gpiod_Line_set_flags_doc, +"set_flags(flags) -> None\n" +"\n" +"Set the flags of this GPIO line.\n" +"\n" +" flags\n" +" New flags (integer)"); + +static PyObject *gpiod_Line_set_flags(gpiod_LineObject *self, PyObject *args) +{ + gpiod_LineBulkObject *bulk_obj; + PyObject *ret; + + bulk_obj = gpiod_LineToLineBulk(self); + if (!bulk_obj) + return NULL; + + ret = PyObject_CallMethod((PyObject *)bulk_obj, + "set_flags", "O", args); + Py_DECREF(bulk_obj); + + return ret; +} + +PyDoc_STRVAR(gpiod_Line_set_direction_input_doc, +"set_direction_input() -> None\n" +"\n" +"Set the direction of this GPIO line to input.\n"); + +static PyObject *gpiod_Line_set_direction_input(gpiod_LineObject *self, + PyObject *Py_UNUSED(ignored)) +{ + gpiod_LineBulkObject *bulk_obj; + PyObject *ret; + + bulk_obj = gpiod_LineToLineBulk(self); + if (!bulk_obj) + return NULL; + + ret = PyObject_CallMethod((PyObject *)bulk_obj, + "set_direction_input", ""); + Py_DECREF(bulk_obj); + + return ret; +} + +PyDoc_STRVAR(gpiod_Line_set_direction_output_doc, +"set_direction_output(value) -> None\n" +"\n" +"Set the direction of this GPIO line to output.\n" +"\n" +" value\n" +" New value (integer)"); + +static PyObject *gpiod_Line_set_direction_output(gpiod_LineObject *self, + PyObject *args) +{ + gpiod_LineBulkObject *bulk_obj; + PyObject *val, *vals, *ret; + int rv; + const char *fmt; + + val = NULL; + rv = PyArg_ParseTuple(args, "|O", &val); + if (!rv) + return NULL; + + if (val) { + fmt = "(O)"; + vals = Py_BuildValue(fmt, val); + } else { + vals = Py_BuildValue("()"); + fmt = "O"; // pass empty args to bulk + } + if (!vals) + return NULL; + + bulk_obj = gpiod_LineToLineBulk(self); + if (!bulk_obj) + return NULL; + + ret = PyObject_CallMethod((PyObject *)bulk_obj, + "set_direction_output", fmt, vals); + Py_DECREF(bulk_obj); Py_DECREF(vals); @@ -838,6 +973,30 @@ static PyMethodDef gpiod_Line_methods[] = { .ml_flags = METH_VARARGS, .ml_doc = gpiod_Line_set_value_doc, }, + { + .ml_name = "set_config", + .ml_meth = (PyCFunction)gpiod_Line_set_config, + .ml_flags = METH_VARARGS, + .ml_doc = gpiod_Line_set_config_doc, + }, + { + .ml_name = "set_flags", + .ml_meth = (PyCFunction)gpiod_Line_set_flags, + .ml_flags = METH_VARARGS, + .ml_doc = gpiod_Line_set_flags_doc, + }, + { + .ml_name = "set_direction_input", + .ml_meth = (PyCFunction)gpiod_Line_set_direction_input, + .ml_flags = METH_NOARGS, + .ml_doc = gpiod_Line_set_direction_input_doc, + }, + { + .ml_name = "set_direction_output", + .ml_meth = (PyCFunction)gpiod_Line_set_direction_output, + .ml_flags = METH_VARARGS, + .ml_doc = gpiod_Line_set_direction_output_doc, + }, { .ml_name = "release", .ml_meth = (PyCFunction)gpiod_Line_release, @@ -1283,6 +1442,200 @@ static PyObject *gpiod_LineBulk_set_values(gpiod_LineBulkObject *self, Py_RETURN_NONE; } +static int convert_values(PyObject *src, int *dst, Py_ssize_t n) +{ + int val; + Py_ssize_t num_vals, i; + PyObject *iter, *next; + + num_vals = PyObject_Size(src); + if (num_vals != n) { + PyErr_SetString(PyExc_TypeError, + "Number of values must correspond to the number of lines"); + return -1; + } + iter = PyObject_GetIter(src); + if (!iter) + return -1; + for (i = 0;; i++) { + next = PyIter_Next(iter); + if (!next) { + Py_DECREF(iter); + break; + } + val = PyLong_AsLong(next); + Py_DECREF(next); + if (PyErr_Occurred()) { + Py_DECREF(iter); + return -1; + } + dst[i] = (int)val; + } + return 0; +} + +PyDoc_STRVAR(gpiod_LineBulk_set_config_doc, +"set_config(direction,flags,values) -> None\n" +"\n" +"Set the configuration of all the lines held by this LineBulk object.\n" +"\n" +" direction\n" +" New direction (integer)\n" +" flags\n" +" New flags (integer)\n" +" values\n" +" List of values (integers) to set when direction is output.\n" +"\n" +"The number of values in the list passed as argument must be the same as\n" +"the number of lines held by this gpiod.LineBulk object. The index of each\n" +"value corresponds to the index of each line in the object.\n"); + +static PyObject *gpiod_LineBulk_set_config(gpiod_LineBulkObject *self, + PyObject *args) +{ + int rv, vals[GPIOD_LINE_BULK_MAX_LINES]; + PyObject *val_list; + struct gpiod_line_bulk bulk; + const int *valp; + int dirn, flags; + + if (gpiod_LineBulkOwnerIsClosed(self)) + return NULL; + + gpiod_LineBulkObjToCLineBulk(self, &bulk); + + val_list = NULL; + rv = PyArg_ParseTuple(args, "ii|(O)", &dirn, &flags, &val_list); + if (!rv) + return NULL; + + if (val_list == NULL) + valp = NULL; + else { + memset(vals, 0, sizeof(vals)); + rv = convert_values(val_list, vals, self->num_lines); + if (rv) + return NULL; + valp = vals; + } + + Py_BEGIN_ALLOW_THREADS; + rv = gpiod_line_set_config_bulk(&bulk, dirn, flags, valp); + Py_END_ALLOW_THREADS; + if (rv) + return PyErr_SetFromErrno(PyExc_OSError); + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(gpiod_LineBulk_set_flags_doc, +"set_flags(flags) -> None\n" +"\n" +"Set the flags of all the lines held by this LineBulk object.\n" +"\n" +" flags\n" +" New flags (integer)"); + +static PyObject *gpiod_LineBulk_set_flags(gpiod_LineBulkObject *self, + PyObject *args) +{ + int rv; + struct gpiod_line_bulk bulk; + int flags; + + if (gpiod_LineBulkOwnerIsClosed(self)) + return NULL; + + gpiod_LineBulkObjToCLineBulk(self, &bulk); + + rv = PyArg_ParseTuple(args, "i", &flags); + if (!rv) + return NULL; + + Py_BEGIN_ALLOW_THREADS; + rv = gpiod_line_set_flags_bulk(&bulk, flags); + Py_END_ALLOW_THREADS; + if (rv) + return PyErr_SetFromErrno(PyExc_OSError); + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(gpiod_LineBulk_set_direction_input_doc, +"set_direction_input() -> None\n" +"\n" +"Set the direction of all the lines held by this LineBulk object to input.\n"); + +static PyObject *gpiod_LineBulk_set_direction_input(gpiod_LineBulkObject *self, + PyObject *Py_UNUSED(ignored)) +{ + struct gpiod_line_bulk bulk; + int rv; + + if (gpiod_LineBulkOwnerIsClosed(self)) + return NULL; + + gpiod_LineBulkObjToCLineBulk(self, &bulk); + + Py_BEGIN_ALLOW_THREADS; + rv = gpiod_line_set_direction_bulk_input(&bulk); + Py_END_ALLOW_THREADS; + if (rv) + return PyErr_SetFromErrno(PyExc_OSError); + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(gpiod_LineBulk_set_direction_output_doc, +"set_direction_output(value) -> None\n" +"\n" +"Set the direction of all the lines held by this LineBulk object to output.\n" +"\n" +" values\n" +" List of values (integers) to set when direction is output.\n" +"\n" +"The number of values in the list passed as argument must be the same as\n" +"the number of lines held by this gpiod.LineBulk object. The index of each\n" +"value corresponds to the index of each line in the object.\n"); + +static PyObject *gpiod_LineBulk_set_direction_output( + gpiod_LineBulkObject *self, + PyObject *args) +{ + int rv, vals[GPIOD_LINE_BULK_MAX_LINES]; + PyObject *val_list; + struct gpiod_line_bulk bulk; + const int *valp; + + if (gpiod_LineBulkOwnerIsClosed(self)) + return NULL; + + gpiod_LineBulkObjToCLineBulk(self, &bulk); + + val_list = NULL; + rv = PyArg_ParseTuple(args, "|O", &val_list); + if (!rv) + return NULL; + + if (val_list == NULL) + valp = NULL; + else { + memset(vals, 0, sizeof(vals)); + rv = convert_values(val_list, vals, self->num_lines); + if (rv) + return NULL; + valp = vals; + } + + Py_BEGIN_ALLOW_THREADS; + rv = gpiod_line_set_direction_bulk_output(&bulk, valp); + Py_END_ALLOW_THREADS; + if (rv) + return PyErr_SetFromErrno(PyExc_OSError); + + Py_RETURN_NONE; +} + PyDoc_STRVAR(gpiod_LineBulk_release_doc, "release() -> None\n" "\n" @@ -1431,6 +1784,30 @@ static PyMethodDef gpiod_LineBulk_methods[] = { .ml_doc = gpiod_LineBulk_set_values_doc, .ml_flags = METH_VARARGS, }, + { + .ml_name = "set_config", + .ml_meth = (PyCFunction)gpiod_LineBulk_set_config, + .ml_flags = METH_VARARGS, + .ml_doc = gpiod_LineBulk_set_config_doc, + }, + { + .ml_name = "set_flags", + .ml_meth = (PyCFunction)gpiod_LineBulk_set_flags, + .ml_flags = METH_VARARGS, + .ml_doc = gpiod_LineBulk_set_flags_doc, + }, + { + .ml_name = "set_direction_input", + .ml_meth = (PyCFunction)gpiod_LineBulk_set_direction_input, + .ml_flags = METH_NOARGS, + .ml_doc = gpiod_LineBulk_set_direction_input_doc, + }, + { + .ml_name = "set_direction_output", + .ml_meth = (PyCFunction)gpiod_LineBulk_set_direction_output, + .ml_flags = METH_VARARGS, + .ml_doc = gpiod_LineBulk_set_direction_output_doc, + }, { .ml_name = "release", .ml_meth = (PyCFunction)gpiod_LineBulk_release, From patchwork Fri Nov 15 14:43:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mYCvIdqU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1P33fz5z9sP6 for ; Sat, 16 Nov 2019 01:45:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727557AbfKOOpm (ORCPT ); Fri, 15 Nov 2019 09:45:42 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38725 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbfKOOpm (ORCPT ); Fri, 15 Nov 2019 09:45:42 -0500 Received: by mail-pf1-f196.google.com with SMTP id c13so6786461pfp.5 for ; Fri, 15 Nov 2019 06:45:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xZlbgmFt9O1mvX0rp/4awL3PbMSgZdBNoRECTogus8M=; b=mYCvIdqU4XDc+JdBEaqo4+bNCbyFDs7mV7fZ9u/SjLmujSJ3O3eAaYClFxUfkK8/WJ hy6wxSUX17LcwZBvMf5kL58ubW9aVzwnxKaAt9WoBwuZ45CLRtDp0xhDRH80iCF7hftW vCjcoraCAyoNepWW0PISrIwMo3WJYFEcUXfcgp4+r9nvU0KwAR5gR6L+611Nb/aHFuW2 qfStq0l9pqeF1IO2s99LiDFGF73P4a9RhofXb+x8sSR19tgSaJY3CUdZpHxJ4vVsabJQ lHxRcEWoed1R/CBVT0e3OPCnMcQSu0dzmrJR1f6uDwuOQ2SKGnbd/ObTm2XGY2aD+dRe 7v8w== 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:mime-version:content-transfer-encoding; bh=xZlbgmFt9O1mvX0rp/4awL3PbMSgZdBNoRECTogus8M=; b=dTJ0k1c8LdOjFn2Thnfy0cImzBVX0anF84mOW0uct57FcJfetRy1qCckxYM816ZSVY J0YPNv/iYtflZqZhV8RVV5h5NZl25nCNICouGk51pJeT17phQkoRc+qsh0X078eonb5G Ugx8zyJktdIqQAcJAVQgHkXTuZSkn/AsW64DVK/VD313WfdCuamXoeeb9qJu2HwFkwWo Dy69qQuJoYHMEuQhrjlPfjMC3M4tebcv6wycSKLJN/H4+5Hw79Np/tKee87p9N1w0R0E pc6bW73qzdw+WE+EClDgTLgxOLxcDEHcHdTKBTBkD9r6k0uHaIrHiyRD2zKg4PscySDv dw1w== X-Gm-Message-State: APjAAAXaOZLyC4p0Bn5KgDpw3Asfa2q/aP+iqelpsBvZB9e0pjrPyXAq BpsrB8BfqvFa1IDx0AVP57hGMd+AXNU= X-Google-Smtp-Source: APXvYqx+mfdv17S3TUGECacLOE1FyYNHc0ystagkRI7bRg7iuB4HrAeQBITlzLeiWzI40knr9mP0jg== X-Received: by 2002:a65:6685:: with SMTP id b5mr7537517pgw.94.1573829141121; Fri, 15 Nov 2019 06:45:41 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:40 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 17/19] bindings: python: tests: add tests for SET_CONFIG methods Date: Fri, 15 Nov 2019 22:43:53 +0800 Message-Id: <20191115144355.975-18-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend test coverage over set_config, set_flags, set_direction_input, and set_direction_output methods. Signed-off-by: Kent Gibson --- bindings/python/tests/gpiod_py_test.py | 163 +++++++++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/bindings/python/tests/gpiod_py_test.py b/bindings/python/tests/gpiod_py_test.py index 9330b43..704d916 100755 --- a/bindings/python/tests/gpiod_py_test.py +++ b/bindings/python/tests/gpiod_py_test.py @@ -493,6 +493,169 @@ class LineValues(MockupTestCase): line.set_value(0) self.assertEqual(mockup.chip_get_value(0, 3), 1) +class LineConfig(MockupTestCase): + + chip_sizes = ( 8, ) + + def test_set_config_direction(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(3) + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_IN) + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_INPUT) + line.set_config(gpiod.LINE_REQ_DIR_IN, 0, 0) + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_INPUT) + line.set_config(gpiod.LINE_REQ_DIR_OUT,0,0) + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + + def test_set_config_flags(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(3) + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT) + line.set_config(gpiod.LINE_REQ_DIR_OUT, + gpiod.LINE_REQ_FLAG_ACTIVE_LOW, 0) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + line.set_config(gpiod.LINE_REQ_DIR_OUT, 0, 0) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + + def test_set_config_output_value(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(3) + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_IN) + line.set_config(gpiod.LINE_REQ_DIR_OUT,0,1) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + line.set_config(gpiod.LINE_REQ_DIR_OUT,0,0) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + + def test_set_config_output_no_value(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(3) + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + default_val=1) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + line.set_config(gpiod.LINE_REQ_DIR_OUT,0) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + + def test_set_config_bulk_output_no_values(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + lines = chip.get_lines(( 0, 3, 4, 6 )) + lines.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + default_vals=(1,1,1,1)) + self.assertEqual(mockup.chip_get_value(0, 0), 1) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + self.assertEqual(mockup.chip_get_value(0, 4), 1) + self.assertEqual(mockup.chip_get_value(0, 6), 1) + lines.set_config(gpiod.LINE_REQ_DIR_OUT,0) + self.assertEqual(mockup.chip_get_value(0, 0), 0) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + self.assertEqual(mockup.chip_get_value(0, 4), 0) + self.assertEqual(mockup.chip_get_value(0, 6), 0) + +class LineFlags(MockupTestCase): + + chip_sizes = ( 8, ) + + def test_set_flags(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(3) + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + default_val=1) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + line.set_flags(gpiod.LINE_REQ_FLAG_ACTIVE_LOW) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + line.set_flags(0) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + + def test_set_flags_bulk(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + lines = chip.get_lines(( 0, 3, 4, 6 )) + lines.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT, + default_vals=(1,1,1,1)) + self.assertEqual(mockup.chip_get_value(0, 0), 1) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + self.assertEqual(mockup.chip_get_value(0, 4), 1) + self.assertEqual(mockup.chip_get_value(0, 6), 1) + lines.set_flags(gpiod.LINE_REQ_FLAG_ACTIVE_LOW) + self.assertEqual(mockup.chip_get_value(0, 0), 0) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + self.assertEqual(mockup.chip_get_value(0, 4), 0) + self.assertEqual(mockup.chip_get_value(0, 6), 0) + lines.set_flags(0) + self.assertEqual(mockup.chip_get_value(0, 0), 1) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + self.assertEqual(mockup.chip_get_value(0, 4), 1) + self.assertEqual(mockup.chip_get_value(0, 6), 1) + +class LineDirection(MockupTestCase): + + chip_sizes = ( 8, ) + + def test_set_direction(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(3) + line.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT) + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + line.set_direction_input() + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_INPUT) + line.set_direction_output(0) + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + line.set_direction_output(1) + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + line.set_direction_output() + self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + + def test_set_direction_bulk(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + lines = chip.get_lines(( 0, 3, 4, 6 )) + lines.request(consumer=default_consumer, + type=gpiod.LINE_REQ_DIR_OUT) + self.assertEqual(lines.to_list()[0].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[1].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[2].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[3].direction(), gpiod.Line.DIRECTION_OUTPUT) + lines.set_direction_input() + self.assertEqual(lines.to_list()[0].direction(), gpiod.Line.DIRECTION_INPUT) + self.assertEqual(lines.to_list()[1].direction(), gpiod.Line.DIRECTION_INPUT) + self.assertEqual(lines.to_list()[2].direction(), gpiod.Line.DIRECTION_INPUT) + self.assertEqual(lines.to_list()[3].direction(), gpiod.Line.DIRECTION_INPUT) + lines.set_direction_output((0,0,1,0)) + self.assertEqual(lines.to_list()[0].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[1].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[2].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[3].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(mockup.chip_get_value(0, 0), 0) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + self.assertEqual(mockup.chip_get_value(0, 4), 1) + self.assertEqual(mockup.chip_get_value(0, 6), 0) + lines.set_direction_output((1,1,1,0)) + self.assertEqual(lines.to_list()[0].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[1].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[2].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[3].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(mockup.chip_get_value(0, 0), 1) + self.assertEqual(mockup.chip_get_value(0, 3), 1) + self.assertEqual(mockup.chip_get_value(0, 4), 1) + self.assertEqual(mockup.chip_get_value(0, 6), 0) + lines.set_direction_output() + self.assertEqual(lines.to_list()[0].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[1].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[2].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(lines.to_list()[3].direction(), gpiod.Line.DIRECTION_OUTPUT) + self.assertEqual(mockup.chip_get_value(0, 0), 0) + self.assertEqual(mockup.chip_get_value(0, 3), 0) + self.assertEqual(mockup.chip_get_value(0, 4), 0) + self.assertEqual(mockup.chip_get_value(0, 6), 0) + class LineRequestBehavior(MockupTestCase): chip_sizes = ( 8, ) From patchwork Fri Nov 15 14:43:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195694 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qVgzTk0c"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1P73tjjz9sPF for ; Sat, 16 Nov 2019 01:45:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727626AbfKOOpr (ORCPT ); Fri, 15 Nov 2019 09:45:47 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46026 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbfKOOpq (ORCPT ); Fri, 15 Nov 2019 09:45:46 -0500 Received: by mail-pl1-f195.google.com with SMTP id w7so4792011plz.12 for ; Fri, 15 Nov 2019 06:45:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WOr1Q6dXWaibFXJlC1SbG3Y209qZriV1js594rgglWc=; b=qVgzTk0c7xk2yv9G9/UuB+NoDgrQ/JdXSZHWSXRBeqg+vefEXmFaCQLaNM3wwpNRB3 +u0Lq44Zh6dwhI5GSroIBjgyyS0Fs/t4aNiqAdDDAxzDI3zSe8Awe5KUfnskq/YxOnKV fO87IQmXCbjhOQkWOU1bVyx6jPalg7adFAZGSpxOZLwGOzKBkj5mOXzhBITcpnfz9yhZ QQfElP50R0atcVxxL+mKari351Lg08gy4fnznZX0ai7fN4eeIsXDKyDbOIRqIDHkIsRL KQmYM/GUAEolF0nRz0GIsY1eV82883a4rQJHhaepUmnN1WPB6Isca4NIhIJ3WAsvr04f 4y4A== 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:mime-version:content-transfer-encoding; bh=WOr1Q6dXWaibFXJlC1SbG3Y209qZriV1js594rgglWc=; b=OHKPHPGQavDJSvCMKTmesCUYt4zuaH9bInyT8cfFEjBqjT4OOpZq0bPShIEQBj6ezr E1F1d9RSuJafxQIGOV3AX40Ki1H4d25qHv3QLub6yfGcEGJdb3hP1XcZu9Vab+09AUWB KUdmlWtHDnco/nufS72sL+FIC9Bdu8a7pK0PuGk5nl67QJINMZwLBeDQyx+qqFTb8WGY miDJXldTGD8xX3Rd+aBGw0gKbywR7fQFTgebe+xko3mSKobdGvUcniz6YnUkizUjAaNS 3VFYRZsnQRpv1+fuzdeTYrOqXe/1QGAztk1FrfjnbephyAbD5pmTE3al0tRYmThDbD7J IEvA== X-Gm-Message-State: APjAAAWm6HlEeHR6/UrTethiUVWdphmrgIQF+4K/Xfq5oMhtzFV8d/yE Mx6ini5NbZolHHhcyygoFM/9KoKCHn4= X-Google-Smtp-Source: APXvYqx9ovrM2wBRm4LzTuI7SND+bq6MysK69J7l++Gvre5gt7116NLzRQX7C33KT9ZPCdH1jxrE/Q== X-Received: by 2002:a17:90b:4386:: with SMTP id in6mr20255461pjb.33.1573829145547; Fri, 15 Nov 2019 06:45:45 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:45 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 18/19] tools: add support for bias flags Date: Fri, 15 Nov 2019 22:43:54 +0800 Message-Id: <20191115144355.975-19-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add support for bias flags to applicable tools - gpioget, gpioset, and gpiomon. Signed-off-by: Kent Gibson --- tools/gpioget.c | 24 ++++++++++++++++++++---- tools/gpiomon.c | 28 ++++++++++++++++++++++------ tools/gpioset.c | 26 +++++++++++++++++++++----- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/tools/gpioget.c b/tools/gpioget.c index 196ebeb..025811a 100644 --- a/tools/gpioget.c +++ b/tools/gpioget.c @@ -17,10 +17,13 @@ static const struct option longopts[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { "active-low", no_argument, NULL, 'l' }, + { "pull-down", no_argument, NULL, 'D' }, + { "pull-up", no_argument, NULL, 'U' }, + { "bias-disable", no_argument, NULL, 'B' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvl"; +static const char *const shortopts = "+hvlDUB"; static void print_help(void) { @@ -32,6 +35,9 @@ static void print_help(void) printf(" -h, --help:\t\tdisplay this message and exit\n"); printf(" -v, --version:\tdisplay the version and exit\n"); printf(" -l, --active-low:\tset the line active state to low\n"); + printf(" -D, --pull-down:\tenable internal pull-down\n"); + printf(" -U, --pull-up:\tenable internal pull-up\n"); + printf(" -B, --bias-disable:\tdisable internal bias\n"); } int main(int argc, char **argv) @@ -39,6 +45,7 @@ int main(int argc, char **argv) unsigned int *offsets, i, num_lines; int *values, optc, opti, rv; bool active_low = false; + int flags = 0; char *device, *end; for (;;) { @@ -56,6 +63,15 @@ int main(int argc, char **argv) case 'l': active_low = true; break; + case 'D': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN; + break; + case 'U': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP; + break; + case 'B': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE; + break; case '?': die("try %s --help", get_progname()); default: @@ -86,9 +102,9 @@ int main(int argc, char **argv) die("invalid GPIO offset: %s", argv[i + 1]); } - rv = gpiod_ctxless_get_value_multiple(device, offsets, values, - num_lines, active_low, - "gpioget"); + rv = gpiod_ctxless_get_value_multiple_ext(device, offsets, values, + num_lines, active_low, flags, + "gpioget"); if (rv < 0) die_perror("error reading GPIO values"); diff --git a/tools/gpiomon.c b/tools/gpiomon.c index 9a1843b..5779718 100644 --- a/tools/gpiomon.c +++ b/tools/gpiomon.c @@ -26,12 +26,15 @@ static const struct option longopts[] = { { "silent", no_argument, NULL, 's' }, { "rising-edge", no_argument, NULL, 'r' }, { "falling-edge", no_argument, NULL, 'f' }, + { "pull-down", no_argument, NULL, 'D' }, + { "pull-up", no_argument, NULL, 'U' }, + { "bias-disable", no_argument, NULL, 'B' }, { "line-buffered", no_argument, NULL, 'b' }, { "format", required_argument, NULL, 'F' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvln:srfbF:"; +static const char *const shortopts = "+hvln:srfDUBbF:"; static void print_help(void) { @@ -47,6 +50,9 @@ static void print_help(void) printf(" -s, --silent:\t\tdon't print event info\n"); printf(" -r, --rising-edge:\tonly process rising edge events\n"); printf(" -f, --falling-edge:\tonly process falling edge events\n"); + printf(" -D, --pull-down:\tenable internal pull-down\n"); + printf(" -U, --pull-up:\tenable internal pull-up\n"); + printf(" -B, --bias-disable:\tdisable internal bias\n"); printf(" -b, --line-buffered:\tset standard output as line buffered\n"); printf(" -F, --format=FMT\tspecify custom output format\n"); printf("\n"); @@ -244,6 +250,7 @@ int main(int argc, char **argv) { unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES], num_lines = 0, offset; bool active_low = false, watch_rising = false, watch_falling = false; + int flags = 0; struct timespec timeout = { 10, 0 }; int optc, opti, rv, i, event_type; struct mon_ctx ctx; @@ -266,6 +273,15 @@ int main(int argc, char **argv) case 'l': active_low = true; break; + case 'D': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN; + break; + case 'U': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP; + break; + case 'B': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE; + break; case 'n': ctx.events_wanted = strtoul(optarg, &end, 10); if (*end != '\0') @@ -320,11 +336,11 @@ int main(int argc, char **argv) ctx.sigfd = make_signalfd(); - rv = gpiod_ctxless_event_monitor_multiple(argv[0], event_type, - offsets, num_lines, - active_low, "gpiomon", - &timeout, poll_callback, - event_callback, &ctx); + rv = gpiod_ctxless_event_monitor_multiple_ext( + argv[0], event_type, offsets, + num_lines, active_low, flags, "gpiomon", + &timeout, poll_callback, + event_callback, &ctx); if (rv) die_perror("error waiting for events"); diff --git a/tools/gpioset.c b/tools/gpioset.c index d9977a7..8855eb0 100644 --- a/tools/gpioset.c +++ b/tools/gpioset.c @@ -27,10 +27,13 @@ static const struct option longopts[] = { { "sec", required_argument, NULL, 's' }, { "usec", required_argument, NULL, 'u' }, { "background", no_argument, NULL, 'b' }, + { "pull-down", no_argument, NULL, 'D' }, + { "pull-up", no_argument, NULL, 'U' }, + { "bias-disable", no_argument, NULL, 'B' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvlm:s:u:b"; +static const char *const shortopts = "+hvlm:s:u:bDUB"; static void print_help(void) { @@ -42,6 +45,9 @@ static void print_help(void) printf(" -h, --help:\t\tdisplay this message and exit\n"); printf(" -v, --version:\tdisplay the version and exit\n"); printf(" -l, --active-low:\tset the line active state to low\n"); + printf(" -D, --pull-down:\tenable internal pull-down\n"); + printf(" -U, --pull-up:\tenable internal pull-up\n"); + printf(" -B, --bias-disable:\tdisable internal bias\n"); printf(" -m, --mode=[exit|wait|time|signal] (defaults to 'exit'):\n"); printf(" tell the program what to do after setting values\n"); printf(" -s, --sec=SEC:\tspecify the number of seconds to wait (only valid for --mode=time)\n"); @@ -182,7 +188,7 @@ int main(int argc, char **argv) { const struct mode_mapping *mode = &modes[MODE_EXIT]; unsigned int *offsets, num_lines, i; - int *values, rv, optc, opti; + int *values, rv, optc, opti, flags = 0; struct callback_data cbdata; bool active_low = false; char *device, *end; @@ -204,6 +210,15 @@ int main(int argc, char **argv) case 'l': active_low = true; break; + case 'D': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN; + break; + case 'U': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP; + break; + case 'B': + flags |= GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE; + break; case 'm': mode = parse_mode(optarg); if (!mode) @@ -268,9 +283,10 @@ int main(int argc, char **argv) die("invalid offset: %s", argv[i + 1]); } - rv = gpiod_ctxless_set_value_multiple(device, offsets, values, - num_lines, active_low, "gpioset", - mode->callback, &cbdata); + rv = gpiod_ctxless_set_value_multiple_ext( + device, offsets, values, + num_lines, active_low, flags, "gpioset", + mode->callback, &cbdata); if (rv < 0) die_perror("error setting the GPIO line values"); From patchwork Fri Nov 15 14:43:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1195695 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="S7FkTgw8"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47F1PC0sldz9sPF for ; Sat, 16 Nov 2019 01:45:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727629AbfKOOpu (ORCPT ); Fri, 15 Nov 2019 09:45:50 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45358 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbfKOOpu (ORCPT ); Fri, 15 Nov 2019 09:45:50 -0500 Received: by mail-pg1-f196.google.com with SMTP id k1so4803176pgg.12 for ; Fri, 15 Nov 2019 06:45:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l8pvExKzv81RSRzZL9JexJ46sAgxZIhB5BLRMYlkMRc=; b=S7FkTgw8ofDxC585OEZfB49I2hcImPshD4Olm7Miv7pKboN3qCc0UQjj8nJrt4VRZ9 EP01BVmDRh/LffR3K3ImRat6gE6P/a+RloZOyQxza3Sic4czBgzuDP+T51lTnuPSByfy j9hLuD5hRHmT+FnEDzpayCPteLDAuPc6Lf4CNN2gTn52fqGqNR38ClVHEyfBMJtyALaX tSe6xzcrvB9G3FzT1XMTLn2EqvhX1OJwlHaKuBPlWMpOk18QE9osOH77dfxnqzv6JwIy Vf0Hgl/zy6U/x2ALqOfL9vFb2eVVeUZpsgWzk87vhnTWsDRcMT4Tko9ChafWiGbMAjli gTig== 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:mime-version:content-transfer-encoding; bh=l8pvExKzv81RSRzZL9JexJ46sAgxZIhB5BLRMYlkMRc=; b=eaASmgPVEMxUgsG29Q1+f0qn2BRmZFEm/aXcH8k+BGQ+13joQA+fSMHwnxFm/mCiaJ ihuYxOQeY5pMmft/OkQ8TBp61fyiqL3B/ktU5lMBSI7qrXYn68XYJd6WXqym/Umi7ghE gZk9Bb7rCvuTNrMWQSbesHPq8gr9i8v87FKMDAXT85fXlLF6kdVLO0e8KgfIcPpKHZdz Gxeg7kAH/g3qefZmua9Z4NQV07UM7dOXg0RP0LuL2dvXHMGavNvIF/0qGRpUsNgC3ZgW 70cLy8gcaqi8zBY1nudLFKrdLFBTsmm+Fp5NrSWjQ9k6jTKD7w6BOl3YkHTG8j9g4BPY zlaw== X-Gm-Message-State: APjAAAUFIsBp/1pOeYC3w221hQPUpAlGNjR1/trkeJwmex5/jpvneSm4 ywcQ7V5OGz9ca1PMA6WgjvxbW2lYo/Q= X-Google-Smtp-Source: APXvYqx6trvXtWS2qjqUCHBpPY9aisotCLRtP0O0f3JfrI/lA6CVRHZfAI8kzUUGevMjlFbav4bdVg== X-Received: by 2002:a63:368c:: with SMTP id d134mr16522018pga.321.1573829149363; Fri, 15 Nov 2019 06:45:49 -0800 (PST) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id y123sm10517726pfg.64.2019.11.15.06.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 06:45:48 -0800 (PST) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com Cc: Kent Gibson Subject: [libgpiod] [PATCH 19/19] treewide: change "correspond with" to "correspond to" Date: Fri, 15 Nov 2019 22:43:55 +0800 Message-Id: <20191115144355.975-20-warthog618@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191115144355.975-1-warthog618@gmail.com> References: <20191115144355.975-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Trivial grammar fix. "correspond with" can mean either being in agreement with, happening at the same time, or communication between parties. "correspond to" is used to mean equivalance, which is the intended use throughout the documentation. Signed-off-by: Kent Gibson --- bindings/python/gpiodmodule.c | 6 +++--- include/gpiod.h | 2 +- lib/core.c | 2 +- tests/mockup/gpio-mockup.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index 4949b14..74fbea3 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -1330,7 +1330,7 @@ PyDoc_STRVAR(gpiod_LineBulk_get_values_doc, "get_values() -> list of integers\n" "\n" "Read the values of all the lines held by this LineBulk object. The index\n" -"of each value in the returned list corresponds with the index of the line\n" +"of each value in the returned list corresponds to the index of the line\n" "in this gpiod.LineBulk object."); static PyObject *gpiod_LineBulk_get_values(gpiod_LineBulkObject *self, @@ -1385,7 +1385,7 @@ PyDoc_STRVAR(gpiod_LineBulk_set_values_doc, "\n" "The number of values in the list passed as argument must be the same as\n" "the number of lines held by this gpiod.LineBulk object. The index of each\n" -"value corresponds with the index of each line in the object.\n"); +"value corresponds to the index of each line in the object.\n"); static PyObject *gpiod_LineBulk_set_values(gpiod_LineBulkObject *self, PyObject *args) @@ -1408,7 +1408,7 @@ static PyObject *gpiod_LineBulk_set_values(gpiod_LineBulkObject *self, num_vals = PyObject_Size(val_list); if (self->num_lines != num_vals) { PyErr_SetString(PyExc_TypeError, - "Number of values must correspond with the number of lines"); + "Number of values must correspond to the number of lines"); return NULL; } diff --git a/include/gpiod.h b/include/gpiod.h index 4053fd2..6776852 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -779,7 +779,7 @@ gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk) * * This is a variant of ::gpiod_line_bulk_foreach_line which uses an integer * variable (either signed or unsigned) to store the loop state. This offset - * variable is guaranteed to correspond with the offset of the current line in + * variable is guaranteed to correspond to the offset of the current line in * the bulk->lines array. */ #define gpiod_line_bulk_foreach_line_off(bulk, line, offset) \ diff --git a/lib/core.c b/lib/core.c index 2e54def..54ae09c 100644 --- a/lib/core.c +++ b/lib/core.c @@ -111,7 +111,7 @@ static bool is_gpiochip_cdev(const char *path) /* * Make sure the major and minor numbers of the character device - * correspond with the ones in the dev attribute in sysfs. + * correspond to the ones in the dev attribute in sysfs. */ snprintf(devstr, sizeof(devstr), "%u:%u", major(statbuf.st_rdev), minor(statbuf.st_rdev)); diff --git a/tests/mockup/gpio-mockup.c b/tests/mockup/gpio-mockup.c index e3a53da..fa27bd7 100644 --- a/tests/mockup/gpio-mockup.c +++ b/tests/mockup/gpio-mockup.c @@ -333,7 +333,7 @@ EXPORT int gpio_mockup_probe(struct gpio_mockup *ctx, unsigned int num_chips, /* * We can't assume that the order in which the mockup gpiochip * devices are created will be deterministic, yet we want the - * index passed to the test_chip_*() functions to correspond with the + * index passed to the test_chip_*() functions to correspond to the * order in which the chips were defined in the TEST_DEFINE() * macro. *