From ca16c3821053e5bf2b87aeb10007f73f31dc1eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 29 May 2017 10:08:14 +0300 Subject: [PATCH 01/20] various: Spelling fixes --- cc3200/README.md | 2 +- docs/library/btree.rst | 2 +- docs/library/machine.SD.rst | 2 +- docs/library/machine.UART.rst | 2 +- docs/library/uhashlib.rst | 4 ++-- docs/library/utime.rst | 4 ++-- docs/sphinx_selective_exclude/README.md | 2 +- docs/sphinx_selective_exclude/modindex_exclude.py | 2 +- esp8266/README.md | 2 +- esp8266/machine_rtc.c | 2 +- examples/conwaylife.py | 4 ++-- examples/embedding/Makefile.upylib | 2 +- examples/embedding/README.md | 2 +- extmod/modlwip.c | 4 ++-- extmod/modwebsocket.c | 2 +- lib/timeutils/timeutils.c | 2 +- lib/utils/stdout_helpers.c | 2 +- py/asmthumb.c | 2 +- py/builtinimport.c | 4 ++-- py/compile.c | 4 ++-- py/misc.h | 2 +- py/mkenv.mk | 2 +- py/mpconfig.h | 2 +- py/obj.c | 2 +- py/objstr.c | 4 ++-- py/py.mk | 2 +- py/ringbuf.h | 2 +- py/stream.c | 2 +- py/vm.c | 4 ++-- qemu-arm/README.md | 2 +- tests/basics/namedtuple1.py | 2 +- tests/basics/try_reraise2.py | 2 +- tests/pyb/can.py | 2 +- tests/thread/stress_aes.py | 2 +- tests/wipy/uart.py | 2 +- tools/insert-usb-ids.py | 2 +- tools/pyboard.py | 2 +- unix/Makefile | 2 +- unix/modsocket.c | 2 +- windows/windows_mphal.c | 2 +- zephyr/modutime.c | 2 +- 41 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cc3200/README.md b/cc3200/README.md index 753fd450a2..53cad3ba0f 100644 --- a/cc3200/README.md +++ b/cc3200/README.md @@ -138,7 +138,7 @@ If `WIPY_IP`, `WIPY_USER` or `WIPY_PWD` are omitted the default values (the ones ## Regarding old revisions of the CC3200-LAUNCHXL First silicon (pre-release) revisions of the CC3200 had issues with the ram blocks, and MicroPython cannot run -there. Make sure to use a **v4.1 (or higer) LAUNCHXL board** when trying this port, otherwise it won't work. +there. Make sure to use a **v4.1 (or higher) LAUNCHXL board** when trying this port, otherwise it won't work. ### Note regarding FileZilla diff --git a/docs/library/btree.rst b/docs/library/btree.rst index aebcbc1604..bd7890586a 100644 --- a/docs/library/btree.rst +++ b/docs/library/btree.rst @@ -69,7 +69,7 @@ Functions Open a database from a random-access `stream` (like an open file). All other parameters are optional and keyword-only, and allow to tweak advanced - paramters of the database operation (most users will not need them): + parameters of the database operation (most users will not need them): * `flags` - Currently unused. * `cachesize` - Suggested maximum memory cache size in bytes. For a diff --git a/docs/library/machine.SD.rst b/docs/library/machine.SD.rst index 0eb024602f..608e958317 100644 --- a/docs/library/machine.SD.rst +++ b/docs/library/machine.SD.rst @@ -34,7 +34,7 @@ Methods .. method:: SD.init(id=0, pins=('GP10', 'GP11', 'GP15')) - Enable the SD card. In order to initalize the card, give it a 3-tuple: + Enable the SD card. In order to initialize the card, give it a 3-tuple: ``(clk_pin, cmd_pin, dat0_pin)``. .. method:: SD.deinit() diff --git a/docs/library/machine.UART.rst b/docs/library/machine.UART.rst index f9c8efef78..64ff28e1ab 100644 --- a/docs/library/machine.UART.rst +++ b/docs/library/machine.UART.rst @@ -16,7 +16,7 @@ UART objects can be created and initialised using:: uart = UART(1, 9600) # init with given baudrate uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters -Supported paramters differ on a board: +Supported parameters differ on a board: Pyboard: Bits can be 7, 8 or 9. Stop can be 1 or 2. With `parity=None`, only 8 and 9 bits are supported. With parity enabled, only 7 and 8 bits diff --git a/docs/library/uhashlib.rst b/docs/library/uhashlib.rst index cd0216dae9..6b9a764ba8 100644 --- a/docs/library/uhashlib.rst +++ b/docs/library/uhashlib.rst @@ -15,11 +15,11 @@ be implemented: * SHA1 - A previous generation algorithm. Not recommended for new usages, but SHA1 is a part of number of Internet standards and existing - applications, so boards targetting network connectivity and + applications, so boards targeting network connectivity and interoperatiability will try to provide this. * MD5 - A legacy algorithm, not considered cryptographically secure. Only - selected boards, targetting interoperatibility with legacy applications, + selected boards, targeting interoperatibility with legacy applications, will offer this. Constructors diff --git a/docs/library/utime.rst b/docs/library/utime.rst index 871f6c678d..f3a067cdef 100644 --- a/docs/library/utime.rst +++ b/docs/library/utime.rst @@ -146,8 +146,8 @@ Functions too distant inbetween, see below). The function returns **signed** value in the range [``-TICKS_PERIOD/2`` .. ``TICKS_PERIOD/2-1``] (that's a typical range definition for two's-complement signed binary integers). If the result is negative, it means that - ``ticks1`` occured earlier in time than ``ticks2``. Otherwise, it means that - ``ticks1`` occured after ``ticks2``. This holds ``only`` if ``ticks1`` and ``ticks2`` + ``ticks1`` occurred earlier in time than ``ticks2``. Otherwise, it means that + ``ticks1`` occurred after ``ticks2``. This holds ``only`` if ``ticks1`` and ``ticks2`` are apart from each other for no more than ``TICKS_PERIOD/2-1`` ticks. If that does not hold, incorrect result will be returned. Specifically, if two tick values are apart for ``TICKS_PERIOD/2-1`` ticks, that value will be returned by the function. diff --git a/docs/sphinx_selective_exclude/README.md b/docs/sphinx_selective_exclude/README.md index cc9725c21c..dab1407392 100644 --- a/docs/sphinx_selective_exclude/README.md +++ b/docs/sphinx_selective_exclude/README.md @@ -66,7 +66,7 @@ index for PDF, just the same as for HTML. search_auto_exclude ------------------- -Even if you exclude soem documents from toctree:: using only:: +Even if you exclude some documents from toctree:: using only:: directive, they will be indexed for full-text search, so user may find them and get confused. This plugin follows very simple idea that if you didn't include some documents in the toctree, then diff --git a/docs/sphinx_selective_exclude/modindex_exclude.py b/docs/sphinx_selective_exclude/modindex_exclude.py index 18b49cc80f..bf8db795e6 100644 --- a/docs/sphinx_selective_exclude/modindex_exclude.py +++ b/docs/sphinx_selective_exclude/modindex_exclude.py @@ -2,7 +2,7 @@ # This is a Sphinx documentation tool extension which allows to # exclude some Python modules from the generated indexes. Modules # are excluded both from "modindex" and "genindex" index tables -# (in the latter case, all members of a module are exlcuded). +# (in the latter case, all members of a module are excluded). # To control exclusion, set "modindex_exclude" variable in Sphinx # conf.py to the list of modules to exclude. Note: these should be # modules (as defined by py:module directive, not just raw filenames). diff --git a/esp8266/README.md b/esp8266/README.md index 897bb47377..d717d26fed 100644 --- a/esp8266/README.md +++ b/esp8266/README.md @@ -100,7 +100,7 @@ programming). __WiFi__ -Initally, the device configures itself as a WiFi access point (AP). +Initially, the device configures itself as a WiFi access point (AP). - ESSID: MicroPython-xxxxxx (x’s are replaced with part of the MAC address). - Password: micropythoN (note the upper-case N). - IP address of the board: 192.168.4.1. diff --git a/esp8266/machine_rtc.c b/esp8266/machine_rtc.c index 019b705ba2..b17bcb2616 100644 --- a/esp8266/machine_rtc.c +++ b/esp8266/machine_rtc.c @@ -93,7 +93,7 @@ void pyb_rtc_set_us_since_2000(uint64_t nowus) { int64_t delta = nowus - (((uint64_t)rtc_last_ticks * cal) >> 12); // As the calibration value jitters quite a bit, to make the - // clock at least somewhat practially usable, we need to store it + // clock at least somewhat practically usable, we need to store it system_rtc_mem_write(MEM_CAL_ADDR, &cal, sizeof(cal)); system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta)); }; diff --git a/examples/conwaylife.py b/examples/conwaylife.py index f99796175f..323f42e850 100644 --- a/examples/conwaylife.py +++ b/examples/conwaylife.py @@ -8,7 +8,7 @@ lcd.light(1) def conway_step(): for x in range(128): # loop over x coordinates for y in range(32): # loop over y coordinates - # count number of neigbours + # count number of neighbours num_neighbours = (lcd.get(x - 1, y - 1) + lcd.get(x, y - 1) + lcd.get(x + 1, y - 1) + @@ -25,7 +25,7 @@ def conway_step(): if self and not (2 <= num_neighbours <= 3): lcd.pixel(x, y, 0) # not enough, or too many neighbours: cell dies elif not self and num_neighbours == 3: - lcd.pixel(x, y, 1) # exactly 3 neigbours around an empty cell: cell is born + lcd.pixel(x, y, 1) # exactly 3 neighbours around an empty cell: cell is born # randomise the start def conway_rand(): diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib index 873c0fd344..4663ad30ab 100644 --- a/examples/embedding/Makefile.upylib +++ b/examples/embedding/Makefile.upylib @@ -170,7 +170,7 @@ SRC_QSTR_AUTO_DEPS += include $(MPTOP)/py/mkrules.mk # Value of configure's --host= option (required for cross-compilation). -# Deduce it from CROSS_COMPILE by default, but can be overriden. +# Deduce it from CROSS_COMPILE by default, but can be overridden. ifneq ($(CROSS_COMPILE),) CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE)) else diff --git a/examples/embedding/README.md b/examples/embedding/README.md index 989ce1fc8f..804dfede6f 100644 --- a/examples/embedding/README.md +++ b/examples/embedding/README.md @@ -18,7 +18,7 @@ Building the example is as simple as running: It's worth to trace what's happening behind the scenes though: 1. As a first step, a MicroPython library is built. This is handled by a -seperate makefile, Makefile.upylib. It is more or less complex, but the +separate makefile, Makefile.upylib. It is more or less complex, but the good news is that you won't need to change anything in it, just use it as is, the main Makefile shows how. What may require editing though is a MicroPython configuration file. MicroPython is highly configurable, so diff --git a/extmod/modlwip.c b/extmod/modlwip.c index c72849cf9d..47669cb3a0 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -373,7 +373,7 @@ STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err } /*******************************************************************************/ -// Functions for socket send/recieve operations. Socket send/recv and friends call +// Functions for socket send/receive operations. Socket send/recv and friends call // these to do the work. // Helper function for send/sendto to handle UDP packets. @@ -805,7 +805,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { mp_raise_OSError(MP_EINPROGRESS); } } - // Register our recieve callback. + // Register our receive callback. tcp_recv(socket->pcb.tcp, _lwip_tcp_recv); socket->state = STATE_CONNECTING; err = tcp_connect(socket->pcb.tcp, &dest, port, _lwip_tcp_connected); diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index 8200ea708a..9e17d6a6d8 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -132,7 +132,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int self->buf_pos = 0; self->to_recv = to_recv; - self->msg_sz = sz; // May be overriden by FRAME_OPT + self->msg_sz = sz; // May be overridden by FRAME_OPT if (to_recv != 0) { self->state = FRAME_OPT; } else { diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index 0af39a2958..06915f25ae 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -165,7 +165,7 @@ mp_uint_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday, // // tm_tomorrow = list(time.localtime()) // tm_tomorrow[2] += 1 # Adds 1 to mday - // tomorrow = time.mktime(tm_tommorrow) + // tomorrow = time.mktime(tm_tomorrow) // // And not have to worry about all the weird overflows. // diff --git a/lib/utils/stdout_helpers.c b/lib/utils/stdout_helpers.c index 5f7a17d320..3de1197571 100644 --- a/lib/utils/stdout_helpers.c +++ b/lib/utils/stdout_helpers.c @@ -9,7 +9,7 @@ * implementation below can be used. */ -// Send "cooked" string of given length, where every occurance of +// Send "cooked" string of given length, where every occurrence of // LF character is replaced with CR LF. void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { while (len--) { diff --git a/py/asmthumb.c b/py/asmthumb.c index 749c1e405b..7e92e4de41 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -52,7 +52,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) { #if defined(MCU_SERIES_F7) if (as->base.pass == MP_ASM_PASS_EMIT) { - // flush D-cache, so the code emited is stored in memory + // flush D-cache, so the code emitted is stored in memory SCB_CleanDCache_by_Addr((uint32_t*)as->base.code_base, as->base.code_size); // invalidate I-cache SCB_InvalidateICache(); diff --git a/py/builtinimport.c b/py/builtinimport.c index d01ebbe73f..6994fc48f4 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -271,7 +271,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { if (level != 0) { // What we want to do here is to take name of current module, // chop trailing components, and concatenate with passed-in - // module name, thus resolving relative import name into absolue. + // module name, thus resolving relative import name into absolute. // This even appears to be correct per // http://legacy.python.org/dev/peps/pep-0328/#relative-imports-and-name // "Relative imports use a module's __name__ attribute to determine that @@ -441,7 +441,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { #if MICROPY_CPYTHON_COMPAT // Store module as "__main__" in the dictionary of loaded modules (returned by sys.modules). mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_loaded_modules_dict)), MP_OBJ_NEW_QSTR(MP_QSTR___main__), module_obj); - // Store real name in "__main__" attribute. Choosen semi-randonly, to reuse existing qstr's. + // Store real name in "__main__" attribute. Chosen semi-randonly, to reuse existing qstr's. mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(mod_name)); #endif } diff --git a/py/compile.c b/py/compile.c index 8533e0528f..3b6a264d61 100644 --- a/py/compile.c +++ b/py/compile.c @@ -939,7 +939,7 @@ STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { } } } else { - // some arbitrary statment that we can't delete (eg del 1) + // some arbitrary statement that we can't delete (eg del 1) goto cannot_delete; } @@ -1090,7 +1090,7 @@ STATIC void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_t pn_import_source = pns->nodes[0]; - // extract the preceeding .'s (if any) for a relative import, to compute the import level + // extract the preceding .'s (if any) for a relative import, to compute the import level uint import_level = 0; do { mp_parse_node_t pn_rel; diff --git a/py/misc.h b/py/misc.h index 146b9a8e4a..caa5945bf2 100644 --- a/py/misc.h +++ b/py/misc.h @@ -197,7 +197,7 @@ int DEBUG_printf(const char *fmt, ...); extern mp_uint_t mp_verbose_flag; // This is useful for unicode handling. Some CPU archs has -// special instructions for efficient implentation of this +// special instructions for efficient implementation of this // function (e.g. CLZ on ARM). // NOTE: this function is unused at the moment #ifndef count_lead_ones diff --git a/py/mkenv.mk b/py/mkenv.mk index eb1e44fef5..b167b2533d 100644 --- a/py/mkenv.mk +++ b/py/mkenv.mk @@ -32,7 +32,7 @@ ifeq ($(BUILD_VERBOSE),0) $(info Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.) endif -# default settings; can be overriden in main Makefile +# default settings; can be overridden in main Makefile PY_SRC ?= $(TOP)/py BUILD ?= build diff --git a/py/mpconfig.h b/py/mpconfig.h index a61d431e5a..78e346d734 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -32,7 +32,7 @@ // mpconfigport.h is a file containing configuration settings for a // particular port. mpconfigport.h is actually a default name for -// such config, and it can be overriden using MP_CONFIGFILE preprocessor +// such config, and it can be overridden using MP_CONFIGFILE preprocessor // define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE=""' // argument to make when using standard MicroPython makefiles). // This is useful to have more than one config per port, for example, diff --git a/py/obj.c b/py/obj.c index 98ffa930b5..493945a227 100644 --- a/py/obj.c +++ b/py/obj.c @@ -401,7 +401,7 @@ mp_obj_t mp_obj_id(mp_obj_t o_in) { return MP_OBJ_NEW_SMALL_INT(id); } else { // If that didn't work, well, let's return long int, just as - // a (big) positve value, so it will never clash with the range + // a (big) positive value, so it will never clash with the range // of small int returned in previous case. return mp_obj_new_int_from_uint((mp_uint_t)id); } diff --git a/py/objstr.c b/py/objstr.c index 70de0a693a..a1e2235720 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -798,7 +798,7 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { } assert(last_good_char_pos >= first_good_char_pos); - //+1 to accomodate the last character + //+1 to accommodate the last character size_t stripped_len = last_good_char_pos - first_good_char_pos + 1; if (stripped_len == orig_str_len) { // If nothing was stripped, don't bother to dup original string @@ -1811,7 +1811,7 @@ STATIC mp_obj_t str_islower(mp_obj_t self_in) { } #if MICROPY_CPYTHON_COMPAT -// These methods are superfluous in the presense of str() and bytes() +// These methods are superfluous in the presence of str() and bytes() // constructors. // TODO: should accept kwargs too STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { diff --git a/py/py.mk b/py/py.mk index 5ff1fd6a6c..70891677d6 100644 --- a/py/py.mk +++ b/py/py.mk @@ -25,7 +25,7 @@ ifeq ($(MICROPY_SSL_AXTLS),1) CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config LDFLAGS_MOD += -Lbuild -laxtls else ifeq ($(MICROPY_SSL_MBEDTLS),1) -# Can be overriden by ports which have "builtin" mbedTLS +# Can be overridden by ports which have "builtin" mbedTLS MICROPY_SSL_MBEDTLS_INCLUDE ?= ../lib/mbedtls/include CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(MICROPY_SSL_MBEDTLS_INCLUDE) LDFLAGS_MOD += -L../lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto diff --git a/py/ringbuf.h b/py/ringbuf.h index 5662594f76..5e108afad7 100644 --- a/py/ringbuf.h +++ b/py/ringbuf.h @@ -33,7 +33,7 @@ typedef struct _ringbuf_t { uint16_t iput; } ringbuf_t; -// Static initalization: +// Static initialization: // byte buf_array[N]; // ringbuf_t buf = {buf_array, sizeof(buf_array)}; diff --git a/py/stream.c b/py/stream.c index c915110e0b..d3fc767bbd 100644 --- a/py/stream.c +++ b/py/stream.c @@ -51,7 +51,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in); #define STREAM_CONTENT_TYPE(stream) (((stream)->is_text) ? &mp_type_str : &mp_type_bytes) // Returns error condition in *errcode, if non-zero, return value is number of bytes written -// before error condition occured. If *errcode == 0, returns total bytes written (which will +// before error condition occurred. If *errcode == 0, returns total bytes written (which will // be equal to input size). mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode, byte flags) { byte *buf = buf_; diff --git a/py/vm.c b/py/vm.c index 5094e3e450..ad3d9e29c8 100644 --- a/py/vm.c +++ b/py/vm.c @@ -947,7 +947,7 @@ unwind_jump:; DECODE_UINT; // unum & 0xff == n_positional // (unum >> 8) & 0xff == n_keyword - // We have folowing stack layout here: + // We have following stack layout here: // fun arg0 arg1 ... kw0 val0 kw1 val1 ... seq dict <- TOS sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 2; #if MICROPY_STACKLESS @@ -1018,7 +1018,7 @@ unwind_jump:; DECODE_UINT; // unum & 0xff == n_positional // (unum >> 8) & 0xff == n_keyword - // We have folowing stack layout here: + // We have following stack layout here: // fun self arg0 arg1 ... kw0 val0 kw1 val1 ... seq dict <- TOS sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 3; #if MICROPY_STACKLESS diff --git a/qemu-arm/README.md b/qemu-arm/README.md index 329ae4d921..0cf93c7d56 100644 --- a/qemu-arm/README.md +++ b/qemu-arm/README.md @@ -4,7 +4,7 @@ provided by QEMU (http://qemu.org). The purposes of this port are to enable: 1. Continuous integration - - run tests agains architecture-specific parts of code base + - run tests against architecture-specific parts of code base 2. Experimentation - simulation & prototyping of anything that has architecture-specific code diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index 132dcf96b3..70372f7cab 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -76,7 +76,7 @@ T4 = namedtuple("TupTuple", ("foo", "bar")) t = T4(1, 2) print(t.foo, t.bar) -# Try single string with comma field seperator +# Try single string with comma field separator # Not implemented so far #T2 = namedtuple("TupComma", "foo,bar") #t = T2(1, 2) diff --git a/tests/basics/try_reraise2.py b/tests/basics/try_reraise2.py index d9434397c2..5648d2467b 100644 --- a/tests/basics/try_reraise2.py +++ b/tests/basics/try_reraise2.py @@ -1,4 +1,4 @@ -# Reraise not the latest occured exception +# Reraise not the latest occurred exception def f(): try: raise ValueError("val", 3) diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 617eb7cccc..7f2d070ecb 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -158,7 +158,7 @@ print(can.recv(1)) del can -# Testing asyncronous send +# Testing asynchronous send can = CAN(1, CAN.LOOPBACK) can.setfilter(0, CAN.MASK16, 0, (0, 0, 0, 0)) diff --git a/tests/thread/stress_aes.py b/tests/thread/stress_aes.py index ecc963c925..df75e616c6 100644 --- a/tests/thread/stress_aes.py +++ b/tests/thread/stress_aes.py @@ -8,7 +8,7 @@ # # The AES code comes first (code originates from a C version authored by D.P.George) # and then the test harness at the bottom. It can be tuned to be more/less -# agressive by changing the amount of data to encrypt, the number of loops and +# aggressive by changing the amount of data to encrypt, the number of loops and # the number of threads. # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd diff --git a/tests/wipy/uart.py b/tests/wipy/uart.py index a3a1c14e88..8e794015de 100644 --- a/tests/wipy/uart.py +++ b/tests/wipy/uart.py @@ -95,7 +95,7 @@ print(uart1.read() == None) print(uart1.write(b'123') == 3) print(uart0.read() == b'123') -# no pin assignemnt +# no pin assignment uart0 = UART(0, 1000000, pins=(None, None)) print(uart0.write(b'123456789') == 9) print(uart1.read() == None) diff --git a/tools/insert-usb-ids.py b/tools/insert-usb-ids.py index 420db34c5a..cdccd3be97 100644 --- a/tools/insert-usb-ids.py +++ b/tools/insert-usb-ids.py @@ -1,4 +1,4 @@ -# Reads the USB VID and PID from the file specifed by sys.arg[1] and then +# Reads the USB VID and PID from the file specified by sys.argv[1] and then # inserts those values into the template file specified by sys.argv[2], # printing the result to stdout diff --git a/tools/pyboard.py b/tools/pyboard.py index 5eac030bdd..921ffc52d3 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -69,7 +69,7 @@ class TelnetToSerial: self.tn.write(bytes(password, 'ascii') + b"\r\n") if b'for more information.' in self.tn.read_until(b'Type "help()" for more information.', timeout=read_timeout): - # login succesful + # login successful from collections import deque self.fifo = deque() return diff --git a/unix/Makefile b/unix/Makefile index 837ddf2b78..006bce0ef2 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -262,7 +262,7 @@ coverage_test: coverage gcov -o build-coverage/extmod ../extmod/*.c # Value of configure's --host= option (required for cross-compilation). -# Deduce it from CROSS_COMPILE by default, but can be overriden. +# Deduce it from CROSS_COMPILE by default, but can be overridden. ifneq ($(CROSS_COMPILE),) CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE)) else diff --git a/unix/modsocket.c b/unix/modsocket.c index 9ca04b88b4..c7be6461e8 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -58,7 +58,7 @@ from socket_more_funcs2 import * ------------------- I.e. this module should stay lean, and more functions (if needed) - should be add to seperate modules (C or Python level). + should be add to separate modules (C or Python level). */ #define MICROPY_SOCKET_EXTRA (0) diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c index 1dd3105d86..a73140e544 100644 --- a/windows/windows_mphal.c +++ b/windows/windows_mphal.c @@ -72,7 +72,7 @@ void mp_hal_stdio_mode_orig(void) { // Previous versions of the mp_hal code would install a handler whenever Ctrl-C input is // allowed and remove the handler again when it is not. That is not necessary though (1), // and it might introduce problems (2) because console notifications are delivered to the -// application in a seperate thread. +// application in a separate thread. // (1) mp_hal_set_interrupt_char effectively enables/disables processing of Ctrl-C via the // ENABLE_PROCESSED_INPUT flag so in raw mode console_sighandler won't be called. // (2) if mp_hal_set_interrupt_char would remove the handler while Ctrl-C was issued earlier, diff --git a/zephyr/modutime.c b/zephyr/modutime.c index 378068bb38..0c268046a9 100644 --- a/zephyr/modutime.c +++ b/zephyr/modutime.c @@ -36,7 +36,7 @@ #include "extmod/utime_mphal.h" STATIC mp_obj_t mod_time_time(void) { - /* The absense of FP support is deliberate. The Zephyr port uses + /* The absence of FP support is deliberate. The Zephyr port uses * single precision floats so the fraction component will start to * lose precision on devices with a long uptime. */ From 3496d9e4bd39452484d8a99e991ef7c0a92d5b51 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 29 May 2017 20:51:30 +0300 Subject: [PATCH 02/20] docs/machine.Pin: Remove out_value() method. This method isn't implemented in any port. It seemed to have originated in cc3200 port, but actually never was implemented there either. In general case, it's impossible to implement this method (for example, for a perfect GPO, which has only output latch without any feedback look into a CPU). --- docs/library/machine.Pin.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/library/machine.Pin.rst b/docs/library/machine.Pin.rst index 2efd84688a..e7f3141542 100644 --- a/docs/library/machine.Pin.rst +++ b/docs/library/machine.Pin.rst @@ -146,12 +146,6 @@ Methods When setting the value this method returns ``None``. -.. method:: Pin.out_value() - - Return the value stored in the output buffer of a pin, regardless of its mode. - - Not all ports implement this method. - .. method:: Pin.__call__([x]) Pin objects are callable. The call method provides a (fast) shortcut to set From d5b8825d5f5c6110f9cf3bd39848cfe94137d291 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 29 May 2017 20:56:13 +0300 Subject: [PATCH 03/20] docs/machine.Pin: Add on() and off() methods. --- docs/library/machine.Pin.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/library/machine.Pin.rst b/docs/library/machine.Pin.rst index e7f3141542..05ceb4ad33 100644 --- a/docs/library/machine.Pin.rst +++ b/docs/library/machine.Pin.rst @@ -152,6 +152,14 @@ Methods and get the value of the pin. It is equivalent to Pin.value([x]). See :meth:`Pin.value` for more details. +.. method:: Pin.on() + + Set pin to "1" output level. + +.. method:: Pin.off() + + Set pin to "0" output level. + .. method:: Pin.mode([mode]) Get or set the pin mode. From 272a5d95e040994039eb91830d310339253bcbb9 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 30 May 2017 07:36:25 +0300 Subject: [PATCH 04/20] docs/esp8266: Consistently replace Pin.high/low methods with .on/off. --- docs/esp8266/quickref.rst | 4 ++-- docs/esp8266/tutorial/pins.rst | 4 ++-- docs/esp8266/tutorial/repl.rst | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/esp8266/quickref.rst b/docs/esp8266/quickref.rst index 5ff33e02bd..406a5bb456 100644 --- a/docs/esp8266/quickref.rst +++ b/docs/esp8266/quickref.rst @@ -107,8 +107,8 @@ Use the :ref:`machine.Pin ` class:: from machine import Pin p0 = Pin(0, Pin.OUT) # create output pin on GPIO0 - p0.high() # set pin to high - p0.low() # set pin to low + p0.on() # turn on pin, set to high + p0.off() # turn off pin, set to low p0.value(1) # set pin to high p2 = Pin(2, Pin.IN) # create input pin on GPIO2 diff --git a/docs/esp8266/tutorial/pins.rst b/docs/esp8266/tutorial/pins.rst index a44f40d3a7..cd45c83cd3 100644 --- a/docs/esp8266/tutorial/pins.rst +++ b/docs/esp8266/tutorial/pins.rst @@ -35,8 +35,8 @@ Then set its value using:: Or:: - >>> pin.low() - >>> pin.high() + >>> pin.off() + >>> pin.on() External interrupts ------------------- diff --git a/docs/esp8266/tutorial/repl.rst b/docs/esp8266/tutorial/repl.rst index 21e889c9a8..ba64fcccbe 100644 --- a/docs/esp8266/tutorial/repl.rst +++ b/docs/esp8266/tutorial/repl.rst @@ -101,11 +101,12 @@ turn it on and off using the following code:: >>> import machine >>> pin = machine.Pin(2, machine.Pin.OUT) - >>> pin.high() - >>> pin.low() + >>> pin.on() + >>> pin.off() -Note that ``high`` might turn the LED off and ``low`` might turn it on (or vice -versa), depending on how the LED is wired on your board. +Note that ``on`` method of a Pin might turn the LED off and ``off`` might +turn it on (or vice versa), depending on how the LED is wired on your board. +To resolve this, machine.Signal class is provided. Line editing ~~~~~~~~~~~~ From 821dc27eecf2d47d175222e9259d5b287b45380c Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 30 May 2017 18:31:55 +1000 Subject: [PATCH 05/20] stmhal/boards: Enable DAC for NUCLEO_F767ZI board. --- stmhal/boards/NUCLEO_F767ZI/mpconfigboard.h | 2 +- stmhal/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stmhal/boards/NUCLEO_F767ZI/mpconfigboard.h b/stmhal/boards/NUCLEO_F767ZI/mpconfigboard.h index cafea136f9..8952bce82f 100644 --- a/stmhal/boards/NUCLEO_F767ZI/mpconfigboard.h +++ b/stmhal/boards/NUCLEO_F767ZI/mpconfigboard.h @@ -16,7 +16,7 @@ #define MICROPY_HW_ENABLE_RTC (1) #define MICROPY_HW_ENABLE_TIMER (1) #define MICROPY_HW_ENABLE_SERVO (0) -#define MICROPY_HW_ENABLE_DAC (0) +#define MICROPY_HW_ENABLE_DAC (1) #define MICROPY_HW_ENABLE_CAN (1) // HSE is 25MHz diff --git a/stmhal/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h b/stmhal/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h index d2c31cb098..e1aa4578d5 100644 --- a/stmhal/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h +++ b/stmhal/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h @@ -58,7 +58,7 @@ /* #define HAL_CEC_MODULE_ENABLED */ /* #define HAL_CRC_MODULE_ENABLED */ /* #define HAL_CRYP_MODULE_ENABLED */ -/* #define HAL_DAC_MODULE_ENABLED */ +#define HAL_DAC_MODULE_ENABLED /* #define HAL_DCMI_MODULE_ENABLED */ #define HAL_DMA_MODULE_ENABLED /* #define HAL_DMA2D_MODULE_ENABLED */ From b53a63517a71278d0f73f98f4f5ce1b15b14370e Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 31 May 2017 11:34:29 +1000 Subject: [PATCH 06/20] lib/libm: Use isfinite instead of finitef, for C99 compatibility. --- lib/libm/sf_ldexp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libm/sf_ldexp.c b/lib/libm/sf_ldexp.c index 32a134eea1..a0941df9fd 100644 --- a/lib/libm/sf_ldexp.c +++ b/lib/libm/sf_ldexp.c @@ -32,7 +32,7 @@ float value; int exp; #endif { - if(!finitef(value)||value==(float)0.0) return value; + if(!isfinite(value)||value==(float)0.0) return value; value = scalbnf(value,exp); //if(!finitef(value)||value==(float)0.0) errno = ERANGE; return value; From bc76302eab56368967af4f1cf8813ac816b9c22f Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jun 2017 15:32:23 +1000 Subject: [PATCH 07/20] py/modbuiltins: Add core-provided version of input() function. The implementation is taken from stmhal/input.c, with code added to handle ctrl-C. This built-in is controlled by MICROPY_PY_BUILTINS_INPUT and is disabled by default. It uses readline() to capture input but this can be overridden by defining the mp_hal_readline macro. --- py/modbuiltins.c | 32 ++++++++++++++++++++++++++++++++ py/mpconfig.h | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 17bd30c521..fe8159953a 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -259,6 +259,35 @@ STATIC mp_obj_t mp_builtin_hex(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hex_obj, mp_builtin_hex); +#if MICROPY_PY_BUILTINS_INPUT + +#include "py/mphal.h" +#include "lib/mp-readline/readline.h" + +// A port can define mp_hal_readline if they want to use a custom function here +#ifndef mp_hal_readline +#define mp_hal_readline readline +#endif + +STATIC mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) { + if (n_args == 1) { + mp_obj_print(args[0], PRINT_STR); + } + vstr_t line; + vstr_init(&line, 16); + int ret = mp_hal_readline(&line, ""); + if (ret == CHAR_CTRL_C) { + nlr_raise(mp_obj_new_exception(&mp_type_KeyboardInterrupt)); + } + if (line.len == 0 && ret == CHAR_CTRL_D) { + nlr_raise(mp_obj_new_exception(&mp_type_EOFError)); + } + return mp_obj_new_str_from_vstr(&mp_type_str, &line); +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input); + +#endif + STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) { return mp_getiter(o_in, NULL); } @@ -676,6 +705,9 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { #endif { MP_ROM_QSTR(MP_QSTR_hex), MP_ROM_PTR(&mp_builtin_hex_obj) }, { MP_ROM_QSTR(MP_QSTR_id), MP_ROM_PTR(&mp_builtin_id_obj) }, + #if MICROPY_PY_BUILTINS_INPUT + { MP_ROM_QSTR(MP_QSTR_input), MP_ROM_PTR(&mp_builtin_input_obj) }, + #endif { MP_ROM_QSTR(MP_QSTR_isinstance), MP_ROM_PTR(&mp_builtin_isinstance_obj) }, { MP_ROM_QSTR(MP_QSTR_issubclass), MP_ROM_PTR(&mp_builtin_issubclass_obj) }, { MP_ROM_QSTR(MP_QSTR_iter), MP_ROM_PTR(&mp_builtin_iter_obj) }, diff --git a/py/mpconfig.h b/py/mpconfig.h index 78e346d734..1ec8ae21c8 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -791,6 +791,12 @@ typedef double mp_float_t; #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0) #endif +// Whether to provide the built-in input() function. The implementation of this +// uses mp-readline, so can only be enabled if the port uses this readline. +#ifndef MICROPY_PY_BUILTINS_INPUT +#define MICROPY_PY_BUILTINS_INPUT (0) +#endif + // Whether to support min/max functions #ifndef MICROPY_PY_BUILTINS_MIN_MAX #define MICROPY_PY_BUILTINS_MIN_MAX (1) From 6ff0ecfffcea4e7aa6301c54870ae97aa4a0cf72 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jun 2017 15:43:20 +1000 Subject: [PATCH 08/20] ports: Convert from using stmhal's input() to core provided version. --- cc3200/application.mk | 1 - cc3200/mpconfigport.h | 2 +- esp8266/Makefile | 1 - esp8266/mpconfigport.h | 2 +- stmhal/Makefile | 1 - stmhal/input.c | 44 ------------------------------------------ stmhal/mpconfigport.h | 2 +- teensy/Makefile | 1 - teensy/mpconfigport.h | 2 +- 9 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 stmhal/input.c diff --git a/cc3200/application.mk b/cc3200/application.mk index 5d25424e15..1f54b764b9 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -151,7 +151,6 @@ APP_LIB_SRC_C = $(addprefix lib/,\ APP_STM_SRC_C = $(addprefix stmhal/,\ bufhelper.c \ - input.c \ irq.c \ pybstdio.c \ ) diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 4d19900aee..4bd583a4b8 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -80,6 +80,7 @@ #define MICROPY_VFS_FAT (1) #define MICROPY_PY_ASYNC_AWAIT (0) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT cc3200_help_text #ifndef DEBUG @@ -142,7 +143,6 @@ // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, \ // extra built in modules to add to the list of known ones diff --git a/esp8266/Makefile b/esp8266/Makefile index a3da9d3986..cf4b288ca2 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -94,7 +94,6 @@ SRC_C = \ STM_SRC_C = $(addprefix stmhal/,\ pybstdio.c \ - input.c \ ) EXTMOD_SRC_C = $(addprefix extmod/,\ diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index c286bdcdd9..483f93d02b 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -39,6 +39,7 @@ #define MICROPY_PY_BUILTINS_SLICE (1) #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) #define MICROPY_PY_BUILTINS_PROPERTY (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT esp_help_text #define MICROPY_PY_BUILTINS_HELP_MODULES (1) @@ -147,7 +148,6 @@ void *esp_native_code_commit(void*, size_t); // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, // extra built in modules to add to the list of known ones diff --git a/stmhal/Makefile b/stmhal/Makefile index 09643be94a..2d9d44afd9 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -147,7 +147,6 @@ SRC_C = \ gccollect.c \ pybstdio.c \ help.c \ - input.c \ machine_i2c.c \ modmachine.c \ modpyb.c \ diff --git a/stmhal/input.c b/stmhal/input.c deleted file mode 100644 index c78525cc91..0000000000 --- a/stmhal/input.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/nlr.h" -#include "py/obj.h" -#include "lib/mp-readline/readline.h" - -STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) { - if (n_args == 1) { - mp_obj_print(args[0], PRINT_STR); - } - vstr_t line; - vstr_init(&line, 16); - int ret = readline(&line, ""); - if (line.len == 0 && ret == CHAR_CTRL_D) { - nlr_raise(mp_obj_new_exception(&mp_type_EOFError)); - } - return mp_obj_new_str_from_vstr(&mp_type_str, &line); -} - -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input); diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 444ce93032..ac3c1f2470 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -87,6 +87,7 @@ #define MICROPY_PY_ALL_SPECIAL_METHODS (1) #define MICROPY_PY_BUILTINS_COMPILE (1) #define MICROPY_PY_BUILTINS_EXECFILE (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_POW3 (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT stmhal_help_text @@ -159,7 +160,6 @@ // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, // extra built in modules to add to the list of known ones diff --git a/teensy/Makefile b/teensy/Makefile index 9f52cc3c76..923ea77ecd 100644 --- a/teensy/Makefile +++ b/teensy/Makefile @@ -93,7 +93,6 @@ SRC_C = \ STM_SRC_C = $(addprefix stmhal/,\ gccollect.c \ - input.c \ irq.c \ pin.c \ pin_named_pins.c \ diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h index 8c40220465..de30924d9e 100644 --- a/teensy/mpconfigport.h +++ b/teensy/mpconfigport.h @@ -14,6 +14,7 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_OPT_COMPUTED_GOTO (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT teensy_help_text @@ -31,7 +32,6 @@ // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ // extra built in modules to add to the list of known ones extern const struct _mp_obj_module_t os_module; From d92898a35acdb6fc665be75f7c53d0fec107c4c4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jun 2017 16:01:27 +1000 Subject: [PATCH 09/20] unix: Convert to use core-provided version of built-in import(). --- unix/input.c | 43 ++----------------------------------------- unix/mpconfigport.h | 2 +- unix/mphalport.h | 13 +++++++++++++ 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/unix/input.c b/unix/input.c index 7cd527fedc..4b10350dfc 100644 --- a/unix/input.c +++ b/unix/input.c @@ -37,32 +37,8 @@ #include "lib/mp-readline/readline.h" #endif +#if MICROPY_USE_READLINE == 0 char *prompt(char *p) { -#if MICROPY_USE_READLINE == 1 - // MicroPython supplied readline - vstr_t vstr; - vstr_init(&vstr, 16); - mp_hal_stdio_mode_raw(); - int ret = readline(&vstr, p); - mp_hal_stdio_mode_orig(); - if (ret != 0) { - vstr_clear(&vstr); - if (ret == CHAR_CTRL_D) { - // EOF - printf("\n"); - return NULL; - } else { - printf("\n"); - char *line = malloc(1); - line[0] = '\0'; - return line; - } - } - vstr_null_terminated_str(&vstr); - char *line = malloc(vstr.len + 1); - memcpy(line, vstr.buf, vstr.len + 1); - vstr_clear(&vstr); -#else // simple read string static char buf[256]; fputs(p, stdout); @@ -78,9 +54,9 @@ char *prompt(char *p) { } char *line = malloc(l); memcpy(line, buf, l); -#endif return line; } +#endif void prompt_read_history(void) { #if MICROPY_USE_READLINE_HISTORY @@ -143,18 +119,3 @@ void prompt_write_history(void) { #endif #endif } - -STATIC mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) { - if (n_args == 1) { - mp_obj_print(args[0], PRINT_STR); - } - - char *line = prompt(""); - if (line == NULL) { - nlr_raise(mp_obj_new_exception(&mp_type_EOFError)); - } - mp_obj_t o = mp_obj_new_str(line, strlen(line), false); - free(line); - return o; -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input); diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index d8b8e9d1e8..047121fe66 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -81,6 +81,7 @@ #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_COMPILE (1) #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_POW3 (1) #define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) @@ -279,7 +280,6 @@ void mp_unix_mark_exec(void); #endif #define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_input), MP_ROM_PTR(&mp_builtin_input_obj) }, \ { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, #define MP_STATE_PORT MP_STATE_VM diff --git a/unix/mphalport.h b/unix/mphalport.h index 00e79ec17c..cf227872f9 100644 --- a/unix/mphalport.h +++ b/unix/mphalport.h @@ -34,6 +34,19 @@ void mp_hal_set_interrupt_char(char c); void mp_hal_stdio_mode_raw(void); void mp_hal_stdio_mode_orig(void); +#if MICROPY_USE_READLINE == 1 && MICROPY_PY_BUILTINS_INPUT +#include "py/misc.h" +#include "lib/mp-readline/readline.h" +// For built-in input() we need to wrap the standard readline() to enable raw mode +#define mp_hal_readline mp_hal_readline +static inline int mp_hal_readline(vstr_t *vstr, const char *p) { + mp_hal_stdio_mode_raw(); + int ret = readline(vstr, p); + mp_hal_stdio_mode_orig(); + return ret; +} +#endif + // TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep: // "The useconds argument shall be less than one million." static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); } From 00e4f0590759c69371a3f57208863be7ef375083 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Jun 2017 16:29:02 +1000 Subject: [PATCH 10/20] windows: Convert to use core-provided version of built-in import(). --- windows/mpconfigport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index 8cef506713..f2f6cbd323 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -69,6 +69,7 @@ #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_COMPILE (1) #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) +#define MICROPY_PY_BUILTINS_INPUT (1) #define MICROPY_PY_BUILTINS_POW3 (1) #define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) @@ -163,7 +164,6 @@ void mp_hal_dupterm_tx_strn(const char *str, size_t len); #endif #define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, extern const struct _mp_obj_module_t mp_module_os; From ab954ed5136af8be910b3c3fb9246bad6289a3a4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2017 12:03:57 +1000 Subject: [PATCH 11/20] lib/utils/interrupt_char: Remove support for KBD_EXCEPTION disabled. If a port is using interrupt_char.c then it must enable MICROPY_KBD_EXCEPTION. This is the case for all official ports. --- lib/utils/interrupt_char.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/utils/interrupt_char.c b/lib/utils/interrupt_char.c index 344db88c72..fca0f95b5b 100644 --- a/lib/utils/interrupt_char.c +++ b/lib/utils/interrupt_char.c @@ -27,28 +27,24 @@ #include "py/obj.h" #include "py/mpstate.h" +#if MICROPY_KBD_EXCEPTION + int mp_interrupt_char; void mp_hal_set_interrupt_char(int c) { if (c != -1) { - #if MICROPY_KBD_EXCEPTION mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))); - #else - mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_kbd_exception)); - #endif } mp_interrupt_char = c; } void mp_keyboard_interrupt(void) { - #if MICROPY_KBD_EXCEPTION MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)); - #else - MP_STATE_VM(mp_pending_exception) = MP_STATE_PORT(mp_kbd_exception); - #endif #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; } #endif } + +#endif From 9f85c4fe488a8f123348786448f534263dc003e1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2017 13:07:22 +1000 Subject: [PATCH 12/20] py/objstr: Catch case of negative "maxsplit" arg to str.rsplit(). Negative values mean no limit on the number of splits so should delegate to the .split() method. --- py/objstr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/py/objstr.c b/py/objstr.c index a1e2235720..1d2a280453 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -602,6 +602,11 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], s, len); mp_int_t splits = mp_obj_get_int(args[2]); + if (splits < 0) { + // Negative limit means no limit, so delegate to split(). + return mp_obj_str_split(n_args, args); + } + mp_int_t org_splits = splits; // Preallocate list to the max expected # of elements, as we // will fill it from the end. From 7400d88762570b110d70752dea741fbca778818c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2017 13:08:18 +1000 Subject: [PATCH 13/20] tests/basics/string_rsplit: Add tests for negative "maxsplit" argument. --- tests/basics/string_rsplit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/basics/string_rsplit.py b/tests/basics/string_rsplit.py index 563b64f1c9..b92b8f359f 100644 --- a/tests/basics/string_rsplit.py +++ b/tests/basics/string_rsplit.py @@ -52,3 +52,7 @@ print("/*10/*11/*12/*".rsplit("/*", 4)) print("/*10/*11/*12/*".rsplit("/*", 5)) print(b"abcabc".rsplit(b"bc", 2)) + +# negative "maxsplit" should delegate to .split() +print('abaca'.rsplit('a', -1)) +print('abaca'.rsplit('a', -2)) From 22ca5390f7ec55400bd55cec5e52fc6c704f8be7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 31 May 2017 22:57:11 +0300 Subject: [PATCH 14/20] docs/esp8266/quickref: Polish Pin.on()/off() examples. --- docs/esp8266/quickref.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/esp8266/quickref.rst b/docs/esp8266/quickref.rst index 406a5bb456..ccf6365c83 100644 --- a/docs/esp8266/quickref.rst +++ b/docs/esp8266/quickref.rst @@ -107,9 +107,9 @@ Use the :ref:`machine.Pin ` class:: from machine import Pin p0 = Pin(0, Pin.OUT) # create output pin on GPIO0 - p0.on() # turn on pin, set to high - p0.off() # turn off pin, set to low - p0.value(1) # set pin to high + p0.on() # set pin to "on" (high) level + p0.off() # set pin to "off" (low) level + p0.value(1) # set pin to on/high p2 = Pin(2, Pin.IN) # create input pin on GPIO2 print(p2.value()) # get value, 0 or 1 From 92206a78aeddf81eca08fb25589231e5a62df69c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 3 Jun 2017 13:34:28 +0300 Subject: [PATCH 15/20] docs/network: Move confusingly-named cc3200 Server class to its reference. cc3200 port has network.Server class to control behavior of builtin Telnet/FTP server of that port. --- docs/library/network.rst | 46 ---------------------------------------- docs/wipy/general.rst | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/docs/library/network.rst b/docs/library/network.rst index 251e68c76e..75640250f7 100644 --- a/docs/library/network.rst +++ b/docs/library/network.rst @@ -29,52 +29,6 @@ For example:: data = s.recv(1000) s.close() -.. only:: port_wipy - - .. _network.Server: - - class Server - ============ - - The ``Server`` class controls the behaviour and the configuration of the FTP and telnet - services running on the WiPy. Any changes performed using this class' methods will - affect both. - - Example:: - - import network - server = network.Server() - server.deinit() # disable the server - # enable the server again with new settings - server.init(login=('user', 'password'), timeout=600) - - Constructors - ------------ - - .. class:: network.Server(id, ...) - - Create a server instance, see ``init`` for parameters of initialization. - - Methods - ------- - - .. method:: server.init(\*, login=('micro', 'python'), timeout=300) - - Init (and effectively start the server). Optionally a new ``user``, ``password`` - and ``timeout`` (in seconds) can be passed. - - .. method:: server.deinit() - - Stop the server - - .. method:: server.timeout([timeout_in_seconds]) - - Get or set the server timeout. - - .. method:: server.isrunning() - - Returns ``True`` if the server is running, ``False`` otherwise. - .. only:: port_pyboard class CC3K diff --git a/docs/wipy/general.rst b/docs/wipy/general.rst index 8b9b91c534..ca6f77ab05 100644 --- a/docs/wipy/general.rst +++ b/docs/wipy/general.rst @@ -323,3 +323,40 @@ Unrelated function in machine module this function is not called then the default file main.py will be executed. It only makes sense to call this function from within boot.py. + +Adhoc way to control telnet/FTP server via network module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``Server`` class controls the behaviour and the configuration of the FTP and telnet +services running on the WiPy. Any changes performed using this class' methods will +affect both. + +Example:: + + import network + server = network.Server() + server.deinit() # disable the server + # enable the server again with new settings + server.init(login=('user', 'password'), timeout=600) + +.. class:: network.Server(id, ...) + + Create a server instance, see ``init`` for parameters of initialization. + +.. method:: server.init(\*, login=('micro', 'python'), timeout=300) + + Init (and effectively start the server). Optionally a new ``user``, ``password`` + and ``timeout`` (in seconds) can be passed. + +.. method:: server.deinit() + + Stop the server + +.. method:: server.timeout([timeout_in_seconds]) + + Get or set the server timeout. + +.. method:: server.isrunning() + + Returns ``True`` if the server is running, ``False`` otherwise. + From 1ce44f30467e4882580ca8545f15ba7d882cb428 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 3 Jun 2017 13:51:13 +0300 Subject: [PATCH 16/20] docs/uos: Deconditionalize, remove minor port-specific details. For a couple of ports, there was information which directory is set as current after boot. This information doesn't belong to "uos" module, and is moved to boards' references (which actually already contained information on which directory is chosen for boot, even if without explicit mentioning that it becomes current directory, which is now done). --- docs/library/uos.rst | 21 +-------------------- docs/pyboard/general.rst | 4 +++- docs/wipy/general.rst | 2 +- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/docs/library/uos.rst b/docs/library/uos.rst index d1f83d2cc3..82ed5dbc93 100644 --- a/docs/library/uos.rst +++ b/docs/library/uos.rst @@ -4,28 +4,9 @@ .. module:: uos :synopsis: basic "operating system" services -The ``os`` module contains functions for filesystem access and ``urandom`` +The ``uos`` module contains functions for filesystem access and ``urandom`` function. -Port specifics --------------- - -The filesystem has ``/`` as the root directory and the -available physical drives are accessible from here. They are currently: - - ``/flash`` -- the internal flash filesystem - - ``/sd`` -- the SD card (if it exists) - -.. only:: port_pyboard - - On boot up, the current directory is ``/flash`` if no SD card is inserted, - otherwise it is ``/sd``. - -.. only:: port_wipy - - On boot up, the current directory is ``/flash``. - Functions --------- diff --git a/docs/pyboard/general.rst b/docs/pyboard/general.rst index 48e0146442..1d040f6ccc 100644 --- a/docs/pyboard/general.rst +++ b/docs/pyboard/general.rst @@ -10,7 +10,9 @@ is inserted into the slot, it is available as ``/sd``. When the pyboard boots up, it needs to choose a filesystem to boot from. If there is no SD card, then it uses the internal filesystem ``/flash`` as the boot -filesystem, otherwise, it uses the SD card ``/sd``. +filesystem, otherwise, it uses the SD card ``/sd``. After the boot, the current +directory is set to one of the directories above. + If needed, you can prevent the use of the SD card by creating an empty file called ``/flash/SKIPSD``. If this file exists when the pyboard boots up then the SD card will be skipped and the pyboard will always boot from the diff --git a/docs/wipy/general.rst b/docs/wipy/general.rst index ca6f77ab05..1e396518e0 100644 --- a/docs/wipy/general.rst +++ b/docs/wipy/general.rst @@ -53,7 +53,7 @@ which is stored within the external serial flash memory. If a micro SD card is hooked-up and mounted, it will be available as well. When the WiPy starts up, it always boots from the ``boot.py`` located in the -``/flash`` file system. +``/flash`` file system. On boot up, the current directory is ``/flash``. The file system is accessible via the native FTP server running in the WiPy. Open your FTP client of choice and connect to: From e91b1cdae38d693fbd34a57341d8c72737f0ec22 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 3 Jun 2017 14:19:53 +0300 Subject: [PATCH 17/20] docs/uos: Move cc3200 port legacy VFS mounting functions to its ref doc. This patch also unconditionalizes uos.dupterm(), though exact interface and semantics is yet to be defined. --- docs/library/uos.rst | 26 ++++---------------------- docs/wipy/general.rst | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/docs/library/uos.rst b/docs/library/uos.rst index 82ed5dbc93..3d0aa46c70 100644 --- a/docs/library/uos.rst +++ b/docs/library/uos.rst @@ -87,26 +87,8 @@ Functions Return a bytes object with n random bytes. Whenever possible, it is generated by the hardware random number generator. -.. only:: port_wipy +.. function:: dupterm(stream_object) - .. function:: mount(block_device, mount_point, \*, readonly=False) - - Mounts a block device (like an ``SD`` object) in the specified mount - point. Example:: - - os.mount(sd, '/sd') - - .. function:: unmount(path) - - Unmounts a previously mounted block device from the given path. - - .. function:: mkfs(block_device or path) - - Formats the specified path, must be either ``/flash`` or ``/sd``. - A block device can also be passed like an ``SD`` object before - being mounted. - - .. function:: dupterm(stream_object) - - Duplicate the terminal (the REPL) on the passed stream-like object. - The given object must at least implement the ``.read()`` and ``.write()`` methods. + Duplicate or switch MicroPython terminal (the REPL) on the passed stream-like + object. The given object must implement the `.readinto()` and `.write()` + methods. If ``None`` is passed, previously set redirection is cancelled. diff --git a/docs/wipy/general.rst b/docs/wipy/general.rst index 1e396518e0..f28edb4e4b 100644 --- a/docs/wipy/general.rst +++ b/docs/wipy/general.rst @@ -360,3 +360,26 @@ Example:: Returns ``True`` if the server is running, ``False`` otherwise. +Adhoc VFS-like support +~~~~~~~~~~~~~~~~~~~~~~ + +WiPy doesn't implement full MicroPython VFS support, instead following +functions are defined in ``uos`` module: + +.. function:: mount(block_device, mount_point, \*, readonly=False) + + Mounts a block device (like an ``SD`` object) in the specified mount + point. Example:: + + os.mount(sd, '/sd') + +.. function:: unmount(path) + + Unmounts a previously mounted block device from the given path. + +.. function:: mkfs(block_device or path) + + Formats the specified path, must be either ``/flash`` or ``/sd``. + A block device can also be passed like an ``SD`` object before + being mounted. + From f245f5d7cc62ae60c73d51d9962a995ff3e579c5 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 3 Jun 2017 14:50:54 +0300 Subject: [PATCH 18/20] docs/machine: Sort machine classes in logical order, not alphabetically. The list starts with the simplest functionality - GPIO, proceeds to communication interfaces (UART, SPI, I2C), the to time(r) related things, then everything else. --- docs/library/machine.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/library/machine.rst b/docs/library/machine.rst index c2c6b83fd6..7ea7f565e7 100644 --- a/docs/library/machine.rst +++ b/docs/library/machine.rst @@ -145,13 +145,13 @@ Classes .. toctree:: :maxdepth: 1 - machine.I2C.rst machine.Pin.rst machine.Signal.rst - machine.RTC.rst - machine.SPI.rst - machine.Timer.rst machine.UART.rst + machine.SPI.rst + machine.I2C.rst + machine.RTC.rst + machine.Timer.rst machine.WDT.rst .. only:: port_wipy @@ -159,12 +159,12 @@ Classes .. toctree:: :maxdepth: 1 - machine.ADC.rst - machine.I2C.rst machine.Pin.rst - machine.RTC.rst - machine.SD.rst - machine.SPI.rst - machine.Timer.rst machine.UART.rst + machine.SPI.rst + machine.I2C.rst + machine.RTC.rst + machine.Timer.rst machine.WDT.rst + machine.ADC.rst + machine.SD.rst From 43f58386e0686943c053d529a1e5f39ba5d7e3ad Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 3 Jun 2017 16:10:12 +0300 Subject: [PATCH 19/20] zephyr/modusocket: getaddrinfo: Fix mp_obj_len() usage. Return value is mp_obj_t, so needs to be accessed using MP_OBJ_SMALL_INT_VALUE(). --- zephyr/modusocket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zephyr/modusocket.c b/zephyr/modusocket.c index 0a54ea576c..cec0eec7c4 100644 --- a/zephyr/modusocket.c +++ b/zephyr/modusocket.c @@ -587,7 +587,8 @@ STATIC mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) { // Raise error only if there's nothing to return, otherwise // it may be IPv4 vs IPv6 differences. - if (state.status != 0 && mp_obj_len(state.result) == 0) { + mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(state.result)); + if (state.status != 0 && len == 0) { mp_raise_OSError(state.status); } From a0dbbbebb8c0286e00ae06751b0173cbca4ec801 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 3 Jun 2017 22:32:07 +0300 Subject: [PATCH 20/20] extmod/modlwip: connect: For non-blocking mode, return EINPROGRESS. Instead of ETIMEDOUT. This is consistent with POSIX: http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html --- extmod/modlwip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 47669cb3a0..aa93eaa276 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -822,7 +822,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { if (socket->state != STATE_CONNECTING) break; } if (socket->state == STATE_CONNECTING) { - mp_raise_OSError(MP_ETIMEDOUT); + mp_raise_OSError(MP_EINPROGRESS); } } else { while (socket->state == STATE_CONNECTING) {