Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ads1114.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 ENAC
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 /* driver for the ADC ads1114 (16 bits I2C 860SpS max) from Texas instruments
24  * Navarro & Gorraz & Hattenberger
25  */
26 
27 #ifndef ADS_1114_H
28 #define ADS_1114_H
29 
30 #include "std.h"
31 #include "mcu_periph/i2c.h"
32 
33 
34 /* I2C slave address */
35 #ifndef ADS1114_1_I2C_ADDR
36 #define ADS1114_1_I2C_ADDR 0x90 // slave address byte (I2c address(7bits) + R/W @ 0)
37 #endif
38 #ifndef ADS1114_2_I2C_ADDR
39 #define ADS1114_2_I2C_ADDR 0x92 // slave address byte (I2c address(7bits) + R/W @ 0)
40 #endif
41 
42 /* I2C conf register */
43 #define ADS1114_POINTER_CONV_REG 0x00 // access to the Conversion register (16bits)
44 #define ADS1114_POINTER_CONFIG_REG 0x01 // access to the Configuration register (16bits)
45 
46 /* ADS1114_1 default conf */
47 #ifndef ADS1114_1_OS
48 #define ADS1114_1_OS 0x0 // Operational status
49 #endif
50 #ifndef ADS1114_1_MUX
51 #define ADS1114_1_MUX 0x0 // Input multiplexer
52 #endif
53 #ifndef ADS1114_1_PGA
54 #define ADS1114_1_PGA 0x3 // Programable gain amplifier (= 4 with a Full Scale of +/- 1.024V)
55 #endif
56 #ifndef ADS1114_1_MODE
57 #define ADS1114_1_MODE 0x0 // Continuous conversion mode
58 #endif
59 #ifndef ADS1114_1_DR
60 #define ADS1114_1_DR 0x4 // Data rate (128 SPS)
61 #endif
62 #ifndef ADS1114_1_COMP_MODE
63 #define ADS1114_1_COMP_MODE 0x0 // Comparator mode
64 #endif
65 #ifndef ADS1114_1_COMP_POL
66 #define ADS1114_1_COMP_POL 0x0 // Comparator polarity
67 #endif
68 #ifndef ADS1114_1_COMP_LAT
69 #define ADS1114_1_COMP_LAT 0x0 // Latching comparator
70 #endif
71 #ifndef ADS1114_1_COMP_QUE
72 #define ADS1114_1_COMP_QUE 0x3 // Comparator queue (disable)
73 #endif
74 
75 #define ADS1114_1_CONFIG_MSB ((ADS1114_1_OS<<7)|(ADS1114_1_MUX<<4)|(ADS1114_1_PGA<<1)|(ADS1114_1_MODE))
76 #define ADS1114_1_CONFIG_LSB ((ADS1114_1_DR<<5)|(ADS1114_1_COMP_MODE<<4)|(ADS1114_1_COMP_POL<<3)|(ADS1114_1_COMP_LAT<<2)|(ADS1114_1_COMP_QUE))
77 
78 /* ADS1114_1 default conf */
79 #ifndef ADS1114_2_OS
80 #define ADS1114_2_OS 0x0 // Operational status
81 #endif
82 #ifndef ADS1114_2_MUX
83 #define ADS1114_2_MUX 0x0 // Input multiplexer
84 #endif
85 #ifndef ADS1114_2_PGA
86 #define ADS1114_2_PGA 0x3 // Programable gain amplifier (= 4 with a Full Scale of +/- 1.024V)
87 #endif
88 #ifndef ADS1114_2_MODE
89 #define ADS1114_2_MODE 0x0 // Continuous conversion mode
90 #endif
91 #ifndef ADS1114_2_DR
92 #define ADS1114_2_DR 0x4 // Data rate (128 SPS)
93 #endif
94 #ifndef ADS1114_2_COMP_MODE
95 #define ADS1114_2_COMP_MODE 0x0 // Comparator mode
96 #endif
97 #ifndef ADS1114_2_COMP_POL
98 #define ADS1114_2_COMP_POL 0x0 // Comparator polarity
99 #endif
100 #ifndef ADS1114_2_COMP_LAT
101 #define ADS1114_2_COMP_LAT 0x0 // Latching comparator
102 #endif
103 #ifndef ADS1114_2_COMP_QUE
104 #define ADS1114_2_COMP_QUE 0x3 // Comparator queue (disable)
105 #endif
106 
107 #define ADS1114_2_CONFIG_MSB ((ADS1114_2_OS<<7)|(ADS1114_2_MUX<<4)|(ADS1114_2_PGA<<1)|(ADS1114_2_MODE))
108 #define ADS1114_2_CONFIG_LSB ((ADS1114_2_DR<<5)|(ADS1114_2_COMP_MODE<<4)|(ADS1114_2_COMP_POL<<3)|(ADS1114_2_COMP_LAT<<2)|(ADS1114_2_COMP_QUE))
109 
110 /* Default I2C device */
111 // FIXME all ads on the same device for now
112 #ifndef ADS1114_I2C_DEVICE
113 #define ADS1114_I2C_DEVICE i2c1
114 #endif
115 
119  bool_t config_done;
121 };
122 
123 #if USE_ADS1114_1
124 extern struct ads1114_periph ads1114_1;
125 #endif
126 
127 #if USE_ADS1114_2
128 extern struct ads1114_periph ads1114_2;
129 #endif
130 
131 extern void ads1114_init(void);
132 extern void ads1114_read(struct ads1114_periph * p);
133 
134 // Generic Event Macro
135 #define _Ads1114Event(_p) {\
136  if (!_p.config_done) { \
137  if (_p.trans.status == I2CTransSuccess) { _p.config_done = TRUE; _p.trans.status = I2CTransDone; } \
138  if (_p.trans.status == I2CTransFailed) { _p.trans.status = I2CTransDone; } \
139  } else { \
140  if (_p.trans.status == I2CTransSuccess) { _p.data_available = TRUE; _p.trans.status = I2CTransDone; } \
141  if (_p.trans.status == I2CTransFailed) { _p.trans.status = I2CTransDone; } \
142  } \
143 }
144 
145 #if USE_ADS1114_1
146 #define Ads1114_1Event() _Ads1114Event(ads1114_1)
147 #else
148 #define Ads1114_1Event() {}
149 #endif
150 
151 #if USE_ADS1114_2
152 #define Ads1114_2Event() _Ads1114Event(ads1114_2)
153 #else
154 #define Ads1114_2Event() {}
155 #endif
156 
157 // Final event macro
158 #define Ads1114Event() { \
159  Ads1114_1Event(); \
160  Ads1114_2Event(); \
161 }
162 
163 // Get value macro
164 // @param ads1114 periph
165 #define Ads1114GetValue(_p) ((int16_t)(((int16_t)_p.trans.buf[0]<<8)|_p.trans.buf[1]))
166 
167 #endif // ADS_1114_H
bool_t data_available
Definition: ads1114.h:120
void ads1114_init(void)
Definition: ads1114.c:37
bool_t config_done
Definition: ads1114.h:119
uint8_t i2c_addr
Definition: ads1114.h:118
struct i2c_transaction trans
Definition: ads1114.h:117
unsigned char uint8_t
Definition: types.h:14
void ads1114_read(struct ads1114_periph *p)
Definition: ads1114.c:62