aboutsummaryrefslogtreecommitdiff
path: root/lib/libgpio/libgpio.h
diff options
context:
space:
mode:
authorRui Paulo <rpaulo@FreeBSD.org>2014-11-24 21:49:40 +0000
committerRui Paulo <rpaulo@FreeBSD.org>2014-11-24 21:49:40 +0000
commitf12128e4dfcb41c597fb9d0de1403026e8fb2ec1 (patch)
tree07e4ac9a29efb8adc16692cb4dd944b03139a9cc /lib/libgpio/libgpio.h
parenta736c8ae2a3b940f89189151f3e11113a83300a7 (diff)
downloadsrc-f12128e4dfcb41c597fb9d0de1403026e8fb2ec1.tar.gz
src-f12128e4dfcb41c597fb9d0de1403026e8fb2ec1.zip
Import libgpio.
This is a thin wrapper around the kernel interface which should make it easier to write GPIO applications. gpioctl(8) will be converted to use this library in a separate commit. Differential Revision: https://reviews.freebsd.org/D1183 Reviewed by: adrian, loos Discussed on: arm@, embedded@ Relnotes: yes
Notes
Notes: svn path=/head/; revision=274987
Diffstat (limited to 'lib/libgpio/libgpio.h')
-rw-r--r--lib/libgpio/libgpio.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/lib/libgpio/libgpio.h b/lib/libgpio/libgpio.h
new file mode 100644
index 000000000000..b7486ebc5472
--- /dev/null
+++ b/lib/libgpio/libgpio.h
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2013-2014 Rui Paulo <rpaulo@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBGPIO_H_
+#define _LIBGPIO_H_
+
+#include <sys/gpio.h>
+
+__BEGIN_DECLS
+
+#define GPIO_INVALID_HANDLE -1
+typedef int gpio_handle_t;
+typedef uint32_t gpio_pin_t;
+
+/*
+ * Structure describing a GPIO pin configuration.
+ */
+typedef struct {
+ gpio_pin_t g_pin;
+ char g_name[GPIOMAXNAME];
+ uint32_t g_caps;
+ uint32_t g_flags;
+} gpio_config_t;
+
+typedef enum {
+ GPIO_VALUE_INVALID = -1,
+ GPIO_VALUE_LOW = GPIO_PIN_LOW,
+ GPIO_VALUE_HIGH = GPIO_PIN_HIGH
+} gpio_value_t;
+
+/*
+ * Open /dev/gpiocN or a specific device.
+ */
+gpio_handle_t gpio_open(unsigned int);
+gpio_handle_t gpio_open_device(const char *);
+void gpio_close(gpio_handle_t);
+/*
+ * Get a list of all the GPIO pins.
+ */
+int gpio_pin_list(gpio_handle_t, gpio_config_t **);
+/*
+ * GPIO pin configuration.
+ *
+ * Retrieve the configuration of a specific GPIO pin. The pin number is
+ * passed through the gpio_config_t structure.
+ */
+int gpio_pin_config(gpio_handle_t, gpio_config_t *);
+/*
+ * Sets the GPIO flags on a specific GPIO pin. The pin number and the flags
+ * to be set are passed through the gpio_config_t structure.
+ */
+int gpio_pin_set_flags(gpio_handle_t, gpio_config_t *);
+/*
+ * GPIO pin values.
+ */
+int gpio_pin_get(gpio_handle_t, gpio_pin_t);
+int gpio_pin_set(gpio_handle_t, gpio_pin_t, int);
+int gpio_pin_toggle(gpio_handle_t, gpio_pin_t);
+/*
+ * Helper functions to set pin states.
+ */
+int gpio_pin_low(gpio_handle_t, gpio_pin_t);
+int gpio_pin_high(gpio_handle_t, gpio_pin_t);
+/*
+ * Helper functions to configure pins.
+ */
+int gpio_pin_input(gpio_handle_t, gpio_pin_t);
+int gpio_pin_output(gpio_handle_t, gpio_pin_t);
+int gpio_pin_opendrain(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pushpull(gpio_handle_t, gpio_pin_t);
+int gpio_pin_tristate(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pullup(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pulldown(gpio_handle_t, gpio_pin_t);
+int gpio_pin_invin(gpio_handle_t, gpio_pin_t);
+int gpio_pin_invout(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pulsate(gpio_handle_t, gpio_pin_t);
+
+__END_DECLS
+
+#endif /* _LIBGPIO_H_ */