From 60e4aba272a1b14a9290219cf6bc53a9f16b2e88 Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Mon, 2 Nov 2015 18:42:28 +0000 Subject: [PATCH] Re-organised for two barometers --- firmware/inc/{bmp180.h => barometer.h} | 10 +++--- firmware/inc/hw_config.h | 6 ++++ firmware/inc/ms5607.h | 42 ------------------------- firmware/src/bmp180.c | 9 ++++-- firmware/src/data.c | 2 +- firmware/src/init.c | 2 +- firmware/src/ms5607.c | 12 +++++-- firmware/test/tc/pressure_temperature.h | 2 +- 8 files changed, 30 insertions(+), 55 deletions(-) rename firmware/inc/{bmp180.h => barometer.h} (92%) delete mode 100644 firmware/inc/ms5607.h diff --git a/firmware/inc/bmp180.h b/firmware/inc/barometer.h similarity index 92% rename from firmware/inc/bmp180.h rename to firmware/inc/barometer.h index ebd08ed..564a982 100644 --- a/firmware/inc/bmp180.h +++ b/firmware/inc/barometer.h @@ -1,5 +1,5 @@ /* - * BMP180 (also BMP085) + * Header for Barometer * Copyright (C) 2014 Richard Meadows * * Permission is hereby granted, free of charge, to any person obtaining @@ -22,8 +22,8 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef BMP180_H -#define BMP180_H +#ifndef BAROMETER_H +#define BAROMETER_H #include "samd20.h" @@ -37,6 +37,6 @@ struct barometer { }; struct barometer* get_barometer(void); -void bmp180_init(void); +void barometer_init(void); -#endif /* BMP180_H */ +#endif /* BAROMETER_H */ diff --git a/firmware/inc/hw_config.h b/firmware/inc/hw_config.h index 87fdfe7..6383003 100644 --- a/firmware/inc/hw_config.h +++ b/firmware/inc/hw_config.h @@ -102,6 +102,12 @@ #define I2C_SERCOM_SCL_PIN PIN_PA01 #define I2C_SERCOM_SCL_PINMUX PINMUX_PA01D_SERCOM1_PAD1 +/** + * Barometer + */ +#define BAROMETER_TYPE_BMP180 0 +#define BAROMETER_TYPE_MS5607 1 + /** * Battery ADC */ diff --git a/firmware/inc/ms5607.h b/firmware/inc/ms5607.h deleted file mode 100644 index fa4801c..0000000 --- a/firmware/inc/ms5607.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MS5607 - * Copyright (C) 2015 Richard Meadows - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef MS5607_H -#define MS5607_H - -#include "samd20.h" - -/** - * Barometer data structure - */ -struct barometer { - double temperature; - double pressure; - int valid; // 1 = valid, 0 = invalid -}; - -struct barometer* get_barometer(void); -void ms5607_init(void); - -#endif /* MS5607_H */ diff --git a/firmware/src/bmp180.c b/firmware/src/bmp180.c index 29d0bec..64679af 100644 --- a/firmware/src/bmp180.c +++ b/firmware/src/bmp180.c @@ -26,9 +26,12 @@ #include #include "samd20.h" -#include "bmp180.h" -#include "sercom/i2c.h" +#include "hw_config.h" +#if BAROMETER_TYPE_BMP180 + +#include "barometer.h" +#include "sercom/i2c.h" #define BMP180_ADDRESS 0xEE #define BMP180_REG_ID 0xD0 @@ -273,3 +276,5 @@ void bmp180_init(void) /* Get the calibration parameters */ get_cal_param(&calibration); } + +#endif diff --git a/firmware/src/data.c b/firmware/src/data.c index 48464f3..5ee2399 100644 --- a/firmware/src/data.c +++ b/firmware/src/data.c @@ -29,7 +29,7 @@ #include "xosc.h" #include "hw_config.h" #include "analogue.h" -#include "bmp180.h" +#include "barometer.h" #include "gps.h" #include "ubx_messages.h" #include "telemetry.h" diff --git a/firmware/src/init.c b/firmware/src/init.c index efdefa7..6631f50 100644 --- a/firmware/src/init.c +++ b/firmware/src/init.c @@ -38,7 +38,7 @@ #include "data.h" #include "memory.h" #include "telemetry.h" -#include "bmp180.h" +#include "barometer.h" #include "init.h" /** diff --git a/firmware/src/ms5607.c b/firmware/src/ms5607.c index 1ac625b..8d8a420 100644 --- a/firmware/src/ms5607.c +++ b/firmware/src/ms5607.c @@ -26,7 +26,11 @@ #include #include "samd20.h" -#include "ms5607.h" +#include "hw_config.h" + +#if BAROMETER_TYPE_MS5607 + +#include "barometer.h" #include "sercom/i2c.h" #define MS5607_ADDRESS 0xEE @@ -160,7 +164,7 @@ void get_cal_param(struct calibration *c) { uint32_t get_d1(void) { /* Write command */ - write_command(D1_COMMAND); + command(D1_COMMAND); /* Wait?? */ @@ -173,7 +177,7 @@ uint32_t get_d1(void) { uint32_t get_d2(void) { /* Write command */ - write_command(D2_COMMAND); + command(D2_COMMAND); /* Wait?? */ @@ -238,3 +242,5 @@ void ms5607_init(void) /* Get the calibration parameters */ get_cal_param(&calibration); } + +#endif diff --git a/firmware/test/tc/pressure_temperature.h b/firmware/test/tc/pressure_temperature.h index 34bb4a6..4bc2053 100644 --- a/firmware/test/tc/pressure_temperature.h +++ b/firmware/test/tc/pressure_temperature.h @@ -3,7 +3,7 @@ #endif #include "samd20.h" -#include "bmp180.h" +#include "barometer.h" /****************************//* pressure_temperature_tc *//****************************/ /**