SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Presented by
Date
Event
SFO15-505: Introducing
I2C and GPIO userspace
APIs for Android
Satish PatelSatish Patel
Friday 25 September 2015
SFO15
Scope
● Background
● High level diagram
● API reference
● Why native libs ?
● Why SDK Addon ?
● Application reference
● Demo!!
Master Slave
VCC
SDA
SCL
GND
GPIO
Background
● Modularity spreading across all domains
○ e.g. Project ARA based on concept - Phoneblocks
● Plenty i2c/spi/gpio based sensors/devices..
- But no straight APIs to Android at present
● It’s a kick start to build bridge to access non-
conventional protocols inside Android
High Level Diagram - I2C
I2C DEVICE
HARDWARE
/dev/i2c-x
KERNEL
ioctl
I2C NATIVE API
(libandroidruntime.so) II2cManagerService
I2cService
I2cManagerI2cDevice
libudev
I2C APP
------------------------------------
I2C SDK Addon lib
I2C HAL
HAL
FRAMEWORK
APPLICATION
Read app meta-data
and extra device
information for which
access is requested
High Level Diagram - GPIO
GPIO DEVICE
HARDWARE
/sys/class/gpio
KERNEL
IGpioManagerService
GpioService
GpioManager
libudev
GPIO APP
------------------------------------
GPIO SDK Addon lib
GPIO HAL
FRAMEWORK
APPLICATION
HAL
API Reference - I2C
APIs Description
I2cManager :
getInstance(Context context)
Returns a new instance of this class
I2cManager :
openDevice()
Opens an i2c device so it can be used to send
and receive data using I2cDevice
I2cDevice :
closePfd()
Close ParcelFileDescriptor attached to i2c
device
I2cDevice : doTransaction
(I2cMessage... msgs)
Perform i2c transaction
I2cDevice : setSlave(int addr) Set i2c slave address
I2cDevice : getPfd() Returns ParcelFileDescriptor of an i2c device
API Reference - GPIO
APIs Description
GpioManager :
getInstance(Context context)
Returns a new instance of this class
GpioManager :
openGpio(int gpio, java.lang.String
direction)
Returns file descriptor of gpio device value
closeGpio(int gpio) Close mentioned gpio number
Why libudev ?
● Hotplug does not guarantee static device node
● I2C HAL opens device based on “product id” not with
actual device node
● HAL finds correct i2c device based on “product id” and
map the device node.
So HAL need libudev help!!!
char *find_i2cdevice(const char *dev_name)
shell@pxa1928:/ # cat /sys/class/i2c-dev/i2c-0/device/0-0030/name
88pm800
Why Native Libs?
● I2cDevice class has PFD:ParcelFileDescriptor
● JAVA developers can use - i/o stream to do
transaction with i2c device using PFD
● Still “I want more…”
○ set slave address
○ multiple i2c transactions
○ setting 10 bit address scheme
Why Native Libs? Contd..
I2cService
● lPC lentancy
● Some apps need
continuous data from the
device might suffer
Native Extension (I2cDevice)
● Runs in application context
● APIs
○ setSlave()
○ doTransaction()
● Work on opened PFD
● No special permission
needed
SERVICE
APP
BINDER
Why SDK Addon?
● Enable device specific features to app developers
● Avoid distribution of whole OEM specific SDK -
Can run on existing AOSP SDK - Size matters !!!
● Only Stubs will be visible to App developer
● Easy of integration - Android Studio
Application Front
<?xml version="1.0" encoding="utf-8"?>
<manifest ….
<uses-feature android:name="android.hardware.i2c" />
<application…
<uses-library android:name="com.google.ara.i2c" />
<activity…..
<intent-filter>
<category android:name="android.intent.category.
DEFAULT" />
<action android:name="android.hardware.i2c.action.
I2C_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.i2c.action.
I2C_DEVICE_ATTACHED"
android:resource="@xml/i2c_filter" />
</activity>
</application>
</manifest>
res/xml/i2c_filter.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<i2c-device product-id="<ABC>" vendor-id=”
<XYZ>" version="1.0"/>
</resources>
Application Front - open device & set slave
import com.google.ara.i2c.I2cManager;
import com.google.ara.i2c.I2cDevice;
import com.google.ara.i2c.I2cMessage;
…...
…...
private I2cManager i2cm;
I2cDevice mDevice;
void openI2cDevice() {
i2cm = I2cManager.getInstance(this);
mDevice = i2cm.openDevice();
..…..
.…...
}
// set slave addr
I2cDevice mDevice;
/* open i2c device before setting slave address */
public void setSlave() {
int ret;
ret = mDevice.setSlave(0x4c); //0x4c is for ref#
if(ret == 0)
Log.d(TAG, "Slave address set!!");
else
Log.d(TAG, "Error in setting slave
address");
}
Application Front - i2c transactions
// use native APIs
public void readValueNative() {
byte[] reg = new byte[1];
byte[] data = new byte[1];
int ret = 0;
reg[0] = (byte)0x3A;
/* Two operation is necessary for read operation
* first write the register we want to read
* and then read the data
*/
I2cMessage[] msg = new I2cMessage[2];
msg[0] = new I2cMessage(0x30, 0, 1, reg); /* slave addr, write, length, reg */
msg[1] = new I2cMessage(0x30, 1, 1, data); /* slave addr, read, lenght, data */
ret = mDevice.doTransaction(msg);
String hexString = Integer.toHexString(data[0]);
Log.d(TAG, "Read Value Native, hex string:" + hexString);
}
Application Front - Using Java I/O
public void openI2cDevice() {
mDevice =i2cm.openDevice();
mPfd = mDevice.getPfd();
// open file stream using fd
mFile = pfd.getFileDescriptor();
mInputStream = new FileInputStream(pfile);
mOutputStream = new FileOutputStream(pfile);
………
}
//reading the value from i2c device
public void readValue () {
byte[] data = {0,0,0,0,0};
byte[] cmd = new byte[1];
cmd[0] = (byte) 0x3A;
setSlave();
// first write the cmd for register we want to read and then
read the value
try {
mOutputStream.write(cmd);
mOutputStream.flush();
mInputStream.read(data);
} catch (IOException e) {
Log.d(TAG, "Something wrong with device read
and write"); }
Application Front - GPIO
<?xml version="1.0" encoding="utf-8"?>
<manifest ….
<uses-feature android:name="android.hardware.gpio" />
<application…
<uses-library android:name="com.google.ara.gpio" />
<activity…..
<meta-data
android:name="android.hardware.gpio.action.
GPIO_DEVICE_ATTACHED"
android:resource="@xml/gpio_filter" />
</activity>
</application>
</manifest>
res/xml/gpio_filter.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<gpio-device product-id="<ABC>" vendor-
id=”<XYZ>" version="1.0"/>
</resources>
References
● Helium - PXA1928 based release with i2c/gpio support
available at
http://releases-ara-mdk.linaro.org/ara_pxa1928-5.1.1-open/
● Release includes prebuilt binary, demo application binary
and sources
Demo !!
Thank You

Contenu connexe

Plus de Linaro

It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...
It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...
It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...Linaro
 
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...Linaro
 
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...Linaro
 
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...Linaro
 
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainlineHKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainlineLinaro
 
HKG18-100K1 - George Grey: Opening Keynote
HKG18-100K1 - George Grey: Opening KeynoteHKG18-100K1 - George Grey: Opening Keynote
HKG18-100K1 - George Grey: Opening KeynoteLinaro
 
HKG18-318 - OpenAMP Workshop
HKG18-318 - OpenAMP WorkshopHKG18-318 - OpenAMP Workshop
HKG18-318 - OpenAMP WorkshopLinaro
 
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainlineHKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainlineLinaro
 
HKG18-315 - Why the ecosystem is a wonderful thing, warts and all
HKG18-315 - Why the ecosystem is a wonderful thing, warts and allHKG18-315 - Why the ecosystem is a wonderful thing, warts and all
HKG18-315 - Why the ecosystem is a wonderful thing, warts and allLinaro
 
HKG18- 115 - Partitioning ARM Systems with the Jailhouse Hypervisor
HKG18- 115 - Partitioning ARM Systems with the Jailhouse HypervisorHKG18- 115 - Partitioning ARM Systems with the Jailhouse Hypervisor
HKG18- 115 - Partitioning ARM Systems with the Jailhouse HypervisorLinaro
 
HKG18-TR08 - Upstreaming SVE in QEMU
HKG18-TR08 - Upstreaming SVE in QEMUHKG18-TR08 - Upstreaming SVE in QEMU
HKG18-TR08 - Upstreaming SVE in QEMULinaro
 
HKG18-113- Secure Data Path work with i.MX8M
HKG18-113- Secure Data Path work with i.MX8MHKG18-113- Secure Data Path work with i.MX8M
HKG18-113- Secure Data Path work with i.MX8MLinaro
 
HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation Linaro
 
HKG18-223 - Trusted FirmwareM: Trusted boot
HKG18-223 - Trusted FirmwareM: Trusted bootHKG18-223 - Trusted FirmwareM: Trusted boot
HKG18-223 - Trusted FirmwareM: Trusted bootLinaro
 
HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...
HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...
HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...Linaro
 
HKG18-317 - Arm Server Ready Program
HKG18-317 - Arm Server Ready ProgramHKG18-317 - Arm Server Ready Program
HKG18-317 - Arm Server Ready ProgramLinaro
 
HKG18-312 - CMSIS-NN
HKG18-312 - CMSIS-NNHKG18-312 - CMSIS-NN
HKG18-312 - CMSIS-NNLinaro
 
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...Linaro
 
HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...
HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...
HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...Linaro
 
HKG18-212 - Trusted Firmware M: Introduction
HKG18-212 - Trusted Firmware M: IntroductionHKG18-212 - Trusted Firmware M: Introduction
HKG18-212 - Trusted Firmware M: IntroductionLinaro
 

Plus de Linaro (20)

It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...
It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...
It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...
 
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...
 
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...
 
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...
 
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainlineHKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
 
HKG18-100K1 - George Grey: Opening Keynote
HKG18-100K1 - George Grey: Opening KeynoteHKG18-100K1 - George Grey: Opening Keynote
HKG18-100K1 - George Grey: Opening Keynote
 
HKG18-318 - OpenAMP Workshop
HKG18-318 - OpenAMP WorkshopHKG18-318 - OpenAMP Workshop
HKG18-318 - OpenAMP Workshop
 
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainlineHKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
 
HKG18-315 - Why the ecosystem is a wonderful thing, warts and all
HKG18-315 - Why the ecosystem is a wonderful thing, warts and allHKG18-315 - Why the ecosystem is a wonderful thing, warts and all
HKG18-315 - Why the ecosystem is a wonderful thing, warts and all
 
HKG18- 115 - Partitioning ARM Systems with the Jailhouse Hypervisor
HKG18- 115 - Partitioning ARM Systems with the Jailhouse HypervisorHKG18- 115 - Partitioning ARM Systems with the Jailhouse Hypervisor
HKG18- 115 - Partitioning ARM Systems with the Jailhouse Hypervisor
 
HKG18-TR08 - Upstreaming SVE in QEMU
HKG18-TR08 - Upstreaming SVE in QEMUHKG18-TR08 - Upstreaming SVE in QEMU
HKG18-TR08 - Upstreaming SVE in QEMU
 
HKG18-113- Secure Data Path work with i.MX8M
HKG18-113- Secure Data Path work with i.MX8MHKG18-113- Secure Data Path work with i.MX8M
HKG18-113- Secure Data Path work with i.MX8M
 
HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation
 
HKG18-223 - Trusted FirmwareM: Trusted boot
HKG18-223 - Trusted FirmwareM: Trusted bootHKG18-223 - Trusted FirmwareM: Trusted boot
HKG18-223 - Trusted FirmwareM: Trusted boot
 
HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...
HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...
HKG18-500K1 - Keynote: Dileep Bhandarkar - Emerging Computing Trends in the D...
 
HKG18-317 - Arm Server Ready Program
HKG18-317 - Arm Server Ready ProgramHKG18-317 - Arm Server Ready Program
HKG18-317 - Arm Server Ready Program
 
HKG18-312 - CMSIS-NN
HKG18-312 - CMSIS-NNHKG18-312 - CMSIS-NN
HKG18-312 - CMSIS-NN
 
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...
 
HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...
HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...
HKG18-300K2 - Keynote: Tomas Evensen - All Programmable SoCs? – Platforms to ...
 
HKG18-212 - Trusted Firmware M: Introduction
HKG18-212 - Trusted Firmware M: IntroductionHKG18-212 - Trusted Firmware M: Introduction
HKG18-212 - Trusted Firmware M: Introduction
 

Dernier

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Dernier (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

SFO15-505: Introducing I2C & GPIO user space APIs for Android

  • 1. Presented by Date Event SFO15-505: Introducing I2C and GPIO userspace APIs for Android Satish PatelSatish Patel Friday 25 September 2015 SFO15
  • 2. Scope ● Background ● High level diagram ● API reference ● Why native libs ? ● Why SDK Addon ? ● Application reference ● Demo!! Master Slave VCC SDA SCL GND GPIO
  • 3. Background ● Modularity spreading across all domains ○ e.g. Project ARA based on concept - Phoneblocks ● Plenty i2c/spi/gpio based sensors/devices.. - But no straight APIs to Android at present ● It’s a kick start to build bridge to access non- conventional protocols inside Android
  • 4. High Level Diagram - I2C I2C DEVICE HARDWARE /dev/i2c-x KERNEL ioctl I2C NATIVE API (libandroidruntime.so) II2cManagerService I2cService I2cManagerI2cDevice libudev I2C APP ------------------------------------ I2C SDK Addon lib I2C HAL HAL FRAMEWORK APPLICATION Read app meta-data and extra device information for which access is requested
  • 5. High Level Diagram - GPIO GPIO DEVICE HARDWARE /sys/class/gpio KERNEL IGpioManagerService GpioService GpioManager libudev GPIO APP ------------------------------------ GPIO SDK Addon lib GPIO HAL FRAMEWORK APPLICATION HAL
  • 6. API Reference - I2C APIs Description I2cManager : getInstance(Context context) Returns a new instance of this class I2cManager : openDevice() Opens an i2c device so it can be used to send and receive data using I2cDevice I2cDevice : closePfd() Close ParcelFileDescriptor attached to i2c device I2cDevice : doTransaction (I2cMessage... msgs) Perform i2c transaction I2cDevice : setSlave(int addr) Set i2c slave address I2cDevice : getPfd() Returns ParcelFileDescriptor of an i2c device
  • 7. API Reference - GPIO APIs Description GpioManager : getInstance(Context context) Returns a new instance of this class GpioManager : openGpio(int gpio, java.lang.String direction) Returns file descriptor of gpio device value closeGpio(int gpio) Close mentioned gpio number
  • 8. Why libudev ? ● Hotplug does not guarantee static device node ● I2C HAL opens device based on “product id” not with actual device node ● HAL finds correct i2c device based on “product id” and map the device node. So HAL need libudev help!!! char *find_i2cdevice(const char *dev_name) shell@pxa1928:/ # cat /sys/class/i2c-dev/i2c-0/device/0-0030/name 88pm800
  • 9. Why Native Libs? ● I2cDevice class has PFD:ParcelFileDescriptor ● JAVA developers can use - i/o stream to do transaction with i2c device using PFD ● Still “I want more…” ○ set slave address ○ multiple i2c transactions ○ setting 10 bit address scheme
  • 10. Why Native Libs? Contd.. I2cService ● lPC lentancy ● Some apps need continuous data from the device might suffer Native Extension (I2cDevice) ● Runs in application context ● APIs ○ setSlave() ○ doTransaction() ● Work on opened PFD ● No special permission needed SERVICE APP BINDER
  • 11. Why SDK Addon? ● Enable device specific features to app developers ● Avoid distribution of whole OEM specific SDK - Can run on existing AOSP SDK - Size matters !!! ● Only Stubs will be visible to App developer ● Easy of integration - Android Studio
  • 12. Application Front <?xml version="1.0" encoding="utf-8"?> <manifest …. <uses-feature android:name="android.hardware.i2c" /> <application… <uses-library android:name="com.google.ara.i2c" /> <activity….. <intent-filter> <category android:name="android.intent.category. DEFAULT" /> <action android:name="android.hardware.i2c.action. I2C_DEVICE_ATTACHED" /> </intent-filter> <meta-data android:name="android.hardware.i2c.action. I2C_DEVICE_ATTACHED" android:resource="@xml/i2c_filter" /> </activity> </application> </manifest> res/xml/i2c_filter.xml <?xml version="1.0" encoding="utf-8"?> <resources> <i2c-device product-id="<ABC>" vendor-id=” <XYZ>" version="1.0"/> </resources>
  • 13. Application Front - open device & set slave import com.google.ara.i2c.I2cManager; import com.google.ara.i2c.I2cDevice; import com.google.ara.i2c.I2cMessage; …... …... private I2cManager i2cm; I2cDevice mDevice; void openI2cDevice() { i2cm = I2cManager.getInstance(this); mDevice = i2cm.openDevice(); ..….. .…... } // set slave addr I2cDevice mDevice; /* open i2c device before setting slave address */ public void setSlave() { int ret; ret = mDevice.setSlave(0x4c); //0x4c is for ref# if(ret == 0) Log.d(TAG, "Slave address set!!"); else Log.d(TAG, "Error in setting slave address"); }
  • 14. Application Front - i2c transactions // use native APIs public void readValueNative() { byte[] reg = new byte[1]; byte[] data = new byte[1]; int ret = 0; reg[0] = (byte)0x3A; /* Two operation is necessary for read operation * first write the register we want to read * and then read the data */ I2cMessage[] msg = new I2cMessage[2]; msg[0] = new I2cMessage(0x30, 0, 1, reg); /* slave addr, write, length, reg */ msg[1] = new I2cMessage(0x30, 1, 1, data); /* slave addr, read, lenght, data */ ret = mDevice.doTransaction(msg); String hexString = Integer.toHexString(data[0]); Log.d(TAG, "Read Value Native, hex string:" + hexString); }
  • 15. Application Front - Using Java I/O public void openI2cDevice() { mDevice =i2cm.openDevice(); mPfd = mDevice.getPfd(); // open file stream using fd mFile = pfd.getFileDescriptor(); mInputStream = new FileInputStream(pfile); mOutputStream = new FileOutputStream(pfile); ……… } //reading the value from i2c device public void readValue () { byte[] data = {0,0,0,0,0}; byte[] cmd = new byte[1]; cmd[0] = (byte) 0x3A; setSlave(); // first write the cmd for register we want to read and then read the value try { mOutputStream.write(cmd); mOutputStream.flush(); mInputStream.read(data); } catch (IOException e) { Log.d(TAG, "Something wrong with device read and write"); }
  • 16. Application Front - GPIO <?xml version="1.0" encoding="utf-8"?> <manifest …. <uses-feature android:name="android.hardware.gpio" /> <application… <uses-library android:name="com.google.ara.gpio" /> <activity….. <meta-data android:name="android.hardware.gpio.action. GPIO_DEVICE_ATTACHED" android:resource="@xml/gpio_filter" /> </activity> </application> </manifest> res/xml/gpio_filter.xml <?xml version="1.0" encoding="utf-8"?> <resources> <gpio-device product-id="<ABC>" vendor- id=”<XYZ>" version="1.0"/> </resources>
  • 17. References ● Helium - PXA1928 based release with i2c/gpio support available at http://releases-ara-mdk.linaro.org/ara_pxa1928-5.1.1-open/ ● Release includes prebuilt binary, demo application binary and sources