Home | History | Annotate | Download | only in mllite
      1 /*
      2  $License:
      3    Copyright 2011 InvenSense, Inc.
      4 
      5  Licensed under the Apache License, Version 2.0 (the "License");
      6  you may not use this file except in compliance with the License.
      7  You may obtain a copy of the License at
      8 
      9  http://www.apache.org/licenses/LICENSE-2.0
     10 
     11  Unless required by applicable law or agreed to in writing, software
     12  distributed under the License is distributed on an "AS IS" BASIS,
     13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  See the License for the specific language governing permissions and
     15  limitations under the License.
     16   $
     17  */
     18 /*******************************************************************************
     19  *
     20  * $Id: mldl.h 5639 2011-06-14 01:23:05Z nroyer $
     21  *
     22  *******************************************************************************/
     23 
     24 #ifndef MLDL_H
     25 #define MLDL_H
     26 
     27 #include "mltypes.h"
     28 #include "mlsl.h"
     29 #include <linux/mpu.h>
     30 #include "mldl_cfg.h"
     31 #ifdef INV_INCLUDE_LEGACY_HEADERS
     32 #include "mldl_legacy.h"
     33 #endif
     34 
     35     /* ------------ */
     36     /* - Defines. - */
     37     /* ------------ */
     38 
     39 typedef enum _DEVICE_CONFIG {
     40     DEVICE_MPU_ACCEL = 0,
     41     DEVICE_MPU,
     42     NUM_OF_DEVICES
     43 } DEVICE_CONFIG;
     44 
     45 #define SERIAL_I2C                  0
     46 #define SERIAL_SPI                  1
     47 
     48 #define DATAMODE_MANUAL             0   // Manual data mode
     49 #define DATAMODE_AUTO               1   // Auto data mode
     50 
     51 #define DATASRC_IMMEDIATE           0   // Return data immediately
     52 #define DATASRC_WHENREADY           1   // Only return data when new data is available
     53 #define DATASRC_FIFO                2   // Use FIFO for data
     54 
     55 #define SENSOR_DATA_GYROX           0x0001
     56 #define SENSOR_DATA_GYROY           0x0002
     57 #define SENSOR_DATA_GYROZ           0x0004
     58 #define SENSOR_DATA_ACCELX          0x0008
     59 #define SENSOR_DATA_ACCELY          0x0010
     60 #define SENSOR_DATA_ACCELZ          0x0020
     61 #define SENSOR_DATA_AUX1            0x0040
     62 #define SENSOR_DATA_AUX2            0x0080
     63 #define SENSOR_DATA_AUX3            0x0100
     64 #define SENSOR_DATA_TEMP            0x0200
     65 
     66 #define INTPIN_MPU                  0
     67 
     68 #define INTLOGIC_HIGH               0
     69 #define INTLOGIC_LOW                1
     70 
     71 #define INTTYPE_PUSHPULL            0
     72 #define INTTYPE_OPENDRAIN           1
     73 
     74 #define INTLATCH_DISABLE            0
     75 #define INTLATCH_ENABLE             1
     76 
     77 #define MPUINT_MPU_READY            0x04
     78 #define MPUINT_DMP_DONE             0x02
     79 #define MPUINT_DATA_READY           0x01
     80 
     81 #define INTLATCHCLEAR_READSTATUS    0
     82 #define INTLATCHCLEAR_ANYREAD       1
     83 
     84 #define DMP_DONTRUN                 0
     85 #define DMP_RUN                     1
     86 
     87     /*---- defines for external interrupt status (via external call into library) ----*/
     88 #define INT_CLEAR                   0
     89 #define INT_TRIGGERED               1
     90 
     91 typedef enum {
     92     INTSRC_MPU = 0,
     93     INTSRC_AUX1,
     94     INTSRC_AUX2,
     95     INTSRC_AUX3,
     96     INTSRC_TIMER,
     97     INTSRC_UNKNOWN,
     98     INTSRC_MPU_FIFO,
     99     INTSRC_MPU_MOTION,
    100     NUM_OF_INTSOURCES,
    101 } INT_SOURCE;
    102 
    103     /* --------------- */
    104     /* - Structures. - */
    105     /* --------------- */
    106 
    107     /* --------------- */
    108     /* - Variables.  - */
    109     /* --------------- */
    110 
    111     /* --------------------- */
    112     /* - Function p-types. - */
    113     /* --------------------- */
    114 #ifdef __cplusplus
    115 extern "C" {
    116 #endif
    117 
    118     inv_error_t inv_dl_open(void *mlslHandle);
    119     inv_error_t inv_dl_close(void);
    120 
    121     inv_error_t inv_dl_start(unsigned long sensors);
    122     inv_error_t inv_dl_stop(unsigned long sensors);
    123 
    124     struct mldl_cfg *inv_get_dl_config(void);
    125 
    126     inv_error_t inv_init_requested_sensors(unsigned long sensors);
    127     unsigned char inv_get_mpu_slave_addr(void);
    128     inv_error_t inv_get_dl_ctrl_dmp(unsigned char enableRun,
    129                                     unsigned char enableFIFO);
    130     inv_error_t inv_get_dl_cfg_int(unsigned char triggers);
    131     inv_error_t inv_dl_cfg_sampling(unsigned char lpf, unsigned char divider);
    132     inv_error_t inv_set_full_scale(float fullScale);
    133     inv_error_t inv_set_external_sync(unsigned char extSync);
    134     inv_error_t inv_set_ignore_system_suspend(unsigned char ignore);
    135     inv_error_t inv_clock_source(unsigned char clkSource);
    136     inv_error_t inv_get_mpu_memory(unsigned short key,
    137                                    unsigned short length,
    138                                    unsigned char *buffer);
    139     inv_error_t inv_set_mpu_memory(unsigned short key,
    140                                    unsigned short length,
    141                                    const unsigned char *buffer);
    142     inv_error_t inv_load_dmp(const unsigned char *buffer,
    143                              unsigned short length,
    144                              unsigned short startAddress);
    145 
    146     unsigned char inv_get_slicon_rev(void);
    147     inv_error_t inv_set_offsetTC(const unsigned char *tc);
    148     inv_error_t inv_set_offset(const short *offset);
    149 
    150     /* Functions for setting and retrieving the DMP memory */
    151     inv_error_t inv_get_mpu_memory_original(unsigned short key,
    152                                             unsigned short length,
    153                                             unsigned char *buffer);
    154     void inv_set_get_address(unsigned short (*func) (unsigned short key));
    155     unsigned short inv_dl_get_address(unsigned short key);
    156     uint_fast8_t inv_dmpkey_supported(unsigned short key);
    157 
    158     inv_error_t inv_get_interrupt_status(unsigned char intPin,
    159                                          unsigned char *value);
    160     unsigned char inv_get_interrupt_trigger(unsigned char index);
    161     void inv_clear_interrupt_trigger(unsigned char index);
    162     inv_error_t inv_interrupt_handler(unsigned char intSource);
    163 
    164     /** Only exposed for testing purposes */
    165     inv_error_t inv_set_mpu_memory_one_bank(unsigned char bank,
    166                                             unsigned short memAddr,
    167                                             unsigned short length,
    168                                             const unsigned char *buffer);
    169     inv_error_t inv_get_mpu_memory_one_bank(unsigned char bank,
    170                                             unsigned char memAddr,
    171                                             unsigned short length,
    172                                             unsigned char *buffer);
    173 #ifdef __cplusplus
    174 }
    175 #endif
    176 #endif                          // MLDL_H
    177