summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-02-05 14:20:17 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-02-05 14:20:17 +0300
commitd5e9ab6e61729f533dbed5c2b6b27307ce6c3b55 (patch)
tree727c3606486ac2722726ad9471f37e6f95f7d660 /drivers
parentbd04ed3e8a4235664743fd4c452091a9ce603011 (diff)
extmod/machine_pulse: Make time_pulse_us() not throw exceptions.
machine.time_pulse_us() is intended to provide very fine timing, including while working with signal bursts, where each transition is tracked in row. Throwing and handling an exception may take too much time and "signal loss". So instead, in case of a timeout, just return negative value. Cases of timeout while waiting for initial signal stabilization, and during actual timing, are recognized. The documentation is updated accordingly, and rewritten somewhat to clarify the function behavior.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/dht/dht.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c
index 1f0cffc6f..6bdda44b4 100644
--- a/drivers/dht/dht.c
+++ b/drivers/dht/dht.c
@@ -65,7 +65,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) {
// time pulse, should be 80us
ticks = machine_time_pulse_us(pin, 1, 150);
- if (ticks == (mp_uint_t)-1) {
+ if ((mp_int_t)ticks < 0) {
goto timeout;
}
@@ -73,7 +73,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) {
uint8_t *buf = bufinfo.buf;
for (int i = 0; i < 40; ++i) {
ticks = machine_time_pulse_us(pin, 1, 100);
- if (ticks == (mp_uint_t)-1) {
+ if ((mp_int_t)ticks < 0) {
goto timeout;
}
buf[i / 8] = (buf[i / 8] << 1) | (ticks > 48);