Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
ads1220.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Gautier Hattenberger, Alexandre Bustico
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, see
18  * <http://www.gnu.org/licenses/>.
19  *
20  */
21 
31 #ifndef ADS1220_H
32 #define ADS1220_H
33 
34 #include "std.h"
35 #include "math/pprz_algebra_int.h"
36 #include "mcu_periph/spi.h"
37 
38 // Conf status
44 };
45 
46 // Input multiplexer
47 enum Ads1220Mux {
63 };
64 
65 // Gain config
75 };
76 
77 // Real gain table
78 static const float Ads1220GainTable[] = {
79  1.0f, 2.0f, 4.0f, 8.0f, 16.0f, 32.0f, 64.0f, 128.0f
80 };
81 
82 // Data sample in normal mode
88 };
89 
90 // Conversion mode
94 };
95 
96 // Voltage reference
102 };
103 
104 // IDAC current setting
114 };
115 
116 // IDAC routing
125 };
126 
131  enum Ads1220Mux mux;
132  enum Ads1220Gain gain;
133  bool pga_bypass;
134  enum Ads1220SampleRate rate;
135  enum Ads1220ConvMode conv;
136  enum Ads1220VRef vref;
137  enum Ads1220Idac idac;
138  enum Ads1220Imux i1mux;
139  enum Ads1220Imux i2mux;
140 };
141 
142 
143 //enum Ads1220ClockFrequency {
144 // CLOCK_328_KHZ = 0,
145 // CLOCK_656_KHZ,
146 // CLOCK_1312_KHZ
147 //};
148 
149 #define ADS1220_BUFFER_LEN 5
150 
151 struct Ads1220 {
152  // SPI
153  struct spi_periph *spi_p;
154  struct spi_transaction spi_trans;
157  // Config
158  struct Ads1220Config config;
159  // Data
161  volatile bool data_available;
162 };
163 
164 // Functions
165 extern void ads1220_init(struct Ads1220 *ads, struct spi_periph *spi_p, uint8_t slave_idx);
166 extern void ads1220_configure(struct Ads1220 *ads);
167 extern void ads1220_read(struct Ads1220 *ads);
168 extern void ads1220_event(struct Ads1220 *ads);
169 
171 static inline void ads1220_periodic(struct Ads1220 *ads)
172 {
173  if (ads->config.status == ADS1220_INITIALIZED) {
174  ads1220_read(ads);
175  } else {
176  ads1220_configure(ads);
177  }
178 }
179 
180 #endif // ADS1220_H
181 
enum Ads1220VRef vref
voltage ref
Definition: ads1220.h:136
Ads1220Idac
Definition: ads1220.h:105
@ ADS1220_IDAC_100_uA
Definition: ads1220.h:109
@ ADS1220_IDAC_10_uA
Definition: ads1220.h:107
@ ADS1220_IDAC_250_uA
Definition: ads1220.h:110
@ ADS1220_IDAC_1500_uA
Definition: ads1220.h:113
@ ADS1220_IDAC_1000_uA
Definition: ads1220.h:112
@ ADS1220_IDAC_50_uA
Definition: ads1220.h:108
@ ADS1220_IDAC_500_uA
Definition: ads1220.h:111
@ ADS1220_IDAC_OFF
Definition: ads1220.h:106
struct spi_transaction spi_trans
spi transaction
Definition: ads1220.h:154
Ads1220ConvMode
Definition: ads1220.h:91
@ ADS1220_SINGLE_SHOT
Definition: ads1220.h:92
@ ADS1220_CONTINIOUS_CONVERSION
Definition: ads1220.h:93
Ads1220VRef
Definition: ads1220.h:97
@ ADS1220_VREF_INTERNAL
Definition: ads1220.h:98
@ ADS1220_VREF_EXTERNAL_AIN
Definition: ads1220.h:100
@ ADS1220_VREF_VDD
Definition: ads1220.h:101
@ ADS1220_VREF_EXTERNAL_REF
Definition: ads1220.h:99
volatile uint8_t tx_buf[ADS1220_BUFFER_LEN]
transmit buffer
Definition: ads1220.h:155
static void ads1220_periodic(struct Ads1220 *ads)
convenience function: read or start configuration if not already initialized
Definition: ads1220.h:171
enum Ads1220Imux i1mux
IDAC routing 1.
Definition: ads1220.h:138
enum Ads1220Idac idac
IDAC config.
Definition: ads1220.h:137
void ads1220_read(struct Ads1220 *ads)
Definition: ads1220.c:120
enum Ads1220Imux i2mux
IDAC routing 2.
Definition: ads1220.h:139
volatile bool data_available
data ready flag
Definition: ads1220.h:161
enum Ads1220Gain gain
gain
Definition: ads1220.h:132
static const float Ads1220GainTable[]
Definition: ads1220.h:78
Ads1220ConfStatus
Definition: ads1220.h:39
@ ADS1220_SEND_RESET
Definition: ads1220.h:41
@ ADS1220_INITIALIZING
Definition: ads1220.h:42
@ ADS1220_UNINIT
Definition: ads1220.h:40
@ ADS1220_INITIALIZED
Definition: ads1220.h:43
void ads1220_event(struct Ads1220 *ads)
Definition: ads1220.c:130
enum Ads1220SampleRate rate
data output rate
Definition: ads1220.h:134
enum Ads1220ConfStatus status
config status
Definition: ads1220.h:130
Ads1220SampleRate
Definition: ads1220.h:83
@ ADS1220_RATE_45_HZ
Definition: ads1220.h:85
@ ADS1220_RATE_90_HZ
Definition: ads1220.h:86
@ ADS1220_RATE_175_HZ
Definition: ads1220.h:87
@ ADS1220_RATE_20_HZ
Definition: ads1220.h:84
struct Ads1220Config config
configuration
Definition: ads1220.h:158
Ads1220Mux
Definition: ads1220.h:47
@ ADS1220_MUX_AVDD_AVSS
Definition: ads1220.h:61
@ ADS1220_MUX_AIN0_AVSS
Definition: ads1220.h:56
@ ADS1220_MUX_AIN2_AVSS
Definition: ads1220.h:58
@ ADS1220_MUX_REFP_REFN
Definition: ads1220.h:60
@ ADS1220_MUX_AIN1_AIN3
Definition: ads1220.h:52
@ ADS1220_MUX_AIN0_AIN3
Definition: ads1220.h:50
@ ADS1220_MUX_AIN3_AIN2
Definition: ads1220.h:55
@ ADS1220_MUX_AIN0_AIN1
Definition: ads1220.h:48
@ ADS1220_MUX_AIN2_AIN3
Definition: ads1220.h:53
@ ADS1220_MUX_AVDD_AVSS_2
Definition: ads1220.h:62
@ ADS1220_MUX_AIN1_AIN0
Definition: ads1220.h:54
@ ADS1220_MUX_AIN3_AVSS
Definition: ads1220.h:59
@ ADS1220_MUX_AIN1_AIN2
Definition: ads1220.h:51
@ ADS1220_MUX_AIN0_AIN2
Definition: ads1220.h:49
@ ADS1220_MUX_AIN1_AVSS
Definition: ads1220.h:57
void ads1220_configure(struct Ads1220 *ads)
Definition: ads1220.c:102
struct spi_periph * spi_p
spi peripheral
Definition: ads1220.h:153
uint32_t data
raw ADC value
Definition: ads1220.h:160
enum Ads1220ConvMode conv
conversion mode
Definition: ads1220.h:135
volatile uint8_t rx_buf[ADS1220_BUFFER_LEN]
receive buffer
Definition: ads1220.h:156
bool pga_bypass
bypass PGA (PGA enabled = 0)
Definition: ads1220.h:133
void ads1220_init(struct Ads1220 *ads, struct spi_periph *spi_p, uint8_t slave_idx)
Definition: ads1220.c:49
Ads1220Gain
Definition: ads1220.h:66
@ ADS1220_GAIN_16
Definition: ads1220.h:71
@ ADS1220_GAIN_1
Definition: ads1220.h:67
@ ADS1220_GAIN_128
Definition: ads1220.h:74
@ ADS1220_GAIN_2
Definition: ads1220.h:68
@ ADS1220_GAIN_32
Definition: ads1220.h:72
@ ADS1220_GAIN_64
Definition: ads1220.h:73
@ ADS1220_GAIN_8
Definition: ads1220.h:70
@ ADS1220_GAIN_4
Definition: ads1220.h:69
Ads1220Imux
Definition: ads1220.h:117
@ ADS1220_IMUX_RP0
Definition: ads1220.h:123
@ ADS1220_IMUX_OFF
Definition: ads1220.h:118
@ ADS1220_IMUX_A3_RN1
Definition: ads1220.h:122
@ ADS1220_IMUX_A0_RP1
Definition: ads1220.h:119
@ ADS1220_IMUX_A2
Definition: ads1220.h:121
@ ADS1220_IMUX_RN0
Definition: ads1220.h:124
@ ADS1220_IMUX_A1
Definition: ads1220.h:120
enum Ads1220Mux mux
input multiplexer
Definition: ads1220.h:131
#define ADS1220_BUFFER_LEN
Definition: ads1220.h:149
ADS1220 configuration options.
Definition: ads1220.h:129
SPI peripheral structure.
Definition: spi.h:174
SPI transaction structure.
Definition: spi.h:148
Paparazzi fixed point algebra.
Architecture independent SPI (Serial Peripheral Interface) API.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98