Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Oskar Andero <oskar.andero@sonymobile.com>
  • Loading branch information
Oskar Andero committed Jun 13, 2012
0 parents commit 133b721
Show file tree
Hide file tree
Showing 48 changed files with 6,665 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ifeq ($(SOMC_CFG_DASH_INCLUDED),yes)

LOCAL_PATH := $(call my-dir)

# HAL module implemenation, not prelinked and stored in
# hw/<SENSORS_HARDWARE_MODULE_ID>.<ro.product.board>.so
include $(CLEAR_VARS)

LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_SHARED_LIBRARIES := \
liblog \
libcutils

LOCAL_SRC_FILES += sensors_module.c \
sensors_list.c \
sensors_config.c \
sensors_fifo.c \
sensors_worker.c \
sensors_select.c \
sensors_wrapper.c \
sensors/sensor_util.c

LOCAL_CFLAGS += -I$(LOCAL_PATH)/sensors

# Uncomment to enable debug
#LOCAL_CFLAGS += -DDEBUG -UNDEBUG

# Comment to enable debug
LOCAL_CFLAGS += -DLOG_NDEBUG

# Set 1 to enable verbose debug
LOCAL_CFLAGS += -DDEBUG_VERBOSE=0

include $(LOCAL_PATH)/sensors/Sensors.mk
LOCAL_SRC_FILES += $(patsubst %,sensors/%, $(DASH_SENSORS))
LOCAL_CFLAGS += $(DASH_SENSORS_CFLAGS)
LOCAL_STATIC_LIBRARIES += $(DASH_SENSORS_STATIC_LIBS)
LOCAL_SHARED_LIBRARIES += $(DASH_SENSORS_SHARED_LIBS)

LOCAL_MODULE := sensors.default
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)

include $(call first-makefiles-under, $(LOCAL_PATH)/libs)

endif
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Copyright (C) 2012 Sony Mobile Communications AB

This code is licensed under Apache License, Version 2.0
For details please see: http://www.apache.org/licenses/LICENSE-2.0
154 changes: 154 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
Dynamic Android Sensor HAL
D * A * S * H

Copyright (C) Sony Mobile Communication 2012


Table of contents
-----------------

1 ............ Description
2 ............ File overview
3 ............ License


1 Motivation
------------

This sensor HAL implementation makes it possible to use one generic piece
of code to satisfy multiple product requirements. By adding the possibility
to enable sensors at compile-time it's simply a matter of specifying which
sensors the product uses.

The implementation also adds support for configuring the sensors at run-time
using a configuration file. This makes it possible to, e.g. setting PCB mounting
coordinates of the sensors.

The DASH is the only sensor HAL implementation that is needed and hence the
maintenance work is kept to a minimal.


2 File overview
---------------

2.1 Control
File: sensors_module.c

This file implements the sensor HAL interface. It traverses the enabled sensors
and routes incoming requests to the right sensor.


2.2 Sensor list
File: sensors_list.c

Each sensor registers to this list at linking of the library using gcc
constructors. This makes it possible to decide at compile-time which sensors
should be supported.

The module provides an interface for fetching and iterating over sensors.


2.3 Sensor API
File: sensor_api.h

This defines the abstraction of a sensor. A sensor supports: init, activate,
set_delay and close.


2.4 Sensor implementations
File: sensors/*.c

Each sensor is an implementation of the sensor abstraction (see Sensor API).

At startup of the library each sensor implementation has to register to the
sensor list (see Sensor list). This is done using the macro list_constructor().

Each sensor implementation will create a thread using either a sensor worker
(see Polling sensor) or a select thread (see Interrupt driven sensor).

When data has been collected it is written to the fifo by issuing a
sensors_fifo_put-call.

In the file sensor_util.c some generic helper functions have been gathered.


2.5 Polling sensor
File: sensors_worker.c

A polling sensor implementation has to own its own thread since each sensor
can run at a different poll rate. A thread is created by instanciating a sensor
worker using sensors_worker_init().

The sensors_worker will then call the provided work_func at the delay specified
by the set_delay()-call.


2.6 Interrupt driven sensor
File: sensors_select.c

An interrupt driven sensor can report data when it gets an interrupt that there
is new data to be collected. This can save some clock cycles and battery time.

By instanciating a sensors_select-worker by calling sensors_select_init(), one
will get a call to the select_func when there is new data to be read on the
provided file descriptor.


2.7 Sensor config
File: sensors_config.c

This module can be used by the sensor implementations to read configuration
parameters from a file.

Each parameter should have the following format:
<sensor name>_<parameter name> = <value>

A sensor implementation reads out the value with the function
sensors_config_get_key().


2.8 Some utilitiy stuff
File: sensors/sensor_util.c

In the file sensor_util there are some code to be used by the sensor
implementations. It contains code for transforming coordinates and some
functions for reading time.


2.9 Vendor libraries
Directory: libs/

Some sensors need vendor libraries to calibrate their output. These will
put in the libs directory.


2.10 ASCII Design

A N D R O I D
------------------------------------------------------------
|
+---------------+
| sensors_module|
+---------------+
|
+------------+
|sensors_list|
+------------+ +--------+
/ \ | Vendor |
+--------+ +--------+ | libs |
|sensor 1| ... |sensor N| -- | |
+--------+ +--------+ | |
| | +--------+
------------------------------------------------------------
L I N U X

+------------+ +------------+
|sensor dev 1| ... |sensor dev N|
+------------+ +------------+


3 License
---------

The license for all code in this project is specified in the LICENSE file.
Please, refer to this file for further details.
12 changes: 12 additions & 0 deletions docs/sensors.conf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# This is an example of a sensor configuration file for DASH.
# It sets up the axis of a bma250 accelerometer as mounted on
# the PCB.
#
bma250input_axis_x = 0
bma250input_axis_y = 1
bma250input_axis_z = 2

bma250input_neg_x = 0
bma250input_neg_y = 0
bma250input_neg_z = 0
8 changes: 8 additions & 0 deletions docs/sensors.mk.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# This is an example of a DASH configuration makefile. It should preferably be
# included from your device configuration make files.
#
SOMC_CFG_DASH_INCLUDED := yes
SOMC_CFG_SENSORS_ACCEL_BMA250_INPUT := yes
SOMC_CFG_SENSORS_COMPASS_LSM303DLH := yes
SOMC_CFG_SENSORS_PROXIMITY_NOA3402 := yes
39 changes: 39 additions & 0 deletions sensor_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2012 Sony Mobile Communications AB.
*
* 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_API_H_
#define SENSOR_API_H_
#include <stdint.h>

struct sensor_data_t {
struct sensor_t *sensor;
int *data;
int size;
float scale;
int status;
int64_t timestamp;
int delay;
};

struct sensor_api_t {
int (*init)(struct sensor_api_t *s);
int (*activate)(struct sensor_api_t *s, int enable);
int (*set_delay)(struct sensor_api_t *s, int64_t ns);
void (*close)(struct sensor_api_t *s);
void (*data)(struct sensor_api_t *s, struct sensor_data_t *sd);
};

#endif
102 changes: 102 additions & 0 deletions sensors/Sensors.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#
# Accelerometers
#
ifeq ($(SOMC_CFG_SENSORS_ACCEL_BMA150_INPUT),yes)
DASH_SENSORS += bma150_input.c
DASH_SENSORS_CFLAGS += -DACC_BMA150_INPUT
endif

ifeq ($(SOMC_CFG_SENSORS_ACCEL_BMA250_INPUT),yes)
DASH_SENSORS += bma250_input.c
DASH_SENSORS_CFLAGS += -DACC_BMA250_INPUT
endif

ifeq ($(SOMC_CFG_SENSORS_ACCEL_BMA250NA_INPUT),yes)
DASH_SENSORS += bma250na_input.c
DASH_SENSORS += wrappers/bma250na_input_accelerometer.c
DASH_SENSORS_CFLAGS += -DACC_BMA250_INPUT
endif

ifeq ($(SOMC_CFG_SENSORS_COMPASS_LSM303DLH),yes)
DASH_SENSORS_CFLAGS += -DST_LSM303DLH
DASH_ST_LSM303DLHX_ENABLE = yes
endif

ifeq ($(SOMC_CFG_SENSORS_COMPASS_LSM303DLHC),yes)
DASH_SENSORS_CFLAGS += -DST_LSM303DLHC
DASH_ST_LSM303DLHX_ENABLE = yes
endif

ifeq ($(DASH_ST_LSM303DLHX_ENABLE),yes)
DASH_SENSORS += sensor_xyz.c
DASH_SENSORS += lsm303dlhx_acc.c
DASH_SENSORS += wrappers/lsm303dlhx_accelerometer.c
endif

#
# Compasses
#

#
# Light sensors
#

#
# Proximity sensors
#
ifeq ($(SOMC_CFG_SENSORS_PROXIMITY_APDS9700),yes)
DASH_SENSORS += apds970x.c
PROXIMITY_SENSOR_NAME = "APDS9700 Proximity"
DASH_SENSORS_CFLAGS += -DPROXIMITY_SENSOR_NAME=\"$(PROXIMITY_SENSOR_NAME)\"
endif

ifeq ($(SOMC_CFG_SENSORS_PROXIMITY_APDS9702),yes)
DASH_SENSORS += apds970x.c
PROXIMITY_SENSOR_NAME = "APDS9702 Proximity"
DASH_SENSORS_CFLAGS += -DPROXIMITY_SENSOR_NAME=\"$(PROXIMITY_SENSOR_NAME)\"
endif

ifeq ($(SOMC_CFG_SENSORS_PROXIMITY_SHARP_GP2),yes)
DASH_SENSORS += sharp_gp2.c
endif

ifeq ($(SOMC_CFG_SENSORS_PROXIMITY_NOA3402),yes)
DASH_SENSORS += noa3402.c
DASH_SENSORS_CFLAGS += -DPROXIMITY_PATH=\"$(SOMC_CFG_SENSORS_PROXIMITY_NOA3402_PATH)\"
endif

ifeq ($(SOMC_CFG_SENSORS_PROXIMITY_TLS2772),yes)
DASH_SENSORS += tsl2772.c
endif

#
# Pressure sensors
#
ifeq ($(SOMC_CFG_SENSORS_PRESSURE_BMP180),yes)
DASH_SENSORS += bmp180_input.c
endif

ifeq ($(SOMC_CFG_SENSORS_PRESSURE_LPS331AP),yes)
DASH_SENSORS += lps331ap_input.c
endif

#
# Gyro sensors
#

ifeq ($(SOMC_CFG_SENSORS_GYRO_L3G4200D),yes)
ifneq ($(DASH_ST_LSM303DLHX_ENABLE),yes)
DASH_SENSORS += sensor_xyz.c
endif
DASH_SENSORS += l3g4200d_gyro.c
DASH_SENSORS += wrappers/l3g4200d_gyroscope.c
DASH_SENSORS_CFLAGS += -DGYRO_L3G4200D_INPUT
endif

#
# Wrapper sensors
#

#
# LinearAcceleration, RotationVector, Gravity
#
Loading

0 comments on commit 133b721

Please sign in to comment.