From 2515a3f9efd720320211ace2f6bf80698e2c7523 Mon Sep 17 00:00:00 2001
From: Hauke Petersen <hauke.petersen@fu-berlin.de>
Date: Sat, 20 Feb 2016 16:48:24 +0100
Subject: [PATCH] drivers/gpio: changed the way the mode is configured

- joined pushpull and dir into one single mode parameter
- with this enabled the configuration of open-drain mode
---
 drivers/include/periph/gpio.h | 38 +++++++++++++++++------------------
 drivers/include/saul/periph.h |  3 +--
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/include/periph/gpio.h b/drivers/include/periph/gpio.h
index c91dda1f64..eb7f0efa85 100644
--- a/drivers/include/periph/gpio.h
+++ b/drivers/include/periph/gpio.h
@@ -86,24 +86,24 @@ typedef unsigned int gpio_t;
 #endif
 
 /**
- * @brief   Definition of available pin directions
- */
-#ifndef HAVE_GPIO_DIR_T
-typedef enum {
-    GPIO_DIR_IN = 0,        /**< configure pin as input */
-    GPIO_DIR_OUT = 1        /**< configure pin as output */
-} gpio_dir_t;
-#endif
-
-/**
- * @brief   Definition of pull-up/pull-down modes
+ * @brief   Available pin modes
+ *
+ * Generally, a pin can be configured to be input or output. In output mode, a
+ * pin can further be put into push-pull or open drain configuration. Though
+ * this is supported by most platforms, this is not always the case, so driver
+ * implementations may return an error code if a mode is not supported.
  */
-#ifndef HAVE_GPIO_PP_T
+#ifndef HAVE_GPIO_MODE_T
 typedef enum {
-    GPIO_NOPULL = 0,        /**< do not use internal pull resistors */
-    GPIO_PULLUP = 1,        /**< enable internal pull-up resistor */
-    GPIO_PULLDOWN = 2       /**< enable internal pull-down resistor */
-} gpio_pp_t;
+    GPIO_IN ,               /**< configure as input without pull resistor */
+    GPIO_IN_PD,             /**< configure as input with pull-down resistor */
+    GPIO_IN_PU,             /**< configure as input with pull-up resistor */
+    GPIO_OUT,               /**< configure as output in push-pull mode */
+    GPIO_OD,                /**< configure as output in open-drain mode without
+                             *   pull resistor */
+    GPIO_OD_PU              /**< configure as output in open-drain mode with
+                             *   pull resistor enabled */
+} gpio_mode_t;
 #endif
 
 /**
@@ -146,7 +146,7 @@ typedef struct {
  * @return              0 on success
  * @return              -1 on error
  */
-int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pullup);
+int gpio_init(gpio_t pin, gpio_mode_t mode);
 
 /**
  * @brief   Initialize a GPIO pin for external interrupt usage
@@ -165,8 +165,8 @@ int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pullup);
  * @return              0 on success
  * @return              -1 on error
  */
-int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank,
-                    gpio_cb_t cb, void *arg);
+int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
+                  gpio_cb_t cb, void *arg);
 
 /**
  * @brief   Enable pin's interrupt if configured as interrupt source
diff --git a/drivers/include/saul/periph.h b/drivers/include/saul/periph.h
index 98e47dd38d..4f49cdf83d 100644
--- a/drivers/include/saul/periph.h
+++ b/drivers/include/saul/periph.h
@@ -31,8 +31,7 @@ extern "C" {
 typedef struct {
     const char *name;       /**< name of the device connected to this pin */
     gpio_t pin;             /**< GPIO pin to initialize and expose */
-    gpio_dir_t dir;         /**< use GPIO as input or output */
-    gpio_pp_t pull;         /**< define the pull-up/pull-down mode */
+    gpio_mode_t mode;       /**< pin mode to use */
 } saul_gpio_params_t;
 
 #ifdef __cplusplus
-- 
GitLab