diff options
author | Damien George <damien.p.george@gmail.com> | 2017-08-14 12:47:47 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-08-14 12:47:47 +1000 |
commit | f6e6776d6f8233432615f1ef438cbd1447c51aac (patch) | |
tree | 34589f98ab4d89914025b7d4ee10d2801cd80b3d /esp8266 | |
parent | d9d9b0a3005a810543724622374cc26a5399bd0e (diff) | |
parent | c8d31585a00616b39839d112b7c696dafed6b08d (diff) | |
download | micropython-f6e6776d6f8233432615f1ef438cbd1447c51aac.tar.gz micropython-f6e6776d6f8233432615f1ef438cbd1447c51aac.zip |
Merge tag 'v1.8.5' into parse-bytecode
New port to Zephyr, upip runs on baremetal, and reduction in code size
This release adds a new port of MicroPython to run on top of the Zephyr
real-time operating system. As part of this there is now basic support for
using mbedTLS as the ussl module. The release also brings initial support
for running the package manager upip on baremetal systems with low heap
memory (such as esp8266), through a Python module interface.
Work has been done in this release to clean up the core, removing redundant
and/or unreachable code, and factoring existing duplicated code patterns.
This brings a reduction of 828 bytes in code size to the bare-arm port, and
1368 bytes to the minimal port. There is also improved coverage through
the addition of new tests for corner cases.
The "micropython" module sees the addition of the "const" identity function
which should be used as "from micropython import const" in scripts that
want to use the MicroPython constant optimisations in the compile stage.
There is also the addition of the "opt_level" function to change the
parser/compiler optimisation level at runtime.
The behaviour of "sys.exit" (and "raise SystemExit") on baremetal is now
changed: this function no longer does a soft-reset of the board, rather it
just stops the running script and drops to the REPL. In order to do an
actual soft reset the "machine.soft_reset" function has been added (to the
stmhal port only, for the time being).
Following CPython, KeyError exceptions for dictionary lookups now have the
failed key stored as the argument of the exception instance, accessible as
exc.args[0]. The "ujson.load" function has also been added, to load JSON
data from an arbitrary stream.
The I2C support in the machine module now has clock stretching, the
addition of the "addrsize" parameter in memory transfer methods, and I2C
scanning now uses dummy writes instead of dummy reads to make the scanning
more reliable.
The CMSIS library has been upgrade to v4.30, and the boards section of
the stmhal port has been refactored to use a common.ld script. The stmhal
port now has a full implementation of the machine.SPI class, with support
for both hardware SPI peripherals and fast software SPI. The USB HID
driver in stmhal has added support to receive USB HID messages from the
host.
py core:
- asmthumb: flush D-cache, and invalidate I-cache on STM32F7
- makeqstrdefs.py: use python 2.6 syntax for set creation
- objnone: remove unnecessary handling of MP_UNARY_OP_BOOL
- move frozen modules rules from esp8266 port for reuse across ports
- combine 3 comprehension emit functions (list/dict/set) into 1
- combine 3 comprehension opcodes (list/dict/set) into 1
- vstr: remove vstr.had_error flag and inline basic vstr functions
- objnone: use mp_generic_unary_op instead of custom one
- showbc: make printf's go to the platform print stream
- remove 'name' member from mp_obj_module_t struct
- builtinimport: fix nanbox build after change to better handle -m modules
- stream: remove unnecessary check for NULL return from vstr_extend
- py.mk: suppress some compiler warnings when building berkeley-db
- shrink mp_arg_t struct by using reduced-size integer members
- update opcode format table because 3 opcodes were removed, 1 added
- parse: only replace constants that are standalone identifiers
- py.mk: add support for building modussl_mbedtls
- only store the exception instance on Py stack in bytecode try block
- vm: use MP_OBJ_FROM_PTR to cast a type to an object
- modmicropython: add micropython.const, alias for identity function
- objstr: remove unreachable function used only for terse error msgs
- emitbc: remove/refactor unreachable code, to improve coverage
- objfun: remove unnecessary check for viper fun with 5 or more args
- objfun: use if instead of switch to check return value of VM execute
- objset: use mp_check_self() to check args of set/frozenset methods
- objset: ensure that use of frozenset.update raises an exception
- compile: fix async-for/async-with to work with simpler exc on stack
- scope: use lookup-table to determine a scope's simple name
- scope: shrink scope_t struct by 1 machine word
- scope: factor common code to find locals and close over them
- compile: fix typo when checking for parse-node kind
- argcheck: simplify if-chain so that the last one is the default
- objbool: defer bool's unary op implementation to small int
- objbool: make a slight simplification of bool constructor
- modstruct: remove unreachable code, and add comment about CPy diff
- add mp_raise_OSError(errno) helper function
- objstringio: add readinto() method
- modmicropython: add micropython.opt_level([value]) function
- compile: remove unreachable code
- mpz: in divmod, replace check for rhs!=0 with assert
- mpz: use assert to verify mpz does not have a fixed digit buffer
- factor duplicated function to calculate size of formatted int
- objint: use size_t for arguments that measure bytes/sizes
- compile: remove debugging code for compiler dispatch
- lexer: remove unnecessary code, and unreachable code
- vstr: combine vstr_new_size with vstr_new since they are rarely used
- objdict: fix optimisation for allocating result in fromkeys
- objdict: actually provide the key that failed in KeyError exception
- use mp_raise_msg helper function where appropriate
- add the module specified by -m to sys.modules as '__main__'
extmod:
- modussl_mbedtls: initial implementation of mbedTLS ussl module
- uctypes: allow full 32-bit address range
- modubinascii: fix crc32() function on 32-bit platforms
- modussl_mbedtls: implement key= and cert= args to wrap_socket()
- modussl_mbedtls: use 2-component include paths
- machine_i2c: add clock stretching support
- modussl_mbedtls: add server_hostname param for wrap_socket()
- uzlib: add tinfgzip.c (gzip header parsing) from upstream
- moduzlib: DecompIO: Add support for gzip-formatted streams
- uzlib/: update uzlib to v2.0.3
- vfs_fat: add fat_vfs_statvfs(), reused from stmhal
- machine_i2c: add support for the addrsize parameter in mem xfers
- machine_spi: simplify SPI xfer function to only take one buf len
- machine_spi: factor out software SPI code from esp8266 to extmod
- machine_spi: use delay_half, not baudrate, for internal timing
- machine_spi: add optional support for fast software SPI
- vfs_fat: use mp_raise_OSError helper function
- modlwip: use mp_raise_OSError helper function
- use mp_raise_OSError helper function
- vfs_fat_file: use MP_Exxx errno constants
- uzlib: update to upstream v2.1
- machine_i2c: use writes not reads in i2c.scan()
- vfs_fat: add file and directory checks for remove and rmdir
- modujson: implement ujson.load() to load JSON from a stream
- modujson: fix nanbox build
- utime_mphal: factor out implementations in terms of mp_hal_* for reuse
- utime_mphal: sleep_us/ms(): Don't wait on negative argument
- modussl_mbedtls: add dummy setblocking() method
lib:
- interrupt_char: factor out typical Ctrl+C handling from esp8266 port
- cmsis: move CMSIS headers to lib/
- cmsis: remove CMSIS-DSP headers, they are unused
- cmsis: upgrade CMSIS-CORE to V4.30
- utils/pyexec: don't treat SystemExit as "forced exit"
- utils/pyexec: allow behaviour of SystemExit to be configurable
drivers:
- dht: use mp_raise_OSError helper function
tools:
- update upip to 0.8, fixes IPv6 support
- upgrade upip to 1.0, fully self-hosted release (without fallbacks), and
uses stream gzip decompression (step towards support for limited-heap
baremetal systems)
- upgrade upip to 1.1.3, initial support for running on a baremetal,
low-heap systems (like esp8266), using Python module interface
tests:
- pyb: add test for ExtInt when doing swint while disabled
- pyb: update exp file for previously updated extint test
- extmod/urandom: add urandom tests for error cases
- basics: add errno1 test, to check basics of uerrno module
- extmod: add test for machine.time_pulse_us()
- struct1: test "l" specifier to improve coverage
- array1: add tests for "l", "L" array types to improve coverage
- get cmdline verbose tests running again
- run-tests: add --via-mpy option to run test from precompiled code
- uzlib_decompio_gz: test for DecompIO with gzip bitstream
- basics: add test case for overflowing Py stack in try-finally
- micropython: add tests for const names being replaced in parser
- cmdline/cmd_showbc: fix test now that 1 value is stored on stack
- extmod/vfs_fat_ramdisk: add test for VFS.statvfs()
- float: add test for parsing a float from an empty string
- basics: add test for set.difference_update with arg being itself
- basics: add further tests for nonlocal scoping and closures
- import: add test for compiling "import a.b as c"
- basics: add test constructing a set from a non-trivial expression
- basics: add test for printing OSError when errno is unknown
- run-tests: disable cmdline/cmd_showbc test on Windows
- extmod/btree1: checks for put, seq, string print and unsupported binary op
- fix expected output of verbose cmdline test
- extmod/uzlib: test adaptive huffman tree for tinflate coverage
- improve coverage of struct with test for non-compliant behaviour
- io/write_ext: add description comment
- io/bytesio_ext: add test for readinto()
- micropython: add test for micropython.opt_level() function
- improve test coverage of py/compile.c
- extmod/vfs_fat: test coverage for remove() and rmdir()
- extmod: add test for ujson.load()
- extmod/vfs_fat: replace asserts with prints and expected outputs
- micropython: add tests for heap_lock, and emergency exceptions
- cmdline: improve coverage test for printing bytecode
- improve coverage of array, range, dict, slice, exc, unicode
- add test to print full KeyError exc from failed dict lookup
- run-tests: enable extmod/machine1.py on pyboard
unix port:
- fix build for when MICROPY_PY_SOCKET=0
- modjni: implement subscription for object arrays
- modjni: add array() top-level function to create Java array
- modjni: array(): Support creation of object arrays
- enable btree module for coverage build
- use mp_raise_OSError helper function
- use common RAISE_ERRNO macro from mphalport.h
windows port:
- enable MICROPY_PY_UERRNO
qemu-arm port:
- enable lots of extmods and enable tests for them
stmhal port:
- lcd: de-assert chip select after completing SPI transmission
- {accel,lcd}: use GPIO_{set,clear}_pin
- extint: force 0 to 1 transition on swint()
- boards: add pllvalues.py script to compute PLL values for sysclk
- boards: for OLIMEX_E407, enable UART1 and fix I2C1 mapping
- use attribute to avoid inlining
- put common definitions from linker files to common.ld
- remove STM32CubeF2 HAL files, they are unused/unsupported
- modmachine: fix clearing of reset-cause flags
- add virtual com port support for STM32L476DISC
- remove CMSIS STM32F2xx files, they are unused/unsupported
- spi: simplify spi_transfer function to take only one buf len arg
- mphalport: implement mp_hal_pin_{input,output,write}
- spi: make machine.SPI class conform to correct API
- mphalport: fix mp_hal_pin_write to use correct pin_mask
- spi: use software SPI if no periph id given, even if pins given
- spi: enable use of fast software SPI
- fix linker map for STM32L476 chips
- usbdev: add OUT endpoint to HID interface
- usb: add support to receive USB HID messages from host
- usb: use correct ClassData structure for HID receive
- usb: use real packet size (not maximum) in HID receive
- fix ESPRUINO_PICO by adding ld scripts with correct flash size
- mphalport: change pin obj type to const pointer, to avoid casts
- moduos: implement total-number-of-blocks field in statvfs
- disable network and usocket for ESPRUINO_PICO
- enable machine.time_pulse_us() function
- use mp_raise_OSError helper function
- pybstdio: use size_t instead of mp_uint_t
- modutime: refactor to use extmod/utime_mphal.c
- implement machine.soft_reset()
- enable str.center(), str.[r]partition() and builtin compile()
cc3200 port:
- add ssl_version argument to ssl.wrap_socket()
esp8266 port:
- Makefile: rename SCRIPTDIR to FROZEN_DIR for consistency with FROZEN_MPY_DIR
- ets_alt_task: ets_post: Should return 0 on success, !0 - failure
- esp_mphal: add tentative change to mp_hal_stdin_rx_chr() to wait IRQ
- extend system microsecond counter to 64-bits; use in ticks_ms
- add uos.statvfs() to get filesystem status
- moduos: move stat/statvfs funcs to sit within #if VFS guard
- modmachine: idle(): Return number of CPU cycles spent idling
- main: put /lib before / in sys.path
- modpybrtc.c: implement machine.RTC.alarm_left()
- make PY_UHASHLIB_SHA1 config depend on PY_USSL and SSL_AXTLS
- add FLASH_MODE,FLASH_SIZE options for make deploy target
- use mp_raise_OSError helper function
- make neopixel support configurable
- mpconfigport: enable MICROPY_PY_BUILTINS_SLICE_ATTRS
- enable sys.{stdin,stdout,stderr}.buffer for raw serial access
- enable importing of precompiled .mpy files
- enable micropython.alloc_emergency_exception_buf()
zephyr port:
- initial Zephyr RTOS port, MicroPython part
- initial Zephyr RTOS port, Zephyr part
- add zephyr_getchar module to handle console input
- switch to microkernel, required for network to work in background
- automatically derive ARCH
- support extra make targets
- Makefile: automatically derive target-specific CFLAGS
- use recently added "make outputexports" Zephyr target
- add README
- enable stack checking and micropython.mem_info()
- enable frozen modules support
- main: execute main.py frozen module on boot, if available
- zephyr_getchar: add support for Ctrl+C handling
- add Ctrl+C handling
- implement the help() function
- add copyright blurbs
README:
- remove issue-stats badges, the service is no longer available
- mention _thread module availability in select ports
docs:
- library/pyb.SPI: init(): describe "bits" argument
- library/machine: update description of disable/enable IRQ funcs
- uos: add uos.statvfs() documentation
- wipy: correct deep sleep current figure
- wipy: small doc fixes
- reference: add constrained.rst doc
travis:
- abandon mingw32 in favour of mingw-w64
- run feature and coverage test for precompiled mpy files
examples:
- network/http_client*: use \r\n line-endings in request
Diffstat (limited to 'esp8266')
-rw-r--r-- | esp8266/Makefile | 18 | ||||
-rw-r--r-- | esp8266/README.md | 5 | ||||
-rw-r--r-- | esp8266/esp_mphal.c | 19 | ||||
-rw-r--r-- | esp8266/esp_mphal.h | 2 | ||||
-rw-r--r-- | esp8266/espneopixel.c | 5 | ||||
-rw-r--r-- | esp8266/ets_alt_task.c | 16 | ||||
-rw-r--r-- | esp8266/ets_alt_task.h | 2 | ||||
-rw-r--r-- | esp8266/main.c | 6 | ||||
-rw-r--r-- | esp8266/modesp.c | 13 | ||||
-rw-r--r-- | esp8266/modmachine.c | 5 | ||||
-rw-r--r-- | esp8266/modnetwork.c | 1 | ||||
-rw-r--r-- | esp8266/modonewire.c | 1 | ||||
-rw-r--r-- | esp8266/modpybhspi.c | 32 | ||||
-rw-r--r-- | esp8266/modpybrtc.c | 16 | ||||
-rw-r--r-- | esp8266/modpybspi.c | 78 | ||||
-rw-r--r-- | esp8266/moduos.c | 19 | ||||
-rw-r--r-- | esp8266/modutime.c | 63 | ||||
-rw-r--r-- | esp8266/mpconfigport.h | 8 | ||||
-rw-r--r-- | esp8266/uart.c | 4 |
19 files changed, 126 insertions, 187 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile index 433b41ecfd..65a513afd6 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -12,12 +12,13 @@ include ../py/py.mk MPY_CROSS = ../mpy-cross/mpy-cross MPY_TOOL = ../tools/mpy-tool.py -MAKE_FROZEN = ../tools/make-frozen.py -SCRIPTDIR = scripts +FROZEN_DIR = scripts FROZEN_MPY_DIR = modules PORT ?= /dev/ttyACM0 BAUD ?= 115200 +FLASH_MODE ?= qio +FLASH_SIZE ?= 8m CROSS_COMPILE = xtensa-lx106-elf- ESP_SDK = $(shell $(CC) -print-sysroot)/usr @@ -128,6 +129,7 @@ LIB_SRC_C = $(addprefix lib/,\ timeutils/timeutils.c \ utils/pyexec.c \ utils/pyhelp.c \ + utils/interrupt_char.c \ fatfs/ff.c \ fatfs/option/ccsbcs.c \ ) @@ -164,16 +166,14 @@ CONFVARS_FILE = $(BUILD)/confvars ifeq ($(wildcard $(CONFVARS_FILE)),) $(shell $(MKDIR) -p $(BUILD)) -$(shell echo $(SCRIPTDIR) $(UART_OS) > $(CONFVARS_FILE)) -else ifneq ($(shell cat $(CONFVARS_FILE)), $(SCRIPTDIR) $(UART_OS)) -$(shell echo $(SCRIPTDIR) $(UART_OS) > $(CONFVARS_FILE)) +$(shell echo $(FROZEN_DIR) $(UART_OS) > $(CONFVARS_FILE)) +else ifneq ($(shell cat $(CONFVARS_FILE)), $(FROZEN_DIR) $(UART_OS)) +$(shell echo $(FROZEN_DIR) $(UART_OS) > $(CONFVARS_FILE)) endif $(BUILD)/uart.o: $(CONFVARS_FILE) -$(BUILD)/frozen.c: $(wildcard $(SCRIPTDIR)/*) $(CONFVARS_FILE) - $(ECHO) "Generating $@" - $(Q)$(MAKE_FROZEN) $(SCRIPTDIR) > $@ +FROZEN_EXTRA_DEPS = $(CONFVARS_FILE) # to build .mpy files from .py files $(BUILD)/$(FROZEN_MPY_DIR)/%.mpy: $(FROZEN_MPY_DIR)/%.py @@ -190,7 +190,7 @@ $(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generate deploy: $(BUILD)/firmware-combined.bin $(ECHO) "Writing $< to the board" - $(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --verify --flash_size=8m 0 $< + $(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --verify --flash_size=$(FLASH_SIZE) --flash_mode=$(FLASH_MODE) 0 $< #$(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --flash_size=8m 0 $(BUILD)/firmware.elf-0x00000.bin 0x9000 $(BUILD)/firmware.elf-0x0[1-f]000.bin reset: diff --git a/esp8266/README.md b/esp8266/README.md index b9162e9585..c998b7ad18 100644 --- a/esp8266/README.md +++ b/esp8266/README.md @@ -70,9 +70,10 @@ $ make deploy ``` This will use the `esptool.py` script to download the images. You must have your ESP module in the bootloader mode, and connected to a serial port on your PC. -The default serial port is `/dev/ttyACM0`. To specify another, use, eg: +The default serial port is `/dev/ttyACM0`, flash mode is `qio` and flash size is `8m`. +To specify other values, use, eg: ```bash -$ make PORT=/dev/ttyUSB0 deploy +$ make PORT=/dev/ttyUSB0 FLASH_MODE=qio FLASH_SIZE=8m deploy ``` The image produced is `firmware-combined.bin`, to be flashed at 0x00000. diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index dc6944fd4c..f5e284fde6 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -60,7 +60,14 @@ int mp_hal_stdin_rx_chr(void) { if (c != -1) { return c; } + #if 0 + // Idles CPU but need more testing before enabling + if (!ets_loop_iter()) { + asm("waiti 0"); + } + #else mp_hal_delay_us(1); + #endif } } @@ -110,7 +117,7 @@ void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len) { } uint32_t mp_hal_ticks_ms(void) { - return system_get_time() / 1000; + return ((uint64_t)system_time_high_word << 32 | (uint64_t)system_get_time()) / 1000; } uint32_t mp_hal_ticks_us(void) { @@ -121,14 +128,6 @@ void mp_hal_delay_ms(uint32_t delay) { mp_hal_delay_us(delay * 1000); } -void mp_hal_set_interrupt_char(int c) { - if (c != -1) { - mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_kbd_exception)); - } - extern int interrupt_char; - interrupt_char = c; -} - void ets_event_poll(void) { ets_loop_iter(); if (MP_STATE_VM(mp_pending_exception) != NULL) { @@ -173,7 +172,7 @@ static int call_dupterm_read(void) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(MP_STATE_PORT(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ); nlr_pop(); - if (*(byte*)bufinfo.buf == interrupt_char) { + if (*(byte*)bufinfo.buf == mp_interrupt_char) { mp_keyboard_interrupt(); return -2; } diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h index fa52ae53a2..7a71c0f032 100644 --- a/esp8266/esp_mphal.h +++ b/esp8266/esp_mphal.h @@ -28,10 +28,10 @@ #define _INCLUDED_MPHAL_H_ #include "py/ringbuf.h" +#include "lib/utils/interrupt_char.h" #include "xtirq.h" void mp_keyboard_interrupt(void); -extern int interrupt_char; struct _mp_print_t; // Structure for UART-only output via mp_printf() diff --git a/esp8266/espneopixel.c b/esp8266/espneopixel.c index e16c874f23..27c7731064 100644 --- a/esp8266/espneopixel.c +++ b/esp8266/espneopixel.c @@ -5,6 +5,9 @@ // ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus // Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution. +#include "py/mpconfig.h" +#if MICROPY_ESP8266_NEOPIXEL + #include "c_types.h" #include "eagle_soc.h" #include "user_interface.h" @@ -58,3 +61,5 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32 while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit mp_hal_quiet_timing_exit(irq_state); } + +#endif // MICROPY_ESP8266_NEOPIXEL diff --git a/esp8266/ets_alt_task.c b/esp8266/ets_alt_task.c index 62872affb9..6434f23660 100644 --- a/esp8266/ets_alt_task.c +++ b/esp8266/ets_alt_task.c @@ -87,7 +87,7 @@ bool ets_post(uint8 prio, os_signal_t sig, os_param_t param) { if (emu_tasks[id].i_put == -1) { // queue is full printf("ets_post: task %d queue full\n", prio); - return false; + return 1; } q = &q[emu_tasks[id].i_put++]; q->sig = sig; @@ -104,16 +104,28 @@ bool ets_post(uint8 prio, os_signal_t sig, os_param_t param) { ets_intr_unlock(); - return true; + return 0; #endif } int ets_loop_iter_disable = 0; +// to implement a 64-bit wide microsecond counter +static uint32_t system_time_prev = 0; +uint32_t system_time_high_word = 0; + bool ets_loop_iter(void) { if (ets_loop_iter_disable) { return false; } + + // handle overflow of system microsecond counter + uint32_t system_time_cur = system_get_time(); + if (system_time_cur < system_time_prev) { + system_time_high_word += 1; // record overflow of low 32-bits + } + system_time_prev = system_time_cur; + //static unsigned cnt; bool progress = false; for (volatile struct task_entry *t = emu_tasks; t < &emu_tasks[MP_ARRAY_SIZE(emu_tasks)]; t++) { diff --git a/esp8266/ets_alt_task.h b/esp8266/ets_alt_task.h index 4b5ba26dbd..dba0c5fa64 100644 --- a/esp8266/ets_alt_task.h +++ b/esp8266/ets_alt_task.h @@ -1,2 +1,4 @@ extern int ets_loop_iter_disable; +extern uint32_t system_time_high_word; + bool ets_loop_iter(void); diff --git a/esp8266/main.c b/esp8266/main.c index 71dfeb2ac6..c938dcb30b 100644 --- a/esp8266/main.c +++ b/esp8266/main.c @@ -49,8 +49,8 @@ STATIC void mp_reset(void) { mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) - mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_)); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib)); + mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_)); mp_obj_list_init(mp_sys_argv, 0); #if MICROPY_VFS_FAT memset(MP_STATE_PORT(fs_user_mount), 0, sizeof(MP_STATE_PORT(fs_user_mount))); @@ -141,10 +141,6 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); -void mp_keyboard_interrupt(void) { - MP_STATE_VM(mp_pending_exception) = MP_STATE_PORT(mp_kbd_exception); -} - void nlr_jump_fail(void *val) { printf("NLR jump failed\n"); for (;;) { diff --git a/esp8266/modesp.c b/esp8266/modesp.c index 39cc514afc..515319c9e0 100644 --- a/esp8266/modesp.c +++ b/esp8266/modesp.c @@ -583,7 +583,7 @@ STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t len_or_buf_in) { if (alloc_buf) { m_del(byte, buf, len); } - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO))); + mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_read_obj, esp_flash_read); @@ -598,9 +598,7 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) { if (res == SPI_FLASH_RESULT_OK) { return mp_const_none; } - nlr_raise(mp_obj_new_exception_arg1( - &mp_type_OSError, - MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO))); + mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_write_obj, esp_flash_write); @@ -610,9 +608,7 @@ STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) { if (res == SPI_FLASH_RESULT_OK) { return mp_const_none; } - nlr_raise(mp_obj_new_exception_arg1( - &mp_type_OSError, - MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO))); + mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase); @@ -714,7 +710,9 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&esp_socket_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&esp_getaddrinfo_obj }, #endif + #if MICROPY_ESP8266_NEOPIXEL { MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write), (mp_obj_t)&esp_neopixel_write_obj }, + #endif #if MICROPY_ESP8266_APA102 { MP_OBJ_NEW_QSTR(MP_QSTR_apa102_write), (mp_obj_t)&esp_apa102_write_obj }, #endif @@ -748,6 +746,5 @@ STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table); const mp_obj_module_t esp_module = { .base = { &mp_type_module }, - .name = MP_QSTR_esp, .globals = (mp_obj_dict_t*)&esp_module_globals, }; diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c index b0b7f3a1a3..0ab3c122b7 100644 --- a/esp8266/modmachine.c +++ b/esp8266/modmachine.c @@ -86,8 +86,10 @@ STATIC mp_obj_t machine_unique_id(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); STATIC mp_obj_t machine_idle(void) { + uint32_t t = mp_hal_ticks_cpu(); asm("waiti 0"); - return mp_const_none; + t = mp_hal_ticks_cpu() - t; + return MP_OBJ_NEW_SMALL_INT(t); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); @@ -271,7 +273,6 @@ STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table const mp_obj_module_t mp_module_machine = { .base = { &mp_type_module }, - .name = MP_QSTR_umachine, .globals = (mp_obj_dict_t*)&machine_module_globals, }; diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c index 7031197fa5..86bf27ca66 100644 --- a/esp8266/modnetwork.c +++ b/esp8266/modnetwork.c @@ -484,6 +484,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals const mp_obj_module_t network_module = { .base = { &mp_type_module }, - .name = MP_QSTR_network, .globals = (mp_obj_dict_t*)&mp_module_network_globals, }; diff --git a/esp8266/modonewire.c b/esp8266/modonewire.c index 0fcf1ab6a6..0d8958ceee 100644 --- a/esp8266/modonewire.c +++ b/esp8266/modonewire.c @@ -117,6 +117,5 @@ STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table const mp_obj_module_t onewire_module = { .base = { &mp_type_module }, - .name = MP_QSTR_onewire, .globals = (mp_obj_dict_t*)&onewire_module_globals, }; diff --git a/esp8266/modpybhspi.c b/esp8266/modpybhspi.c index c1cd7f662d..10a090269f 100644 --- a/esp8266/modpybhspi.c +++ b/esp8266/modpybhspi.c @@ -50,23 +50,23 @@ typedef struct _pyb_hspi_obj_t { } pyb_hspi_obj_t; -STATIC void hspi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t *src_buf, size_t dest_len, uint8_t *dest_buf) { +STATIC void hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { (void)self_in; - if (dest_len == 0) { + if (dest == NULL) { // fast case when we only need to write data size_t chunk_size = 1024; - size_t count = src_len / chunk_size; + size_t count = len / chunk_size; size_t i = 0; for (size_t j = 0; j < count; ++j) { for (size_t k = 0; k < chunk_size; ++k) { - spi_tx8fast(HSPI, src_buf[i]); + spi_tx8fast(HSPI, src[i]); ++i; } ets_loop_iter(); } - while (i < src_len) { - spi_tx8fast(HSPI, src_buf[i]); + while (i < len) { + spi_tx8fast(HSPI, src[i]); ++i; } } else { @@ -74,29 +74,17 @@ STATIC void hspi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t // Process data in chunks, let the pending tasks run in between size_t chunk_size = 1024; // TODO this should depend on baudrate - size_t count = dest_len / chunk_size; + size_t count = len / chunk_size; size_t i = 0; for (size_t j = 0; j < count; ++j) { for (size_t k = 0; k < chunk_size; ++k) { - uint32_t data_out; - if (src_len == 1) { - data_out = src_buf[0]; - } else { - data_out = src_buf[i]; - } - dest_buf[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, data_out, 8, 0); + dest[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, src[i], 8, 0); ++i; } ets_loop_iter(); } - while (i < dest_len) { - uint32_t data_out; - if (src_len == 1) { - data_out = src_buf[0]; - } else { - data_out = src_buf[i]; - } - dest_buf[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, data_out, 8, 0); + while (i < len) { + dest[i] = spi_transaction(HSPI, 0, 0, 0, 0, 8, src[i], 8, 0); ++i; } } diff --git a/esp8266/modpybrtc.c b/esp8266/modpybrtc.c index 500b2bc545..d69fc47a8e 100644 --- a/esp8266/modpybrtc.c +++ b/esp8266/modpybrtc.c @@ -219,6 +219,21 @@ STATIC mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time } STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_rtc_alarm_obj, pyb_rtc_alarm); +STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { + // check we want alarm0 + if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { + mp_raise_ValueError("invalid alarm"); + } + + uint64_t now = pyb_rtc_get_us_since_2000(); + if (pyb_rtc_alarm0_expiry <= now) { + return MP_OBJ_NEW_SMALL_INT(0); + } else { + return mp_obj_new_int((pyb_rtc_alarm0_expiry - now) / 1000); + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left); + STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_trigger, ARG_wake }; static const mp_arg_t allowed_args[] = { @@ -244,6 +259,7 @@ STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_datetime), (mp_obj_t)&pyb_rtc_datetime_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_memory), (mp_obj_t)&pyb_rtc_memory_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_alarm), (mp_obj_t)&pyb_rtc_alarm_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_left), (mp_obj_t)&pyb_rtc_alarm_left_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_rtc_irq_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_ALARM0), MP_OBJ_NEW_SMALL_INT(0) }, }; diff --git a/esp8266/modpybspi.c b/esp8266/modpybspi.c index 4c4b843c5d..e974547111 100644 --- a/esp8266/modpybspi.c +++ b/esp8266/modpybspi.c @@ -28,73 +28,35 @@ #include <stdint.h> #include <string.h> -#include "ets_sys.h" -#include "etshal.h" -#include "ets_alt_task.h" - #include "py/runtime.h" #include "py/stream.h" #include "py/mphal.h" #include "extmod/machine_spi.h" -typedef struct _pyb_spi_obj_t { - mp_obj_base_t base; - uint32_t baudrate; - uint8_t polarity; - uint8_t phase; - mp_hal_pin_obj_t sck; - mp_hal_pin_obj_t mosi; - mp_hal_pin_obj_t miso; -} pyb_spi_obj_t; +/******************************************************************************/ +// MicroPython bindings for SPI -STATIC void mp_hal_spi_transfer(mp_obj_base_t *self_in, size_t src_len, const uint8_t *src_buf, size_t dest_len, uint8_t *dest_buf) { - pyb_spi_obj_t *self = (pyb_spi_obj_t*)self_in; - // only MSB transfer is implemented - uint32_t delay_half = 500000 / self->baudrate + 1; - for (size_t i = 0; i < src_len || i < dest_len; ++i) { - uint8_t data_out; - if (src_len == 1) { - data_out = src_buf[0]; - } else { - data_out = src_buf[i]; - } - uint8_t data_in = 0; - for (int j = 0; j < 8; ++j, data_out <<= 1) { - mp_hal_pin_write(self->mosi, (data_out >> 7) & 1); - if (self->phase == 0) { - ets_delay_us(delay_half); - mp_hal_pin_write(self->sck, 1 - self->polarity); - } else { - mp_hal_pin_write(self->sck, 1 - self->polarity); - ets_delay_us(delay_half); - } - data_in = (data_in << 1) | mp_hal_pin_read(self->miso); - if (self->phase == 0) { - ets_delay_us(delay_half); - mp_hal_pin_write(self->sck, self->polarity); - } else { - mp_hal_pin_write(self->sck, self->polarity); - ets_delay_us(delay_half); - } - } - if (dest_len != 0) { - dest_buf[i] = data_in; - } - // make sure pending tasks have a chance to run - ets_loop_iter(); - } +STATIC uint32_t baudrate_from_delay_half(uint32_t delay_half) { + return 500000 / delay_half; } -/******************************************************************************/ -// MicroPython bindings for SPI +STATIC uint32_t baudrate_to_delay_half(uint32_t baudrate) { + uint32_t delay_half = 500000 / baudrate; + // round delay_half up so that: actual_baudrate <= requested_baudrate + if (500000 % baudrate != 0) { + delay_half += 1; + } + return delay_half; +} STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - pyb_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_machine_soft_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SPI(baudrate=%u, polarity=%u, phase=%u, sck=%u, mosi=%u, miso=%u)", - self->baudrate, self->polarity, self->phase, self->sck, self->mosi, self->miso); + baudrate_from_delay_half(self->delay_half), + self->polarity, self->phase, self->sck, self->mosi, self->miso); } -STATIC void pyb_spi_init_helper(pyb_spi_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC void pyb_spi_init_helper(mp_machine_soft_spi_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_sck, ARG_mosi, ARG_miso }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = -1} }, @@ -108,7 +70,7 @@ STATIC void pyb_spi_init_helper(pyb_spi_obj_t *self, size_t n_args, const mp_obj mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); if (args[ARG_baudrate].u_int != -1) { - self->baudrate = args[ARG_baudrate].u_int; + self->delay_half = baudrate_to_delay_half(args[ARG_baudrate].u_int); } if (args[ARG_polarity].u_int != -1) { self->polarity = args[ARG_polarity].u_int; @@ -135,10 +97,10 @@ STATIC void pyb_spi_init_helper(pyb_spi_obj_t *self, size_t n_args, const mp_obj mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true); - pyb_spi_obj_t *self = m_new_obj(pyb_spi_obj_t); + mp_machine_soft_spi_obj_t *self = m_new_obj(mp_machine_soft_spi_obj_t); self->base.type = &pyb_spi_type; // set defaults - self->baudrate = 500000; + self->delay_half = baudrate_to_delay_half(500000); self->polarity = 0; self->phase = 0; self->sck = 14; @@ -167,7 +129,7 @@ STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table); STATIC const mp_machine_spi_p_t pyb_spi_p = { - .transfer = mp_hal_spi_transfer, + .transfer = mp_machine_soft_spi_transfer, }; const mp_obj_type_t pyb_spi_type = { diff --git a/esp8266/moduos.c b/esp8266/moduos.c index bbbf2b6b8b..e9c4c3e8cc 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -74,7 +74,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname); #if MICROPY_VFS_FAT mp_obj_t vfs_proxy_call(qstr method_name, mp_uint_t n_args, const mp_obj_t *args) { if (MP_STATE_PORT(fs_user_mount)[0] == NULL) { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENODEV))); + mp_raise_OSError(MP_ENODEV); } mp_obj_t meth[n_args + 2]; @@ -123,6 +123,16 @@ STATIC mp_obj_t os_rename(mp_obj_t path_old, mp_obj_t path_new) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename); +STATIC mp_obj_t os_stat(mp_obj_t path_in) { + return vfs_proxy_call(MP_QSTR_stat, 1, &path_in); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat); + +STATIC mp_obj_t os_statvfs(mp_obj_t path_in) { + return vfs_proxy_call(MP_QSTR_statvfs, 1, &path_in); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_statvfs_obj, os_statvfs); + STATIC mp_obj_t os_umount(void) { return vfs_proxy_call(MP_QSTR_umount, 0, NULL); } @@ -147,11 +157,6 @@ STATIC mp_obj_t os_dupterm_notify(mp_obj_t obj_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_dupterm_notify_obj, os_dupterm_notify); -STATIC mp_obj_t os_stat(mp_obj_t path_in) { - return vfs_proxy_call(MP_QSTR_stat, 1, &path_in); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat); - STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) }, { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) }, @@ -170,6 +175,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) }, { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&os_rename_obj) }, { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_stat_obj) }, + { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&os_statvfs_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&os_umount_obj) }, #endif }; @@ -178,6 +184,5 @@ STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); const mp_obj_module_t uos_module = { .base = { &mp_type_module }, - .name = MP_QSTR_uos, .globals = (mp_obj_dict_t*)&os_module_globals, }; diff --git a/esp8266/modutime.c b/esp8266/modutime.c index bf56feb5ce..abfe069cc3 100644 --- a/esp8266/modutime.c +++ b/esp8266/modutime.c @@ -38,6 +38,7 @@ #include "modpybrtc.h" #include "timeutils.h" #include "user_interface.h" +#include "extmod/utime_mphal.h" /// \module time - time related functions /// @@ -99,53 +100,6 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) { } MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); -/// \function sleep(seconds) -/// Sleep for the given number of seconds. -STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { - #if MICROPY_PY_BUILTINS_FLOAT - mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o)); - #else - mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o)); - #endif - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep); - -STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { - mp_hal_delay_ms(mp_obj_get_int(arg)); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_ms_obj, time_sleep_ms); - -STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { - mp_hal_delay_us(mp_obj_get_int(arg)); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_us_obj, time_sleep_us); - -STATIC mp_obj_t time_ticks_ms(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_ms_obj, time_ticks_ms); - -STATIC mp_obj_t time_ticks_us(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us); - -STATIC mp_obj_t time_ticks_cpu(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu); - -STATIC mp_obj_t time_ticks_diff(mp_obj_t start_in, mp_obj_t end_in) { - // we assume that the arguments come from ticks_xx so are small ints - uint32_t start = MP_OBJ_SMALL_INT_VALUE(start_in); - uint32_t end = MP_OBJ_SMALL_INT_VALUE(end_in); - return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff); - /// \function time() /// Returns the number of seconds, as an integer, since 1/1/2000. STATIC mp_obj_t time_time(void) { @@ -159,13 +113,13 @@ STATIC const mp_map_elem_t time_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_localtime), (mp_obj_t)&time_localtime_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mktime), (mp_obj_t)&time_mktime_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&time_sleep_ms_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&time_sleep_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&time_ticks_ms_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&time_ticks_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&time_ticks_cpu_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&time_ticks_diff_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&mp_utime_sleep_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&mp_utime_sleep_ms_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&mp_utime_sleep_us_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&mp_utime_ticks_ms_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&mp_utime_ticks_us_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&mp_utime_ticks_cpu_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&mp_utime_ticks_diff_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_time_obj }, }; @@ -173,6 +127,5 @@ STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); const mp_obj_module_t utime_module = { .base = { &mp_type_module }, - .name = MP_QSTR_utime, .globals = (mp_obj_dict_t*)&time_module_globals, }; diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 4fc8d856b6..201057f128 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -9,6 +9,7 @@ #define MICROPY_ALLOC_PARSE_RULE_INC (8) #define MICROPY_ALLOC_PARSE_RESULT_INC (8) #define MICROPY_ALLOC_PARSE_CHUNK_INIT (64) +#define MICROPY_PERSISTENT_CODE_LOAD (1) #define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) @@ -17,6 +18,7 @@ #define MICROPY_DEBUG_PRINTER_DEST mp_debug_print #define MICROPY_ENABLE_GC (1) #define MICROPY_STACK_CHECK (1) +#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_REPL_EVENT_DRIVEN (0) #define MICROPY_REPL_AUTO_INDENT (1) #define MICROPY_HELPER_REPL (1) @@ -33,6 +35,7 @@ #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_SET (1) #define MICROPY_PY_BUILTINS_SLICE (1) +#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) #define MICROPY_PY_BUILTINS_PROPERTY (1) #define MICROPY_PY___FILE__ (0) #define MICROPY_PY_GC (1) @@ -49,15 +52,17 @@ #define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_STDFILES (1) +#define MICROPY_PY_SYS_STDIO_BUFFER (1) #define MICROPY_PY_UERRNO (1) #define MICROPY_PY_UBINASCII (1) #define MICROPY_PY_UCTYPES (1) #define MICROPY_PY_UHASHLIB (1) -#define MICROPY_PY_UHASHLIB_SHA1 (1) +#define MICROPY_PY_UHASHLIB_SHA1 (MICROPY_PY_USSL && MICROPY_SSL_AXTLS) #define MICROPY_PY_UHEAPQ (1) #define MICROPY_PY_UJSON (1) #define MICROPY_PY_URANDOM (1) #define MICROPY_PY_URE (1) +#define MICROPY_PY_UTIME_MP_HAL (1) #define MICROPY_PY_UZLIB (1) #define MICROPY_PY_LWIP (1) #define MICROPY_PY_MACHINE (1) @@ -91,6 +96,7 @@ #define MICROPY_FSUSERMOUNT (1) #define MICROPY_VFS_FAT (1) #define MICROPY_ESP8266_APA102 (1) +#define MICROPY_ESP8266_NEOPIXEL (1) #define MICROPY_EVENT_POLL_HOOK {ets_event_poll();} #define MICROPY_VM_HOOK_COUNT (10) diff --git a/esp8266/uart.c b/esp8266/uart.c index d724331c41..001a9c673c 100644 --- a/esp8266/uart.c +++ b/esp8266/uart.c @@ -39,8 +39,6 @@ static void uart0_rx_intr_handler(void *para); void soft_reset(void); void mp_keyboard_interrupt(void); -int interrupt_char; - /****************************************************************************** * FunctionName : uart_config * Description : Internal used function @@ -172,7 +170,7 @@ static void uart0_rx_intr_handler(void *para) { while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) { uint8 RcvChar = READ_PERI_REG(UART_FIFO(uart_no)) & 0xff; - if (RcvChar == interrupt_char) { + if (RcvChar == mp_interrupt_char) { mp_keyboard_interrupt(); } else { ringbuf_put(&input_buf, RcvChar); |