/* * bmp180_stm32_hw.h * * Created on: 3 окт. 2016 г. * Author: l-pro */ #ifndef BMP180_STM32_HW_H_ #define BMP180_STM32_HW_H_ #include "stm32f4xx_hal.h" extern I2C_HandleTypeDef hi2c3; struct Bmp180Stm32Interface { static void delayUs(uint32_t us){ HAL_Delay((us + 999) / 1000); } static uint8_t read8(uint8_t deviceAddress, uint8_t address) { uint8_t result = 0; HAL_I2C_Master_Transmit(&hi2c3, deviceAddress, &address, 1, HAL_MAX_DELAY); HAL_I2C_Master_Receive(&hi2c3, deviceAddress, &result, 1, HAL_MAX_DELAY); return result; } static void read16(uint8_t deviceAddress, uint8_t address, uint16_t* data) { HAL_I2C_Master_Transmit(&hi2c3, deviceAddress, &address, 1, HAL_MAX_DELAY); HAL_I2C_Master_Receive(&hi2c3, deviceAddress, reinterpret_cast(data), 2, HAL_MAX_DELAY); //swap bytes *data = (((*data) & 0xff) << 8) | (((*data) & 0xff00) >> 8); } static void write8(uint8_t deviceAddress, uint8_t address, uint8_t data){ uint8_t bytes[] = {address, data}; HAL_I2C_Master_Transmit(&hi2c3, deviceAddress, &bytes[0], 2, HAL_MAX_DELAY); } }; #endif /* BMP180_STM32_HW_H_ */