2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "peripheral_interface_gpio.h"
19 #define MAX_ERR_LEN 255
21 int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
23 static predefined_type_s types[3] = {
29 int ret = write(gpio->fd_direction, types[direction].type, types[direction].len);
30 CHECK_ERROR(ret != types[direction].len);
35 int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
37 static predefined_type_s types[4] = {
44 int ret = write(gpio->fd_edge, types[edge].type, types[edge].len);
45 CHECK_ERROR(ret != types[edge].len);
50 int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value)
52 static predefined_type_s types[2] = {
57 int ret = write(gpio->fd_value, types[value].type, types[value].len);
58 CHECK_ERROR(ret != types[value].len);
63 int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
67 char gpio_buf[GPIO_BUFFER_MAX] = {0, };
69 ret = read(gpio->fd_value, &gpio_buf, length);
70 CHECK_ERROR(ret != length);
72 if (gpio_buf[0] == '0')
74 else if (gpio_buf[0] == '1')
77 _E("Error: gpio value is error \n");
83 int peripheral_interface_gpio_close(peripheral_gpio_h gpio)
87 ret = close(gpio->fd_direction);
88 CHECK_ERROR(ret != 0);
90 ret = close(gpio->fd_edge);
91 CHECK_ERROR(ret != 0);
93 ret = close(gpio->fd_value);
94 CHECK_ERROR(ret != 0);
99 int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio)
101 // TODO: set interrupted callback function
106 int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio)
108 // TODO: unset interrupted callback function