- Add log message for failure cases.
- Improve parameter validation with log messages.
Change-Id: I21f99c8fbbe1f50032da8933dbb92b6b21faad11
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
int peripheral_adc_read(unsigned int device, unsigned int channel, int *data)
{
- int ret = PERIPHERAL_ERROR_NONE;
+ int ret;
adc_proxy_init();
ret = peripheral_gdbus_adc_read(device, channel, data);
- if (ret < PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to read, ret : %d", ret);
return ret;
int ret = PERIPHERAL_ERROR_NONE;
peripheral_gpio_h handle;
- assert(gpio_pin >= 0);
+ RETVM_IF(gpio_pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin number");
/* Initialize */
handle = (peripheral_gpio_h)calloc(1, sizeof(struct _peripheral_gpio_s));
ret = peripheral_gdbus_gpio_open(handle);
if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open the gpio pin, ret : %d", ret);
free(handle);
handle = NULL;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
/* call gpio_close */
ret = peripheral_gdbus_gpio_close(gpio);
- if (ret)
- ret = TIZEN_ERROR_IO_ERROR;
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to close the gpio pin, ret : %d", ret);
gpio_proxy_deinit();
free(gpio);
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
ret = peripheral_gdbus_gpio_get_direction(gpio, direction);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get direction of the gpio pin, ret : %d", ret);
return ret;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
-
- if (direction > PERIPHERAL_GPIO_DIRECTION_OUT_HIGH)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
+ RETVM_IF(direction > PERIPHERAL_GPIO_DIRECTION_OUT_HIGH, PERIPHERAL_ERROR_INVALID_PARAMETER,
+ "Invalid direction input");
/* call gpio_set_direction */
ret = peripheral_gdbus_gpio_set_direction(gpio, direction);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set gpio direction, ret : %d", ret);
return ret;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
/* call gpio_read */
ret = peripheral_gdbus_gpio_read(gpio, value);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to read value of the gpio pin, ret : %d", ret);
return ret;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
/* call gpio_write */
ret = peripheral_gdbus_gpio_write(gpio, value);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to write to the gpio pin, ret : %d", ret);
return ret;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
ret = peripheral_gdbus_gpio_get_edge_mode(gpio, edge);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get edge mode of the gpio pin, ret : %d", ret);
return ret;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
-
- if (edge > PERIPHERAL_GPIO_EDGE_BOTH)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
+ RETVM_IF(edge > PERIPHERAL_GPIO_EDGE_BOTH, PERIPHERAL_ERROR_INVALID_PARAMETER,
+ "Invalid edge input");
/* call gpio_set_edge_mode */
ret = peripheral_gdbus_gpio_set_edge_mode(gpio, edge);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set edge mode of the gpio pin, ret : %d", ret);
return ret;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
ret = peripheral_gdbus_gpio_register_cb(gpio, callback, user_data);
- if (ret != PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to register cb, ret : %d", ret);
return ret;
+ }
/* set isr */
ret = peripheral_gpio_isr_set(gpio->pin, callback, user_data);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to register gpio isr, ret : %d", ret);
return ret;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
ret = peripheral_gdbus_gpio_unregister_cb(gpio);
- if (ret != PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to unregister gpio isr, ret : %d", ret);
return ret;
+ }
/* clean up isr */
ret = peripheral_gpio_isr_unset(gpio->pin);
*/
int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin)
{
- /* check validation of gpio context handle */
- if (gpio == NULL)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
*gpio_pin = gpio->pin;
peripheral_i2c_h handle;
int ret = PERIPHERAL_ERROR_NONE;
- if (bus < 0)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
handle = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s));
ret = peripheral_gdbus_i2c_open(handle, bus, address);
if (ret != PERIPHERAL_ERROR_NONE) {
- _E("[PERIPHERAL] I2C init error\n");
+ _E("Failed to open i2c communication, ret : %d", ret);
free(handle);
handle = NULL;
}
int peripheral_i2c_close(peripheral_i2c_h i2c)
{
- int ret = PERIPHERAL_ERROR_NONE;
+ int ret;
- if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
ret = peripheral_gdbus_i2c_close(i2c);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to close i2c communcation, ret : %d", ret);
i2c_proxy_deinit();
free(i2c);
int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length)
{
- int ret = PERIPHERAL_ERROR_NONE;
+ int ret;
- if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+ RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
ret = peripheral_gdbus_i2c_read(i2c, data, length);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to read data from device, ret : %d", ret);
return ret;
}
int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length)
{
- if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+ RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- return peripheral_gdbus_i2c_write(i2c, data, length);
+ ret = peripheral_gdbus_i2c_write(i2c, data, length);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to write data to device, ret : %d", ret);
+
+ return ret;
}
int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data)
{
- int ret = PERIPHERAL_ERROR_NONE;
+ int ret;
uint16_t w_data, dummy = 0;
- if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, 0x0, I2C_SMBUS_BYTE, dummy, &w_data);
- if (ret < PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to read, ret : %d", ret);
*data = (uint8_t)w_data;
int ret = PERIPHERAL_ERROR_NONE;
uint16_t dummy = 0;
- if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, dummy, I2C_SMBUS_BYTE, (uint16_t)data, &dummy);
- if (ret < PERIPHERAL_ERROR_NONE)
- _E("Failed to read, ret : %d", ret);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to write, ret : %d", ret);
return ret;
}
int ret;
uint16_t w_data, dummy = 0;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+
ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_BYTE_DATA, dummy, &w_data);
- if (ret < PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Smbus transaction failed, ret : %d", ret);
*data = (uint8_t)w_data;
int ret;
uint16_t dummy = 0;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+
ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy);
- if (ret < PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Smbus transaction failed, ret : %d", ret);
return ret;
int ret;
uint16_t dummy = 0, data_out;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+
ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_WORD_DATA, dummy, &data_out);
- if (ret < PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Smbus transaction failed, ret : %d", ret);
*data = data_out;
int ret;
uint16_t dummy = 0;
+ RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+
ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_WORD_DATA, data, &dummy);
- if (ret < PERIPHERAL_ERROR_NONE)
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Smbus transaction failed, ret : %d", ret);
return ret;
peripheral_pwm_h handle;
int ret = PERIPHERAL_ERROR_NONE;
- if (device < 0 || channel < 0) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(device < 0 || channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
/* Initialize */
handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s));
ret = peripheral_gdbus_pwm_open(handle, device, channel);
if (ret != PERIPHERAL_ERROR_NONE) {
- _E("PWM open error (%d, %d)", device, channel);
+ _E("Failed to open PWM device : %d, channel : %d", device, channel);
free(handle);
handle = NULL;
}
{
int ret = PERIPHERAL_ERROR_NONE;
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0)
- _E("Failed to close PWM device, continuing anyway");
+ _E("Failed to close PWM device, continuing anyway, ret : %d", ret);
pwm_proxy_deinit();
free(pwm);
int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_set_period(pwm, period);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+
+ ret = peripheral_gdbus_pwm_set_period(pwm, period);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set period, ret : %d", ret);
+
+ return ret;
}
int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_get_period(pwm, period);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+
+ ret = peripheral_gdbus_pwm_get_period(pwm, period);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get period, ret : %d", ret);
+
+ return ret;
}
int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+
+ ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set duty cycle, ret : %d", ret);
+
+ return ret;
}
int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+
+ ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get duty cycle, ret : %d", ret);
+
+ return ret;
}
int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_set_polarity(pwm, polarity);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+ RETVM_IF(polarity > PERIPHERAL_PWM_POLARITY_INVERSED, PERIPHERAL_ERROR_INVALID_PARAMETER,
+ "Invalid polarity parameter");
+
+ ret = peripheral_gdbus_pwm_set_polarity(pwm, polarity);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set polarity, ret : %d", ret);
+
+ return ret;
}
int peripheral_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_get_polarity(pwm, polarity);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+
+ ret = peripheral_gdbus_pwm_get_polarity(pwm, polarity);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get polarity, ret : %d", ret);
+
+ return ret;
}
int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_set_enable(pwm, enable);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+
+ ret = peripheral_gdbus_pwm_set_enable(pwm, enable);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set enable, ret : %d", ret);
+
+ return ret;
}
int peripheral_pwm_get_enable(peripheral_pwm_h pwm, bool *enable)
{
- if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_pwm_get_enable(pwm, enable);
+ RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+
+ ret = peripheral_gdbus_pwm_get_enable(pwm, enable);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get enable, ret : %d", ret);
+
+ return ret;
}
peripheral_spi_h handle;
int ret = PERIPHERAL_ERROR_NONE;
- if (bus < 0 || cs < 0) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(bus < 0 || cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
/* Initialize */
handle = (peripheral_spi_h)calloc(1, sizeof(struct _peripheral_spi_s));
{
int ret = PERIPHERAL_ERROR_NONE;
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- if ((ret = peripheral_gdbus_spi_close(spi)) < 0)
- _E("Failed to close SPI device, continuing anyway");
+ ret = peripheral_gdbus_spi_close(spi);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Failed to close SPI device, continuing anyway, ret : %d", ret);
spi_proxy_deinit();
free(spi);
int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_spi_set_mode(spi, mode);
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+ RETVM_IF(mode > PERIPHERAL_SPI_MODE_3, PERIPHERAL_ERROR_INVALID_PARAMETER,
+ "Invalid spi mode parameter");
+
+ ret = peripheral_gdbus_spi_set_mode(spi, mode);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set mode, ret : %d", ret);
+
+ return ret;
}
int peripheral_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+
+ ret = peripheral_gdbus_spi_get_mode(spi, mode);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get spi mode, ret : %d", ret);
- return peripheral_gdbus_spi_get_mode(spi, mode);
+ return ret;
}
int peripheral_spi_set_lsb_first(peripheral_spi_h spi, bool lsb)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- return peripheral_gdbus_spi_set_lsb_first(spi, lsb);
+ ret = peripheral_gdbus_spi_set_lsb_first(spi, lsb);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set lsb first, ret : %d", ret);
+
+ return ret;
}
int peripheral_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_spi_get_lsb_first(spi, lsb);
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+
+ ret = peripheral_gdbus_spi_get_lsb_first(spi, lsb);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get lsb first, ret : %d", ret);
+
+ return ret;
}
int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- return peripheral_gdbus_spi_set_bits(spi, bits);
+ ret = peripheral_gdbus_spi_set_bits(spi, bits);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set bits per word, ret : %d", ret);
+
+ return ret;
}
int peripheral_spi_get_bits_per_word(peripheral_spi_h spi, unsigned char *bits)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+
+ ret = peripheral_gdbus_spi_get_bits(spi, bits);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get bits per word, ret : %d", ret);
- return peripheral_gdbus_spi_get_bits(spi, bits);
+ return ret;
}
int peripheral_spi_set_frequency(peripheral_spi_h spi, unsigned int freq)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- return peripheral_gdbus_spi_set_frequency(spi, freq);
+ ret = peripheral_gdbus_spi_set_frequency(spi, freq);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set frequency, ret : %d", ret);
+
+ return ret;
}
int peripheral_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_spi_get_frequency(spi, freq);
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+
+ ret = peripheral_gdbus_spi_get_frequency(spi, freq);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to get spi frequency, ret : %d", ret);
+
+ return ret;
}
int peripheral_spi_read(peripheral_spi_h spi, unsigned char *data, int length)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- return peripheral_gdbus_spi_read(spi, data, length);
+ ret = peripheral_gdbus_spi_read(spi, data, length);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to read from spi device, ret : %d", ret);
+
+ return ret;
}
int peripheral_spi_write(peripheral_spi_h spi, unsigned char *data, int length)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+
+ ret = peripheral_gdbus_spi_write(spi, data, length);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to write to spi device, ret : %d", ret);
- return peripheral_gdbus_spi_write(spi, data, length);
+ return ret;
}
int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsigned char *rxdata, int length)
{
- if (spi == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- return peripheral_gdbus_spi_read_write(spi, txdata, rxdata, length);
+ ret = peripheral_gdbus_spi_read_write(spi, txdata, rxdata, length);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to read and write, ret : %d", ret);
+
+ return ret;
}
int peripheral_uart_open(int port, peripheral_uart_h *uart)
{
peripheral_uart_h handle;
- int ret = PERIPHERAL_ERROR_NONE;
+ int ret;
- if (port < 0)
- return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number");
handle = (peripheral_uart_h)calloc(1, sizeof(struct _peripheral_uart_s));
ret = peripheral_gdbus_uart_open(handle, port);
if (ret != PERIPHERAL_ERROR_NONE) {
- _E("[PERIPHERAL] UART open error\n");
+ _E("Failed to open uart port, ret : %d", ret);
free(handle);
handle = NULL;
}
*/
int peripheral_uart_close(peripheral_uart_h uart)
{
- int ret = PERIPHERAL_ERROR_NONE;
+ int ret;
- if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
ret = peripheral_gdbus_uart_close(uart);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Failed to close uart communication, continuing anyway, ret : %d", ret);
uart_proxy_deinit();
free(uart);
*/
int peripheral_uart_flush(peripheral_uart_h uart)
{
- if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_uart_flush(uart);
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+
+ ret = peripheral_gdbus_uart_flush(uart);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to flush, ret : %d", ret);
+
+ return ret;
}
/**
*/
int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud)
{
- if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+ RETVM_IF(baud > PERIPHERAL_UART_BAUDRATE_230400, PERIPHERAL_ERROR_INVALID_PARAMETER,
+ "Invalid baud input");
+
+ ret = peripheral_gdbus_uart_set_baudrate(uart, baud);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set baudrate, ret : %d", ret);
- return peripheral_gdbus_uart_set_baudrate(uart, baud);
+ return ret;
}
/**
*/
int peripheral_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits)
{
- if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+ RETVM_IF(bytesize > PERIPHERAL_UART_BYTESIZE_8BIT
+ || parity > PERIPHERAL_UART_PARITY_ODD
+ || stopbits > PERIPHERAL_UART_STOPBITS_2BIT,
+ PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- return peripheral_gdbus_uart_set_mode(uart, bytesize, parity, stopbits);
+ ret = peripheral_gdbus_uart_set_mode(uart, bytesize, parity, stopbits);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set uart mode, ret : %d", ret);
+
+ return ret;
}
/**
*/
int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts)
{
- if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
- return peripheral_gdbus_uart_set_flowcontrol(uart, xonxoff, rtscts);
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+
+ ret = peripheral_gdbus_uart_set_flowcontrol(uart, xonxoff, rtscts);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to set flocontrol, ret : %d", ret);
+
+ return ret;
}
/**
*/
int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length)
{
- if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+ RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+ ret = peripheral_gdbus_uart_read(uart, data, length);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Failed to read from uart device, ret : %d", ret);
- return peripheral_gdbus_uart_read(uart, data, length);
+ return ret;
}
/**
*/
int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length)
{
- if (uart == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
+ int ret;
+
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+ RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- return peripheral_gdbus_uart_write(uart, data, length);
+ ret = peripheral_gdbus_uart_write(uart, data, length);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Failed to write to uart device, ret : %d", ret);
+
+ return ret;
}