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: compass.h 5629 2011-06-11 03:13:08Z mcaramello $
     21  *
     22  *******************************************************************************/
     23 
     24 #ifndef COMPASS_H
     25 #define COMPASS_H
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 #include "mltypes.h"
     32 #include "mpu.h"
     33 #ifdef INV_INCLUDE_LEGACY_HEADERS
     34 #include "compass_legacy.h"
     35 #endif
     36     /* ------------ */
     37     /* - Defines. - */
     38     /* ------------ */
     39 
     40 #define YAS_MAX_FILTER_LEN (20)
     41 #define YAS_DEFAULT_FILTER_LEN (20)
     42 #define YAS_DEFAULT_FILTER_THRESH (300) /* 300 nT */
     43 #define YAS_DEFAULT_FILTER_NOISE (2000 * 2000) /* standard deviation 2000 nT */
     44 
     45     /* --------------- */
     46     /* - Structures. - */
     47     /* --------------- */
     48 
     49 struct yas_adaptive_filter {
     50     int num;
     51     int index;
     52     int len;
     53     float noise;
     54     float sequence[YAS_MAX_FILTER_LEN];
     55 };
     56 
     57 struct yas_thresh_filter {
     58     float threshold;
     59     float last;
     60 };
     61 
     62 typedef struct {
     63     struct yas_adaptive_filter adap_filter[3];
     64     struct yas_thresh_filter thresh_filter[3];
     65 } yas_filter_handle_t;
     66 
     67 typedef struct {
     68     int (*init)(yas_filter_handle_t *t);
     69     int (*update)(yas_filter_handle_t *t, float *input, float *output);
     70 } yas_filter_if_s;
     71 
     72     /* --------------------- */
     73     /* - Function p-types. - */
     74     /* --------------------- */
     75 
     76     unsigned char inv_compass_present(void);
     77     unsigned char inv_get_compass_slave_addr(void);
     78     inv_error_t inv_get_compass_data(long *data);
     79     inv_error_t inv_set_compass_bias(long *bias);
     80     unsigned short inv_get_compass_id(void);
     81     inv_error_t inv_set_compass_offset(void);
     82     inv_error_t inv_compass_check_range(void);
     83     inv_error_t inv_compass_write_reg(unsigned char reg, unsigned char val);
     84     inv_error_t inv_compass_read_reg(unsigned char reg, unsigned char *val);
     85     inv_error_t inv_compass_read_scale(long *val);
     86 
     87     int yas_filter_init(yas_filter_if_s *f);
     88 
     89 #ifdef __cplusplus
     90 }
     91 #endif
     92 #endif                          // COMPASS_H
     93