0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef _GPIO_UTILS_H_
0013 #define _GPIO_UTILS_H_
0014
0015 #include <stdbool.h>
0016 #include <string.h>
0017 #include <linux/types.h>
0018
0019 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
0020
0021 static inline int check_prefix(const char *str, const char *prefix)
0022 {
0023 return strlen(str) > strlen(prefix) &&
0024 strncmp(str, prefix, strlen(prefix)) == 0;
0025 }
0026
0027 int gpiotools_request_line(const char *device_name,
0028 unsigned int *lines,
0029 unsigned int num_lines,
0030 struct gpio_v2_line_config *config,
0031 const char *consumer);
0032 int gpiotools_set_values(const int fd, struct gpio_v2_line_values *values);
0033 int gpiotools_get_values(const int fd, struct gpio_v2_line_values *values);
0034 int gpiotools_release_line(const int fd);
0035
0036 int gpiotools_get(const char *device_name, unsigned int line);
0037 int gpiotools_gets(const char *device_name, unsigned int *lines,
0038 unsigned int num_lines, unsigned int *values);
0039 int gpiotools_set(const char *device_name, unsigned int line,
0040 unsigned int value);
0041 int gpiotools_sets(const char *device_name, unsigned int *lines,
0042 unsigned int num_lines, unsigned int *values);
0043
0044
0045 static inline void gpiotools_set_bit(__u64 *b, int n)
0046 {
0047 *b |= _BITULL(n);
0048 }
0049
0050 static inline void gpiotools_change_bit(__u64 *b, int n)
0051 {
0052 *b ^= _BITULL(n);
0053 }
0054
0055 static inline void gpiotools_clear_bit(__u64 *b, int n)
0056 {
0057 *b &= ~_BITULL(n);
0058 }
0059
0060 static inline int gpiotools_test_bit(__u64 b, int n)
0061 {
0062 return !!(b & _BITULL(n));
0063 }
0064
0065 static inline void gpiotools_assign_bit(__u64 *b, int n, bool value)
0066 {
0067 if (value)
0068 gpiotools_set_bit(b, n);
0069 else
0070 gpiotools_clear_bit(b, n);
0071 }
0072
0073 #endif