18f99bf8928867c0d7802667fa3ba4fa1c0cfd1a
[fw/altos] / src / drivers / ao_ms5607.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; 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_MS5607_H_
20 #define _AO_MS5607_H_
21
22 #define AO_MS5607_RESET                 0x1e
23
24 #define AO_MS5607_CONVERT_D1_256        0x40
25 #define AO_MS5607_CONVERT_D1_512        0x42
26 #define AO_MS5607_CONVERT_D1_1024       0x44
27 #define AO_MS5607_CONVERT_D1_2048       0x46
28 #define AO_MS5607_CONVERT_D1_4096       0x48
29
30 #define AO_MS5607_CONVERT_D2_256        0x50
31 #define AO_MS5607_CONVERT_D2_512        0x52
32 #define AO_MS5607_CONVERT_D2_1024       0x54
33 #define AO_MS5607_CONVERT_D2_2048       0x56
34 #define AO_MS5607_CONVERT_D2_4096       0x58
35
36 #define AO_MS5607_ADC_READ              0x00
37 #define AO_MS5607_PROM_READ(ad)         (0xA0 | ((ad) << 1))
38
39 struct ao_ms5607_prom {
40         uint16_t        reserved;
41         uint16_t        sens;
42         uint16_t        off;
43         uint16_t        tcs;
44         uint16_t        tco;
45         uint16_t        tref;
46         uint16_t        tempsens;
47         uint16_t        crc;
48 };
49
50 struct ao_ms5607_sample {
51         uint32_t        pres;   /* raw 24 bit sensor */
52         uint32_t        temp;   /* raw 24 bit sensor */
53 };
54
55 struct ao_ms5607_value {
56         int32_t         pres;   /* in Pa * 10 */
57         int32_t         temp;   /* in °C * 100 */
58 };
59
60 extern __xdata struct ao_ms5607_sample  ao_ms5607_current;
61 extern __xdata struct ao_ms5607_prom    ao_ms5607_prom;
62
63 void
64 ao_ms5607_setup(void);
65
66 void
67 ao_ms5607_init(void);
68
69 void
70 ao_ms5607_info(void);
71
72 void
73 ao_ms5607_sample(__xdata struct ao_ms5607_sample *sample);
74
75 void
76 ao_ms5607_convert(__xdata struct ao_ms5607_sample *sample,
77                   __xdata struct ao_ms5607_value *value);
78
79 #endif /* _AO_MS5607_H_ */