gpio: add the GPIO properties getter functions 79/168379/1 devel
authorSegwon <segwon.han@samsung.com>
Fri, 26 Jan 2018 06:18:52 +0000 (15:18 +0900)
committerSegwon <segwon.han@samsung.com>
Fri, 26 Jan 2018 06:18:52 +0000 (15:18 +0900)
 - peripheral_interface_gpio_get_direction()
 - peripheral_interface_gpio_get_edge_mode()
 - add enum - PERIPHERAL_GPIO_DIRECTION_OUT

Change-Id: I055e9bd63935550728b1a704ae643f8072ed2eb4
Signed-off-by: Segwon <segwon.han@samsung.com>
include/interface/peripheral_interface_gpio.h
include/peripheral_io.h
src/interface/peripheral_interface_gpio.c

index bfc7b09..67b8107 100644 (file)
@@ -25,9 +25,11 @@ void peripheral_interface_gpio_close(peripheral_gpio_h gpio);
 
 int peripheral_interface_gpio_set_initial_edge_into_handle(peripheral_gpio_h gpio);
 int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
+int peripheral_interface_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *out_edge);
 
 int peripheral_interface_gpio_set_initial_direction_into_handle(peripheral_gpio_h gpio);
 int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
+int peripheral_interface_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *out_direction);
 
 int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value);
 int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value);
index 747fc34..9fc1308 100644 (file)
@@ -65,9 +65,10 @@ typedef enum {
  * @since_tizen 4.0
  */
 typedef enum {
-       PERIPHERAL_GPIO_DIRECTION_IN = 0,              /**< Input Mode */
+       PERIPHERAL_GPIO_DIRECTION_IN = 0,              /**< Input mode */
        PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH,  /**< Output mode with high value */
        PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW,   /**< Output mode with low value */
+       PERIPHERAL_GPIO_DIRECTION_OUT = PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW, /**< Output mode */
 } peripheral_gpio_direction_e;
 
 /**
index 90c2a21..c6d23b1 100644 (file)
@@ -72,6 +72,34 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g
        return PERIPHERAL_ERROR_NONE;
 }
 
+int peripheral_interface_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *out_direction)
+{
+       static predefined_type_s types[2] = {
+               {"in",  2},
+               {"out", 3}
+       };
+
+       int ret;
+       char gpio_buf[GPIO_BUFFER_MAX] = {0, };
+
+       lseek(gpio->fd_direction, 0, SEEK_SET);
+       ret = read(gpio->fd_direction, &gpio_buf, GPIO_BUFFER_MAX);
+       CHECK_ERROR(ret < 0);
+
+       for (int index = 0; index < 2; index++) {
+               if (!strncmp(gpio_buf, types[index].type, types[index].len)) {
+                       if (index == 0) {
+                               *out_direction = PERIPHERAL_GPIO_DIRECTION_IN;
+                       } else {
+                               *out_direction = PERIPHERAL_GPIO_DIRECTION_OUT;
+                       }
+                       break;
+               }
+       }
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
 int peripheral_interface_gpio_set_initial_edge_into_handle(peripheral_gpio_h gpio)
 {
        static predefined_type_s types[4] = {
@@ -126,6 +154,32 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g
        return PERIPHERAL_ERROR_NONE;
 }
 
+int peripheral_interface_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *out_edge)
+{
+       static predefined_type_s types[4] = {
+               {"none",    4},
+               {"rising",  6},
+               {"falling", 7},
+               {"both",    4}
+       };
+
+       int ret;
+       char gpio_buf[GPIO_BUFFER_MAX] = {0, };
+
+       lseek(gpio->fd_edge, 0, SEEK_SET);
+       ret = read(gpio->fd_edge, &gpio_buf, GPIO_BUFFER_MAX);
+       CHECK_ERROR(ret < 0);
+
+       for (int index = 0; index < 4; index++) {
+               if (!strncmp(gpio_buf, types[index].type, types[index].len)){
+                       *out_edge = (peripheral_gpio_edge_e)index;
+                       return PERIPHERAL_ERROR_NONE;
+               }
+       }
+
+       return PERIPHERAL_ERROR_UNKNOWN;
+}
+
 /*
  * [direction]     [value]
  *