summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHan Minsu <tizenhan@gmail.com>2019-09-08 23:08:50 +0900
committerHan Minsu <tizenhan@gmail.com>2019-09-11 19:57:48 +0900
commit8f3616c8aae7bc6495a108b3748d4340723dbde3 (patch)
treec7597c6d41274aa1f923a8b9c9bbc197003f38d5
parenta4fed45c61ce5c802ceed53d18b3f3ceeb71ac0b (diff)
downloadrcc-8f3616c8aae7bc6495a108b3748d4340723dbde3.tar.gz
rcc-8f3616c8aae7bc6495a108b3748d4340723dbde3.tar.bz2
rcc-8f3616c8aae7bc6495a108b3748d4340723dbde3.zip
Resource : MCU90614(Temperature/UART)
Change-Id: I40ec7875f60c7d653a9abf7285e5aca8981b69d3
-rwxr-xr-xinc/resource.h1
-rw-r--r--inc/resource/resource_mcu90615.h30
-rw-r--r--inc/resource/resource_mcu90615_internal.h22
-rwxr-xr-xinc/resource_internal.h1
-rw-r--r--src/resource/resource_mcu90615.c100
5 files changed, 154 insertions, 0 deletions
diff --git a/inc/resource.h b/inc/resource.h
index d91f671..db2f1e9 100755
--- a/inc/resource.h
+++ b/inc/resource.h
@@ -38,5 +38,6 @@
#include "resource/resource_tilt_sensor.h"
#include "resource/resource_gas_detection_sensor.h"
#include "resource/resource_sound_level_sensor.h"
+#include "resource/resource_mcu90615.h"
#endif /* __RCC_RESOURCE_H__ */
diff --git a/inc/resource/resource_mcu90615.h b/inc/resource/resource_mcu90615.h
new file mode 100644
index 0000000..0670483
--- /dev/null
+++ b/inc/resource/resource_mcu90615.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019 SINO TECH 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 __RESOURCE_MCU90615_H__
+#define __RESOURCE_MCU90615_H__
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+extern int resource_read_mcu90615(double *target_object, double *target_ambient);
+
+#if defined (__cplusplus)
+}
+#endif
+
+#endif /* __RESOURCE_MCU90615_H__ */
diff --git a/inc/resource/resource_mcu90615_internal.h b/inc/resource/resource_mcu90615_internal.h
new file mode 100644
index 0000000..a29e437
--- /dev/null
+++ b/inc/resource/resource_mcu90615_internal.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2019 SINO TECH 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 __RESOURCE_MCU90615_INTERNAL_H__
+#define __RESOURCE_MCU90615_INTERNAL_H__
+
+extern void resource_close_mcu90615(int pin_num);
+
+#endif /* __RESOURCE_MCU90615_INTERNAL_H__ */
diff --git a/inc/resource_internal.h b/inc/resource_internal.h
index 9de2070..4a6b4b0 100755
--- a/inc/resource_internal.h
+++ b/inc/resource_internal.h
@@ -37,6 +37,7 @@
#include "resource/resource_tilt_sensor_internal.h"
#include "resource/resource_gas_detection_sensor_internal.h"
#include "resource/resource_sound_level_sensor_internal.h"
+#include "resource/resource_mcu90615_internal.h"
#define PIN_MAX 40
diff --git a/src/resource/resource_mcu90615.c b/src/resource/resource_mcu90615.c
new file mode 100644
index 0000000..56e5188
--- /dev/null
+++ b/src/resource/resource_mcu90615.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2019 SINO TECH 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_io.h>
+
+#include "log.h"
+#include "resource_internal.h"
+
+#define UART_BUS 0 /* RPI3 - Tizen */
+
+#define GPIO_UART 14
+
+#define INPUT_SIZE 3
+#define OUTPUT_SIZE 9
+
+static peripheral_uart_h g_uart_h = NULL;
+
+void resource_close_mcu90615(int pin_num)
+{
+ _I("MCU90615 is finishing...[%d]", pin_num);
+ resource_get_info(GPIO_UART)->opened = 0;
+ if (!g_uart_h) return;
+
+ peripheral_uart_close(g_uart_h);
+ g_uart_h = NULL;
+}
+
+int resource_read_mcu90615(double *target_object, double *target_ambient)
+{
+ int ret = PERIPHERAL_ERROR_NONE;
+ uint8_t data[INPUT_SIZE] = {0xA5, 0x45, 0xEA};
+ uint8_t rdata[OUTPUT_SIZE] = {0, };
+
+ if (!g_uart_h) {
+ ret = peripheral_uart_open(UART_BUS, &g_uart_h);
+ retv_if(ret != PERIPHERAL_ERROR_NONE, -1);
+
+ resource_get_info(GPIO_UART)->opened = 1;
+ resource_get_info(GPIO_UART)->close = resource_close_mcu90615;
+
+ ret = peripheral_uart_set_baud_rate(g_uart_h, PERIPHERAL_UART_BAUD_RATE_115200);
+ goto_if(ret != PERIPHERAL_ERROR_NONE, error);
+
+ ret = peripheral_uart_set_byte_size(g_uart_h, PERIPHERAL_UART_BYTE_SIZE_8BIT);
+ goto_if(ret != PERIPHERAL_ERROR_NONE, error);
+
+ ret = peripheral_uart_set_parity(g_uart_h, PERIPHERAL_UART_PARITY_NONE);
+ goto_if(ret != PERIPHERAL_ERROR_NONE, error);
+
+ ret = peripheral_uart_set_stop_bits(g_uart_h, PERIPHERAL_UART_STOP_BITS_1BIT);
+ goto_if(ret != PERIPHERAL_ERROR_NONE, error);
+
+ ret = peripheral_uart_set_flow_control(g_uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE);
+ goto_if(ret != PERIPHERAL_ERROR_NONE, error);
+
+ ret = peripheral_uart_write(g_uart_h, data, INPUT_SIZE);
+ goto_if(ret < 0, error); /* the number of bytes write on success, otherwise a negative error value */
+ }
+
+ ret = peripheral_uart_read(g_uart_h, rdata, OUTPUT_SIZE);
+ goto_if(ret < 0, error); /* the number of bytes write on success, otherwise a negative error value */
+
+#ifdef DEBUG
+ _D("Read : %d", ret);
+#endif
+
+#ifdef DEBUG
+ for (int i = 0; i < OUTPUT_SIZE; i++) {
+ _D("0x%X", rdata[i]);
+ }
+#endif
+
+ *target_object = (double) (rdata[4] << 8 | rdata[5]) / 100.0f;
+ *target_ambient = (double) (rdata[6] << 8 | rdata[7]) / 100.0f;
+
+#ifdef DEBUG
+ if (*target_object != 0.0f)
+ _D("Target Object : %f, Target Ambient : %f", target_object, target_ambient);
+#endif
+
+ return 0;
+
+error:
+ resource_close_mcu90615(GPIO_UART);
+
+ return -1;
+}