mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
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
|
||||
endif
|
||||
|
||||
ifneq (,$(filter sdp3x_%,$(USEMODULE)))
|
||||
USEMODULE += sdp3x
|
||||
endif
|
||||
|
||||
ifneq (,$(filter sht1%,$(USEMODULE)))
|
||||
USEMODULE += sht1x
|
||||
endif
|
||||
|
@ -1,4 +1,7 @@
|
||||
FEATURES_REQUIRED += periph_i2c
|
||||
FEATURES_REQUIRED += periph_gpio_irq
|
||||
USEMODULE += checksum
|
||||
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
|
||||
#endif
|
||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
||||
#define SDP3X_PARAM_IRQ_PIN (GPIO_PIN(0, 2))
|
||||
#define SDP3X_PARAM_IRQ_PIN GPIO_UNDEF
|
||||
#endif
|
||||
|
||||
#ifndef SDP3X_PARAMS
|
||||
|
@ -36,7 +36,9 @@
|
||||
#define DATA_READY_SLEEP_US (50 * US_PER_MS)
|
||||
|
||||
static bool _check_product_number(uint8_t *readData);
|
||||
#ifdef MODULE_SDP3X_IRQ
|
||||
static void _sdp3x_irq_callback(void *arg);
|
||||
#endif
|
||||
static int8_t _checkCRC(uint16_t value, uint8_t test);
|
||||
static int8_t _SDP3x_read_data(const sdp3x_t *dev, int16_t *data);
|
||||
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;
|
||||
}
|
||||
|
||||
#ifdef SDP3X_PARAM_IRQ_PIN
|
||||
mutex_init(&dev->mutex);
|
||||
/* lock mutex initially to be unlocked when interrupt is raised */
|
||||
mutex_lock(&dev->mutex);
|
||||
/* Interrupt set to trigger on falling edge of interrupt pin */
|
||||
gpio_init_int(params->irq_pin, GPIO_IN, GPIO_FALLING, _sdp3x_irq_callback,
|
||||
dev);
|
||||
#ifdef MODULE_SDP3X_IRQ
|
||||
/* check if current device has irq pin connected */
|
||||
if (params->irq_pin != GPIO_UNDEF) {
|
||||
mutex_init(&dev->mutex);
|
||||
/* lock mutex initially to be unlocked when interrupt is raised */
|
||||
mutex_lock(&dev->mutex);
|
||||
/* 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
|
||||
|
||||
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)
|
||||
{
|
||||
_SDP3x_start_triggered(dev, flags);
|
||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
||||
/* Wait for measurement to be ready if irq pin not used */
|
||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||
#else
|
||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||
#endif
|
||||
if (!IS_USED(MODULE_SDP3X_IRQ) || dev->params.irq_pin == GPIO_UNDEF) {
|
||||
/* Wait for measurement to be ready if irq pin not used */
|
||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||
}
|
||||
else {
|
||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||
}
|
||||
return _SDP3x_read_temp(dev);
|
||||
}
|
||||
|
||||
@ -117,13 +123,14 @@ int32_t sdp3x_read_single_differential_pressure(sdp3x_t *dev,
|
||||
uint8_t flags)
|
||||
{
|
||||
_SDP3x_start_triggered(dev, flags);
|
||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
||||
/* Wait for measurement to be ready if irq pin not used */
|
||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||
#else
|
||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||
#endif
|
||||
if (!IS_USED(MODULE_SDP3X_IRQ) || dev->params.irq_pin == GPIO_UNDEF) {
|
||||
/* Wait for measurement to be ready if irq pin not used */
|
||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||
}
|
||||
else {
|
||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||
}
|
||||
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_start_triggered(dev, flags);
|
||||
#ifndef SDP3X_PARAM_IRQ_PIN
|
||||
/* Wait for measurement to be ready if irq pin not used */
|
||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||
#else
|
||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||
#endif
|
||||
if (!IS_USED(MODULE_SDP3X_IRQ) || dev->params.irq_pin == GPIO_UNDEF) {
|
||||
/* Wait for measurement to be ready if irq pin not used */
|
||||
xtimer_usleep(DATA_READY_SLEEP_US);
|
||||
}
|
||||
else {
|
||||
/* Try to lock mutex till the interrupt is raised or till timeut happens */
|
||||
xtimer_mutex_lock_timeout(&dev->mutex, DATA_READY_SLEEP_US);
|
||||
}
|
||||
/* read in sensor values here */
|
||||
int16_t data[3];
|
||||
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;
|
||||
uint8_t cmd[2] = { 0x3F, 0xF9 };
|
||||
|
||||
DEBUG("[SDP3x] stop_continuous: Stopping continuous\
|
||||
measurement on device %#X\n", DEV_ADDR);
|
||||
DEBUG("[SDP3x] stop_continuous: Stopping continuous"
|
||||
" measurement on device %#X\n", DEV_ADDR);
|
||||
i2c_acquire(DEV_I2C);
|
||||
ret = i2c_write_bytes(DEV_I2C, DEV_ADDR, cmd, 2, 0);
|
||||
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
|
||||
* (in this case sdp3x dev)
|
||||
*/
|
||||
#ifdef MODULE_SDP3X_IRQ
|
||||
static void _sdp3x_irq_callback(void *arg)
|
||||
{
|
||||
sdp3x_t *dev = (sdp3x_t *)arg;
|
||||
@ -430,6 +439,7 @@ static void _sdp3x_irq_callback(void *arg)
|
||||
mutex_unlock(&(dev->mutex));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Function to check if the product number set
|
||||
|
@ -187,6 +187,9 @@ PSEUDOMODULES += ina220
|
||||
# include variants of mrf24j40 drivers as pseudo modules
|
||||
PSEUDOMODULES += mrf24j40m%
|
||||
|
||||
# include variants of sdp3x drivers as pseudo modules
|
||||
PSEUDOMODULES += sdp3x_irq
|
||||
|
||||
# include variants of SX127X drivers as pseudo modules
|
||||
PSEUDOMODULES += sx1272
|
||||
PSEUDOMODULES += sx1276
|
||||
|
@ -1,6 +1,6 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
DRIVER ?= sdp3x
|
||||
DRIVER ?= sdp3x_irq
|
||||
|
||||
USEMODULE += $(DRIVER)
|
||||
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
|
||||
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
|
||||
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…
Reference in New Issue
Block a user