int gpiod_simple_get_value(const char *device, unsigned int offset)
{
+ struct gpiod_line_request_config config;
struct gpiod_chip *chip;
struct gpiod_line *line;
int status, value;
+ memset(&config, 0, sizeof(config));
+ config.consumer = libgpiod_consumer;
+ config.direction = GPIOD_DIRECTION_AS_IS;
+
chip = gpiod_chip_open_lookup(device);
if (!chip)
return -1;
return -1;
}
- status = gpiod_line_request(line, libgpiod_consumer, 0,
- GPIOD_REQUEST_DIRECTION_INPUT);
+ status = gpiod_line_request(line, &config, 0);
if (status < 0) {
gpiod_chip_close(chip);
return -1;
}
int gpiod_line_request(struct gpiod_line *line,
- const char *consumer, int default_val, int flags)
+ 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, consumer, &default_val, flags);
+ return gpiod_line_request_bulk(&bulk, config, &default_val);
}
static bool verify_line_bulk(struct gpiod_line_bulk *line_bulk)
}
int gpiod_line_request_bulk(struct gpiod_line_bulk *line_bulk,
- const char *consumer, int *default_vals, int flags)
+ const struct gpiod_line_request_config *config,
+ int *default_vals)
{
struct gpiohandle_request *req;
struct gpiod_chip *chip;
- unsigned int i;
int status, fd;
+ unsigned int i;
/* Paranoia: verify that all lines are from the same gpiochip. */
if (!verify_line_bulk(line_bulk))
memset(req, 0, sizeof(*req));
- if ((flags & GPIOD_REQUEST_POLARITY_ACTIVE_HIGH) &&
- (flags & GPIOD_REQUEST_POLARITY_ACTIVE_LOW)) {
- set_last_error(EINVAL);
- return -1;
- }
-
- if ((flags & GPIOD_REQUEST_DIRECTION_INPUT) &&
- (flags & GPIOD_REQUEST_DIRECTION_OUTPUT)) {
- set_last_error(EINVAL);
- return -1;
- }
-
- if (flags & GPIOD_REQUEST_POLARITY_ACTIVE_LOW)
- req->flags |= GPIOHANDLE_REQUEST_ACTIVE_LOW;
- if (flags & GPIOD_REQUEST_OPEN_DRAIN)
+ if (config->flags & GPIOD_REQUEST_OPEN_DRAIN)
req->flags |= GPIOHANDLE_REQUEST_OPEN_DRAIN;
- if (flags & GPIOD_REQUEST_OPEN_SOURCE)
+ if (config->flags & GPIOD_REQUEST_OPEN_SOURCE)
req->flags |= GPIOHANDLE_REQUEST_OPEN_SOURCE;
- if (flags & GPIOD_REQUEST_DIRECTION_INPUT)
+ if (config->direction == GPIOD_DIRECTION_IN)
req->flags |= GPIOHANDLE_REQUEST_INPUT;
- else if (flags & GPIOD_REQUEST_DIRECTION_OUTPUT)
+ else if (config->direction == GPIOD_DIRECTION_OUT)
req->flags |= GPIOHANDLE_REQUEST_OUTPUT;
+ if (config->polarity == GPIOD_POLARITY_ACTIVE_LOW)
+ req->flags |= GPIOHANDLE_REQUEST_ACTIVE_LOW;
+
req->lines = line_bulk->num_lines;
for (i = 0; i < line_bulk->num_lines; i++) {
req->lineoffsets[i] = gpiod_line_offset(line_bulk->lines[i]);
- if (flags & GPIOD_REQUEST_DIRECTION_OUTPUT)
+ if (config->direction == GPIOD_DIRECTION_OUT)
req->default_values[i] = !!default_vals[i];
}
- strncpy(req->consumer_label, consumer,
+ strncpy(req->consumer_label, config->consumer,
sizeof(req->consumer_label) - 1);
chip = gpiod_line_get_chip(line_bulk->lines[0]);
int gpiod_simple_get_value(const char *device, unsigned int offset) GPIOD_API;
enum {
+ GPIOD_DIRECTION_AS_IS,
GPIOD_DIRECTION_IN,
GPIOD_DIRECTION_OUT,
};
};
enum {
- GPIOD_REQUEST_DIRECTION_AS_IS = GPIOD_BIT(0),
- GPIOD_REQUEST_DIRECTION_INPUT = GPIOD_BIT(1),
- GPIOD_REQUEST_DIRECTION_OUTPUT = GPIOD_BIT(2),
- GPIOD_REQUEST_POLARITY_ACTIVE_HIGH = GPIOD_BIT(3),
- GPIOD_REQUEST_POLARITY_ACTIVE_LOW = GPIOD_BIT(4),
GPIOD_REQUEST_OPEN_DRAIN = GPIOD_BIT(5),
GPIOD_REQUEST_OPEN_SOURCE = GPIOD_BIT(6),
};
int gpiod_line_update(struct gpiod_line *line) GPIOD_API;
-int gpiod_line_request(struct gpiod_line *line, const char *consumer,
- int default_val, int flags) GPIOD_API;
+struct gpiod_line_request_config {
+ const char *consumer;
+ int direction;
+ int polarity;
+ int flags;
+};
+
+int gpiod_line_request(struct gpiod_line *line,
+ const struct gpiod_line_request_config *config,
+ int default_val) GPIOD_API;
struct gpiod_line_bulk {
struct gpiod_line *lines[GPIOD_REQUEST_MAX_LINES];
}
int gpiod_line_request_bulk(struct gpiod_line_bulk *line_bulk,
- const char *consumer, int *default_vals,
- int flags) GPIOD_API;
+ const struct gpiod_line_request_config *config,
+ int *default_vals) GPIOD_API;
void gpiod_line_release(struct gpiod_line *line) GPIOD_API;