From 916da294eb330d2c975a17d1524914c62cf4d650 Mon Sep 17 00:00:00 2001 From: Marty Fouts Date: Wed, 29 Jun 2011 18:13:42 -0700 Subject: ARM: omap4: tuna: Add input event reader to sensor HAL Change-Id: I34a4a4dea8b30b22046889246f164c3ea40ab2a4 Signed-off-by: Danke Xie --- libsensors/Android.mk | 3 +- libsensors/InputEventReader.cpp | 111 ++++++++++++++++++++++++++++++++++++++++ libsensors/InputEventReader.h | 48 +++++++++++++++++ libsensors/sensors.cpp | 11 ++-- libsensors/sensors.h | 54 +++++++++++++++++++ 5 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 libsensors/InputEventReader.cpp create mode 100644 libsensors/InputEventReader.h create mode 100644 libsensors/sensors.h (limited to 'libsensors') diff --git a/libsensors/Android.mk b/libsensors/Android.mk index 6eb9556..5fe88f4 100644 --- a/libsensors/Android.mk +++ b/libsensors/Android.mk @@ -30,7 +30,8 @@ LOCAL_MODULE_TAGS := optional LOCAL_CFLAGS := -DLOG_TAG=\"Sensors\" LOCAL_C_INCLUDES += vendor/invensense/libsensors LOCAL_SRC_FILES := \ - sensors.cpp + sensors.cpp \ + InputEventReader.cpp LOCAL_SHARED_LIBRARIES := libinvensense_hal libcutils libutils libdl diff --git a/libsensors/InputEventReader.cpp b/libsensors/InputEventReader.cpp new file mode 100644 index 0000000..964eda5 --- /dev/null +++ b/libsensors/InputEventReader.cpp @@ -0,0 +1,111 @@ +/* + * 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 +#include +#include +#include + +#include +#include + +#include + +#include + +#include "InputEventReader.h" + +/*****************************************************************************/ + +template +static inline T min(T a, T b) { + return a 0) + { + iovcnt++; + iov[1].iov_base = mBuffer; + iov[1].iov_len = numSecond * sizeof(input_event); + } + + const ssize_t nread = readv(fd, iov, iovcnt); + if (nread < 0 || nread % sizeof(input_event)) { + // we got a partial event!! + return nread < 0 ? -errno : -EINVAL; + } + + numEventsRead = nread / sizeof(input_event); + if (numEventsRead) { + mHead += numEventsRead; + mFreeSpace -= numEventsRead; + if (mHead >= mBufferEnd) + mHead -= mBufferEnd - mBuffer; + } + } + + return numEventsRead; +} + +bool InputEventCircularReader::readEvent(int fd, input_event const** events) +{ + if (mFreeSpace >= mEvents) { + ssize_t eventCount = fill(fd); + if (eventCount <= 0) + return false; + } + *events = mCurr; + return true; +} + +void InputEventCircularReader::next() +{ + mCurr++; + mFreeSpace++; + if (mCurr >= mBufferEnd) { + mCurr = mBuffer; + } +} diff --git a/libsensors/InputEventReader.h b/libsensors/InputEventReader.h new file mode 100644 index 0000000..736cc17 --- /dev/null +++ b/libsensors/InputEventReader.h @@ -0,0 +1,48 @@ +/* + * 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 ANDROID_INPUT_EVENT_READER_H +#define ANDROID_INPUT_EVENT_READER_H + +#include +#include +#include +#include + +/*****************************************************************************/ + +struct input_event; + +class InputEventCircularReader +{ + struct input_event* const mBuffer; + struct input_event* const mBufferEnd; + struct input_event* mHead; + struct input_event* mCurr; + size_t mEvents; + size_t mFreeSpace; + +public: + InputEventCircularReader(size_t numEvents); + ~InputEventCircularReader(); + ssize_t fill(int fd); + bool readEvent(int fd, input_event const** events); + void next(); +}; + +/*****************************************************************************/ + +#endif /* ANDROID_INPUT_EVENT_READER_H */ diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp index 44697bf..f9dd0ef 100644 --- a/libsensors/sensors.cpp +++ b/libsensors/sensors.cpp @@ -1,6 +1,5 @@ - /* - * Copyright (C) 2011 Invensense, Inc. + * Copyright (C) 2011 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. @@ -14,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/**********Removed the gesture related code from this file for Google code check modified by Meenakshi Ramamoorthi on May 31st **********/ #define LOG_NDEBUG 0 #define LOG_TAG "Sensors" @@ -60,7 +58,6 @@ #define SENSORS_MAGNETIC_FIELD_HANDLE (ID_M) #define SENSORS_ORIENTATION_HANDLE (ID_O) - #define AKM_FTRACE 0 #define AKM_DEBUG 0 #define AKM_DATA 0 @@ -123,9 +120,11 @@ struct sensors_module_t HAL_MODULE_INFO_SYM = { version_major: 1, version_minor: 0, id: SENSORS_HARDWARE_MODULE_ID, - name: "Invensense module", - author: "Invensense Inc.", + name: "Samsung Sensor module", + author: "Samsung Electronic Company", methods: &sensors_module_methods, + dso: 0, + reserved: {}, }, get_sensors_list: sensors__get_sensors_list, }; diff --git a/libsensors/sensors.h b/libsensors/sensors.h new file mode 100644 index 0000000..4628865 --- /dev/null +++ b/libsensors/sensors.h @@ -0,0 +1,54 @@ +/* + * 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 ANDROID_SAMSUNG_SENSORS_H +#define ANDROID_SAMSUNG_SENSORS_H + +#include +#include +#include +#include + +#include + +#include +#include + +__BEGIN_DECLS + +/*****************************************************************************/ + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +/* + * The MPL-supported sensors need to have same IDs as in Invensense .so + * (from ID_MPL_BASE up to ID_O) + */ +#define ID_MPL_BASE (0) +#define ID_RV (ID_MPL_BASE) +#define ID_LA (ID_RV + 1) +#define ID_GR (ID_LA + 1) +#define ID_GY (ID_GR + 1) +#define ID_A (ID_GY + 1) +#define ID_M (ID_A + 1) +#define ID_O (ID_M + 1) + +/*****************************************************************************/ + + +__END_DECLS + +#endif /* ANDROID_SAMSUNG_SENSORS_H */ -- cgit v1.1