2 * Copyright (c) 2019 G.camp,
4 * Contact: Jin Seog Bang <seog814@gmail.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <peripheral_io.h>
25 #include "resource_internal.h"
28 #define I2C_PIN_MAX 28
30 #define LIDAR_V1_ADDRW 0x62
31 #define LIDAR_V1_ADDRR 0x63
32 #define LIDAR_CONSTANT_NUM (1.00)
36 peripheral_i2c_h sensor_h;
40 void resource_close_initial_LIDAR_sensor(void)
42 if (!resource_sensor_s.opened)
45 _I("initial_LIDAR_Sensor is finishing...");
46 peripheral_i2c_close(resource_sensor_s.sensor_h);
47 resource_sensor_s.opened = 0;
50 void resource_close_two_read_set_LIDAR_sensor(void)
52 if (!resource_sensor_s.opened)
55 _I("2 byte read_set LIDAR_Sensor is finishing...");
56 peripheral_i2c_close(resource_sensor_s.sensor_h);
57 resource_sensor_s.opened = 0;
60 void resource_close_read_LIDAR_sensor(void)
62 if (!resource_sensor_s.opened)
65 _I("2 byte read_LIDAR_Sensor is finishing...");
66 peripheral_i2c_close(resource_sensor_s.sensor_h);
67 resource_sensor_s.opened = 0;
70 int resource_initial_LIDAR_sensor(int i2c_bus)
72 int ret = PERIPHERAL_ERROR_NONE;
74 unsigned char buf[10] = { 0, };
75 resource_write_led(5, 1); // debug led on
76 if (!resource_sensor_s.opened) {
78 ret = peripheral_i2c_open(i2c_bus, LIDAR_V1_ADDRW, &resource_sensor_s.sensor_h);
80 if (ret != PERIPHERAL_ERROR_NONE) {
81 _E("i2c open error : %s", get_error_message(ret));
85 resource_sensor_s.opened = 1;
93 ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 2);
94 if (ret != PERIPHERAL_ERROR_NONE) {
95 _E("i2c write error : %s", get_error_message(ret));
100 _I("iic LIDAR control reset ... step ");
106 ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 2);
107 if (ret != PERIPHERAL_ERROR_NONE) {
108 _E("i2c write error : %s", get_error_message(ret));
113 _I("iic LIDAR control reset ... step ");
118 int resource_two_read_set_LIDAR_sensor(int i2c_bus)
120 int ret = PERIPHERAL_ERROR_NONE;
121 static int write = 0;
122 unsigned char buf[10] = { 0, };
124 if (!resource_sensor_s.opened) {
126 ret = peripheral_i2c_open(i2c_bus, LIDAR_V1_ADDRW, &resource_sensor_s.sensor_h);
127 if (ret != PERIPHERAL_ERROR_NONE) {
128 _E("i2c open error : %s", get_error_message(ret));
132 resource_sensor_s.opened = 1;
139 ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 1);
140 if (ret != PERIPHERAL_ERROR_NONE) {
141 _E("i2c write error : %s", get_error_message(ret));
147 _I("iic LIDAR control 2byte read set .. step ");
152 int resource_read_LIDAR_sensor(int i2c_bus, uint32_t *out_value)
154 int ret = PERIPHERAL_ERROR_NONE;
156 unsigned char buf[10] = { 0, };
158 if (!resource_sensor_s.opened) {
160 ret = peripheral_i2c_open(i2c_bus, LIDAR_V1_ADDRR, &resource_sensor_s.sensor_h);
161 if (ret != PERIPHERAL_ERROR_NONE) {
162 _E("i2c open error : %s", get_error_message(ret));
165 resource_sensor_s.opened = 1;
168 ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2);
170 if (ret != PERIPHERAL_ERROR_NONE) {
171 _E("i2c read error : %s", get_error_message(ret));
176 *out_value = (buf[0] << 8 | buf[1]) / LIDAR_CONSTANT_NUM;
179 resource_write_led(5, 0); // debug led off