From: Bartosz Golaszewski Date: Wed, 11 Jan 2017 14:50:31 +0000 (+0100) Subject: gpiod.h: add line request helpers X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=7672bdff717e79b5ea05f334a6d7e27d1d5addcb;p=qemu-gpiodev%2Flibgpiod.git gpiod.h: add line request helpers Add inline functions to gpiod.h which allow to request lines with less arguments. Signed-off-by: Bartosz Golaszewski --- diff --git a/gpiod.h b/gpiod.h index 13b0277..bbebbd3 100644 --- a/gpiod.h +++ b/gpiod.h @@ -394,6 +394,49 @@ int gpiod_line_request(struct gpiod_line *line, const struct gpiod_line_request_config *config, int default_val) GPIOD_API; +/** + * @brief Reserve a single line, set the direction to input. + * @param line GPIO line object. + * @param consumer Name of the consumer. + * @param active_low Active state of the line (true if low). + * @return 0 if the line was properly reserved, -1 on failure. + */ +static inline int gpiod_line_request_input(struct gpiod_line *line, + const char *consumer, + bool active_low) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .direction = GPIOD_DIRECTION_INPUT, + .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW + : GPIOD_ACTIVE_STATE_HIGH, + }; + + return gpiod_line_request(line, &config, 0); +} + +/** + * @brief Reserve a single line, set the direction to output. + * @param line GPIO line object. + * @param consumer Name of the consumer. + * @param active_low Active state of the line (true if low). + * @param default_val Default line value. + * @return 0 if the line was properly reserved, -1 on failure. + */ +static inline int gpiod_line_request_output(struct gpiod_line *line, + const char *consumer, + bool active_low, int default_val) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .direction = GPIOD_DIRECTION_OUTPUT, + .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW + : GPIOD_ACTIVE_STATE_HIGH, + }; + + return gpiod_line_request(line, &config, default_val); +} + /** * @brief Reserve a set of GPIO lines. * @param line_bulk Set of GPIO lines to reserve. @@ -410,6 +453,50 @@ int gpiod_line_request_bulk(struct gpiod_line_bulk *line_bulk, const struct gpiod_line_request_config *config, int *default_vals) GPIOD_API; +/** + * @brief Reserve a set of GPIO lines, set the direction to input. + * @param bulk Set of GPIO lines to reserve. + * @param consumer Name of the consumer. + * @param active_low Active state of the lines (true if low). + * @return 0 if the lines were properly reserved, -1 on failure. + */ +static inline int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk, + const char *consumer, + bool active_low) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .direction = GPIOD_DIRECTION_INPUT, + .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW + : GPIOD_ACTIVE_STATE_HIGH, + }; + + return gpiod_line_request_bulk(bulk, &config, 0); +} + +/** + * @brief Reserve a set of GPIO lines, set the direction to output. + * @param bulk Set of GPIO lines to reserve. + * @param consumer Name of the consumer. + * @param active_low Active state of the lines (true if low). + * @param default_vals Default line values. + * @return 0 if the lines were properly reserved, -1 on failure. + */ +static inline int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk, + const char *consumer, + bool active_low, + int *default_vals) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .direction = GPIOD_DIRECTION_OUTPUT, + .active_state = active_low ? GPIOD_ACTIVE_STATE_LOW + : GPIOD_ACTIVE_STATE_HIGH, + }; + + return gpiod_line_request_bulk(bulk, &config, default_vals); +} + /** * @brief Release a previously reserved line. * @param line GPIO line object.