AN4156 Application note



Similar documents
EVL185W-LEDTV. 185 W power supply with PFC and standby supply for LED TV based on the L6564, L6599A and Viper27L. Features.

AN4108 Application note

AN3332 Application note

AN3354 Application note

DDSL01. Secondary protection for DSL lines. Features. Description

BD238. Low voltage PNP power transistor. Features. Applications. Description. Low saturation voltage PNP transistor

TN0023 Technical note

ULN2801A, ULN2802A, ULN2803A, ULN2804A

Single LNB supply and control IC DiSEqC 1.X compliant with EXTM based on the LNBH29 in a QFN16 (4x4) Description

2STBN15D100. Low voltage NPN power Darlington transistor. Features. Application. Description

BD241A BD241C. NPN power transistors. Features. Applications. Description. NPN transistors. Audio, general purpose switching and amplifier transistors

SPC5-FLASHER. Flash management tool for SPC56xx family. Description. Features

UM0985 User manual. Developing your STM32VLDISCOVERY application using the IAR Embedded Workbench software. Introduction

AN3998 Application note

BD135 - BD136 BD139 - BD140

ST High voltage fast-switching NPN power transistor. Features. Applications. Description

UM1676 User manual. Getting started with.net Micro Framework on the STM32F429 Discovery kit. Introduction

AN2604 Application note

M24LRxx/CR95HF application software installation guide

AN3353 Application note

DSL01-xxxSC5. Secondary protection for DSL lines. Features. Description. Applications. Benefits. Complies with the following standards

AN2389 Application note

ULN2001, ULN2002 ULN2003, ULN2004

LM337. Three-terminal adjustable negative voltage regulators. Features. Description

AN2680 Application note

AN3110 Application note

ETP01-xx21. Protection for Ethernet lines. Features. Description. Applications. Benefits. Complies with the following standards

ESDLIN1524BJ. Transil, transient voltage surge suppressor diode for ESD protection. Features. Description SOD323

AN3265 Application note

STEVAL-IEG001V2. Smart real-time vehicle tracking system. Features

AN2824 Application note

EN: This Datasheet is presented by the m anufacturer. Please v isit our website for pricing and availability at ore.hu.

L78MxxAB L78MxxAC. Precision 500 ma regulators. Features. Description

UM1790 User manual. Getting started with STM32L053 discovery kit software development tools. Introduction

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

Description. IO and RF AGC. ASIC controller and power management. Carrier recovery loop. GPIO switch matrix. Lock indicator and monitoring DVBS2 FEC

BZW50. Transil, transient voltage surge suppressor (TVS) Features. Description

LM135-LM235-LM335. Precision temperature sensors. Features. Description

How To Write To An Eeprom Memory On A Flash Memory On An Iphone Or Ipro Memory On Microsoft Flash Memory (Eeprom) On A Microsoft Microsoft Powerbook (Ai) 2.2.2

Description. Table 1. Device summary

LM134-LM234-LM334. Three terminal adjustable current sources. Features. Description

ST19NP18-TPM-I2C. Trusted Platform Module (TPM) with I²C Interface. Features

AN3359 Application note

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

Order code Temperature range Package Packaging

MC Low noise quad operational amplifier. Features. Description

UM1680 User manual. Getting started with STM32F429 Discovery software development tools. Introduction

UM1613 User manual. 16-pin smartcard interface ST8034P demonstration board. Introduction

Table 1. Absolute maximum ratings (T amb = 25 C) Symbol Parameter Value Unit. ISO C = 330 pf, R = 330 Ω : Contact discharge Air discharge

AN2866 Application note

STTH2R06. High efficiency ultrafast diode. Features. Description

Description. Table 1. Device summary. Order code Temperature range Package Packaging Marking

L6234. Three phase motor driver. Features. Description

AN2557 Application note

Description. Table 1. Device summary. Order codes. TO-220 (single gauge) TO-220 (double gauge) D²PAK (tape and reel) TO-220FP

STP60NF06. N-channel 60V Ω - 60A TO-220 STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

SPC5-CRYP-LIB. SPC5 Software Cryptography Library. Description. Features. SHA-512 Random engine based on DRBG-AES-128

AN4128 Application note

UA741. General-purpose single operational amplifier. Features. Applications. Description. N DIP8 (plastic package)

STTH1R04-Y. Automotive ultrafast recovery diode. Features. Description

P6KE. Transil, transient voltage surge suppressor (TVS) Features. Description. Complies with the following standards

STP60NF06FP. N-channel 60V Ω - 30A TO-220FP STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

STN3NF06L. N-channel 60 V, 0.07 Ω, 4 A, SOT-223 STripFET II Power MOSFET. Features. Application. Description

AN2703 Application note

AN2760 Application note

AN3990 Application note

AN3270 Application note

TDA W CAR RADIO AUDIO AMPLIFIER

Description SO-8. series. Furthermore, in the 8-pin configuration Very low-dropout voltage (0.2 V typ.)

AN3252 Application note

AN4368 Application note

Obsolete Product(s) - Obsolete Product(s)

TDA2004R W stereo amplifier for car radio. Features. Description

STP55NF06L STB55NF06L - STB55NF06L-1

AN2328 Application note

STGB10NB37LZ STGP10NB37LZ

AN1819 APPLICATION NOTE Bad Block Management in Single Level Cell NAND Flash Memories

AN820 APPLICATION NOTE INPUT/OUTPUT PROTECTION FOR AUTOMOTIVE COMPUTER

STP10NK80ZFP STP10NK80Z - STW10NK80Z

STDP2690. Advanced DisplayPort to DisplayPort (dual mode) converter. Features. Applications

MC34063AB, MC34063AC, MC34063EB, MC34063EC

STTH110. High voltage ultrafast rectifier. Description. Features

STCS A max constant current LED driver. Features. Applications. Description

AN2146 APPLICATION NOTE

VN05N. High side smart power solid state relay PENTAWATT. Features. Description

AN3155 Application note

STB75NF75 STP75NF75 - STP75NF75FP

STB4NK60Z, STB4NK60Z-1, STD4NK60Z STD4NK60Z-1, STP4NK60Z,STP4NK60ZFP

STCS1A. 1.5 A max constant current LED driver. Features. Applications. Description

VN03. ISO high side smart power solid state relay PENTAWATT. Features. Description.

UM1075 User manual. ST-LINK/V2 in-circuit debugger/programmer for STM8 and STM32. Introduction

LM2901. Low-power quad voltage comparator. Features. Description

STOD2540. PMOLED display power supply. Features. Application. Description

AN3211 Application note

UM0834 User manual. Developing and debugging your STM8S-DISCOVERY application code. Introduction. Reference documents

AN438 APPLICATION NOTE SAFETY PRECAUTIONS FOR DEVELOPMENT TOOL TRIAC + MICROCONTROLLER

STLM20. Ultra-low current 2.4 V precision analog temperature sensor. Features. Applications

STDP2600. Advanced HDMI to DisplayPort (dual mode) converter. Features. Applications

VN5R003H-E. 3 mω reverse battery protection switch. Features. Description. Application

Transcription:

Application note Hardware abstraction layer for Android Introduction This application note provides guidelines for successfully integrating STMicroelectronics sensors (accelerometer, magnetometer, gyroscope and pressure) into the Android operating system. The configuration files of the sensor HAL (hardware abstraction layer) are discussed along with the issues and possible solutions for successfully integrating different kinds of sensors. Finally, the building and installation of this library is also described. September 2012 Doc ID 023584 Rev 1 1/12 www.st.com

Contents AN4156 Contents 1 Sensor HAL: overview....................................... 4 2 Sensor HAL: files........................................... 5 2.1 Configuration.h.............................................. 5 2.1.1 SENSOR_ACC_LABEL...................................... 5 2.1.2 SENSOR_ACC_INCLUDE_FILE_NAME........................ 5 2.1.3 SENSOR_ACC_DATANAME_ACCELEROMETER................. 6 2.1.4 SENSOR_DELAY_FILENAME, SENSOR_ENABLE_FILENAME, SENSOR_RANGE_FILENAME................................ 6 2.1.5 ACCEL_MAX_RANGE, ACCEL_MAX_RANGE................... 6 2.1.6 ACCEL_POWER_CONSUMPTION............................ 6 2.1.7 ACCEL_DEFAULT_FULLSCALE............................... 6 2.2 Sensor.h................................................... 6 3 How to build and install the Android sensor HAL................ 10 4 Revision history........................................... 11 2/12 Doc ID 023584 Rev 1

List of figures List of figures Figure 1. Android sensor subsystem.................................................. 4 Figure 2. ENU coordinate system.................................................... 7 Figure 3. Example of sensor placement on the board..................................... 7 Figure 4. UML of hardware abstraction layer............................................ 9 Doc ID 023584 Rev 1 3/12

Sensor HAL: overview AN4156 1 Sensor HAL: overview The Android sensor HAL is the library which provides the links by kernel-space drivers to the Android sensor service and Android sensor manager. The architecture of the Android sensor framework is shown in Figure 1: Application framework: applications that make use of the sensors utilize the Application framework to get data from the devices. The communication starts in the sensor manager class to then pass to the lower layer through the sensor JNI (Java native interface). Sensor libraries: these libraries have the purpose of creating a sophisticated interface for the upper layer. This is done through the sensor manager class, sensor service class, and the sensor HAL, which is the focus of this document. Kernel: in this layer we find Linux device drivers created using the input subsystem, a generic Linux framework for all input devices such as the mouse, keyboard, joystick, etc. The data are exported to the user space through the sysfs virtual file system (/sys/class/input/). The driver sends/receives data to/from the sensor through the stable Linux subsystem I2C. Figure 1. Android sensor subsystem 4/12 Doc ID 023584 Rev 1

Sensor HAL: files 2 Sensor HAL: files In this section we examine the sensor HAL library files and its architecture model. There are two configuration files in the library: configuration.h and sensors.h. The configuration.h file is used to set some parameters such as the names of the sensors, full scale defaults, names of the sysfs files, enable or disable debug information, etc. The sensors.h file is used to set the convert value of the data, the axis mapping through rotation matrices and the event type of the drivers. The UML graph of the HAL library structure is shown in Figure 4. The library is written in C++ language using the object-oriented approach, for each sensor there is a custom class file (AccelSensor.cpp, MagnSensor.cpp, GyroSensor.cpp and PressTempSensor.cpp) which extends the common base class (SensorBase.cpp). 2.1 Configuration.h As mentioned above, the configuration file is used to describe some parameters of the sensors. In this short paragraph we describe all the parameters and what they mean. An example of a configuration file for the LSM303DLHC accelerometer is shown in Figure 2. The first macro visible in this file, ANDROID_JELLY_BEAN, is used as the define if the library is built for Android Jelly Bean version (4.1). The parameters of the other sensors are the same as those used in this accelerometer example...... /* ACCELEROMETER SENSOR \*/ #define SENSOR_ACC_LABEL LSM303DLHC 3-axis Accelerometer #define SENSOR_ACC_INCLUDE_FILE_NAME lsm303dlhc.h #define SENSOR_DATANAME_ACCELEROMETER LSM303DLHC_ACC_DEV_NAME #define ACCEL_DELAY_FILE_NAME pollrate_ms #define ACCEL_ENABLE_FILE_NAME enable_device #define ACCEL_RANGE_FILE_NAME range #define ACCEL_MAX_RANGE 16*GRAVITY_EARTH #define ACCEL_MAX_ODR 400 #define ACCEL_POWER_CONSUMPTION 0.033f #define ACCEL_DEFAULT_FULLSCALE 4..... 2.1.1 SENSOR_ACC_LABEL This macro is used to define the sensor name visible in the Android application. Doc ID 023584 Rev 1 5/12

Sensor HAL: files AN4156 2.1.2 SENSOR_ACC_INCLUDE_FILE_NAME This macro is used to define the name of the header file of the device driver, located in the include subfolder. 2.1.3 SENSOR_ACC_DATANAME_ACCELEROMETER This macro is necessary to search the device in the input subsystem. This name is visible in the header file of the driver (in this case it is set in the LSM303DLHC_ACC_DEV_NAME macro) and used in the implementation file of the driver through the input device structure called input_dev->name. 2.1.4 SENSOR_DELAY_FILENAME, SENSOR_ENABLE_FILENAME, SENSOR_RANGE_FILENAME ACCEL_DELAY_FILE_NAME, ACCEL_ENABLE_FILE_NAME and ACCEL_RANGE_FILE_NAME are necessary to define the names of the files needed to read/write sensor data (these files are located in the sysfs virtual file system [/sys/class/i2c-adapter/i2c-n/n-00xx/], where n is the I2C bus number and xx the sensor I2C address). 2.1.5 ACCEL_MAX_RANGE, ACCEL_MAX_RANGE These macros are used to inform Android about the operating range for the sensors. When Android requires the value for the maximum range of measurements: this value is set through the ACCEL_MAX_RANGE macro and expressed in m/s^2 (in this example, 16 is the full scale of the accelerometer) for the maximum ODR (output data rate) defined in the ACCEL_MAX_ODR macro and expressed in Hz (400 Hz is the maximum ODR for the accelerometer). 2.1.6 ACCEL_POWER_CONSUMPTION Power consumption of the sensor expressed in ma. 2.1.7 ACCEL_DEFAULT_FULLSCALE The ACCEL_DEFAULT_FULLSCALE macro is used to define the default full scale used when Android requires the use of this sensor (in this example, 4g). 2.2 Sensor.h This configuration file is used to change the event type generated by the driver through the input subsystem, to define rotation matrix as regards the ENU Android coordinate system and, finally, to define the factor of the data conversion. In most cases the event type does not change, however, this parameter is set through the EVENT_TYPE_****_* macro, according to the driver: see input set_abs_params() function in the input driver. The most important parameters of this file are the rotation matrices: they are necessary to rotate the single coordinate system of each sensor to only one general coordinate system of the board/smartphone. In fact, the Android O.S. expects sensor data in only one coordinate system called ENU (East, North, Up), visible in Figure 2. 6/12 Doc ID 023584 Rev 1

Sensor HAL: files Figure 2. ENU coordinate system Figure 3 shows the accelerometer, magnetometer and gyroscope placed on a PCB. The orientation of the device on the PCB can be done in the driver code through the axis_map_x, axis_map_y and axis_map_z variables or with rotation matrices. Figure 3. Example of sensor placement on the board The transformation matrices are defined as: x b y b z b x s y s z s = y 1 y 2 y 3 = x 1 x 2 x 3 z 1 z 2 z 3 T x s x 1 + x s y 1 + z s z 1 x s x 2 + x s y 2 + z s z 2 x s x 3 + x s y 3 + z s z 3 where x b, y b, z b are board coordinates and x s, y s, z s are sensor coordinates. The single coordinate system for each sensor is visible in the sensor datasheet. Doc ID 023584 Rev 1 7/12

Sensor HAL: files AN4156 In this case, for example, the rotation matrices are defined as: Accelerometer: x b y b z b x a y a z a = 100 = 010 001 T x a y a z a Magnetometer: x b y b z b x m y m z m = 0 1 0 = 1 0 0 0 0 1 T x m y m z m Gyroscope: x b y b z b x g y g z g = 1 0 0 = 0 1 0 0 0 1 T x g y g z g In the last section of the configuration file the user must define what the conversion factors are to convert driver data values into the Android default measurement units. Android expects accelerometer data in m/s^2, magnetometer data in ut and the gyroscope data in rad/sec. 8/12 Doc ID 023584 Rev 1

Sensor HAL: files Figure 4. UML of hardware abstraction layer Doc ID 023584 Rev 1 9/12

How to build and install the Android sensor HAL AN4156 3 How to build and install the Android sensor HAL The build system in Android is very easy thanks to the Android build environment and to the Android makefiles. After having successfully downloaded and compiled the Android sources, the user can compile and add/substitute the sensor HAL library. To do this, copy the sensor HAL library folder in the android sources path, usually located in: [Root Android Sources]/vendor/[vendor name]/[boardname]/ Before the build operation of the library, the user must initialize the Android environment: [Root Android Sources]$ source build/envsetup.sh [Root Android Sources]$ lunch [target board] It is now possible to build the library; just launch the mm command in the HAL folder. The result of this process is a dynamic library located in: [Root Android Sources]/out/target/product/[board name]/system/lib/hw/sensors.[board name].so The user can add this library or substitute the existing library using adb push, but they must remount the Android system partition to push it: [Root Android Sources]$ adb shell] [Android shell]$ mount... /dev/block/platform/omap/omap_hsmmc.0/by-name/system /system ext4 ro,relatime,barrier=1,data=ordered 0 0... [Android shell]$ mount -o remount,rw /dev/block/platform/omap/omap_hsmmc.0/by-name/system [Root Android Sources]/out/target/product/[board name]/system/lib/hw/adb push sensors.[board name].so /system/lib/hw/ 10/12 Doc ID 023584 Rev 1

Revision history 4 Revision history Table 1. Document revision history Date Revision Changes 24-Sep-2012 1 Initial release. Doc ID 023584 Rev 1 11/12

Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. 2012 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 12/12 Doc ID 023584 Rev 1