Commit Graph

295 Commits

Author SHA1 Message Date
Alexander Steffen 299bc62586 all: Unify header guard usage.
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.

This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.

The rules are as follows.

Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _

In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.

py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
2017-07-18 11:57:39 +10:00
Damien George 4d55d8805a cc3200/modusocket: Fix connect() when in non-blocking or timeout mode.
Non-blocking connect on the CC3100 has non-POSIX behaviour and needs to be
modified to match standard semantics.
2017-07-11 16:16:14 +10:00
Damien George e6782428be cc3200: Initialise variable to zero to prevent compiler warnings. 2017-06-20 17:14:48 +10:00
Damien George 1686346d53 cc3200: Make non-zero socket timeout work with connect/accept/send.
The CC3100 only allows to set a timeout for receiving data, not for accept,
connect or send.  But it can set non-blocking for all these operations and
this patch uses that feature to implement socket timeout in terms of non-
blocking behaviour combined with a loop.
2017-06-20 16:52:39 +10:00
Damien George 696fcde800 cc3200/modusocket: Simplify socket.makefile() function.
Following how extmod/modlwip.c does it.
2017-06-14 17:40:02 +10:00
Paul Sokolovsky 19e065294d cc3200/mods/pybpin: Remove toggle() method.
It's not part of MicroPython HW API and can be easily implemented on Python
level in case of need.

Saved 56 bytes of binary.
2017-05-21 15:39:27 +03:00
Damien George f1609bc843 ports: Add ilistdir in uos module. 2017-05-10 12:13:53 +10:00
Damien George 9d7c53734c cc3200/mods/pybi2c: Make readfnom_mem_into/writeto_mem return None.
This aligns the I2C class to match the standard machine.I2C API.

Note that this is a (small) breaking change to the existing cc3200 API.
The original API just returned the size of the input buffer so there's no
information lost by this change.  To update scripts users should just use
the size of the buffer passed to these functions to get the number of bytes
that are read/written.
2017-04-18 15:31:08 +10:00
Damien George 8f205c2c9b cc3200/mods/pybi2c: Make machine.I2C constructor/init conform to HW API.
This is a user-facing change to the cc3200's API, to make it conform to the
new machine hardware API.  The changes are:

- change I2C constructor to: I2C(id=0, *, freq=100000, scl=None, sda=None)
- change I2C init to: init(*, freq, scl, sda)
- removal of machine.I2C.MASTER constant
- I2C str/repr no longer prints I2C.MASTER

To update existing code it should be enough to just remove the I2C.MASTER
constant from contructor/init for I2C.
2017-04-18 13:16:05 +10:00
Paul Sokolovsky e322b2afbf cc3200/pybuart: Make parity specifications consistent with HW API.
parity=0 means even parity, parity=1 - odd.
2017-04-09 00:19:02 +03:00
Paul Sokolovsky 9a38b7afe0 cc3200/modmachine: Return frequency value directly, like other ports. 2017-04-05 11:58:17 +03:00
Damien George b6c7e4b143 all: Use full path name when including mp-readline/timeutils/netutils.
This follows the pattern of how all other headers are now included, and
makes it explicit where the header file comes from.  This patch also
removes -I options from Makefile's that specify the mp-readline/timeutils/
netutils directories, which are no longer needed.
2017-03-31 22:29:39 +11:00
Damien George 6bfb344a80 cc3200/mods/pybi2c: Raise OSError if readfrom_mem fails to write addr. 2017-03-29 16:09:46 +11:00
Damien George 3a77342719 cc3200: Update for changes to mp_obj_str_get_data. 2017-03-29 12:56:45 +11:00
Damien George 87f068d7d9 cc3200: Update to use size_t for tuple/list accessors. 2017-03-29 12:56:17 +11:00
Damien George 1110c8873c cc3200/mods/modutime: Use generic sleep_ms and sleep_us implementations. 2017-03-22 12:57:51 +11:00
Paul Sokolovsky f5ee4d95a9 cc3200/moduos: Remove uos.sep, as it's strictly optional.
In MicroPython, the path separator is guaranteed to be "/", extra unneeded
things take precious code space (in the port which doesn't have basic things
like floating-port support).
2017-02-23 22:10:58 -08:00
Damien George 047af9b10b cc3200: Remove socket.timeout class, use OSError(ETIMEDOUT) instead.
socket.timeout is a subclass of OSError, and using the latter is more
efficient than having a dedicated class.  The argument of OSError is
ETIMEDOUT so the error can be distinguished from other kinds of
OSErrors.  This follows how the esp8266 port does it.
2017-02-22 15:08:32 +11:00
Damien George d03f089baa cc3200/mods/modusocket: Init vars to 0 to silence compiler warnings.
Some compilers can't analyse the code to determine that these variables
are always set before being used.
2017-02-22 14:58:37 +11:00
Damien George 22a6344ebe cc3200: When raising OSError's use MP_Exxx as arg instead of a string. 2017-02-22 12:58:11 +11:00
Damien George 8bb8e97dfe cc3200: Convert to using uPy internal errno numbers. 2017-02-22 12:58:11 +11:00
Damien George 85ab469c64 cc3200: Move wlan socket glue functions from modwlan to modusocket.
It saves about 400 bytes of code space because the functions can now be
inlined.
2017-02-22 11:29:19 +11:00
Damien George 71ae3f389d cc3200: Remove remaining references to std.h. 2017-02-21 18:01:43 +11:00
Damien George 8c5988bf61 cc3200/mods/modwlan: Add int casts to silence compiler warnings. 2017-02-21 17:29:40 +11:00
Damien George 0258f819bd cc3200/mods/modwlan: Allow antenna diversity to be fully compiled out. 2017-02-21 17:29:02 +11:00
Damien George a162832b1a cc3200/mods/modwlan: Make multi-threaded a proper compile-time option. 2017-02-21 17:28:14 +11:00
Damien George 26ddd4b621 cc3200/mods/modwlan: Remove unused header includes; simplify others. 2017-02-21 17:27:17 +11:00
Damien George 1c35270667 cc3200: Remove util/std.h, can just use stdio.h instead. 2017-02-21 17:26:21 +11:00
Damien George d9f7120af1 cc3200: Use simplelink API instead of emulated BSD API.
Most of cc3200 uses explicit simplelink calls anyway, and this means there
are no longer any clashes with macros from the C stdlib.
2017-02-21 17:24:12 +11:00
Damien George ae8d867586 py: Add iter_buf to getiter type method.
Allows to iterate over the following without allocating on the heap:
- tuple
- list
- string, bytes
- bytearray, array
- dict (not dict.keys, dict.values, dict.items)
- set, frozenset

Allows to call the following without heap memory:
- all, any, min, max, sum

TODO: still need to allocate stack memory in bytecode for iter_buf.
2017-02-16 18:38:06 +11:00
Damien George b7d27e31e8 cc3200: Refactor "ticks" functions to use common extmod implementation.
The port now uses the common mp_utime_ticks_{ms,us,cpu,add,diff} functions
from extmod/utime_mphal.c.

The mp_utime_sleep_XXX functions are still cc3200-specific because they
handle the GIL differently to the ones in extmod.

The files misc/mpsystick.[ch] have been removed because they contain 2
unused functions, and the other remaining function is renamed to
mp_hal_ticks_us and moved to hal/cc3200_hal.c.
2017-02-06 11:14:16 +11:00
Damien George b697c89009 extmod: Merge old fsusermount.h header into vfs.h and vfs_fat.h.
vfs.h is for generic VFS declarations, and vfs_fat.h is for VfsFat
specific things.
2017-01-30 12:26:08 +11:00
Damien George 56506fd64a cc3200: Convert to use new VFS sub-system and new ooFatFs library. 2017-01-30 12:26:07 +11:00
Paul Sokolovsky 3a3543251f cc3200/modusocket: Remove deprecated socket.error.
socket.error is deprecated even in upstream:
https://docs.python.org/3/library/socket.html#socket.error,
and never was a part of MicroPython socket API.
2017-01-29 02:47:26 +03:00
Damien George 32a1138b9f extmod: Rename vfs_fat_file.h to vfs_fat.h.
And move declaration of mp_fat_vfs_type to this file.
2017-01-27 15:04:17 +11:00
Paul Sokolovsky 044f96c330 cc3200/modwlan: Add network.WLAN.print_ver() diagnostic function.
Prints NWP/MAC/PHY version, as affected by servicepack installed.
2017-01-07 19:48:12 +03:00
Paul Sokolovsky eac22e29a5 all: Consistently update signatures of .make_new and .call methods.
Otherwise, they serve reoccurring source of copy-paste mistakes and
breaking nanbox build.
2017-01-04 16:10:42 +03: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 3f8bb80eb2 cc3200/mods/pybspi: Remove SPI.MASTER constant, it's no longer needed. 2016-11-15 16:35:54 +11:00
Paul Sokolovsky 7602dc5f32 cc3200/pybspi: Remove static mode=SPI.MASTER parameter for latest HW API.
Per the latest HW API, "SPI" class implements only master side of the
protocol, so mode=SPI.MASTER (which was static for WiPy anyway) is not
required (or allowed). This change is required to correspond to updated
documentation of machine.SPI class which no longer lists "mode".
2016-11-15 16:31:57 +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
Damien George 628799cd36 cc3200/mods/pybspi: Allow "write" arg of read/readinto to be positional.
To conform with Hardware API.
2016-10-18 10:16:46 +11:00
Damien George 50ddaafa6a cc3200: Use mp_raise_XXX helper functions to reduce code size.
Reduces code size by 632 bytes.
2016-10-18 09:53:43 +11:00
daniel a0d97fe408 cc3200: Add ssl_version argument to ssl.wrap_socket().
This resolves issue #2343.
2016-10-01 21:35:09 +02: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
Damien George f3b5480be7 stmhal,cc3200,esp8266: Consistently use PWRON_RESET constant.
machine.POWER_ON is renamed to machine.PWRON_RESET to match other
reset-cause constants that all end in _RESET.  The cc3200 port keeps a
legacy definition of POWER_ON for backwards compatibility.
2016-09-08 12:50:38 +10: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
Damien George 70ff7350e7 stmhal, cc3200: Change i2c.scan() method to scan addresses 0x08-0x77.
A standard I2C address is 7 bits but addresses 0b0000xxx and 0b1111xxx
are reserved.  The scan() method is changed to reflect this, along with
the docs.
2016-05-02 11:15:36 +01:00
Paul Sokolovsky 4e51a3038c cc3200/mods/modwlan: Include stream.h after recent refactor. 2016-04-06 01:18:39 +03:00
danicampora add930c4b5 cc3200: Rename 'server' class to 'Server' for consistency. 2016-02-22 22:54:34 +01:00