Commit Graph

415 Commits

Author SHA1 Message Date
Damien George
304cfda8c4 py/stream: Move ad-hoc ioctl constants to stream.h and rename them.
The constants MP_IOCTL_POLL_xxx, which were stmhal-specific, are moved
from stmhal/pybioctl.h (now deleted) to py/stream.h.  And they are renamed
to MP_STREAM_POLL_xxx to be consistent with other such constants.

All uses of these constants have been updated.
2016-12-02 16:37:29 +11:00
Damien George
b7df3e541a extmod/vfs_fat: Implement POSIX behaviour of rename, allow to overwrite.
If the destination of os.rename() exists then it will be overwritten if it
is a file.  This is the POSIX behaviour, which is also the CPython
behaviour, and so we follow suit.

See issue #2598 for discussion.
2016-12-02 15:06:09 +11:00
Damien George
a081b49d55 extmod/modframebuf: Optimise fill and fill_rect methods.
Fill is a very common operation (eg to clear the screen) and it is worth
optimising it, by providing a specialised fill_rect function for each
framebuffer format.

This patch improved the speed of fill by 10 times for a 16-bit display
with 160*128 pixels.
2016-12-01 16:51:31 +11:00
Damien George
81e171b7bb extmod/modframebuf: Add back legacy FrameBuffer1 "class".
For backwards compatibility.  It simple creates a frame buffer with the
MVLSB format.
2016-12-01 16:43:25 +11:00
Radomir Dopieralski
225e22b287 extmod/modframebuf: Make FrameBuffer handle 16bit depth.
Rename FrameBuffer1 into FrameBuffer and make it handle different bit
depths via a method table that has getpixel and setpixel.  Currently
supported formats are MVLSB (monochrome, vertical, LSB) and RGB565.

Also add blit() and fill_rect() methods.
2016-12-01 16:43:25 +11:00
Damien George
8b8242954e extmod/modurandom: Allow to build with float disabled. 2016-11-30 12:58:54 +11:00
Damien George
5d2279bec1 extmod/machine_i2c: Add hook to constructor to call port-specific code.
If MICROPY_PY_MACHINE_I2C_MAKE_NEW is defined then it is called when an
I2C object is constructed with an id which is not -1.
2016-11-24 00:12:51 +11:00
Damien George
8b74048d2a extmod/machine_i2c: Expose soft I2C obj and readfrom/writeto funcs.
For external use by ports if needed.
2016-11-24 00:11:45 +11:00
Damien George
4c905616f0 extmod/machine_i2c: Remove trivial function wrappers. 2016-11-23 17:05:38 +11:00
Damien George
37333cb00a extmod/machine_i2c: Add 'stop' argument to i2c readfrom/writeto meths. 2016-11-23 17:05:38 +11:00
Damien George
0bc99b4836 extmod/machine_i2c: Make i2c.write[to] methods return num of ACKs recvd. 2016-11-23 17:05:38 +11:00
Damien George
07e83573c8 extmod/machine_i2c: Add 'nack' argument to i2c.readinto. 2016-11-23 17:05:38 +11:00
Damien George
ced240e72a extmod/machine_i2c: Make C-level functions return -errno on I2C error. 2016-11-23 17:05:38 +11:00
Damien George
946f8dd46f extmod/machine_i2c: Remove unneeded i2c_write_mem/i2c_read_mem funcs. 2016-11-23 17:05:38 +11:00
Damien George
96c3911a0a extmod/machine_i2c: Rewrite mem xfer funcs in terms of C-level protocol. 2016-11-23 17:05:37 +11:00
Damien George
c81247f1ab extmod/machine_i2c: Rewrite i2c.scan in terms of C-level protocol. 2016-11-23 17:05:37 +11:00
Damien George
bc4ea69795 extmod/machine_i2c: Add argument to C funcs to control stop generation. 2016-11-23 17:05:37 +11:00
Damien George
b983cfaf41 extmod/machine_i2c: Add a C-level I2C-protocol, refactoring soft I2C. 2016-11-23 17:05:37 +11:00
Damien George
0d56c65d3e extmod/moduselect: Fix comment describing endif. 2016-11-21 15:47:48 +11:00
Paul Sokolovsky
5362bcc487 extmod/machine_mem: Typo fix in comment. 2016-11-21 01:09:17 +03:00
Paul Sokolovsky
8f5bc3ffc0 stmhal/moduselect: Move to extmod/ for reuse by other ports. 2016-11-21 00:05:56 +03:00
Radomir Dopieralski
e81a5353cb extmod/machine_i2c: Release SDA on bus error 2016-11-17 12:43:13 +11:00
Radomir Dopieralski
9a82b67f39 extmod/machine_i2c: Raise an error when clock stretching times out 2016-11-17 12:43:13 +11:00
Radomir Dopieralski
702928915c extmod/machine_i2c: Make the clock stretching timeout configurable 2016-11-17 12:43:12 +11:00
Damien George
e5ef15a9d7 py/lexer: Provide generic mp_lexer_new_from_file based on mp_reader.
If a port defines MICROPY_READER_POSIX or MICROPY_READER_FATFS then
lexer.c now provides an implementation of mp_lexer_new_from_file using
the mp_reader_new_file function.
2016-11-16 18:13:51 +11:00
Damien George
6b239c271c py: Factor out persistent-code reader into separate files.
Implementations of persistent-code reader are provided for POSIX systems
and systems using FatFS.  Macros to use these are MICROPY_READER_POSIX and
MICROPY_READER_FATFS respectively.  If an alternative implementation is
needed then a port can define the function mp_reader_new_file.
2016-11-16 18:13:50 +11:00
Paul Sokolovsky
59a1201da9 all: Remove readall() method, which is equivalent to read() w/o args.
Its addition was due to an early exploration on how to add CPython-like
stream interface. It's clear that it's not needed and just takes up
bytes in all ports.
2016-11-14 00:24:22 +03:00
Paul Sokolovsky
0cbc07227c extmod/moduheapq: Adhoc changes to support ordering by utime.ticks_ms().
As required for further elaboration of uasyncio, like supporting baremetal
systems with wraparound timesources. This is not intended to be public
interface, and likely will be further refactored in the future.
2016-11-12 02:33:17 +03:00
Paul Sokolovsky
9b345a9e48 extmod/utime_mphal: ticks_diff/ticks_add: Don't hardcode 32-bit types.
Use normal mp_int_t/mp_uint_t types, algorithms (hm, formulas) can work
with any type width.
2016-11-03 23:54:16 +03:00
Paul Sokolovsky
10bde6933e extmod/utime_mphal: ticks_diff(): Optimize to avoid if conditions. 2016-11-02 02:50:48 +03:00
Paul Sokolovsky
e429daa572 extmod/utime_mphal: Fix implementation of new semantics of ticks_diff().
Now the function properly uses ring arithmetic to return signed value
in range (inclusive):
[-MICROPY_PY_UTIME_TICKS_PERIOD/2, MICROPY_PY_UTIME_TICKS_PERIOD/2-1].

That means that function can properly process 2 time values away from
each other within MICROPY_PY_UTIME_TICKS_PERIOD/2 ticks, but away in
both directions. For example, if tick value 'a' predates tick value 'b',
ticks_diff(a, b) will return negative value, and positive value otherwise.
But at positive value of MICROPY_PY_UTIME_TICKS_PERIOD/2-1, the result
of the function will wrap around to negative -MICROPY_PY_UTIME_TICKS_PERIOD/2,
in other words, if a follows b in more than MICROPY_PY_UTIME_TICKS_PERIOD/2 - 1
ticks, the function will "consider" a to actually predate b.
2016-10-30 03:07:22 +03:00
Paul Sokolovsky
76146b3d9a extmod/utime_mphal: Allow ticks functions period be configurable by a port.
Using MICROPY_PY_UTIME_TICKS_PERIOD config var.
2016-10-30 03:02:07 +03:00
Paul Sokolovsky
d86cac4b82 extmod/utime_mphal: Implement ticks_add(), add to all maintained ports. 2016-10-29 17:30:05 +03:00
Paul Sokolovsky
6a87084019 extmod/utime_mphal: Add MP_THREAD_GIL_EXIT/ENTER warppers for sleep functions.
Ported from unix port.
2016-10-29 13:42:36 +03:00
Paul Sokolovsky
6ed5583f8c extmod/utime_mphal: ticks_diff(): switch arg order, return signed value.
Based on the earlier discussed RFC. Practice showed that the most natural
order for arguments corresponds to mathematical subtraction:

ticks_diff(x, y) <=> x - y

Also, practice showed that in real life, it's hard to order events by time
of occurance a priori, events tend to miss deadlines, etc. and the expected
order breaks. And then there's a need to detect such cases. And ticks_diff
can be used exactly for this purpose, if it returns a signed, instead of
unsigned, value. E.g. if x is scheduled time for event, and y is the current
time, then if ticks_diff(x, y) < 0 then event has missed a deadline (and e.g.
needs to executed ASAP or skipped). Returning in this case a large unsigned
number (like ticks_diff behaved previously) doesn't make sense, and such
"large unsigned number" can't be reliably detected per our definition of
ticks_* function (we don't expose to user level maximum value, it can be
anything, relatively small or relatively large).
2016-10-29 05:02:24 +03:00
Paul Sokolovsky
f00ecdb54d extmod/moduos_dupterm: Renamed to uos_dupterm.
As part of file naming clean up (moduos_dupterm doesn't implement a
full module, so should skip "mod" prefix, similar to other files in
extmod/).
2016-10-26 02:08:37 +03:00
Damien George
5694201930 extmod/vfs_fat_file: Make file.close() a no-op if file already closed.
As per CPython semantics.  In particular, file.__del__() should not raise
an exception if the file is already closed.
2016-10-24 12:59:20 +11:00
Damien George
4ebdb1f2b2 py: Be more specific with MP_DECLARE_CONST_FUN_OBJ macros.
In order to have more fine-grained control over how builtin functions are
constructed, the MP_DECLARE_CONST_FUN_OBJ macros are made more specific,
with suffix of _0, _1, _2, _3, _VAR, _VAR_BETEEN or _KW.  These names now
match the MP_DEFINE_CONST_FUN_OBJ macros.
2016-10-21 16:26:01 +11:00
Alex March
84679e0c06 extmod/vfs_fat_file: Check fatfs f_sync() and f_close() returns for errors. 2016-10-19 15:57:07 +11:00
Paul Sokolovsky
06234a6115 extmod/modussl_mbedtls: Add dummy setblocking() method.
Accepts only value of True.
2016-10-15 23:46:13 +03:00
Paul Sokolovsky
36f97f19b4 extmod/utime_mphal: sleep_us/ms(): Don't wait on negative argument. 2016-10-14 22:19:45 +03:00
Paul Sokolovsky
a97284423e extmod/utime_mphal: Factor out implementations in terms of mp_hal_* for reuse.
As long as a port implement mp_hal_sleep_ms(), mp_hal_ticks_ms(), etc.
functions, it can just use standard implementations of utime.sleel_ms(),
utime.ticks_ms(), etc. Python-level functions.
2016-10-14 20:14:01 +03:00
Damien George
f2f8ae110b extmod/modujson: Fix nanbox build. 2016-10-13 12:09:18 +11:00
Damien George
e93c1ca5da extmod/modujson: Implement ujson.load() to load JSON from a stream.
This refactors ujson.loads(s) to behave as ujson.load(StringIO(s)).

Increase in code size is: 366 bytes for unix x86-64, 180 bytes for
stmhal, 84 bytes for esp8266.
2016-10-13 11:46:14 +11:00
Alex March
d02f3a57f4 extmod/vfs_fat: Add file and directory checks for remove and rmdir. 2016-10-11 16:03:52 +11:00
Radomir Dopieralski
eaef6b5324 extmod/machine_i2c: Use writes not reads in i2c.scan().
As per discussion in #2449, using write requests instead of read requests
for I2C.scan() seems to support a larger number of devices, especially
ones that are write-only.  Even a read-only I2C device has to implement
writes in order to be able to receive the address of the register to read.
2016-10-11 15:30:46 +11:00
Paul Sokolovsky
39968aaaff extmod/uzlib: Update to upstream v2.1.
Adds check that LZ offsets fall into the sliding dictionary used. This
catches a case when uzlib.DecompIO with a smaller dictionary is used
to decompress data which was compressed with a larger dictionary.
Previously, this would lead to producing invalid data or crash, now
an exception will be thrown.
2016-10-11 07:13:23 +03:00
Damien George
dc43508cc2 extmod/vfs_fat_file: Use MP_Exxx errno constants. 2016-10-07 14:14:41 +11:00
Damien George
75af908c0e extmod: Use mp_raise_OSError helper function. 2016-10-07 13:52:14 +11:00
Damien George
06d0083468 extmod/modlwip: Use mp_raise_OSError helper function.
Reduces esp8266 code size by about 230 bytes.
2016-10-07 13:47:57 +11:00
Damien George
620c4c32bf extmod/vfs_fat: Use mp_raise_OSError helper function. 2016-10-07 13:44:55 +11:00
Damien George
b0eb0d6153 extmod/machine_spi: Add optional support for fast software SPI.
If a port defines MICROPY_PY_MACHINE_SPI_MIN_DELAY then it can use a
faster software SPI loop that does not make calls to the delay_us
function.
2016-10-04 13:46:40 +11:00
Damien George
b932b2dd1f extmod/machine_spi: Use delay_half, not baudrate, for internal timing.
The delay_half parameter must be specified by the port to set up the
timing of the software SPI.  This allows the port to adjust the timing
value to better suit its timing characteristics, as well as provide a
more accurate printing of the baudrate.
2016-10-04 13:43:02 +11:00
Damien George
d434ce3fca extmod/machine_spi: Factor out software SPI code from esp8266 to extmod. 2016-10-03 16:43:44 +11:00
Damien George
5bb28c7f10 extmod/machine_spi: Simplify SPI xfer function to only take one buf len.
There is no need to take src_len and dest_len arguments.  The case of
reading-only with a single output byte (originally src_len=1, dest_len>1)
is now handled by using the output buffer as the input buffer, and using
memset to fill the output byte into this buffer.  This simplifies the
implementations of the spi_transfer protocol function.
2016-10-03 12:39:31 +11:00
Radomir Dopieralski
219245e10f extmod/machine_i2c: Add support for the addrsize parameter in mem xfers.
The memory read/write I2C functions now take an optional keyword-only
parameter that specifies the number of bits in the memory address.
Only mem-addrs that are a multiple of 8-bits are supported (otherwise
the behaviour is undefined).

Due to the integer type used for the address, for values larger than 32
bits, only 32 bits of address will be sent, and the rest will be padded
with 0s. Right now no exception is raised when that happens. For values
smaller than 8, no address is sent. Also no exception then.

Tested with a VL6180 sensor, which has 16-bit register addresses.

Due to code refactoring, this patch reduces stmhal and esp8266 builds
by about 50 bytes.
2016-09-28 14:45:29 +10:00
Alex March
dcf14c1b18 extmod/vfs_fat: Add fat_vfs_statvfs(), reused from stmhal. 2016-09-27 13:48:45 +10:00
Paul Sokolovsky
67d52d8cb9 extmod/uzlib/: Update uzlib to v2.0.3.
Fixes for more pedantic warnings.
2016-09-24 16:07:18 +03:00
Paul Sokolovsky
7b901d6fb7 extmod/moduzlib: DecompIO: Add support for gzip-formatted streams.
This uses extension introduced in CPython 3.5: if wbits (dictionary size
code) has value 16 + 8..15, it means that gzip-formatted stream expected.
2016-09-24 15:30:11 +03:00
Paul Sokolovsky
d8a4d9d67c extmod/uzlib: Add tinfgzip.c (gzip header parsing) from upstream. 2016-09-24 15:28:51 +03:00
Paul Sokolovsky
46ab042230 extmod/modussl_mbedtls: Add server_hostname param for wrap_socket().
In CPython, module-level .wrap_socket() function actually doesn't accept
(or document) this param, only SSLContext.wrap_socket() has.
2016-09-23 01:44:23 +03:00
Radomir Dopieralski
ec078af985 extmod/machine_i2c: Add clock stretching support.
When the clock is too fast for the i2c slave, it can temporarily hold
down the scl line to signal to the master that it needs to wait. The
master should check the scl line when it is releasing it after
transmitting data, and wait for it to be released.

This change has been tested with a logic analyzer and an i2c slace
implemented on an atmega328p using its twi peripheral, clocked at 8Mhz.
Without the change, the i2c communication works up to aboy 150kHz
frequency, and above that results in the slave stuck in an unresponsive
state. With this change, communication has been tested to work up to
400kHz.
2016-09-22 14:10:02 +10:00
Paul Sokolovsky
080e4d44f3 extmod/modussl_mbedtls: Use 2-component include paths.
This is required to use mbedTLS versions from various sources, e.g.
mainline vs embedded into Zephyr RTOS.
2016-09-22 01:30:48 +03:00
Paul Sokolovsky
5f0ecb72c2 extmod/modussl_mbedtls: Implement key= and cert= args to wrap_socket().
Unlike standard keyfile= and certfile=, these accept byte buffer objects
(to not depend on FS implementation).
2016-09-22 00:17:44 +03:00
Pavol Rusnak
7f5a541b84 extmod/modubinascii: Fix crc32() function on 32-bit platforms. 2016-09-21 21:40:18 +03:00
Stefan Agner
b84e1231c9 extmod/uctypes: Allow full 32-bit address range.
Use mp_obj_int_get_truncated to allow the full 32-bit address range
as first parameter.
2016-09-21 21:37:08 +03:00
Paul Sokolovsky
9ea2882317 extmod/modussl_mbedtls: Initial implementation of mbedTLS ussl module. 2016-09-21 21:25:33 +03:00
Damien George
93c4a6a3f7 all: Remove 'name' member from mp_obj_module_t struct.
One can instead lookup __name__ in the modules dict to get the value.
2016-09-22 00:23:16 +10:00
Radomir Dopieralski
778729c597 extmod/framebuf: Add the xstep!=0 case to scroll() method.
Adds horizontal scrolling. Right now, I'm just leaving the margins
created by the scrolling as they were -- so they will repeat the
edge of the framebuf. This is fast, and the user can always fill
the margins themselves.
2016-09-05 12:06:56 +10:00
Paul Sokolovsky
1bc5cb4312 extmod/moduzlib: Support wbits arg to DecompIO. 2016-09-04 14:44:12 +03:00
Damien George
47899a1ab8 extmod/modframebuf: Include font from stmhal directory explicitly.
So that users of framebuf don't need to have stmhal directory in their
path.  (Eventually the font can be moved elsewhere.)
2016-09-04 16:39:28 +10:00
Paul Sokolovsky
f7c4611523 extmod/moduzlib: Use mperrno.h for error constants. 2016-09-03 00:34:57 +03:00
Paul Sokolovsky
a6864a13c7 extmod/moduzlib: Implement zlib stream decompressor class, DecompIO. 2016-09-03 00:19:35 +03:00
Radomir Dopieralski
41ec22632d extmod/modframebuf: Fix fill and scroll when height not divisible by 8.
There was a bug in `framebuf1_fill` function, that makes it leave a few
lines unfilled at the bottom if the height is not divisible by 8.

A similar bug is fixed in the scroll method.
2016-09-02 23:58:34 +10:00
Damien George
0823c1baf8 extmod: Add machine_spi with generic SPI C-protocol and helper methods.
The idea is that all ports can use these helper methods and only need to
provide initialisation of the SPI bus, as well as a single transfer
function.  The coding pattern follows the stream protocol and helper
methods.
2016-09-01 15:07:20 +10:00
Damien George
531217a06b extmod/modframebuf: Fix pixel accessor to return a 1-bit result. 2016-08-27 18:31:58 +10:00
Radomir Dopieralski
d29ca28288 esp8266/modous: Add os.umount method to unmount a filesystem.
This is an object-oriented approach, where uos is only a proxy for the
methods on the vfs object.  Some internals had to be exposed (the STATIC
keyword removed) for this to work.

Fixes #2338.
2016-08-26 12:45:21 +10:00
Paul Sokolovsky
c428367543 extmod/modubinascii: Make crc32() support configurable.
Disable by default, enable in unix port.
2016-08-24 18:28:43 +03:00
Pavol Rusnak
39799f7564
extmod/modubinascii: implement binascii.crc32 2016-08-24 10:42:46 +02:00
Krzysztof Blazewicz
5a5449d4eb extmod/modbtree: do CHECK_ERROR after __bt_seq()
In `btree_seq()`, when `__bt_seq()` gets called with invalid
`flags` argument it will return `RET_ERROR` and it won't
initialize `val`. If field `data` of uninitialized `val`
is passed to `mp_obj_new_bytes()` it causes a segfault.
2016-08-24 01:31:16 +03:00
Paul Sokolovsky
49dd532180 extmod/uzlib/: Update uzlib to v2.0.2.
Consistently use stdint types. Fixes stmhal build.
2016-08-17 14:47:30 +03:00
Paul Sokolovsky
244332df9f extmod/uzlib/: Update uzlib to v2.0.1.
Fixes for pedantic compiler warnings.
2016-08-17 06:24:12 +03:00
Paul Sokolovsky
ed4ce196ed extmod/moduzlib: Refactor to new stream-compatible uzlib 2.0 API. 2016-08-17 06:06:34 +03:00
Paul Sokolovsky
ff1c2b03a9 extmod/uzlib/: Update uzlib to v2.0.
New API supporting stream decompression.
2016-08-17 06:06:33 +03:00
Paul Sokolovsky
d2cc7c720b extmod/modwebrepl: set_password(): Raise exception for too long password. 2016-08-16 17:02:04 +03:00
Paul Sokolovsky
e15fb33e10 extmod/modwebrepl: Add GET_VER operation to query MicroPython version. 2016-08-07 00:01:25 +03:00
Paul Sokolovsky
cbef0dba2e extmod/modwebsocket: Use mp_rom_map_elem_t and friends. 2016-08-06 16:18:03 +03:00
Paul Sokolovsky
e0d49b7e1b extmod/modwebsocket: Make compatible with non-default object models. 2016-08-06 15:53:16 +03:00
Paul Sokolovsky
a931c4eeec extmod/modwebsocket: Add readline method.
This goes bit against websocket nature (message-based communication),
as it ignores boundaries bertween messages, but may be very practical
to do simple things with websockets.
2016-08-06 15:13:26 +03:00
Paul Sokolovsky
d79342d33e extmod/modbtree: open(): Add option kwargs.
Namely: flags, cachesize, pagesize, minkeypage.
2016-08-06 00:10:22 +03:00
Paul Sokolovsky
ed500e4987 extmod/modwebrepl: Make GET_FILE operation non-blocking.
In the sense that while GET_FILE transfers its data, REPL still works.
This is done by requiring client to send 1-byte block before WebREPL
server transfers next block of data.
2016-08-05 22:57:50 +03:00
Paul Sokolovsky
c16612ee87 extmod/modwebrepl: Factor out "GET" iteration to write_file_chunk(). 2016-08-05 22:53:10 +03:00
Paul Sokolovsky
3eb532e974 extmod/modbtree: Implement __contains__ operation. 2016-08-02 00:24:59 +03:00
Paul Sokolovsky
99061d1dcb extmod/modbtree: Switch to accepting stream object instead of filename.
Requires "embedded" BerkeleyDB BTree implementation.
2016-07-31 00:40:35 +03:00
Paul Sokolovsky
4f1b0292db py/stream: Add adapter methods with POSIX-compatible signatures.
Previoussly such read() and write() methods were used by modussl_axtls,
move to py/stream for reuse.
2016-07-30 00:25:06 +03:00
Paul Sokolovsky
25df419c67 extmod/modbtree: Check __bt_open() return value for error. 2016-07-24 00:29:32 +03:00
Paul Sokolovsky
2dd21d9a68 extmod/modwebrepl: Use mp_stream_close() method. 2016-07-23 00:52:35 +03:00
Paul Sokolovsky
a53e0e59f3 extmod/modussl_axtls: Use mp_stream_close() method. 2016-07-23 00:38:56 +03:00
Paul Sokolovsky
0a6f599cf2 extmod/vfs_fat: Implement rmdir() method.
Shares the code with remove() method due to the same underlying f_unlink()
FatFs operation.
2016-07-16 03:46:42 +03:00
Paul Sokolovsky
780114e398 extmod/modussl_axtls: Add dummy setblocking() method.
Accepts only value of True.
2016-07-15 01:05:06 +03:00