| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* SPDX-FileCopyrightText: 2022-2024 Bartosz Golaszewski <[email protected]> */ |
| 3 | |
| 4 | #ifndef __GPIODGLIB_CHIP_H__ |
| 5 | #define __GPIODGLIB_CHIP_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 "chip-info.h" |
| 15 | #include "line-config.h" |
| 16 | #include "line-info.h" |
| 17 | #include "line-request.h" |
| 18 | #include "request-config.h" |
| 19 | |
| 20 | G_BEGIN_DECLS |
| 21 | |
| 22 | G_DECLARE_FINAL_TYPE(GpiodglibChip, gpiodglib_chip, GPIODGLIB, CHIP, GObject); |
| 23 | |
| 24 | #define GPIODGLIB_CHIP_TYPE (gpiodglib_chip_get_type()) |
| 25 | #define GPIODGLIB_CHIP_OBJ(obj) \ |
| 26 | (G_TYPE_CHECK_INSTANCE_CAST((obj), GPIODGLIB_CHIP_TYPE, GpiodglibChip)) |
| 27 | |
| 28 | /** |
| 29 | * gpiodglib_chip_new: |
| 30 | * @path: Path to the device file to open. |
| 31 | * @err: Return location for error or %NULL. |
| 32 | * |
| 33 | * Instantiates a new chip object by opening the device file indicated by path. |
| 34 | * |
| 35 | * Returns: (transfer full): New GPIO chip object. |
| 36 | */ |
| 37 | GpiodglibChip *gpiodglib_chip_new(const gchar *path, GError **err); |
| 38 | |
| 39 | /** |
| 40 | * gpiodglib_chip_close: |
| 41 | * @self: #GpiodglibChip to close. |
| 42 | * |
| 43 | * Close the GPIO chip device file and free associated resources. |
| 44 | * |
| 45 | * The chip object can live after calling this method but any of the chip's |
| 46 | * methods will result in an error being set. |
| 47 | */ |
| 48 | void gpiodglib_chip_close(GpiodglibChip *self); |
| 49 | |
| 50 | /** |
| 51 | * gpiodglib_chip_is_closed: |
| 52 | * @self: #GpiodglibChip to manipulate. |
| 53 | * |
| 54 | * @brief Check if this object is valid. |
| 55 | * |
| 56 | * Returns: TRUE if this object's methods can be used, FALSE otherwise. |
| 57 | */ |
| 58 | gboolean gpiodglib_chip_is_closed(GpiodglibChip *self); |
| 59 | |
| 60 | /** |
| 61 | * gpiodglib_chip_dup_path: |
| 62 | * @self: #GpiodglibChip to manipulate. |
| 63 | * |
| 64 | * Get the filesystem path that was used to open this GPIO chip. |
| 65 | * |
| 66 | * Returns: Path to the underlying character device file. The string is a copy |
| 67 | * and must be freed by the caller with g_free(). |
| 68 | */ |
| 69 | gchar * G_GNUC_WARN_UNUSED_RESULT |
| 70 | gpiodglib_chip_dup_path(GpiodglibChip *self); |
| 71 | |
| 72 | /** |
| 73 | * gpiodglib_chip_get_info: |
| 74 | * @self: #GpiodglibChip to manipulate. |
| 75 | * @err: Return location for error or %NULL. |
| 76 | * |
| 77 | * Get information about the chip. |
| 78 | * |
| 79 | * Returns: (transfer full): New #GpiodglibChipInfo. |
| 80 | */ |
| 81 | GpiodglibChipInfo *gpiodglib_chip_get_info(GpiodglibChip *self, GError **err); |
| 82 | |
| 83 | /** |
| 84 | * gpiodglib_chip_get_line_info: |
| 85 | * @self: #GpiodglibChip to manipulate. |
| 86 | * @offset: Offset of the line to get the info for. |
| 87 | * @err: Return location for error or %NULL. |
| 88 | * |
| 89 | * Retrieve the current snapshot of line information for a single line. |
| 90 | * |
| 91 | * Returns: (transfer full): New #GpiodglibLineInfo. |
| 92 | */ |
| 93 | GpiodglibLineInfo * |
| 94 | gpiodglib_chip_get_line_info(GpiodglibChip *self, guint offset, GError **err); |
| 95 | |
| 96 | /** |
| 97 | * gpiodglib_chip_watch_line_info: |
| 98 | * @self: #GpiodglibChip to manipulate. |
| 99 | * @offset: Offset of the line to get the info for and to watch. |
| 100 | * @err: Return location for error or %NULL. |
| 101 | * |
| 102 | * Retrieve the current snapshot of line information for a single line and |
| 103 | * start watching this line for future changes. |
| 104 | * |
| 105 | * Returns: (transfer full): New #GpiodglibLineInfo. |
| 106 | */ |
| 107 | GpiodglibLineInfo * |
| 108 | gpiodglib_chip_watch_line_info(GpiodglibChip *self, guint offset, GError **err); |
| 109 | |
| 110 | /** |
| 111 | * gpiodglib_chip_unwatch_line_info: |
| 112 | * @self: #GpiodglibChip to manipulate. |
| 113 | * @offset: Offset of the line to get the info for. |
| 114 | * @err: Return location for error or %NULL. |
| 115 | * |
| 116 | * Stop watching the line at given offset for info events. |
| 117 | * |
| 118 | * Returns: TRUE on success, FALSE on failure. |
| 119 | */ |
| 120 | gboolean |
| 121 | gpiodglib_chip_unwatch_line_info(GpiodglibChip *self, guint offset, |
| 122 | GError **err); |
| 123 | |
| 124 | /** |
| 125 | * gpiodglib_chip_get_line_offset_from_name: |
| 126 | * @self: #GpiodglibChip to manipulate. |
| 127 | * @name: Name of the GPIO line to map. |
| 128 | * @offset: Return location for the mapped offset. |
| 129 | * @err: Return location for error or %NULL. |
| 130 | * |
| 131 | * Map a GPIO line's name to its offset within the chip. |
| 132 | * |
| 133 | * Returns: TRUE on success, FALSE on failure. |
| 134 | */ |
| 135 | gboolean |
| 136 | gpiodglib_chip_get_line_offset_from_name(GpiodglibChip *self, const gchar *name, |
| 137 | guint *offset, GError **err); |
| 138 | |
| 139 | /** |
| 140 | * gpiodglib_chip_request_lines: |
| 141 | * @self: #GpiodglibChip to manipulate. |
| 142 | * @req_cfg: Request config object. Can be NULL for default settings. |
| 143 | * @line_cfg: Line config object. |
| 144 | * @err: Return location for error or %NULL. |
| 145 | * |
| 146 | * Request a set of lines for exclusive usage. |
| 147 | * |
| 148 | * Returns: (transfer full): New #GpiodglibLineRequest. |
| 149 | */ |
| 150 | GpiodglibLineRequest * |
| 151 | gpiodglib_chip_request_lines(GpiodglibChip *self, |
| 152 | GpiodglibRequestConfig *req_cfg, |
| 153 | GpiodglibLineConfig *line_cfg, GError **err); |
| 154 | |
| 155 | G_END_DECLS |
| 156 | |
| 157 | #endif /* __GPIODGLIB_CHIP_H__ */ |