From: Segwon Date: Thu, 14 Dec 2017 11:13:04 +0000 (+0900) Subject: gpio: enhance exception handling in interface function X-Git-Tag: submit/tizen_4.0/20171220.125806^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4e217917479bccac3d79b1312c249cbf72ae9593;p=platform%2Fcore%2Fapi%2Fperipheral-io.git gpio: enhance exception handling in interface function - GPIO set type functions require prerequisites 1) [edge_mode] [direction] none ----------------------> in, out (O) rising, falling, both -----> in (O) \ ---> out (X) 2) [direction] [edge_mode] in ------------------------> none, rising, falling, both (O) out -----------------------> none (O) \ ----------------> rising, falling, both (X) 3) [direction] [value] in ------------------------> read (O) \ ----------------> write (X) out -----------------------> read, write (O) Change-Id: I72f8557568916b01c1e2e9edef79ed79f5bb20e6 Signed-off-by: Segwon --- diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 4ca79e4..119230d 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -40,8 +40,20 @@ int peripheral_interface_gpio_set_initial_direction_into_handle(peripheral_gpio_ return PERIPHERAL_ERROR_IO_ERROR; } +/* + * [edge_mode] [direction] + * + * none -----------------> in, out (O) + * + * rising, falling, both ---------> in (O) + * \ + * -----> out (X) + */ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { + RETV_IF(gpio->direction == direction, PERIPHERAL_ERROR_NONE); + RETV_IF(gpio->edge != PERIPHERAL_GPIO_EDGE_NONE, PERIPHERAL_ERROR_IO_ERROR); + static predefined_type_s types[3] = { {"in", 2}, {"high", 4}, @@ -81,8 +93,20 @@ int peripheral_interface_gpio_set_initial_edge_into_handle(peripheral_gpio_h gpi return PERIPHERAL_ERROR_IO_ERROR; } +/* + * [direction] [edge_mode] + * + * in ---------> none, rising, falling, both (O) + * + * out --------> none (O) + * \ + * -----> rising, falling, both (X) + */ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { + RETV_IF(gpio->edge == edge, PERIPHERAL_ERROR_NONE); + RETV_IF(gpio->direction != PERIPHERAL_GPIO_DIRECTION_IN, PERIPHERAL_ERROR_IO_ERROR); + static predefined_type_s types[4] = { {"none", 4}, {"rising", 6}, @@ -98,8 +122,16 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g return PERIPHERAL_ERROR_NONE; } +/* + * [direction] [value] + * + * in ---------> write (X) + * out --------> write (O) + */ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) { + RETV_IF(gpio->direction == PERIPHERAL_GPIO_DIRECTION_IN, PERIPHERAL_ERROR_IO_ERROR); + static predefined_type_s types[2] = { {"0", 1}, {"1", 1} @@ -111,6 +143,12 @@ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) return PERIPHERAL_ERROR_NONE; } +/* + * [direction] [value] + * + * in ---------> read (O) + * out --------> read (O) + */ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) { int ret; @@ -151,4 +189,4 @@ int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio) // TODO: unset interrupted callback function return PERIPHERAL_ERROR_NONE; -} \ No newline at end of file +}