mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers: bmx280: adapt to new I2C api.
This commit is contained in:
parent
78c5b46eac
commit
76b1200460
@ -71,12 +71,6 @@ int bmx280_init(bmx280_t* dev, const bmx280_params_t* params)
|
||||
|
||||
dev->params = *params;
|
||||
|
||||
/* Initialize I2C interface */
|
||||
if (i2c_init_master(dev->params.i2c_dev, I2C_SPEED_NORMAL)) {
|
||||
DEBUG("[Error] I2C device not enabled\n");
|
||||
return BMX280_ERR_I2C;
|
||||
}
|
||||
|
||||
/* Read chip ID */
|
||||
chip_id = read_u8_reg(dev, BMX280_CHIP_ID_REG);
|
||||
if ((chip_id != BME280_CHIP_ID) && (chip_id != BMP280_CHIP_ID)) {
|
||||
@ -216,7 +210,7 @@ uint16_t bme280_read_humidity(const bmx280_t *dev)
|
||||
static int read_calibration_data(bmx280_t* dev)
|
||||
{
|
||||
uint8_t buffer[128]; /* 128 should be enough to read all calibration bytes */
|
||||
int nr_bytes;
|
||||
int result;
|
||||
#ifdef MODULE_BME280
|
||||
int nr_bytes_to_read = (BME280_DIG_H6_REG - BMX280_DIG_T1_LSB_REG) + 1;
|
||||
#else
|
||||
@ -225,13 +219,15 @@ static int read_calibration_data(bmx280_t* dev)
|
||||
uint8_t offset = 0x88;
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
nr_bytes = i2c_read_regs(dev->params.i2c_dev, dev->params.i2c_addr, offset,
|
||||
buffer, nr_bytes_to_read);
|
||||
if (nr_bytes != nr_bytes_to_read) {
|
||||
i2c_acquire(dev->params.i2c_dev);
|
||||
result = i2c_read_regs(dev->params.i2c_dev, dev->params.i2c_addr, offset,
|
||||
buffer, nr_bytes_to_read, 0);
|
||||
i2c_release(dev->params.i2c_dev);
|
||||
if (result != 0) {
|
||||
LOG_ERROR("Unable to read calibration data\n");
|
||||
return -1;
|
||||
}
|
||||
DUMP_BUFFER("Raw Calibration Data", buffer, nr_bytes);
|
||||
DUMP_BUFFER("Raw Calibration Data", buffer, nr_bytes_to_read);
|
||||
|
||||
/* All little endian */
|
||||
dev->calibration.dig_T1 = get_uint16_le(buffer, BMX280_DIG_T1_LSB_REG - offset);
|
||||
@ -261,9 +257,11 @@ static int read_calibration_data(bmx280_t* dev)
|
||||
|
||||
DEBUG("[INFO] Chip ID = 0x%02X\n", buffer[BMX280_CHIP_ID_REG - offset]);
|
||||
|
||||
/* Config is only be writable in sleep mode */
|
||||
/* Config is only writable in sleep mode */
|
||||
i2c_acquire(dev->params.i2c_dev);
|
||||
(void)i2c_write_reg(dev->params.i2c_dev, dev->params.i2c_addr,
|
||||
BMX280_CTRL_MEAS_REG, 0);
|
||||
BMX280_CTRL_MEAS_REG, 0, 0);
|
||||
i2c_release(dev->params.i2c_dev);
|
||||
|
||||
uint8_t b;
|
||||
|
||||
@ -315,17 +313,19 @@ static int do_measurement(const bmx280_t* dev)
|
||||
}
|
||||
/* What to do when measuring is still on? */
|
||||
}
|
||||
int nr_bytes;
|
||||
int result;
|
||||
int nr_bytes_to_read = sizeof(measurement_regs);
|
||||
uint8_t offset = BMX280_PRESSURE_MSB_REG;
|
||||
|
||||
nr_bytes = i2c_read_regs(dev->params.i2c_dev, dev->params.i2c_addr,
|
||||
offset, measurement_regs, nr_bytes_to_read);
|
||||
if (nr_bytes != nr_bytes_to_read) {
|
||||
i2c_acquire(dev->params.i2c_dev);
|
||||
result = i2c_read_regs(dev->params.i2c_dev, dev->params.i2c_addr,
|
||||
offset, measurement_regs, nr_bytes_to_read, 0);
|
||||
i2c_release(dev->params.i2c_dev);
|
||||
if (result != 0) {
|
||||
LOG_ERROR("Unable to read temperature data\n");
|
||||
return -1;
|
||||
}
|
||||
DUMP_BUFFER("Raw Sensor Data", measurement_regs, nr_bytes);
|
||||
DUMP_BUFFER("Raw Sensor Data", measurement_regs, nr_bytes_to_read);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -344,14 +344,18 @@ static uint8_t read_u8_reg(const bmx280_t* dev, uint8_t reg)
|
||||
{
|
||||
uint8_t b;
|
||||
/* Assuming device is correct, it should return 1 (nr bytes) */
|
||||
(void)i2c_read_reg(dev->params.i2c_dev, dev->params.i2c_addr, reg, &b);
|
||||
i2c_acquire(dev->params.i2c_dev);
|
||||
(void)i2c_read_reg(dev->params.i2c_dev, dev->params.i2c_addr, reg, &b, 0);
|
||||
i2c_release(dev->params.i2c_dev);
|
||||
return b;
|
||||
}
|
||||
|
||||
static void write_u8_reg(const bmx280_t* dev, uint8_t reg, uint8_t b)
|
||||
{
|
||||
/* Assuming device is correct, it should return 1 (nr bytes) */
|
||||
(void)i2c_write_reg(dev->params.i2c_dev, dev->params.i2c_addr, reg, b);
|
||||
i2c_acquire(dev->params.i2c_dev);
|
||||
(void)i2c_write_reg(dev->params.i2c_dev, dev->params.i2c_addr, reg, b, 0);
|
||||
i2c_release(dev->params.i2c_dev);
|
||||
}
|
||||
|
||||
static uint16_t get_uint16_le(const uint8_t *buffer, size_t offset)
|
||||
|
@ -164,9 +164,8 @@ typedef struct {
|
||||
*/
|
||||
enum {
|
||||
BMX280_OK = 0, /**< everything was fine */
|
||||
BMX280_ERR_I2C = -1, /**< error initializing the I2C bus */
|
||||
BMX280_ERR_NODEV = -2, /**< did not detect BME280 or BMP280 */
|
||||
BMX280_ERR_NOCAL = -3, /**< could not read calibration data */
|
||||
BMX280_ERR_NODEV = -1, /**< did not detect BME280 or BMP280 */
|
||||
BMX280_ERR_NOCAL = -2, /**< could not read calibration data */
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user