SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Kürzlich hochgeladen (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

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