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

drivers/isl29020: Acquire exclusive access ti I2C bus

This commit is contained in:
PeterKietzmann 2015-01-29 10:15:27 +01:00
parent 9c3a89edbf
commit dcd70c807b
9 changed files with 15 additions and 8 deletions

View File

@ -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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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