ret = tcgetattr(uart->fd, &tio);
CHECK_ERROR(ret != 0);
- /* set stop bit */
- switch (stop_bits) {
- case PERIPHERAL_UART_STOP_BITS_1BIT:
+ if (stop_bits == PERIPHERAL_UART_STOP_BITS_1BIT)
tio.c_cflag &= ~CSTOPB;
- break;
- case PERIPHERAL_UART_STOP_BITS_2BIT:
+ else // PERIPHERAL_UART_STOP_BITS_2BIT
tio.c_cflag |= CSTOPB;
- break;
- default:
- _E("Invalid parameter stop_bits");
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
- }
peripheral_uart_flush(uart);
if (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS)
tio.c_cflag |= CRTSCTS;
- else if (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE)
+ else // PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE
tio.c_cflag &= ~CRTSCTS;
- else
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
if (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF)
tio.c_iflag |= (IXON | IXOFF | IXANY);
- else if (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE)
+ else // PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE
tio.c_iflag &= ~(IXON | IXOFF | IXANY);
- else
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
peripheral_uart_flush(uart);
static int pass_count = 0;
static int skip_count = 0;
-char *model_name = NULL;
+static char *model_name = NULL;
typedef struct
{
if (g_feature == false) {
ret = peripheral_adc_open(device, channel, &adc_h);
- if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED)
+ if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) {
+ peripheral_adc_close(adc_h);
return ret;
-
+ }
} else {
ret = peripheral_adc_open(device, channel, &adc_h);
if (ret != PERIPHERAL_ERROR_NONE)
if (g_feature == false) {
ret = peripheral_gpio_open(pin, &gpio_h);
- if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED)
+ if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) {
+ peripheral_gpio_close(gpio_h);
return ret;
+ }
} else {
ret = peripheral_gpio_open(pin, &gpio_h);
if (g_feature == false) {
ret = peripheral_i2c_open(bus, address, &i2c_h);
- if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED)
+ if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) {
+ peripheral_i2c_close(i2c_h);
return ret;
+ }
} else {
ret = peripheral_i2c_open(bus, address, &i2c_h);
if (g_feature == false) {
ret = peripheral_pwm_open(chip, pin, &pwm_h);
- if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED)
+ if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) {
+ peripheral_pwm_close(pwm_h);
return ret;
+ }
} else {
ret = peripheral_pwm_open(chip, pin, &pwm_h);
if (g_feature == false) {
ret = peripheral_spi_open(bus, cs, &spi_h);
- if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED)
+ if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) {
+ peripheral_spi_close(spi_h);
return ret;
+ }
} else {
ret = peripheral_spi_open(bus, cs, &spi_h);
if (g_feature == false) {
ret = peripheral_uart_open(port, &uart_h);
- if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED)
+ if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) {
+ peripheral_uart_close(uart_h);
return ret;
+ }
} else {
ret = peripheral_uart_open(port, &uart_h);