spi: flatten structure - remove 'interface' 56/259756/7
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Jun 2021 12:59:27 +0000 (14:59 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 25 Jun 2021 06:01:51 +0000 (08:01 +0200)
Merge src/peripheral_spi.c with src/interface/peripheral_interface_spi.c.

Change-Id: I9b45addfafe7c71e99cbd7797069df6f98fc69ec

CMakeLists.txt
include/interface/peripheral_interface_spi.h [deleted file]
include/peripheral_handle.h
src/interface/peripheral_interface_spi.c [deleted file]
src/peripheral_spi.c

index e5b255c8b67e3507ab7290f1ef15661193f1a136..edcfbacbd61f62a534b42b9796bb5dfd0b9248fa 100644 (file)
@@ -63,7 +63,6 @@ SET(SOURCES src/peripheral_gpio.c
                        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
diff --git a/include/interface/peripheral_interface_spi.h b/include/interface/peripheral_interface_spi.h
deleted file mode 100644 (file)
index 7667bd2..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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__ */
index b766364e07e4cd784e32b4dcc98b284b45a48bd7..bd6567e1cfb45fe9a834d857acc4513e85049c6f 100644 (file)
@@ -88,7 +88,6 @@ struct _peripheral_uart_s {
  * @brief Internal struct for spi context
  */
 struct _peripheral_spi_s {
-       uint handle;
        int fd;
 };
 
diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c
deleted file mode 100644 (file)
index b38436b..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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;
-}
index 24dc78e03a6d93379f6aeec6340409c9d5c7c18e..9381d007dd16146ef87f7cbb5d5ca45df32134e2 100644 (file)
  */
 
 #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"
@@ -112,7 +113,10 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
        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)
@@ -121,7 +125,10 @@ int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_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)
@@ -129,7 +136,10 @@ 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)
@@ -137,7 +147,10 @@ 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)
@@ -146,7 +159,16 @@ 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)
@@ -155,7 +177,16 @@ 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)
@@ -164,5 +195,15 @@ int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxda
        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;
 }