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
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.
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.
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.
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.
The -ansi flag is used for C dialect selection and it is equivalent to -std=c90.
Because it goes right before -std=gnu99 it is ignored as for conflicting flags
GCC always uses the last one.
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).
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.
Since we recently replaced the OSError string messages with simple error
codes, having the uerrno module gets back some user friendly error
messages. The total code size (after removing strings, replacing with
uerrno module) is decreased.
ftp.c is the only user of this function so making it static in that file
allows it to be inlined. Also, reusing unichar_toupper means we no longer
depend on the C stdlib for toupper, saving about 300 bytes of code space.
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.
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.