Merge pull request #14818 from Nishchay-sopho/drivers/sps30/add_sleep_mode

drivers/sps30: Add sleep mode
This commit is contained in:
benpicco 2020-08-25 23:49:32 +02:00 committed by GitHub
commit a0bae383d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View File

@ -287,6 +287,24 @@ int sps30_read_serial_number(const sps30_t *dev, char *str, size_t len);
*/
int sps30_reset(const sps30_t *dev);
/**
* @brief Put the sensor in sleep mode
*
* @param[in] dev Pointer to an SPS30 device handle
*
* @return #SPS30_OK on success, negative #sps30_error_code_t on error
*/
int sps30_sleep(const sps30_t *dev);
/**
* @brief Wake up sensor from sleep mode (returns sensor to Idle mode)
*
* @param[in] dev Pointer to an SPS30 device handle
*
* @return #SPS30_OK on success, negative #sps30_error_code_t on error
*/
int sps30_wakeup(const sps30_t *dev);
#ifdef __cplusplus
}
#endif

View File

@ -50,6 +50,8 @@ typedef enum {
SPS30_CMD_RD_ARTICLE = 0xD025, /**< Read article code */
SPS30_CMD_RD_SERIAL = 0xD033, /**< Read serial number */
SPS30_CMD_RESET = 0xD304, /**< Reset */
SPS30_CMD_SLEEP = 0x1001, /**< Sleep */
SPS30_CMD_WAKE_UP = 0x1103 /**< Wake-up */
} sps30_cmd_t;
/** @} */
@ -283,3 +285,18 @@ int sps30_reset(const sps30_t *dev)
assert(dev);
return _rx_tx_data(dev, SPS30_CMD_RESET, NULL, 0, false);
}
int sps30_sleep(const sps30_t *dev)
{
assert(dev);
sps30_stop_measurement(dev);
return _rx_tx_data(dev, SPS30_CMD_SLEEP, NULL, 0, false);
}
int sps30_wakeup(const sps30_t *dev)
{
assert(dev);
/* Send I2C start stop sequence to re-enable I2C interface on sensor */
i2c_write_bytes(dev->p.i2c_dev, SPS30_I2C_ADDR, NULL, 0, 0);
return _rx_tx_data(dev, SPS30_CMD_WAKE_UP, NULL, 0, false);
}

View File

@ -25,6 +25,7 @@
#define TEST_START_DELAY_S (2U)
#define SENSOR_RESET_DELAY_S (10U)
#define SENSOR_STARTUP_DELAY_S (10U)
#define SENSOR_SLEEP_WAKE_DELAY_S (5U)
#define POLL_FOR_READY_S (1U)
#define NUM_OF_MEASUREMENTS (10U)
@ -102,6 +103,16 @@ int main(void)
xtimer_sleep(SENSOR_RESET_DELAY_S);
/* Put the sensor in sleep */
ec = sps30_sleep(&dev);
error |= _print_error("sleep", ec);
xtimer_sleep(SENSOR_SLEEP_WAKE_DELAY_S);
/* Wake-up the sensor */
ec = sps30_wakeup(&dev);
error |= _print_error("wake-up", ec);
xtimer_sleep(SENSOR_SLEEP_WAKE_DELAY_S);
/* start the sensor again again... */
ec = sps30_start_measurement(&dev);
error |= _print_error("start_measurement", ec);