Merge pull request #14653 from Nishchay-sopho/drivers/sdp3x_#14603
driver/sdp3x: Resolved irq pin code used even if irq pin not connected
This commit is contained in:
commit
7e4b3d0f40
@ -105,6 +105,10 @@ ifneq (,$(filter rn2%3,$(USEMODULE)))
|
|||||||
USEMODULE += rn2xx3
|
USEMODULE += rn2xx3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter sdp3x_%,$(USEMODULE)))
|
||||||
|
USEMODULE += sdp3x
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter sht1%,$(USEMODULE)))
|
ifneq (,$(filter sht1%,$(USEMODULE)))
|
||||||
USEMODULE += sht1x
|
USEMODULE += sht1x
|
||||||
endif
|
endif
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
FEATURES_REQUIRED += periph_i2c
|
FEATURES_REQUIRED += periph_i2c
|
||||||
FEATURES_REQUIRED += periph_gpio_irq
|
|
||||||
USEMODULE += checksum
|
USEMODULE += checksum
|
||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
|
|
||||||
|
ifneq (,$(filter sdp3x_irq,$(USEMODULE)))
|
||||||
|
FEATURES_REQUIRED += periph_gpio_irq
|
||||||
|
endif
|
||||||
|
|||||||
@ -62,7 +62,7 @@ extern "C" {
|
|||||||
#define SDP3X_PARAM_I2C_ADDR SDP3X_ADDR1
|
#define SDP3X_PARAM_I2C_ADDR SDP3X_ADDR1
|
||||||
#endif
|
#endif
|
||||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
#ifndef SDP3X_PARAM_IRQ_PIN
|
||||||
#define SDP3X_PARAM_IRQ_PIN (GPIO_PIN(0, 2))
|
#define SDP3X_PARAM_IRQ_PIN GPIO_UNDEF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SDP3X_PARAMS
|
#ifndef SDP3X_PARAMS
|
||||||
|
|||||||
@ -36,7 +36,9 @@
|
|||||||
#define DATA_READY_SLEEP_US (50 * US_PER_MS)
|
#define DATA_READY_SLEEP_US (50 * US_PER_MS)
|
||||||
|
|
||||||
static bool _check_product_number(uint8_t *readData);
|
static bool _check_product_number(uint8_t *readData);
|
||||||
|
#ifdef MODULE_SDP3X_IRQ
|
||||||
static void _sdp3x_irq_callback(void *arg);
|
static void _sdp3x_irq_callback(void *arg);
|
||||||
|
#endif
|
||||||
static int8_t _checkCRC(uint16_t value, uint8_t test);
|
static int8_t _checkCRC(uint16_t value, uint8_t test);
|
||||||
static int8_t _SDP3x_read_data(const sdp3x_t *dev, int16_t *data);
|
static int8_t _SDP3x_read_data(const sdp3x_t *dev, int16_t *data);
|
||||||
static int32_t _SDP3x_convert_to_pascal(int16_t value,
|
static int32_t _SDP3x_convert_to_pascal(int16_t value,
|
||||||
@ -87,13 +89,16 @@ int sdp3x_init(sdp3x_t *dev, const sdp3x_params_t *params)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SDP3X_PARAM_IRQ_PIN
|
#ifdef MODULE_SDP3X_IRQ
|
||||||
mutex_init(&dev->mutex);
|
/* check if current device has irq pin connected */
|
||||||
/* lock mutex initially to be unlocked when interrupt is raised */
|
if (params->irq_pin != GPIO_UNDEF) {
|
||||||
mutex_lock(&dev->mutex);
|
mutex_init(&dev->mutex);
|
||||||
/* Interrupt set to trigger on falling edge of interrupt pin */
|
/* lock mutex initially to be unlocked when interrupt is raised */
|
||||||
gpio_init_int(params->irq_pin, GPIO_IN, GPIO_FALLING, _sdp3x_irq_callback,
|
mutex_lock(&dev->mutex);
|
||||||
dev);
|
/* Interrupt set to trigger on falling edge of interrupt pin */
|
||||||
|
gpio_init_int(params->irq_pin, GPIO_IN, GPIO_FALLING, _sdp3x_irq_callback,
|
||||||
|
dev);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUG("[SDP3x] init: Init done\n");
|
DEBUG("[SDP3x] init: Init done\n");
|
||||||
@ -103,13 +108,14 @@ int sdp3x_init(sdp3x_t *dev, const sdp3x_params_t *params)
|
|||||||
int32_t sdp3x_read_single_temperature(sdp3x_t *dev, uint8_t flags)
|
int32_t sdp3x_read_single_temperature(sdp3x_t *dev, uint8_t flags)
|
||||||
{
|
{
|
||||||
_SDP3x_start_triggered(dev, flags);
|
_SDP3x_start_triggered(dev, flags);
|
||||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
if (!IS_USED(MODULE_SDP3X_IRQ) || dev->params.irq_pin == GPIO_UNDEF) {
|
||||||
/* Wait for measurement to be ready if irq pin not used */
|
/* Wait for measurement to be ready if irq pin not used */
|
||||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||||
#else
|
}
|
||||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
else {
|
||||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||||
#endif
|
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||||
|
}
|
||||||
return _SDP3x_read_temp(dev);
|
return _SDP3x_read_temp(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,13 +123,14 @@ int32_t sdp3x_read_single_differential_pressure(sdp3x_t *dev,
|
|||||||
uint8_t flags)
|
uint8_t flags)
|
||||||
{
|
{
|
||||||
_SDP3x_start_triggered(dev, flags);
|
_SDP3x_start_triggered(dev, flags);
|
||||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
if (!IS_USED(MODULE_SDP3X_IRQ) || dev->params.irq_pin == GPIO_UNDEF) {
|
||||||
/* Wait for measurement to be ready if irq pin not used */
|
/* Wait for measurement to be ready if irq pin not used */
|
||||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||||
#else
|
}
|
||||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
else {
|
||||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||||
#endif
|
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||||
|
}
|
||||||
return _SDP3x_read_pressure(dev);
|
return _SDP3x_read_pressure(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,13 +138,14 @@ int8_t sdp3x_read_single_measurement(sdp3x_t *dev, uint8_t flags,
|
|||||||
sdp3x_measurement_t *result)
|
sdp3x_measurement_t *result)
|
||||||
{
|
{
|
||||||
_SDP3x_start_triggered(dev, flags);
|
_SDP3x_start_triggered(dev, flags);
|
||||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
if (!IS_USED(MODULE_SDP3X_IRQ) || dev->params.irq_pin == GPIO_UNDEF) {
|
||||||
/* Wait for measurement to be ready if irq pin not used */
|
/* Wait for measurement to be ready if irq pin not used */
|
||||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||||
#else
|
}
|
||||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
else {
|
||||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||||
#endif
|
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||||
|
}
|
||||||
/* read in sensor values here */
|
/* read in sensor values here */
|
||||||
int16_t data[3];
|
int16_t data[3];
|
||||||
uint8_t ret = _SDP3x_read_data(dev, data);
|
uint8_t ret = _SDP3x_read_data(dev, data);
|
||||||
@ -234,8 +242,8 @@ int8_t sdp3x_stop_continuous(sdp3x_t *dev, xtimer_t *continuous_timer)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint8_t cmd[2] = { 0x3F, 0xF9 };
|
uint8_t cmd[2] = { 0x3F, 0xF9 };
|
||||||
|
|
||||||
DEBUG("[SDP3x] stop_continuous: Stopping continuous\
|
DEBUG("[SDP3x] stop_continuous: Stopping continuous"
|
||||||
measurement on device %#X\n", DEV_ADDR);
|
" measurement on device %#X\n", DEV_ADDR);
|
||||||
i2c_acquire(DEV_I2C);
|
i2c_acquire(DEV_I2C);
|
||||||
ret = i2c_write_bytes(DEV_I2C, DEV_ADDR, cmd, 2, 0);
|
ret = i2c_write_bytes(DEV_I2C, DEV_ADDR, cmd, 2, 0);
|
||||||
i2c_release(DEV_I2C);
|
i2c_release(DEV_I2C);
|
||||||
@ -423,6 +431,7 @@ static int8_t _checkCRC(uint16_t value, uint8_t test)
|
|||||||
* @param arguments passed when interrupt is raised
|
* @param arguments passed when interrupt is raised
|
||||||
* (in this case sdp3x dev)
|
* (in this case sdp3x dev)
|
||||||
*/
|
*/
|
||||||
|
#ifdef MODULE_SDP3X_IRQ
|
||||||
static void _sdp3x_irq_callback(void *arg)
|
static void _sdp3x_irq_callback(void *arg)
|
||||||
{
|
{
|
||||||
sdp3x_t *dev = (sdp3x_t *)arg;
|
sdp3x_t *dev = (sdp3x_t *)arg;
|
||||||
@ -430,6 +439,7 @@ static void _sdp3x_irq_callback(void *arg)
|
|||||||
mutex_unlock(&(dev->mutex));
|
mutex_unlock(&(dev->mutex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to check if the product number set
|
* Function to check if the product number set
|
||||||
|
|||||||
@ -187,6 +187,9 @@ PSEUDOMODULES += ina220
|
|||||||
# include variants of mrf24j40 drivers as pseudo modules
|
# include variants of mrf24j40 drivers as pseudo modules
|
||||||
PSEUDOMODULES += mrf24j40m%
|
PSEUDOMODULES += mrf24j40m%
|
||||||
|
|
||||||
|
# include variants of sdp3x drivers as pseudo modules
|
||||||
|
PSEUDOMODULES += sdp3x_irq
|
||||||
|
|
||||||
# include variants of SX127X drivers as pseudo modules
|
# include variants of SX127X drivers as pseudo modules
|
||||||
PSEUDOMODULES += sx1272
|
PSEUDOMODULES += sx1272
|
||||||
PSEUDOMODULES += sx1276
|
PSEUDOMODULES += sx1276
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
include ../Makefile.tests_common
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
DRIVER ?= sdp3x
|
DRIVER ?= sdp3x_irq
|
||||||
|
|
||||||
USEMODULE += $(DRIVER)
|
USEMODULE += $(DRIVER)
|
||||||
USEMODULE += printf_float
|
USEMODULE += printf_float
|
||||||
|
|||||||
@ -18,4 +18,6 @@ make BOARD=... TEST_ITERATIONS=... -C tests/driver_sdp3x
|
|||||||
The sensor has an IRQn pin which indicates data ready on the sensor. This pin can be
|
The sensor has an IRQn pin which indicates data ready on the sensor. This pin can be
|
||||||
connected on the GPIO ports and configured in the variable `SDP3X_PARAM_IRQ_PIN`. This
|
connected on the GPIO ports and configured in the variable `SDP3X_PARAM_IRQ_PIN`. This
|
||||||
helps getting measurements as soon as they are ready instead of the 46ms wait (which is
|
helps getting measurements as soon as they are ready instead of the 46ms wait (which is
|
||||||
the maximum time the sensor might take the get the measurement ready).
|
the maximum time the sensor might take the get the measurement ready).
|
||||||
|
|
||||||
|
When not using irq pin, instead of `USEMODULE = sdp3x_irq`, use `USEMODULE = sdp3x`.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user