altos: Execute self-test on MMA655X part
[fw/altos] / src / drivers / ao_mma655x.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_MMA655X_H_
19 #define _AO_MMA655X_H_
20
21
22 #define AO_MMA655X_SN0          0x00
23 #define AO_MMA655X_SN1          0x01
24 #define AO_MMA655X_SN2          0x02
25 #define AO_MMA655X_SN3          0x03
26 #define AO_MMA655X_SN3          0x03
27 #define AO_MMA655X_STDEFL       0x04
28 #define AO_MMA655X_FCTCFG       0x06
29 # define AO_MMA655X_FCTCFG_STMAG        7
30
31 #define AO_MMA655X_PN           0x08
32 #define AO_MMA655X_DEVCTL       0x0a
33 #define AO_MMA655X_DEVCTL_RES_1         7
34 #define AO_MMA655X_DEVCTL_RES_0         6
35 #define AO_MMA655X_DEVCTL_OCPHASE       4
36 #define AO_MMA655X_DEVCTL_OCPHASE_MASK  3
37 #define AO_MMA655X_DEVCTL_OFFCFG_EN     3
38
39 #define AO_MMA655X_DEVCFG       0x0b
40 #define AO_MMA655X_DEVCFG_OC            7
41 #define AO_MMA655X_DEVCFG_ENDINIT       5
42 #define AO_MMA655X_DEVCFG_SD            4
43 #define AO_MMA655X_DEVCFG_OFMON         3
44 #define AO_MMA655X_DEVCFG_A_CFG         0
45 #define AO_MMA655X_DEVCFG_A_CFG_DISABLE         0
46 #define AO_MMA655X_DEVCFG_A_CFG_PCM             1
47 #define AO_MMA655X_DEVCFG_A_CFG_MOVING_AVG_HIGH 2
48 #define AO_MMA655X_DEVCFG_A_CFG_MOVING_AVG_LOW  3
49 #define AO_MMA655X_DEVCFG_A_CFG_COUNT_HIGH      4
50 #define AO_MMA655X_DEVCFG_A_CFG_COUNT_LOW       5
51 #define AO_MMA655X_DEVCFG_A_CFG_UNFILTERED_HIGH 6
52 #define AO_MMA655X_DEVCFG_A_CFG_UNFILTERED_LOW  7
53 #define AO_MMA655X_DEVCFG_A_CFG_MASK            7
54
55 #define AO_MMA655X_AXISCFG      0x0c
56 #define AO_MMA655X_AXISCFG_ST           7
57 #define AO_MMA655X_AXISCFG_LPF          0
58 #define AO_MMA655X_AXISCFG_LPF_MASK     0xf
59
60 #define AO_MMA655X_ARMCFG       0x0e
61 #define AO_MMA655X_ARMCFG_APS           4
62 #define AO_MMA655X_ARMCFG_APS_MASK      3
63 #define AO_MMA655X_ARMCFG_AWS_N         2
64 #define AO_MMA655X_ARMCFG_AWS_N_MASK    3
65 #define AO_MMA655X_ARMCFG_AWS_P         0
66 #define AO_MMA655X_ARMCFG_AWS_P_MASK    3
67
68 #define AO_MMA655X_ARMT_P       0x10
69 #define AO_MMA655X_ARMT_N       0x12
70
71 #define AO_MMA655X_DEVSTAT      0x14
72 #define AO_MMA655X_DEVSTAT_IDE          6
73 #define AO_MMA655X_DEVSTAT_DEVINIT      4
74 #define AO_MMA655X_DEVSTAT_MISOERR      3
75 #define AO_MMA655X_DEVSTAT_OFFSET       1
76 #define AO_MMA655X_DEVSTAT_DEVRES       0
77
78 #define AO_MMA655X_COUNT        0x15
79 #define AO_MMA655X_OFFCORR      0x16
80
81 /*
82  * Range of valid self-test difference from
83  * normal measurement
84  */
85
86 #define AO_ST_MIN       300
87 #define AO_ST_MAX       800
88
89 extern uint16_t ao_mma655x_current;
90
91 void
92 ao_mma655x_init(void);
93
94 #endif /* _AO_MMA655X_H_ */