OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2006-2009 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 |
| 33 /** |
| 34 * @file |
| 35 * <b>NVIDIA Tegra ODM Kit: |
| 36 * Accelerometer Interface</b> |
| 37 * |
| 38 * @b Description: Defines the ODM interface for accelerometer devices. |
| 39 * |
| 40 */ |
| 41 |
| 42 #ifndef INCLUDED_NVODM_ACCELEROMETER_H |
| 43 #define INCLUDED_NVODM_ACCELEROMETER_H |
| 44 |
| 45 #if defined(__cplusplus) |
| 46 extern "C" |
| 47 { |
| 48 #endif |
| 49 |
| 50 #include "nvodm_services.h" |
| 51 #include "nvassert.h" |
| 52 |
| 53 /** |
| 54 * @defgroup nvodm_accelerometer Accelerometer Adapation Interface |
| 55 * |
| 56 * This is the accelerometer ODM adaptation interface. Currently, only 3-axis |
| 57 * accelerometers are supported by this interface. |
| 58 * |
| 59 * This section shows the calls made by the NVIDIA® Driver Development Kit |
| 60 * (DDK) accelerometer. |
| 61 * |
| 62 * @par Physical Accelerometer |
| 63 * |
| 64 * All applications share the same physical accelerometer. |
| 65 * |
| 66 * @par Sample Rate |
| 67 * |
| 68 * Every application has its own sample rate in Hz (samples/second). |
| 69 * You can set the sample rate with the NvOdmAccelSetSampleRate() function, |
| 70 * or you can request the sample rate using the NvOdmAccelGetSampleRate() |
| 71 * function. |
| 72 * |
| 73 * |
| 74 * @par Motion/Tap Interrupt Trigger |
| 75 * |
| 76 * Applications can decide to accept motion/tap interrupts in NvOdmAccelOpen(). |
| 77 * The motion/tap interrupt threshold is set by the driver. The application |
| 78 * can get a message queue name by \c NvOdmAccelOpen, and then use the name to |
| 79 * create a Windows message queue. Then the application can read interrupt |
| 80 * information from the queue. |
| 81 * |
| 82 * See also <a class="el" href="group__nvodm__example__accel.html">Examples: |
| 83 * Accelerometer</a> |
| 84 * |
| 85 * @ingroup nvodm_adaptation |
| 86 * @{ |
| 87 */ |
| 88 /** |
| 89 * @brief Opaque handle to the vibrate device. |
| 90 */ |
| 91 typedef struct NvOdmAccelRec *NvOdmAcrDeviceHandle; |
| 92 |
| 93 /** |
| 94 * Defines interrupt events that accelerometers may generate during |
| 95 * operation. |
| 96 */ |
| 97 |
| 98 typedef enum |
| 99 { |
| 100 /// Indicates that no interrupt has been generated (this value is returned |
| 101 /// when interrupt time-outs occur). |
| 102 NvOdmAccelInt_None = 0, |
| 103 |
| 104 /// Indicates that an interrupt has been generated due to motion across |
| 105 /// any axis crossing the specified threshold level. |
| 106 NvOdmAccelInt_MotionThreshold, |
| 107 |
| 108 /// Indicates that an interrupt has been generated due to a swinging |
| 109 /// (forward and back motion) ocurring within the specified time threshold. |
| 110 NvOdmAccelInt_TapThreshold, |
| 111 |
| 112 /// Indicates that an interrupt has been generated due to detection of |
| 113 /// linear freefall motion. |
| 114 NvOdmAccelInt_Freefall, |
| 115 |
| 116 NvOdmAccelInt_Num, |
| 117 |
| 118 /// Ignore -- Forces compilers to make 32-bit enums. |
| 119 NvOdmAccelInt_Force32 = 0x7fffffffUL, |
| 120 } NvOdmAccelIntType; |
| 121 |
| 122 /** |
| 123 * Defines axis types for accelerometer. Interrupts are trigger by the axis. |
| 124 * An interrupt is triggered for enabled interrupts whenever a forced value |
| 125 * on an axis is greater than the threshold. |
| 126 */ |
| 127 typedef enum { |
| 128 NvOdmAccelAxis_None = 0x0, |
| 129 NvOdmAccelAxis_X = 0x1, |
| 130 NvOdmAccelAxis_Y = 0x2, |
| 131 NvOdmAccelAxis_Z = 0x4, |
| 132 NvOdmAccelAxis_All = 0x7, |
| 133 NvOdmAccelAxis_Force32 = 0x7fffffffUL, |
| 134 } NvOdmAccelAxisType; |
| 135 |
| 136 /** |
| 137 * Defines the accelerometer power state. |
| 138 */ |
| 139 typedef enum { |
| 140 /// Specifies the accelerometer is working normally -- sample rate is high. |
| 141 NvOdmAccelPower_Fullrun = 0, |
| 142 /// Specifies the accelerometer is working normally -- sample rate is lower |
| 143 /// than \c NvOdmAccelPower_Fullrun. |
| 144 NvOdmAccelPower_Low, |
| 145 /// Specifies the accelerometer is not working, but the power supply is there
. |
| 146 NvOdmAccelPower_Standby, |
| 147 /// Specifies the accelerometer is not working, and there is no power supply |
| 148 /// to the device. |
| 149 NvOdmAccelPower_Off, |
| 150 NvOdmAccelPower_None, |
| 151 /// Ignore -- Forces compilers to make 32-bit enums. |
| 152 NvOdmAccelPower_Force32 =0x7fffffffUL, |
| 153 } NvOdmAccelPowerType; |
| 154 |
| 155 /** |
| 156 * Holds device-specific accelerometer capabilities. |
| 157 */ |
| 158 typedef struct NvOdmAccelCapsRec |
| 159 { |
| 160 /// Holds the maximum force in g-force (\em g) registered by this |
| 161 /// accelerometer. |
| 162 /// The value is in increments of 1000. For example, when the maximum |
| 163 /// force is 2 \em g, the value should return 2000. |
| 164 NvU32 MaxForceInGs; |
| 165 |
| 166 /// Holds the size of the register for the g-force values in bits. |
| 167 /// This is to specify the resolution of the force value range. |
| 168 NvU32 ForceResolution; |
| 169 |
| 170 /// Holds the number of motion thresholds that clients may use to generate |
| 171 /// interrupts. 0 indicates that no threshold motion interrupts |
| 172 /// are supported. |
| 173 NvU32 NumMotionThresholds; |
| 174 |
| 175 /// Holds the maximum amount of time in microseconds (Usecs) that may |
| 176 /// be specified as the threshold for a tap-style interrupt. 0 |
| 177 /// indicates that tap interrupts are not supported by the accelerometer. |
| 178 NvU32 MaxTapTimeDeltaInUs; |
| 179 |
| 180 /// Holds TRUE if the accelerometer can generate an interrupt when |
| 181 /// linear free-fall motion is detected. |
| 182 NvBool SupportsFreefallInt; |
| 183 |
| 184 /// Holds the maximum sample rate the accelerometer supports. |
| 185 NvU32 MaxSampleRate; |
| 186 |
| 187 /// Holds the minimum sample rate the accelerometer supports. |
| 188 NvU32 MinSampleRate; |
| 189 } NvOdmAccelerometerCaps; |
| 190 |
| 191 /// Opaque handle to an accelerometer object. |
| 192 typedef struct NvOdmAccelRec *NvOdmAccelHandle; |
| 193 |
| 194 |
| 195 /** |
| 196 * Initializes the accelerometer and allocates resources used by the ODM |
| 197 * adaptation driver. |
| 198 * |
| 199 * @return A handle to the accelerometer if initialization is successful, or |
| 200 * NULL if unsuccessful or no accelerometer exists. |
| 201 */ |
| 202 NvBool |
| 203 NvOdmAccelOpen(NvOdmAccelHandle* hDevice); |
| 204 |
| 205 /** |
| 206 * Disables the accelerometer and frees any resources used by the driver. |
| 207 * |
| 208 * @param hDevice The accelerometer handle. |
| 209 */ |
| 210 void |
| 211 NvOdmAccelClose(NvOdmAccelHandle hDevice); |
| 212 |
| 213 /** |
| 214 * Sets the threshold value in g-force (\em g) for interrupt types that are |
| 215 * triggered at g-force thresholds, such as NvOdmAccelInt_MotionThreshold(). |
| 216 * The threshold is applied to all 3 axes on the accelerometer. This does not |
| 217 * enable or disable the specified interrupt. |
| 218 * |
| 219 * @param hDevice The accelerometer handle. |
| 220 * @param IntType The type of interrupt being configured (::NvOdmAccelIntType). |
| 221 * @param IntNum For accelerometers that support multiple interrupt thresholds |
| 222 * (::NvOdmAccelerometerCaps), specifies which threshold to |
| 223 * configure. If the accelerometer supports a single threshold for |
| 224 * the specified interrupt type, this parameter should be 0. |
| 225 * @param Threshold The desired threshold value, in g-forces. If this value is |
| 226 * outside of the accelerometer's supported range, it will be |
| 227 * clamped to the maximum supported value. If the accelerometer |
| 228 * does not have enough precision to support the exact value |
| 229 * specified, the threshold will be rounded to the nearest |
| 230 * supported value. The value is by increments of 1000. |
| 231 * For example, when the maximum force is 2 \em g, the value |
| 232 * should return 2000. |
| 233 * |
| 234 * @return NV_TRUE if successful, or NV_FALSE otherwise. |
| 235 */ |
| 236 NvBool |
| 237 NvOdmAccelSetIntForceThreshold(NvOdmAccelHandle hDevice, |
| 238 NvOdmAccelIntType IntType, |
| 239 NvU32 IntNum, |
| 240 NvU32 Threshold); |
| 241 |
| 242 /** |
| 243 * Sets the threshold value in microseconds (Usecs) for interrupt types that |
| 244 * are triggered at time thresholds. This does not enable or disable the |
| 245 * specified interrupt. |
| 246 * |
| 247 * Sets the threshold value in g-force (\em g) for interrupt types that are |
| 248 * triggered at g-force thresholds, such as NvOdmAccelInt_MotionThreshold(). |
| 249 * The threshold is applied to all 3 axes on the accelerometer. This does not |
| 250 * enable or disable the specified interrupt. |
| 251 * |
| 252 * @param hDevice The accelerometer handle. |
| 253 * @param IntType The type of interrupt being configured (::NvOdmAccelIntType). |
| 254 * @param IntNum For accelerometers that support multiple interrupt thresholds |
| 255 * (::NvOdmAccelerometerCaps), specifies which threshold to |
| 256 * configure. If the accelerometer supports a single threshold for |
| 257 * the specified interrupt type, this parameter should be 0. |
| 258 * @param Threshold The desired threshold value in microseconds. If this value |
| 259 * is outside of the accelerometer's supported range, it will b
e |
| 260 * clamped to the maximum supported value. |
| 261 * |
| 262 * @return NV_TRUE if successful, or NV_FALSE otherwise. |
| 263 */ |
| 264 NvBool |
| 265 NvOdmAccelSetIntTimeThreshold(NvOdmAccelHandle hDevice, |
| 266 NvOdmAccelIntType IntType, |
| 267 NvU32 IntNum, |
| 268 NvU32 Threshold); |
| 269 |
| 270 |
| 271 /** |
| 272 * Enables/disables the specified interrupt source. If the interrupt |
| 273 * thresholds were not set prior to enabling the interrupt, the ODM-defined |
| 274 * default values are used. If enabling a previously-enabled interrupt, |
| 275 * or disabling a previously-disabled interrupt, this function returns |
| 276 * silently. |
| 277 * |
| 278 * @param hDevice The accelerometer handle. |
| 279 * @param IntType The type of interrupt being configured (::NvOdmAccelIntType). |
| 280 * @param IntAxis The axis interrupt type (::NvOdmAccelAxisType). |
| 281 * @param IntNum For accelerometers that support multiple interrupt thresholds |
| 282 * (::NvOdmAccelerometerCaps), specifies which threshold to |
| 283 * configure. If the accelerometer supports a single threshold for |
| 284 * the specified interrupt type, this parameter should be 0. |
| 285 * @param Toggle NV_TRUE specifies to enable the interrupt source, NV_FALSE to |
| 286 * disable. |
| 287 * |
| 288 * @return NV_TRUE if successful, or NV_FALSE otherwise. |
| 289 */ |
| 290 NvBool |
| 291 NvOdmAccelSetIntEnable(NvOdmAccelHandle hDevice, |
| 292 NvOdmAccelIntType IntType, |
| 293 NvOdmAccelAxisType IntAxis, |
| 294 NvU32 IntNum, |
| 295 NvBool Toggle); |
| 296 |
| 297 /** |
| 298 * Waits for any enabled interrupt, and returns the type of interrupt to the |
| 299 * caller. If multiple interrupts occur simultaneously, returns each |
| 300 * separately. |
| 301 * |
| 302 * @param hDevice The accelerometer handle. |
| 303 * @param IntType The type of the interrupt that has been generated |
| 304 * (::NvOdmAccelIntType). If no interrupt occurs before the timeout |
| 305 * interval expires, or no interrupts are enabled, returns |
| 306 * ::NvOdmAccelInt_None. |
| 307 * @param IntMotionAxis The axis that triggered the motion interrupt (::NvOdmAcc
elAxisType). |
| 308 * If no interrupt occurs before the timeout interval expires, or no |
| 309 * interrupts are enabled, returns ::NvOdmAccelAxis_None. |
| 310 * @param IntTapAxis The axis that triggered the tap interrupt (::NvOdmAccelAxis
Type). |
| 311 * If no interrupt occurs before the timeout interval expires, or no |
| 312 * interrupts are enabled, returns ::NvOdmAccelAxis_None. |
| 313 */ |
| 314 |
| 315 void |
| 316 NvOdmAccelWaitInt(NvOdmAccelHandle hDevice, |
| 317 NvOdmAccelIntType *IntType, |
| 318 NvOdmAccelAxisType *IntMotionAxis, |
| 319 NvOdmAccelAxisType *IntTapAxis); |
| 320 |
| 321 /** |
| 322 * Signals the waiting semaphore. |
| 323 * |
| 324 * @param hDevice The accelerometer handle. |
| 325 */ |
| 326 void |
| 327 NvOdmAccelSignal(NvOdmAccelHandle hDevice); |
| 328 |
| 329 |
| 330 /** |
| 331 * Returns the current acceleration data in g-forces (\em g) as measured |
| 332 * by the accelerometer. |
| 333 * |
| 334 * To allow higher-level software to be written independently of the |
| 335 * precision and physical orientation of the accelerometer, the values |
| 336 * returned by this function must be normalized by the adaptation to the |
| 337 * following coordinate system: |
| 338 * |
| 339 * - Upright -- when the device is held upright with the primary display |
| 340 * facing the user, the returned acceleration should be (0, 1, 0). |
| 341 * - 90% rotation -- when the device is rotated 90 degrees clockwise, so that |
| 342 * the left edge of the primary display is pointing up, the returned acceleratio
n |
| 343 * should be (1, 0, 0). |
| 344 * - Flat face up -- when the device is laid flat, like on a desk, with |
| 345 * the primary display face-up, the returned acceleration should be |
| 346 * (0, 0, 1). |
| 347 * |
| 348 * @param [in] hDevice The accelerometer handle. |
| 349 * @param [out] AccelX Measured acceleration along the X axis. The value is by |
| 350 * increments of 1000. For example, 1 \em g is equal to 1000. |
| 351 * @param [out] AccelY Measured acceleration along the Y axis. The value is by |
| 352 * increments of 1000. For example, 1 \em g is equal to 1000. |
| 353 * @param [out] AccelZ Measured acceleration along the Z axis. The value is by |
| 354 * increments of 1000. For example, 1 \em g is equal to 1000. |
| 355 * |
| 356 * @return NV_TRUE if successful, or NV_FALSE otherwise. |
| 357 */ |
| 358 NvBool |
| 359 NvOdmAccelGetAcceleration(NvOdmAccelHandle hDevice, |
| 360 NvS32 *AccelX, |
| 361 NvS32 *AccelY, |
| 362 NvS32 *AccelZ); |
| 363 |
| 364 /** |
| 365 * Gets the accelerometer's character. |
| 366 * |
| 367 * @param hDevice The accelerometer handle. |
| 368 * @return The accelerometer's character. |
| 369 */ |
| 370 NvOdmAccelerometerCaps |
| 371 NvOdmAccelGetCaps(NvOdmAccelHandle hDevice); |
| 372 |
| 373 |
| 374 /** |
| 375 * Sets the accelerometer's power state. |
| 376 * |
| 377 * @param hDevice The accelerometer handle. |
| 378 * @param PowerState The accelerometer power state to set. |
| 379 * @return NV_TRUE if successful, or NV_FALSE otherwise. |
| 380 */ |
| 381 NvBool |
| 382 NvOdmAccelSetPowerState(NvOdmAccelHandle hDevice, NvOdmAccelPowerType PowerState
); |
| 383 |
| 384 |
| 385 /** |
| 386 * Sets the accelerometer's current sample rate state. |
| 387 * |
| 388 * @param hDevice The accelerometer handle. |
| 389 * @param SampleRate The ::NvOdmAccelPowerType accelerometer |
| 390 * sample rate in Hz (samples/second); if there |
| 391 * is none suitable, the nearest sample rate is set. |
| 392 * @return NV_TRUE if successful, or NV_FALSE otherwise. |
| 393 */ |
| 394 NvBool |
| 395 NvOdmAccelSetSampleRate(NvOdmAccelHandle hDevice, NvU32 SampleRate); |
| 396 |
| 397 /** |
| 398 * Gets the accelerometer's current sample rate state. |
| 399 * |
| 400 * @param hDevice The accelerometer handle. |
| 401 * @param pSampleRate The ::NvOdmAccelPowerType accelerometer |
| 402 * sample rate in Hz (samples/second); if there |
| 403 * is none suitable, the nearest sample rate is set. |
| 404 * @return NV_TRUE if successful, or NV_FALSE otherwise. |
| 405 */ |
| 406 NvBool |
| 407 NvOdmAccelGetSampleRate(NvOdmAccelHandle hDevice, NvU32* pSampleRate); |
| 408 |
| 409 |
| 410 #if defined(__cplusplus) |
| 411 } |
| 412 #endif |
| 413 /** @} */ |
| 414 #endif // INCLUDED_NVODM_ACCELEROMETER_H |
OLD | NEW |