[riot-notifications] [RIOT-OS/RIOT] driver/sgp30: initial import (#16222)

Kaspar Schleiser notifications at github.com
Wed Apr 7 14:36:31 CEST 2021


@kaspar030 requested changes on this pull request.

last round of doc typos

> +
+/**
+ * @defgroup    drivers_sgp30 SGP30 Gas Sensor
+ * @ingroup     drivers_sensors
+ * @brief       Device driver interface for the Sensirion SGP30 Gas Sensor
+ *
+ * About
+ * =====
+ *
+ * This driver provides an interface for the Sensirion SGP30 Gas Sensor.
+ * The Datasheet can be found [here](https://www.mouser.com/pdfdocs/Sensirion_Gas_Sensors_SGP30_Datasheet_EN-1148053.pdf)
+ *
+ * After the sensor is powered up and starts measuring air quality for the
+ * first 15s @ref sgp30_read_measurements calls will return fixed values of
+ * of 400ppm CO2eq and 0ppb TVOC. Afterwards values should be read in regular
+ * intervals of 1s for best operation of the dynamic baseline compensationalgorithm.

```suggestion
 * intervals of 1s for best operation of the dynamic baseline compensation algorithm.
```

> + * @defgroup    drivers_sgp30 SGP30 Gas Sensor
+ * @ingroup     drivers_sensors
+ * @brief       Device driver interface for the Sensirion SGP30 Gas Sensor
+ *
+ * About
+ * =====
+ *
+ * This driver provides an interface for the Sensirion SGP30 Gas Sensor.
+ * The Datasheet can be found [here](https://www.mouser.com/pdfdocs/Sensirion_Gas_Sensors_SGP30_Datasheet_EN-1148053.pdf)
+ *
+ * After the sensor is powered up and starts measuring air quality for the
+ * first 15s @ref sgp30_read_measurements calls will return fixed values of
+ * of 400ppm CO2eq and 0ppb TVOC. Afterwards values should be read in regular
+ * intervals of 1s for best operation of the dynamic baseline compensationalgorithm.
+ *
+ * This above not done by default but if the `sgp30_strict` module is included then

```suggestion
 * The above not done by default but if the `sgp30_strict` module is included.
```

> + * @ingroup     drivers_sensors
+ * @brief       Device driver interface for the Sensirion SGP30 Gas Sensor
+ *
+ * About
+ * =====
+ *
+ * This driver provides an interface for the Sensirion SGP30 Gas Sensor.
+ * The Datasheet can be found [here](https://www.mouser.com/pdfdocs/Sensirion_Gas_Sensors_SGP30_Datasheet_EN-1148053.pdf)
+ *
+ * After the sensor is powered up and starts measuring air quality for the
+ * first 15s @ref sgp30_read_measurements calls will return fixed values of
+ * of 400ppm CO2eq and 0ppb TVOC. Afterwards values should be read in regular
+ * intervals of 1s for best operation of the dynamic baseline compensationalgorithm.
+ *
+ * This above not done by default but if the `sgp30_strict` module is included then
+ * then if attempting to read before the is completed then -EAGAIN will be returned.

```suggestion
 * In that case, if attempting to read before the is completed, -EAGAIN will be returned.
```

> + * This driver provides an interface for the Sensirion SGP30 Gas Sensor.
+ * The Datasheet can be found [here](https://www.mouser.com/pdfdocs/Sensirion_Gas_Sensors_SGP30_Datasheet_EN-1148053.pdf)
+ *
+ * After the sensor is powered up and starts measuring air quality for the
+ * first 15s @ref sgp30_read_measurements calls will return fixed values of
+ * of 400ppm CO2eq and 0ppb TVOC. Afterwards values should be read in regular
+ * intervals of 1s for best operation of the dynamic baseline compensationalgorithm.
+ *
+ * This above not done by default but if the `sgp30_strict` module is included then
+ * then if attempting to read before the is completed then -EAGAIN will be returned.
+ * After this periodic readings happen every 1s, and the last value read is
+ * returned when calling @ref sgp30_read_measurements. A timestamp is also added
+ * to @ref sgp30_data_t.
+ *
+ * The sensor features on-chip humidity compensation for the air quality
+ * signals. @ref sgp30_set_absolute_humidity can be used to change the

```suggestion
 * measurements. @ref sgp30_set_absolute_humidity can be used to change the
```

> + * first 15s @ref sgp30_read_measurements calls will return fixed values of
+ * of 400ppm CO2eq and 0ppb TVOC. Afterwards values should be read in regular
+ * intervals of 1s for best operation of the dynamic baseline compensationalgorithm.
+ *
+ * This above not done by default but if the `sgp30_strict` module is included then
+ * then if attempting to read before the is completed then -EAGAIN will be returned.
+ * After this periodic readings happen every 1s, and the last value read is
+ * returned when calling @ref sgp30_read_measurements. A timestamp is also added
+ * to @ref sgp30_data_t.
+ *
+ * The sensor features on-chip humidity compensation for the air quality
+ * signals. @ref sgp30_set_absolute_humidity can be used to change the
+ * absolute humidity value used. See [SGP30 driver integration] (https://files.seeedstudio.com/wiki/Grove-VOC_and_eCO2_Gas_Sensor-SGP30/res/Sensirion_Gas_Sensors_SGP30_Driver-Integration-Guide_HW_I2C.pdf)
+ * for more on this. The baseline values for the correction algorithm can
+ * also be tweaked with @ref sgp30_set_baseline. More on how to implement
+ * dynamic baseline compensation can be seen in at [SGP30 driver integration] (https://files.seeedstudio.com/wiki/Grove-VOC_and_eCO2_Gas_Sensor-SGP30/res/Sensirion_Gas_Sensors_SGP30_Driver-Integration-Guide_HW_I2C.pdf).

```suggestion
 * dynamic baseline compensation can be seen at [SGP30 driver integration] (https://files.seeedstudio.com/wiki/Grove-VOC_and_eCO2_Gas_Sensor-SGP30/res/Sensirion_Gas_Sensors_SGP30_Driver-Integration-Guide_HW_I2C.pdf).
```

> + *
+ * @param[in]   dev        Device descriptor of the driver
+ * @param[out]  data       Air quality measurements
+ *
+ * @retval  0         Success
+ * @retval -EAGAIN    Sensor is not yet ready
+ * @retval -EBADMSG   CRC checksum didn't match
+ * @retval -EPROTO    Sensor did not acknowledge command
+ */
+int sgp30_read_measurements(sgp30_t *dev, sgp30_data_t *data);
+
+/**
+ * @brief   Set absolute humidity value for on-chop humidity compensation
+ *
+ * @note This function requires absolute humidity values, most sensors
+ * output relative humidity, this can be calculated it temperature is also

```suggestion
 * output relative humidity, this can be calculated if temperature is also
```

> +/**
+ * @brief   Returns baseline values
+ *
+ * @param[in]   dev        Device descriptor of the driver
+ * @param[out]  data       Current baseline values
+ *
+ * @retval  0         Success
+ * @retval -EBADMSG   CRC checksum didn't match
+ * @retval -EPROTO    Sensor did not acknowledge command
+ */
+int sgp30_get_baseline(sgp30_t *dev, sgp30_data_t *data);
+
+/**
+ * @brief   Read raw signals H2 (sout_H2) and Ethanol(sout_EthOH)
+ *
+ * It returns the sensor raw signals which are used as inputs for

```suggestion
 * It returns the raw sensor signals which are used as inputs for
```

> + * @brief   Returns baseline values
+ *
+ * @param[in]   dev        Device descriptor of the driver
+ * @param[out]  data       Current baseline values
+ *
+ * @retval  0         Success
+ * @retval -EBADMSG   CRC checksum didn't match
+ * @retval -EPROTO    Sensor did not acknowledge command
+ */
+int sgp30_get_baseline(sgp30_t *dev, sgp30_data_t *data);
+
+/**
+ * @brief   Read raw signals H2 (sout_H2) and Ethanol(sout_EthOH)
+ *
+ * It returns the sensor raw signals which are used as inputs for
+ * the  on-chip calibration and baseline compensationalgorithms.

```suggestion
 * the  on-chip calibration and baseline compensation algorithms.
```

> @@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2018 Gunar Schorcht

```suggestion
 * Copyright (C) 2021 Inria
```

> @@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2018 Gunar Schorcht
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup     sys_auto_init_saul
+ * @brief       Auto initialization of AMS SGP30 digital gas sensor driver
+ * @author      Gunar Schorcht <gunar at schorcht.net>

you?

> +    buf[0] = *val >> 8;
+    buf[1] = *val & 0xFF;
+    buf[2] = _crc8(buf, sizeof(uint16_t));
+}
+
+
+int _get_uint16_and_check_crc(uint8_t *buf, uint16_t *val)
+{
+    if (_crc8(buf, sizeof(uint16_t)) == buf[2]) {
+        *val = (buf[0] << 8) + buf[1];
+        return 0;
+    }
+    return -EBADMSG;
+}
+
+

newline

> +/* Seed used in crc check */
+#define SGP30_CRC8_SEED             0xFF
+
+static inline uint8_t _crc8(const void *buf, size_t len)
+{
+    return crc8(buf, len, SGP30_CRC8_POLYNOMIAL, SGP30_CRC8_SEED);
+}
+
+void _set_uint16_and_crc(uint8_t *buf, uint16_t *val)
+{
+    buf[0] = *val >> 8;
+    buf[1] = *val & 0xFF;
+    buf[2] = _crc8(buf, sizeof(uint16_t));
+}
+
+

newline

> +    buf[2] = _crc8(buf, sizeof(uint16_t));
+}
+
+
+int _get_uint16_and_check_crc(uint8_t *buf, uint16_t *val)
+{
+    if (_crc8(buf, sizeof(uint16_t)) == buf[2]) {
+        *val = (buf[0] << 8) + buf[1];
+        return 0;
+    }
+    return -EBADMSG;
+}
+
+
+static int _rx_tx_data(sgp30_t *dev, uint16_t cmd, uint8_t *data,
+                       size_t len, uint32_t delay, bool read)

still called `read`

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16222#pullrequestreview-629944732
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210407/0a7e88ba/attachment-0001.htm>


More information about the notifications mailing list