--- /dev/null
+# Copyright (C) 2008 The Android Open Source Project
+#
+# 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.
+
+# HAL module implemenation, not prelinked, and stored in
+# hw/<SENSORS_HARDWARE_MODULE_ID>.<ro.product.board>.so
+
+ifeq ($(TARGET_BOARD_PLATFORM),baytrail)
+ifeq ($(BOARD_USE_PLATFORM_SENSOR_LIB),true)
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# Common files.
+common_src_path := ..
+common_src_files := $(common_src_path)/sensors.cpp \
+ $(common_src_path)/SensorBase.cpp \
+ $(common_src_path)/SensorInputDev.cpp \
+ $(common_src_path)/InputEventReader.cpp \
+ $(common_src_path)/Helpers.cpp \
+ $(common_src_path)/SensorIIODev.cpp \
+
+# Board specific sensors.
+sensor_src_files := $(common_src_path)/HidSensor_Accel3D.cpp \
+ $(common_src_path)/HidSensor_Gyro3D.cpp \
+ $(common_src_path)/HidSensor_Compass3D.cpp \
+ $(common_src_path)/HidSensor_ALS.cpp \
+ $(common_src_path)/RotVecSensor.cpp \
+ $(common_src_path)/SynthCompassSensor.cpp \
+ $(common_src_path)/OrientationSensor.cpp \
+
+include external/stlport/libstlport.mk
+LOCAL_C_INCLUDES += $(LOCAL_PATH) vendor/intel/hardware/libsensors
+
+LOCAL_MODULE := sensors.$(TARGET_DEVICE)
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -DLOG_TAG=\"Sensors\"
+LOCAL_SHARED_LIBRARIES := liblog libcutils libdl libstlport
+LOCAL_PRELINK_MODULE := false
+LOCAL_SRC_FILES := $(common_src_files) $(sensor_src_files) BoardConfig.cpp
+
+include $(BUILD_SHARED_LIBRARY)
+
+endif # BOARD_USE_PLATFORM_SENSOR_LIB == true
+endif # TARGET_BOARD_PLATFORM == baytrail
--- /dev/null
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * 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 <fcntl.h>
+#include <errno.h>
+#include <cutils/log.h>
+#include <unistd.h>
+#include <cutils/properties.h>
+
+#include "common.h"
+
+#include "BoardConfig.h"
+#include "SensorConfig.h"
+#include "HidSensor_Accel3D.h"
+#include "HidSensor_Gyro3D.h"
+#include "HidSensor_Compass3D.h"
+#include "HidSensor_ALS.h"
+#include "OrientationSensor.h"
+#include "RotVecSensor.h"
+#include "SynthCompassSensor.h"
+
+static const struct sensor_t sSensorList[] = {
+ AccelSensor::sSensorInfo_accel3D,
+ GyroSensor::sSensorInfo_gyro3D,
+ SynthCompassSensor::sSensorInfo_compass,
+ ALSSensor::sSensorInfo_als,
+ RotVecSensor::sSensorInfo_rotvec,
+ OrientationSensor::sSensorInfo_orientation,
+};
+
+const struct sensor_t* BoardConfig::sensorList()
+{
+ return sSensorList;
+}
+
+int BoardConfig::sensorListSize()
+{
+ int num_files(0);
+ DIR *dp(0);
+ struct dirent *dirp(0);
+ const char *key = "persist.sys.sensors.iio.present";
+ char value[PROPERTY_VALUE_MAX];
+
+ if (property_get(key, value, "")) {
+ if (strncmp(value, "1", 1) == 0) {
+ ALOGI("IIO sensor hub detected previously; assuming it is still attached.");
+ return ARRAY_SIZE(sSensorList);
+ } else {
+ ALOGI("IIO sensor hub not detected previously; assuming it still is not attached.");
+ return 0;
+ }
+ }
+
+ for (int i=0; i<250; i++) {
+ num_files = 0;
+ if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
+ usleep(20000);
+ continue;
+ }
+ while ((dirp = readdir(dp)) != NULL){
+ num_files++;
+ }
+ closedir(dp);
+
+ if (num_files <= 2) {
+ usleep(20000);
+ continue;
+ }
+ ALOGI("Found IIO sensor hub.");
+ if (property_set(key, "1") != 0) {
+ ALOGE("Failed to set %s", key);
+ }
+ return ARRAY_SIZE(sSensorList);
+ }
+
+ ALOGI("Didn't find IIO sensor hub.");
+ if (property_set(key, "0") != 0) {
+ ALOGE("Failed to set %s", key);
+ }
+ return 0;
+}
+
+void BoardConfig::initSensors(SensorBase* sensors[])
+{
+ sensors[accel] = new AccelSensor();
+ sensors[gyro] = new GyroSensor();
+ sensors[compass] = new CompassSensor();
+ sensors[light] = new ALSSensor();
+ sensors[rotvec] = new RotVecSensor();
+ sensors[syncompass] = new SynthCompassSensor();
+ sensors[orientation] = new OrientationSensor();
+}
+
+int BoardConfig::handleToDriver(int handle)
+{
+ switch (handle) {
+ case ID_A:
+ return accel;
+ case ID_M:
+ return compass;
+ case ID_PR:
+ case ID_T:
+ return -EINVAL;
+ case ID_GY:
+ return gyro;
+ case ID_L:
+ return light;
+ case ID_R:
+ return rotvec;
+ case ID_SC:
+ return syncompass;
+ case ID_O:
+ return orientation;
+ default:
+ return -EINVAL;
+ }
+ return -EINVAL;
+}
--- /dev/null
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * 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 SENSOR_CONFIG_H
+#define SENSOR_CONFIG_H
+
+#include <hardware/hardware.h>
+#include <hardware/sensors.h>
+#include <cmath>
+
+/* Maps senor id's to the sensor list */
+enum {
+ accel = 0,
+ gyro,
+ compass,
+ light,
+ rotvec,
+ syncompass,
+ orientation,
+ numSensorDrivers,
+ numFds,
+};
+
+
+
+/*****************************************************************************/
+
+/* Board specific sensor configs. */
+#define GRAVITY 9.80665f
+#define EVENT_TYPE_ACCEL_X REL_X
+#define EVENT_TYPE_ACCEL_Y REL_Y
+#define EVENT_TYPE_ACCEL_Z REL_Z
+
+#define EVENT_TYPE_COMP_X REL_X
+#define EVENT_TYPE_COMP_Y REL_Y
+#define EVENT_TYPE_COMP_Z REL_Z
+
+#define EVENT_TYPE_YAW REL_RX
+#define EVENT_TYPE_PITCH REL_RY
+#define EVENT_TYPE_ROLL REL_RZ
+#define EVENT_TYPE_ORIENT_STATUS REL_WHEEL
+
+#define EVENT_TYPE_MAGV_X REL_DIAL
+#define EVENT_TYPE_MAGV_Y REL_HWHEEL
+#define EVENT_TYPE_MAGV_Z REL_MISC
+
+#define EVENT_TYPE_PROXIMITY ABS_DISTANCE
+#define EVENT_TYPE_LIGHT ABS_MISC
+
+#define EVENT_TYPE_GYRO_X REL_X
+#define EVENT_TYPE_GYRO_Y REL_Y
+#define EVENT_TYPE_GYRO_Z REL_Z
+
+#define EVENT_TYPE_PRESSURE REL_X
+#define EVENT_TYPE_TEMPERATURE REL_Y
+
+// 720 LSG = 1G
+#define LSG (1024.0f)
+#define NUMOFACCDATA (8.0f)
+
+// conversion of acceleration data to SI units (m/s^2)
+
+#define RANGE_A (2*GRAVITY_EARTH)
+#define RESOLUTION_A (RANGE_A/(256*NUMOFACCDATA))
+#define CONVERT_A (GRAVITY_EARTH / LSG / NUMOFACCDATA)
+#define CONVERT_A_X(x) ((float(x)/1000) * (GRAVITY * -1.0))
+#define CONVERT_A_Y(x) ((float(x)/1000) * (GRAVITY * 1.0))
+#define CONVERT_A_Z(x) ((float(x)/1000) * (GRAVITY * 1.0))
+// conversion of magnetic data to uT units
+#define RANGE_M (2048.0f)
+#define RESOLUTION_M (0.01)
+#define CONVERT_M (1.0f/6.6f)
+#define CONVERT_M_X (-CONVERT_M)
+#define CONVERT_M_Y (-CONVERT_M)
+#define CONVERT_M_Z (CONVERT_M)
+
+/* conversion of orientation data to degree units */
+#define CONVERT_O (1.0f/64.0f)
+#define CONVERT_O_A (CONVERT_O)
+#define CONVERT_O_P (CONVERT_O)
+#define CONVERT_O_R (-CONVERT_O)
+
+// conversion of gyro data to SI units (radian/sec)
+#define RANGE_GYRO (2000.0f*(float)M_PI/180.0f)
+#define CONVERT_GYRO ((2000.0f / 32767.0f) * ((float)M_PI / 180.0f))
+#define CONVERT_GYRO_X (-CONVERT_GYRO)
+#define CONVERT_GYRO_Y (-CONVERT_GYRO)
+#define CONVERT_GYRO_Z (CONVERT_GYRO)
+
+// conversion of pressure and temperature data
+#define CONVERT_PRESSURE (1.0f/100.0f)
+#define CONVERT_TEMPERATURE (1.0f/100.0f)
+
+#define RESOLUTION_GYRO (RANGE_GYRO/(2000*NUMOFACCDATA))
+#define SENSOR_STATE_MASK (0x7FFF)
+
+// Proximity Threshold
+#define PROXIMITY_THRESHOLD_GP2A 5.0f
+
+//Used in timespec_to_ns calculations
+#define NSEC_PER_SEC 1000000000L
+
+#define BIT(x) (1 << (x))
+
+inline unsigned int set_bit_range(int start, int end)
+{
+ int i;
+ unsigned int value = 0;
+
+ for (i = start; i < end; ++i)
+ value |= BIT(i);
+ return value;
+}
+
+inline float convert_from_vtf_format(int size, int exponent, unsigned int value)
+{
+ int divider=1;
+ int i;
+ float sample;
+ int mul = 1.0;
+
+ value = value & set_bit_range(0, size*8);
+ if (value & BIT(size*8-1)) {
+ value = ((1LL << (size*8)) - value);
+ mul = -1.0;
+ }
+ sample = value * 1.0;
+ if (exponent < 0) {
+ exponent = abs(exponent);
+ for (i = 0; i < exponent; ++i) {
+ divider = divider*10;
+ }
+ return mul * sample/divider;
+ } else {
+ return mul * sample * pow(10.0, exponent);
+ }
+}
+
+// Platform sensor orientatation
+#define DEF_ORIENT_ACCEL_X -1
+#define DEF_ORIENT_ACCEL_Y -1
+#define DEF_ORIENT_ACCEL_Z -1
+
+#define DEF_ORIENT_GYRO_X 1
+#define DEF_ORIENT_GYRO_Y 1
+#define DEF_ORIENT_GYRO_Z 1
+
+// G to m/s2
+#define CONVERT_FROM_VTF16(s,d,x) (convert_from_vtf_format(s,d,x))
+#define CONVERT_A_G_VTF16E14_X(s,d,x) (DEF_ORIENT_ACCEL_X *\
+ convert_from_vtf_format(s,d,x)*GRAVITY)
+#define CONVERT_A_G_VTF16E14_Y(s,d,x) (DEF_ORIENT_ACCEL_Y *\
+ convert_from_vtf_format(s,d,x)*GRAVITY)
+#define CONVERT_A_G_VTF16E14_Z(s,d,x) (DEF_ORIENT_ACCEL_Z *\
+ convert_from_vtf_format(s,d,x)*GRAVITY)
+
+// Degree/sec to radian/sec
+#define CONVERT_G_D_VTF16E14_X(s,d,x) (DEF_ORIENT_GYRO_X *\
+ convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
+#define CONVERT_G_D_VTF16E14_Y(s,d,x) (DEF_ORIENT_GYRO_Y *\
+ convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
+#define CONVERT_G_D_VTF16E14_Z(s,d,x) (DEF_ORIENT_GYRO_Z *\
+ convert_from_vtf_format(s,d,x) * ((float)M_PI/180.0f))
+
+// Milli gauss to micro tesla
+#define CONVERT_M_MG_VTF16E14_X(s,d,x) (convert_from_vtf_format(s,d,x)/10)
+#define CONVERT_M_MG_VTF16E14_Y(s,d,x) (convert_from_vtf_format(s,d,x)/10)
+#define CONVERT_M_MG_VTF16E14_Z(s,d,x) (convert_from_vtf_format(s,d,x)/10)
+
+/*****************************************************************************/
+
+#endif // SENSOR_CONFIG_H