Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
resources:tools-software:android-drivers:sensor-acceleration:adxl345 [08 Nov 2011 16:42] – [Platform data configuration] fix dead link Lars-Peter Clausenresources:tools-software:android-drivers:sensor-acceleration:adxl345 [03 Jan 2013 20:42] – external edit
Line 1: Line 1:
 +====== ADXL345/6 Android Acceleration Sensor ======
  
 +Using the ADXL345/6 under Android as Acceleration Sensor
 +
 +{{:software:driver:android:adxl_sensor_list.png|}}
 +
 +The ADXL345/6 can be easily used as Android Acceleration Sensor.
 +A few steps are necessary to add appropriate sensor support.
 +
 +===== Add Linux Driver Support: =====
 +
 +Starting with linux-2.6.36 the ADXL34x driver is mainlined.
 +If you are using an pre linux-2.6.36 kernel get the source from our repositories and add them to your kernel tree.
 +
 +Example platform data:
 +
 +<code c>
 +#include <linux/input/adxl34x.h>
 +static const struct adxl34x_platform_data adxl34x_info = {
 + .x_axis_offset = 0,
 + .y_axis_offset = 0,
 + .z_axis_offset = 0,
 + .tap_threshold = 0x31,
 + .tap_duration = 0x10,
 + .tap_latency = 0x60,
 + .tap_window = 0xF0,
 + .tap_axis_control = 0,
 + .act_axis_control = 0xFF,
 + .activity_threshold = 5,
 + .inactivity_threshold = 3,
 + .inactivity_time = 4,
 + .free_fall_threshold = 0x7,
 + .free_fall_time = 0x20,
 + .data_rate = 0x8,
 + .data_range = ADXL_FULL_RES,
 +
 + .ev_type = EV_ABS,
 + .ev_code_x = ABS_X, /* EV_REL */
 + .ev_code_y = ABS_Y, /* EV_REL */
 + .ev_code_z = ABS_Z, /* EV_REL */
 +
 + .ev_code_tap = {BTN_0, BTN_1, BTN_2}, /* EV_KEY x,y,z */
 +
 +/* .ev_code_ff = KEY_F,*/ /* EV_KEY */
 +/* .ev_code_act_inactivity = KEY_A,*/ /* EV_KEY */
 + .power_mode = ADXL_AUTO_SLEEP | ADXL_LINK,
 + .fifo_mode = ADXL_FIFO_STREAM,
 + .orientation_enable = 0, /* Disable Orientation Reports */
 + .deadzone_angle = ADXL_DEADZONE_ANGLE_10p8,
 + .divisor_length =  ADXL_LP_FILTER_DIVISOR_16,
 + /* EV_KEY {+Z, +Y, +X, -X, -Y, -Z} */
 + .ev_codes_orient_3d = {BTN_Z, BTN_Y, BTN_X, BTN_A, BTN_B, BTN_C},
 +};
 +</code>
 +
 +===== Create an Android sensor library =====
 +
 +The readme file in libhardware states: 
 +The source code for the "board" variant, usually lives under partners/...
 +The source code for "default" and "arch" would usually live under hardware/modules/.
 +
 +The sensor file is typically source code for the "board" variant.
 +However for simplicity this example puts it into a common folder structure under libhardware/modules/.
 +
 +  * Create an sensors folder under libhardware/modules
 +
 +  * Copy files sensors_adxl34x.c and Android.mk to libhardware/modules/sensors
 +
 +
 +----
 +**The files can be downloaded here:**\\
 +
 +[[bf>project/android/scmgit/|Android git]]
 +
 +  * [[http://blackfin.uclinux.org/git/?p=android;a=blob_plain;f=hardware/sensors/sensors_adxl34x.c;hb=master|sensors_adxl34x.c]]
 +  * [[http://blackfin.uclinux.org/git/?p=android;a=blob_plain;f=hardware/sensors/Android.mk;hb=master|Android.mk]]
 +
 +----
 +
 +
 +  * Make sure the makefile in the higher folder hierarchy picks up the one in libhardware/modules/sensors.
 +
 +  * Add following lines to: libhardware/Android.mk
 +
 +<code>
 +include $(addsuffix /Android.mk, $(addprefix $(LOCAL_PATH)/, \
 + modules/sensors \
 + ))
 +</code>
 +
 +In your platforms init.rc file make sure all ADXL34x drivers sysfs files {disable, rate} are owned by system:system
 +
 +  * Add following lines to your init.rc script:
 +
 +<code>
 +    chown system system /sys/class/input/event0/device/device/disable
 +    chown system system /sys/class/input/event0/device/device/rate
 +</code>
 +
 +<WRAP tip>
 +In case the ADXL345/6 is not always event0 you can alternatively approach via /sys/bus/i2c/devices/...
 +</WRAP>
 +
 +  * Rebuilt your Android tree
 +
 +<WRAP tip>
 +Upon start the Android log file (use logcat) should include following lines:
 +
 +<xterm>
 +I/SystemServer( 1862): Sensor Service
 +[--snip--]
 +D/SensorManager( 2064): found sensor: Analog Devices ADXL345/6 3-axis Accelerometer, handle=0
 +</xterm>
 +</WRAP>
 +
 +
 +===== Hints =====
 +
 +==== Sample Rate ====
 +
 +The ADXL345/6 sample rate is configurable.
 +The maximum sample rate is by default limited to 200Hz, to change this limit modify define ADXL_MAX_SAMPLE_RATE_VAL in the sensor file.
 +
 +<WRAP alert>
 +Very high sample rates > 400Hz can freeze your system!
 +</WRAP>
 +
 +<source master/hardware/sensors/sensors_adxl34x.c:control_set_delay{} c android>
 +
 +==== Platform data configuration ====
 +
 +=== Don't use BTN_TOUCH ===
 +
 +In case you experience strange input device gui interaction it might be the case that Android EventHub included the ADXL34x as input device.
 +This is typically the case if you put an BTN_TOUCH key into your ADXL34x drivers platform data.
 +
 +Upon start EventHub must emit classes=0x0:
 +<code>
 +I/EventHub( 1862): New device: path=/dev/input/event0 name=ADXL34x accelerometer id=0x10003 (of 0x4) index=4 fd=50 classes=0x0
 +</code>
 +classes=0x4 means that the ADXL34x driver is considered as Touchscreen.
 +
 +=== Auto Sleep ===
 +
 +The default platform configuration sets the driver automatically switch to sleep mode during periods of inactivity.
 +To disable this feature remove ADXL_AUTO_SLEEP from power_mode.
 +
 +Alternatively during runtime:
 +<code>
 +#echo 0 > /sys/class/input/event0/device/device/autosleep
 +</code> 
 +
 +For more information visit the [[resources/tools-software/linux-drivers/input-misc/adxl345|ADXL34x driver page]]
 +
 +
 +==== The Sources ====
 +<source master/hardware/sensors/Android.mk c android>
 +
 +<source master/hardware/sensors/sensors_adxl34x.c c android>
resources/tools-software/android-drivers/sensor-acceleration/adxl345.txt · Last modified: 11 Dec 2013 09:57 by Michael Hennerich