2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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 Flora License, Version 1.1 (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://floralicense.org/license/
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("Illuminance Sensor is finishing...");
46 peripheral_i2c_close(resource_sensor_s.sensor_h);
47 resource_sensor_s.opened = 0;
50 int resource_read_illuminance_sensor(int i2c_bus, int *out_value)
52 int ret = PERIPHERAL_ERROR_NONE;
53 unsigned char buf[10] = { 0, };
55 if (!resource_sensor_s.opened) {
56 ret = peripheral_i2c_open(i2c_bus, GY30_ADDR, &resource_sensor_s.sensor_h);
57 retv_if(!resource_sensor_s.sensor_h, -1);
58 resource_sensor_s.opened = 1;
61 buf[0] = GY30_CONT_HIGH_RES_MODE;
62 ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 1);
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("Illuminance Sensor Value : %d", *out_value);