mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-20 11:28:58 +08:00
modify ads1114 driver to use 2 modules (same i2c bus for now)
add airspeed_ads1114 module modify baro_board module (baro for umarim) to use airspeed when airspeed_ads1114 is loaded
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
|
||||
<modules>
|
||||
<load name="baro_board.xml"/>
|
||||
<load name="airspeed_ads1114.xml"/>
|
||||
<!--load name="mcp355x.xml"/-->
|
||||
</modules>
|
||||
|
||||
<firmware name="fixedwing">
|
||||
@@ -40,6 +42,8 @@
|
||||
<subsystem name="navigation"/>
|
||||
<!-- Sensors -->
|
||||
<subsystem name="gps" type="ublox"/>
|
||||
|
||||
<!--subsystem name="spi"/-->
|
||||
</firmware>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
<!-- Module to extend the baro_board module with an airspeed sensor using ads1114 adc -->
|
||||
|
||||
<module name="airspeed_ads1114" dir="sensors">
|
||||
<depend require="baro_board.xml"/>
|
||||
<header>
|
||||
<file name="airspeed_ads1114.h"/>
|
||||
</header>
|
||||
<periodic fun="airspeed_periodic()" freq="60."/>
|
||||
<makefile target="ap">
|
||||
<file name="airspeed_ads1114.c"/>
|
||||
<define name="USE_BARO_DIFF"/>
|
||||
<define name="USE_ADS1114_2"/>
|
||||
<define name="ADS1114_2_PGA" value="0x1"/> <!-- PGA gain = 1 (+/- 4.096V) -->
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<define name="USE_BARO_AS_ALTIMETER"/>
|
||||
<file name="baro_board.c" dir="boards/$(BOARD)"/>
|
||||
<define name="ADS1114_I2C_DEVICE" value="i2c1"/>
|
||||
<define name="USE_ADS1114_1"/>
|
||||
<file name="ads1114.c" dir="peripherals"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -55,7 +55,7 @@ void baro_init( void ) {
|
||||
ads1114_init();
|
||||
baro.status = BS_UNINITIALIZED;
|
||||
baro.absolute = 0;
|
||||
baro.differential = 0; /* not handled on this board */
|
||||
baro.differential = 0; /* not handled on this board, use extra module (ex: airspeed_ads1114) */
|
||||
#ifdef USE_BARO_AS_ALTIMETER
|
||||
baro_alt = 0.;
|
||||
baro_alt_offset = 0.;
|
||||
@@ -66,7 +66,7 @@ void baro_init( void ) {
|
||||
void baro_periodic( void ) {
|
||||
|
||||
#ifdef USE_BARO_AS_ALTIMETER
|
||||
if (baro.status == BS_UNINITIALIZED && ads1114_data_available) {
|
||||
if (baro.status == BS_UNINITIALIZED && BARO_ABS_ADS.data_available) {
|
||||
// IIR filter to compute an initial offset
|
||||
baro_alt_offset = (OFFSET_FILTER * baro_alt_offset + (float)baro.absolute) / (OFFSET_FILTER + 1);
|
||||
// decrease init counter
|
||||
@@ -75,7 +75,7 @@ void baro_periodic( void ) {
|
||||
}
|
||||
#endif
|
||||
// Read the ADC
|
||||
ads1114_read();
|
||||
ads1114_read(&BARO_ABS_ADS);
|
||||
}
|
||||
|
||||
void baro_downlink_raw( void )
|
||||
|
||||
@@ -35,6 +35,11 @@
|
||||
|
||||
#define BARO_FILTER_GAIN 5
|
||||
|
||||
/* There is no differential pressure on the board but
|
||||
* it can be available from an external sensor
|
||||
* */
|
||||
#define DIFF_FILTER_GAIN 5
|
||||
|
||||
#ifdef USE_BARO_AS_ALTIMETER
|
||||
extern float baro_alt;
|
||||
extern float baro_alt_offset;
|
||||
@@ -43,15 +48,45 @@ extern float baro_alt_offset;
|
||||
|
||||
extern void baro_downlink_raw( void );
|
||||
|
||||
#define BARO_ABS_ADS ads1114_1
|
||||
|
||||
#define BaroAbs(_ads, _handler) { \
|
||||
if (_ads.data_available) { \
|
||||
baro.absolute = (baro.absolute + BARO_FILTER_GAIN*Ads1114GetValue(_ads)) / (BARO_FILTER_GAIN+1); \
|
||||
if (baro.status == BS_RUNNING) { \
|
||||
_handler(); \
|
||||
_ads.data_available = FALSE; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifndef BaroDiff // Allow custom redefinition ?
|
||||
|
||||
#if USE_BARO_DIFF
|
||||
|
||||
#ifndef BARO_DIFF_ADS
|
||||
#define BARO_DIFF_ADS ads1114_2
|
||||
#endif
|
||||
#define BaroDiff(_ads, _handler) { \
|
||||
if (_ads.data_available) { \
|
||||
baro.differential = (baro.differential + DIFF_FILTER_GAIN*Ads1114GetValue(_ads)) / (DIFF_FILTER_GAIN+1); \
|
||||
if (baro.status == BS_RUNNING) { \
|
||||
_handler(); \
|
||||
_ads.data_available = FALSE; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#else // Not using differential with ADS1114
|
||||
#define BaroDiff(_a, _h) {}
|
||||
#endif
|
||||
|
||||
#endif // ifndef BaroDiff
|
||||
|
||||
#define BaroEvent(_b_abs_handler, _b_diff_handler) { \
|
||||
Ads1114Event(); \
|
||||
if (ads1114_data_available) { \
|
||||
baro.absolute = (baro.absolute + BARO_FILTER_GAIN*Ads1114GetValue()) / (BARO_FILTER_GAIN+1); \
|
||||
if (baro.status == BS_RUNNING) { \
|
||||
_b_abs_handler(); \
|
||||
ads1114_data_available = FALSE; \
|
||||
} \
|
||||
} \
|
||||
BaroAbs(BARO_ABS_ADS,_b_abs_handler); \
|
||||
BaroDiff(BARO_DIFF_ADS,_b_diff_handler); \
|
||||
}
|
||||
|
||||
#endif // BOARDS_UMARIM_BARO_H
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Gautier Hattenberger
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Module to extend the baro_board module with an airspeed sensor
|
||||
* Init and event functions are handled by the baro_board module
|
||||
*/
|
||||
|
||||
#include "modules/sensors/airspeed_ads1114.h"
|
||||
#include "subsystems/sensors/baro.h"
|
||||
#include "baro_board.h"
|
||||
|
||||
void airspeed_periodic(void) {
|
||||
ads1114_read(&BARO_DIFF_ADS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Gautier Hattenberger
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Module to extend the baro_board module with an airspeed sensor
|
||||
*/
|
||||
|
||||
#ifndef AIRSPEED_ADS1114_H
|
||||
#define AIRSPEED_ADS1114_H
|
||||
|
||||
extern void airspeed_periodic(void);
|
||||
|
||||
#endif
|
||||
@@ -27,28 +27,44 @@
|
||||
|
||||
#include "peripherals/ads1114.h"
|
||||
|
||||
struct i2c_transaction ads1114_trans;
|
||||
|
||||
bool_t ads1114_config_done;
|
||||
bool_t ads1114_data_available;
|
||||
#if USE_ADS1114_1
|
||||
struct ads1114_periph ads1114_1;
|
||||
#endif
|
||||
#if USE_ADS1114_2
|
||||
struct ads1114_periph ads1114_2;
|
||||
#endif
|
||||
|
||||
void ads1114_init( void ) {
|
||||
/* configure the ads1114 */
|
||||
ads1114_trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
|
||||
ads1114_trans.buf[1] = ADS1114_CONFIG_MSB;
|
||||
ads1114_trans.buf[2] = ADS1114_CONFIG_LSB;
|
||||
I2CTransmit(ADS1114_I2C_DEVICE, ads1114_trans, ADS1114_I2C_ADDR, 3);
|
||||
ads1114_config_done = FALSE;
|
||||
ads1114_data_available = FALSE;
|
||||
/* configure the ads1114_1 */
|
||||
#if USE_ADS1114_1
|
||||
ads1114_1.i2c_addr = ADS1114_1_I2C_ADDR;
|
||||
ads1114_1.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
|
||||
ads1114_1.trans.buf[1] = ADS1114_1_CONFIG_MSB;
|
||||
ads1114_1.trans.buf[2] = ADS1114_1_CONFIG_LSB;
|
||||
I2CTransmit(ADS1114_I2C_DEVICE, ads1114_1.trans, ADS1114_1_I2C_ADDR, 3);
|
||||
ads1114_1.config_done = FALSE;
|
||||
ads1114_1.data_available = FALSE;
|
||||
#endif
|
||||
|
||||
/* configure the ads1114_2 */
|
||||
#if USE_ADS1114_2
|
||||
ads1114_2.i2c_addr = ADS1114_2_I2C_ADDR;
|
||||
ads1114_2.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
|
||||
ads1114_2.trans.buf[1] = ADS1114_2_CONFIG_MSB;
|
||||
ads1114_2.trans.buf[2] = ADS1114_2_CONFIG_LSB;
|
||||
I2CTransmit(ADS1114_I2C_DEVICE, ads1114_2.trans, ADS1114_2_I2C_ADDR, 3);
|
||||
ads1114_2.config_done = FALSE;
|
||||
ads1114_2.data_available = FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void ads1114_read( void ) {
|
||||
void ads1114_read( struct ads1114_periph * p ) {
|
||||
// Config done with success
|
||||
// start new reading when previous is done (and read if success)
|
||||
if (ads1114_config_done && ads1114_trans.status == I2CTransDone) {
|
||||
ads1114_trans.buf[0] = ADS1114_POINTER_CONV_REG;
|
||||
I2CTransceive(ADS1114_I2C_DEVICE, ads1114_trans, ADS1114_I2C_ADDR, 1, 2);
|
||||
if (p->config_done && p->trans.status == I2CTransDone) {
|
||||
p->trans.buf[0] = ADS1114_POINTER_CONV_REG;
|
||||
I2CTransceive(ADS1114_I2C_DEVICE, p->trans, p->i2c_addr, 1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,66 +32,136 @@
|
||||
|
||||
|
||||
/* I2C slave address */
|
||||
#define ADS1114_I2C_ADDR 0x90 // slave address byte (I2c address(7bits) + R/W @ 0)
|
||||
#ifndef ADS1114_1_I2C_ADDR
|
||||
#define ADS1114_1_I2C_ADDR 0x90 // slave address byte (I2c address(7bits) + R/W @ 0)
|
||||
#endif
|
||||
#ifndef ADS1114_2_I2C_ADDR
|
||||
#define ADS1114_2_I2C_ADDR 0x92 // slave address byte (I2c address(7bits) + R/W @ 0)
|
||||
#endif
|
||||
|
||||
/* I2C conf register */
|
||||
#define ADS1114_POINTER_CONV_REG 0x00 // access to the Conversion register (16bits)
|
||||
#define ADS1114_POINTER_CONFIG_REG 0x01 // access to the Configuration register (16bits)
|
||||
|
||||
/* ADS1114 default conf */
|
||||
#ifndef ADS1114_OS
|
||||
#define ADS1114_OS 0x0 // Operational status
|
||||
/* ADS1114_1 default conf */
|
||||
#ifndef ADS1114_1_OS
|
||||
#define ADS1114_1_OS 0x0 // Operational status
|
||||
#endif
|
||||
#ifndef ADS1114_MUX
|
||||
#define ADS1114_MUX 0x0 // Input multiplexer
|
||||
#ifndef ADS1114_1_MUX
|
||||
#define ADS1114_1_MUX 0x0 // Input multiplexer
|
||||
#endif
|
||||
#ifndef ADS1114_PGA
|
||||
#define ADS1114_PGA 0x3 // Programable gain amplifier (= 4 with a Full Scale of +/- 1.024V)
|
||||
#ifndef ADS1114_1_PGA
|
||||
#define ADS1114_1_PGA 0x3 // Programable gain amplifier (= 4 with a Full Scale of +/- 1.024V)
|
||||
#endif
|
||||
#ifndef ADS1114_MODE
|
||||
#define ADS1114_MODE 0x0 // Continuous conversion mode
|
||||
#ifndef ADS1114_1_MODE
|
||||
#define ADS1114_1_MODE 0x0 // Continuous conversion mode
|
||||
#endif
|
||||
#ifndef ADS1114_DR
|
||||
#define ADS1114_DR 0x4 // Data rate (128 SPS)
|
||||
#ifndef ADS1114_1_DR
|
||||
#define ADS1114_1_DR 0x4 // Data rate (128 SPS)
|
||||
#endif
|
||||
#ifndef ADS1114_COMP_MODE
|
||||
#define ADS1114_COMP_MODE 0x0 // Comparator mode
|
||||
#ifndef ADS1114_1_COMP_MODE
|
||||
#define ADS1114_1_COMP_MODE 0x0 // Comparator mode
|
||||
#endif
|
||||
#ifndef ADS1114_COMP_POL
|
||||
#define ADS1114_COMP_POL 0x0 // Comparator polarity
|
||||
#ifndef ADS1114_1_COMP_POL
|
||||
#define ADS1114_1_COMP_POL 0x0 // Comparator polarity
|
||||
#endif
|
||||
#ifndef ADS1114_COMP_LAT
|
||||
#define ADS1114_COMP_LAT 0x0 // Latching comparator
|
||||
#ifndef ADS1114_1_COMP_LAT
|
||||
#define ADS1114_1_COMP_LAT 0x0 // Latching comparator
|
||||
#endif
|
||||
#ifndef ADS1114_COMP_QUE
|
||||
#define ADS1114_COMP_QUE 0x3 // Comparator queue (disable)
|
||||
#ifndef ADS1114_1_COMP_QUE
|
||||
#define ADS1114_1_COMP_QUE 0x3 // Comparator queue (disable)
|
||||
#endif
|
||||
|
||||
#define ADS1114_CONFIG_MSB ((ADS1114_OS<<7)|(ADS1114_MUX<<4)|(ADS1114_PGA<<1)|(ADS1114_MODE))
|
||||
#define ADS1114_CONFIG_LSB ((ADS1114_DR<<5)|(ADS1114_COMP_MODE<<4)|(ADS1114_COMP_POL<<3)|(ADS1114_COMP_LAT<<2)|(ADS1114_COMP_QUE))
|
||||
#define ADS1114_1_CONFIG_MSB ((ADS1114_1_OS<<7)|(ADS1114_1_MUX<<4)|(ADS1114_1_PGA<<1)|(ADS1114_1_MODE))
|
||||
#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))
|
||||
|
||||
/* ADS1114_1 default conf */
|
||||
#ifndef ADS1114_2_OS
|
||||
#define ADS1114_2_OS 0x0 // Operational status
|
||||
#endif
|
||||
#ifndef ADS1114_2_MUX
|
||||
#define ADS1114_2_MUX 0x0 // Input multiplexer
|
||||
#endif
|
||||
#ifndef ADS1114_2_PGA
|
||||
#define ADS1114_2_PGA 0x3 // Programable gain amplifier (= 4 with a Full Scale of +/- 1.024V)
|
||||
#endif
|
||||
#ifndef ADS1114_2_MODE
|
||||
#define ADS1114_2_MODE 0x0 // Continuous conversion mode
|
||||
#endif
|
||||
#ifndef ADS1114_2_DR
|
||||
#define ADS1114_2_DR 0x4 // Data rate (128 SPS)
|
||||
#endif
|
||||
#ifndef ADS1114_2_COMP_MODE
|
||||
#define ADS1114_2_COMP_MODE 0x0 // Comparator mode
|
||||
#endif
|
||||
#ifndef ADS1114_2_COMP_POL
|
||||
#define ADS1114_2_COMP_POL 0x0 // Comparator polarity
|
||||
#endif
|
||||
#ifndef ADS1114_2_COMP_LAT
|
||||
#define ADS1114_2_COMP_LAT 0x0 // Latching comparator
|
||||
#endif
|
||||
#ifndef ADS1114_2_COMP_QUE
|
||||
#define ADS1114_2_COMP_QUE 0x3 // Comparator queue (disable)
|
||||
#endif
|
||||
|
||||
#define ADS1114_2_CONFIG_MSB ((ADS1114_2_OS<<7)|(ADS1114_2_MUX<<4)|(ADS1114_2_PGA<<1)|(ADS1114_2_MODE))
|
||||
#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))
|
||||
|
||||
/* Default I2C device */
|
||||
// FIXME all ads on the same device for now
|
||||
#ifndef ADS1114_I2C_DEVICE
|
||||
#define ADS1114_I2C_DEVICE i2c1
|
||||
#endif
|
||||
|
||||
extern struct i2c_transaction ads1114_trans;
|
||||
extern bool_t ads1114_config_done;
|
||||
extern bool_t ads1114_data_available;
|
||||
struct ads1114_periph {
|
||||
struct i2c_transaction trans;
|
||||
uint8_t i2c_addr;
|
||||
bool_t config_done;
|
||||
bool_t data_available;
|
||||
};
|
||||
|
||||
#if USE_ADS1114_1
|
||||
extern struct ads1114_periph ads1114_1;
|
||||
#endif
|
||||
|
||||
#if USE_ADS1114_2
|
||||
extern struct ads1114_periph ads1114_2;
|
||||
#endif
|
||||
|
||||
extern void ads1114_init(void);
|
||||
extern void ads1114_read(void);
|
||||
extern void ads1114_read(struct ads1114_periph * p);
|
||||
|
||||
#define Ads1114Event() { \
|
||||
if (!ads1114_config_done) { \
|
||||
if (ads1114_trans.status == I2CTransSuccess) { ads1114_config_done = TRUE; ads1114_trans.status = I2CTransDone; } \
|
||||
if (ads1114_trans.status == I2CTransFailed) { ads1114_trans.status = I2CTransDone; } \
|
||||
// Generic Event Macro
|
||||
#define _Ads1114Event(_p) {\
|
||||
if (!_p.config_done) { \
|
||||
if (_p.trans.status == I2CTransSuccess) { _p.config_done = TRUE; _p.trans.status = I2CTransDone; } \
|
||||
if (_p.trans.status == I2CTransFailed) { _p.trans.status = I2CTransDone; } \
|
||||
} else { \
|
||||
if (ads1114_trans.status == I2CTransSuccess) { ads1114_data_available = TRUE; ads1114_trans.status = I2CTransDone; } \
|
||||
if (ads1114_trans.status == I2CTransFailed) { ads1114_trans.status = I2CTransDone; } \
|
||||
}\
|
||||
if (_p.trans.status == I2CTransSuccess) { _p.data_available = TRUE; _p.trans.status = I2CTransDone; } \
|
||||
if (_p.trans.status == I2CTransFailed) { _p.trans.status = I2CTransDone; } \
|
||||
} \
|
||||
}
|
||||
|
||||
#define Ads1114GetValue() ((int16_t)(((int16_t)ads1114_trans.buf[0]<<8)|ads1114_trans.buf[1]))
|
||||
#if USE_ADS1114_1
|
||||
#define Ads1114_1Event() _Ads1114Event(ads1114_1)
|
||||
#else
|
||||
#define Ads1114_1Event() {}
|
||||
#endif
|
||||
|
||||
#if USE_ADS1114_2
|
||||
#define Ads1114_2Event() _Ads1114Event(ads1114_2)
|
||||
#else
|
||||
#define Ads1114_2Event() {}
|
||||
#endif
|
||||
|
||||
// Final event macro
|
||||
#define Ads1114Event() { \
|
||||
Ads1114_1Event(); \
|
||||
Ads1114_2Event(); \
|
||||
}
|
||||
|
||||
// Get value macro
|
||||
// @param ads1114 periph
|
||||
#define Ads1114GetValue(_p) ((int16_t)(((int16_t)_p.trans.buf[0]<<8)|_p.trans.buf[1]))
|
||||
|
||||
#endif // ADS_1114_H
|
||||
|
||||
Reference in New Issue
Block a user