| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* SPDX-FileCopyrightText: 2023-2024 Bartosz Golaszewski <[email protected]> */ |
| 3 | |
| 4 | #ifndef __GPIODGLIB_LINE_INFO_H__ |
| 5 | #define __GPIODGLIB_LINE_INFO_H__ |
| 6 | |
| 7 | #if !defined(__INSIDE_GPIOD_GLIB_H__) && !defined(GPIODGLIB_COMPILATION) |
| 8 | #error "Only <gpiod-glib.h> can be included directly." |
| 9 | #endif |
| 10 | |
| 11 | #include <glib.h> |
| 12 | #include <glib-object.h> |
| 13 | |
| 14 | #include "line.h" |
| 15 | |
| 16 | G_BEGIN_DECLS |
| 17 | |
| 18 | G_DECLARE_FINAL_TYPE(GpiodglibLineInfo, gpiodglib_line_info, |
| 19 | GPIODGLIB, LINE_INFO, GObject); |
| 20 | |
| 21 | #define GPIODGLIB_LINE_INFO_TYPE (gpiodglib_line_info_get_type()) |
| 22 | #define GPIODGLIB_LINE_INFO_OBJ(obj) \ |
| 23 | (G_TYPE_CHECK_INSTANCE_CAST((obj), GPIODGLIB_LINE_INFO_TYPE, \ |
| 24 | GpiodglibLineInfo)) |
| 25 | |
| 26 | /** |
| 27 | * gpiodglib_line_info_get_offset: |
| 28 | * @self: #GpiodglibLineInfo to manipulate. |
| 29 | * |
| 30 | * Get the offset of the line. |
| 31 | * |
| 32 | * The offset uniquely identifies the line on the chip. The combination of the |
| 33 | * chip and offset uniquely identifies the line within the system. |
| 34 | * |
| 35 | * Returns: Offset of the line within the parent chip. |
| 36 | */ |
| 37 | guint gpiodglib_line_info_get_offset(GpiodglibLineInfo *self); |
| 38 | |
| 39 | /** |
| 40 | * gpiodglib_line_info_dup_name: |
| 41 | * @self: #GpiodglibLineInfo to manipulate. |
| 42 | * |
| 43 | * Get the name of the line. |
| 44 | * |
| 45 | * Returns: Name of the GPIO line as it is represented in the kernel. This |
| 46 | * function returns a valid pointer to a null-terminated string or NULL if the |
| 47 | * line is unnamed. The string is a copy of the line name and must be freed by |
| 48 | * the caller with g_free(). |
| 49 | */ |
| 50 | gchar * G_GNUC_WARN_UNUSED_RESULT |
| 51 | gpiodglib_line_info_dup_name(GpiodglibLineInfo *self); |
| 52 | |
| 53 | /** |
| 54 | * gpiodglib_line_info_is_used: |
| 55 | * @self: #GpiodglibLineInfo to manipulate. |
| 56 | * |
| 57 | * Check if the line is in use. |
| 58 | * |
| 59 | * The exact reason a line is busy cannot be determined from user space. |
| 60 | * It may have been requested by another process or hogged by the kernel. |
| 61 | * It only matters that the line is used and can't be requested until |
| 62 | * released by the existing consumer. |
| 63 | * |
| 64 | * Returns: TRUE if the line is in use, FALSE otherwise. |
| 65 | */ |
| 66 | gboolean gpiodglib_line_info_is_used(GpiodglibLineInfo *self); |
| 67 | |
| 68 | /** |
| 69 | * gpiodglib_line_info_dup_consumer: |
| 70 | * @self: #GpiodglibLineInfo to manipulate. |
| 71 | * |
| 72 | * Get the name of the consumer of the line. |
| 73 | * |
| 74 | * Returns: Name of the GPIO consumer as it is represented in the kernel. This |
| 75 | * function returns a valid pointer to a null-terminated string or NULL if the |
| 76 | * consumer name is not set. The string is a copy of the consumer label and |
| 77 | * must be freed by the caller with g_free(). |
| 78 | */ |
| 79 | gchar * G_GNUC_WARN_UNUSED_RESULT |
| 80 | gpiodglib_line_info_dup_consumer(GpiodglibLineInfo *self); |
| 81 | |
| 82 | /** |
| 83 | * gpiodglib_line_info_get_direction: |
| 84 | * @self: #GpiodglibLineInfo to manipulate. |
| 85 | * |
| 86 | * Get the direction setting of the line. |
| 87 | * |
| 88 | * Returns: @GPIODGLIB_LINE_DIRECTION_INPUT or @GPIODGLIB_LINE_DIRECTION_OUTPUT. |
| 89 | */ |
| 90 | GpiodglibLineDirection |
| 91 | gpiodglib_line_info_get_direction(GpiodglibLineInfo *self); |
| 92 | |
| 93 | /** |
| 94 | * gpiodglib_line_info_get_edge_detection: |
| 95 | * @self: #GpiodglibLineInfo to manipulate. |
| 96 | * |
| 97 | * Get the edge detection setting of the line. |
| 98 | * |
| 99 | * Returns: @GPIODGLIB_LINE_EDGE_NONE, @GPIODGLIB_LINE_EDGE_RISING, |
| 100 | * @GPIODGLIB_LINE_EDGE_FALLING or @GPIODGLIB_LINE_EDGE_BOTH. |
| 101 | */ |
| 102 | GpiodglibLineEdge |
| 103 | gpiodglib_line_info_get_edge_detection(GpiodglibLineInfo *self); |
| 104 | |
| 105 | /** |
| 106 | * gpiodglib_line_info_get_bias: |
| 107 | * @self: #GpiodglibLineInfo to manipulate. |
| 108 | * |
| 109 | * Get the bias setting of the line. |
| 110 | * |
| 111 | * Returns: @GPIODGLIB_LINE_BIAS_PULL_UP, @GPIODGLIB_LINE_BIAS_PULL_DOWN, |
| 112 | * @GPIODGLIB_LINE_BIAS_DISABLED or @GPIODGLIB_LINE_BIAS_UNKNOWN. |
| 113 | */ |
| 114 | GpiodglibLineBias gpiodglib_line_info_get_bias(GpiodglibLineInfo *self); |
| 115 | |
| 116 | /** |
| 117 | * gpiodglib_line_info_get_drive: |
| 118 | * @self: #GpiodglibLineInfo to manipulate. |
| 119 | * |
| 120 | * Get the drive setting of the line. |
| 121 | * |
| 122 | * Returns: @GPIODGLIB_LINE_DRIVE_PUSH_PULL, @GPIODGLIB_LINE_DRIVE_OPEN_DRAIN |
| 123 | * or @GPIODGLIB_LINE_DRIVE_OPEN_SOURCE. |
| 124 | */ |
| 125 | GpiodglibLineDrive gpiodglib_line_info_get_drive(GpiodglibLineInfo *self); |
| 126 | |
| 127 | /** |
| 128 | * gpiodglib_line_info_is_active_low: |
| 129 | * @self: #GpiodglibLineInfo to manipulate. |
| 130 | * |
| 131 | * Check if the logical value of the line is inverted compared to the physical. |
| 132 | * |
| 133 | * Returns: TRUE if the line is "active-low", FALSE otherwise. |
| 134 | */ |
| 135 | gboolean gpiodglib_line_info_is_active_low(GpiodglibLineInfo *self); |
| 136 | |
| 137 | /** |
| 138 | * gpiodglib_line_info_is_debounced: |
| 139 | * @self: #GpiodglibLineInfo to manipulate. |
| 140 | * |
| 141 | * Check if the line is debounced (either by hardware or by the kernel |
| 142 | * software debouncer). |
| 143 | * |
| 144 | * Returns: TRUE if the line is debounced, FALSE otherwise. |
| 145 | */ |
| 146 | gboolean gpiodglib_line_info_is_debounced(GpiodglibLineInfo *self); |
| 147 | |
| 148 | /** |
| 149 | * gpiodglib_line_info_get_debounce_period_us: |
| 150 | * @self: #GpiodglibLineInfo to manipulate. |
| 151 | * |
| 152 | * Get the debounce period of the line, in microseconds. |
| 153 | * |
| 154 | * Returns: Debounce period in microseconds. 0 if the line is not debounced. |
| 155 | */ |
| 156 | GTimeSpan gpiodglib_line_info_get_debounce_period_us(GpiodglibLineInfo *self); |
| 157 | |
| 158 | /** |
| 159 | * gpiodglib_line_info_get_event_clock: |
| 160 | * @self: #GpiodglibLineInfo to manipulate. |
| 161 | * |
| 162 | * Get the event clock setting used for edge event timestamps for the line. |
| 163 | * |
| 164 | * Returns: @GPIODGLIB_LINE_CLOCK_MONOTONIC, @GPIODGLIB_LINE_CLOCK_HTE or |
| 165 | * @GPIODGLIB_LINE_CLOCK_REALTIME. |
| 166 | */ |
| 167 | GpiodglibLineClock gpiodglib_line_info_get_event_clock(GpiodglibLineInfo *self); |
| 168 | |
| 169 | G_END_DECLS |
| 170 | |
| 171 | #endif /* __GPIODGLIB_LINE_INFO_H__ */ |