interface: unuse the enum types defined in the interface 71/159971/4
authorSegwon <segwon.han@samsung.com>
Tue, 14 Nov 2017 03:55:52 +0000 (12:55 +0900)
committerSegwon <segwon.han@samsung.com>
Tue, 14 Nov 2017 08:20:38 +0000 (17:20 +0900)
 - replace with enum types provided by the API
 - remove enum list
    1) gpio_direction_e
    2) gpio_edge_e
    3) pwm_polarity_e
    4) uart_baud_rate_e
    5) uart_byte_size_e
    6) uart_parity_e
    7) uart_stop_bits_e

Change-Id: Id70350fabf29b18c7b440be8bbfdd4b99ed3b98d
Signed-off-by: Segwon <segwon.han@samsung.com>
include/interface/peripheral_interface_gpio.h
include/interface/peripheral_interface_pwm.h
include/interface/peripheral_interface_spi.h
include/interface/peripheral_interface_uart.h
src/interface/peripheral_interface_gpio.c
src/interface/peripheral_interface_pwm.c
src/interface/peripheral_interface_spi.c
src/interface/peripheral_interface_uart.c

index cf5d76c..9792a1c 100644 (file)
 #define SYSFS_GPIO_DIR "/sys/class/gpio"
 #define GPIO_BUFFER_MAX 64
 
-typedef enum {
-       GPIO_DIRECTION_IN = 0,
-       GPIO_DIRECTION_OUT_HIGH = 1,
-       GPIO_DIRECTION_OUT_LOW = 2,
-} gpio_direction_e;
-
-typedef enum {
-       GPIO_EDGE_NONE = 0,
-       GPIO_EDGE_RISING = 1,
-       GPIO_EDGE_FALLING = 2,
-       GPIO_EDGE_BOTH = 3,
-} gpio_edge_e;
-
 int peripheral_interface_gpio_close(peripheral_gpio_h gpio);
-int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge);
-int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir);
+int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
+int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
 int peripheral_interface_gpio_write(peripheral_gpio_h gpio, int value);
 int peripheral_interface_gpio_read(peripheral_gpio_h gpio, int *value);
 
index 833de2b..e45c2d6 100644 (file)
 #include "peripheral_io.h"
 
 /**
- * @brief Enumeration for Polarity
- */
-typedef enum {
-       PWM_POLARITY_NORMAL = 0,
-       PWM_POLARITY_INVERSED,
-} pwm_polarity_e;
-
-
-/**
 * @brief pwm_close() deinit pwm pin.
 *
 * @param[in] chip pwm chip number
@@ -65,7 +56,7 @@ int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle
 * @param[in] polarity pwm polarity
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity);
+int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity);
 
 /**
 * @brief pwm_set_enable() sets the pwm state.
index 937caa7..2cee142 100644 (file)
@@ -20,8 +20,8 @@
 #include "peripheral_io.h"
 
 int peripheral_interface_spi_close(peripheral_spi_h spi);
-int peripheral_interface_spi_set_mode(peripheral_spi_h spi, unsigned char mode);
-int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb);
+int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
+int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order);
 int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
 int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, unsigned int freq);
 int peripheral_interface_spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length);
index c9a8c30..5541618 100644 (file)
 #include <stdint.h>
 
 /**
- * @brief Enumeration for Baud Rate
- */
-typedef enum {
-       UART_BAUD_RATE_0 = 0,
-       UART_BAUD_RATE_50,
-       UART_BAUD_RATE_75,
-       UART_BAUD_RATE_110,
-       UART_BAUD_RATE_134,
-       UART_BAUD_RATE_150,
-       UART_BAUD_RATE_200,
-       UART_BAUD_RATE_300,
-       UART_BAUD_RATE_600,
-       UART_BAUD_RATE_1200,
-       UART_BAUD_RATE_1800,
-       UART_BAUD_RATE_2400,
-       UART_BAUD_RATE_4800,
-       UART_BAUD_RATE_9600,
-       UART_BAUD_RATE_19200,
-       UART_BAUD_RATE_38400,
-       UART_BAUD_RATE_57600,
-       UART_BAUD_RATE_115200,
-       UART_BAUD_RATE_230400
-} uart_baud_rate_e;
-
-/**
- * @brief Enumeration for Byte Size
- */
-typedef enum {
-       UART_BYTE_SIZE_5BIT = 0,
-       UART_BYTE_SIZE_6BIT,
-       UART_BYTE_SIZE_7BIT,
-       UART_BYTE_SIZE_8BIT
-} uart_byte_size_e;
-
-/**
- * @brief Enumeration of Parity Bit
- */
-typedef enum {
-       UART_PARITY_NONE = 0,
-       UART_PARITY_EVEN,
-       UART_PARITY_ODD
-} uart_parity_e;
-
-/**
- * @brief Enumeration for Stop Bits
- */
-typedef enum {
-       UART_STOP_BITS_1BIT = 0,
-       UART_STOP_BITS_2BIT
-} uart_stop_bits_e;
-
-/**
 * @brief uart_close() closes uart port.
 *
 * @param[in] file_hndl handle of uart_context
@@ -96,7 +44,7 @@ int peripheral_interface_uart_flush(peripheral_uart_h uart);
 * @param[in] baud uart baud rate
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud);
+int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud);
 
 /**
 * @brief peripheral_bus_uart_set_byte_size() set byte size.
@@ -105,7 +53,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_ra
 * @param[in] byte_size uart byte size
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size);
+int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size);
 
 /**
 * @brief peripheral_bus_uart_set_parity() set parity bit.
@@ -114,7 +62,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_si
 * @param[in] parity uart parity type (even/odd/none)
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e parity);
+int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity);
 
 /**
 * @brief peripheral_bus_uart_set_stop_bits() set stop bits.
@@ -123,7 +71,7 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e p
 * @param[in] stop_bits uart stop bits
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits);
+int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits);
 
 /**
 * @brief uart_set_flow_control() set flow control settings.
@@ -133,7 +81,7 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bi
 * @param[in] rtscts rts/cts
 * @return On success, 0 is returned. On failure, a negative value is returned.
 */
-int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts);
+int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e xonxoff, peripheral_uart_hardware_flow_control_e rtscts);
 
 /**
 * @brief uart_read() reads data over uart bus.
index e4620ca..24c1837 100644 (file)
 
 #define MAX_ERR_LEN 255
 
-int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir)
+int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
 {
        int status;
 
-       if (dir == GPIO_DIRECTION_IN)
+       if (direction == PERIPHERAL_GPIO_DIRECTION_IN)
                status = write(gpio->fd_direction, "in", strlen("in")+1);
-       else if (dir == GPIO_DIRECTION_OUT_HIGH)
+       else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH)
                status = write(gpio->fd_direction, "high", strlen("high")+1);
-       else if (dir == GPIO_DIRECTION_OUT_LOW)
+       else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW)
                status = write(gpio->fd_direction, "low", strlen("low")+1);
        else {
                _E("Error: gpio direction is wrong\n");
@@ -51,17 +51,17 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, gpio_directi
        return 0;
 }
 
-int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge)
+int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
 {
        int status;
 
-       if (edge == GPIO_EDGE_NONE)
+       if (edge == PERIPHERAL_GPIO_EDGE_NONE)
                status = write(gpio->fd_edge, "none", strlen("none")+1);
-       else if (edge == GPIO_EDGE_RISING)
+       else if (edge == PERIPHERAL_GPIO_EDGE_RISING)
                status = write(gpio->fd_edge, "rising", strlen("rising")+1);
-       else if (edge == GPIO_EDGE_FALLING)
+       else if (edge == PERIPHERAL_GPIO_EDGE_FALLING)
                status = write(gpio->fd_edge, "falling", strlen("falling")+1);
-       else if (edge == GPIO_EDGE_BOTH)
+       else if (edge == PERIPHERAL_GPIO_EDGE_BOTH)
                status = write(gpio->fd_edge, "both", strlen("both")+1);
        else {
                _E("Error: gpio edge is wrong\n");
index a5cae4d..da6cbca 100644 (file)
@@ -93,13 +93,13 @@ int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle
        return 0;
 }
 
-int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity)
+int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
 {
        int status;
 
-       if (polarity == PWM_POLARITY_NORMAL)
+       if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH)
                status = write(pwm->fd_polarity, "normal", strlen("normal")+1);
-       else if (polarity == PWM_POLARITY_INVERSED)
+       else if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_LOW)
                status = write(pwm->fd_polarity, "inversed", strlen("inversed")+1);
        else {
                _E("Invalid pwm polarity : %d", polarity);
index 1296d9f..1ea88de 100644 (file)
@@ -50,7 +50,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi)
        return 0;
 }
 
-int peripheral_interface_spi_set_mode(peripheral_spi_h spi, unsigned char mode)
+int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
 {
        int status;
 
@@ -68,18 +68,18 @@ int peripheral_interface_spi_set_mode(peripheral_spi_h spi, unsigned char mode)
        return 0;
 }
 
-int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb)
+int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order)
 {
        int status;
 
-       _D("fd : %d, lsb : %d", spi->fd, lsb);
+       _D("fd : %d, lsb : %d", spi->fd, bit_order);
        RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
 
-       status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &lsb);
+       status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order);
        if (status < 0) {
                char errmsg[MAX_ERR_LEN];
                strerror_r(errno, errmsg, MAX_ERR_LEN);
-               _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", lsb, spi->fd, errmsg);
+               _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", bit_order, spi->fd, errmsg);
                return -EIO;
        }
 
index c563fc6..49f9346 100644 (file)
@@ -103,7 +103,7 @@ int peripheral_interface_uart_flush(peripheral_uart_h uart)
        return 0;
 }
 
-int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud)
+int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud)
 {
        int ret;
        struct termios tio;
@@ -116,7 +116,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_ra
                return -EINVAL;
        }
 
-       if (baud > UART_BAUD_RATE_230400) {
+       if (baud > PERIPHERAL_UART_BAUD_RATE_230400) {
                _E("Invalid parameter");
                return -EINVAL;
        }
@@ -147,7 +147,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_ra
        return 0;
 }
 
-int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size)
+int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size)
 {
        int ret;
        struct termios tio;
@@ -159,7 +159,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_si
                return -EINVAL;
        }
 
-       if (byte_size > UART_BYTE_SIZE_8BIT) {
+       if (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT) {
                _E("Invalid bytesize parameter");
                return -EINVAL;
        }
@@ -189,7 +189,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_si
        return 0;
 }
 
-int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e parity)
+int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity)
 {
        int ret;
        struct termios tio;
@@ -211,15 +211,15 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e p
 
        /* set parity info */
        switch (parity) {
-       case UART_PARITY_EVEN:
+       case PERIPHERAL_UART_PARITY_EVEN:
                tio.c_cflag |= PARENB;
                tio.c_cflag &= ~PARODD;
                break;
-       case UART_PARITY_ODD:
+       case PERIPHERAL_UART_PARITY_ODD:
                tio.c_cflag |= PARENB;
                tio.c_cflag |= PARODD;
                break;
-       case UART_PARITY_NONE:
+       case PERIPHERAL_UART_PARITY_NONE:
        default:
                tio.c_cflag &= ~PARENB;
                tio.c_cflag &= ~PARODD;
@@ -238,7 +238,7 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e p
        return 0;
 }
 
-int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits)
+int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits)
 {
        int ret;
        struct termios tio;
@@ -260,10 +260,10 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bi
 
        /* set stop bit */
        switch (stop_bits) {
-       case UART_STOP_BITS_1BIT:
+       case PERIPHERAL_UART_STOP_BITS_1BIT:
                tio.c_cflag &= ~CSTOPB;
                break;
-       case UART_STOP_BITS_2BIT:
+       case PERIPHERAL_UART_STOP_BITS_2BIT:
                tio.c_cflag |= CSTOPB;
                break;
        default:
@@ -283,7 +283,7 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bi
        return 0;
 }
 
-int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts)
+int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e xonxoff, peripheral_uart_hardware_flow_control_e rtscts)
 {
        int ret;
        struct termios tio;
@@ -303,17 +303,19 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, bool xonx
                return -1;
        }
 
-       /* rtscts => 1: rts/cts on, 0: off */
-       if (rtscts)
+       if (rtscts == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS)
                tio.c_cflag |= CRTSCTS;
-       else
+       else if (rtscts == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE)
                tio.c_cflag &= ~CRTSCTS;
+       else
+               return -EINVAL;
 
-       /* xonxoff => 1: xon/xoff on, 0: off */
-       if (xonxoff)
+       if (xonxoff == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF)
                tio.c_iflag |= (IXON | IXOFF | IXANY);
-       else
+       else if (xonxoff == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE)
                tio.c_iflag &= ~(IXON | IXOFF | IXANY);
+       else
+               return -EINVAL;
 
        ret = tcsetattr(uart->fd, TCSANOW, &tio);
        if (ret) {