diff --git a/sw/airborne/boards/lia/baro_board.c b/sw/airborne/boards/lia/baro_board.c new file mode 100644 index 0000000000..daf96d61df --- /dev/null +++ b/sw/airborne/boards/lia/baro_board.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2013 Felix Ruess + * + * 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. + */ + +/** @file boards/lisa_m/baro_board.c + * Baro board interface for Bosch BMP085 on LisaM I2C2 with EOC check. + */ + +#include "std.h" + +#include "subsystems/sensors/baro.h" +#include "peripherals/bmp085.h" +#include "peripherals/bmp085_regs.h" +#include +#include "subsystems/abi.h" + +#include "led.h" + + +struct Bmp085 baro_bmp085; + +static bool baro_eoc(void) +{ + return gpio_get(GPIOB, GPIO0); +} + +void baro_init(void) +{ + bmp085_init(&baro_bmp085, &i2c2, BMP085_SLAVE_ADDR); + + /* setup eoc check function */ + baro_bmp085.eoc = &baro_eoc; + + gpio_clear(GPIOB, GPIO0); + gpio_set_mode(GPIOB, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, GPIO0); + +#ifdef BARO_LED + LED_OFF(BARO_LED); +#endif +} + + +void baro_periodic(void) +{ + if (baro_bmp085.initialized) { + bmp085_periodic(&baro_bmp085); + } else { + bmp085_read_eeprom_calib(&baro_bmp085); + } +} + + + +void baro_event(void) +{ + bmp085_event(&baro_bmp085); + + if (baro_bmp085.data_available) { + float pressure = (float)baro_bmp085.pressure; + AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, pressure); + float temp = baro_bmp085.temperature / 10.0f; + AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp); + baro_bmp085.data_available = false; +#ifdef BARO_LED + RunOnceEvery(10, LED_TOGGLE(BARO_LED)); +#endif + } +} diff --git a/sw/airborne/boards/lia/baro_board.h b/sw/airborne/boards/lia/baro_board.h new file mode 100644 index 0000000000..751fc75e91 --- /dev/null +++ b/sw/airborne/boards/lia/baro_board.h @@ -0,0 +1,18 @@ + +/* + * board specific functions for the lia board + * + */ + +#ifndef BOARDS_LIA_BARO_H +#define BOARDS_LIA_BARO_H + +// only for printing the baro type during compilation +#ifndef BARO_BOARD +#define BARO_BOARD BARO_BOARD_BMP085 +#endif + +extern void baro_event(void); +#define BaroEvent baro_event + +#endif /* BOARDS_LIA_BARO_H */ diff --git a/sw/airborne/boards/lia_1.1.h b/sw/airborne/boards/lia_1.1.h index 280b65bd0d..01e543420d 100644 --- a/sw/airborne/boards/lia_1.1.h +++ b/sw/airborne/boards/lia_1.1.h @@ -127,9 +127,10 @@ #define DefaultVoltageOfAdc(adc) (0.0045*adc) - -// FIXME, using baro_board right now to include the appropriate header -#define USE_BARO_BOARD 0 +/* by default activate onboard baro */ +#ifndef USE_BARO_BOARD +#define USE_BARO_BOARD 1 +#endif #endif /* CONFIG_LIA_1_1_H */