Paparazzi UAS  v5.15_devel-47-g0391b4d
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
133  bool pga_bypass;
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;
157  // 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 Ads1220ConvMode conv
conversion mode
Definition: ads1220.h:135
void ads1220_configure(struct Ads1220 *ads)
Definition: ads1220.c:102
enum Ads1220Imux i2mux
IDAC routing 2.
Definition: ads1220.h:139
volatile bool data_available
data ready flag
Definition: ads1220.h:161
enum Ads1220Mux mux
input multiplexer
Definition: ads1220.h:131
SPI transaction structure.
Definition: spi.h:142
Ads1220Imux
Definition: ads1220.h:117
volatile uint8_t rx_buf[ADS1220_BUFFER_LEN]
receive buffer
Definition: ads1220.h:156
void ads1220_read(struct Ads1220 *ads)
Definition: ads1220.c:120
struct spi_transaction spi_trans
spi transaction
Definition: ads1220.h:154
Ads1220VRef
Definition: ads1220.h:97
Ads1220ConfStatus
Definition: ads1220.h:39
struct spi_periph * spi_p
spi peripheral
Definition: ads1220.h:153
struct Ads1220Config config
configuration
Definition: ads1220.h:158
void ads1220_event(struct Ads1220 *ads)
Definition: ads1220.c:130
Architecture independent SPI (Serial Peripheral Interface) API.
Ads1220SampleRate
Definition: ads1220.h:83
SPI peripheral structure.
Definition: spi.h:168
enum Ads1220Gain gain
gain
Definition: ads1220.h:132
ADS1220 configuration options.
Definition: ads1220.h:129
#define ADS1220_BUFFER_LEN
Definition: ads1220.h:149
bool pga_bypass
bypass PGA (PGA enabled = 0)
Definition: ads1220.h:133
enum Ads1220VRef vref
voltage ref
Definition: ads1220.h:136
unsigned long uint32_t
Definition: types.h:18
Ads1220Gain
Definition: ads1220.h:66
Ads1220Idac
Definition: ads1220.h:105
enum Ads1220SampleRate rate
data output rate
Definition: ads1220.h:134
static void ads1220_periodic(struct Ads1220 *ads)
convenience function: read or start configuration if not already initialized
Definition: ads1220.h:171
enum Ads1220ConfStatus status
config status
Definition: ads1220.h:130
unsigned char uint8_t
Definition: types.h:14
static const float Ads1220GainTable[]
Definition: ads1220.h:78
uint32_t data
raw ADC value
Definition: ads1220.h:160
enum Ads1220Idac idac
IDAC config.
Definition: ads1220.h:137
Ads1220ConvMode
Definition: ads1220.h:91
void ads1220_init(struct Ads1220 *ads, struct spi_periph *spi_p, uint8_t slave_idx)
Definition: ads1220.c:49
enum Ads1220Imux i1mux
IDAC routing 1.
Definition: ads1220.h:138
Ads1220Mux
Definition: ads1220.h:47
volatile uint8_t tx_buf[ADS1220_BUFFER_LEN]
transmit buffer
Definition: ads1220.h:155
Paparazzi fixed point algebra.