| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef __GPIOCLI_COMMON_H__ |
| 5 |
#define __GPIOCLI_COMMON_H__ |
| 6 |
|
| 7 |
#include <gio/gio.h> |
| 8 |
#include <glib.h> |
| 9 |
#include <gpiodbus.h> |
| 10 |
|
| 11 |
void die(const gchar *fmt, ...) G_NORETURN G_GNUC_PRINTF(1, 2); |
| 12 |
void |
| 13 |
die_gerror(GError *err, const gchar *fmt, ...) G_NORETURN G_GNUC_PRINTF(2, 3); |
| 14 |
void die_parsing_opts(const char *fmt, ...) G_NORETURN G_GNUC_PRINTF(1, 2); |
| 15 |
|
| 16 |
void parse_options(const GOptionEntry *opts, const gchar *summary, |
| 17 |
const gchar *description, int *argc, char ***argv); |
| 18 |
void check_manager(void); |
| 19 |
|
| 20 |
gboolean quit_main_loop_on_signal(gpointer user_data); |
| 21 |
void die_on_name_vanished(GDBusConnection *con, const gchar *name, |
| 22 |
gpointer user_data); |
| 23 |
|
| 24 |
GList *strv_to_gstring_list(GStrv lines); |
| 25 |
gint output_value_from_str(const gchar *value_str); |
| 26 |
|
| 27 |
GDBusObjectManager *get_object_manager_client(const gchar *obj_path); |
| 28 |
GpiodbusObject *get_chip_obj_by_path(const gchar *obj_path); |
| 29 |
GpiodbusObject *get_chip_obj(const gchar *chip_name); |
| 30 |
GList *get_chip_objs(GStrv chip_names); |
| 31 |
gchar *make_request_obj_path(const gchar *request); |
| 32 |
GpiodbusObject *get_request_obj(const gchar *request_name); |
| 33 |
GList *get_request_objs(void); |
| 34 |
GArray *get_request_offsets(GpiodbusRequest *request); |
| 35 |
gboolean get_line_obj_by_name(const gchar *name, GpiodbusObject **line_obj, |
| 36 |
GpiodbusObject **chip_obj); |
| 37 |
GpiodbusObject * |
| 38 |
get_line_obj_by_name_for_chip(GpiodbusObject *chip_obj, const gchar *name_line); |
| 39 |
GList *get_all_line_objs_for_chip(GpiodbusObject *chip_obj); |
| 40 |
|
| 41 |
gchar *sanitize_object_path(const gchar *path); |
| 42 |
|
| 43 |
typedef struct { |
| 44 |
gchar *name; |
| 45 |
guint offset; |
| 46 |
gboolean used; |
| 47 |
gchar *consumer; |
| 48 |
const gchar *direction; |
| 49 |
const gchar *drive; |
| 50 |
const gchar *bias; |
| 51 |
gboolean active_low; |
| 52 |
const gchar *edge; |
| 53 |
gboolean debounced; |
| 54 |
guint64 debounce_period; |
| 55 |
const gchar *event_clock; |
| 56 |
gboolean managed; |
| 57 |
gchar *request_name; |
| 58 |
} LineProperties; |
| 59 |
|
| 60 |
LineProperties *get_line_properties(GpiodbusLine *line); |
| 61 |
void free_line_properties(LineProperties *props); |
| 62 |
|
| 63 |
G_DEFINE_AUTOPTR_CLEANUP_FUNC(LineProperties, free_line_properties); |
| 64 |
|
| 65 |
typedef struct { |
| 66 |
gboolean input; |
| 67 |
gboolean output; |
| 68 |
gboolean active_low; |
| 69 |
gboolean rising_edge; |
| 70 |
gboolean falling_edge; |
| 71 |
gboolean both_edges; |
| 72 |
gboolean push_pull; |
| 73 |
gboolean open_source; |
| 74 |
gboolean open_drain; |
| 75 |
gboolean pull_up; |
| 76 |
gboolean pull_down; |
| 77 |
gboolean bias_disabled; |
| 78 |
gboolean clock_monotonic; |
| 79 |
gboolean clock_realtime; |
| 80 |
gboolean clock_hte; |
| 81 |
GTimeSpan debounce_period; |
| 82 |
GArray *output_values; |
| 83 |
} LineConfigOpts; |
| 84 |
|
| 85 |
#define LINE_CONFIG_OPTIONS(opts) \ |
| 86 |
{ \ |
| 87 |
.long_name = "input", \ |
| 88 |
.flags = G_OPTION_FLAG_NONE, \ |
| 89 |
.arg = G_OPTION_ARG_NONE, \ |
| 90 |
.arg_data = &(opts)->input, \ |
| 91 |
.description = "Set direction to input.", \ |
| 92 |
}, \ |
| 93 |
{ \ |
| 94 |
.long_name = "output", \ |
| 95 |
.flags = G_OPTION_FLAG_NONE, \ |
| 96 |
.arg = G_OPTION_ARG_NONE, \ |
| 97 |
.arg_data = &(opts)->output, \ |
| 98 |
.description = "Set direction to output.", \ |
| 99 |
}, \ |
| 100 |
{ \ |
| 101 |
.long_name = "rising-edge", \ |
| 102 |
.flags = G_OPTION_FLAG_NONE, \ |
| 103 |
.arg = G_OPTION_ARG_NONE, \ |
| 104 |
.arg_data = &(opts)->rising_edge, \ |
| 105 |
.description = "Monitor rising edges." \ |
| 106 |
}, \ |
| 107 |
{ \ |
| 108 |
.long_name = "falling-edge", \ |
| 109 |
.flags = G_OPTION_FLAG_NONE, \ |
| 110 |
.arg = G_OPTION_ARG_NONE, \ |
| 111 |
.arg_data = &(opts)->falling_edge, \ |
| 112 |
.description = "Monitor falling edges." \ |
| 113 |
}, \ |
| 114 |
{ \ |
| 115 |
.long_name = "both-edges", \ |
| 116 |
.flags = G_OPTION_FLAG_NONE, \ |
| 117 |
.arg = G_OPTION_ARG_NONE, \ |
| 118 |
.arg_data = &(opts)->both_edges, \ |
| 119 |
.description = "Monitor rising and falling edges." \ |
| 120 |
}, \ |
| 121 |
{ \ |
| 122 |
.long_name = "push-pull", \ |
| 123 |
.flags = G_OPTION_FLAG_NONE, \ |
| 124 |
.arg = G_OPTION_ARG_NONE, \ |
| 125 |
.arg_data = &(opts)->push_pull, \ |
| 126 |
.description = "Drive the line in push-pull mode.", \ |
| 127 |
}, \ |
| 128 |
{ \ |
| 129 |
.long_name = "open-drain", \ |
| 130 |
.flags = G_OPTION_FLAG_NONE, \ |
| 131 |
.arg = G_OPTION_ARG_NONE, \ |
| 132 |
.arg_data = &(opts)->open_drain, \ |
| 133 |
.description = "Drive the line in open-drain mode.", \ |
| 134 |
}, \ |
| 135 |
{ \ |
| 136 |
.long_name = "open-source", \ |
| 137 |
.flags = G_OPTION_FLAG_NONE, \ |
| 138 |
.arg = G_OPTION_ARG_NONE, \ |
| 139 |
.arg_data = &(opts)->open_source, \ |
| 140 |
.description = "Drive the line in open-source mode.", \ |
| 141 |
}, \ |
| 142 |
{ \ |
| 143 |
.long_name = "pull-up", \ |
| 144 |
.flags = G_OPTION_FLAG_NONE, \ |
| 145 |
.arg = G_OPTION_ARG_NONE, \ |
| 146 |
.arg_data = &(opts)->pull_up, \ |
| 147 |
.description = "Enable internal pull-up bias.", \ |
| 148 |
}, \ |
| 149 |
{ \ |
| 150 |
.long_name = "pull-down", \ |
| 151 |
.flags = G_OPTION_FLAG_NONE, \ |
| 152 |
.arg = G_OPTION_ARG_NONE, \ |
| 153 |
.arg_data = &(opts)->pull_down, \ |
| 154 |
.description = "Enable internal pull-down bias.", \ |
| 155 |
}, \ |
| 156 |
{ \ |
| 157 |
.long_name = "bias-disabled", \ |
| 158 |
.flags = G_OPTION_FLAG_NONE, \ |
| 159 |
.arg = G_OPTION_ARG_NONE, \ |
| 160 |
.arg_data = &(opts)->bias_disabled, \ |
| 161 |
.description = "Disable internal pull-up/down bias.", \ |
| 162 |
}, \ |
| 163 |
{ \ |
| 164 |
.long_name = "active-low", \ |
| 165 |
.flags = G_OPTION_FLAG_NONE, \ |
| 166 |
.arg = G_OPTION_ARG_NONE, \ |
| 167 |
.arg_data = &(opts)->active_low, \ |
| 168 |
.description = "Treat the lines as active low.", \ |
| 169 |
}, \ |
| 170 |
{ \ |
| 171 |
.long_name = "debounce-period", \ |
| 172 |
.flags = G_OPTION_FLAG_NONE, \ |
| 173 |
.arg = G_OPTION_ARG_INT64, \ |
| 174 |
.arg_data = &(opts)->debounce_period, \ |
| 175 |
.arg_description = "<period in miliseconds>", \ |
| 176 |
.description = "Enable debouncing and set the period", \ |
| 177 |
}, \ |
| 178 |
{ \ |
| 179 |
.long_name = "clock-monotonic", \ |
| 180 |
.flags = G_OPTION_FLAG_NONE, \ |
| 181 |
.arg = G_OPTION_ARG_NONE, \ |
| 182 |
.arg_data = &(opts)->clock_monotonic, \ |
| 183 |
.description = "Use monotonic clock for edge event timestamps", \ |
| 184 |
}, \ |
| 185 |
{ \ |
| 186 |
.long_name = "clock-realtime", \ |
| 187 |
.flags = G_OPTION_FLAG_NONE, \ |
| 188 |
.arg = G_OPTION_ARG_NONE, \ |
| 189 |
.arg_data = &(opts)->clock_realtime, \ |
| 190 |
.description = "Use realtime clock for edge event timestamps", \ |
| 191 |
}, \ |
| 192 |
{ \ |
| 193 |
.long_name = "clock-hte", \ |
| 194 |
.flags = G_OPTION_FLAG_NONE, \ |
| 195 |
.arg = G_OPTION_ARG_NONE, \ |
| 196 |
.arg_data = &(opts)->clock_hte, \ |
| 197 |
.description = "Use HTE clock (if available) for edge event timestamps", \ |
| 198 |
} |
| 199 |
|
| 200 |
void validate_line_config_opts(LineConfigOpts *opts); |
| 201 |
GVariant *make_line_config(GArray *offsets, LineConfigOpts *cfg_opts); |
| 202 |
|
| 203 |
#endif |