From: Nils Forssén Date: Mon, 2 Jun 2025 20:52:22 +0000 (+0200) Subject: WiP click reader, spi probably works now X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=fca2db4ab04f379217e8380a456c53c9c83ffbc2;p=flygplan.git WiP click reader, spi probably works now --- diff --git a/processes/click_reader/CMakeLists.txt b/processes/click_reader/CMakeLists.txt index 13d97ef..d76aadc 100644 --- a/processes/click_reader/CMakeLists.txt +++ b/processes/click_reader/CMakeLists.txt @@ -1,16 +1,13 @@ add_executable(click_reader main.cpp - #accel_click.cpp - #baro_click.cpp - bmp280.c - bmp280_support.c - spi.c ) target_include_directories(click_reader PRIVATE include) target_link_libraries(click_reader PRIVATE MAVLink) target_link_libraries(click_reader PRIVATE spdlog::spdlog) -target_link_libraries(click_reader PRIVATE wiringPi) + + +target_link_libraries(click_reader PRIVATE ${BCM2835_LIB}) target_include_directories(click_reader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) diff --git a/processes/click_reader/accel_click.cpp b/processes/click_reader/accel_click.cpp deleted file mode 100644 index cdab40f..0000000 --- a/processes/click_reader/accel_click.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "accel_click.h" - -#include - -static std::shared_ptr logger; - -static const cs_t CHIP_SELECT = CS_0; - -err_t c6dofimu17::init(std::shared_ptr logg) -{ - logger = logg; - - return spi_init(logg); -} - -err_t c6dofimu17::close() -{ - return spi_close();; -} - -float c6dofimu17::read_temp() -{ - return 0; -} \ No newline at end of file diff --git a/processes/click_reader/bmp280.c b/processes/click_reader/bmp280.c deleted file mode 100644 index 78ecca0..0000000 --- a/processes/click_reader/bmp280.c +++ /dev/null @@ -1,1493 +0,0 @@ -/* -**************************************************************************** -* Copyright (C) 2012 - 2014 Bosch Sensortec GmbH -* -* File : bmp280.h -* -* Date : 2014/12/12 -* -* Revision : 2.0.3(Pressure and Temperature compensation code revision is 1.1) -* -* Usage: Sensor Driver for BMP280 sensor -* -**************************************************************************** -* -* \section License -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* -* Neither the name of the copyright holder nor the names of the -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER -* OR CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, -* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -* ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE -* -* The information provided is believed to be accurate and reliable. -* The copyright holder assumes no responsibility -* for the consequences of use -* of such information nor for any infringement of patents or -* other rights of third parties which may result from its use. -* No license is granted by implication or otherwise under any patent or -* patent rights of the copyright holder. -**************************************************************************/ -#include "bmp280.h" -static struct bmp280_t *p_bmp280; /**< pointer to BMP280 */ - -/*! - * @brief This function is used for initialize - * the bus read and bus write functions - * and assign the chip id and I2C address of the BMP280 sensor - * chip id is read in the register 0xD0 bit from 0 to 7 - * - * @param *bmp280 structure pointer. - * - * @note While changing the parameter of the p_bmp280 - * @note consider the following point: - * Changing the reference value of the parameter - * will changes the local copy or local reference - * make sure your changes will not - * affect the reference value of the parameter - * (Better case don't change the reference value of the parameter) - * - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - p_bmp280 = bmp280;/* assign BMP280 ptr */ - /* read chip id */ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, - BMP280_CHIP_ID_REG, &v_data_u8, BMP280_ONE_U8X);/* read Chip Id */ - p_bmp280->chip_id = v_data_u8; - /* readout bmp280 calibparam structure */ - com_rslt += bmp280_get_calib_param(); - return com_rslt; -} -/*! - * @brief This API is used to read uncompensated temperature - * in the registers 0xFA, 0xFB and 0xFC - * @note 0xFA -> MSB -> bit from 0 to 7 - * @note 0xFB -> LSB -> bit from 0 to 7 - * @note 0xFC -> LSB -> bit from 4 to 7 - * - * @param v_uncomp_temperature_s32 : The uncompensated temperature. - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_temperature( -s32 *v_uncomp_temperature_s32) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - /* Array holding the MSB and LSb value - a_data_u8r[0] - Temperature MSB - a_data_u8r[1] - Temperature LSB - a_data_u8r[2] - Temperature LSB - */ - u8 a_data_u8r[ARRAY_SIZE_THREE] = { - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X}; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read temperature data */ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_TEMPERATURE_MSB_REG, - a_data_u8r, BMP280_THREE_U8X); - *v_uncomp_temperature_s32 = (s32)((( - (u32) (a_data_u8r[INDEX_ZERO])) - << SHIFT_LEFT_12_POSITION) | - (((u32)(a_data_u8r[INDEX_ONE])) - << SHIFT_LEFT_4_POSITION) - | ((u32)a_data_u8r[INDEX_TWO] - >> SHIFT_RIGHT_4_POSITION)); - } - return com_rslt; -} -/*! - * @brief Reads actual temperature - * from uncompensated temperature - * @note Returns the value in 0.01 degree Centigrade - * @note Output value of "5123" equals 51.23 DegC. - * - * - * - * @param v_uncomp_temperature_s32 : value of uncompensated temperature - * - * - * - * @return Actual temperature output as s32 - * -*/ -s32 bmp280_compensate_T_int32(s32 v_uncomp_temperature_s32) -{ - s32 v_x1_u32r = BMP280_ZERO_U8X; - s32 v_x2_u32r = BMP280_ZERO_U8X; - s32 temperature = BMP280_ZERO_U8X; - /* calculate true temperature*/ - v_x1_u32r = ((((v_uncomp_temperature_s32 - >> SHIFT_RIGHT_3_POSITION) - ((s32) - p_bmp280->calib_param.dig_T1 << SHIFT_LEFT_1_POSITION))) * - ((s32)p_bmp280->calib_param.dig_T2)) - >> SHIFT_RIGHT_11_POSITION; - v_x2_u32r = (((((v_uncomp_temperature_s32 - >> SHIFT_RIGHT_4_POSITION) - - ((s32)p_bmp280->calib_param.dig_T1)) * - ((v_uncomp_temperature_s32 >> SHIFT_RIGHT_4_POSITION) - - ((s32)p_bmp280->calib_param.dig_T1))) - >> SHIFT_RIGHT_12_POSITION) * - ((s32)p_bmp280->calib_param.dig_T3)) - >> SHIFT_RIGHT_14_POSITION; - p_bmp280->calib_param.t_fine = v_x1_u32r + v_x2_u32r; - temperature = (p_bmp280->calib_param.t_fine * - BMP20_DEC_TRUE_TEMP_FIVE_DATA - + BMP20_DEC_TRUE_TEMP_ONE_TWO_EIGHT_DATA) - >> SHIFT_RIGHT_8_POSITION; - - return temperature; -} -/*! - * @brief This API is used to read uncompensated pressure. - * in the registers 0xF7, 0xF8 and 0xF9 - * @note 0xF7 -> MSB -> bit from 0 to 7 - * @note 0xF8 -> LSB -> bit from 0 to 7 - * @note 0xF9 -> LSB -> bit from 4 to 7 - * - * - * - * @param v_uncomp_pressure_s32 : The value of uncompensated pressure - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure( -s32 *v_uncomp_pressure_s32) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - /* Array holding the MSB and LSb value - a_data_u8[0] - Pressure MSB - a_data_u8[1] - Pressure LSB - a_data_u8[2] - Pressure LSB - */ - u8 a_data_u8[ARRAY_SIZE_THREE] = { - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X}; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_PRESSURE_MSB_REG, - a_data_u8, BMP280_THREE_U8X); - *v_uncomp_pressure_s32 = (s32)( - (((u32)(a_data_u8[INDEX_ZERO])) - << SHIFT_LEFT_12_POSITION) | - (((u32)(a_data_u8[INDEX_ONE])) - << SHIFT_LEFT_4_POSITION) | - ((u32)a_data_u8[INDEX_TWO] >> - SHIFT_RIGHT_4_POSITION)); - } - return com_rslt; -} -/*! - * @brief Reads actual pressure from uncompensated pressure - * and returns the value in Pascal(Pa) - * @note Output value of "96386" equals 96386 Pa = - * 963.86 hPa = 963.86 millibar - * - * - * - * - * @param v_uncomp_pressure_s32: value of uncompensated pressure - * - * - * - * @return Returns the Actual pressure out put as s32 - * -*/ -u32 bmp280_compensate_P_int32(s32 v_uncomp_pressure_s32) -{ - s32 v_x1_u32r = BMP280_ZERO_U8X; - s32 v_x2_u32r = BMP280_ZERO_U8X; - u32 v_pressure_u32 = BMP280_ZERO_U8X; - /* calculate true pressure*/ - v_x1_u32r = (((s32)p_bmp280->calib_param.t_fine) - >> SHIFT_RIGHT_1_POSITION) - - (s32)BMP20_DEC_TRUE_PRESSURE_6_4_0_0_0_DATA; - v_x2_u32r = (((v_x1_u32r >> SHIFT_RIGHT_2_POSITION) * - (v_x1_u32r >> SHIFT_RIGHT_2_POSITION)) - >> SHIFT_RIGHT_11_POSITION) * - ((s32)p_bmp280->calib_param.dig_P6); - v_x2_u32r = v_x2_u32r + ((v_x1_u32r * - ((s32)p_bmp280->calib_param.dig_P5)) - << SHIFT_LEFT_1_POSITION); - v_x2_u32r = (v_x2_u32r >> SHIFT_RIGHT_2_POSITION) + - (((s32)p_bmp280->calib_param.dig_P4) - << SHIFT_LEFT_16_POSITION); - v_x1_u32r = (((p_bmp280->calib_param.dig_P3 * - (((v_x1_u32r >> SHIFT_RIGHT_2_POSITION) * - (v_x1_u32r >> SHIFT_RIGHT_2_POSITION)) - >> SHIFT_RIGHT_13_POSITION)) >> SHIFT_RIGHT_3_POSITION) + - ((((s32)p_bmp280->calib_param.dig_P2) * - v_x1_u32r) >> SHIFT_RIGHT_1_POSITION)) - >> SHIFT_RIGHT_18_POSITION; - v_x1_u32r = ((((BMP20_DEC_TRUE_PRESSURE_3_2_7_6_8_DATA - + v_x1_u32r)) * - ((s32)p_bmp280->calib_param.dig_P1)) - >> SHIFT_RIGHT_15_POSITION); - v_pressure_u32 = - (((u32)(((s32)BMP20_DEC_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA) - - v_uncomp_pressure_s32) - - (v_x2_u32r >> SHIFT_RIGHT_12_POSITION))) - * BMP20_DEC_TRUE_PRESSURE_3_1_2_5_DATA; - if (v_pressure_u32 - < BMP20_HEX_TRUE_PRESSURE_8_0_0_0_0_0_0_0_DATA) - /* Avoid exception caused by division by zero */ - if (v_x1_u32r != BMP280_ZERO_U8X) - v_pressure_u32 = - (v_pressure_u32 << SHIFT_LEFT_1_POSITION) - / ((u32)v_x1_u32r); - else - return BMP280_ZERO_U8X; - else - /* Avoid exception caused by division by zero */ - if (v_x1_u32r != BMP280_ZERO_U8X) - v_pressure_u32 = (v_pressure_u32 / - (u32)v_x1_u32r) - * BMP20_DEC_TRUE_PRESSURE_TWO_DATA; - else - return BMP280_ZERO_U8X; - v_x1_u32r = (((s32) - p_bmp280->calib_param.dig_P9) * - ((s32)(((v_pressure_u32 - >> SHIFT_RIGHT_3_POSITION) - * (v_pressure_u32 >> SHIFT_RIGHT_3_POSITION)) - >> SHIFT_RIGHT_13_POSITION))) - >> SHIFT_RIGHT_12_POSITION; - v_x2_u32r = (((s32)(v_pressure_u32 - >> SHIFT_RIGHT_2_POSITION)) * - ((s32)p_bmp280->calib_param.dig_P8)) - >> SHIFT_RIGHT_13_POSITION; - v_pressure_u32 = (u32) - ((s32)v_pressure_u32 + - ((v_x1_u32r + v_x2_u32r + - p_bmp280->calib_param.dig_P7) - >> SHIFT_RIGHT_4_POSITION)); - - return v_pressure_u32; -} -/*! - * @brief reads uncompensated pressure and temperature - * - * - * @param v_uncomp_pressure_s32: The value of uncompensated pressure. - * @param v_uncomp_temperature_s32: The value of uncompensated temperature. - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure_temperature( -s32 *v_uncomp_pressure_s32, -s32 *v_uncomp_temperature_s32) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - /* Array holding the temperature and pressure data - a_data_u8[0] - Pressure MSB - a_data_u8[1] - Pressure LSB - a_data_u8[2] - Pressure LSB - a_data_u8[3] - Temperature MSB - a_data_u8[4] - Temperature LSB - a_data_u8[5] - Temperature LSB - */ - u8 a_data_u8[ARRAY_SIZE_SIX] = {BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X}; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_PRESSURE_MSB_REG, a_data_u8, BMP280_SIX_U8X); - /*Pressure*/ - *v_uncomp_pressure_s32 = (s32)( - (((u32)(a_data_u8[INDEX_ZERO])) - << SHIFT_LEFT_12_POSITION) | - (((u32)(a_data_u8[INDEX_ONE])) - << SHIFT_LEFT_4_POSITION) | - ((u32)a_data_u8[INDEX_TWO] >> - SHIFT_RIGHT_4_POSITION)); - - /* Temperature */ - *v_uncomp_temperature_s32 = (s32)((( - (u32) (a_data_u8[INDEX_THREE])) - << SHIFT_LEFT_12_POSITION) | - (((u32)(a_data_u8[INDEX_FOUR])) - << SHIFT_LEFT_4_POSITION) - | ((u32)a_data_u8[INDEX_FIVE] - >> SHIFT_RIGHT_4_POSITION)); - } - return com_rslt; -} -/*! - * @brief This API reads the true pressure and temperature - * - * - * @param v_pressure_u32 : The value of compensated pressure. - * @param v_temperature_s32 : The value of compensated temperature. - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_pressure_temperature( -u32 *v_pressure_u32, -s32 *v_temperature_s32) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - s32 v_uncomp_pressure_s32 = BMP280_ZERO_U8X; - s32 v_uncomp_temperature_s32 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read uncompensated pressure and temperature*/ - com_rslt = bmp280_read_uncomp_pressure_temperature( - &v_uncomp_pressure_s32, &v_uncomp_temperature_s32); - /* read trure pressure and temperature*/ - *v_temperature_s32 = bmp280_compensate_T_int32( - v_uncomp_temperature_s32); - *v_pressure_u32 = bmp280_compensate_P_int32( - v_uncomp_pressure_s32); - } - return com_rslt; -} -/*! - * @brief This API is used to - * calibration parameters used for calculation in the registers - * - * parameter | Register address | bit - *------------|------------------|---------------- - * dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15 - * dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15 - * dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15 - * dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15 - * dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15 - * dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15 - * dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15 - * dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15 - * dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15 - * dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15 - * dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15 - * dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15 - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_calib_param() -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 a_data_u8[ARRAY_SIZE_TWENTY_SIX] = { - BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X, - BMP280_ZERO_U8X, BMP280_ZERO_U8X, BMP280_ZERO_U8X}; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_DIG_T1_LSB_REG, - a_data_u8, BMP280_TWENTY_FOUR_U8X); - /* read calibration values*/ - p_bmp280->calib_param.dig_T1 = (u16)((( - (u16)((u8)a_data_u8[INDEX_ONE])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_ZERO]); - p_bmp280->calib_param.dig_T2 = (s16)((( - (s16)((s8)a_data_u8[INDEX_THREE])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_TWO]); - p_bmp280->calib_param.dig_T3 = (s16)((( - (s16)((s8)a_data_u8[INDEX_FIVE])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_FOUR]); - p_bmp280->calib_param.dig_P1 = (u16)((( - (u16)((u8)a_data_u8[INDEX_SEVEN])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_SIX]); - p_bmp280->calib_param.dig_P2 = (s16)((( - (s16)((s8)a_data_u8[INDEX_NINE])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_EIGHT]); - p_bmp280->calib_param.dig_P3 = (s16)((( - (s16)((s8)a_data_u8[INDEX_ELEVEN])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_TEN]); - p_bmp280->calib_param.dig_P4 = (s16)((( - (s16)((s8)a_data_u8[INDEX_THIRTEEN])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_TWELVE]); - p_bmp280->calib_param.dig_P5 = (s16)((( - (s16)((s8)a_data_u8[INDEX_FIVETEEN])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_FOURTEEN]); - p_bmp280->calib_param.dig_P6 = (s16)((( - (s16)((s8)a_data_u8[INDEX_SEVENTEEN])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_SIXTEEN]); - p_bmp280->calib_param.dig_P7 = (s16)((( - (s16)((s8)a_data_u8[INDEX_NINETEEN])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_EIGHTEEN]); - p_bmp280->calib_param.dig_P8 = (s16)((( - (s16)((s8)a_data_u8[INDEX_TWENTY_ONE])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_TWENTY]); - p_bmp280->calib_param.dig_P9 = (s16)((( - (s16)((s8)a_data_u8[INDEX_TWENTY_THREE])) << - SHIFT_LEFT_8_POSITION) | a_data_u8[INDEX_TWENTY_TWO]); - } - return com_rslt; -} -/*! - * @brief This API is used to get - * the temperature oversampling setting in the register 0xF4 - * bits from 5 to 7 - * - * value | Temperature oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 :The value of temperature over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_temperature( -u8 *v_value_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read temperature over sampling*/ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG, - &v_data_u8, BMP280_ONE_U8X); - *v_value_u8 = BMP280_GET_BITSLICE(v_data_u8, - BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE); - /* assign temperature oversampling*/ - p_bmp280->oversamp_temperature = *v_value_u8; - } - return com_rslt; -} -/*! - * @brief This API is used to set - * the temperature oversampling setting in the register 0xF4 - * bits from 5 to 7 - * - * value | Temperature oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 :The value of temperature over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_temperature( -u8 v_value_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG, - &v_data_u8, BMP280_ONE_U8X); - if (com_rslt == SUCCESS) { - /* write over sampling*/ - v_data_u8 = - BMP280_SET_BITSLICE(v_data_u8, - BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE, - v_value_u8); - com_rslt += - p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG, - &v_data_u8, BMP280_ONE_U8X); - p_bmp280->oversamp_temperature = v_value_u8; - } - } - return com_rslt; -} -/*! - * @brief This API is used to get - * the pressure oversampling setting in the register 0xF4 - * bits from 2 to 4 - * - * value | Pressure oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 : The value of pressure over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_pressure( -u8 *v_value_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read pressure over sampling */ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG, - &v_data_u8, BMP280_ONE_U8X); - *v_value_u8 = BMP280_GET_BITSLICE(v_data_u8, - BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE); - - p_bmp280->oversamp_pressure = *v_value_u8; - } - return com_rslt; -} -/*! - * @brief This API is used to set - * the pressure oversampling setting in the register 0xF4 - * bits from 2 to 4 - * - * value | Pressure oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 : The value of pressure over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_pressure( -u8 v_value_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG, - &v_data_u8, BMP280_ONE_U8X); - if (com_rslt == SUCCESS) { - /* write pressure over sampling */ - v_data_u8 = BMP280_SET_BITSLICE( - v_data_u8, - BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE, - v_value_u8); - com_rslt += - p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG, - &v_data_u8, BMP280_ONE_U8X); - - p_bmp280->oversamp_pressure = v_value_u8; - } - } - return com_rslt; -} -/*! - * @brief This API used to get the - * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 - * - * - * - * @param v_power_mode_u8 : The value of power mode value - * value | Power mode - * ------------------|------------------ - * 0x00 | BMP280_SLEEP_MODE - * 0x01 and 0x02 | BMP280_FORCED_MODE - * 0x03 | BMP280_NORMAL_MODE - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_power_mode(u8 *v_power_mode_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_mode_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read the power mode*/ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_POWER_MODE__REG, - &v_mode_u8, BMP280_ONE_U8X); - *v_power_mode_u8 = BMP280_GET_BITSLICE(v_mode_u8, - BMP280_CTRL_MEAS_REG_POWER_MODE); - } - return com_rslt; -} -/*! - * @brief This API used to set the - * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 - * - * - * - * @param v_power_mode_u8 : The value of power mode value - * value | Power mode - * ------------------|------------------ - * 0x00 | BMP280_SLEEP_MODE - * 0x01 and 0x02 | BMP280_FORCED_MODE - * 0x03 | BMP280_NORMAL_MODE - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_power_mode(u8 v_power_mode_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_mode_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - if (v_power_mode_u8 < BMP280_FOUR_U8X) { - /* write the power mode*/ - v_mode_u8 = (p_bmp280->oversamp_temperature << - SHIFT_LEFT_5_POSITION) + - (p_bmp280->oversamp_pressure << - SHIFT_LEFT_2_POSITION) + v_power_mode_u8; - com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - BMP280_CTRL_MEAS_REG_POWER_MODE__REG, - &v_mode_u8, BMP280_ONE_U8X); - } else { - com_rslt = E_BMP280_OUT_OF_RANGE; - } - } - return com_rslt; -} -/*! - * @brief Used to reset the sensor - * The value 0xB6 is written to the 0xE0 register - * the device is reset using the - * complete power-on-reset procedure. - * Softreset can be easily set using bmp280_set_softreset(). - * - * @note Usage Hint : bmp280_set_softreset() - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_soft_rst() -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_SOFT_RESET_CODE; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* write soft reset */ - com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - BMP280_RST_REG, &v_data_u8, BMP280_ONE_U8X); - } - return com_rslt; -} -/*! - * @brief This API used to get the sensor - * SPI mode(communication type) in the register 0xF5 bit 0 - * - * - * - * @param v_enable_disable_u8 : The spi3 enable or disable state - * value | Description - * -----------|--------------- - * 0 | Disable - * 1 | Enable - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_spi3(u8 *v_enable_disable_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_SPI3_ENABLE__REG, - &v_data_u8, BMP280_ONE_U8X); - *v_enable_disable_u8 = BMP280_GET_BITSLICE( - v_data_u8, - BMP280_CONFIG_REG_SPI3_ENABLE); - } - return com_rslt; -} -/*! - * @brief This API used to set the sensor - * SPI mode(communication type) in the register 0xF5 bit 0 - * - * - * - * @param v_enable_disable_u8 : The spi3 enable or disable state - * value | Description - * -----------|--------------- - * 0 | Disable - * 1 | Enable - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_spi3(u8 v_enable_disable_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_SPI3_ENABLE__REG, - &v_data_u8, BMP280_ONE_U8X); - if (com_rslt == SUCCESS) { - v_data_u8 = BMP280_SET_BITSLICE( - v_data_u8, - BMP280_CONFIG_REG_SPI3_ENABLE, - v_enable_disable_u8); - com_rslt += - p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_SPI3_ENABLE__REG, - &v_data_u8, BMP280_ONE_U8X); - } - } - return com_rslt; -} -/*! - * @brief This API is used to reads filter setting - * in the register 0xF5 bit 3 and 4 - * - * - * - * @param v_value_u8 : The value of filter coefficient - * value | Filter coefficient - * -------------|------------------------- - * 0x00 | BMP280_FILTER_COEFF_OFF - * 0x01 | BMP280_FILTER_COEFF_2 - * 0x02 | BMP280_FILTER_COEFF_4 - * 0x03 | BMP280_FILTER_COEFF_8 - * 0x04 | BMP280_FILTER_COEFF_16 - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_filter(u8 *v_value_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read filter*/ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_FILTER__REG, - &v_data_u8, BMP280_ONE_U8X); - *v_value_u8 = BMP280_GET_BITSLICE(v_data_u8, - BMP280_CONFIG_REG_FILTER); - } - return com_rslt; -} -/*! - * @brief This API is used to write filter setting - * in the register 0xF5 bit 3 and 4 - * - * - * - * @param v_value_u8 : The value of filter coefficient - * value | Filter coefficient - * -------------|------------------------- - * 0x00 | BMP280_FILTER_COEFF_OFF - * 0x01 | BMP280_FILTER_COEFF_2 - * 0x02 | BMP280_FILTER_COEFF_4 - * 0x03 | BMP280_FILTER_COEFF_8 - * 0x04 | BMP280_FILTER_COEFF_16 - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_filter(u8 v_value_u8) -{ - BMP280_RETURN_FUNCTION_TYPE com_rslt = SUCCESS; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* write filter*/ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_FILTER__REG, - &v_data_u8, BMP280_ONE_U8X); - if (com_rslt == SUCCESS) { - v_data_u8 = BMP280_SET_BITSLICE( - v_data_u8, - BMP280_CONFIG_REG_FILTER, v_value_u8); - com_rslt += - p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_FILTER__REG, - &v_data_u8, BMP280_ONE_U8X); - } - } - return com_rslt; -} -/*! - * @brief This API used to Read the - * standby duration time from the sensor in the register 0xF5 bit 5 to 7 - * - * @param v_standby_durn_u8 : The standby duration time value. - * value | standby duration - * -----------|-------------------- - * 0x00 | BMP280_STANDBYTIME_1_MS - * 0x01 | BMP280_STANDBYTIME_63_MS - * 0x02 | BMP280_STANDBYTIME_125_MS - * 0x03 | BMP280_STANDBYTIME_250_MS - * 0x04 | BMP280_STANDBYTIME_500_MS - * 0x05 | BMP280_STANDBYTIME_1000_MS - * 0x06 | BMP280_STANDBYTIME_2000_MS - * 0x07 | BMP280_STANDBYTIME_4000_MS - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_standby_durn(u8 *v_standby_durn_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read the standby duration*/ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_STANDBY_DURN__REG, - &v_data_u8, BMP280_ONE_U8X); - *v_standby_durn_u8 = BMP280_GET_BITSLICE(v_data_u8, - BMP280_CONFIG_REG_STANDBY_DURN); - } - return com_rslt; -} -/*! - * @brief This API used to Read the - * standby duration time from the sensor - * in the register 0xF5 bit 5 to 7 - * @note Normal mode comprises an - * automated perpetual cycling between an (active) - * Measurement period and an (inactive) standby period. - * @note The standby time is determined - * by the contents of the register t_sb. - * Standby time can be set using BME280_STANDBYTIME_125_MS. - * - * @note bme280_set_standby_durN(BME280_STANDBYTIME_125_MS) - * - * - * - * @param v_standby_durn_u8 : The standby duration time value. - * value | standby duration - * -----------|-------------------- - * 0x00 | BMP280_STANDBYTIME_1_MS - * 0x01 | BMP280_STANDBYTIME_63_MS - * 0x02 | BMP280_STANDBYTIME_125_MS - * 0x03 | BMP280_STANDBYTIME_250_MS - * 0x04 | BMP280_STANDBYTIME_500_MS - * 0x05 | BMP280_STANDBYTIME_1000_MS - * 0x06 | BMP280_STANDBYTIME_2000_MS - * 0x07 | BMP280_STANDBYTIME_4000_MS - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_standby_durn(u8 v_standby_durn_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* write the standby duration*/ - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_STANDBY_DURN__REG, - &v_data_u8, BMP280_ONE_U8X); - if (com_rslt == SUCCESS) { - v_data_u8 = - BMP280_SET_BITSLICE(v_data_u8, - BMP280_CONFIG_REG_STANDBY_DURN, - v_standby_durn_u8); - com_rslt += - p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - BMP280_CONFIG_REG_STANDBY_DURN__REG, - &v_data_u8, BMP280_ONE_U8X); - } - } - return com_rslt; -} -/*! - * @brief This API is used to write - * the working mode of the sensor - * - * - * @param v_work_mode_u8 : The value of work mode - * value | mode - * -------------|------------- - * 0 | BMP280_ULTRA_LOW_POWER_MODE - * 1 | BMP280_LOW_POWER_MODE - * 2 | BMP280_STANDARD_RESOLUTION_MODE - * 3 | BMP280_HIGH_RESOLUTION_MODE - * 4 | BMP280_ULTRA_HIGH_RESOLUTION_MODE - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_work_mode(u8 v_work_mode_u8) -{ -/* variable used to return communication result*/ -BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; -u8 v_data_u8 = BMP280_ZERO_U8X; -/* check the p_bmp280 struct pointer as NULL*/ -if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; -} else { - if (v_work_mode_u8 <= BMP280_FOUR_U8X) { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, BMP280_CTRL_MEAS_REG, - &v_data_u8, BMP280_ONE_U8X); - if (com_rslt == SUCCESS) { - switch (v_work_mode_u8) { - /* write work mode*/ - case BMP280_ULTRA_LOW_POWER_MODE: - p_bmp280->oversamp_temperature = - BMP280_ULTRALOWPOWER_OVERSAMP_TEMPERATURE; - p_bmp280->oversamp_pressure = - BMP280_ULTRALOWPOWER_OVERSAMP_PRESSURE; - break; - case BMP280_LOW_POWER_MODE: - p_bmp280->oversamp_temperature = - BMP280_LOWPOWER_OVERSAMP_TEMPERATURE; - p_bmp280->oversamp_pressure = - BMP280_LOWPOWER_OVERSAMP_PRESSURE; - break; - case BMP280_STANDARD_RESOLUTION_MODE: - p_bmp280->oversamp_temperature = - BMP280_STANDARDRESOLUTION_OVERSAMP_TEMPERATURE; - p_bmp280->oversamp_pressure = - BMP280_STANDARDRESOLUTION_OVERSAMP_PRESSURE; - break; - case BMP280_HIGH_RESOLUTION_MODE: - p_bmp280->oversamp_temperature = - BMP280_HIGHRESOLUTION_OVERSAMP_TEMPERATURE; - p_bmp280->oversamp_pressure = - BMP280_HIGHRESOLUTION_OVERSAMP_PRESSURE; - break; - case BMP280_ULTRA_HIGH_RESOLUTION_MODE: - p_bmp280->oversamp_temperature = - BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_TEMPERATURE; - p_bmp280->oversamp_pressure = - BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_PRESSURE; - break; - } - v_data_u8 = BMP280_SET_BITSLICE(v_data_u8, - BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE, - p_bmp280->oversamp_temperature); - v_data_u8 = BMP280_SET_BITSLICE(v_data_u8, - BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE, - p_bmp280->oversamp_pressure); - com_rslt += p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, BMP280_CTRL_MEAS_REG, - &v_data_u8, BMP280_ONE_U8X); - } - } else { - com_rslt = E_BMP280_OUT_OF_RANGE; - } -} -return com_rslt; -} -/*! - * @brief This API used to read both - * uncompensated pressure and temperature in forced mode - * - * - * @param v_uncomp_pressure_s32: The value of uncompensated pressure. - * @param v_uncomp_temperature_s32: The value of uncompensated temperature - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE -bmp280_get_forced_uncomp_pressure_temperature(s32 *v_uncomp_pressure_s32, -s32 *v_uncomp_temperature_s32) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - u8 v_data_u8 = BMP280_ZERO_U8X; - u8 v_waittime_u8 = BMP280_ZERO_U8X; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - /* read pressure and temperature*/ - v_data_u8 = (p_bmp280->oversamp_temperature - << SHIFT_LEFT_5_POSITION) + - (p_bmp280->oversamp_pressure << SHIFT_LEFT_2_POSITION) + - BMP280_FORCED_MODE; - com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, BMP280_CTRL_MEAS_REG, - &v_data_u8, BMP280_ONE_U8X); - bmp280_compute_wait_time(&v_waittime_u8); - p_bmp280->delay_msec(v_waittime_u8); - com_rslt += bmp280_read_uncomp_pressure_temperature( - v_uncomp_pressure_s32, v_uncomp_temperature_s32); - } - return com_rslt; -} -/*! - * @brief - * This API write the data to - * the given register - * - * - * @param v_addr_u8 -> Address of the register - * @param v_data_u8 -> The data from the register - * @param v_len_u8 -> no of bytes to read - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * - */ -BMP280_RETURN_FUNCTION_TYPE bmp280_write_register(u8 v_addr_u8, -u8 *v_data_u8, u8 v_len_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC( - p_bmp280->dev_addr, - v_addr_u8, v_data_u8, v_len_u8); - } - return com_rslt; -} -/*! - * @brief - * This API reads the data from - * the given register - * - * - * @param v_addr_u8 -> Address of the register - * @param v_data_u8 -> The data from the register - * @param v_len_u8 -> no of bytes to read - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * - */ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_register(u8 v_addr_u8, -u8 *v_data_u8, u8 v_len_u8) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR; - /* check the p_bmp280 struct pointer as NULL*/ - if (p_bmp280 == BMP280_NULL) { - return E_BMP280_NULL_PTR; - } else { - com_rslt = p_bmp280->BMP280_BUS_READ_FUNC( - p_bmp280->dev_addr, - v_addr_u8, v_data_u8, v_len_u8); - } - return com_rslt; -} -#ifdef BMP280_ENABLE_FLOAT -/*! - * @brief This API used to read - * actual temperature from uncompensated temperature - * @note Returns the value in Degree centigrade - * @note Output value of "51.23" equals 51.23 DegC. - * - * - * - * @param v_uncomp_temperature_s32 : value of uncompensated temperature - * - * - * - * @return - * Actual temperature in floating point - * -*/ -double bmp280_compensate_T_double(s32 v_uncomp_temperature_s32) -{ - double v_x1_u32r = BMP280_ZERO_U8X; - double v_x2_u32r = BMP280_ZERO_U8X; - double temperature = BMP280_ZERO_U8X; - - v_x1_u32r = (((double)v_uncomp_temperature_s32) - / BMP280_FLOAT_TRUE_TEMP_1_6_3_8_4_DATA - - ((double)p_bmp280->calib_param.dig_T1) - / BMP280_FLOAT_TRUE_TEMP_1_0_2_4_DATA) * - ((double)p_bmp280->calib_param.dig_T2); - v_x2_u32r = ((((double)v_uncomp_temperature_s32) - / BMP280_FLOAT_TRUE_TEMP_1_3_1_0_7_2_DATA - - ((double)p_bmp280->calib_param.dig_T1) - / BMP280_FLOAT_TRUE_TEMP_8_1_9_2_DATA) * - (((double)v_uncomp_temperature_s32) - / BMP280_FLOAT_TRUE_TEMP_1_3_1_0_7_2_DATA - - ((double)p_bmp280->calib_param.dig_T1) - / BMP280_FLOAT_TRUE_TEMP_8_1_9_2_DATA)) * - ((double)p_bmp280->calib_param.dig_T3); - p_bmp280->calib_param.t_fine = (s32)(v_x1_u32r + v_x2_u32r); - temperature = (v_x1_u32r + v_x2_u32r) - / BMP280_FLOAT_TRUE_TEMP_5_1_2_0_DATA; - - - return temperature; -} -/*! - * @brief Reads actual pressure from uncompensated pressure - * and returns pressure in Pa as double. - * @note Output value of "96386.2" - * equals 96386.2 Pa = 963.862 hPa. - * - * - * - * @param v_uncomp_pressure_s32 : value of uncompensated pressure - * - * - * - * @return - * Actual pressure in floating point - * -*/ -double bmp280_compensate_P_double(s32 v_uncomp_pressure_s32) -{ - double v_x1_u32r = BMP280_ZERO_U8X; - double v_x2_u32r = BMP280_ZERO_U8X; - double pressure = BMP280_ZERO_U8X; - - v_x1_u32r = ((double)p_bmp280->calib_param.t_fine / - BMP280_FLAOT_TRUE_PRESSURE_2_DATA) - - BMP280_FLAOT_TRUE_PRESSURE_6_4_0_0_0_DATA; - v_x2_u32r = v_x1_u32r * v_x1_u32r * - ((double)p_bmp280->calib_param.dig_P6) / - BMP280_FLAOT_TRUE_PRESSURE_3_2_7_6_8_DATA; - v_x2_u32r = v_x2_u32r + v_x1_u32r * - ((double)p_bmp280->calib_param.dig_P5) - * BMP280_FLAOT_TRUE_PRESSURE_2_DATA; - v_x2_u32r = (v_x2_u32r / BMP280_FLAOT_TRUE_PRESSURE_4_DATA) + - (((double)p_bmp280->calib_param.dig_P4) - * BMP280_FLAOT_TRUE_PRESSURE_6_5_5_3_6_DATA); - v_x1_u32r = (((double)p_bmp280->calib_param.dig_P3) * - v_x1_u32r * v_x1_u32r - / BMP280_FLAOT_TRUE_PRESSURE_5_2_4_2_8_8_DATA + - ((double)p_bmp280->calib_param.dig_P2) * v_x1_u32r) - / BMP280_FLAOT_TRUE_PRESSURE_5_2_4_2_8_8_DATA; - v_x1_u32r = (BMP280_FLAOT_TRUE_PRESSURE_1_DATA + v_x1_u32r - / BMP280_FLAOT_TRUE_PRESSURE_3_2_7_6_8_DATA) * - ((double)p_bmp280->calib_param.dig_P1); - pressure = BMP280_FLAOT_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA - - (double)v_uncomp_pressure_s32; - /* Avoid exception caused by division by zero */ - if (v_x1_u32r != BMP280_FLAOT_TRUE_PRESSURE_0_DATA) - pressure = (pressure - (v_x2_u32r - / BMP280_FLAOT_TRUE_PRESSURE_4_0_9_6_DATA)) * - BMP280_FLAOT_TRUE_PRESSURE_6_2_5_0_DATA / v_x1_u32r; - else - return BMP280_ZERO_U8X; - v_x1_u32r = ((double)p_bmp280->calib_param.dig_P9) * - pressure * pressure / - BMP280_FLAOT_TRUE_PRESSURE_2_1_4_7_4_8_3_6_4_8_DATA; - v_x2_u32r = pressure * ((double)p_bmp280->calib_param.dig_P8) - / BMP280_FLAOT_TRUE_PRESSURE_3_2_7_6_8_DATA; - pressure = pressure + (v_x1_u32r + v_x2_u32r + - ((double)p_bmp280->calib_param.dig_P7)) - / BMP280_FLAOT_TRUE_PRESSURE_1_6_DATA; - - return pressure; -} -#endif -#if defined(BMP280_ENABLE_INT64) && defined(BMP280_64BITSUPPORT_PRESENT) -/*! - * @brief This API used to read actual pressure from uncompensated pressure - * @note returns the value in Pa as unsigned 32 bit - * integer in Q24.8 format (24 integer bits and - * 8 fractional bits). Output value of "24674867" - * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa - * - * - * - * @param v_uncomp_pressure_s32 : value of uncompensated pressure - * - * - * - * @return actual pressure as 64bit output - * -*/ -u32 bmp280_compensate_P_int64(s32 v_uncomp_pressure_s32) -{ - s64 v_x1_s64r = BMP280_ZERO_U8X; - s64 v_x2_s64r = BMP280_ZERO_U8X; - s64 pressure = BMP280_ZERO_U8X; - v_x1_s64r = ((s64)p_bmp280->calib_param.t_fine) - - BMP280_TRUE_PRESSURE_1_2_8_0_0_0_DATA; - v_x2_s64r = v_x1_s64r * v_x1_s64r * - (s64)p_bmp280->calib_param.dig_P6; - v_x2_s64r = v_x2_s64r + ((v_x1_s64r * - (s64)p_bmp280->calib_param.dig_P5) - << SHIFT_LEFT_17_POSITION); - v_x2_s64r = v_x2_s64r + - (((s64)p_bmp280->calib_param.dig_P4) - << SHIFT_LEFT_35_POSITION); - v_x1_s64r = ((v_x1_s64r * v_x1_s64r * - (s64)p_bmp280->calib_param.dig_P3) - >> SHIFT_RIGHT_8_POSITION) + - ((v_x1_s64r * (s64)p_bmp280->calib_param.dig_P2) - << SHIFT_LEFT_12_POSITION); - v_x1_s64r = (((((s64)BMP280_TRUE_PRESSURE_1_DATA) - << SHIFT_LEFT_47_POSITION) + v_x1_s64r)) * - ((s64)p_bmp280->calib_param.dig_P1) - >> SHIFT_RIGHT_33_POSITION; - pressure = BMP280_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA - - v_uncomp_pressure_s32; - if (v_x1_s64r != BMP280_ZERO_U8X) - #if defined __KERNEL__ - pressure = div64_s64((((pressure - << SHIFT_LEFT_31_POSITION) - v_x2_s64r) - * BMP280_TRUE_PRESSURE_3_1_2_5_DATA), v_x1_s64r); - #else - pressure = (((pressure - << SHIFT_LEFT_31_POSITION) - v_x2_s64r) - * BMP280_TRUE_PRESSURE_3_1_2_5_DATA) / v_x1_s64r; - #endif - else - return BMP280_ZERO_U8X; - v_x1_s64r = (((s64)p_bmp280->calib_param.dig_P9) * - (pressure >> SHIFT_RIGHT_13_POSITION) * - (pressure >> SHIFT_RIGHT_13_POSITION)) - >> SHIFT_RIGHT_25_POSITION; - v_x2_s64r = (((s64)p_bmp280->calib_param.dig_P8) * - pressure) >> SHIFT_RIGHT_19_POSITION; - pressure = ((pressure + v_x1_s64r + v_x2_s64r) - >> SHIFT_RIGHT_8_POSITION) + - (((s64)p_bmp280->calib_param.dig_P7) - << SHIFT_LEFT_4_POSITION); - return (u32)pressure; -} -#endif -/*! - * @brief Computing waiting time for sensor data read - * - * - * - * - * @param v_delaytime_u8r: The value of delay time - * - * - * @return 0 - * - * - */ -BMP280_RETURN_FUNCTION_TYPE bmp280_compute_wait_time(u8 -*v_delaytime_u8r) -{ - /* variable used to return communication result*/ - BMP280_RETURN_FUNCTION_TYPE com_rslt = SUCCESS; - - *v_delaytime_u8r = (T_INIT_MAX + T_MEASURE_PER_OSRS_MAX * - (((BMP280_ONE_U8X << p_bmp280->oversamp_temperature) - >> SHIFT_RIGHT_1_POSITION) + - ((BMP280_ONE_U8X << p_bmp280->oversamp_pressure) - >> SHIFT_RIGHT_1_POSITION)) + - (p_bmp280->oversamp_pressure ? T_SETUP_PRESSURE_MAX : BMP280_ZERO_U8X) - + BMP280_FIVETEEN_U8X) - / BMP280_SIXTEEN_U8X; - return com_rslt; -} diff --git a/processes/click_reader/bmp280_support.c b/processes/click_reader/bmp280_support.c deleted file mode 100644 index a39f7d7..0000000 --- a/processes/click_reader/bmp280_support.c +++ /dev/null @@ -1,489 +0,0 @@ - /* -**************************************************************************** -* Copyright (C) 2014 Bosch Sensortec GmbH -* -* bmp280_support.c -* Date: 2014/12/12 -* Revision: 1.0.4 -* -* Usage: Sensor Driver support file for BMP280 sensor -* -**************************************************************************** -* License: -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* -* Neither the name of the copyright holder nor the names of the -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER -* OR CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, -* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -* ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE -* -* The information provided is believed to be accurate and reliable. -* The copyright holder assumes no responsibility -* for the consequences of use -* of such information nor for any infringement of patents or -* other rights of third parties which may result from its use. -* No license is granted by implication or otherwise under any patent or -* patent rights of the copyright holder. -**************************************************************************/ -/*---------------------------------------------------------------------------*/ -/* Includes*/ -/*---------------------------------------------------------------------------*/ -#include "bmp280.h" - -#include -#include "spi.h" - -#define BMP280_API -#define BMP280 -/*----------------------------------------------------------------------------* -* The following functions are used for reading and writing of -* sensor data using I2C or SPI communication -*----------------------------------------------------------------------------*/ -#ifdef BMP280_API -/* \Brief: The function is used as I2C bus read - * \Return : Status of the I2C read - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be read - * \param reg_data : This data read from the sensor, which is hold in an array - * \param cnt : The no of byte of data to be read - */ -s8 BMP280_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); - /* \Brief: The function is used as I2C bus write - * \Return : Status of the I2C write - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be written - * \param reg_data : It is a value hold in the array, - * will be used for write the value into the register - * \param cnt : The no of byte of data to be write - */ -s8 BMP280_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); -/* \Brief: The function is used as SPI bus write - * \Return : Status of the SPI write - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be written - * \param reg_data : It is a value hold in the array, - * will be used for write the value into the register - * \param cnt : The no of byte of data to be write - */ -s8 BMP280_SPI_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); -/* \Brief: The function is used as SPI bus read - * \Return : Status of the SPI read - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be read - * \param reg_data : This data read from the sensor, which is hold in an array - * \param cnt : The no of byte of data to be read */ -s8 BMP280_SPI_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt); -/* - * \Brief: SPI/I2C init routine -*/ -s8 I2C_routine(void); -s8 SPI_routine(void); -#endif -/********************End of I2C/SPI function declarations***********************/ -/* Brief : The delay routine - * \param : delay in ms -*/ -void BMP280_delay_msek(u32 msek); -/* This function is an example for reading sensor data - * \param: None - * \return: communication result - */ -s32 bmp280_data_readout_template(void); -/*----------------------------------------------------------------------------* - * struct bmp280_t parameters can be accessed by using bmp280 - * bmp280_t having the following parameters - * Bus write function pointer: BMP280_WR_FUNC_PTR - * Bus read function pointer: BMP280_RD_FUNC_PTR - * Delay function pointer: delay_msec - * I2C address: dev_addr - * Chip id of the sensor: chip_id - *---------------------------------------------------------------------------*/ -struct bmp280_t bmp280; -/* This function is an example for reading sensor data - * \param: None - * \return: communication result - */ -s32 bmp280_data_readout_template(void) -{ - /* The variable used to assign the standby time*/ - u8 v_standby_time_u8 = BMP280_ZERO_U8X; - /* The variable used to read uncompensated temperature*/ - s32 v_data_uncomp_tem_s32 = BMP280_ZERO_U8X; - /* The variable used to read uncompensated pressure*/ - s32 v_data_uncomp_pres_s32 = BMP280_ZERO_U8X; - /* The variable used to read real temperature*/ - s32 v_actual_temp_s32 = BMP280_ZERO_U8X; - /* The variable used to read real pressure*/ - u32 v_actual_press_u32 = BMP280_ZERO_U8X; - s32 v_actual_press_data_s32 = BMP280_ZERO_U8X; - /* result of communication results*/ - s32 com_rslt = ERROR; -/*********************** START INITIALIZATION ************************/ - /* Based on the user need configure I2C or SPI interface. - * It is example code to explain how to use the bma2x2 API*/ - #ifdef BMP280 - /*I2C_routine(); */ - SPI_routine(); - #endif -/*--------------------------------------------------------------------------* - * This function used to assign the value/reference of - * the following parameters - * I2C address - * Bus Write - * Bus read - * Chip id -*-------------------------------------------------------------------------*/ - com_rslt = bmp280_init(&bmp280); - - /* For initialization it is required to set the mode of - * the sensor as "NORMAL" - * data acquisition/read/write is possible in this mode - * by using the below API able to set the power mode as NORMAL*/ - /* Set the power mode as NORMAL*/ - com_rslt += bmp280_set_power_mode(BMP280_NORMAL_MODE); - /* For reading the pressure and temperature data it is required to - * set the work mode - * The measurement period in the Normal mode is depends on the setting of - * over sampling setting of pressure, temperature and standby time - * - * OSS pressure OSS temperature OSS - * ultra low power x1 x1 - * low power x2 x1 - * standard resolution x4 x1 - * high resolution x8 x2 - * ultra high resolution x16 x2 - */ - /* The oversampling settings are set by using the following API*/ - com_rslt += bmp280_set_work_mode(BMP280_ULTRA_LOW_POWER_MODE); -/*------------------------------------------------------------------------* -************************* START GET and SET FUNCTIONS DATA **************** -*---------------------------------------------------------------------------*/ - /* This API used to Write the standby time of the sensor input - * value have to be given*/ - /* Normal mode comprises an automated perpetual cycling between an (active) - * Measurement period and an (inactive) standby period. - * The standby time is determined by the contents of the register t_sb. - * Standby time can be set using BMP280_STANDBYTIME_125_MS. - * Usage Hint : BMP280_set_standbydur(BMP280_STANDBYTIME_125_MS)*/ - - com_rslt += bmp280_set_standby_durn(BMP280_STANDBY_TIME_1_MS); - - /* This API used to read back the written value of standby time*/ - com_rslt += bmp280_get_standby_durn(&v_standby_time_u8); -/*-----------------------------------------------------------------* -************************* END GET and SET FUNCTIONS **************** -*------------------------------------------------------------------*/ - -/************************* END INITIALIZATION *************************/ - -/*------------------------------------------------------------------* -************ START READ UNCOMPENSATED PRESSURE AND TEMPERATURE******** -*---------------------------------------------------------------------*/ - /* API is used to read the uncompensated temperature*/ - com_rslt += bmp280_read_uncomp_temperature(&v_data_uncomp_tem_s32); - - /* API is used to read the uncompensated pressure*/ - com_rslt += bmp280_read_uncomp_pressure(&v_data_uncomp_pres_s32); - - /* API is used to read the uncompensated temperature and pressure*/ - com_rslt += bmp280_read_uncomp_pressure_temperature(&v_actual_press_data_s32, - &v_actual_temp_s32); -/*--------------------------------------------------------------------* -************ END READ UNCOMPENSATED PRESSURE AND TEMPERATURE******** -*-------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------* -************ START READ TRUE PRESSURE AND TEMPERATURE******** -*---------------------------------------------------------------------*/ - /* API is used to read the true temperature*/ - /* Input value as uncompensated temperature*/ - com_rslt += bmp280_compensate_T_int32(v_actual_temp_s32); - - /* API is used to read the true pressure*/ - /* Input value as uncompensated pressure*/ - com_rslt += bmp280_compensate_P_int32(v_actual_press_u32); - - /* API is used to read the true temperature and pressure*/ - /* Input value as uncompensated pressure and temperature*/ - com_rslt += bmp280_read_pressure_temperature(&v_actual_press_u32, - &v_actual_temp_s32); -/*--------------------------------------------------------------------* -************ END READ TRUE PRESSURE AND TEMPERATURE******** -*-------------------------------------------------------------------------*/ - - -/************************* START DE-INITIALIZATION ***********************/ - - /* For de-initialization it is required to set the mode of - * the sensor as "SLEEP" - * the device reaches the lowest power consumption only - * In SLEEP mode no measurements are performed - * All registers are accessible - * by using the below API able to set the power mode as SLEEP*/ - /* Set the power mode as SLEEP*/ - com_rslt += bmp280_set_power_mode(BMP280_SLEEP_MODE); - - return com_rslt; -/************************* END DE-INITIALIZATION **********************/ -} - -#ifdef BMP280_API -/*--------------------------------------------------------------------------* -* The following function is used to map the I2C bus read, write, delay and -* device address with global structure bmp280_t -*-------------------------------------------------------------------------*/ -s8 I2C_routine(void) { -/*--------------------------------------------------------------------------* - * By using bmp280 the following structure parameter can be accessed - * Bus write function pointer: BMP280_WR_FUNC_PTR - * Bus read function pointer: BMP280_RD_FUNC_PTR - * Delay function pointer: delay_msec - * I2C address: dev_addr - *--------------------------------------------------------------------------*/ - bmp280.bus_write = BMP280_I2C_bus_write; - bmp280.bus_read = BMP280_I2C_bus_read; - bmp280.dev_addr = BMP280_I2C_ADDRESS2; - bmp280.delay_msec = BMP280_delay_msek; - - return BMP280_ZERO_U8X; -} - -/*---------------------------------------------------------------------------* - * The following function is used to map the SPI bus read, write and delay - * with global structure bmp280_t - *--------------------------------------------------------------------------*/ -s8 SPI_routine(void) { -/*--------------------------------------------------------------------------* - * By using bmp280 the following structure parameter can be accessed - * Bus write function pointer: BMP280_WR_FUNC_PTR - * Bus read function pointer: BMP280_RD_FUNC_PTR - * Delay function pointer: delay_msec - *--------------------------------------------------------------------------*/ - - bmp280.bus_write = BMP280_SPI_bus_write; - bmp280.bus_read = BMP280_SPI_bus_read; - bmp280.delay_msec = BMP280_delay_msek; - - return BMP280_ZERO_U8X; -} - -/************** I2C/SPI buffer length ******/ - -#define I2C_BUFFER_LEN 8 -#define SPI_BUFFER_LEN 5 -#define BUFFER_LENGTH 0xFF -#define MASK_DATA 0x80 -#define REGISTER_MASK 0x7F -/*-------------------------------------------------------------------* -* This is a sample code for read and write the data by using I2C/SPI -* Use either I2C or SPI based on your need -* The device address defined in the bmp180.c -* -*-----------------------------------------------------------------------*/ - /* \Brief: The function is used as I2C bus write - * \Return : Status of the I2C write - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be written - * \param reg_data : It is a value hold in the array, - * will be used for write the value into the register - * \param cnt : The no of byte of data to be write - */ -s8 BMP280_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) -{ - s32 iError = BMP280_ZERO_U8X; - u8 array[I2C_BUFFER_LEN]; - u8 stringpos = BMP280_ZERO_U8X; - array[BMP280_ZERO_U8X] = reg_addr; - for (stringpos = BMP280_ZERO_U8X; stringpos < cnt; stringpos++) { - array[stringpos + BMP280_ONE_U8X] = *(reg_data + stringpos); - } - /* - * Please take the below function as your reference for - * write the data using I2C communication - * "IERROR = I2C_WRITE_STRING(DEV_ADDR, ARRAY, CNT+1)" - * add your I2C write function here - * iError is an return value of I2C read function - * Please select your valid return value - * In the driver SUCCESS defined as BMP280_ZERO_U8X - * and FAILURE defined as -1 - * Note : - * This is a full duplex operation, - * The first read data is discarded, for that extra write operation - * have to be initiated. For that cnt+1 operation done in the I2C write string function - * For more information please refer data sheet SPI communication: - */ - return (s8)iError; -} - - /* \Brief: The function is used as I2C bus read - * \Return : Status of the I2C read - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be read - * \param reg_data : This data read from the sensor, which is hold in an array - * \param cnt : The no of data to be read - */ -s8 BMP280_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) -{ - s32 iError = BMP280_ZERO_U8X; - u8 array[I2C_BUFFER_LEN] = {BMP280_ZERO_U8X}; - u8 stringpos = BMP280_ZERO_U8X; - array[BMP280_ZERO_U8X] = reg_addr; - /* Please take the below function as your reference - * for read the data using I2C communication - * add your I2C rad function here. - * "IERROR = I2C_WRITE_READ_STRING(DEV_ADDR, ARRAY, ARRAY, 1, CNT)" - * iError is an return value of SPI write function - * Please select your valid return value - * In the driver SUCCESS defined as BMP280_ZERO_U8X - * and FAILURE defined as -1 - */ - for (stringpos = BMP280_ZERO_U8X; stringpos < cnt; stringpos++) { - *(reg_data + stringpos) = array[stringpos]; - } - return (s8)iError; -} - -/* \Brief: The function is used as SPI bus read - * \Return : Status of the SPI read - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be read - * \param reg_data : This data read from the sensor, which is hold in an array - * \param cnt : The no of data to be read - */ -s8 BMP280_SPI_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) -{ - s32 iError=BMP280_ZERO_U8X; - u8 array[SPI_BUFFER_LEN]={BUFFER_LENGTH}; - u8 stringpos; - /* For the SPI mode only 7 bits of register addresses are used. - The MSB of register address is declared the bit what functionality it is - read/write (read as 1/write as BMP280_ZERO_U8X)*/ - array[BMP280_ZERO_U8X] = reg_addr|MASK_DATA;/*read routine is initiated register address is mask with 0x80*/ - /* - * Please take the below function as your reference for - * read the data using SPI communication - * " IERROR = SPI_READ_WRITE_STRING(ARRAY, ARRAY, CNT+1)" - * add your SPI read function here - * iError is an return value of SPI read function - * Please select your valid return value - * In the driver SUCCESS defined as BMP280_ZERO_U8X - * and FAILURE defined as -1 - * Note : - * This is a full duplex operation, - * The first read data is discarded, for that extra write operation - * have to be initiated. For that cnt+1 operation done in the SPI read - * and write string function - * For more information please refer data sheet SPI communication: - */ - u8 rx_array[100]={0}; - - - iError = spi_transfer(0, array, rx_array, cnt + 1, 0); - - rx_array[BMP280_ZERO_U8X] = reg_addr|MASK_DATA; - - for (stringpos = BMP280_ZERO_U8X; stringpos < cnt; stringpos++) { - *(reg_data + stringpos) = rx_array[stringpos+BMP280_ONE_U8X]; - } - return (s8)iError; -} - -/* \Brief: The function is used as SPI bus write - * \Return : Status of the SPI write - * \param dev_addr : The device address of the sensor - * \param reg_addr : Address of the first register, will data is going to be written - * \param reg_data : It is a value hold in the array, - * will be used for write the value into the register - * \param cnt : The no of byte of data to be write - */ -s8 BMP280_SPI_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) -{ - s32 iError = BMP280_ZERO_U8X; - u8 array[SPI_BUFFER_LEN * BMP280_TWO_U8X]; - u8 stringpos = BMP280_ZERO_U8X; - for (stringpos = BMP280_ZERO_U8X; stringpos < cnt; stringpos++) { - /* the operation of (reg_addr++)&0x7F done: because it ensure the - BMP280_ZERO_U8X and 1 of the given value - It is done only for 8bit operation*/ - array[stringpos * BMP280_TWO_U8X] = (reg_addr++) & REGISTER_MASK; - array[stringpos * BMP280_TWO_U8X + BMP280_ONE_U8X] = *(reg_data + stringpos); - } - /* Please take the below function as your reference - * for write the data using SPI communication - * add your SPI write function here. - * "IERROR = SPI_WRITE_STRING(ARRAY, CNT*2)" - * iError is an return value of SPI write function - * Please select your valid return value - * In the driver SUCCESS defined as BMP280_ZERO_U8X - * and FAILURE defined as -1 - */ - - u8 rx_array[SPI_BUFFER_LEN * BMP280_TWO_U8X] = {0}; - iError = spi_transfer(0, array, rx_array, cnt * 2, 0); - - return (s8)iError; -} - -/* Brief : The delay routine - * \param : delay in ms -*/ -void BMP280_delay_msek(u32 msek) -{ - /*Here you can write your own delay routine*/ - sleep(msek / 1000); -} - -s8 bmp280_init_my(void) -{ - SPI_routine(); - - bmp280_init(&bmp280); - - s8 value_to_write[] = {0b01010111, 0b001010000}; - bmp280_write_register(0xF4, value_to_write, 2); - - return 0; -} - -s32 bmp280_read_temperature(void) -{ - s32 uncomp_temp; - - bmp280_read_uncomp_temperature(&uncomp_temp); - - return bmp280_compensate_T_int32(uncomp_temp); -} - -s64 bmp280_read_pressure(void) -{ - s32 uncomp_temp; - - bmp280_read_uncomp_pressure(&uncomp_temp); - - return bmp280_compensate_P_int64(uncomp_temp); -} -#endif diff --git a/processes/click_reader/include/accel_click.h b/processes/click_reader/include/accel_click.h deleted file mode 100644 index dd09d5d..0000000 --- a/processes/click_reader/include/accel_click.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef ACCEL_CLICK_H -#define ACCEL_CLICK_H - -#define C6DOFIMU_OK 0x00 -#define C6DOFIMU_INIT_ERROR 0xFF - -#define C6DOFIMU_SLAVE_ADDRESS 0x6B; - -#define C6DOFIMU_FUNC_CFG_ACCESS 0x01 - -#define C6DOFIMU_FIFO_CTRL1 0x06 -#define C6DOFIMU_FIFO_CTRL2 0x07 -#define C6DOFIMU_FIFO_CTRL3 0x08 -#define C6DOFIMU_FIFO_CTRL4 0x09 -#define C6DOFIMU_FIFO_CTRL5 0x0A - -#define C6DOFIMU_ORIENT_CFG_G 0x0B - -#define C6DOFIMU_INT1_CTRL 0x0D -#define C6DOFIMU_INT2_CTRL 0x0E - -#define C6DOFIMU_CTRL1_XL 0x10 -#define C6DOFIMU_CTRL2_G 0x11 -#define C6DOFIMU_CTRL3_C 0x12 -#define C6DOFIMU_CTRL4_C 0x13 -#define C6DOFIMU_CTRL5_C 0x14 -#define C6DOFIMU_CTRL6_C 0x15 -#define C6DOFIMU_CTRL7_G 0x16 -#define C6DOFIMU_CTRL8_XL 0x17 -#define C6DOFIMU_CTRL9_XL 0x18 -#define C6DOFIMU_CTRL10_C 0x19 - -#define C6DOFIMU_OUT_TEMP_L 0x20 -#define C6DOFIMU_OUT_TEMP_H 0x21 - -#define C6DOFIMU_OUTX_L_G 0x22 -#define C6DOFIMU_OUTX_H_G 0x23 -#define C6DOFIMU_OUTY_L_G 0x24 -#define C6DOFIMU_OUTY_H_G 0x25 -#define C6DOFIMU_OUTZ_L_G 0x26 -#define C6DOFIMU_OUTZ_H_G 0x27 - -#define C6DOFIMU_OUTX_L_XL 0x28 -#define C6DOFIMU_OUTX_H_XL 0x29 -#define C6DOFIMU_OUTY_L_XL 0x2A -#define C6DOFIMU_OUTY_H_XL 0x2B -#define C6DOFIMU_OUTZ_L_XL 0x2C -#define C6DOFIMU_OUTZ_H_XL 0x2D - -#define C6DOFIMU_FIFO_DATA_OUT_L 0x3E -#define C6DOFIMU_FIFO_DATA_OUT_H 0x3F - -#define C6DOFIMU_TIMESTAMP0_REG 0x40 -#define C6DOFIMU_TIMESTAMP1_REG 0x41 -#define C6DOFIMU_TIMESTAMP2_REG 0x42 - -#define C6DOFIMU_STEP_COUNTER_L 0x4B -#define C6DOFIMU_STEP_COUNTER_H 0x4C - -#define C6DOFIMU_STATUS_REG 0x1E - -#define C6DOFIMU_FIFO_STATUS1 0x3A -#define C6DOFIMU_FIFO_STATUS2 0x3B -#define C6DOFIMU_FIFO_STATUS3 0x3C -#define C6DOFIMU_FIFO_STATUS4 0x3D - -#define C6DOFIMU_TIMESTAMP_L 0x49 -#define C6DOFIMU_TIMESTAMP_H 0x4A - -#define C6DOFIMU_WHO_AM_I 0x0F - -#define C6DOFIMU_WAKE_UP_SRC 0x1B -#define C6DOFIMU_TAP_SRC 0x1C -#define C6DOFIMU_D6D_SRC 0x1D - -#define C6DOFIMU_FUN_SRC 0x53 - -#define C6DOFIMU_TAP_CFG 0x58 -#define C6DOFIMU_TAP_THS_6D 0x59 -#define C6DOFIMU_INT_DUR2 0x5A -#define C6DOFIMU_WAKE_UP_THS 0x5B -#define C6DOFIMU_WAKE_UP_DUR 0x5C -#define C6DOFIMU_FREE_FALL 0x5D -#define C6DOFIMU_MD1_CFG 0x5E -#define C6DOFIMU_MD2_CFG 0x5F - -#define C6DOFIMU_CFG_BIT_0 0x01 -#define C6DOFIMU_CFG_BIT_1 0x02 -#define C6DOFIMU_CFG_BIT_2 0x04 -#define C6DOFIMU_CFG_BIT_3 0x08 -#define C6DOFIMU_CFG_BIT_4 0x10 -#define C6DOFIMU_CFG_BIT_5 0x20 -#define C6DOFIMU_CFG_BIT_6 0x40 -#define C6DOFIMU_CFG_BIT_7 0x80 - -#define C6DOFIMU_ACCEL_READ_MODE 0x00 -#define C6DOFIMU_GYRO_READ_MODE 0x01 - -#include - -#include - -#include "util.h" - - -namespace c6dofimu17 -{ - err_t init(std::shared_ptr logg); - err_t close(); - - float read_temp(); -} - - -#endif \ No newline at end of file diff --git a/processes/click_reader/include/bmp280.h b/processes/click_reader/include/bmp280.h deleted file mode 100644 index 7262c0c..0000000 --- a/processes/click_reader/include/bmp280.h +++ /dev/null @@ -1,1501 +0,0 @@ -/** \mainpage -* -**************************************************************************** -* Copyright (C) 2012 - 2014 Bosch Sensortec GmbH -* -* File : bmp280.h -* -* Date : 2014/12/12 -* -* Revision : 2.0.3(Pressure and Temperature compensation code revision is 1.1) -* -* Usage: Sensor Driver for BMP280 sensor -* -**************************************************************************** -* -* \section License -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* -* Neither the name of the copyright holder nor the names of the -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER -* OR CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, -* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -* ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE -* -* The information provided is believed to be accurate and reliable. -* The copyright holder assumes no responsibility -* for the consequences of use -* of such information nor for any infringement of patents or -* other rights of third parties which may result from its use. -* No license is granted by implication or otherwise under any patent or -* patent rights of the copyright holder. -**************************************************************************/ -/*! \file bmp280.h - \brief BMP280 Sensor Driver Support Header File */ -#ifndef __BMP280_H__ -#define __BMP280_H__ - -#ifdef __cplusplus -extern "C" { -#endif -/*! -* @brief The following definition uses for define the data types -* -* @note While porting the API please consider the following -* @note Please check the version of C standard -* @note Are you using Linux platform -*/ - -/*! -* @brief For the Linux platform support -* Please use the types.h for your data types definitions -*/ -#ifdef __KERNEL__ - -#include -#include -#define BMP280_64BITSUPPORT_PRESENT -/* singed integer type*/ -typedef int8_t s8;/**< used for signed 8bit */ -typedef int16_t s16;/**< used for signed 16bit */ -typedef int32_t s32;/**< used for signed 32bit */ -typedef int64_t s64;/**< used for signed 64bit */ - -typedef u_int8_t u8;/**< used for unsigned 8bit */ -typedef u_int16_t u16;/**< used for unsigned 16bit */ -typedef u_int32_t u32;/**< used for unsigned 32bit */ -typedef u_int64_t u64;/**< used for unsigned 64bit */ - - - -#else /* ! __KERNEL__ */ -/********************************************************** -* These definition uses for define the C -* standard version data types -***********************************************************/ -# if !defined(__STDC_VERSION__) - -/************************************************ - * compiler is C11 C standard -************************************************/ -#if (__STDC_VERSION__ == 201112L) - -/************************************************/ -#include -/************************************************/ - -/*unsigned integer types*/ -typedef uint8_t u8;/**< used for unsigned 8bit */ -typedef uint16_t u16;/**< used for unsigned 16bit */ -typedef uint32_t u32;/**< used for unsigned 32bit */ -typedef uint64_t u64;/**< used for unsigned 64bit */ - -/*signed integer types*/ -typedef int8_t s8;/**< used for signed 8bit */ -typedef int16_t s16;/**< used for signed 16bit */ -typedef int32_t s32;/**< used for signed 32bit */ -typedef int64_t s64;/**< used for signed 64bit */ -#define BMP280_64BITSUPPORT_PRESENT -/************************************************ - * compiler is C99 C standard -************************************************/ - -#elif (__STDC_VERSION__ == 199901L) - -/* stdint.h is a C99 supported c library. -which is used to fixed the integer size*/ -/************************************************/ -#include -/************************************************/ - -/*unsigned integer types*/ -typedef uint8_t u8;/**< used for unsigned 8bit */ -typedef uint16_t u16;/**< used for unsigned 16bit */ -typedef uint32_t u32;/**< used for unsigned 32bit */ -typedef uint64_t u64;/**< used for unsigned 64bit */ - -/*signed integer types*/ -typedef int8_t s8;/**< used for signed 8bit */ -typedef int16_t s16;/**< used for signed 16bit */ -typedef int32_t s32;/**< used for signed 32bit */ -typedef int64_t s64;/**< used for signed 64bit */ -#define BMP280_64BITSUPPORT_PRESENT -/************************************************ - * compiler is C89 or other C standard -************************************************/ - -#else /* !defined(__STDC_VERSION__) */ -/*! -* @brief By default it is defined as 32 bit machine configuration -* define your data types based on your -* machine/compiler/controller configuration -*/ -#define MACHINE_32_BIT - -/*! @brief - * If your machine support 16 bit - * define the MACHINE_16_BIT - */ -#ifdef MACHINE_16_BIT -#include -/*signed integer types*/ -typedef signed char s8;/**< used for signed 8bit */ -typedef signed short int s16;/**< used for signed 16bit */ -typedef signed long int s32;/**< used for signed 32bit */ - -#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL -typedef long int s64;/**< used for signed 64bit */ -typedef unsigned long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT -#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) -typedef long long int s64;/**< used for signed 64bit */ -typedef unsigned long long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT -#else -#warning Either the correct data type for signed 64 bit integer \ -could not be found, or 64 bit integers are not supported in your environment. -#warning The API will only offer 32 bit pressure calculation.This will \ -slightly impede accuracy(noise of ~1 pascal RMS will be added to output). -#warning If 64 bit integers are supported on your platform, \ -please set s64 manually and "#define(BMP280_64BITSUPPORT_PRESENT)" manually. -#endif - -/*unsigned integer types*/ -typedef unsigned char u8;/**< used for unsigned 8bit */ -typedef unsigned short int u16;/**< used for unsigned 16bit */ -typedef unsigned long int u32;/**< used for unsigned 32bit */ - -/* If your machine support 32 bit -define the MACHINE_32_BIT*/ -#elif defined MACHINE_32_BIT -/*signed integer types*/ -typedef signed char s8;/**< used for signed 8bit */ -typedef signed short int s16;/**< used for signed 16bit */ -typedef signed int s32;/**< used for signed 32bit */ -typedef signed long long int s64;/**< used for signed 64bit */ - -/*unsigned integer types*/ -typedef unsigned char u8;/**< used for unsigned 8bit */ -typedef unsigned short int u16;/**< used for unsigned 16bit */ -typedef unsigned int u32;/**< used for unsigned 32bit */ -typedef unsigned long long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT - -/* If your machine support 64 bit -define the MACHINE_64_BIT*/ -#elif defined MACHINE_64_BIT -/*signed integer types*/ -typedef signed char s8;/**< used for signed 8bit */ -typedef signed short int s16;/**< used for signed 16bit */ -typedef signed int s32;/**< used for signed 32bit */ -typedef signed long int s64;/**< used for signed 64bit */ - -/*unsigned integer types*/ -typedef unsigned char u8;/**< used for unsigned 8bit */ -typedef unsigned short int u16;/**< used for unsigned 16bit */ -typedef unsigned int u32;/**< used for unsigned 32bit */ -typedef unsigned long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT - -#else -#warning The data types defined above which not supported \ -define the data types manually -#endif -#endif - -/*** This else will execute for the compilers - * which are not supported the C standards - * Like C89/C99/C11***/ -#else -/*! -* @brief By default it is defined as 32 bit machine configuration -* define your data types based on your -* machine/compiler/controller configuration -*/ -#define MACHINE_32_BIT - -/* If your machine support 16 bit -define the MACHINE_16_BIT*/ -#ifdef MACHINE_16_BIT -#include -/*signed integer types*/ -typedef signed char s8;/**< used for signed 8bit */ -typedef signed short int s16;/**< used for signed 16bit */ -typedef signed long int s32;/**< used for signed 32bit */ - -#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL -typedef long int s64;/**< used for signed 64bit */ -typedef unsigned long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT -#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) -typedef long long int s64;/**< used for signed 64bit */ -typedef unsigned long long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT -#else -#warning Either the correct data type for signed 64 bit integer \ -could not be found, or 64 bit integers are not supported in your environment. -#warning The API will only offer 32 bit pressure calculation.This will \ -slightly impede accuracy(noise of ~1 pascal RMS will be added to output). -#warning If 64 bit integers are supported on your platform, \ -please set s64 manually and "#define(BMP280_64BITSUPPORT_PRESENT)" manually. -#endif - -/*unsigned integer types*/ -typedef unsigned char u8;/**< used for unsigned 8bit */ -typedef unsigned short int u16;/**< used for unsigned 16bit */ -typedef unsigned long int u32;/**< used for unsigned 32bit */ - -/*! @brief If your machine support 32 bit -define the MACHINE_32_BIT*/ -#elif defined MACHINE_32_BIT -/*signed integer types*/ -typedef signed char s8;/**< used for signed 8bit */ -typedef signed short int s16;/**< used for signed 16bit */ -typedef signed int s32;/**< used for signed 32bit */ -typedef signed long long int s64;/**< used for signed 64bit */ - -/*unsigned integer types*/ -typedef unsigned char u8;/**< used for unsigned 8bit */ -typedef unsigned short int u16;/**< used for unsigned 16bit */ -typedef unsigned int u32;/**< used for unsigned 32bit */ -typedef unsigned long long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT - -/* If your machine support 64 bit -define the MACHINE_64_BIT*/ -#elif defined MACHINE_64_BIT -/*signed integer types*/ -typedef signed char s8;/**< used for signed 8bit */ -typedef signed short int s16;/**< used for signed 16bit */ -typedef signed int s32;/**< used for signed 32bit */ -typedef signed long int s64;/**< used for signed 64bit */ - -/*unsigned integer types*/ -typedef unsigned char u8;/**< used for unsigned 8bit */ -typedef unsigned short int u16;/**< used for unsigned 16bit */ -typedef unsigned int u32;/**< used for unsigned 32bit */ -typedef unsigned long int u64;/**< used for unsigned 64bit */ -#define BMP280_64BITSUPPORT_PRESENT - -#else -#warning The data types defined above which not supported \ -define the data types manually -#endif -#endif -#endif -/********************************************/ -/**\name ENABLE FLATING OUTPUT */ -/**************************************/ -/*! -* @brief If the user wants to support floating point calculations, please set -* the following define. If floating point calculation is not wanted -* or allowed (e.g. in Linux kernel), please do not set the definition. -*/ -#define BMP280_ENABLE_FLOAT - -/*! -* @brief If the user wants to support 64 bit integer calculation (needed for -* optimal pressure accuracy) please set the following definition. If -* int64 calculation is not wanted (e.g. because it would include -* large libraries), please do not set the definition. -*/ -#define BMP280_ENABLE_INT64 -/***************************************************************/ -/**\name BUS READ AND WRITE FUNCTION POINTERS */ -/***************************************************************/ -/*! - @brief Define the calling convention of YOUR bus communication routine. - @note This includes types of parameters. This example shows the - configuration for an SPI bus link. - - If your communication function looks like this: - - write_my_bus_xy(u8 device_addr, u8 register_addr, - u8 * data, u8 length); - - The BMP280_WR_FUNC_PTR would equal: - - BMP280_WR_FUNC_PTR s8 (* bus_write)(u8, - u8, u8 *, u8) - - Parameters can be mixed as needed refer to the - refer BMP280_BUS_WRITE_FUNC macro. - - -*/ -/* defines the return parameter type of the BMP280_WR_FUNCTION */ -#define BMP280_BUS_WR_RETURN_TYPE s8 - -/* links the order of parameters defined in -BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ -#define BMP280_BUS_WR_PARAM_TYPES u8, u8,\ - u8 *, u8 - -/* links the order of parameters defined in -BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ -#define BMP280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\ - register_data, wr_len) - -/* never change this line */ -#define BMP280_BUS_WRITE_FUNC(device_addr, register_addr,\ -register_data, wr_len) bus_write(device_addr, register_addr,\ - register_data, wr_len) -/*! - @brief link macro between API function calls and bus read function - @note The bus write function can change since this is a - system dependant issue. - - If the bus_read parameter calling order is like: reg_addr, - reg_data, wr_len it would be as it is here. - - If the parameters are differently ordered or your communication - function like I2C need to know the device address, - you can change this macro accordingly. - - - BMP280_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ - bus_read(dev_addr, reg_addr, reg_data, wr_len) - - This macro lets all API functions call YOUR communication routine in a - way that equals your definition in the - refer BMP280_WR_FUNC_PTR definition. - - @note: this macro also includes the "MSB='1' - for reading BMP280 addresses. - -*/ -/* defines the return parameter type of the BMP280_RD_FUNCTION -*/ -#define BMP280_BUS_RD_RETURN_TYPE s8 - -/* defines the calling parameter types of the BMP280_RD_FUNCTION -*/ -#define BMP280_BUS_RD_PARAM_TYPES (u8, u8,\ - u8 *, u8) - -/* links the order of parameters defined in \ -BMP280_BUS_RD_PARAM_TYPE to function calls used inside the API -*/ -#define BMP280_BUS_RD_PARAM_ORDER (device_addr, register_addr,\ - register_data) - -/* never change this line */ -#define BMP280_BUS_READ_FUNC(device_addr, register_addr,\ - register_data, rd_len)bus_read(device_addr, register_addr,\ - register_data, rd_len) -/****************************************/ -/**\name DELAY */ -/****************************************/ -/*! -* @brief defines the return parameter type of the BMP280_DELAY_FUNCTION -*/ -#define BMP280_DELAY_RETURN_TYPE void - -/*! -* @brief defines the calling parameter types of the BMP280_DELAY_FUNCTION -*/ -#define BMP280_DELAY_PARAM_TYPES u16 -/***************************************************************/ -/**\name GET AND SET BITSLICE FUNCTIONS */ -/***************************************************************/ -/* never change this line */ -#define BMP280_DELAY_FUNC(delay_in_msec)\ - delay_func(delay_in_msec) - -#define BMP280_GET_BITSLICE(regvar, bitname)\ - ((regvar & bitname##__MSK) >> bitname##__POS) - -#define BMP280_SET_BITSLICE(regvar, bitname, val)\ - ((regvar & ~bitname##__MSK) | ((val< Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280); -/**************************************************************/ -/**\name FUNCTION FOR READ UNCOMPENSATED TEMPERATURE */ -/**************************************************************/ -/*! - * @brief This API is used to read uncompensated temperature - * in the registers 0xFA, 0xFB and 0xFC - * @note 0xFA -> MSB -> bit from 0 to 7 - * @note 0xFB -> LSB -> bit from 0 to 7 - * @note 0xFC -> LSB -> bit from 4 to 7 - * - * @param v_uncomp_temperature_s32 : The uncompensated temperature. - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_temperature( -s32 *v_uncomp_temperature_s32); -/**************************************************************/ -/**\name FUNCTION FOR READ TRUE TEMPERATURE S32 OUTPUT */ -/**************************************************************/ -/*! - * @brief Reads actual temperature - * from uncompensated temperature - * @note Returns the value in 0.01 degree Centigrade - * @note Output value of "5123" equals 51.23 DegC. - * - * - * - * @param v_uncomp_temperature_s32 : value of uncompensated temperature - * - * - * - * @return Actual temperature output as s32 - * -*/ -s32 bmp280_compensate_T_int32(s32 v_uncomp_temperature_s32); -/**************************************************************/ -/**\name FUNCTION FOR READ UNCOMPENSATED PRESSURE */ -/**************************************************************/ -/*! - * @brief This API is used to read uncompensated pressure. - * in the registers 0xF7, 0xF8 and 0xF9 - * @note 0xF7 -> MSB -> bit from 0 to 7 - * @note 0xF8 -> LSB -> bit from 0 to 7 - * @note 0xF9 -> LSB -> bit from 4 to 7 - * - * - * - * @param v_uncomp_pressure_s32 : The value of uncompensated pressure - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure( -s32 *v_uncomp_pressure_s32); -/**************************************************************/ -/**\name FUNCTION FOR READ TRUE PRESSURE S32 OUTPUT */ -/**************************************************************/ -/*! - * @brief Reads actual pressure from uncompensated pressure - * and returns the value in Pascal(Pa) - * @note Output value of "96386" equals 96386 Pa = - * 963.86 hPa = 963.86 millibar - * - * - * - * - * @param v_uncomp_pressure_s32: value of uncompensated pressure - * - * - * - * @return Returns the Actual pressure out put as s32 - * -*/ -u32 bmp280_compensate_P_int32(s32 v_uncomp_pressure_s32); -/**************************************************************/ -/**\name FUNCTION FOR READ UNCOMPENSATED TEMPERATURE AND PRESSURE */ -/**************************************************************/ -/*! - * @brief reads uncompensated pressure and temperature - * - * - * @param v_uncomp_pressure_s32: The value of uncompensated pressure. - * @param v_uncomp_temperature_s32: The value of uncompensated temperature. - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure_temperature( -s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32); -/**************************************************************/ -/**\name FUNCTION FOR READ TRUE TEMPERATURE AND PRESSURE */ -/**************************************************************/ -/*! - * @brief This API reads the true pressure and temperature - * - * - * @param v_pressure_u32 : The value of compensated pressure. - * @param v_temperature_s32 : The value of compensated temperature. - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_pressure_temperature( -u32 *v_pressure_u32, s32 *v_pressure_s32); -/**************************************************************/ -/**\name FUNCTION FOR READ CALIBRATION DATA */ -/**************************************************************/ -/*! - * @brief This API is used to - * calibration parameters used for calculation in the registers - * - * parameter | Register address | bit - *------------|------------------|---------------- - * dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15 - * dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15 - * dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15 - * dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15 - * dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15 - * dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15 - * dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15 - * dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15 - * dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15 - * dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15 - * dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15 - * dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15 - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_calib_param(void); -/**************************************************************/ -/**\name FUNCTION FOR OVERSAMPLING TEMPERATURE AND PRESSURE */ -/**************************************************************/ -/*! - * @brief This API is used to get - * the temperature oversampling setting in the register 0xF4 - * bits from 5 to 7 - * - * value | Temperature oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 :The value of temperature over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_temperature(u8 *v_value_u8); -/*! - * @brief This API is used to set - * the temperature oversampling setting in the register 0xF4 - * bits from 5 to 7 - * - * value | Temperature oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 :The value of temperature over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_temperature(u8 v_value_u8); -/*! - * @brief This API is used to get - * the pressure oversampling setting in the register 0xF4 - * bits from 2 to 4 - * - * value | Pressure oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 : The value of pressure over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_pressure(u8 *v_value_u8); -/*! - * @brief This API is used to set - * the pressure oversampling setting in the register 0xF4 - * bits from 2 to 4 - * - * value | Pressure oversampling - * ------------------------|------------------------------ - * 0x00 | Skipped - * 0x01 | BMP280_OVERSAMP_1X - * 0x02 | BMP280_OVERSAMP_2X - * 0x03 | BMP280_OVERSAMP_4X - * 0x04 | BMP280_OVERSAMP_8X - * 0x05,0x06 and 0x07 | BMP280_OVERSAMP_16X - * - * - * @param v_value_u8 : The value of pressure over sampling - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_pressure(u8 v_value_u8); -/**************************************************************/ -/**\name FUNCTION FOR POWER MODE */ -/**************************************************************/ -/*! - * @brief This API used to get the - * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 - * - * - * - * @param v_power_mode_u8 : The value of power mode value - * value | Power mode - * ------------------|------------------ - * 0x00 | BMP280_SLEEP_MODE - * 0x01 and 0x02 | BMP280_FORCED_MODE - * 0x03 | BMP280_NORMAL_MODE - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_power_mode(u8 *v_power_mode_u8); -/*! - * @brief This API used to set the - * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 - * - * - * - * @param v_power_mode_u8 : The value of power mode value - * value | Power mode - * ------------------|------------------ - * 0x00 | BMP280_SLEEP_MODE - * 0x01 and 0x02 | BMP280_FORCED_MODE - * 0x03 | BMP280_NORMAL_MODE - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_power_mode(u8 v_power_mode_u8); -/**************************************************************/ -/**\name FUNCTION FOR SOFT RESET */ -/**************************************************************/ -/*! - * @brief Used to reset the sensor - * The value 0xB6 is written to the 0xE0 register the device is reset using the - * complete power-on-reset procedure. - * Softreset can be easily set using bmp280_set_softreset(). - * - * @note Usage Hint : bmp280_set_softreset() - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_soft_rst(void); -/**************************************************************/ -/**\name FUNCTION FOR SPI ENABLE */ -/**************************************************************/ -/*! - * @brief This API used to get the sensor - * SPI mode(communication type) in the register 0xF5 bit 0 - * - * - * - * @param v_enable_disable_u8 : The spi3 enable or disable state - * value | Description - * -----------|--------------- - * 0 | Disable - * 1 | Enable - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_spi3(u8 *v_enable_disable_u8); -/*! - * @brief This API used to set the sensor - * SPI mode(communication type) in the register 0xF5 bit 0 - * - * - * - * @param v_enable_disable_u8 : The spi3 enable or disable state - * value | Description - * -----------|--------------- - * 0 | Disable - * 1 | Enable - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_spi3(u8 v_enable_disable_u8); -/**************************************************************/ -/**\name FUNCTION FOR IIR FILTER SETTING */ -/**************************************************************/ -/*! - * @brief This API is used to reads filter setting - * in the register 0xF5 bit 3 and 4 - * - * - * - * @param v_value_u8 : The value of filter coefficient - * value | Filter coefficient - * -------------|------------------------- - * 0x00 | BMP280_FILTER_COEFF_OFF - * 0x01 | BMP280_FILTER_COEFF_2 - * 0x02 | BMP280_FILTER_COEFF_4 - * 0x03 | BMP280_FILTER_COEFF_8 - * 0x04 | BMP280_FILTER_COEFF_16 - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_filter(u8 *v_value_u8); -/*! - * @brief This API is used to write filter setting - * in the register 0xF5 bit 3 and 4 - * - * - * - * @param v_value_u8 : The value of filter coefficient - * value | Filter coefficient - * -------------|------------------------- - * 0x00 | BMP280_FILTER_COEFF_OFF - * 0x01 | BMP280_FILTER_COEFF_2 - * 0x02 | BMP280_FILTER_COEFF_4 - * 0x03 | BMP280_FILTER_COEFF_8 - * 0x04 | BMP280_FILTER_COEFF_16 - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_filter(u8 v_value_u8); -/**************************************************************/ -/**\name FUNCTION FOR STANDBY DURATION */ -/**************************************************************/ -/*! - * @brief This API used to Read the - * standby duration time from the sensor in the register 0xF5 bit 5 to 7 - * - * @param v_standby_durn_u8 : The standby duration time value. - * value | standby duration - * -----------|-------------------- - * 0x00 | BMP280_STANDBYTIME_1_MS - * 0x01 | BMP280_STANDBYTIME_63_MS - * 0x02 | BMP280_STANDBYTIME_125_MS - * 0x03 | BMP280_STANDBYTIME_250_MS - * 0x04 | BMP280_STANDBYTIME_500_MS - * 0x05 | BMP280_STANDBYTIME_1000_MS - * 0x06 | BMP280_STANDBYTIME_2000_MS - * 0x07 | BMP280_STANDBYTIME_4000_MS - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_standby_durn(u8 *v_standby_durn_u8); -/*! - * @brief This API used to Read the - * standby duration time from the sensor in the register 0xF5 bit 5 to 7 - * @note Normal mode comprises an automated perpetual cycling between an (active) - * Measurement period and an (inactive) standby period. - * @note The standby time is determined by the contents of the register t_sb. - * Standby time can be set using BME280_STANDBYTIME_125_MS. - * - * @note bme280_set_standby_durN(BME280_STANDBYTIME_125_MS) - * - * - * - * @param v_standby_durn_u8 : The standby duration time value. - * value | standby duration - * -----------|-------------------- - * 0x00 | BMP280_STANDBYTIME_1_MS - * 0x01 | BMP280_STANDBYTIME_63_MS - * 0x02 | BMP280_STANDBYTIME_125_MS - * 0x03 | BMP280_STANDBYTIME_250_MS - * 0x04 | BMP280_STANDBYTIME_500_MS - * 0x05 | BMP280_STANDBYTIME_1000_MS - * 0x06 | BMP280_STANDBYTIME_2000_MS - * 0x07 | BMP280_STANDBYTIME_4000_MS - * - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_standby_durn(u8 v_standby_durn_u8); -/**************************************************************/ -/**\name FUNCTION FOR WORK MODE */ -/**************************************************************/ -/*! - * @brief This API is used to write - * the working mode of the sensor - * - * - * @param v_work_mode_u8 : The value of work mode - * value | mode - * -------------|------------- - * 0 | BMP280_ULTRA_LOW_POWER_MODE - * 1 | BMP280_LOW_POWER_MODE - * 2 | BMP280_STANDARD_RESOLUTION_MODE - * 3 | BMP280_HIGH_RESOLUTION_MODE - * 4 | BMP280_ULTRA_HIGH_RESOLUTION_MODE - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_work_mode(u8 v_work_mode_u8); -/**************************************************************/ -/**\name FUNCTION FOR FORCE MODE READING */ -/**************************************************************/ -/*! - * @brief This API used to read both - * uncompensated pressure and temperature in forced mode - * - * - * @param v_uncomp_pressure_s32: The value of uncompensated pressure. - * @param v_uncomp_temperature_s32: The value of uncompensated temperature - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * -*/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_forced_uncomp_pressure_temperature( -s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32); -/**************************************************************/ -/**\name FUNCTION FOR COMMON READ AND WRITE */ -/**************************************************************/ -/*! - * @brief - * This API write the data to - * the given register - * - * - * @param v_addr_u8 -> Address of the register - * @param v_data_u8 -> The data from the register - * @param v_len_u8 -> no of bytes to read - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * - */ -BMP280_RETURN_FUNCTION_TYPE bmp280_write_register(u8 v_addr_u8, -u8 *v_data_u8, u8 v_len_u8); -/*! - * @brief - * This API reads the data from - * the given register - * - * - * @param v_addr_u8 -> Address of the register - * @param v_data_u8 -> The data from the register - * @param v_len_u8 -> no of bytes to read - * - * - * @return results of bus communication function - * @retval 0 -> Success - * @retval -1 -> Error - * - * - */ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_register(u8 v_addr_u8, -u8 *v_data_u8, u8 v_len_u8); -/**************************************************************/ -/**\name FUNCTION FOR TRUE TEMPERATURE CALCULATION */ -/**************************************************************/ -#ifdef BMP280_ENABLE_FLOAT -/*! - * @brief This API used to read - * actual temperature from uncompensated temperature - * @note Returns the value in Degree centigrade - * @note Output value of "51.23" equals 51.23 DegC. - * - * - * - * @param v_uncomp_temperature_s32 : value of uncompensated temperature - * - * - * - * @return - * Actual temperature in floating point - * -*/ -double bmp280_compensate_T_double(s32 v_uncomp_temperature_s32); -/**************************************************************/ -/**\name FUNCTION FOR TRUE PRESSURE CALCULATION */ -/**************************************************************/ -/*! - * @brief Reads actual pressure from uncompensated pressure - * and returns pressure in Pa as double. - * @note Output value of "96386.2" - * equals 96386.2 Pa = 963.862 hPa. - * - * - * - * @param v_uncomp_pressure_s32 : value of uncompensated pressure - * - * - * - * @return - * Actual pressure in floating point - * -*/ -double bmp280_compensate_P_double(s32 v_uncomp_pressure_s32); -#endif -#if defined(BMP280_ENABLE_INT64) && defined(BMP280_64BITSUPPORT_PRESENT) -/*! - * @brief This API used to read actual pressure from uncompensated pressure - * @note returns the value in Pa as unsigned 32 bit - * integer in Q24.8 format (24 integer bits and - * 8 fractional bits). Output value of "24674867" - * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa - * - * - * - * @param v_uncomp_pressure_s32 : value of uncompensated pressure - * - * - * - * @return actual pressure as 64bit output - * -*/ -u32 bmp280_compensate_P_int64(s32 v_uncomp_pressure_s32); -#endif -/**************************************************************/ -/**\name FUNCTION FOR DELAY CALCULATION DURING FORCEMODE */ -/**************************************************************/ -/*! - * @brief Computing waiting time for sensor data read - * - * - * - * - * @param v_delaytime_u8r: The value of delay time - * - * - * @return 0 - * - * - */ -BMP280_RETURN_FUNCTION_TYPE bmp280_compute_wait_time(u8 -*v_delaytime_u8r); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/processes/click_reader/include/bmp280_support.h b/processes/click_reader/include/bmp280_support.h deleted file mode 100644 index 57774e3..0000000 --- a/processes/click_reader/include/bmp280_support.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef BMP280_SUPPORT_H -#define BMP280_SUPPORT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "bmp280.h" - -s32 bmp280_data_readout_template(void); -s32 bmp280_read_temperature(void); -s64 bmp280_read_pressure(void); -s8 bmp280_init_my(void); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/processes/click_reader/include/spi.h b/processes/click_reader/include/spi.h deleted file mode 100644 index 822a61d..0000000 --- a/processes/click_reader/include/spi.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SPI_H -#define SPI_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define SPI_SPEED 20000000 // 20MHz -#define SPI_MODE 0 -#define SPI_BITS_PER_WORD 8 - -int spi_init(); - -int spi_transfer(int chip_select, unsigned char* tx_data, unsigned char* rx_data, int len, int leave_cs_low); - -int spi_close(); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/processes/click_reader/main.cpp b/processes/click_reader/main.cpp index d528317..9e2b188 100644 --- a/processes/click_reader/main.cpp +++ b/processes/click_reader/main.cpp @@ -1,6 +1,7 @@ // Standard #include #include +#include // Pipes #include @@ -12,24 +13,29 @@ #include #include #include +#include // Local #include "pipe_def.h" #include "util.h" -#include "spi.h" -#include "bmp280_support.h" - static std::shared_ptr logger; int main(int argc, char* argv[]) { + logger = spdlog::stdout_color_mt("click_reader"); logger->set_level(CLICK_LOGLEVEL); - logger->debug("Opening sendpipe for writing"); + logger->debug("Opening sendpipe for writing."); pipe_fd_t sendpipe_fd = open(SEND_PIPE, O_WRONLY); + if (!bcm2835_init()) + { + logger->error("bcm2835_init failed. Are you running as root?"); + return 1; + } + /* mavlink_message_t message; const uint8_t system_id = 42; @@ -60,23 +66,14 @@ int main(int argc, char* argv[]) } */ - logger->info("Initializing Click devices"); - spi_init(); + logger->info("Initializing serial communication!"); - THREAD_SLEEP(1s); - //c6dofimu17::init(logger); - //pressure4::init(logger); - bmp280_init_my(); - THREAD_SLEEP(1s); while (true) { - printf("pressure: %d\n", bmp280_read_pressure() / 256); - THREAD_SLEEP(50ms); - printf("Temp: %d\n", bmp280_read_temperature()); - THREAD_SLEEP(50ms); + THREAD_SLEEP(1s); } logger->error("here"); close(sendpipe_fd); return 0; -} +} \ No newline at end of file diff --git a/processes/click_reader/spi.c b/processes/click_reader/spi.c deleted file mode 100644 index e8dde83..0000000 --- a/processes/click_reader/spi.c +++ /dev/null @@ -1,151 +0,0 @@ -#include "spi.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int spi_fd_0 = -1; -static int spi_fd_1 = -1; - -unsigned char spi_mode = SPI_MODE; -unsigned char spi_bits_per_word = SPI_BITS_PER_WORD; -unsigned int spi_speed = SPI_SPEED; - -int spi_init() -{ - if (spi_fd_0 != -1 || spi_fd_1 != -1) - { - printf("At least one SPI device (CS) already initialized, exiting..."); - return 0; - } - - spi_fd_0 = open("/dev/spidev0.0", O_RDWR); - spi_fd_1 = open("/dev/spidev0.1", O_RDWR); - - int ret; - - int spi_fd_arr[] = {spi_fd_0, spi_fd_1}; - int spi_fd; - - for (int i = 0; i < 2; i++) - { - spi_fd = spi_fd_arr[i]; - // Check if SPI device is available - if (spi_fd < 0) - { - printf("Could not open SPI device"); - return -1; - } - - // Set SPI mode WR - ret = ioctl(spi_fd, SPI_IOC_WR_MODE, &spi_mode); - if (ret < 0) - { - printf("Could not set SPIMode (WR)...ioctl fail"); - return -1; - } - - // Set SPI mode RD - ret = ioctl(spi_fd, SPI_IOC_RD_MODE, &spi_mode); - if (ret < 0) - { - printf("Could not set SPIMode (RD)...ioctl fail"); - return -1; - } - - // Set SPI bits per word WR - ret = ioctl(spi_fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits_per_word); - if(ret < 0) - { - printf("Could not set SPI bitsPerWord (WR)...ioctl fail"); - return -1; - } - - // Set SPI bits per word RD - ret = ioctl(spi_fd, SPI_IOC_RD_BITS_PER_WORD, &spi_bits_per_word); - if(ret < 0) - { - printf("Could not set SPI bitsPerWord(RD)...ioctl fail"); - return -1; - } - - // Set SPI speed WR - ret = ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed); - if(ret < 0) - { - printf("Could not set SPI speed (WR)...ioctl fail"); - return -1; - } - - // Set SPI speed RD - ret = ioctl(spi_fd, SPI_IOC_RD_MAX_SPEED_HZ, &spi_speed); - if(ret < 0) - { - printf("Could not set SPI speed (RD)...ioctl fail"); - return -1; - } - } - - return 0; -} - -int spi_transfer(int chip_select, unsigned char* tx_data, unsigned char* rx_data, int len, int leave_cs_low) -{ - struct spi_ioc_transfer spi; - memset (&spi, 0, sizeof(spi)); - int ret = -1; - int spi_fd; - - if (chip_select) - spi_fd = spi_fd_1; - else - spi_fd = spi_fd_0; - - spi.tx_buf = (unsigned long) tx_data; - spi.rx_buf = (unsigned long) rx_data; - spi.len = len; - spi.delay_usecs = 0; - spi.speed_hz = spi_speed; - spi.bits_per_word = spi_bits_per_word; - spi.cs_change = leave_cs_low; - - ret = ioctl(spi_fd, SPI_IOC_MESSAGE(1), &spi); - - if(ret < 0) - { - printf("Problem transmitting spi data..ioctl"); - return -1; - } - - return ret; -} - -int spi_close() -{ - int ret; - - ret = close(spi_fd_0); - if(ret < 0) - { - printf("Could not close SPI device {}", spi_fd_0); - return -1; - } - - ret = close(spi_fd_1); - if(ret < 0) - { - printf("Could not close SPI device {}", spi_fd_1); - return -1; - } - - return 0; -} \ No newline at end of file