<p><b>@benpicco</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327345399">drivers/include/opt3001.h</a>:</p>
<pre style='color:#555'>> @@ -165,7 +151,7 @@ int opt3001_read(const opt3001_t *dev, uint16_t *crf, uint16_t *rawl);
  * @param[in]  rawl         raw lux value
  * @param[out] convl        converted lux value
</pre>
<p>What is the unit of the converted lux value?</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327347215">drivers/opt3001/opt3001.c</a>:</p>
<pre style='color:#555'>>  {
   uint16_t mantissa;
   uint8_t exponent;
 
   exponent = OPT3001_REGS_REG_EXPONENT(rawl);
   mantissa = OPT3001_REGS_REG_MANTISSA(rawl);
 
-  *convl = 0.01 * pow(2, exponent) * mantissa;
+  *convl = (1 << exponent) * mantissa;
</pre>
<p>If you want to return mLux, you have to multiply by 10 now.</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327347380">drivers/opt3001/opt3001.c</a>:</p>
<pre style='color:#555'>> @@ -182,13 +184,6 @@ int opt3001_read_lux(const opt3001_t *dev, int16_t *convl)
 
     opt3001_convert(rawl, &convlux);
     *convl = (int16_t)(convlux*100);
</pre>
<p>This is not needed anymore.</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327347497">drivers/opt3001/opt3001_saul.c</a>:</p>
<pre style='color:#555'>> @@ -31,13 +31,9 @@
 
     res->val[1] = 0;
 
- #if OPT3001_USE_RAW_VALUES
-     res->unit = UNIT_NONE;
-     res->scale = 0;
- #else
-     res->unit = UNIT_LUX;
-     res->scale = -2;
- #endif
+    res->unit = UNIT_LUX;
+    res->scale = -2;
</pre>
<p>Is this still right?</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327348211">drivers/opt3001/opt3001.c</a>:</p>
<pre style='color:#555'>> +    if (i2c_read_regs(DEV_I2C, DEV_ADDR, OPT3001_REGS_CONFIG, &reg, 2, 0) < 0) {
+        i2c_release(DEV_I2C);
+        LOG_ERROR("opt3001_init: Error reading BUS!\n");
+        return -OPT3001_ERROR_BUS;
+    }
+
+    *crf = htons(reg) & OPT3001_REGS_CONFIG_CRF;
+
+    if (!(*crf)) {
+        i2c_release(DEV_I2C);
+        LOG_DEBUG("opt3001_read: conversion in progress!\n");
+        return -OPT3001_ERROR;
+    }
+
+    /* wait for the conversion to finish */
+    if (OPT3001_CONVERSION_TIME) {
</pre>
<p>Why wait now?<br>
We already know here that no conversion is in progress anymore.</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327354365">drivers/opt3001/opt3001.c</a>:</p>
<pre style='color:#555'>> +    uint16_t reg;
+
+    i2c_acquire(DEV_I2C);
+
+    if (i2c_read_regs(DEV_I2C, DEV_ADDR, OPT3001_REGS_CONFIG, &reg, 2, 0) < 0) {
+        i2c_release(DEV_I2C);
+        LOG_ERROR("opt3001_init: Error reading BUS!\n");
+        return -OPT3001_ERROR_BUS;
+    }
+
+    *crf = htons(reg) & OPT3001_REGS_CONFIG_CRF;
+
+    if (!(*crf)) {
+        i2c_release(DEV_I2C);
+        LOG_DEBUG("opt3001_read: conversion in progress!\n");
+        return -OPT3001_ERROR;
</pre>
<p>Instead of returning error here, why not repeat reading <code>OPT3001_REGS_CONFIG</code> in a loop until <code>OPT3001_REGS_CONFIG_CRF</code> is set?<br>
You can still call <code>xtimer_usleep()</code> in the loop, but only sleep 1ms at a time until you have reached <code>OPT3001_CONVERSION_TIME</code>.</p>
<p>Another option instead of polling would be to use the interrupt pin to get an interrupt when conversion is done.</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327354825">drivers/opt3001/include/opt3001_regs.h</a>:</p>
<pre style='color:#555'>> +
+ #define OPT3001_CONFIG_M_SHUTDOWN     (0x0) /**< Shutdown mode */
+ #define OPT3001_CONFIG_M_SINGLE       (0x1) /**< Single-shot mode */
+ #define OPT3001_CONFIG_M_CONTINUOUS   (0x2) /**< Continuous mode (also 0x3) */
+ #define OPT3001_CONFIG_MOC_SHIFT      (9U)  /**< Mode of conversion shift */
+ #define OPT3001_CONFIG_MOC_MASK       (0x0600) /**< Mode of conversion mask */
+ #define OPT3001_REGS_CONFIG_MOC(x)    (((uint16_t)(((uint16_t)(x)) \
+                                       << OPT3001_CONFIG_MOC_SHIFT)) \
+                                       & OPT3001_CONFIG_MOC_MASK) /**< Mode of conversion field */
+
+ #define OPT3001_REGS_CONFIG_OVF (1 << 8)  /**< Overflow flag field */
+ #define OPT3001_REGS_CONFIG_CRF (1 << 7)  /**< Conversion ready field */
+ #define OPT3001_REGS_CONFIG_FH         (1 << 6)  /**< Flag high field */
+ #define OPT3001_REGS_CONFIG_FL         (1 << 5)  /**< Flag low field */
+ #define OPT3001_REGS_CONFIG_L  (1 << 4)  /**< Latch field */
+ #define OPT3001_REGS_CONFIG_POL (1 << 3)  /**< Polarity field */
</pre>
<p>Indentation</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327354852">drivers/opt3001/include/opt3001_regs.h</a>:</p>
<pre style='color:#555'>> + #define OPT3001_REGS_CONFIG_CT_MASK   (0x0800) /**< Conversion time mask */
+ #define OPT3001_REGS_CONFIG_CT(x)     (((uint16_t)(((uint16_t)(x)) \
+                                       << OPT3001_REGS_CONFIG_CT_SHIFT)) \
+                                       & OPT3001_REGS_CONFIG_CT_MASK) /**< Conversion time field */
+
+ #define OPT3001_CONFIG_M_SHUTDOWN     (0x0) /**< Shutdown mode */
+ #define OPT3001_CONFIG_M_SINGLE       (0x1) /**< Single-shot mode */
+ #define OPT3001_CONFIG_M_CONTINUOUS   (0x2) /**< Continuous mode (also 0x3) */
+ #define OPT3001_CONFIG_MOC_SHIFT      (9U)  /**< Mode of conversion shift */
+ #define OPT3001_CONFIG_MOC_MASK       (0x0600) /**< Mode of conversion mask */
+ #define OPT3001_REGS_CONFIG_MOC(x)    (((uint16_t)(((uint16_t)(x)) \
+                                       << OPT3001_CONFIG_MOC_SHIFT)) \
+                                       & OPT3001_CONFIG_MOC_MASK) /**< Mode of conversion field */
+
+ #define OPT3001_REGS_CONFIG_OVF (1 << 8)  /**< Overflow flag field */
+ #define OPT3001_REGS_CONFIG_CRF (1 << 7)  /**< Conversion ready field */
</pre>
<p>Indentation</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/12260#discussion_r327355204">drivers/opt3001/opt3001.c</a>:</p>
<pre style='color:#555'>> +    if (i2c_read_regs(DEV_I2C, DEV_ADDR, OPT3001_REGS_RESULT, &reg, 2, 0) < 0) {
+        i2c_release(DEV_I2C);
+        LOG_ERROR("opt3001_init: Error reading BUS!\n");
+        return -OPT3001_ERROR_BUS;
+    }
+
+    *rawl = htons(reg);
+
+    i2c_release(DEV_I2C);
+    return OPT3001_OK;
+}
+
+void opt3001_convert(int16_t rawl, uint16_t *convl)
+{
+  uint16_t mantissa;
+  uint8_t exponent;
</pre>
<p>Indentation should always be 4 spaces.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/12260?email_source=notifications&email_token=ABE7WYHKFSVXPYVR47TYJGLQLE6SDA5CNFSM4IXNJYGKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCFULD3A#pullrequestreview-292073964">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYFCU4O2YJJMKK4UH3DQLE6SDANCNFSM4IXNJYGA">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABE7WYDNX5OIGTA3JY6T23TQLE6SDA5CNFSM4IXNJYGKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCFULD3A.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/12260?email_source=notifications\u0026email_token=ABE7WYHKFSVXPYVR47TYJGLQLE6SDA5CNFSM4IXNJYGKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCFULD3A#pullrequestreview-292073964",
"url": "https://github.com/RIOT-OS/RIOT/pull/12260?email_source=notifications\u0026email_token=ABE7WYHKFSVXPYVR47TYJGLQLE6SDA5CNFSM4IXNJYGKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCFULD3A#pullrequestreview-292073964",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>