altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / drivers / ao_mmc5983.h
1 /*
2  * Copyright © 2021 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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_MMC5983_H_
20 #define _AO_MMC5983_H_
21
22 #define MMC5983_READ            0x80
23
24 #define MMC5983_CONFIG_A        0
25
26 #define  MMC5983_CONFIG_A_MA            5
27 #define  MMC5983_CONFIG_A_MA_1                  0
28 #define  MMC5983_CONFIG_A_MA_2                  1
29 #define  MMC5983_CONFIG_A_MA_4                  2
30 #define  MMC5983_CONFIG_A_MA_8                  3
31 #define  MMC5983_CONFIG_A_MA_MASK               3
32
33 #define  MMC5983_CONFIG_A_DO            2
34 #define   MMC5983_CONFIG_A_DO_0_75              0
35 #define   MMC5983_CONFIG_A_DO_1_5               1
36 #define   MMC5983_CONFIG_A_DO_3                 2
37 #define   MMC5983_CONFIG_A_DO_7_5               3
38 #define   MMC5983_CONFIG_A_DO_15                4
39 #define   MMC5983_CONFIG_A_DO_30                5
40 #define   MMC5983_CONFIG_A_DO_75                6
41 #define   MMC5983_CONFIG_A_DO_MASK              7
42
43 #define MMC5983_CONFIG_A_MS             0
44 #define  MMC5983_CONFIG_A_MS_NORMAL             0
45 #define  MMC5983_CONFIG_A_MS_POSITIVE_BIAS      1
46 #define  MMC5983_CONFIG_A_MS_NEGATIVE_BIAS      2
47 #define  MMC5983_CONFIG_A_MS_MASK               3
48
49 #define MMC5983_CONFIG_B        1
50
51 #define MMC5983_CONFIG_B_GN             5
52 #define  MMC5983_CONFIG_B_GN_0_88               0
53 #define  MMC5983_CONFIG_B_GN_1_3                1
54 #define  MMC5983_CONFIG_B_GN_1_9                2
55 #define  MMC5983_CONFIG_B_GN_2_5                3
56 #define  MMC5983_CONFIG_B_GN_4_0                4
57 #define  MMC5983_CONFIG_B_GN_4_7                5
58 #define  MMC5983_CONFIG_B_GN_5_6                6
59 #define  MMC5983_CONFIG_B_GN_8_1                7
60 #define  MMC5983_CONFIG_B_GN_MASK               7
61
62 #define MMC5983_MODE            2
63 #define  MMC5983_MODE_CONTINUOUS        0
64 #define  MMC5983_MODE_SINGLE            1
65 #define  MMC5983_MODE_IDLE              2
66
67 #define MMC5983_X_OUT_0         0
68 #define MMC5983_X_OUT_1         1
69 #define MMC5983_Y_OUT_0         2
70 #define MMC5983_Y_OUT_1         3
71 #define MMC5983_Z_OUT_0         4
72 #define MMC5983_Z_OUT_1         5
73 #define MMC5983_XYZ_OUT_2       6
74 #define MMC5983_T_OUT           7
75
76 #define MMC5983_STATUS          8
77 # define MMC5983_STATUS_OTP_READ_DONE           4
78 # define MMC5983_STATUS_MEAS_T_DONE             1
79 # define MMC5983_STATUS_MEAS_M_DONE             0
80
81 #define MMC5983_CONTROL_0       9
82 # define MMC5983_CONTROL_0_OTP_READ             6
83 # define MMC5983_CONTROL_0_AUTO_SR_EN           5
84 # define MMC5983_CONTROL_0_RESET                4
85 # define MMC5983_CONTROL_0_SET                  3
86 # define MMC5983_CONTROL_0_INT_MEAS_DONE_EN     2
87 # define MMC5983_CONTROL_0_TM_T                 1
88 # define MMC5983_CONTROL_0_TM_M                 0
89
90 #define MMC5983_CONTROL_1       0xa
91 # define MMC5983_CONTROL_1_SW_RST               7
92 # define MMC5983_CONTROL_1_YZ_INHIBIT           3
93 # define MMC5983_CONTROL_1_X_INHIBIT            2
94 # define MMC5983_CONTROL_1_BW                   0
95 # define MMC5983_CONTROL_1_BW_100                       0
96 # define MMC5983_CONTROL_1_BW_200                       1
97 # define MMC5983_CONTROL_1_BW_400                       2
98 # define MMC5983_CONTROL_1_BW_800                       3
99 #define MMC5983_CONTROL_2       0xb
100 # define MMC5983_CONTROL_2_EN_PRD_SET           7
101 # define MMC5983_CONTROL_2_PRD_SET              4
102 # define MMC5983_CONTROL_2_PRD_SET_1                    0
103 # define MMC5983_CONTROL_2_PRD_SET_25                   1
104 # define MMC5983_CONTROL_2_PRD_SET_75                   2
105 # define MMC5983_CONTROL_2_PRD_SET_100                  3
106 # define MMC5983_CONTROL_2_PRD_SET_250                  4
107 # define MMC5983_CONTROL_2_PRD_SET_500                  5
108 # define MMC5983_CONTROL_2_PRD_SET_1000                 6
109 # define MMC5983_CONTROL_2_PRD_SET_2000                 7
110 # define MMC5983_CONTROL_2_CMM_EN               3
111 # define MMC5983_CONTROL_2_CM_FREQ              0
112 # define MMC5983_CONTROL_2_CM_FREQ_OFF                  0
113 # define MMC5983_CONTROL_2_CM_FREQ_1HZ                  1
114 # define MMC5983_CONTROL_2_CM_FREQ_10HZ                 2
115 # define MMC5983_CONTROL_2_CM_FREQ_20HZ                 3
116 # define MMC5983_CONTROL_2_CM_FREQ_50HZ                 4
117 # define MMC5983_CONTROL_2_CM_FREQ_100HZ                5
118 # define MMC5983_CONTROL_2_CM_FREQ_200HZ                6
119 # define MMC5983_CONTROL_2_CM_FREQ_1000HZ               7
120
121 #define MMC5983_CONTROL_3       0xc
122 #define  MMC5983_CONTROL_3_SPI_3W               6
123 #define  MMC5983_CONTROL_3_ST_ENM               2
124 #define  MMC5983_CONTROL_3_ST_ENP               1
125
126 #define MMC5983_PRODUCT_ID      0x2f
127 #define MMC5983_PRODUCT_ID_PRODUCT      0x30
128
129 struct ao_mmc5983_sample {
130         int16_t         x, y, z;
131 };
132
133 struct ao_mmc5983_raw {
134         uint8_t         addr;
135         uint8_t         x0;
136         uint8_t         x1;
137         uint8_t         y0;
138         uint8_t         y1;
139         uint8_t         z0;
140         uint8_t         z1;
141         uint8_t         xyz2;
142 };
143
144 extern struct ao_mmc5983_sample ao_mmc5983_current;
145
146 void
147 ao_mmc5983_init(void);
148
149 #endif /* _AO_MMC5983_H_ */