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 int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
21 static predefined_type_s types[3] = {
27 int ret = write(gpio->fd_direction, types[direction].type, types[direction].len);
28 CHECK_ERROR(ret != types[direction].len);
33 int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
35 static predefined_type_s types[4] = {
42 int ret = write(gpio->fd_edge, types[edge].type, types[edge].len);
43 CHECK_ERROR(ret != types[edge].len);
48 int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value)
50 static predefined_type_s types[2] = {
55 int ret = write(gpio->fd_value, types[value].type, types[value].len);
56 CHECK_ERROR(ret != types[value].len);
61 int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
65 char gpio_buf[GPIO_BUFFER_MAX] = {0, };
67 ret = read(gpio->fd_value, &gpio_buf, length);
68 CHECK_ERROR(ret != length);
70 if (gpio_buf[0] == '0')
72 else if (gpio_buf[0] == '1')
75 _E("Error: gpio value is error \n");
81 int peripheral_interface_gpio_close(peripheral_gpio_h gpio)
85 ret = close(gpio->fd_direction);
86 CHECK_ERROR(ret != 0);
88 ret = close(gpio->fd_edge);
89 CHECK_ERROR(ret != 0);
91 ret = close(gpio->fd_value);
92 CHECK_ERROR(ret != 0);
97 int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio)
99 // TODO: set interrupted callback function
104 int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio)
106 // TODO: unset interrupted callback function