summaryrefslogtreecommitdiff
path: root/esp8266/modules
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-06-20 10:56:05 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-06-20 10:56:05 -0700
commit30ee7019ca651bce1fe966c1089fe977d51dc92b (patch)
tree0114b6f744dd175b7722dd8edcbe24f4ee84bb45 /esp8266/modules
parent97fcdfbd08c922efd7470d6482d7c7c703ffc0ae (diff)
parent869cdcfdfc860b1177baf9b0f8818915ba54f3f5 (diff)
Merge tag 'v1.9.1'2.0.0-alpha.0
Fixes for stmhal USB mass storage, lwIP bindings and VFS regressions This release provides an important fix for the USB mass storage device in the stmhal port by implementing the SCSI SYNCHRONIZE_CACHE command, which is now require by some Operating Systems. There are also fixes for the lwIP bindings to improve non-blocking sockets and error codes. The VFS has some regressions fixed including the ability to statvfs the root. All changes are listed below. py core: - modbuiltins: add core-provided version of input() function - objstr: catch case of negative "maxsplit" arg to str.rsplit() - persistentcode: allow to compile with complex numbers disabled - objstr: allow to compile with obj-repr D, and unicode disabled - modsys: allow to compile with obj-repr D and PY_ATTRTUPLE disabled - provide mp_decode_uint_skip() to help reduce stack usage - makeqstrdefs.py: make script run correctly with Python 2.6 - objstringio: if created from immutable object, follow copy on write policy extmod: - modlwip: connect: for non-blocking mode, return EINPROGRESS - modlwip: fix error codes for duplicate calls to connect() - modlwip: accept: fix error code for non-blocking mode - vfs: allow to statvfs the root directory - vfs: allow "buffering" and "encoding" args to VFS's open() - modframebuf: fix signed/unsigned comparison pendantic warning lib: - libm: use isfinite instead of finitef, for C99 compatibility - utils/interrupt_char: remove support for KBD_EXCEPTION disabled tests: - basics/string_rsplit: add tests for negative "maxsplit" argument - float: convert "sys.exit()" to "raise SystemExit" - float/builtin_float_minmax: PEP8 fixes - basics: convert "sys.exit()" to "raise SystemExit" - convert remaining "sys.exit()" to "raise SystemExit" unix port: - convert to use core-provided version of built-in import() - Makefile: replace references to make with $(MAKE) windows port: - convert to use core-provided version of built-in import() qemu-arm port: - Makefile: adjust object-file lists to get correct dependencies - enable micropython.mem_*() functions to allow more tests stmhal port: - boards: enable DAC for NUCLEO_F767ZI board - add support for NUCLEO_F446RE board - pass USB handler as parameter to allow more than one USB handler - usb: use local USB handler variable in Start-of-Frame handler - usb: make state for USB device private to top-level USB driver - usbdev: for MSC implement SCSI SYNCHRONIZE_CACHE command - convert from using stmhal's input() to core provided version cc3200 port: - convert from using stmhal's input() to core provided version teensy port: - convert from using stmhal's input() to core provided version esp8266 port: - Makefile: replace references to make with $(MAKE) - Makefile: add clean-modules target - convert from using stmhal's input() to core provided version zephyr port: - modusocket: getaddrinfo: Fix mp_obj_len() usage - define MICROPY_PY_SYS_PLATFORM (to "zephyr") - machine_pin: use native Zephyr types for Zephyr API calls docs: - machine.Pin: remove out_value() method - machine.Pin: add on() and off() methods - esp8266: consistently replace Pin.high/low methods with .on/off - esp8266/quickref: polish Pin.on()/off() examples - network: move confusingly-named cc3200 Server class to its reference - uos: deconditionalize, remove minor port-specific details - uos: move cc3200 port legacy VFS mounting functions to its ref doc - machine: sort machine classes in logical order, not alphabetically - network: first step to describe standard network class interface examples: - embedding: use core-provided KeyboardInterrupt object
Diffstat (limited to 'esp8266/modules')
-rw-r--r--esp8266/modules/_boot.py4
-rw-r--r--esp8266/modules/apa102.py17
-rw-r--r--esp8266/modules/dht.py32
-rw-r--r--esp8266/modules/flashbdev.py2
-rw-r--r--esp8266/modules/inisetup.py52
-rw-r--r--esp8266/modules/neopixel.py32
-rw-r--r--esp8266/modules/ntptime.py36
-rw-r--r--esp8266/modules/port_diag.py33
8 files changed, 205 insertions, 3 deletions
diff --git a/esp8266/modules/_boot.py b/esp8266/modules/_boot.py
index c200b3d3f..81eb20dd6 100644
--- a/esp8266/modules/_boot.py
+++ b/esp8266/modules/_boot.py
@@ -5,9 +5,9 @@ from flashbdev import bdev
try:
if bdev:
- vfs = uos.VfsFat(bdev, "")
+ uos.mount(bdev, '/')
except OSError:
import inisetup
- vfs = inisetup.setup()
+ inisetup.setup()
gc.collect()
diff --git a/esp8266/modules/apa102.py b/esp8266/modules/apa102.py
new file mode 100644
index 000000000..41b7c0485
--- /dev/null
+++ b/esp8266/modules/apa102.py
@@ -0,0 +1,17 @@
+# APA102 driver for MicroPython on ESP8266
+# MIT license; Copyright (c) 2016 Robert Foss, Daniel Busch
+
+from esp import apa102_write
+from neopixel import NeoPixel
+
+
+class APA102(NeoPixel):
+ ORDER = (0, 1, 2, 3)
+
+ def __init__(self, clock_pin, data_pin, n, bpp=4):
+ super().__init__(data_pin, n, bpp)
+ self.clock_pin = clock_pin
+ self.clock_pin.init(clock_pin.OUT)
+
+ def write(self):
+ apa102_write(self.clock_pin, self.pin, self.buf)
diff --git a/esp8266/modules/dht.py b/esp8266/modules/dht.py
new file mode 100644
index 000000000..9a69e7e07
--- /dev/null
+++ b/esp8266/modules/dht.py
@@ -0,0 +1,32 @@
+# DHT11/DHT22 driver for MicroPython on ESP8266
+# MIT license; Copyright (c) 2016 Damien P. George
+
+import esp
+
+class DHTBase:
+ def __init__(self, pin):
+ self.pin = pin
+ self.buf = bytearray(5)
+
+ def measure(self):
+ buf = self.buf
+ esp.dht_readinto(self.pin, buf)
+ if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xff != buf[4]:
+ raise Exception("checksum error")
+
+class DHT11(DHTBase):
+ def humidity(self):
+ return self.buf[0]
+
+ def temperature(self):
+ return self.buf[2]
+
+class DHT22(DHTBase):
+ def humidity(self):
+ return (self.buf[0] << 8 | self.buf[1]) * 0.1
+
+ def temperature(self):
+ t = ((self.buf[2] & 0x7f) << 8 | self.buf[3]) * 0.1
+ if self.buf[2] & 0x80:
+ t = -t
+ return t
diff --git a/esp8266/modules/flashbdev.py b/esp8266/modules/flashbdev.py
index 8f8df0b64..40ba655c6 100644
--- a/esp8266/modules/flashbdev.py
+++ b/esp8266/modules/flashbdev.py
@@ -3,7 +3,7 @@ import esp
class FlashBdev:
SEC_SIZE = 4096
- RESERVED_SECS = 0
+ RESERVED_SECS = 1
START_SEC = esp.flash_user_start() // SEC_SIZE + RESERVED_SECS
NUM_BLK = 0x6b - RESERVED_SECS
diff --git a/esp8266/modules/inisetup.py b/esp8266/modules/inisetup.py
new file mode 100644
index 000000000..af78dfad5
--- /dev/null
+++ b/esp8266/modules/inisetup.py
@@ -0,0 +1,52 @@
+import uos
+import network
+from flashbdev import bdev
+
+def wifi():
+ import ubinascii
+ ap_if = network.WLAN(network.AP_IF)
+ essid = b"MicroPython-%s" % ubinascii.hexlify(ap_if.config("mac")[-3:])
+ ap_if.config(essid=essid, authmode=network.AUTH_WPA_WPA2_PSK, password=b"micropythoN")
+
+def check_bootsec():
+ buf = bytearray(bdev.SEC_SIZE)
+ bdev.readblocks(0, buf)
+ empty = True
+ for b in buf:
+ if b != 0xff:
+ empty = False
+ break
+ if empty:
+ return True
+ fs_corrupted()
+
+def fs_corrupted():
+ import time
+ while 1:
+ print("""\
+The FAT filesystem starting at sector %d with size %d sectors appears to
+be corrupted. If you had important data there, you may want to make a flash
+snapshot to try to recover it. Otherwise, perform factory reprogramming
+of MicroPython firmware (completely erase flash, followed by firmware
+programming).
+""" % (bdev.START_SEC, bdev.blocks))
+ time.sleep(3)
+
+def setup():
+ check_bootsec()
+ print("Performing initial setup")
+ wifi()
+ uos.VfsFat.mkfs(bdev)
+ vfs = uos.VfsFat(bdev)
+ uos.mount(vfs, '/')
+ with open("boot.py", "w") as f:
+ f.write("""\
+# This file is executed on every boot (including wake-boot from deepsleep)
+#import esp
+#esp.osdebug(None)
+import gc
+#import webrepl
+#webrepl.start()
+gc.collect()
+""")
+ return vfs
diff --git a/esp8266/modules/neopixel.py b/esp8266/modules/neopixel.py
new file mode 100644
index 000000000..b13424d7d
--- /dev/null
+++ b/esp8266/modules/neopixel.py
@@ -0,0 +1,32 @@
+# NeoPixel driver for MicroPython on ESP8266
+# MIT license; Copyright (c) 2016 Damien P. George
+
+from esp import neopixel_write
+
+
+class NeoPixel:
+ ORDER = (1, 0, 2, 3)
+
+ def __init__(self, pin, n, bpp=3):
+ self.pin = pin
+ self.n = n
+ self.bpp = bpp
+ self.buf = bytearray(n * bpp)
+ self.pin.init(pin.OUT)
+
+ def __setitem__(self, index, val):
+ offset = index * self.bpp
+ for i in range(self.bpp):
+ self.buf[offset + self.ORDER[i]] = val[i]
+
+ def __getitem__(self, index):
+ offset = index * self.bpp
+ return tuple(self.buf[offset + self.ORDER[i]]
+ for i in range(self.bpp))
+
+ def fill(self, color):
+ for i in range(self.n):
+ self[i] = color
+
+ def write(self):
+ neopixel_write(self.pin, self.buf, True)
diff --git a/esp8266/modules/ntptime.py b/esp8266/modules/ntptime.py
new file mode 100644
index 000000000..a97e08e60
--- /dev/null
+++ b/esp8266/modules/ntptime.py
@@ -0,0 +1,36 @@
+try:
+ import usocket as socket
+except:
+ import socket
+try:
+ import ustruct as struct
+except:
+ import struct
+
+# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
+NTP_DELTA = 3155673600
+
+host = "pool.ntp.org"
+
+def time():
+ NTP_QUERY = bytearray(48)
+ NTP_QUERY[0] = 0x1b
+ addr = socket.getaddrinfo(host, 123)[0][-1]
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ s.settimeout(1)
+ res = s.sendto(NTP_QUERY, addr)
+ msg = s.recv(48)
+ s.close()
+ val = struct.unpack("!I", msg[40:44])[0]
+ return val - NTP_DELTA
+
+# There's currently no timezone support in MicroPython, so
+# utime.localtime() will return UTC time (as if it was .gmtime())
+def settime():
+ t = time()
+ import machine
+ import utime
+ tm = utime.localtime(t)
+ tm = tm[0:3] + (0,) + tm[3:6] + (0,)
+ machine.RTC().datetime(tm)
+ print(utime.localtime())
diff --git a/esp8266/modules/port_diag.py b/esp8266/modules/port_diag.py
new file mode 100644
index 000000000..ef8800355
--- /dev/null
+++ b/esp8266/modules/port_diag.py
@@ -0,0 +1,33 @@
+import esp
+import uctypes
+import network
+import lwip
+
+
+def main():
+
+ ROM = uctypes.bytearray_at(0x40200000, 16)
+ fid = esp.flash_id()
+
+ print("FlashROM:")
+ print("Flash ID: %x (Vendor: %x Device: %x)" % (fid, fid & 0xff, fid & 0xff00 | fid >> 16))
+
+ print("Flash bootloader data:")
+ SZ_MAP = {0: "512KB", 1: "256KB", 2: "1MB", 3: "2MB", 4: "4MB"}
+ FREQ_MAP = {0: "40MHZ", 1: "26MHZ", 2: "20MHz", 0xf: "80MHz"}
+ print("Byte @2: %02x" % ROM[2])
+ print("Byte @3: %02x (Flash size: %s Flash freq: %s)" % (ROM[3], SZ_MAP.get(ROM[3] >> 4, "?"), FREQ_MAP.get(ROM[3] & 0xf)))
+ print("Firmware checksum:")
+ print(esp.check_fw())
+
+ print("\nNetworking:")
+ print("STA ifconfig:", network.WLAN(network.STA_IF).ifconfig())
+ print("AP ifconfig:", network.WLAN(network.AP_IF).ifconfig())
+ print("Free WiFi driver buffers of type:")
+ for i, comm in enumerate(("1,2 TX", "4 Mngmt TX(len: 0x41-0x100)", "5 Mngmt TX (len: 0-0x40)", "7", "8 RX")):
+ print("%d: %d (%s)" % (i, esp.esf_free_bufs(i), comm))
+ print("lwIP PCBs:")
+ lwip.print_pcbs()
+
+
+main()