]> Git Repo - pov-display-rpi.git/blob - src/gpio_ctl.c
fix nice val
[pov-display-rpi.git] / src / gpio_ctl.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // SPDX-FileCopyrightText: 2023 Kent Gibson <[email protected]>
3
4 #include "common.h"
5 #include <gpiod.h>
6 #include "gpio_ctl.h"
7
8 struct gpiod_line_request *request_input_line(const char *chip_path,
9                                                      unsigned int offset,
10                                                      const char *consumer,
11                                                      struct gpiod_line_settings *settings) {
12         struct gpiod_line_request *request = NULL;
13         struct gpiod_request_config *req_cfg = NULL;
14         struct gpiod_line_config *line_cfg;
15         struct gpiod_chip *chip;
16         int ret;
17
18         if (!settings)
19                 settings = gpiod_line_settings_new();
20
21         chip = gpiod_chip_open(chip_path);
22         if (!chip)
23                 goto free_settings;
24
25         line_cfg = gpiod_line_config_new();
26         if (!line_cfg)
27                 goto close_chip;
28
29         ret = gpiod_line_config_add_line_settings(line_cfg, &offset, 1,
30                                                   settings);
31         if (ret)
32                 goto free_line_config;
33
34         if (consumer) {
35                 req_cfg = gpiod_request_config_new();
36                 if (!req_cfg)
37                         goto free_line_config;
38
39                 gpiod_request_config_set_consumer(req_cfg, consumer);
40         }
41
42         request = gpiod_chip_request_lines(chip, req_cfg, line_cfg);
43
44         gpiod_request_config_free(req_cfg);
45
46 free_line_config:
47         gpiod_line_config_free(line_cfg);
48
49 close_chip:
50         gpiod_chip_close(chip);
51
52 free_settings:
53         gpiod_line_settings_free(settings);
54         settings = NULL;
55         return request;
56 }
57
58 struct gpiod_edge_event * read_event(struct gpiod_line_request *request,
59                                      struct gpiod_edge_event_buffer *event_buffer) {
60         int err;
61
62         err = gpiod_line_request_read_edge_events(request, event_buffer, 1);
63         if (err == -1) {
64                 fprintf(stderr, "error reading edge events: %s\n",
65                         strerror(errno));
66                 return NULL;
67         }
68         return gpiod_edge_event_buffer_get_event(event_buffer, 0);
69 }
This page took 0.027755 seconds and 4 git commands to generate.