SlideShare a Scribd company logo
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
Legacy driver: address_data
New-style drivers: address_data /* Internal numbers to terminate lists */ I2C_CLIENT_END :  0xfffeU I2C_CLIENT_INSMOD_1  ~  I2C_CLIENT_INSMOD_8 I2C_CLIENT_INSMOD_COMMON : define   structure address_data normal_i2c, probe, ignore value
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;
I2c Driver: i2c_detect /* initial i2c client structure */ struct i2c_client *temp_client; temp_client->adapter = adapter; /* get address from i2c_client_address_data*/ address_data  =  driver ->address_data; /* check if Legacy driver */ if (! driver ->detect || ! address_data ) /* check normal_i2c ignore probe address */ for(i = 0;  address_data ->normal_i2c[i] != I2C_CLIENT_END ; i += 1)
I2c Driver: i2c_detect_address /* Make sure the address is valid */ ( addr  <  0x03  ||  addr  >  0x77 ) /* Make sure there is something at this address */ i2c_smbus_xfer (adapter, addr, 0, 0, 0,  I2C_SMBUS_QUICK , NULL) /* Finally call the custom detection function */ memset(&info, 0, sizeof(struct i2c_board_info)); driver-> detect (temp_client, kind, &info); use info.type[0] == '\0‘ to check driver->detect function /* Detection succeeded, instantiate the device */ client =  i2c_new_device (adapter, &info); list_add_tail (&client->detected, &driver->clients);
I2c Driver: i2c_new_device Set  i2c_client  info from  i2c_board_info  structure strlcpy (client->name, info->type, sizeof(client->name)); client->addr = info->addr; client->irq = info->irq; ……… ..
I2c Driver: i2c_device_match  I2c_bus_type  is used on new-style driver i2c_device_match   match client i2c_device_id  table && i2c_client table id i2c_device_probe   Call  bma150_probe  function if you defined driver’s probe.
I2c Driver:bma150_probe /* bma150 device create ok if return 0*/ misc_register (&bma_device); /* initial data */ data->smb380. bus_write  = bma150_i2c_write; data->smb380. bus_read  = bma150_i2c_read; data->smb380. delay_msec  = bma150_i2c_delay; data->smb380. dev_addr  = client->addr; smb380_init(&(data->smb380));
I2c Driver: file_operations
Build Linux Kernel Edit Kconfig & Makefile Patch all files(bma150_drivers.c…) Make menuconfig Make uImage
Issue: can’t create device /* Make sure there is something at this address */ i2c_smbus_xfer (adapter, addr, 0, 0, 0,  I2C_SMBUS_QUICK , NULL) Please edit  i2c_smbus_xfer_emulated  function and Change message data length: 0 -> 1
Demo To Do: jni module
Reference Linux Device Drivers, Third Edition
Thank You.

More Related Content

PDF
I2C Subsystem In Linux-2.6.24
PPT
Agnostic Device Drivers
PPTX
Linux I2C
PDF
I2c drivers
PDF
Character drivers
PDF
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
PDF
Project ACRN GPIO mediator introduction
PPTX
用Raspberry Pi 學Linux I2C Driver
I2C Subsystem In Linux-2.6.24
Agnostic Device Drivers
Linux I2C
I2c drivers
Character drivers
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
Project ACRN GPIO mediator introduction
用Raspberry Pi 學Linux I2C Driver

What's hot (20)

PPTX
Embedded systems design @ defcon 2015
PPTX
建構嵌入式Linux系統於SD Card
PDF
Embedded systems development Defcon 19
PPTX
Intel galileo gen 2
PDF
Project ACRN USB mediator introduction
PDF
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
PDF
What is CANopen? | ElmoMC
PDF
Intel galileo
PDF
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
PPTX
使用XMPP進行遠端設備控制
PDF
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
PDF
Let's Play STM32
PDF
Project ACRN I2C mediator introduction
PDF
Attack your Trusted Core
PDF
Linux+sensor+device-tree+shell=IoT !
PDF
Project ACRN EtherCAT 101
PDF
Lee 2020 what the clock !
PDF
Kernel Recipes 2014 - Testing Video4Linux Applications and Drivers
PDF
Advanced cfg bypass on adobe flash player 18 defcon russia 23
PDF
Reliability, Availability, and Serviceability (RAS) on ARM64 status - SFO17-203
Embedded systems design @ defcon 2015
建構嵌入式Linux系統於SD Card
Embedded systems development Defcon 19
Intel galileo gen 2
Project ACRN USB mediator introduction
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
What is CANopen? | ElmoMC
Intel galileo
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
使用XMPP進行遠端設備控制
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
Let's Play STM32
Project ACRN I2C mediator introduction
Attack your Trusted Core
Linux+sensor+device-tree+shell=IoT !
Project ACRN EtherCAT 101
Lee 2020 what the clock !
Kernel Recipes 2014 - Testing Video4Linux Applications and Drivers
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Reliability, Availability, and Serviceability (RAS) on ARM64 status - SFO17-203
Ad

Viewers also liked (12)

PDF
How to integrate front end tool via gruntjs
PDF
advanced introduction to codeigniter
PDF
Introduction to Grunt.js on Taiwan JavaScript Conference
PDF
Gearman work queue in php
PDF
Introduction to MVC of CodeIgniter 2.1.x
PPTX
Git flow 與團隊合作
PPTX
Why to choose laravel framework
PPTX
PHP & JavaScript & CSS Coding style
PPTX
用 Docker 改善團隊合作模式
PDF
RESTful API Design & Implementation with CodeIgniter PHP Framework
PPTX
Write microservice in golang
PDF
Maintainable PHP Source Code
How to integrate front end tool via gruntjs
advanced introduction to codeigniter
Introduction to Grunt.js on Taiwan JavaScript Conference
Gearman work queue in php
Introduction to MVC of CodeIgniter 2.1.x
Git flow 與團隊合作
Why to choose laravel framework
PHP & JavaScript & CSS Coding style
用 Docker 改善團隊合作模式
RESTful API Design & Implementation with CodeIgniter PHP Framework
Write microservice in golang
Maintainable PHP Source Code
Ad

Similar to Introduction to Android G Sensor I²C Driver on Android (20)

PPTX
Sdk For Firmware Development
PDF
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
PDF
Embedded system lab work
PPTX
Labs_BT_20221017.pptx
PDF
Deep Learning Edge
PPTX
Chapter 2-Bascs of Switch & Router (1).pptx
PDF
3 g modem_tutorial
PDF
I2c drivers
PPTX
Linux SD/MMC device driver
PDF
Android 5.0 Lollipop platform change investigation report
PDF
Android Things in action
PPTX
Bluetooth World 2018 - Intro to Bluetooth Low Energy with Mbed OS
DOCX
RamachandraParlapalli_RESUME
PPTX
Roll your own toy unix clone os
PDF
망고100 보드로 놀아보자 15
PPTX
Cariot
DOCX
#include stdio.h#include systypes.h#include syssocket.h
PDF
Brillo/Weave Part 2: Deep Dive
PDF
JVM code reading -- C2
PDF
Sprint 131
Sdk For Firmware Development
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
Embedded system lab work
Labs_BT_20221017.pptx
Deep Learning Edge
Chapter 2-Bascs of Switch & Router (1).pptx
3 g modem_tutorial
I2c drivers
Linux SD/MMC device driver
Android 5.0 Lollipop platform change investigation report
Android Things in action
Bluetooth World 2018 - Intro to Bluetooth Low Energy with Mbed OS
RamachandraParlapalli_RESUME
Roll your own toy unix clone os
망고100 보드로 놀아보자 15
Cariot
#include stdio.h#include systypes.h#include syssocket.h
Brillo/Weave Part 2: Deep Dive
JVM code reading -- C2
Sprint 131

More from Bo-Yi Wu (20)

PDF
Drone CI/CD 自動化測試及部署
PDF
用 Go 語言打造多台機器 Scale 架構
PDF
Job Queue in Golang
PDF
Golang Project Layout and Practice
PDF
Introduction to GitHub Actions
PDF
Drone 1.0 Feature
PDF
Drone CI/CD Platform
PDF
GraphQL IN Golang
PPTX
Go 語言基礎簡介
PPTX
drone continuous Integration
PPTX
Gorush: A push notification server written in Go
PPTX
用 Drone 打造 輕量級容器持續交付平台
PPTX
用 Go 語言 打造微服務架構
PPTX
Introduction to Gitea with Drone
PDF
運用 Docker 整合 Laravel 提升團隊開發效率
PDF
用 Go 語言實戰 Push Notification 服務
PPTX
用 Go 語言打造 DevOps Bot
PPTX
A painless self-hosted Git service: Gitea
PPTX
Docker 基礎介紹與實戰
PPTX
How to choose web framework
Drone CI/CD 自動化測試及部署
用 Go 語言打造多台機器 Scale 架構
Job Queue in Golang
Golang Project Layout and Practice
Introduction to GitHub Actions
Drone 1.0 Feature
Drone CI/CD Platform
GraphQL IN Golang
Go 語言基礎簡介
drone continuous Integration
Gorush: A push notification server written in Go
用 Drone 打造 輕量級容器持續交付平台
用 Go 語言 打造微服務架構
Introduction to Gitea with Drone
運用 Docker 整合 Laravel 提升團隊開發效率
用 Go 語言實戰 Push Notification 服務
用 Go 語言打造 DevOps Bot
A painless self-hosted Git service: Gitea
Docker 基礎介紹與實戰
How to choose web framework

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
cuic standard and advanced reporting.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation theory and applications.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
MIND Revenue Release Quarter 2 2025 Press Release
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Network Security Unit 5.pdf for BCA BBA.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation theory and applications.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Review of recent advances in non-invasive hemoglobin estimation
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks

Introduction to Android G Sensor I²C Driver on Android

  • 1. Introduction to Android G sensor I²C Driver on Android Bo-Yi Wu 2010.06.04 Gemtek Technology Co., Ltd
  • 2. Outline What’s G sensor ? I²C Driver Kernel Patch Issue Reference
  • 3. 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.
  • 6. Stability check STABLE_THRES STABLE_COUNT_MIN calling rate? bigger or smaller?
  • 8. I²C : detection capability set i2c address value detect call back function detect address fill the structure i2c_board_info
  • 9. 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.
  • 10. 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)
  • 11. 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
  • 13. New-style drivers: address_data /* Internal numbers to terminate lists */ I2C_CLIENT_END : 0xfffeU I2C_CLIENT_INSMOD_1 ~ I2C_CLIENT_INSMOD_8 I2C_CLIENT_INSMOD_COMMON : define structure address_data normal_i2c, probe, ignore value
  • 14. 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);
  • 15. 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;
  • 16. I2c Driver: i2c_detect /* initial i2c client structure */ struct i2c_client *temp_client; temp_client->adapter = adapter; /* get address from i2c_client_address_data*/ address_data = driver ->address_data; /* check if Legacy driver */ if (! driver ->detect || ! address_data ) /* check normal_i2c ignore probe address */ for(i = 0; address_data ->normal_i2c[i] != I2C_CLIENT_END ; i += 1)
  • 17. I2c Driver: i2c_detect_address /* Make sure the address is valid */ ( addr < 0x03 || addr > 0x77 ) /* Make sure there is something at this address */ i2c_smbus_xfer (adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK , NULL) /* Finally call the custom detection function */ memset(&info, 0, sizeof(struct i2c_board_info)); driver-> detect (temp_client, kind, &info); use info.type[0] == '\0‘ to check driver->detect function /* Detection succeeded, instantiate the device */ client = i2c_new_device (adapter, &info); list_add_tail (&client->detected, &driver->clients);
  • 18. I2c Driver: i2c_new_device Set i2c_client info from i2c_board_info structure strlcpy (client->name, info->type, sizeof(client->name)); client->addr = info->addr; client->irq = info->irq; ……… ..
  • 19. I2c Driver: i2c_device_match I2c_bus_type is used on new-style driver i2c_device_match match client i2c_device_id  table && i2c_client table id i2c_device_probe Call bma150_probe function if you defined driver’s probe.
  • 20. I2c Driver:bma150_probe /* bma150 device create ok if return 0*/ misc_register (&bma_device); /* initial data */ data->smb380. bus_write = bma150_i2c_write; data->smb380. bus_read = bma150_i2c_read; data->smb380. delay_msec = bma150_i2c_delay; data->smb380. dev_addr = client->addr; smb380_init(&(data->smb380));
  • 22. Build Linux Kernel Edit Kconfig & Makefile Patch all files(bma150_drivers.c…) Make menuconfig Make uImage
  • 23. Issue: can’t create device /* Make sure there is something at this address */ i2c_smbus_xfer (adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK , NULL) Please edit i2c_smbus_xfer_emulated function and Change message data length: 0 -> 1
  • 24. Demo To Do: jni module
  • 25. Reference Linux Device Drivers, Third Edition