概述
/*
* 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
*
*
* 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 <string.h>
#include <stdint.h>
#include <string.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/log.h>
#include <hardware/sensors.h>
#include <utils/Timers.h>
char const* getSensorName(int type) {
switch(type) {
case SENSOR_TYPE_ACCELEROMETER:
return "Acc";
case SENSOR_TYPE_MAGNETIC_FIELD:
return "Mag";
case SENSOR_TYPE_ORIENTATION:
return "Ori";
case SENSOR_TYPE_GYROSCOPE:
return "Gyr";
case SENSOR_TYPE_LIGHT:
return "Lux";
case SENSOR_TYPE_PRESSURE:
return "Bar";
case SENSOR_TYPE_TEMPERATURE:
return "Tmp";
case SENSOR_TYPE_PROXIMITY:
return "Prx";
case SENSOR_TYPE_GRAVITY:
return "Grv";
case SENSOR_TYPE_LINEAR_ACCELERATION:
return "Lac";
case SENSOR_TYPE_ROTATION_VECTOR:
return "Rot";
case SENSOR_TYPE_RELATIVE_HUMIDITY:
return "Hum";
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
return "Tam";
}
return "ukn";
}
int main(int argc, char** argv)
{
int err;
struct sensors_poll_device_t* device;
struct sensors_module_t* module;
err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
if (err != 0) {
printf("hw_get_module() failed (%s)n", strerror(-err));
return 0;
}
err = sensors_open(&module->common, &device);
if (err != 0) {
printf("sensors_open() failed (%s)n", strerror(-err));
return 0;
}
struct sensor_t const* list;
int count = module->get_sensors_list(module, &list);
printf("%d sensors found:n", count);
for (int i=0 ; i<count ; i++) {
printf("%sn"
"tvendor: %sn"
"tversion: %dn"
"thandle: %dn"
"ttype: %dn"
"tmaxRange: %fn"
"tresolution: %fn"
"tpower: %f mAn",
list[i].name,
list[i].vendor,
list[i].version,
list[i].handle,
list[i].type,
list[i].maxRange,
list[i].resolution,
list[i].power);
}
static const size_t numEvents = 16;
sensors_event_t buffer[numEvents];
for (int i=0 ; i<count ; i++) {
err = device->activate(device, list[i].handle, 0);
if (err != 0) {
printf("deactivate() for '%s'failed (%s)n",
list[i].name, strerror(-err));
return 0;
}
}
for (int i=0 ; i<count ; i++) {
err = device->activate(device, list[i].handle, 1);
if (err != 0) {
printf("activate() for '%s'failed (%s)n",
list[i].name, strerror(-err));
return 0;
}
device->setDelay(device, list[i].handle, ms2ns(10));
}
do {
int n = device->poll(device, buffer, numEvents);
if (n < 0) {
printf("poll() failed (%s)n", strerror(-err));
break;
}
printf("read %d events:n", n);
for (int i=0 ; i<n ; i++) {
const sensors_event_t& data = buffer[i];
if (data.version != sizeof(sensors_event_t)) {
printf("incorrect event version (version=%d, expected=%d",
data.version, sizeof(sensors_event_t));
break;
}
switch(data.type) {
case SENSOR_TYPE_ACCELEROMETER:
case SENSOR_TYPE_MAGNETIC_FIELD:
case SENSOR_TYPE_ORIENTATION:
case SENSOR_TYPE_GYROSCOPE:
case SENSOR_TYPE_GRAVITY:
case SENSOR_TYPE_LINEAR_ACCELERATION:
case SENSOR_TYPE_ROTATION_VECTOR:
printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>n",
getSensorName(data.type),
data.timestamp,
data.data[0],
data.data[1],
data.data[2]);
break;
case SENSOR_TYPE_LIGHT:
case SENSOR_TYPE_PRESSURE:
case SENSOR_TYPE_TEMPERATURE:
case SENSOR_TYPE_PROXIMITY:
case SENSOR_TYPE_RELATIVE_HUMIDITY:
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
printf("sensor=%s, time=%lld, value=%fn",
getSensorName(data.type),
data.timestamp,
data.data[0]);
break;
default:
printf("sensor=%d, time=%lld, value=<%f,%f,%f, ...>n",
data.type,
data.timestamp,
data.data[0],
data.data[1],
data.data[2]);
break;
}
}
} while (1); // fix that
for (int i=0 ; i<count ; i++) {
err = device->activate(device, list[i].handle, 0);
if (err != 0) {
printf("deactivate() for '%s'failed (%s)n",
list[i].name, strerror(-err));
return 0;
}
}
err = sensors_close(device);
if (err != 0) {
printf("sensors_close() failed (%s)n", strerror(-err));
}
return 0;
}
CamLinux.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:=
nusensors.cpp
LOCAL_SHARED_LIBRARIES :=
libcutils libhardware
LOCAL_MODULE:= test-nusensors
LOCAL_MODULE_TAGS := eng optional
include $(BUILD_EXECUTABLE)
patch1 :
diff --git a/device/softwinner/common/hardware/sensors/sensorDetect.cpp b/device/softwinner/common/hardware/sensors/sensorDetect.cpp
index 16ee80c..de1f4ac 100755
--- a/device/softwinner/common/hardware/sensors/sensorDetect.cpp
+++ b/device/softwinner/common/hardware/sensors/sensorDetect.cpp
@@ -435,6 +435,21 @@ struct sensor_extend_t gsensorList[] = {
{ },
},
},
+ {
+ {
+ "da380", LSG_DAM380,
+ }, {
+ "da380 3-axis Accelerometer",
+ "Bosch",
+ 1, 0,
+ SENSOR_TYPE_ACCELEROMETER,
+ 2.0f*9.81f,
+ (2.0f*9.81f)/1024.0f,
+ 0.2f, 0,
+ 0, 0,
+ { },
+ },
+ },
};
diff --git a/device/softwinner/common/hardware/sensors/sensors.h b/device/softwinner/common/hardware/sensors/sensors.h
index e41d212..eb9288f 100755
--- a/device/softwinner/common/hardware/sensors/sensors.h
+++ b/device/softwinner/common/hardware/sensors/sensors.h
@@ -121,6 +121,7 @@ __BEGIN_DECLS
#define LSG_MC32X0 (64.0f)
#define LSG_LIS3DE_ACC (65.0f)
#define LSG_BMA250 (256.0f)
+#define LSG_DAM380 (256.0f)
#define LSG_STK831X (21.0f)
#define LSG_DMARD06 (256.0f)
#define LSG_DMARD10 (1024.0f)
diff --git a/device/softwinner/crane-cdr/configs/gsensor.cfg b/device/softwinner/crane-cdr/configs/gsensor.cfg
index f9d0e71..8de9128 100755
--- a/device/softwinner/crane-cdr/configs/gsensor.cfg
+++ b/device/softwinner/crane-cdr/configs/gsensor.cfg
@@ -97,3 +97,13 @@ gsensor_direct_x = true
gsensor_direct_y = true
gsensor_direct_z = true
gsensor_xy_revert = false
+
+;--------------------------
+;name:da380
+;--------------------------
+gsensor_name = da380
+gsensor_direct_x = true
+gsensor_direct_y = true
+gsensor_direct_z = true
+gsensor_xy_revert = true
+
patch2:
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index d097fbc..2407108 100755
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -947,6 +947,7 @@ config SENSORS_PCF8591
hardware. If unsure, say N.
source drivers/hwmon/pmbus/Kconfig
+source drivers/hwmon/da380/Kconfig
config SENSORS_SHT15
tristate "Sensiron humidity and temperature sensors. SHT15 and compat."
@@ -1488,3 +1489,4 @@ config SENSORS_INA219_ACCUMULATE
endif # I2C
endif # HWMON
+
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index a12e58e..afeedee 100755
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -137,6 +137,8 @@ obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
obj-$(CONFIG_PMBUS) += pmbus/
+obj-$(CONFIG_DA380) += da380/
+
obj-$(CONFIG_SENSORS_INA219) += ina219.o
ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
diff --git a/drivers/input/sw-device.c b/drivers/input/sw-device.c
index 535e069..019a2d1 100755
--- a/drivers/input/sw-device.c
+++ b/drivers/input/sw-device.c
@@ -15,6 +15,7 @@ module_param_named(ctp_mask, ctp_mask, int , S_IRUGO | S_IWUSR | S_IWGRP);
/*gsensor info*/
static struct sw_device_info gsensors[] = {
{ "bma250", {0x18, 0x19, 0x08, 0x38}, 0x00, {0x02,0x03,0xf9}, 0},
+ { "da380", {0x27, 0x26 }, 0x01, {0x13 }, 0},
{ "mma8452", {0x1c, 0x1d }, 0x0d, {0x2A }, 0},
{ "mma7660", {0x4c }, 0x00, {0x00 }, 0},
{ "mma865x", {0x1d }, 0x0d, {0x4A,0x5A }, 0},
patch3:
diff --git a/pack/chips/sun8iw8p1/configs/CDR/sys_config.fex b/pack/chips/sun8iw8p1/configs/CDR/sys_config.fex
index 0068321..d8e064d 100755
--- a/pack/chips/sun8iw8p1/configs/CDR/sys_config.fex
+++ b/pack/chips/sun8iw8p1/configs/CDR/sys_config.fex
@@ -106,12 +106,17 @@ uart_debug_rx = port:PG07<2><1><default><default>
;jtag_enable = 0-disable jtag, 1-enable jtag
;----------------------------------------------------------------------------------
[jtag_para]
-jtag_enable = 0
+jtag_enable = 1
jtag_ms = port:PB10<2><default><default><default>
jtag_ck = port:PB11<2><default><default><default>
jtag_do = port:PB12<2><default><default><default>
jtag_di = port:PB13<2><default><default><default>
+;jtag_ms = port:PF0<3><default><default><default>
+;jtag_ck = port:PF5<3><default><default><default>
+;jtag_do = port:PF3<3><default><default><default>
+;jtag_di = port:PF1<3><default><default><default>
+
;----------------------------------------------------------------------------------
;[clock] pll configuration
;----------------------------------------------------------------------------------
@@ -825,6 +830,7 @@ gsensor_int2 =
[gsensor_list_para]
gsensor_det_used = 1
bma250 = 1
+da380 = 1
mma8452 = 1
mma7660 = 1
mma865x = 1
最后
以上就是舒心大碗为你收集整理的linux gsensor demo的全部内容,希望文章能够帮你解决linux gsensor demo所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复