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

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/11876#discussion_r306511667">drivers/dht/dht.c</a>:</p>
<pre style='color:#555'>>  
+/**
+ * @brief   Wait until the pin @p pin has level @p expect
+ *
+ * @param   pin     GPIO pin to wait for
+ * @param   expect  Wait until @p pin has this logic level
+ * @param   timeout Timeout in µs
+ *
+ * @retval  0       Success
+ * @retval  -1      Timeout occurred before level was reached
+ */
+static inline int _wait_for_level(gpio_t pin, int expect, unsigned timeout)
+{
+    while ((gpio_read(pin) != expect) && timeout) {
</pre>
<p>not sure this works, bc <code>gpio_read</code> may return anything <code>> 0</code> for HIGH, i.e., must not be <code>1</code> in all cases. That's why I had this rather ugly line <code>((gpio_read(pin) > 0) == set)</code> in my suggested code, that should work for cases there <code>gpio_read()</code> returns <code>42</code> (for example) for HIGH.</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/11876#discussion_r306512287">drivers/dht/dht.c</a>:</p>
<pre style='color:#555'>>  
+/**
+ * @brief   Wait until the pin @p pin has level @p expect
+ *
+ * @param   pin     GPIO pin to wait for
+ * @param   expect  Wait until @p pin has this logic level
+ * @param   timeout Timeout in µs
+ *
+ * @retval  0       Success
+ * @retval  -1      Timeout occurred before level was reached
+ */
+static inline int _wait_for_level(gpio_t pin, int expect, unsigned timeout)
</pre>
<p>again: I'm unsure if <code>unsigned timeout</code> is large enough on all platforms to hold <code>1.000.000</code> microseconds, i.e. verify with arduino-mega2560 for instance.</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/11876#discussion_r306512789">drivers/dht/dht.c</a>:</p>
<pre style='color:#555'>>  
+/**
+ * @brief   Wait until the pin @p pin has level @p expect
+ *
+ * @param   pin     GPIO pin to wait for
+ * @param   expect  Wait until @p pin has this logic level
+ * @param   timeout Timeout in µs
+ *
+ * @retval  0       Success
+ * @retval  -1      Timeout occurred before level was reached
+ */
+static inline int _wait_for_level(gpio_t pin, int expect, unsigned timeout)
</pre>
<p>on that arduino <code>int = unsigned = 16Bits</code>? Which would map 1sec to 65000 microseconds, IIRC?</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/11876#discussion_r306513065">drivers/dht/dht.c</a>:</p>
<pre style='color:#555'>>  
+/**
+ * @brief   Wait until the pin @p pin has level @p expect
+ *
+ * @param   pin     GPIO pin to wait for
+ * @param   expect  Wait until @p pin has this logic level
+ * @param   timeout Timeout in µs
+ *
+ * @retval  0       Success
+ * @retval  -1      Timeout occurred before level was reached
+ */
+static inline int _wait_for_level(gpio_t pin, int expect, unsigned timeout)
</pre>
<p>better use <code>int32_t</code> to be safe and also avoid underflow (which you correctly pointed out).</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/11876?email_source=notifications&email_token=ABE7WYGXWTO4D2MEMBMZNS3QA5RQ3A5CNFSM4IFG24M2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7KYA3I#pullrequestreview-265650285">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYGQFYSSQED3FTMAEGLQA5RQ3ANCNFSM4IFG24MQ">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABE7WYFXXW7DQOSW6IWFOKDQA5RQ3A5CNFSM4IFG24M2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7KYA3I.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/11876?email_source=notifications\u0026email_token=ABE7WYGXWTO4D2MEMBMZNS3QA5RQ3A5CNFSM4IFG24M2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7KYA3I#pullrequestreview-265650285",
"url": "https://github.com/RIOT-OS/RIOT/pull/11876?email_source=notifications\u0026email_token=ABE7WYGXWTO4D2MEMBMZNS3QA5RQ3A5CNFSM4IFG24M2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7KYA3I#pullrequestreview-265650285",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>