summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-01-31 18:12:53 +1100
committerDamien George <damien.p.george@gmail.com>2018-01-31 18:12:53 +1100
commitefdda2c62deba4f4f24672e441cffe496158bb35 (patch)
treece6036a5dc41f4f68010d199c871e0a1a488df19
parenta40ce1d829eca6fe0fad0b7f4478a6651903dd2a (diff)
stm32: Add support for DHT11/DHT22 sensors.
-rw-r--r--drivers/dht/dht.py7
-rw-r--r--ports/stm32/Makefile1
-rw-r--r--ports/stm32/modpyb.c4
l---------ports/stm32/modules/dht.py1
4 files changed, 11 insertions, 2 deletions
diff --git a/drivers/dht/dht.py b/drivers/dht/dht.py
index 9a69e7e07..eed61df7c 100644
--- a/drivers/dht/dht.py
+++ b/drivers/dht/dht.py
@@ -1,7 +1,10 @@
# DHT11/DHT22 driver for MicroPython on ESP8266
# MIT license; Copyright (c) 2016 Damien P. George
-import esp
+try:
+ from esp import dht_readinto
+except:
+ from pyb import dht_readinto
class DHTBase:
def __init__(self, pin):
@@ -10,7 +13,7 @@ class DHTBase:
def measure(self):
buf = self.buf
- esp.dht_readinto(self.pin, buf)
+ dht_readinto(self.pin, buf)
if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xff != buf[4]:
raise Exception("checksum error")
diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile
index 68b007471..65962bea6 100644
--- a/ports/stm32/Makefile
+++ b/ports/stm32/Makefile
@@ -186,6 +186,7 @@ EXTMOD_SRC_C = $(addprefix extmod/,\
DRIVERS_SRC_C = $(addprefix drivers/,\
memory/spiflash.c \
+ dht/dht.c \
)
SRC_C = \
diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c
index 4d186e278..970b5b954 100644
--- a/ports/stm32/modpyb.c
+++ b/ports/stm32/modpyb.c
@@ -34,6 +34,7 @@
#include "lib/utils/pyexec.h"
#include "lib/oofatfs/ff.h"
#include "lib/oofatfs/diskio.h"
+#include "drivers/dht/dht.h"
#include "gccollect.h"
#include "stm32_it.h"
#include "irq.h"
@@ -168,6 +169,9 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) },
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
+ // This function is not intended to be public and may be moved elsewhere
+ { MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) },
+
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&pyb_timer_type) },
#if MICROPY_HW_ENABLE_RNG
diff --git a/ports/stm32/modules/dht.py b/ports/stm32/modules/dht.py
new file mode 120000
index 000000000..2aa2f5cbf
--- /dev/null
+++ b/ports/stm32/modules/dht.py
@@ -0,0 +1 @@
+../../../drivers/dht/dht.py \ No newline at end of file