Browse Source

drivers/isl29020: Acquire exclusive access ti I2C bus

dev/timer
PeterKietzmann 8 years ago
parent
commit
dcd70c807b
  1. 15
      drivers/isl29020/isl29020.c
  2. 1
      drivers/l3g4200d/l3g4200d.c
  3. 1
      drivers/lps331ap/lps331ap.c
  4. 1
      drivers/lsm303dlhc/lsm303dlhc.c
  5. 1
      drivers/mag3110/mag3110.c
  6. 1
      drivers/mma8652/mma8652.c
  7. 1
      drivers/mpl3115a2/mpl3115a2.c
  8. 1
      drivers/srf02/srf02.c
  9. 1
      drivers/tmp006/tmp006.c

15
drivers/isl29020/isl29020.c

@ -14,6 +14,7 @@
* @brief Device driver implementation for the ISL29020 light sensor
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
*
* @}
*/
@ -36,12 +37,16 @@ int isl29020_init(isl29020_t *dev, i2c_t i2c, uint8_t address,
dev->address = address;
dev->lux_fac = (float)((1 << (10 + (2 * range))) - 1) / 0xffff;
/* Acquire exclusive access to the bus. */
i2c_acquire(dev->i2c);
/* initialize the I2C bus */
i2c_init_master(i2c, I2C_SPEED_NORMAL);
/* configure and enable the sensor */
tmp = ISL29020_CMD_EN | ISL29020_CMD_MODE | ISL29020_RES_INT_16 | range | (mode << 5);
res = i2c_write_reg(dev->i2c, address, ISL29020_REG_CMD, tmp);
/* Release the bus for other threads. */
i2c_release(dev->i2c);
if (res < 1) {
return -1;
}
@ -53,9 +58,11 @@ int isl29020_read(isl29020_t *dev)
char low, high;
uint16_t res;
i2c_acquire(dev->i2c);
/* read lightning value */
res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low);
res += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high);
i2c_release(dev->i2c);
if (res < 2) {
return -1;
}
@ -70,15 +77,19 @@ int isl29020_enable(isl29020_t *dev)
int res;
char tmp;
i2c_acquire(dev->i2c);
res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_CMD, &tmp);
if (res < 1) {
i2c_release(dev->i2c);
return -1;
}
tmp |= ISL29020_CMD_EN;
res = i2c_write_reg(dev->i2c, dev->address, ISL29020_REG_CMD, tmp);
if (res < 1) {
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
return 0;
}
@ -87,14 +98,18 @@ int isl29020_disable(isl29020_t *dev)
int res;
char tmp;
i2c_acquire(dev->i2c);
res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_CMD, &tmp);
if (res < 1) {
i2c_release(dev->i2c);
return -1;
}
tmp &= ~(ISL29020_CMD_EN);
res = i2c_write_reg(dev->i2c, dev->address, ISL29020_REG_CMD, tmp);
if (res < 1) {
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
return 0;
}

1
drivers/l3g4200d/l3g4200d.c

@ -21,7 +21,6 @@
#include <stdint.h>
#include "mutex.h"
#include "l3g4200d.h"
#include "l3g4200d-regs.h"
#include "periph/i2c.h"

1
drivers/lps331ap/lps331ap.c

@ -25,7 +25,6 @@
#include <stdint.h>
#include "mutex.h"
#include "periph/i2c.h"
#include "lps331ap.h"
#include "lps331ap-internal.h"

1
drivers/lsm303dlhc/lsm303dlhc.c

@ -19,7 +19,6 @@
* @}
*/
#include "mutex.h"
#include "lsm303dlhc.h"
#include "lsm303dlhc-internal.h"

1
drivers/mag3110/mag3110.c

@ -22,7 +22,6 @@
#include <stdint.h>
#include <stdbool.h>
#include "mutex.h"
#include "periph/i2c.h"
#include "mag3110.h"
#include "mag3110_reg.h"

1
drivers/mma8652/mma8652.c

@ -22,7 +22,6 @@
#include <stdint.h>
#include <stdbool.h>
#include "mutex.h"
#include "periph/i2c.h"
#include "mma8652.h"
#include "mma8652_reg.h"

1
drivers/mpl3115a2/mpl3115a2.c

@ -22,7 +22,6 @@
#include <stdint.h>
#include <stdbool.h>
#include "mutex.h"
#include "periph/i2c.h"
#include "mpl3115a2.h"
#include "mpl3115a2_reg.h"

1
drivers/srf02/srf02.c

@ -23,7 +23,6 @@
#include <stdint.h>
#include <stdio.h>
#include "mutex.h"
#include "hwtimer.h"
#include "srf02.h"
#include "periph/i2c.h"

1
drivers/tmp006/tmp006.c

@ -23,7 +23,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "mutex.h"
#include "periph/i2c.h"
#include "tmp006.h"

Loading…
Cancel
Save