adc: flatten structure - remove 'interface' 98/259798/5
authorAdrian Szyndela <adrian.s@samsung.com>
Mon, 14 Jun 2021 08:48:14 +0000 (10:48 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 25 Jun 2021 09:51:36 +0000 (11:51 +0200)
Merge src/peripheral_adc.c with src/interface/peripheral_interface_adc.c,
with additions from include/interface/peripheral_interface_adc.h.

Change-Id: I95f03beb77a35b9f1c2d3f82f3d0590737cea59c

CMakeLists.txt
include/interface/peripheral_interface_adc.h [deleted file]
include/peripheral_handle.h
src/interface/peripheral_interface_adc.c [deleted file]
src/peripheral_adc.c

index 0e3198b..b5ad98d 100644 (file)
@@ -62,7 +62,6 @@ SET(SOURCES src/peripheral_gpio.c
                        src/peripheral_spi.c
                        src/interface/peripheral_interface_gpio.c
                        src/interface/peripheral_interface_pwm.c
-                       src/interface/peripheral_interface_adc.c
                        src/gdbus/peripheral_gdbus_gpio.c
                        src/gdbus/peripheral_gdbus_pwm.c
                        src/gdbus/peripheral_io_gdbus.c)
diff --git a/include/interface/peripheral_interface_adc.h b/include/interface/peripheral_interface_adc.h
deleted file mode 100644 (file)
index 87d5383..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2018 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_ADC_H__
-#define __PERIPHERAL_INTERFACE_ADC_H__
-
-#include "peripheral_interface_common.h"
-
-#define ADC_BUFFER_MAX 64
-
-void peripheral_interface_adc_close(peripheral_adc_h adc);
-
-int peripheral_interface_adc_read(peripheral_adc_h adc, uint32_t *value);
-
-#endif/*__PERIPHERAL_INTERFACE_GPIO_H__*/
index 2bd5fea..b87dc49 100644 (file)
@@ -72,7 +72,6 @@ struct _peripheral_pwm_s {
  * @brief Internal struct for adc context
  */
 struct _peripheral_adc_s {
-       uint handle;
        int fd;
 };
 
diff --git a/src/interface/peripheral_interface_adc.c b/src/interface/peripheral_interface_adc.c
deleted file mode 100644 (file)
index bce9a50..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2018 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 "peripheral_interface_adc.h"
-
-int peripheral_interface_adc_read(peripheral_adc_h adc, uint32_t *value)
-{
-       int ret;
-       uint32_t tmp_val;
-       char adc_buf[ADC_BUFFER_MAX] = {0, };
-
-       ret = pread(adc->fd, &adc_buf, ADC_BUFFER_MAX, 0);
-       CHECK_ERROR(ret <= 0);
-
-       ret = sscanf(adc_buf, "%d", &tmp_val);
-       if (ret == 1) {
-               *value = tmp_val;
-       } else {
-               _E("Error: unable to read adc value \n");
-               return PERIPHERAL_ERROR_IO_ERROR;
-       }
-
-       return PERIPHERAL_ERROR_NONE;
-}
-
-void peripheral_interface_adc_close(peripheral_adc_h adc)
-{
-       close(adc->fd);
-}
index bf45995..9aa81c6 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <fcntl.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <sys/file.h>
 #include <sys/stat.h>
@@ -22,8 +23,7 @@
 #include <system_info.h>
 
 #include "peripheral_io.h"
-#include "peripheral_handle.h"
-#include "peripheral_interface_adc.h"
+#include "peripheral_interface_common.h"
 #include "peripheral_log.h"
 
 #define PERIPHERAL_IO_ADC_FEATURE "http://tizen.org/feature/peripheral_io.adc"
@@ -32,6 +32,8 @@
 #define ADC_FEATURE_FALSE    0
 #define ADC_FEATURE_TRUE     1
 
+#define ADC_BUFFER_MAX 64
+
 static int adc_feature = ADC_FEATURE_UNKNOWN;
 
 static bool __is_feature_supported(void)
@@ -120,5 +122,17 @@ int peripheral_adc_read(peripheral_adc_h adc, uint32_t *value)
        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");
 
-       return peripheral_interface_adc_read(adc, value);
+       int ret;
+       char adc_buf[ADC_BUFFER_MAX] = {0, };
+
+       ret = pread(adc->fd, &adc_buf, ADC_BUFFER_MAX, 0);
+       CHECK_ERROR(ret <= 0);
+
+       ret = sscanf(adc_buf, "%" SCNu32, value);
+       if (ret != 1) {
+               _E("Error: unable to read adc value: %m\n");
+               return PERIPHERAL_ERROR_IO_ERROR;
+       }
+
+       return PERIPHERAL_ERROR_NONE;
 }