2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jin Yoon <jinny.yoon@samsung.com>
5 * Geunsun Lee <gs86.lee@samsung.com>
6 * Eunyoung Lee <ey928.lee@samsung.com>
7 * Junkyu Han <junkyu.han@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include <peripheral_io.h>
28 #include "resource_internal.h"
30 #define I2C_PIN_MAX 28
32 #define GY30_ADDR 0x23 /* Address of GY30 light sensor */
33 #define GY30_CONT_HIGH_RES_MODE 0x10 /* Start measurement at 11x resolution. Measurement time is approx 120mx */
34 #define GY30_CONSTANT_NUM (1.2)
38 peripheral_i2c_h sensor_h;
41 void resource_close_illuminance_sensor(void)
43 if (!resource_sensor_s.opened) return;
45 _I("Infrared Motion Sensor is finishing...");
46 peripheral_i2c_close(resource_sensor_s.sensor_h);
47 resource_sensor_s.opened = 0;
50 /* You have to use this illuminance sensor ONLY ONE in the pi board */
51 int resource_read_illuminance_sensor(int i2c_bus, int *out_value)
53 int ret = PERIPHERAL_ERROR_NONE;
54 unsigned char buf[10] = { 0, };
56 if (!resource_sensor_s.opened) {
57 ret = peripheral_i2c_open(i2c_bus, GY30_ADDR, &resource_sensor_s.sensor_h);
58 retv_if(!resource_sensor_s.sensor_h, -1);
59 resource_sensor_s.opened = 1;
62 ret = peripheral_i2c_write_byte(resource_sensor_s.sensor_h, GY30_CONT_HIGH_RES_MODE);
65 ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2);
68 *out_value = (buf[0] << 8 | buf[1]) / GY30_CONSTANT_NUM; // Just Sum High 8bit and Low 8bit
70 _I("Infrared Motion Sensor Value : %d", *out_value);