Introduction to Android G Sensor I²C Driver on AndroidPresentation Transcript
Introduction to Android G sensor I²C Driver on Android Bo-Yi Wu 2010.06.04 Gemtek Technology Co., Ltd
Outline
What’s G sensor ?
I²C Driver
Kernel Patch
Issue
Reference
What’s G sensor & Application
As accelerometers are more and more present in mobile devices, new features are developed. Portrait & Landscape is one of them. It allows devices to display the information in the right orientation depending on how it is held.
Orientation estimation
Orientation estimation
Stability check
STABLE_THRES
STABLE_COUNT_MIN
calling rate? bigger or smaller?
Code Review
I²C : detection capability set i2c address value detect call back function detect address fill the structure i2c_board_info
New-style drivers vs Legacy drivers
Legacy drivers duplicate a lot of code .
The code needed in each driver to implement a detect callback is way smaller than the code needed to implement a legacy driver.
New-style drivers: initial function
module_init ( BMA150_init );
return i2c_add_driver (&bma150_driver);
module_exit ( BMA150_exit );
i2c_del_driver (&bma150_driver);
__exit && __init (Kernel built in or module)
G Sensor: bma150_driver structure
New-style driver
Legacy driver probe: Callback for device binding (new-style drivers) remove: Callback for device unbinding (new-style drivers) class : What kind of i2c device we instantiate (for detect) (1<<0) for sensor address_data: The I2C addresses to probe, ignore or force (for detect) id_table: List of I2C devices supported by this driver
I2c Driver: i2c_register_driver 1. new style driver methods can't mix with legacy ones /* check bma150_driver is news style driver or not */ is_newstyle_driver (driver) 2. /* check bma150_driver is Legacy style driver or not */ driver->attach_adapter || driver->detach_adapter || driver->detach_client 4. /* add bma150 driver to list for i2c only */ INIT_LIST_HEAD (&driver->clients) 5. /* Walk the adapters that are already present */ class_for_each_device struct i2c_adapter *adapter = to_i2c_adapter(dev); struct i2c_driver *driver = data; 3. /* register driver with bus, and use bus_add_driver () to add bus driver */ driver_register (&driver->driver);
I2c Driver: __attach_adapter
Call __attach_adapter function
New style driver:
i2c_detect (adapter, driver);
Legacy driver:
driver-> attach_adapter (adapter);
/* Because Legacy driver don’t have detect function */ if (!driver-> detect || !address_data) return 0;
1–1 of 1 previous next