Commit Graph

64 Commits

Author SHA1 Message Date
Damien George af64c2ddbd extmod/machine_pwm: Factor out machine.PWM bindings to common code.
This commit refactors machine.PWM and creates extmod/machine_pwm.c.  The
esp8266, esp32 and rp2 ports all use this and provide implementations of
the required PWM functionality.  This helps to reduce code duplication and
keep the same Python API across ports.

This commit does not make any functional changes.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-04 16:31:17 +10:00
Damien George d41f6dde56 extmod/modonewire: Make _onewire module configurable via macro option.
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Damien George afe0634c98 extmod/machine_spi: Make SoftSPI configurable via macro option.
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Damien George 122d901ef1 extmod/machine_i2c: Make SoftI2C configurable via macro option.
The zephyr port doesn't support SoftI2C so it's not enabled, and the legacy
I2C constructor check can be removed.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Jim Mussared 71f4faac27 esp32: Replace esp.neopixel with machine.bitstream.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-19 22:50:32 +10:00
Jim Mussared 5733c49174 stm32,esp32,rp2: Enable MICROPY_PY_FSTRINGS by default.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-14 16:58:40 +10:00
Jim Mussared bfc8e88ce1 esp32/mpconfigport.h: Enable reverse and inplace special methods.
Reverse operations are supported on stm32 and rp2, and esp32 has enough
space to also enable inplace operations, to make it complete.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-07 13:27:09 +10:00
Damien George 6823514845 esp32: Add initial support for ESP32C3 SoCs.
Supported features for this SoC are:
- UART REPL, filesystem
- Pin, ADC, PWM, SoftI2C, SoftSPI, Timer, RTC
- OneWire, DHT, NeoPixel
- RMT
- WiFi, Bluetooth

Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:24 +10:00
Damien George 0fc0ccabec esp32/machine_i2s: Add MICROPY_PY_MACHINE_I2S option, enable by default.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 12:31:13 +10:00
Damien George 1f9243f8d4 esp32/machine_dac: Add MICROPY_PY_MACHINE_DAC option, enable by default.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 12:11:10 +10:00
Damien George e9e9c76ddf all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.
To match mp_sched_exception() and mp_sched_schedule().

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Damien George 7cbf826a95 py/scheduler: Add mp_sched_exception() to schedule a pending exception.
This helper is added to properly set a pending exception, to mirror
mp_sched_schedule(), which schedules a function.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Damien George 66a86a0615 esp32: Add initial support for ESP32S2 SoCs.
Builds against IDF v4.3-beta2.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-15 10:31:06 +10:00
Damien George ab9d47e023 esp32: Enable btree module.
This was disabled with the move to CMake, and this commit reinstates it.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-09 13:33:26 +10:00
Thorsten von Eicken 902da05a18 esp32: Set MICROPY_USE_INTERNAL_ERRNO=0 to use toolchain's errno.h.
The underlying OS (the ESP-IDF) uses it's own internal errno codes and so
it's simpler and cleaner to use those rather than trying to convert
everything to the values defined in py/mperrno.h.
2021-02-15 23:47:02 +11:00
Damien George f12462ddc4 esp32: Remove obsolete IDF v3 code wrapped in MICROPY_ESP_IDF_4.
Signed-off-by: Damien George <damien@micropython.org>
2021-02-15 23:22:05 +11:00
Damien George da2b5fa1c1 esp32/boards: Enable BLE on all boards.
BLE was enabled by default on all boards in the existing make build.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-15 16:40:07 +11:00
Damien George ad4656b861 all: Rename BYTES_PER_WORD to MP_BYTES_PER_OBJ_WORD.
The "word" referred to by BYTES_PER_WORD is actually the size of mp_obj_t
which is not always the same as the size of a pointer on the target
architecture.  So rename this config value to better reflect what it
measures, and also prefix it with MP_.

For uses of BYTES_PER_WORD in setting the stack limit this has been
changed to sizeof(void *), because the stack usually grows with
machine-word sized values (eg an nlr_buf_t has many machine words in it).

Signed-off-by: Damien George <damien@micropython.org>
2021-02-04 22:46:42 +11:00
Damien George 7c44354592 ports: Remove def of MP_PLAT_PRINT_STRN if it's the same as the default.
To simplify config, there's no need to specify MP_PLAT_PRINT_STRN if it's
the same as the default definition in py/mpconfig.h.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-04 22:39:17 +11:00
robert b4062894df esp32/mpconfigport.h: Seed the urandom module on import.
For seeding, the RNG function of the ESP-IDF is used, which is told to be a
true RNG, at least when WiFi or Bluetooth is enabled.  Seeding on import is
as per CPython.  To obtain a reproducible sequence of pseudo-random numbers
one must explicitly seed with a known value.
2020-10-29 14:11:08 +11:00
Andrew Leech 97108fce57 esp32/mpconfigport.h: Enable MICROPY_PY_DELATTR_SETATTR.
To align with unix and stm32 ports.
2020-10-21 11:11:48 +11:00
Damien George 9e0533b9e1 extmod/machine_spi: Remove "id" arg in SoftSPI constructor.
The SoftSPI constructor is now used soley to create SoftSPI instances, it
can no longer delegate to create a hardware-based SPI instance.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 12:57:10 +10:00
Damien George aaed33896b extmod/machine_i2c: Remove "id" arg in SoftI2C constructor.
The SoftI2C constructor is now used soley to create SoftI2C instances, it
can no longer delegate to create a hardware-based I2C instance.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 12:57:10 +10:00
Jim Mussared 50efce8174 esp32/mpconfigport.h: Remove duplicate uhashlib registration. 2020-09-11 11:03:29 +10:00
Damien George 3b6c9119eb extmod/modbluetooth: Add support for changing the GAP device name.
This commit allows the user to set/get the GAP device name used by service
0x1800, characteristic 0x2a00.  The usage is:

    BLE.config(gap_name="myname")
    print(BLE.config("gap_name"))

As part of this change the compile-time setting
MICROPY_PY_BLUETOOTH_DEFAULT_NAME is renamed to
MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME to emphasise its link to GAP and this
new "gap_name" config value.  And the default value of this for the NimBLE
bindings is changed from "PYBD" to "MPY NIMBLE" to be more generic.
2020-05-11 21:30:41 +10:00
Damien George e292296d52 py/objexcept: Remove optional TimeoutError exception.
TimeoutError was added back in 077812b2ab for
the cc3200 port. In f522849a4d the cc3200
port enabled use of it in the socket module aliased to socket.timeout.  So
it was never added to the builtins.  Then it was replaced by
OSError(ETIMEDOUT) in 047af9b10b.

The esp32 port enables this exception, since the very beginning of that
port, but it could never be accessed because it's not in builtins.

It's being removed: 1) to not encourage its use; 2) because there are a lot
of other OSError subclasses which are not defined at all, and having
TimeoutError is a bit inconsistent.

Note that ports can add anything to the builtins via MICROPY_PORT_BUILTINS.
And they can also define their own exceptions using the
MP_DEFINE_EXCEPTION() macro.
2020-04-09 16:09:38 +10:00
Damien George ad004db662 esp32: Enable and freeze uasyncio. 2020-03-26 01:25:46 +11:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George f4641b2378 esp32/uart: Use core-provided mp_keyboard_interrupt, placed in IRAM. 2020-02-07 16:08:31 +11:00
Damien George 98a3911c43 py/scheduler: Add "raise_exc" argument to mp_handle_pending.
Previous behaviour is when this argument is set to "true", in which case
the function will raise any pending exception.  Setting it to "false" will
cancel any pending exception.
2020-02-07 16:08:20 +11:00
Nicko van Someren 4c93955b7b py/objslice: Add support for indices() method on slice objects.
Instances of the slice class are passed to __getitem__() on objects when
the user indexes them with a slice.  In practice the majority of the time
(other than passing it on untouched) is to work out what the slice means in
the context of an array dimension of a particular length.  Since Python 2.3
there has been a method on the slice class, indices(), that takes a
dimension length and returns the real start, stop and step, accounting for
missing or negative values in the slice spec.  This commit implements such
a indices() method on the slice class.

It is configurable at compile-time via MICROPY_PY_BUILTINS_SLICE_INDICES,
disabled by default, enabled on unix, stm32 and esp32 ports.

This commit also adds new tests for slice indices and for slicing unicode
strings.
2019-12-28 23:55:15 +11:00
Damien George b47e155bd0 py/persistentcode: Add ability to relocate loaded native code.
Implements text, rodata and bss generalised relocations, as well as generic
qstr-object linking.  This allows importing dynamic native modules on all
supported architectures in a unified way.
2019-12-12 20:15:28 +11:00
Damien George 799b6d1e0c extmod: Consolidate FAT FS config to MICROPY_VFS_FAT across all ports.
This commit removes the Makefile-level MICROPY_FATFS config and moves the
MICROPY_VFS_FAT config to the Makefile level to replace it.  It also moves
the include of the oofatfs source files in the build from each port to a
central place in extmod/extmod.mk.

For a port to enabled VFS FAT support it should now set MICROPY_VFS_FAT=1
at the level of the Makefile.  This will include the relevant oofatfs files
in the build and set MICROPY_VFS_FAT=1 at the C (preprocessor) level.
2019-11-11 11:37:38 +11:00
Jim Mussared b02d7e612d extmod/modbluetooth: Rename module to "ubluetooth".
For consistency with "umachine". Now that weak links are enabled
by default for built-in modules, this should be a no-op, but allows
extension of the bluetooth module by user code.

Also move registration of ubluetooth to objmodule rather than
port-specific.
2019-10-22 21:58:05 +11:00
Damien George d2384efa80 py: Automatically provide weak links from "foo" to "ufoo" module name.
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: #1740, #4449, #5229, #5241.
2019-10-22 15:30:52 +11:00
Jim Mussared 6a9bd1c1ab esp32: Implement BLE using Nimble from IDF 4.x. 2019-10-08 14:50:01 +11:00
Damien George 917f027c0b esp32: Enable native emitter. 2019-10-05 13:45:25 +10:00
Jim Mussared 96008ff59a esp32: Support building with ESP IDF 4.0-beta1.
This commit adds support for a second supported hash (currently set to the
4.0-beta1 tag).  When this hash is detected, the relevant changes are
applied.

This allows to start using v4 features (e.g. BLE with Nimble), and also
start doing testing, while still supporting the original, stable, v3.3 IDF.

Note: this feature is experimental, not well tested, and network.LAN and
network.PPP are currently unsupported.
2019-09-17 12:25:36 +10:00
stijn af5c998f37 py/modmath: Implement math.isclose() for non-complex numbers.
As per PEP 485, this function appeared in for Python 3.5.  Configured via
MICROPY_PY_MATH_ISCLOSE which is disabled by default, but enabled for the
ports which already have MICROPY_PY_MATH_SPECIAL_FUNCTIONS enabled.
2019-08-17 23:23:17 +10:00
Jim Mussared 8db517f26d esp32: Add per-board configs, following other ports.
Replaces the `SDKCONFIG` makefile variable with `BOARD`.  Defaults to
BOARD=GENERIC.  spiram can be enabled with `BOARD=GENERIC_SPIRAM`

Add example definition for TINYPICO, currently identical to GENERIC_SPIRAM
but with custom board/SoC names for the uPy banner.
2019-08-16 00:22:29 +10:00
Damien George 2ccf030fd1 esp32: Add support for mDNS queries and responder.
They are both enabled by default, but can be disabled by defining
MICROPY_HW_ENABLE_MDNS_QUERIES and/or MICROPY_HW_ENABLE_MDNS_RESPONDER to
0.  The hostname for the responder is currently taken from
tcpip_adapter_get_hostname() but should eventually be configurable.
2019-08-15 16:36:47 +10:00
Damien George a29334761d esp32: Add support for hardware I2C. 2019-07-19 16:31:25 +10:00
Nicko van Someren 8e3af7d4c8 esp32: Add machine.SDCard class using built-in HW SD/MMC controller.
This adds support for SD cards using the ESP32's built-in hardware SD/MMC
host controller, over either the SDIO bus or SPI.  The class is available
as machine.SDCard and using it can be as simple as:

    uos.mount(machine.SDCard(), '/sd')
2019-06-03 00:37:41 +10:00
Damien George b5f33ac2cb ports: Update to work with new oofatfs version. 2019-03-05 15:56:39 +11:00
Yonatan Goldschmidt bc4f8b438b extmod/moduwebsocket: Refactor `websocket` to `uwebsocket`.
As mentioned in #4450, `websocket` was experimental with a single intended
user, `webrepl`. Therefore, we'll make this change without a weak
link `websocket` -> `uwebsocket`.
2019-02-14 00:35:45 +11:00
Damien George 9ac9aa989c esp32/machine_timer: Deinit all active timers on soft reset.
Otherwise they will keep triggering the callback and access invalid data on
the heap.
2019-01-28 16:16:03 +11:00
Damien George 349d8e1324 esp32: Allow to build with uPy floats disabled. 2018-07-03 12:10:03 +10:00
Damien George 8f86fbfd6c ports: Enable ure.sub() on stm32, esp8266 (not 512k) and esp32. 2018-07-02 15:13:18 +10:00
Damien George 82bc4838d2 esp32/mpconfigport.h: Enable ucryptolib module. 2018-06-27 16:44:59 +10:00
Damien George 0501427907 esp32: Remove port-specific uhashlib implementation and use common one.
Now that the common module has mbedtls support for both SHA1 and SHA256 it
can now be used on this port.
2018-06-12 13:50:11 +10:00