Commit Graph

372 Commits

Author SHA1 Message Date
Damien George
374ed317c5 extmod/modframebuf: Add hline, vline, rect and line methods.
These are basic drawing primitives.  They work in a generic way on all
framebuf formats by calling the underlying setpixel or fill_rect C-level
primitives.
2016-12-05 11:52:51 +11:00
Paul Sokolovsky
4463d8a910 extmod/modbtree: Rename "sync" method to "flush" for consistency.
Rename recently introduced "sync" method to "flush" for consistency with
usual files.
2016-12-05 01:50:55 +03:00
w4kpm
ec22d1739d extmod/modbtree: Add method to sync the database.
If you have longish operations on the db (such as logging data) it may
be desirable to periodically sync the database to the disk.  The added
btree.sync() method merely exposes the berkley __bt_sync function to the
user.
2016-12-02 17:30:53 +11:00
w4kpm
bd476acd41 extmod/vfs_fat_file: Allow file obj to respond to ioctl flush request. 2016-12-02 17:26:37 +11:00
Damien George
cb53226b0c extmod/modlwip: Add ioctl method to socket, with poll implementation.
Implementation of polling may need further fine tuning, but basic
functionality works (tested on esp8266).
2016-12-02 16:41:51 +11:00
Damien George
2d329c4a56 extmod/moduselect: Use configurable EVENT_POLL_HOOK instead of WFI.
To make moduselect be usable by any port.
2016-12-02 16:40:39 +11:00
Damien George
ebc8d730f1 extmod/moduselect: Use stream helper function instead of ad-hoc code. 2016-12-02 16:39:50 +11:00
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