1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/mag3110: adapt to new I2C api

This commit is contained in:
Alexandre Abadie 2018-06-07 23:44:41 +02:00 committed by dylad
parent 93fc27b93b
commit f113f93ca8

View File

@ -35,8 +35,6 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
#define I2C_SPEED I2C_SPEED_FAST
#define BUS (dev->params.i2c)
#define ADDR (dev->params.addr)
@ -51,14 +49,8 @@ int mag3110_init(mag3110_t *dev, const mag3110_params_t *params)
memcpy(dev, params, sizeof(mag3110_params_t));
i2c_acquire(BUS);
/* initialize the I2C bus */
if (i2c_init_master(BUS, I2C_SPEED) < 0) {
i2c_release(BUS);
LOG_ERROR("mag3110_init: failed!\n");
return -MAG3110_ERROR_I2C;
}
/* test device */
i2c_read_regs(BUS, ADDR, MAG3110_WHO_AM_I, &reg, 1);
i2c_read_regs(BUS, ADDR, MAG3110_WHO_AM_I, &reg, 1, 0);
if (reg != dev->params.type) {
i2c_release(BUS);
LOG_ERROR("mag3110_init: invalid WHO_AM_I value (0x%02x)!\n", (int)reg);
@ -66,26 +58,26 @@ int mag3110_init(mag3110_t *dev, const mag3110_params_t *params)
}
/* enable automatic magnetic sensor reset */
reg = MAG3110_CTRL_REG2_AUTO_MRST_EN;
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG2, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG2, &reg, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mag3110_init: failed to enable auto reset!\n");
return -MAG3110_ERROR_CNF;
}
/* set sample rate */
reg = MAG3110_CTRL_REG1_DROS(dev->params.dros);
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mag3110_init: failed to set sample rate!\n");
return -MAG3110_ERROR_CNF;
}
/* set device active */
if (i2c_read_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mag3110_init: failed to read device state!\n");
return -MAG3110_ERROR_I2C;
}
reg |= MAG3110_CTRL_REG1_AC;
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mag3110_init: failed to set device active!\n");
return -MAG3110_ERROR_CNF;
@ -113,7 +105,7 @@ int mag3110_set_user_offset(const mag3110_t *dev, int16_t x, int16_t y, int16_t
(int)x, (int)y, (int)z);
i2c_acquire(BUS);
if (i2c_write_regs(BUS, ADDR, MAG3110_OFF_X_MSB, buf, 6) != 6) {
if (i2c_write_regs(BUS, ADDR, MAG3110_OFF_X_MSB, buf, 6, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mag3110_set_user_offset: failed to set offsets!\n");
return -MAG3110_ERROR_I2C;
@ -130,14 +122,14 @@ int mag3110_set_active(const mag3110_t *dev)
assert(dev);
i2c_acquire(BUS);
if (i2c_read_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MAG3110_ERROR_I2C;
}
reg |= MAG3110_CTRL_REG1_AC;
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MAG3110_ERROR_I2C;
}
@ -153,14 +145,14 @@ int mag3110_set_standby(const mag3110_t *dev)
assert(dev);
i2c_acquire(BUS);
if (i2c_read_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MAG3110_ERROR_I2C;
}
reg &= ~MAG3110_CTRL_REG1_AC;
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1) != 1) {
if (i2c_write_regs(BUS, ADDR, MAG3110_CTRL_REG1, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MAG3110_ERROR_I2C;
}
@ -176,7 +168,7 @@ int mag3110_is_ready(const mag3110_t *dev)
assert(dev);
i2c_acquire(BUS);
if (i2c_read_regs(BUS, ADDR, MAG3110_DR_STATUS, &reg, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MAG3110_DR_STATUS, &reg, 1, 0) < 0) {
i2c_release(BUS);
return -MAG3110_ERROR_I2C;
}
@ -192,7 +184,7 @@ int mag3110_read(const mag3110_t *dev, mag3110_data_t *data)
assert(dev);
i2c_acquire(BUS);
if (i2c_read_regs(BUS, ADDR, MAG3110_DR_STATUS, buf, 7) != 7) {
if (i2c_read_regs(BUS, ADDR, MAG3110_DR_STATUS, buf, 7, 0) < 0) {
i2c_release(BUS);
return -MAG3110_ERROR_I2C;
}
@ -212,7 +204,7 @@ int mag3110_read_dtemp(const mag3110_t *dev, int8_t *dtemp)
assert(dev);
i2c_acquire(BUS);
if (i2c_read_regs(BUS, ADDR, MAG3110_DIE_TEMP, dtemp, 1) != 1) {
if (i2c_read_regs(BUS, ADDR, MAG3110_DIE_TEMP, dtemp, 1, 0) < 0) {
i2c_release(BUS);
return -MAG3110_ERROR_I2C;
}