drivers: sensor: vcnl4040: other small improvements
Fixes the double up test of int_gpio.port. Addition of VCNL4040_ALS_INT_EN macros. Use of BIT() macro where it makes sense. MISRA improvements. Signed-off-by: Nick Ward <nick.ward@ftpsolutions.com.au>
This commit is contained in:
parent
3abd63c093
commit
de9a665b31
3 changed files with 39 additions and 41 deletions
|
@ -25,7 +25,7 @@ int vcnl4040_read(const struct device *dev, uint8_t reg, uint16_t *out)
|
|||
ret = i2c_write_read_dt(&config->i2c,
|
||||
®, sizeof(reg), buff, sizeof(buff));
|
||||
|
||||
if (!ret) {
|
||||
if (ret == 0) {
|
||||
*out = sys_get_le16(buff);
|
||||
}
|
||||
|
||||
|
@ -274,11 +274,9 @@ static int vcnl4040_init(const struct device *dev)
|
|||
k_mutex_init(&data->mutex);
|
||||
|
||||
#if CONFIG_VCNL4040_TRIGGER
|
||||
if (config->int_gpio.port) {
|
||||
if (vcnl4040_trigger_init(dev)) {
|
||||
LOG_ERR("Could not initialise interrupts");
|
||||
return -EIO;
|
||||
}
|
||||
if (vcnl4040_trigger_init(dev)) {
|
||||
LOG_ERR("Could not initialise interrupts");
|
||||
return -EIO;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,34 +13,36 @@
|
|||
#include <zephyr/kernel.h>
|
||||
|
||||
/* Registers all 16 bits */
|
||||
#define VCNL4040_REG_ALS_CONF 0x00
|
||||
#define VCNL4040_REG_ALS_THDH 0x01
|
||||
#define VCNL4040_REG_ALS_THDL 0x02
|
||||
#define VCNL4040_REG_PS_CONF 0x03
|
||||
#define VCNL4040_REG_PS_MS 0x04
|
||||
#define VCNL4040_REG_PS_CANC 0x05
|
||||
#define VCNL4040_REG_PS_THDL 0x06
|
||||
#define VCNL4040_REG_PS_THDH 0x07
|
||||
#define VCNL4040_REG_PS_DATA 0x08
|
||||
#define VCNL4040_REG_ALS_DATA 0x09
|
||||
#define VCNL4040_REG_WHITE_DATA 0x0A
|
||||
#define VCNL4040_REG_INT_FLAG 0x0B
|
||||
#define VCNL4040_REG_DEVICE_ID 0x0C
|
||||
#define VCNL4040_REG_ALS_CONF 0x00
|
||||
#define VCNL4040_REG_ALS_THDH 0x01
|
||||
#define VCNL4040_REG_ALS_THDL 0x02
|
||||
#define VCNL4040_REG_PS_CONF 0x03
|
||||
#define VCNL4040_REG_PS_MS 0x04
|
||||
#define VCNL4040_REG_PS_CANC 0x05
|
||||
#define VCNL4040_REG_PS_THDL 0x06
|
||||
#define VCNL4040_REG_PS_THDH 0x07
|
||||
#define VCNL4040_REG_PS_DATA 0x08
|
||||
#define VCNL4040_REG_ALS_DATA 0x09
|
||||
#define VCNL4040_REG_WHITE_DATA 0x0A
|
||||
#define VCNL4040_REG_INT_FLAG 0x0B
|
||||
#define VCNL4040_REG_DEVICE_ID 0x0C
|
||||
|
||||
#define VCNL4040_RW_REG_COUNT 0x08 /* [0x00, 0x07] */
|
||||
#define VCNL4040_RW_REG_COUNT 0x08 /* [0x00, 0x07] */
|
||||
|
||||
#define VCNL4040_DEFAULT_ID 0x0186
|
||||
#define VCNL4040_DEFAULT_ID 0x0186
|
||||
|
||||
#define VCNL4040_LED_I_POS 8
|
||||
#define VCNL4040_PS_HD_POS 11
|
||||
#define VCNL4040_PS_HD_MASK (0x01 << VCNL4040_PS_HD_POS)
|
||||
#define VCNL4040_PS_DUTY_POS 6
|
||||
#define VCNL4040_PS_IT_POS 1
|
||||
#define VCNL4040_PS_SD_POS 0
|
||||
#define VCNL4040_PS_SD_MASK (0x01 << VCNL4040_PS_SD_POS)
|
||||
#define VCNL4040_ALS_IT_POS 6
|
||||
#define VCNL4040_ALS_SD_POS 0
|
||||
#define VCNL4040_ALS_SD_MASK (0x01 << VCNL4040_ALS_SD_POS)
|
||||
#define VCNL4040_LED_I_POS 8
|
||||
#define VCNL4040_PS_HD_POS 11
|
||||
#define VCNL4040_PS_HD_MASK BIT(VCNL4040_PS_HD_POS)
|
||||
#define VCNL4040_PS_DUTY_POS 6
|
||||
#define VCNL4040_PS_IT_POS 1
|
||||
#define VCNL4040_PS_SD_POS 0
|
||||
#define VCNL4040_PS_SD_MASK BIT(VCNL4040_PS_SD_POS)
|
||||
#define VCNL4040_ALS_IT_POS 6
|
||||
#define VCNL4040_ALS_INT_EN_POS 1
|
||||
#define VCNL4040_ALS_INT_EN_MASK BIT(VCNL4040_ALS_INT_EN_POS)
|
||||
#define VCNL4040_ALS_SD_POS 0
|
||||
#define VCNL4040_ALS_SD_MASK BIT(VCNL4040_ALS_SD_POS)
|
||||
|
||||
enum led_current {
|
||||
VCNL4040_LED_CURRENT_50MA,
|
||||
|
|
|
@ -45,7 +45,7 @@ static int vcnl4040_handle_proxy_int(const struct device *dev)
|
|||
.chan = SENSOR_CHAN_PROX,
|
||||
};
|
||||
|
||||
if (data->proxy_handler) {
|
||||
if (data->proxy_handler != NULL) {
|
||||
data->proxy_handler(dev, &proxy_trig);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ static int vcnl4040_handle_als_int(const struct device *dev)
|
|||
.chan = SENSOR_CHAN_LIGHT,
|
||||
};
|
||||
|
||||
if (data->als_handler) {
|
||||
if (data->als_handler != NULL) {
|
||||
data->als_handler(dev, &als_trig);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ int vcnl4040_trigger_set(const struct device *dev,
|
|||
uint16_t conf;
|
||||
int ret = 0;
|
||||
|
||||
if (!config->int_gpio.port) {
|
||||
if (config->int_gpio.port == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -220,8 +220,8 @@ int vcnl4040_trigger_set(const struct device *dev,
|
|||
goto exit;
|
||||
}
|
||||
|
||||
/* Set interrupt enable bit 1 */
|
||||
conf |= 1 << 1;
|
||||
/* ALS interrupt enable */
|
||||
conf |= VCNL4040_ALS_INT_EN_MASK;
|
||||
|
||||
if (vcnl4040_write(dev, VCNL4040_REG_ALS_CONF, conf)) {
|
||||
ret = -EIO;
|
||||
|
@ -256,10 +256,8 @@ int vcnl4040_trigger_init(const struct device *dev)
|
|||
|
||||
data->dev = dev;
|
||||
|
||||
/* dts doesn't have GPIO int pin set, so we dont support
|
||||
* trigger mode for this instance
|
||||
*/
|
||||
if (!config->int_gpio.port) {
|
||||
if (config->int_gpio.port == NULL) {
|
||||
LOG_DBG("instance '%s' doesn't support trigger mode", dev->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -289,7 +287,7 @@ int vcnl4040_trigger_init(const struct device *dev)
|
|||
BIT(config->int_gpio.pin));
|
||||
|
||||
if (gpio_add_callback(config->int_gpio.port, &data->gpio_cb) < 0) {
|
||||
LOG_DBG("Failed to set gpio callback!");
|
||||
LOG_ERR("Failed to set gpio callback");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue