Commit Graph

353 Commits

Author SHA1 Message Date
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
Paul Sokolovsky 20283aec10 extmod/modussl_axtls: Further changes to allow alternative SSL modules.
Make variable MICROPY_SSL_AXTLS=1 should be defined to activate modussl_axtls
and link with -laxtls.
2016-07-13 01:49:38 +03:00
Paul Sokolovsky e32d1e17bb extmod/modussl: Rename to modussl_axtls.c, to allow impl using other SSL libs. 2016-07-13 01:35:59 +03:00
Paul Sokolovsky a4c8a1ffe8 extmod/moduos_dupterm: Reuse dupterm_arr_obj for write operations.
Instead of allocating new array object header again and again, causing
memory fragmentation.
2016-07-07 02:16:24 +03:00
Paul Sokolovsky 426112ce88 extmod/moduos_dupterm: Reserve buffer bytearray object for dupterm.
Allocating it for each read/write operation is a memory fragmentation
hazard.
2016-07-04 13:32:30 +03:00
Paul Sokolovsky 417dc0c05d extmod/modbtree: Fixes for nanbox build. 2016-07-02 15:58:13 +03:00
Paul Sokolovsky b09cd0e1ec extmod/modbtree: Fix unused argument warning. 2016-07-02 15:21:54 +03:00
Paul Sokolovsky c880f91ac0 extmod/modwebrepl: Add readinto() method. 2016-07-02 14:05:37 +03:00
Paul Sokolovsky 03b0279c6d extmod/modwebsocket: Add readinto() method. 2016-07-02 14:03:49 +03:00
Paul Sokolovsky 2f7ebf16de extmod/modbtree: Cleverly implement "for key in btree:" syntax.
I.e. make it work like btree.keys(), while still not using a separate
iterator type.
2016-06-23 20:08:37 +03:00
Paul Sokolovsky 6b088a671a extmod/modbtree: Implement keys(), values(), items() iterators.
Each takes optional args of starting key, ending key, and flags (ending
key inclusive, reverse order).
2016-06-20 15:50:31 +03:00
Paul Sokolovsky 5071ceea07 extmod/modlwip: Store a chain of incoming pbufs, instead of only one.
Storing a chain of pbuf was an original design of @pfalcon's lwIP socket
module. The problem with storing just one, like modlwip does is that
"peer closed connection" notification is completely asynchronous and out of
band. So, there may be following sequence of actions:

1. pbuf #1 arrives, and stored in a socket.
2. pbuf #2 arrives, and rejected, which causes lwIP to put it into a
queue to re-deliver later.
3. "Peer closed connection" is signaled, and socket is set at such status.
4. pbuf #1 is processed.
5. There's no stored pbufs in teh socket, and socket status is "peer closed
connection", so EOF is returned to a client.
6. pbuf #2 gets redelivered.

Apparently, there's no easy workaround for this, except to queue all
incoming pbufs in a socket. This may lead to increased memory pressure,
as number of pending packets would be regulated only by TCP/IP flow
control, whereas with previous setup lwIP had a global overlook of number
packets waiting for redelivery and could regulate them centrally.
2016-06-19 19:15:20 +03:00
Paul Sokolovsky efee577318 extmod/machine_pinbase: Fix nanbox build.
MP_ROM_PTR() is only for data structures initialization, code should use
MP_OBJ_FROM_PTR().
2016-06-19 00:26:57 +03:00
Paul Sokolovsky 3fecbb2462 extmod/machine_pinbase: Implementation of PinBase class.
Allows to translate C-level pin API to Python-level pin API. In other
words, allows to implement a pin class and Python which will be usable
for efficient C-coded algorithms, like bitbanging SPI/I2C, time_pulse,
etc.
2016-06-18 23:40:28 +03:00
Paul Sokolovsky 07209f8592 all: Rename mp_obj_type_t::stream_p to protocol.
It's now used for more than just stream protocol (e.g. pin protocol), so
don't use false names.
2016-06-18 18:44:57 +03:00
Paul Sokolovsky 080137961d extmod/modbtree: open(): Support "in-memory" database with filename=None.
It's not really in-memory though, just uses anonymous temporary file on
disk.
2016-06-18 01:31:57 +03:00
Paul Sokolovsky e9739e3315 extmod/modbtree: __getitem__() should raise KeyError for non-existing key. 2016-06-18 01:30:49 +03:00
Paul Sokolovsky e6e7e0e9c5 extmod/modbtree: items(): Implement DESC flag. 2016-06-18 00:47:26 +03:00
Paul Sokolovsky 332545baa3 extmod/modbtree: items(): Implement "end key inclusive" flag. 2016-06-17 00:08:55 +03:00
Robert HH 23067a1422 esp8266: Use RTC to set date & time stamps for files.
The time stamp is taken from the RTC for all newly generated
or changed files. RTC must be maintained separately.
The dummy time stamp of Jan 1, 2000 is set in vfs.stat() for the
root directory, avoiding invalid time values.
2016-06-16 19:31:58 +03:00
Paul Sokolovsky d0416ff915 extmod/modbtree: Actually implement end key support for .items(). 2016-06-16 18:16:33 +03:00
Paul Sokolovsky 1babeb47a4 extmod/modbtree: Implement .items() iterator. 2016-06-16 17:31:24 +03:00
Paul Sokolovsky 422396cece extmod/modbtree: Handle default value and error check. 2016-06-15 04:18:44 +03:00
Paul Sokolovsky 8072162170 extmod/modbtree: Initial implementation of "btree" module based on BerkeleyDB.
This implements basic wrapping of native get/put/seq API, and then dictionary
access protocol. Native API is intended to be superceded going forward.
2016-06-14 21:51:59 +03:00
Damien George 33168081f4 extmod/machine: Add MICROPY_PY_MACHINE_PULSE config for time_pulse_us.
Since not all ports that enable the machine module have the pin HAL
functions.
2016-05-31 14:25:19 +01:00
Damien George 4940bee62a extmod: Add machine time_pulse_us function (at C and Python level).
The C implementation is taken from the DHT driver.
2016-05-31 13:58:48 +01:00
Paul Sokolovsky 298c2ae2c7 extmod/vfs_fat: Mark anused "self" arg for fat_vfs_stat(). 2016-05-31 15:42:08 +03:00
Robert HH ee009d713a extmod/vfs_fat.c: Add vfs.stat().
The call to stat() returns a 10 element tuple consistent to the os.stat()
call. At the moment, the only relevant information returned are file
type and file size.
2016-05-31 13:03:12 +03:00
Paul Sokolovsky 480159ca8b extmod/vfs_fat: getcwd(): Use mp_obj_new_exception_arg1().
Copy-paste issue, with the original mistake in stmhal.
2016-05-29 20:04:53 +03:00
Paul Sokolovsky ee5e3f6527 extmod/vfs_fat: chdir(), getcwd() methods should accept VFS object (self). 2016-05-29 18:52:41 +03:00
Paul Sokolovsky cac6c9704e extmod/vfs_fat: Add getcwd() method.
Ported from stmhal.
2016-05-29 18:23:59 +03:00
Paul Sokolovsky f12146cbf6 extmod/vfs_fat: Add chdir() method.
Ported from stmhal.
2016-05-29 18:17:00 +03:00
Robert HH 7c004e794c extmod/vfs_fat*: Replace text error messages by POSIX error numbers.
These changes are in line with similar changes in other modules, and
with standard Python interface.
2016-05-27 23:57:01 +03:00
Paul Sokolovsky 751e3b7a82 extmod/virtpin: Initial implementation of open-ended C-level Pin interface.
Using usual method of virtual method tables. Single virtual method,
ioctl, is defined currently for all operations. This universal and
extensible vtable-based method is also defined as a default MPHAL
GPIO implementation, but a specific port may override it with its
own implementation (e.g. close-ended, but very efficient, e.g. avoiding
virtual method dispatch).
2016-05-27 01:08:43 +03:00
Damien George 4b37e775ea extmod/machine_i2c: Redo mp_hal_pin macros to use open_drain and od_low.
mp_hal_pin_config_od is renamed mp_hal_pin_open_drain, and mp_hal_pin_low
is mp_hal_pin_od_low.
2016-05-26 17:06:40 +01:00
Paul Sokolovsky 2ea019f3d3 extmod/modussl: Coverage build fixes. 2016-05-26 02:11:24 +03:00
Paul Sokolovsky 9d04fec5d9 extmod/modussl: Make more compatible with non-default obj representations.
Still not compatible with nanboxing.
2016-05-26 02:10:35 +03:00
Paul Sokolovsky 0ab372585f extmod/moduos_dupterm: Dumpterm subsystem is responsible for closing stream.
Make dupterm subsystem close a term stream object when EOF or error occurs.
There's no other party than dupterm itself in a better position to do this,
and this is required to properly reclaim stream resources, especially if
multiple dupterm sessions may be established (e.g. as networking
connections).
2016-05-20 22:20:37 +03:00
Paul Sokolovsky 3a29db8e58 extmod/modwebrepl: Add close() method. 2016-05-20 21:32:41 +03:00
Paul Sokolovsky ccf4e5ab7b extmod/modwebsocket: Add close() method. 2016-05-20 21:18:49 +03:00
Damien George f9dc644017 extmod: When including extmod headers, prefix path with extmod/. 2016-05-20 12:46:20 +01:00
Paul Sokolovsky 7f7c84b10a py/stream: Support both "exact size" and "one underlying call" operations.
Both read and write operations support variants where either a) a single
call is made to the undelying stream implementation and returned buffer
length may be less than requested, or b) calls are repeated until requested
amount of data is collected, shorter amount is returned only in case of
EOF or error.

These operations are available from the level of C support functions to be
used by other C modules to implementations of Python methods to be used in
user-facing objects.

The rationale of these changes is to allow to write concise and robust
code to work with *blocking* streams of types prone to short reads, like
serial interfaces and sockets. Particular object types may select "exact"
vs "once" types of methods depending on their needs. E.g., for sockets,
revc() and send() methods continue to be "once", while read() and write()
thus converted to "exactly" versions.

These changes don't affect non-blocking handling, e.g. trying "exact"
method on the non-blocking socket will return as much data as available
without blocking. No data available is continued to be signaled as None
return value to read() and write().

From the point of view of CPython compatibility, this model is a cross
between its io.RawIOBase and io.BufferedIOBase abstract classes. For
blocking streams, it works as io.BufferedIOBase model (guaranteeing
lack of short reads/writes), while for non-blocking - as io.RawIOBase,
returning None in case of lack of data (instead of raising expensive
exception, as required by io.BufferedIOBase). Such a cross-behavior
should be optimal for MicroPython needs.
2016-05-18 02:41:45 +03:00
Paul Sokolovsky afce978aca extmod/modlwip: Rework how Python accept callback is called.
Calling it from lwIP accept callback will lead incorrect functioning
and/or packet leaks if Python callback has any networking calls, due
to lwIP non-reentrancy. So, instead schedule "poll" callback to do
that, which will be called by lwIP when it does not perform networking
activities. "Poll" callback is called infrequently though (docs say
every 0.5s by default), so for better performance, lwIP needs to be
patched to call poll callback soon after accept callback, but when
current packet is already processed.
2016-05-15 22:42:12 +03:00
Damien George 0055457b5f extmod/modlwip: Convert errno's to use MP_Exxx symbols. 2016-05-12 12:49:14 +01:00
Paul Sokolovsky cfc94bec9f extmod/modlwip: Implement sendall() method for TCP sockets. 2016-05-03 10:43:11 +03:00
Paul Sokolovsky b8468d12a1 extmod/modwebrepl: Get rid of using strncpy(). 2016-05-02 20:52:34 +03:00
Paul Sokolovsky 859e4e94f3 extmod/modwebrepl: Add support for password.
Request for password then becomes mandatory part of the protocol.
2016-04-30 20:36:32 +03:00
Paul Sokolovsky 18775d3807 extmod/modwebrepl: Set debugging by default to off.
That's production setting. Also, extra UART output may affect behavior of
(subpar) network drivers.
2016-04-29 19:17:37 +03:00
Paul Sokolovsky b0f3ae58e7 extmod/modwebrepl: Add rate-limiting workaround for broken network drivers.
Like ESP8266 has.
2016-04-29 19:14:03 +03:00
Paul Sokolovsky 8811b0af9c extmod/modwebrepl: Use bigger socket receive buffer.
The smaller chunks we send (and receive), the more packets there to
receive, and higher chance to git internal packet buffer overflow in
WiFi driver.
2016-04-29 18:43:19 +03:00
Paul Sokolovsky b3bc2ee1b9 extmod/modwebrepl: More detailed debug output.
So detailed that even commented by default.
2016-04-29 17:37:40 +03:00
Paul Sokolovsky 473b639845 extmod/modwebrepl: GET_FILE: Send length-prefix chunk with one write().
A bit of optimization.
2016-04-29 17:35:21 +03:00
Paul Sokolovsky f41e1f1bb7 extmod/modwebrepl: Keep reading data when there's something to read.
EAGAIN should be returned only if underlying socket returned it. Wrap
existing read function into external loop to process all data available.
2016-04-29 01:05:02 +03:00
Paul Sokolovsky 6514ff6160 extmod/modwebrepl: Initial implementation of "get file" operation. 2016-04-29 01:02:39 +03:00
Paul Sokolovsky 25d0f7d59d extmod/modwebrepl: Module to handle WebREPL protocol.
While just a websocket is enough for handling terminal part of WebREPL,
handling file transfer operations requires demultiplexing and acting
upon, which is encapsulated in _webrepl class provided by this module,
which wraps a websocket object.
2016-04-29 00:52:52 +03:00
Paul Sokolovsky ba61480df5 extmod/modussl: SSL_OK from ssl_read() means "no user data so far".
SSL_OK is numeric 0, and it's *not* an EOF. So, should keep reading.
2016-04-28 17:29:11 +03:00
Paul Sokolovsky 2534bfdb92 extmod/modussl: Support server-side SSL sockets.
wrap_socket(sock, server_side=True)
2016-04-28 17:27:20 +03:00
Paul Sokolovsky d54290f6e2 extmod/modussl: Throw Python exceptions in case of errors. 2016-04-28 00:49:54 +03:00
Paul Sokolovsky 480c212009 extmod/modwebsocket: Handle CLOSE control frame.
This fixes situation when clients hangs waiting for disconnect and does
so only on timeout.
2016-04-27 12:49:30 +03:00
Paul Sokolovsky 1c6d91d968 extmod/modlwip: Add print_pcbs() debug function.
This requires lwIP built with LWIP_DEBUG (or it will be no-op).
2016-04-26 16:30:13 +03:00
Damien George 45ac5a85d5 extmod/modlwip: Workaround esp8266 sendto issue where 1 is returned. 2016-04-26 13:19:08 +01:00
Damien George a63542387d extmod, stmhal: Fix typo of macro that detects if float is enabled. 2016-04-26 12:47:24 +01:00
Paul Sokolovsky 7a012f4793 extmod/modlwip: Protect recv/accept Python callback against exceptions.
Using usual call_function_*_protected() helper, to avoid NLR jump crashes.
2016-04-25 21:27:55 +03:00