Merge remote-tracking branch 'upstream/master' into nrf5_no_sdk
This commit is contained in:
commit
933507e980
|
@ -24,7 +24,7 @@ a change in a detail, if needed. Any change beyond 5 lines would likely
|
|||
require such detailed description.
|
||||
|
||||
To get good practical examples of good commits and their messages, browse
|
||||
thry the `git log` of the project.
|
||||
the `git log` of the project.
|
||||
|
||||
Python code conventions
|
||||
=======================
|
||||
|
|
|
@ -684,13 +684,6 @@ STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
|
||||
|
||||
STATIC mp_obj_t pin_toggle(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
MAP_GPIOPinWrite(self->port, self->bit, ~MAP_GPIOPinRead(self->port, self->bit));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_toggle_obj, pin_toggle);
|
||||
|
||||
STATIC mp_obj_t pin_id(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
return MP_OBJ_NEW_QSTR(self->name);
|
||||
|
@ -913,7 +906,6 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = {
|
|||
// instance methods
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pin_init_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pin_value_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&pin_toggle_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_id), (mp_obj_t)&pin_id_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&pin_mode_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pull), (mp_obj_t)&pin_pull_obj },
|
||||
|
|
|
@ -97,9 +97,9 @@ copyright = '2014-2017, Damien P. George, Paul Sokolovsky, and contributors'
|
|||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '1.8'
|
||||
version = '1.9'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '1.8.7'
|
||||
release = '1.9'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
|
@ -158,11 +158,6 @@ Methods
|
|||
and get the value of the pin. It is equivalent to Pin.value([x]).
|
||||
See :meth:`Pin.value` for more details.
|
||||
|
||||
.. method:: Pin.id()
|
||||
|
||||
Get the pin identifier. This may return the ``id`` as specified in the
|
||||
constructor. Or it may return a canonical software-specific pin id.
|
||||
|
||||
.. method:: Pin.mode([mode])
|
||||
|
||||
Get or set the pin mode.
|
||||
|
@ -217,19 +212,6 @@ Methods
|
|||
|
||||
This method returns a callback object.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
.. class:: Pin.board
|
||||
|
||||
Contains all ``Pin`` objects supported by the board. Examples::
|
||||
|
||||
Pin.board.GP25
|
||||
led = Pin(Pin.board.GP25, mode=Pin.OUT)
|
||||
Pin.board.GP2.alt_list()
|
||||
|
||||
Availability: WiPy.
|
||||
|
||||
Constants
|
||||
---------
|
||||
|
||||
|
|
|
@ -65,8 +65,16 @@ Methods
|
|||
|
||||
.. method:: UART.any()
|
||||
|
||||
Return true value if there're characters available for reading. On some
|
||||
boards, the number of available characters is returned.
|
||||
Returns an integer counting the number of characters that can be read without
|
||||
blocking. It will return 0 if there are no characters available and a positive
|
||||
number if there are characters. The method may return 1 even if there is more
|
||||
than one character available for reading.
|
||||
|
||||
For more sophisticated querying of available characters use select.poll::
|
||||
|
||||
poll = select.poll()
|
||||
poll.register(uart, select.POLLIN)
|
||||
poll.poll(timeout)
|
||||
|
||||
.. method:: UART.read([nbytes])
|
||||
|
||||
|
|
|
@ -139,23 +139,23 @@ class SSD1306_SPI(SSD1306):
|
|||
|
||||
def write_cmd(self, cmd):
|
||||
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
||||
self.cs.high()
|
||||
self.dc.low()
|
||||
self.cs.low()
|
||||
self.cs(1)
|
||||
self.dc(0)
|
||||
self.cs(0)
|
||||
self.spi.write(bytearray([cmd]))
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
|
||||
def write_data(self, buf):
|
||||
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
|
||||
self.cs.high()
|
||||
self.dc.high()
|
||||
self.cs.low()
|
||||
self.cs(1)
|
||||
self.dc(1)
|
||||
self.cs(0)
|
||||
self.spi.write(buf)
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
|
||||
def poweron(self):
|
||||
self.res.high()
|
||||
self.res(1)
|
||||
time.sleep_ms(1)
|
||||
self.res.low()
|
||||
self.res(0)
|
||||
time.sleep_ms(10)
|
||||
self.res.high()
|
||||
self.res(1)
|
||||
|
|
|
@ -66,8 +66,8 @@ class NRF24L01:
|
|||
ce.init(ce.OUT, value=0)
|
||||
|
||||
# reset everything
|
||||
self.ce.low()
|
||||
self.cs.high()
|
||||
self.ce(0)
|
||||
self.cs(1)
|
||||
self.payload_size = payload_size
|
||||
self.pipe0_read_addr = None
|
||||
utime.sleep_ms(5)
|
||||
|
@ -109,36 +109,36 @@ class NRF24L01:
|
|||
self.spi.init(master, baudrate=baudrate, polarity=0, phase=0)
|
||||
|
||||
def reg_read(self, reg):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.readinto(self.buf, reg)
|
||||
self.spi.readinto(self.buf)
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
return self.buf[0]
|
||||
|
||||
def reg_write_bytes(self, reg, buf):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.readinto(self.buf, 0x20 | reg)
|
||||
self.spi.write(buf)
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
return self.buf[0]
|
||||
|
||||
def reg_write(self, reg, value):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.readinto(self.buf, 0x20 | reg)
|
||||
ret = self.buf[0]
|
||||
self.spi.readinto(self.buf, value)
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
return ret
|
||||
|
||||
def flush_rx(self):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.readinto(self.buf, FLUSH_RX)
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
|
||||
def flush_tx(self):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.readinto(self.buf, FLUSH_TX)
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
|
||||
# power is one of POWER_x defines; speed is one of SPEED_x defines
|
||||
def set_power_speed(self, power, speed):
|
||||
|
@ -190,11 +190,11 @@ class NRF24L01:
|
|||
|
||||
self.flush_rx()
|
||||
self.flush_tx()
|
||||
self.ce.high()
|
||||
self.ce(1)
|
||||
utime.sleep_us(130)
|
||||
|
||||
def stop_listening(self):
|
||||
self.ce.low()
|
||||
self.ce(0)
|
||||
self.flush_tx()
|
||||
self.flush_rx()
|
||||
|
||||
|
@ -204,10 +204,10 @@ class NRF24L01:
|
|||
|
||||
def recv(self):
|
||||
# get the data
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.readinto(self.buf, R_RX_PAYLOAD)
|
||||
buf = self.spi.read(self.payload_size)
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
# clear RX ready flag
|
||||
self.reg_write(STATUS, RX_DR)
|
||||
|
||||
|
@ -229,17 +229,17 @@ class NRF24L01:
|
|||
self.reg_write(CONFIG, (self.reg_read(CONFIG) | PWR_UP) & ~PRIM_RX)
|
||||
utime.sleep_us(150)
|
||||
# send the data
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.readinto(self.buf, W_TX_PAYLOAD)
|
||||
self.spi.write(buf)
|
||||
if len(buf) < self.payload_size:
|
||||
self.spi.write(b'\x00' * (self.payload_size - len(buf))) # pad out data
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
|
||||
# enable the chip so it can send the data
|
||||
self.ce.high()
|
||||
self.ce(1)
|
||||
utime.sleep_us(15) # needs to be >10us
|
||||
self.ce.low()
|
||||
self.ce(0)
|
||||
|
||||
# returns None if send still in progress, 1 for success, 2 for fail
|
||||
def send_done(self):
|
||||
|
|
|
@ -7,11 +7,11 @@ temperature sensors. It supports multiple devices on the same 1-wire bus.
|
|||
The following example assumes the ground of your DS18x20 is connected to
|
||||
Y11, vcc is connected to Y9 and the data pin is connected to Y10.
|
||||
|
||||
>>> from pyb import Pin
|
||||
>>> from machine import Pin
|
||||
>>> gnd = Pin('Y11', Pin.OUT_PP)
|
||||
>>> gnd.low()
|
||||
>>> gnd.off()
|
||||
>>> vcc = Pin('Y9', Pin.OUT_PP)
|
||||
>>> vcc.high()
|
||||
>>> vcc.on()
|
||||
|
||||
>>> from ds18x20 import DS18X20
|
||||
>>> d = DS18X20(Pin('Y10'))
|
||||
|
|
|
@ -130,7 +130,7 @@ class SDCard:
|
|||
raise OSError("timeout waiting for v2 card")
|
||||
|
||||
def cmd(self, cmd, arg, crc, final=0, release=True):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
|
||||
# create and send the command
|
||||
buf = self.cmdbuf
|
||||
|
@ -150,12 +150,12 @@ class SDCard:
|
|||
for j in range(final):
|
||||
self.spi.write(b'\xff')
|
||||
if release:
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
return response
|
||||
|
||||
# timeout
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
return -1
|
||||
|
||||
|
@ -164,15 +164,15 @@ class SDCard:
|
|||
self.spi.read(1, 0xff) # ignore stuff byte
|
||||
for _ in range(_CMD_TIMEOUT):
|
||||
if self.spi.read(1, 0xff)[0] == 0xff:
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
return 0 # OK
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
return 1 # timeout
|
||||
|
||||
def readinto(self, buf):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
|
||||
# read until start byte (0xff)
|
||||
while self.spi.read(1, 0xff)[0] != 0xfe:
|
||||
|
@ -186,11 +186,11 @@ class SDCard:
|
|||
self.spi.write(b'\xff')
|
||||
self.spi.write(b'\xff')
|
||||
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
|
||||
def write(self, token, buf):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
|
||||
# send: start of block, data, checksum
|
||||
self.spi.read(1, token)
|
||||
|
@ -200,7 +200,7 @@ class SDCard:
|
|||
|
||||
# check the response
|
||||
if (self.spi.read(1, 0xff)[0] & 0x1f) != 0x05:
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
return
|
||||
|
||||
|
@ -208,18 +208,18 @@ class SDCard:
|
|||
while self.spi.read(1, 0xff)[0] == 0:
|
||||
pass
|
||||
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
|
||||
def write_token(self, token):
|
||||
self.cs.low()
|
||||
self.cs(0)
|
||||
self.spi.read(1, token)
|
||||
self.spi.write(b'\xff')
|
||||
# wait for write to finish
|
||||
while self.spi.read(1, 0xff)[0] == 0x00:
|
||||
pass
|
||||
|
||||
self.cs.high()
|
||||
self.cs(1)
|
||||
self.spi.write(b'\xff')
|
||||
|
||||
def count(self):
|
||||
|
|
|
@ -336,21 +336,19 @@ STATIC mp_obj_t pyb_pin_value(mp_uint_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_pin_value_obj, 1, 2, pyb_pin_value);
|
||||
|
||||
// pin.low()
|
||||
STATIC mp_obj_t pyb_pin_low(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t pyb_pin_off(mp_obj_t self_in) {
|
||||
pyb_pin_obj_t *self = self_in;
|
||||
pin_set(self->phys_port, 0);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_low_obj, pyb_pin_low);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_off_obj, pyb_pin_off);
|
||||
|
||||
// pin.high()
|
||||
STATIC mp_obj_t pyb_pin_high(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t pyb_pin_on(mp_obj_t self_in) {
|
||||
pyb_pin_obj_t *self = self_in;
|
||||
pin_set(self->phys_port, 1);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_high_obj, pyb_pin_high);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_on_obj, pyb_pin_on);
|
||||
|
||||
// pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False)
|
||||
STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
@ -410,8 +408,8 @@ STATIC const mp_map_elem_t pyb_pin_locals_dict_table[] = {
|
|||
// instance methods
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_pin_init_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pyb_pin_value_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_low), (mp_obj_t)&pyb_pin_low_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_high), (mp_obj_t)&pyb_pin_high_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&pyb_pin_off_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&pyb_pin_on_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_pin_irq_obj },
|
||||
|
||||
// class constants
|
||||
|
|
|
@ -193,9 +193,16 @@ STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
|
||||
|
||||
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_NEW_SMALL_INT(uart_rx_any(self->uart_id));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_uart_init_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&pyb_uart_any_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
|
|
|
@ -8,6 +8,6 @@ try:
|
|||
uos.mount(bdev, '/')
|
||||
except OSError:
|
||||
import inisetup
|
||||
vfs = inisetup.setup()
|
||||
inisetup.setup()
|
||||
|
||||
gc.collect()
|
||||
|
|
|
@ -38,8 +38,7 @@ def setup():
|
|||
wifi()
|
||||
uos.VfsFat.mkfs(bdev)
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, '/flash')
|
||||
uos.chdir('/flash')
|
||||
uos.mount(vfs, '/')
|
||||
with open("boot.py", "w") as f:
|
||||
f.write("""\
|
||||
# This file is executed on every boot (including wake-boot from deepsleep)
|
||||
|
|
|
@ -161,7 +161,6 @@ extern const struct _mp_obj_module_t onewire_module;
|
|||
|
||||
#define MICROPY_PORT_BUILTIN_MODULES \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_lwip), (mp_obj_t)&mp_module_lwip }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_lwip }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_lwip }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&network_module }, \
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# The following is a temporary hack to forefully undefine vars that might have
|
||||
# be defined by a calling Makefile (from recursive make).
|
||||
# TODO: Find a better way to be able to call this Makefile recursively.
|
||||
ifneq ($(findstring undefine,$(.FEATURES)),)
|
||||
override undefine COPT
|
||||
override undefine CFLAGS_EXTRA
|
||||
override undefine LDFLAGS_EXTRA
|
||||
|
@ -8,6 +9,7 @@ override undefine FROZEN_DIR
|
|||
override undefine FROZEN_MPY_DIR
|
||||
override undefine BUILD
|
||||
override undefine PROG
|
||||
endif
|
||||
|
||||
include ../py/mkenv.mk
|
||||
|
||||
|
|
24
py/emitbc.c
24
py/emitbc.c
|
@ -448,7 +448,19 @@ bool mp_emit_bc_last_emit_was_return_value(emit_t *emit) {
|
|||
}
|
||||
|
||||
void mp_emit_bc_adjust_stack_size(emit_t *emit, mp_int_t delta) {
|
||||
if (emit->pass == MP_PASS_SCOPE) {
|
||||
return;
|
||||
}
|
||||
assert((mp_int_t)emit->stack_size + delta >= 0);
|
||||
emit->stack_size += delta;
|
||||
if (emit->stack_size > emit->scope->stack_size) {
|
||||
emit->scope->stack_size = emit->stack_size;
|
||||
}
|
||||
emit->last_emit_was_return_value = false;
|
||||
}
|
||||
|
||||
static inline void emit_bc_pre(emit_t *emit, mp_int_t stack_size_delta) {
|
||||
mp_emit_bc_adjust_stack_size(emit, stack_size_delta);
|
||||
}
|
||||
|
||||
void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) {
|
||||
|
@ -471,18 +483,6 @@ void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) {
|
|||
#endif
|
||||
}
|
||||
|
||||
STATIC void emit_bc_pre(emit_t *emit, mp_int_t stack_size_delta) {
|
||||
if (emit->pass == MP_PASS_SCOPE) {
|
||||
return;
|
||||
}
|
||||
assert((mp_int_t)emit->stack_size + stack_size_delta >= 0);
|
||||
emit->stack_size += stack_size_delta;
|
||||
if (emit->stack_size > emit->scope->stack_size) {
|
||||
emit->scope->stack_size = emit->stack_size;
|
||||
}
|
||||
emit->last_emit_was_return_value = false;
|
||||
}
|
||||
|
||||
void mp_emit_bc_label_assign(emit_t *emit, mp_uint_t l) {
|
||||
emit_bc_pre(emit, 0);
|
||||
if (emit->pass == MP_PASS_SCOPE) {
|
||||
|
|
|
@ -58,9 +58,9 @@ CXX += -m32
|
|||
LD += -m32
|
||||
endif
|
||||
|
||||
MAKE_FROZEN = ../tools/make-frozen.py
|
||||
MPY_CROSS = ../mpy-cross/mpy-cross
|
||||
MPY_TOOL = ../tools/mpy-tool.py
|
||||
MAKE_FROZEN = $(TOP)/tools/make-frozen.py
|
||||
MPY_CROSS = $(TOP)/mpy-cross/mpy-cross
|
||||
MPY_TOOL = $(TOP)/tools/mpy-tool.py
|
||||
|
||||
all:
|
||||
.PHONY: all
|
||||
|
|
|
@ -71,7 +71,7 @@ $(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h
|
|||
|
||||
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) | $(HEADER_BUILD)/mpversion.h
|
||||
$(ECHO) "GEN $@"
|
||||
$(Q)$(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $? >$(HEADER_BUILD)/qstr.i.last;
|
||||
$(Q)$(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(if $?,$?,$^) >$(HEADER_BUILD)/qstr.i.last;
|
||||
|
||||
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last
|
||||
$(ECHO) "GEN $@"
|
||||
|
|
|
@ -72,22 +72,27 @@ STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size,
|
|||
(void)errcode;
|
||||
mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in);
|
||||
check_stringio_is_open(o);
|
||||
mp_int_t remaining = o->vstr->alloc - o->pos;
|
||||
mp_uint_t new_pos = o->pos + size;
|
||||
if (new_pos < size) {
|
||||
// Writing <size> bytes will overflow o->pos beyond limit of mp_uint_t.
|
||||
*errcode = MP_EFBIG;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
mp_uint_t org_len = o->vstr->len;
|
||||
if ((mp_int_t)size > remaining) {
|
||||
if (new_pos > o->vstr->alloc) {
|
||||
// Take all what's already allocated...
|
||||
o->vstr->len = o->vstr->alloc;
|
||||
// ... and add more
|
||||
vstr_add_len(o->vstr, size - remaining);
|
||||
vstr_add_len(o->vstr, new_pos - o->vstr->alloc);
|
||||
}
|
||||
// If there was a seek past EOF, clear the hole
|
||||
if (o->pos > org_len) {
|
||||
memset(o->vstr->buf + org_len, 0, o->pos - org_len);
|
||||
}
|
||||
memcpy(o->vstr->buf + o->pos, buf, size);
|
||||
o->pos += size;
|
||||
if (o->pos > o->vstr->len) {
|
||||
o->vstr->len = o->pos;
|
||||
o->pos = new_pos;
|
||||
if (new_pos > o->vstr->len) {
|
||||
o->vstr->len = new_pos;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
|
4
py/vm.c
4
py/vm.c
|
@ -690,8 +690,7 @@ unwind_jump:;
|
|||
}
|
||||
ip = (const byte*)MP_OBJ_TO_PTR(POP()); // pop destination ip for jump
|
||||
if (unum != 0) {
|
||||
// pop iter and iter_buf
|
||||
sp--;
|
||||
// pop the exhausted iterator
|
||||
sp -= MP_OBJ_ITER_BUF_NSLOTS;
|
||||
}
|
||||
DISPATCH_WITH_PEND_EXC_CHECK();
|
||||
|
@ -1436,6 +1435,7 @@ unwind_loop:
|
|||
} else if (code_state->prev != NULL) {
|
||||
mp_globals_set(code_state->old_globals);
|
||||
code_state = code_state->prev;
|
||||
size_t n_state = mp_decode_uint_value(code_state->fun_bc->bytecode);
|
||||
fastn = &code_state->state[n_state - 1];
|
||||
exc_stack = (mp_exc_stack_t*)(code_state->state + n_state);
|
||||
// variables that are visible to the exception handler (declared volatile)
|
||||
|
|
|
@ -34,15 +34,15 @@ endif
|
|||
## - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/qemu/Makefile
|
||||
LDFLAGS= --specs=nano.specs --specs=rdimon.specs -Wl,--gc-sections -Wl,-Map=$(@:.elf=.map)
|
||||
|
||||
SRC_C = \
|
||||
main.c \
|
||||
SRC_COMMON_C = \
|
||||
moduos.c \
|
||||
modmachine.c \
|
||||
|
||||
SRC_RUN_C = \
|
||||
main.c \
|
||||
|
||||
SRC_TEST_C = \
|
||||
test_main.c \
|
||||
moduos.c \
|
||||
modmachine.c \
|
||||
|
||||
LIB_SRC_C = $(addprefix lib/,\
|
||||
libm/math.c \
|
||||
|
@ -69,25 +69,24 @@ STM_SRC_C = $(addprefix stmhal/,\
|
|||
pybstdio.c \
|
||||
)
|
||||
|
||||
SRC_S = \
|
||||
OBJ_COMMON =
|
||||
OBJ_COMMON += $(PY_O)
|
||||
OBJ_COMMON += $(addprefix $(BUILD)/, $(SRC_COMMON_C:.c=.o))
|
||||
OBJ_COMMON += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
|
||||
OBJ_COMMON += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
|
||||
|
||||
OBJ =
|
||||
OBJ += $(PY_O)
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
|
||||
OBJ_RUN =
|
||||
OBJ_RUN += $(addprefix $(BUILD)/, $(SRC_RUN_C:.c=.o))
|
||||
|
||||
OBJ_TEST =
|
||||
OBJ_TEST += $(PY_O)
|
||||
OBJ_TEST += $(addprefix $(BUILD)/, $(SRC_TEST_C:.c=.o))
|
||||
OBJ_TEST += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
|
||||
OBJ_TEST += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
|
||||
OBJ_TEST += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
|
||||
OBJ_TEST += $(BUILD)/tinytest.o
|
||||
|
||||
# All object files, needed to get dependencies correct
|
||||
OBJ = $(OBJ_COMMON) $(OBJ_RUN) $(OBJ_TEST)
|
||||
|
||||
# List of sources for qstr extraction
|
||||
SRC_QSTR += $(SRC_C) $(STM_SRC_C)
|
||||
SRC_QSTR += $(SRC_COMMON_C) $(SRC_RUN_C) $(STM_SRC_C)
|
||||
|
||||
all: run
|
||||
|
||||
|
@ -109,11 +108,11 @@ $(BUILD)/tinytest.o:
|
|||
$(Q)$(CC) $(CFLAGS) -DNO_FORKING -o $@ -c ../tools/tinytest/tinytest.c
|
||||
|
||||
## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here.
|
||||
$(BUILD)/firmware.elf: $(OBJ)
|
||||
$(BUILD)/firmware.elf: $(OBJ_COMMON) $(OBJ_RUN)
|
||||
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
$(Q)$(SIZE) $@
|
||||
|
||||
$(BUILD)/firmware-test.elf: $(OBJ_TEST)
|
||||
$(BUILD)/firmware-test.elf: $(OBJ_COMMON) $(OBJ_TEST)
|
||||
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
$(Q)$(SIZE) $@
|
||||
|
||||
|
|
19
stmhal/pin.c
19
stmhal/pin.c
|
@ -400,23 +400,19 @@ STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
|
||||
|
||||
/// \method low()
|
||||
/// Set the pin to a low logic level.
|
||||
STATIC mp_obj_t pin_low(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t pin_off(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_hal_pin_low(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off);
|
||||
|
||||
/// \method high()
|
||||
/// Set the pin to a high logic level.
|
||||
STATIC mp_obj_t pin_high(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t pin_on(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_hal_pin_high(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on);
|
||||
|
||||
/// \method name()
|
||||
/// Get the pin name.
|
||||
|
@ -500,8 +496,11 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
|||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_low), MP_ROM_PTR(&pin_low_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&pin_high_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pin_off_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pin_on_obj) },
|
||||
// Legacy names as used by pyb.Pin
|
||||
{ MP_ROM_QSTR(MP_QSTR_low), MP_ROM_PTR(&pin_off_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&pin_on_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_name_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_names), MP_ROM_PTR(&pin_names_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_af_list), MP_ROM_PTR(&pin_af_list_obj) },
|
||||
|
|
|
@ -41,3 +41,28 @@ for i in [1]:
|
|||
break
|
||||
finally:
|
||||
print('finally 4')
|
||||
|
||||
# Test unwind-jump where there is nothing in the body of the try or finally.
|
||||
# This checks that the bytecode emitter allocates enough stack for the unwind.
|
||||
for i in [1]:
|
||||
try:
|
||||
break
|
||||
finally:
|
||||
pass
|
||||
|
||||
# The following test checks that the globals dict is valid after a call to a
|
||||
# function that has an unwind jump.
|
||||
# There was a bug where an unwind jump would trash the globals dict upon return
|
||||
# from a function, because it used the Python-stack incorrectly.
|
||||
def f():
|
||||
for i in [1]:
|
||||
try:
|
||||
break
|
||||
finally:
|
||||
pass
|
||||
def g():
|
||||
global global_var
|
||||
f()
|
||||
print(global_var)
|
||||
global_var = 'global'
|
||||
g()
|
||||
|
|
|
@ -211,7 +211,7 @@ fast:
|
|||
# build a minimal interpreter
|
||||
minimal:
|
||||
$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' \
|
||||
BUILD=build-minimal PROG=micropython_minimal FROZEN_DIR= \
|
||||
BUILD=build-minimal PROG=micropython_minimal FROZEN_DIR= FROZEN_MPY_DIR= \
|
||||
MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 MICROPY_PY_SOCKET=0 MICROPY_PY_THREAD=0 \
|
||||
MICROPY_PY_TERMIOS=0 MICROPY_PY_USSL=0 \
|
||||
MICROPY_USE_READLINE=0
|
||||
|
|
|
@ -138,21 +138,19 @@ STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value);
|
||||
|
||||
// pin.low()
|
||||
STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t machine_pin_off(mp_obj_t self_in) {
|
||||
machine_pin_obj_t *self = self_in;
|
||||
(void)gpio_pin_write(self->port, self->pin, 0);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off);
|
||||
|
||||
// pin.high()
|
||||
STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t machine_pin_on(mp_obj_t self_in) {
|
||||
machine_pin_obj_t *self = self_in;
|
||||
(void)gpio_pin_write(self->port, self->pin, 1);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on);
|
||||
|
||||
STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
(void)errcode;
|
||||
|
@ -176,8 +174,8 @@ STATIC const mp_map_elem_t machine_pin_locals_dict_table[] = {
|
|||
// instance methods
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&machine_pin_init_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&machine_pin_value_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_low), (mp_obj_t)&machine_pin_low_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_high), (mp_obj_t)&machine_pin_high_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&machine_pin_off_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&machine_pin_on_obj },
|
||||
|
||||
// class constants
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IN), MP_OBJ_NEW_SMALL_INT(GPIO_DIR_IN) },
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
#include <net/net_pkt.h>
|
||||
#include <net/dns_resolve.h>
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG // print debugging info
|
||||
#define DEBUG_PRINT 0
|
||||
#if DEBUG_PRINT // print debugging info
|
||||
#define DEBUG_printf printf
|
||||
#else // don't print debugging info
|
||||
#define DEBUG_printf(...) (void)0
|
||||
|
@ -165,7 +165,7 @@ static void sock_received_cb(struct net_context *context, struct net_pkt *pkt, i
|
|||
DEBUG_printf(" (appdatalen=%d), token: %p", pkt->appdatalen, net_pkt_token(pkt));
|
||||
}
|
||||
DEBUG_printf("\n");
|
||||
#if DEBUG > 1
|
||||
#if DEBUG_PRINT > 1
|
||||
net_pkt_print_frags(pkt);
|
||||
#endif
|
||||
|
||||
|
@ -533,12 +533,18 @@ typedef struct _getaddrinfo_state_t {
|
|||
mp_obj_t result;
|
||||
struct k_sem sem;
|
||||
mp_obj_t port;
|
||||
int status;
|
||||
} getaddrinfo_state_t;
|
||||
|
||||
void dns_resolve_cb(enum dns_resolve_status status, struct dns_addrinfo *info, void *user_data) {
|
||||
getaddrinfo_state_t *state = user_data;
|
||||
DEBUG_printf("dns status: %d\n", status);
|
||||
|
||||
if (info == NULL) {
|
||||
if (status == DNS_EAI_ALLDONE) {
|
||||
status = 0;
|
||||
}
|
||||
state->status = status;
|
||||
k_sem_give(&state->sem);
|
||||
return;
|
||||
}
|
||||
|
@ -569,7 +575,6 @@ STATIC mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||
state.result = mp_obj_new_list(0, NULL);
|
||||
k_sem_init(&state.sem, 0, UINT_MAX);
|
||||
|
||||
int status;
|
||||
for (int i = 2; i--;) {
|
||||
int type = (family != AF_INET6 ? DNS_QUERY_TYPE_A : DNS_QUERY_TYPE_AAAA);
|
||||
RAISE_ERRNO(dns_get_addr_info(host, type, NULL, dns_resolve_cb, &state, 3000));
|
||||
|
@ -580,6 +585,12 @@ STATIC mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||
family = AF_INET6;
|
||||
}
|
||||
|
||||
// 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_raise_OSError(state.status);
|
||||
}
|
||||
|
||||
return state.result;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_getaddrinfo_obj, 2, 3, mod_getaddrinfo);
|
||||
|
|
Loading…
Reference in New Issue