| 1 | // SPDX-License-Identifier: LGPL-2.1-or-latercxx . . $ `<file>/lib/line-settings.c`/ |
| 2 | // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <errno.h> |
| 6 | #include <gpiod.h>cxx . . $ `<file>/include/gpiod.h`/ |
| 7 | #include <string.h> |
| 8 | #include <stdlib.h> |
| 9 | |
| 10 | #include "internal.h"cxx . . $ `<file>/lib/internal.h`/ |
| 11 | |
| 12 | struct gpiod_line_settingscxx . . $ gpiod_line_settings# { |
| 13 | enum gpiod_line_directioncxx . . $ gpiod_line_direction# directioncxx . . $ gpiod_line_settings#direction.; |
| 14 | enum gpiod_line_edgecxx . . $ gpiod_line_edge# edge_detectioncxx . . $ gpiod_line_settings#edge_detection.; |
| 15 | enum gpiod_line_drivecxx . . $ gpiod_line_drive# drivecxx . . $ gpiod_line_settings#drive.; |
| 16 | enum gpiod_line_biascxx . . $ gpiod_line_bias# biascxx . . $ gpiod_line_settings#bias.; |
| 17 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! active_lowcxx . . $ gpiod_line_settings#active_low.; |
| 18 | enum gpiod_line_clockcxx . . $ gpiod_line_clock# event_clockcxx . . $ gpiod_line_settings#event_clock.; |
| 19 | unsigned long debounce_period_uscxx . . $ gpiod_line_settings#debounce_period_us.; |
| 20 | enum gpiod_line_valuecxx . . $ gpiod_line_value# output_valuecxx . . $ gpiod_line_settings#output_value.; |
| 21 | }; |
| 22 | |
| 23 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! struct gpiod_line_settingscxx . . $ gpiod_line_settings# *gpiod_line_settings_newcxx . . $ gpiod_line_settings_new(15316d376757b079).(void) |
| 24 | { |
| 25 | struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings; |
| 26 | |
| 27 | settings = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*settings)); |
| 28 | if (!settings) |
| 29 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 30 | |
| 31 | gpiod_line_settings_resetcxx . . $ gpiod_line_settings_reset(d2d57b119af88c6b).(settings); |
| 32 | |
| 33 | return settings; |
| 34 | } |
| 35 | |
| 36 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! void gpiod_line_settings_freecxx . . $ gpiod_line_settings_free(d2d57b119af88c6b).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 37 | { |
| 38 | freecxx . . $ free(5d22bdacc48458e8).(settings); |
| 39 | } |
| 40 | |
| 41 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! void gpiod_line_settings_resetcxx . . $ gpiod_line_settings_reset(d2d57b119af88c6b).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 42 | { |
| 43 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 44 | |
| 45 | settings->directioncxx . . $ gpiod_line_settings#direction. = GPIOD_LINE_DIRECTION_AS_IScxx . . $ GPIOD_LINE_DIRECTION_AS_IS.; |
| 46 | settings->edge_detectioncxx . . $ gpiod_line_settings#edge_detection. = GPIOD_LINE_EDGE_NONEcxx . . $ GPIOD_LINE_EDGE_NONE.; |
| 47 | settings->biascxx . . $ gpiod_line_settings#bias. = GPIOD_LINE_BIAS_AS_IScxx . . $ GPIOD_LINE_BIAS_AS_IS.; |
| 48 | settings->drivecxx . . $ gpiod_line_settings#drive. = GPIOD_LINE_DRIVE_PUSH_PULLcxx . . $ GPIOD_LINE_DRIVE_PUSH_PULL.; |
| 49 | settings->active_lowcxx . . $ gpiod_line_settings#active_low. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 50 | settings->debounce_period_uscxx . . $ gpiod_line_settings#debounce_period_us. = 0; |
| 51 | settings->event_clockcxx . . $ gpiod_line_settings#event_clock. = GPIOD_LINE_CLOCK_MONOTONICcxx . . $ GPIOD_LINE_CLOCK_MONOTONIC.; |
| 52 | settings->output_valuecxx . . $ gpiod_line_settings#output_value. = GPIOD_LINE_VALUE_INACTIVEcxx . . $ GPIOD_LINE_VALUE_INACTIVE.; |
| 53 | } |
| 54 | |
| 55 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! struct gpiod_line_settingscxx . . $ gpiod_line_settings# * |
| 56 | gpiod_line_settings_copycxx . . $ gpiod_line_settings_copy(48e7ea08c6f5ee34).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 57 | { |
| 58 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 59 | |
| 60 | struct gpiod_line_settingscxx . . $ gpiod_line_settings# *copy; |
| 61 | |
| 62 | copy = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*copy)); |
| 63 | if (!copy) |
| 64 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 65 | |
| 66 | memcpycxx . . $ memcpy(cc817cb175f282d).(copy, settings, sizeof(*copy)); |
| 67 | |
| 68 | return copy; |
| 69 | } |
| 70 | |
| 71 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int |
| 72 | gpiod_line_settings_set_directioncxx . . $ gpiod_line_settings_set_direction(882a7f84f8e9d874).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 73 | enum gpiod_line_directioncxx . . $ gpiod_line_direction# direction) |
| 74 | { |
| 75 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 76 | |
| 77 | switch (direction) { |
| 78 | case GPIOD_LINE_DIRECTION_INPUTcxx . . $ GPIOD_LINE_DIRECTION_INPUT.: |
| 79 | case GPIOD_LINE_DIRECTION_OUTPUTcxx . . $ GPIOD_LINE_DIRECTION_OUTPUT.: |
| 80 | case GPIOD_LINE_DIRECTION_AS_IScxx . . $ GPIOD_LINE_DIRECTION_AS_IS.: |
| 81 | settings->directioncxx . . $ gpiod_line_settings#direction. = direction; |
| 82 | break; |
| 83 | default: |
| 84 | settings->directioncxx . . $ gpiod_line_settings#direction. = GPIOD_LINE_DIRECTION_AS_IScxx . . $ GPIOD_LINE_DIRECTION_AS_IS.; |
| 85 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 86 | return -1; |
| 87 | } |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! enum gpiod_line_directioncxx . . $ gpiod_line_direction# |
| 93 | gpiod_line_settings_get_directioncxx . . $ gpiod_line_settings_get_direction(20fd03fc78c7b03e).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 94 | { |
| 95 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 96 | |
| 97 | return settings->directioncxx . . $ gpiod_line_settings#direction.; |
| 98 | } |
| 99 | |
| 100 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int |
| 101 | gpiod_line_settings_set_edge_detectioncxx . . $ gpiod_line_settings_set_edge_detection(886906d11ef93c1e).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 102 | enum gpiod_line_edgecxx . . $ gpiod_line_edge# edge) |
| 103 | { |
| 104 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 105 | |
| 106 | switch (edge) { |
| 107 | case GPIOD_LINE_EDGE_NONEcxx . . $ GPIOD_LINE_EDGE_NONE.: |
| 108 | case GPIOD_LINE_EDGE_RISINGcxx . . $ GPIOD_LINE_EDGE_RISING.: |
| 109 | case GPIOD_LINE_EDGE_FALLINGcxx . . $ GPIOD_LINE_EDGE_FALLING.: |
| 110 | case GPIOD_LINE_EDGE_BOTHcxx . . $ GPIOD_LINE_EDGE_BOTH.: |
| 111 | settings->edge_detectioncxx . . $ gpiod_line_settings#edge_detection. = edge; |
| 112 | break; |
| 113 | default: |
| 114 | settings->edge_detectioncxx . . $ gpiod_line_settings#edge_detection. = GPIOD_LINE_EDGE_NONEcxx . . $ GPIOD_LINE_EDGE_NONE.; |
| 115 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! enum gpiod_line_edgecxx . . $ gpiod_line_edge# |
| 123 | gpiod_line_settings_get_edge_detectioncxx . . $ gpiod_line_settings_get_edge_detection(6b75dd760a1e8450).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 124 | { |
| 125 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 126 | |
| 127 | return settings->edge_detectioncxx . . $ gpiod_line_settings#edge_detection.; |
| 128 | } |
| 129 | |
| 130 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int gpiod_line_settings_set_biascxx . . $ gpiod_line_settings_set_bias(2d98d7c8fce6e3a8).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 131 | enum gpiod_line_biascxx . . $ gpiod_line_bias# bias) |
| 132 | { |
| 133 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 134 | |
| 135 | switch (bias) { |
| 136 | case GPIOD_LINE_BIAS_AS_IScxx . . $ GPIOD_LINE_BIAS_AS_IS.: |
| 137 | case GPIOD_LINE_BIAS_DISABLEDcxx . . $ GPIOD_LINE_BIAS_DISABLED.: |
| 138 | case GPIOD_LINE_BIAS_PULL_UPcxx . . $ GPIOD_LINE_BIAS_PULL_UP.: |
| 139 | case GPIOD_LINE_BIAS_PULL_DOWNcxx . . $ GPIOD_LINE_BIAS_PULL_DOWN.: |
| 140 | settings->biascxx . . $ gpiod_line_settings#bias. = bias; |
| 141 | break; |
| 142 | default: |
| 143 | settings->biascxx . . $ gpiod_line_settings#bias. = GPIOD_LINE_BIAS_AS_IScxx . . $ GPIOD_LINE_BIAS_AS_IS.; |
| 144 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 145 | return -1; |
| 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! enum gpiod_line_biascxx . . $ gpiod_line_bias# |
| 152 | gpiod_line_settings_get_biascxx . . $ gpiod_line_settings_get_bias(2211030472337353).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 153 | { |
| 154 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 155 | |
| 156 | return settings->biascxx . . $ gpiod_line_settings#bias.; |
| 157 | } |
| 158 | |
| 159 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int |
| 160 | gpiod_line_settings_set_drivecxx . . $ gpiod_line_settings_set_drive(69827a18c2837745).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 161 | enum gpiod_line_drivecxx . . $ gpiod_line_drive# drive) |
| 162 | { |
| 163 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 164 | |
| 165 | switch (drive) { |
| 166 | case GPIOD_LINE_DRIVE_PUSH_PULLcxx . . $ GPIOD_LINE_DRIVE_PUSH_PULL.: |
| 167 | case GPIOD_LINE_DRIVE_OPEN_DRAINcxx . . $ GPIOD_LINE_DRIVE_OPEN_DRAIN.: |
| 168 | case GPIOD_LINE_DRIVE_OPEN_SOURCEcxx . . $ GPIOD_LINE_DRIVE_OPEN_SOURCE.: |
| 169 | settings->drivecxx . . $ gpiod_line_settings#drive. = drive; |
| 170 | break; |
| 171 | default: |
| 172 | settings->drivecxx . . $ gpiod_line_settings#drive. = GPIOD_LINE_DRIVE_PUSH_PULLcxx . . $ GPIOD_LINE_DRIVE_PUSH_PULL.; |
| 173 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! enum gpiod_line_drivecxx . . $ gpiod_line_drive# |
| 181 | gpiod_line_settings_get_drivecxx . . $ gpiod_line_settings_get_drive(7253675e15045b0a).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 182 | { |
| 183 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 184 | |
| 185 | return settings->drivecxx . . $ gpiod_line_settings#drive.; |
| 186 | } |
| 187 | |
| 188 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! void |
| 189 | gpiod_line_settings_set_active_lowcxx . . $ gpiod_line_settings_set_active_low(92387796f9e502cd).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 190 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! active_low) |
| 191 | { |
| 192 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 193 | |
| 194 | settings->active_lowcxx . . $ gpiod_line_settings#active_low. = active_low; |
| 195 | } |
| 196 | |
| 197 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 198 | gpiod_line_settings_get_active_lowcxx . . $ gpiod_line_settings_get_active_low(f826ec49283cb6f8).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 199 | { |
| 200 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 201 | |
| 202 | return settings->active_lowcxx . . $ gpiod_line_settings#active_low.; |
| 203 | } |
| 204 | |
| 205 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! void |
| 206 | gpiod_line_settings_set_debounce_period_uscxx . . $ gpiod_line_settings_set_debounce_period_us(6c7484882ea4460b).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 207 | unsigned long period) |
| 208 | { |
| 209 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 210 | |
| 211 | settings->debounce_period_uscxx . . $ gpiod_line_settings#debounce_period_us. = period; |
| 212 | } |
| 213 | |
| 214 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! unsigned long |
| 215 | gpiod_line_settings_get_debounce_period_uscxx . . $ gpiod_line_settings_get_debounce_period_us(f5b4f890d2432d8e).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 216 | { |
| 217 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 218 | |
| 219 | return settings->debounce_period_uscxx . . $ gpiod_line_settings#debounce_period_us.; |
| 220 | } |
| 221 | |
| 222 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int |
| 223 | gpiod_line_settings_set_event_clockcxx . . $ gpiod_line_settings_set_event_clock(17365f8e2b24a154).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 224 | enum gpiod_line_clockcxx . . $ gpiod_line_clock# event_clock) |
| 225 | { |
| 226 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 227 | |
| 228 | switch (event_clock) { |
| 229 | case GPIOD_LINE_CLOCK_MONOTONICcxx . . $ GPIOD_LINE_CLOCK_MONOTONIC.: |
| 230 | case GPIOD_LINE_CLOCK_REALTIMEcxx . . $ GPIOD_LINE_CLOCK_REALTIME.: |
| 231 | case GPIOD_LINE_CLOCK_HTEcxx . . $ GPIOD_LINE_CLOCK_HTE.: |
| 232 | settings->event_clockcxx . . $ gpiod_line_settings#event_clock. = event_clock; |
| 233 | break; |
| 234 | default: |
| 235 | settings->event_clockcxx . . $ gpiod_line_settings#event_clock. = GPIOD_LINE_CLOCK_MONOTONICcxx . . $ GPIOD_LINE_CLOCK_MONOTONIC.; |
| 236 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 237 | return -1; |
| 238 | } |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! enum gpiod_line_clockcxx . . $ gpiod_line_clock# |
| 244 | gpiod_line_settings_get_event_clockcxx . . $ gpiod_line_settings_get_event_clock(dd685642e0d57a9c).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 245 | { |
| 246 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 247 | |
| 248 | return settings->event_clockcxx . . $ gpiod_line_settings#event_clock.; |
| 249 | } |
| 250 | |
| 251 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int |
| 252 | gpiod_line_settings_set_output_valuecxx . . $ gpiod_line_settings_set_output_value(d19601ab04d8b8f9).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings, |
| 253 | enum gpiod_line_valuecxx . . $ gpiod_line_value# value) |
| 254 | { |
| 255 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 256 | |
| 257 | return gpiod_set_output_valuecxx . . $ gpiod_set_output_value(eb3e60c472d1bd0b).(value, &settings->output_valuecxx . . $ gpiod_line_settings#output_value.); |
| 258 | } |
| 259 | |
| 260 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! enum gpiod_line_valuecxx . . $ gpiod_line_value# |
| 261 | gpiod_line_settings_get_output_valuecxx . . $ gpiod_line_settings_get_output_value(10f0a367a2836eed).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 262 | { |
| 263 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(settings); |
| 264 | |
| 265 | return settings->output_valuecxx . . $ gpiod_line_settings#output_value.; |
| 266 | } |