#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);
#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] 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.
#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);
#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] 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.
* @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.
* @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.
* @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.
* @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.
#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");
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");
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);
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;
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;
}
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;
return -EINVAL;
}
- if (baud > UART_BAUD_RATE_230400) {
+ if (baud > PERIPHERAL_UART_BAUD_RATE_230400) {
_E("Invalid parameter");
return -EINVAL;
}
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;
return -EINVAL;
}
- if (byte_size > UART_BYTE_SIZE_8BIT) {
+ if (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT) {
_E("Invalid bytesize parameter");
return -EINVAL;
}
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;
/* 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;
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;
/* 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:
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;
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) {