1 <html devsite> 2 <head> 3 <title>Stylus</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <p>Android 6.0 and higher supports a standard data format for Bluetooth stylus 27 connections over Bluetooth (BT), Bluetooth Low Energy (BTLE), or USB. The 28 platform correlates timing between touch input and stylus data then provides 29 stylus data to render MotionEvents to the active application. The following 30 sections provide guidelines for OEM device implementers, stylus accessory creators, and 31 stylus application developers.</p> 32 33 <h2 id="guide-partners">Guidelines for OEM device implementers</h2> 34 <p>To enable Bluetooth stylus support, OEM device implementers must support Bluetooth 35 (and should support BTLE for wider compatibility). The platform handles data 36 collection, timing correlation, and rendering to the application for supported 37 stylus events.</p> 38 39 <p>At this time, the Android CTS <strong>does not</strong> include tests to 40 ensure existing APIs for touch events support default behavior. As a 41 workaround, we recommend creating a stylus accessory or emulator that can 42 simulate stylus events.</p> 43 44 <h2 id="guide-creators">Guidelines for stylus accessory creators</h2> 45 <p>To implement support on a stylus device, device implementers must use the Stylus 46 Human Interface Device (HID) Descriptor shown below to describe how stylus data 47 (pressure sensitivity, eraser, side buttons, device ID, etc.) is represented. 48 The stylus device sends the HID information to the Android mobile device, 49 enabling the platform to correlate HID data with touch data from the touchscreen 50 to produce stylus events via MotionEvent. Data can be sent over Bluetooth (BT), 51 Bluetooth Low Energy (BTLE), or USB.</p> 52 53 <h3 id="hid-descriptor">HID descriptor</h3> 54 55 <pre class="devsite-click-to-copy"> 56 UsagePage(Digitizer) 57 Usage(Pen) 58 Collection(Application) 59 Usage(Stylus) 60 Collection(Logical) 61 Usage(Tip Pressure) 62 Logical Minimum(0) 63 Logical Maximum(1023) 64 Report Count(1) 65 Report Size(10) 66 Input(Data, Variable, Absolute, No Null) 67 68 Usage(Barrel Switch) 69 Usage(Secondary Barrel Switch) 70 Usage(Tip Switch) 71 Usage(Invert) 72 Logical Maximum(1) 73 Report Count(4) 74 Report Size(1) 75 Input(Data, Variable, Absolute, No Null) 76 77 Usage(Transducer Serial Number) 78 Report Count(1) 79 Report Size(128) 80 Feature(Constant, Variable) 81 EndCollection 82 EndCollection 83 84 unsigned char HID_DESC[] = { 85 0x05, 0x0D, // UsagePage(Digitizer) 86 0x09, 0x02, // Usage(Pen) 87 0xA1, 0x01, // Collection(Application) 88 0x09, 0x20, // Usage(Stylus) 89 0xA1, 0x02, // Collection(Logical) 90 0x09, 0x30, // Usage(Tip Pressure) 91 0x15, 0x00, // Logical Minimum(0) 92 0x26, 0xFF, 0x03, // Logical Maximum(1023) 93 0x95, 0x01, // Report Count(1) 94 0x75, 0x0A, // Report Size(10) 95 0x81, 0x02, // Input(Data, Variable, Absolute, No Null) 96 97 0x09, 0x44, // Usage(Barrel Switch) 98 0x09, 0x5A, // Usage(Secondary Barrel Switch) 99 0x09, 0x42, // Usage(Tip Switch) 100 0x09, 0x3C, // Usage(Invert) 101 0x25, 0x01, // Logical Maximum(1) 102 0x95, 0x04, // Report Count(4) 103 0x75, 0x01, // Report Size(1) 104 0x81, 0x02, // Input(Data, Variable, Absolute, No Null) 105 106 0x09, 0x5B, // Usage(Transducer Serial Number) 107 0x95, 0x01, // Report Count(1) 108 0x75, 0x80, // Report Size(128) 109 0xB1, 0x03, // Feature(Constant, Variable) 110 0xC0, // End Collection 111 0xC0, // End Collection 112 } 113 </pre> 114 115 <h2 id="guidelines-devs">Guidelines for stylus application developers</h2> 116 <p>The Android 6.0 platform automatically handles pairing and event correlation, 117 so both existing and new applications running on Android 6.0 support Bluetooth 118 stylus by default. For details on Bluetooth stylus APIs, refer to 119 <a href="http://developer.android.com/about/versions/marshmallow/android-6.0.html#bluetooth-stylus">developer.android.com</a>. 120 121 </body> 122 </html> 123