src/peripheral_pwm.c
src/peripheral_adc.c
src/peripheral_uart.c
- src/peripheral_spi.c)
+ src/peripheral_spi.c
+ src/common.c)
ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
--- /dev/null
+#include "common.h"
+#include <assert.h>
+#include <system_info.h>
+
+bool peripheral_is_feature_supported(const char *feature_name, int *feature_state)
+{
+ assert(feature_name);
+ assert(feature_state);
+
+ if (*feature_state == PERIPHERAL_FEATURE_UNKNOWN) {
+ bool feature = false;
+ int ret = system_info_get_platform_bool(feature_name, &feature);
+ RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info");
+
+ *feature_state = (feature ? PERIPHERAL_FEATURE_TRUE : PERIPHERAL_FEATURE_FALSE);
+ }
+
+ return *feature_state == PERIPHERAL_FEATURE_TRUE;
+}
+
* limitations under the License.
*/
-#ifndef __PERIPHERAL_INTERFACE_COMMON_H__
-#define __PERIPHERAL_INTERFACE_COMMON_H__
-
+#pragma once
+#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
int len;
} predefined_type_s;
-#endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/
+
+#define PERIPHERAL_FEATURE_UNKNOWN -1
+#define PERIPHERAL_FEATURE_FALSE 0
+#define PERIPHERAL_FEATURE_TRUE 1
+
+bool peripheral_is_feature_supported(const char *feature_name, int *feature_state);
+
+#define FEATURE(feature_name) \
+ static bool __is_feature_supported(void) \
+ { \
+ static int feature = PERIPHERAL_FEATURE_UNKNOWN; \
+ if (feature == PERIPHERAL_FEATURE_UNKNOWN) \
+ return peripheral_is_feature_supported(feature_name, &feature); \
+ return feature == PERIPHERAL_FEATURE_TRUE; \
+ }
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <system_info.h>
#include "peripheral_io.h"
#include "common.h"
#include "log.h"
-#define PERIPHERAL_IO_ADC_FEATURE "http://tizen.org/feature/peripheral_io.adc"
-
-#define ADC_FEATURE_UNKNOWN -1
-#define ADC_FEATURE_FALSE 0
-#define ADC_FEATURE_TRUE 1
+FEATURE("http://tizen.org/feature/peripheral_io.adc")
#define ADC_BUFFER_MAX 64
int fd;
};
-static int adc_feature = ADC_FEATURE_UNKNOWN;
-
-static bool __is_feature_supported(void)
-{
- int ret = SYSTEM_INFO_ERROR_NONE;
- bool feature = false;
-
- if (adc_feature == ADC_FEATURE_UNKNOWN) {
- ret = system_info_get_platform_bool(PERIPHERAL_IO_ADC_FEATURE, &feature);
- RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info");
-
- adc_feature = (feature ? ADC_FEATURE_TRUE : ADC_FEATURE_FALSE);
- }
- return (adc_feature == ADC_FEATURE_TRUE ? true : false);
-}
-
static inline void cleanup_handlep(peripheral_adc_h *handle)
{
if (*handle != NULL) {
*/
int peripheral_adc_open(int device, int channel, peripheral_adc_h *adc)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported");
RETVM_IF(adc == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc handle");
RETVM_IF(device < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc device number");
RETVM_IF(channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid adc channel number");
*/
int peripheral_adc_close(peripheral_adc_h adc)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported");
RETVM_IF(adc == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "adc handle is NULL");
cleanup_handlep(&adc);
*/
int peripheral_adc_read(peripheral_adc_h adc, uint32_t *value)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "ADC feature is not supported");
RETVM_IF(adc == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "adc handle is NULL");
RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "adc read value is invalid");
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
-#include <system_info.h>
#include "peripheral_io.h"
#include "common.h"
#include "log.h"
-#define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio"
+FEATURE("http://tizen.org/feature/peripheral_io.gpio")
-#define GPIO_FEATURE_UNKNOWN -1
-#define GPIO_FEATURE_FALSE 0
-#define GPIO_FEATURE_TRUE 1
#define GPIO_STRUCTURE_VERMAGIC 13712
#define GPIO_CALLBACK_STRUCTURE_VERMAGIC 14469
peripheral_gpio_edge_e edge;
};
-static int gpio_feature = GPIO_FEATURE_UNKNOWN;
-
-static bool __is_feature_supported(void)
-{
- int ret = SYSTEM_INFO_ERROR_NONE;
- bool feature = false;
-
- if (gpio_feature == GPIO_FEATURE_UNKNOWN) {
- ret = system_info_get_platform_bool(PERIPHERAL_IO_GPIO_FEATURE, &feature);
- RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info");
-
- gpio_feature = (feature ? GPIO_FEATURE_TRUE : GPIO_FEATURE_FALSE);
- }
- return (gpio_feature == GPIO_FEATURE_TRUE ? true : false);
-}
-
static int __gpio_create_udev_monitor(struct udev **udev, struct udev_monitor **monitor)
{
struct udev *_udev = NULL;
{
int ret = PERIPHERAL_ERROR_NONE;
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle");
RETVM_IF(gpio_pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin number");
*/
int peripheral_gpio_close(peripheral_gpio_h gpio)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
peripheral_gpio_unset_interrupted_cb(gpio);
*/
int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
RETVM_IF((direction < PERIPHERAL_GPIO_DIRECTION_IN) || (direction > PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid direction input");
*/
int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
RETVM_IF((edge < PERIPHERAL_GPIO_EDGE_NONE) || (edge > PERIPHERAL_GPIO_EDGE_BOTH), PERIPHERAL_ERROR_INVALID_PARAMETER, "edge input is invalid");
*/
int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
RETVM_IF(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL");
RETV_IF(gpio->direction != PERIPHERAL_GPIO_DIRECTION_IN, PERIPHERAL_ERROR_IO_ERROR);
*/
int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
g_atomic_int_set(&gpio->cb_info.status, GPIO_INTERRUPTED_CALLBACK_UNSET);
*/
int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio read value is invalid");
/*
*/
int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported");
RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
RETVM_IF((value != 0) && (value != 1), PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio value is invalid");
/*
#include <stdlib.h>
#include <sys/file.h>
#include <sys/ioctl.h>
-#include <system_info.h>
#include "peripheral_io.h"
#include "common.h"
#include "log.h"
-#define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c"
-
-#define I2C_FEATURE_UNKNOWN -1
-#define I2C_FEATURE_FALSE 0
-#define I2C_FEATURE_TRUE 1
+FEATURE("http://tizen.org/feature/peripheral_io.i2c")
#define I2C_SLAVE 0x0703 /* Use this slave address */
#define I2C_SMBUS 0x0720 /* SMBus transfer */
union i2c_smbus_data *data;
};
-static int i2c_feature = I2C_FEATURE_UNKNOWN;
-
-static bool __is_feature_supported(void)
-{
- int ret = SYSTEM_INFO_ERROR_NONE;
- bool feature = false;
-
- if (i2c_feature == I2C_FEATURE_UNKNOWN) {
- ret = system_info_get_platform_bool(PERIPHERAL_IO_I2C_FEATURE, &feature);
- RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info");
-
- i2c_feature = (feature ? I2C_FEATURE_TRUE : I2C_FEATURE_FALSE);
- }
-
- return (i2c_feature == I2C_FEATURE_TRUE ? true : false);
-}
-
static inline void cleanup_handlep(peripheral_i2c_h *handle) {
if (*handle != NULL) {
if ((*handle)->fd != -1)
#define DEV_PATH_BASE "/dev/i2c-"
char path[sizeof(DEV_PATH_BASE "0000000000")] = {0, }; /* space for /dev/i2c-%d */
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
RETVM_IF(flags != PERIPHERAL_OPEN_FLAGS_PRIVATE && flags != PERIPHERAL_OPEN_FLAGS_SHARED,
int peripheral_i2c_close(peripheral_i2c_h i2c)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
cleanup_handlep(&i2c);
int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data_out, uint32_t length)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
RETVM_IF(data_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data_in, uint32_t length)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
RETVM_IF(data_in == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
RETVM_IF(data_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
union i2c_smbus_data data = {.block = {0,}};
int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
RETVM_IF(data_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
union i2c_smbus_data data = {.block = {0,}};
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
-#include <system_info.h>
#include "peripheral_io.h"
#include "common.h"
#include "log.h"
-#define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm"
-
-#define PWM_FEATURE_UNKNOWN -1
-#define PWM_FEATURE_FALSE 0
-#define PWM_FEATURE_TRUE 1
+FEATURE("http://tizen.org/feature/peripheral_io.pwm")
#define PWM_BUF_MAX 16
int fd_enable;
};
-static int pwm_feature = PWM_FEATURE_UNKNOWN;
-
-static bool __is_feature_supported(void)
-{
- int ret = SYSTEM_INFO_ERROR_NONE;
- bool feature = false;
-
- if (pwm_feature == PWM_FEATURE_UNKNOWN) {
- ret = system_info_get_platform_bool(PERIPHERAL_IO_PWM_FEATURE, &feature);
- RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info");
-
- pwm_feature = (feature ? PWM_FEATURE_TRUE : PWM_FEATURE_FALSE);
- }
-
- return (pwm_feature == PWM_FEATURE_TRUE ? true : false);
-}
-
static int __pwm_create_udev_monitor(struct udev **udev, struct udev_monitor **monitor)
{
struct udev *_udev = NULL;
{
int ret = PERIPHERAL_ERROR_NONE;
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle");
RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_pwm_close(peripheral_pwm_h pwm)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
return cleanup_handle(pwm);
int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
int ret;
int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
int ret;
int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
RETVM_IF((polarity < PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) || (polarity > PERIPHERAL_PWM_POLARITY_ACTIVE_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid polarity parameter");
int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported");
RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
static predefined_type_s types[2] = {
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <system_info.h>
#include "peripheral_io.h"
#include "common.h"
#include "log.h"
-#define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi"
-
-#define SPI_FEATURE_UNKNOWN -1
-#define SPI_FEATURE_FALSE 0
-#define SPI_FEATURE_TRUE 1
+FEATURE("http://tizen.org/feature/peripheral_io.spi")
/**
* @brief Internal struct for spi context
int fd;
};
-static int spi_feature = SPI_FEATURE_UNKNOWN;
-
-static bool __is_feature_supported(void)
-{
- int ret = SYSTEM_INFO_ERROR_NONE;
- bool feature = false;
-
- if (spi_feature == SPI_FEATURE_UNKNOWN) {
- ret = system_info_get_platform_bool(PERIPHERAL_IO_SPI_FEATURE, &feature);
- RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info");
-
- spi_feature = (feature ? SPI_FEATURE_TRUE : SPI_FEATURE_FALSE);
- }
-
- return (spi_feature == SPI_FEATURE_TRUE ? true : false);
-}
-
static inline void cleanup_handlep(peripheral_spi_h *handle)
{
if (*handle != NULL) {
#define DEV_PATH_BASE "/dev/spidev"
char path[sizeof(DEV_PATH_BASE "1234567890.1234567890")] = {0, }; /* space for /dev/spidev%d.%d */
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle");
RETVM_IF(bus < 0 || cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_spi_close(peripheral_spi_h spi)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
cleanup_handlep(&spi);
int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF((mode < PERIPHERAL_SPI_MODE_0) || (mode > PERIPHERAL_SPI_MODE_3), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi mode parameter");
int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF((bit_order < PERIPHERAL_SPI_BIT_ORDER_MSB) || (bit_order > PERIPHERAL_SPI_BIT_ORDER_LSB), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid bit order parameter");
int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
int ret = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
int ret = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq_hz);
int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported");
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <system_info.h>
#include <termios.h>
#include "peripheral_io.h"
#include "common.h"
#include "log.h"
-#define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart"
-
-#define UART_FEATURE_UNKNOWN -1
-#define UART_FEATURE_FALSE 0
-#define UART_FEATURE_TRUE 1
+FEATURE("http://tizen.org/feature/peripheral_io.uart")
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
static const int byteinfo[4] = {CS5, CS6, CS7, CS8};
-static int uart_feature = UART_FEATURE_UNKNOWN;
-
-static bool __is_feature_supported(void)
-{
- int ret = SYSTEM_INFO_ERROR_NONE;
- bool feature = false;
-
- if (uart_feature == UART_FEATURE_UNKNOWN) {
- ret = system_info_get_platform_bool(PERIPHERAL_IO_UART_FEATURE, &feature);
- RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info");
-
- uart_feature = (feature ? UART_FEATURE_TRUE : UART_FEATURE_FALSE);
- }
-
- return (uart_feature == UART_FEATURE_TRUE ? true : false);
-}
-
static inline void cleanup_handlep(peripheral_uart_h *handle)
{
if (*handle != NULL) {
*/
int peripheral_uart_open(int port, peripheral_uart_h *uart)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number");
*/
int peripheral_uart_close(peripheral_uart_h uart)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
peripheral_uart_flush(uart);
*/
int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
RETVM_IF((baud < PERIPHERAL_UART_BAUD_RATE_0) || (baud > PERIPHERAL_UART_BAUD_RATE_230400), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid baud input");
int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
RETVM_IF((byte_size < PERIPHERAL_UART_BYTE_SIZE_5BIT) || (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
RETVM_IF((parity < PERIPHERAL_UART_PARITY_NONE) || (parity > PERIPHERAL_UART_PARITY_ODD), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
RETVM_IF((stop_bits < PERIPHERAL_UART_STOP_BITS_1BIT) || (stop_bits > PERIPHERAL_UART_STOP_BITS_2BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
*/
int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e sw_flow_control, peripheral_uart_hardware_flow_control_e hw_flow_control)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
RETVM_IF((sw_flow_control < PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) || (sw_flow_control > PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid sw_flow_control parameter");
RETVM_IF((hw_flow_control < PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE) || (hw_flow_control > PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid hw_flow_control parameter");
*/
int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
*/
int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length)
{
- RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");