| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#ifndef __GPIOD_TOOLS_COMMON_H__ |
| 6 |
#define __GPIOD_TOOLS_COMMON_H__ |
| 7 |
|
| 8 |
#include <gpiod.h> |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#define NORETURN __attribute__((noreturn)) |
| 18 |
#define PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg))) |
| 19 |
|
| 20 |
#define GETOPT_NULL_LONGOPT NULL, 0, NULL, 0 |
| 21 |
|
| 22 |
struct resolved_line { |
| 23 |
|
| 24 |
const char *id; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
int id_as_offset; |
| 31 |
|
| 32 |
|
| 33 |
bool resolved; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
struct gpiod_line_info *info; |
| 39 |
|
| 40 |
|
| 41 |
int chip_num; |
| 42 |
|
| 43 |
|
| 44 |
unsigned int offset; |
| 45 |
|
| 46 |
|
| 47 |
int value; |
| 48 |
}; |
| 49 |
|
| 50 |
struct resolved_chip { |
| 51 |
|
| 52 |
struct gpiod_chip_info *info; |
| 53 |
|
| 54 |
|
| 55 |
char *path; |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
struct line_resolver { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
int num_chips; |
| 64 |
|
| 65 |
|
| 66 |
int num_lines; |
| 67 |
|
| 68 |
|
| 69 |
int num_found; |
| 70 |
|
| 71 |
|
| 72 |
bool strict; |
| 73 |
|
| 74 |
|
| 75 |
struct resolved_chip *chips; |
| 76 |
|
| 77 |
|
| 78 |
struct resolved_line lines[]; |
| 79 |
}; |
| 80 |
|
| 81 |
void set_prog_name(const char *name); |
| 82 |
const char *get_prog_name(void); |
| 83 |
const char *get_prog_short_name(void); |
| 84 |
void print_error(const char *fmt, ...) PRINTF(1, 2); |
| 85 |
void print_perror(const char *fmt, ...) PRINTF(1, 2); |
| 86 |
void die(const char *fmt, ...) NORETURN PRINTF(1, 2); |
| 87 |
void die_perror(const char *fmt, ...) NORETURN PRINTF(1, 2); |
| 88 |
void print_version(void); |
| 89 |
int parse_bias_or_die(const char *option); |
| 90 |
long long parse_period(const char *option); |
| 91 |
unsigned long long parse_period_or_die(const char *option); |
| 92 |
void sleep_us(unsigned long long period); |
| 93 |
int parse_uint(const char *option); |
| 94 |
unsigned int parse_uint_or_die(const char *option); |
| 95 |
void print_bias_help(void); |
| 96 |
void print_chip_help(void); |
| 97 |
void print_period_help(void); |
| 98 |
void print_event_time(uint64_t evtime, int format); |
| 99 |
void print_line_attributes(struct gpiod_line_info *info, bool unquoted_strings); |
| 100 |
void print_line_id(struct line_resolver *resolver, int chip_num, |
| 101 |
unsigned int offset, const char *chip_id, bool unquoted); |
| 102 |
bool chip_path_lookup(const char *id, char **path_ptr); |
| 103 |
int chip_paths(const char *id, char ***paths_ptr); |
| 104 |
int all_chip_paths(char ***paths_ptr); |
| 105 |
struct line_resolver *resolve_lines(int num_lines, char **lines, |
| 106 |
const char *chip_id, bool strict, |
| 107 |
bool by_name); |
| 108 |
struct line_resolver *resolver_init(int num_lines, char **lines, int num_chips, |
| 109 |
bool strict, bool by_name); |
| 110 |
bool resolve_lines_by_offset(struct line_resolver *resolver, |
| 111 |
unsigned int num_lines); |
| 112 |
bool resolve_done(struct line_resolver *resolver); |
| 113 |
void validate_resolution(struct line_resolver *resolver, const char *chip_id); |
| 114 |
void free_line_resolver(struct line_resolver *resolver); |
| 115 |
int get_line_offsets_and_values(struct line_resolver *resolver, int chip_num, |
| 116 |
unsigned int *offsets, |
| 117 |
enum gpiod_line_value *values); |
| 118 |
const char *get_chip_name(struct line_resolver *resolver, int chip_num); |
| 119 |
const char *get_line_name(struct line_resolver *resolver, int chip_num, |
| 120 |
unsigned int offset); |
| 121 |
void set_line_values(struct line_resolver *resolver, int chip_num, |
| 122 |
enum gpiod_line_value *values); |
| 123 |
|
| 124 |
#endif |