From: Bartosz Golaszewski Date: Thu, 13 Jul 2017 11:15:39 +0000 (+0200) Subject: core: group the line request code together X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=34b8d26a2695c4e9e54156dfe68a286be1986cf0;p=qemu-gpiodev%2Flibgpiod.git core: group the line request code together Put both the regular input & output requests as well as event requests together in the same place in core.c. Signed-off-by: Bartosz Golaszewski --- diff --git a/src/lib/core.c b/src/lib/core.c index 7209351..49efefa 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -389,64 +389,6 @@ int gpiod_line_update(struct gpiod_line *line) return 0; } -int gpiod_line_request(struct gpiod_line *line, - const struct gpiod_line_request_config *config, - int default_val) -{ - struct gpiod_line_bulk bulk; - - gpiod_line_bulk_init(&bulk); - gpiod_line_bulk_add(&bulk, line); - - return gpiod_line_request_bulk(&bulk, config, &default_val); -} - -int gpiod_line_request_input(struct gpiod_line *line, const char *consumer) -{ - struct gpiod_line_request_config config = { - .consumer = consumer, - .request_type = GPIOD_REQUEST_DIRECTION_INPUT, - }; - - return gpiod_line_request(line, &config, 0); -} - -int gpiod_line_request_output(struct gpiod_line *line, - const char *consumer, int default_val) -{ - struct gpiod_line_request_config config = { - .consumer = consumer, - .request_type = GPIOD_REQUEST_DIRECTION_OUTPUT, - }; - - return gpiod_line_request(line, &config, default_val); -} - -int gpiod_line_request_input_flags(struct gpiod_line *line, - const char *consumer, int flags) -{ - struct gpiod_line_request_config config = { - .consumer = consumer, - .request_type = GPIOD_REQUEST_DIRECTION_INPUT, - .flags = flags, - }; - - return gpiod_line_request(line, &config, 0); -} - -int gpiod_line_request_output_flags(struct gpiod_line *line, - const char *consumer, int flags, - int default_val) -{ - struct gpiod_line_request_config config = { - .consumer = consumer, - .request_type = GPIOD_REQUEST_DIRECTION_OUTPUT, - .flags = flags, - }; - - return gpiod_line_request(line, &config, default_val); -} - static bool verify_line_bulk(struct gpiod_line_bulk *bulk) { struct gpiod_line *line; @@ -590,6 +532,120 @@ static int line_request_events(struct gpiod_line_bulk *bulk, return 0; } +int gpiod_line_request(struct gpiod_line *line, + const struct gpiod_line_request_config *config, + int default_val) +{ + struct gpiod_line_bulk bulk; + + gpiod_line_bulk_init(&bulk); + gpiod_line_bulk_add(&bulk, line); + + return gpiod_line_request_bulk(&bulk, config, &default_val); +} + +int gpiod_line_request_input(struct gpiod_line *line, const char *consumer) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .request_type = GPIOD_REQUEST_DIRECTION_INPUT, + }; + + return gpiod_line_request(line, &config, 0); +} + +int gpiod_line_request_output(struct gpiod_line *line, + const char *consumer, int default_val) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .request_type = GPIOD_REQUEST_DIRECTION_OUTPUT, + }; + + return gpiod_line_request(line, &config, default_val); +} + +int gpiod_line_request_input_flags(struct gpiod_line *line, + const char *consumer, int flags) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .request_type = GPIOD_REQUEST_DIRECTION_INPUT, + .flags = flags, + }; + + return gpiod_line_request(line, &config, 0); +} + +int gpiod_line_request_output_flags(struct gpiod_line *line, + const char *consumer, int flags, + int default_val) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .request_type = GPIOD_REQUEST_DIRECTION_OUTPUT, + .flags = flags, + }; + + return gpiod_line_request(line, &config, default_val); +} + +static int line_event_request_type(struct gpiod_line *line, + const char *consumer, int flags, int type) +{ + struct gpiod_line_request_config config = { + .consumer = consumer, + .request_type = type, + .flags = flags, + }; + + return gpiod_line_request(line, &config, 0); +} + +int gpiod_line_request_rising_edge_events(struct gpiod_line *line, + const char *consumer) +{ + return line_event_request_type(line, consumer, 0, + GPIOD_REQUEST_EVENT_RISING_EDGE); +} + +int gpiod_line_request_falling_edge_events(struct gpiod_line *line, + const char *consumer) +{ + return line_event_request_type(line, consumer, 0, + GPIOD_REQUEST_EVENT_FALLING_EDGE); +} + +int gpiod_line_request_both_edges_events(struct gpiod_line *line, + const char *consumer) +{ + return line_event_request_type(line, consumer, 0, + GPIOD_REQUEST_EVENT_BOTH_EDGES); +} + +int gpiod_line_request_rising_edge_events_flags(struct gpiod_line *line, + const char *consumer, + int flags) +{ + return line_event_request_type(line, consumer, flags, + GPIOD_REQUEST_EVENT_RISING_EDGE); +} + +int gpiod_line_request_falling_edge_events_flags(struct gpiod_line *line, + const char *consumer, + int flags) +{ + return line_event_request_type(line, consumer, flags, + GPIOD_REQUEST_EVENT_RISING_EDGE); +} + +int gpiod_line_request_both_edges_events_flags(struct gpiod_line *line, + const char *consumer, int flags) +{ + return line_event_request_type(line, consumer, flags, + GPIOD_REQUEST_EVENT_RISING_EDGE); +} + int gpiod_line_request_bulk(struct gpiod_line_bulk *bulk, const struct gpiod_line_request_config *config, const int *default_vals) @@ -791,62 +847,6 @@ struct gpiod_line * gpiod_line_find_by_name(const char *name) return NULL; } -static int line_event_request_type(struct gpiod_line *line, - const char *consumer, int flags, int type) -{ - struct gpiod_line_request_config config = { - .consumer = consumer, - .request_type = type, - .flags = flags, - }; - - return gpiod_line_request(line, &config, 0); -} - -int gpiod_line_request_rising_edge_events(struct gpiod_line *line, - const char *consumer) -{ - return line_event_request_type(line, consumer, 0, - GPIOD_REQUEST_EVENT_RISING_EDGE); -} - -int gpiod_line_request_falling_edge_events(struct gpiod_line *line, - const char *consumer) -{ - return line_event_request_type(line, consumer, 0, - GPIOD_REQUEST_EVENT_FALLING_EDGE); -} - -int gpiod_line_request_both_edges_events(struct gpiod_line *line, - const char *consumer) -{ - return line_event_request_type(line, consumer, 0, - GPIOD_REQUEST_EVENT_BOTH_EDGES); -} - -int gpiod_line_request_rising_edge_events_flags(struct gpiod_line *line, - const char *consumer, - int flags) -{ - return line_event_request_type(line, consumer, flags, - GPIOD_REQUEST_EVENT_RISING_EDGE); -} - -int gpiod_line_request_falling_edge_events_flags(struct gpiod_line *line, - const char *consumer, - int flags) -{ - return line_event_request_type(line, consumer, flags, - GPIOD_REQUEST_EVENT_RISING_EDGE); -} - -int gpiod_line_request_both_edges_events_flags(struct gpiod_line *line, - const char *consumer, int flags) -{ - return line_event_request_type(line, consumer, flags, - GPIOD_REQUEST_EVENT_RISING_EDGE); -} - int gpiod_line_event_wait(struct gpiod_line *line, const struct timespec *timeout) {