Merge src/peripheral_spi.c with src/interface/peripheral_interface_spi.c.
Change-Id: I9b45addfafe7c71e99cbd7797069df6f98fc69ec
src/interface/peripheral_interface_gpio.c
src/interface/peripheral_interface_pwm.c
src/interface/peripheral_interface_adc.c
- src/interface/peripheral_interface_spi.c
src/interface/peripheral_interface_uart.c
src/gdbus/peripheral_gdbus_gpio.c
src/gdbus/peripheral_gdbus_pwm.c
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __PERIPHERAL_INTERFACE_SPI_H__
-#define __PERIPHERAL_INTERFACE_SPI_H__
-
-#include "peripheral_interface_common.h"
-
-void peripheral_interface_spi_close(peripheral_spi_h spi);
-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, uint8_t bits);
-int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq);
-int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t length);
-int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_t length);
-int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint8_t *rxbuf, uint32_t length);
-
-#endif /* __PERIPHERAL_INTERFACE_SPI_H__ */
* @brief Internal struct for spi context
*/
struct _peripheral_spi_s {
- uint handle;
int fd;
};
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/ioctl.h>
-#include <linux/spi/spidev.h>
-
-#include "peripheral_interface_spi.h"
-
-void peripheral_interface_spi_close(peripheral_spi_h spi)
-{
- close(spi->fd);
-}
-
-int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
-{
- int ret = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode);
- CHECK_ERROR(ret != 0);
-
- return PERIPHERAL_ERROR_NONE;
-}
-
-int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order)
-{
- int ret = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order);
- CHECK_ERROR(ret != 0);
-
- return PERIPHERAL_ERROR_NONE;
-}
-
-int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits)
-{
- int ret = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
- CHECK_ERROR(ret != 0);
-
- return PERIPHERAL_ERROR_NONE;
-}
-
-int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq)
-{
- int ret = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq);
- CHECK_ERROR(ret != 0);
-
- return PERIPHERAL_ERROR_NONE;
-}
-
-int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t length)
-{
- int ret;
- struct spi_ioc_transfer xfer;
-
- memset(&xfer, 0, sizeof(struct spi_ioc_transfer));
- xfer.rx_buf = (unsigned long)rxbuf;
- xfer.len = length;
-
- ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
- CHECK_ERROR(ret < 0);
-
- return PERIPHERAL_ERROR_NONE;
-}
-
-int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_t length)
-{
- int ret;
- struct spi_ioc_transfer xfer;
-
- memset(&xfer, 0, sizeof(struct spi_ioc_transfer));
- xfer.tx_buf = (unsigned long)txbuf;
- xfer.len = length;
-
- ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
- CHECK_ERROR(ret < 0);
-
- return PERIPHERAL_ERROR_NONE;
-}
-
-int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint8_t *rxbuf, uint32_t length)
-{
- int ret;
- struct spi_ioc_transfer xfer;
-
- if (!txbuf || !rxbuf) return PERIPHERAL_ERROR_INVALID_PARAMETER;
-
- memset(&xfer, 0, sizeof(xfer));
- xfer.tx_buf = (unsigned long)txbuf;
- xfer.rx_buf = (unsigned long)rxbuf;
- xfer.len = length;
-
- ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
- CHECK_ERROR(ret < 0);
-
- return PERIPHERAL_ERROR_NONE;
-}
*/
#include <fcntl.h>
+#include <linux/spi/spidev.h>
#include <stdlib.h>
#include <sys/file.h>
+#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <system_info.h>
#include "peripheral_io.h"
-#include "peripheral_handle.h"
-#include "peripheral_interface_spi.h"
+#include "peripheral_interface_common.h"
#include "peripheral_log.h"
#define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi"
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");
- return peripheral_interface_spi_set_mode(spi, mode);
+ int ret = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode);
+ CHECK_ERROR(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
}
int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order)
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");
- return peripheral_interface_spi_set_bit_order(spi, bit_order);
+ int ret = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order);
+ CHECK_ERROR(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
}
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(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- return peripheral_interface_spi_set_bits_per_word(spi, bits);
+ int ret = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
+ CHECK_ERROR(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
}
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(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
- return peripheral_interface_spi_set_frequency(spi, freq_hz);
+ int ret = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq_hz);
+ CHECK_ERROR(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
}
int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length)
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- return peripheral_interface_spi_read(spi, data, length);
+ int ret;
+ struct spi_ioc_transfer xfer = {0, };
+
+ xfer.rx_buf = (unsigned long)data;
+ xfer.len = length;
+
+ ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
+ CHECK_ERROR(ret < 0);
+
+ return PERIPHERAL_ERROR_NONE;
}
int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length)
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- return peripheral_interface_spi_write(spi, data, length);
+ int ret;
+ struct spi_ioc_transfer xfer = {0, };
+
+ xfer.tx_buf = (unsigned long)data;
+ xfer.len = length;
+
+ ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
+ CHECK_ERROR(ret < 0);
+
+ return PERIPHERAL_ERROR_NONE;
}
int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length)
RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
- return peripheral_interface_spi_transfer(spi, txdata, rxdata, length);
+ int ret;
+ struct spi_ioc_transfer xfer = {0, };
+
+ xfer.tx_buf = (unsigned long)txdata;
+ xfer.rx_buf = (unsigned long)rxdata;
+ xfer.len = length;
+
+ ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
+ CHECK_ERROR(ret < 0);
+
+ return PERIPHERAL_ERROR_NONE;
}