Wykres commitów

14787 Commity (5e0452125146f3afed89c09f5813790156d24471)

Autor SHA1 Wiadomość Data
David Lechner 978829fcd6 shared/upytesthelper: Fix spelling of "default".
Signed-off-by: David Lechner <david@pybricks.com>
2023-05-19 21:58:32 +10:00
Jim Mussared 46d070bfee tools/manifestfile.py: Fix license capturing.
The license field was incorrectly being set to the version.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-19 21:56:38 +10:00
marble b5c81f6bfb docs/develop/porting: Add missing code to example main.c and Makefile.
These two missing lines caused the build process to fail when implementing
the tutorial example port.

Signed-off-by: marble <git@computer-in.love>
2023-05-19 21:51:19 +10:00
glenn20 12dbbc8065 docs/library/espnow: Update espnow docs for WLAN.config(pm=x) options.
Update docs/library/espnow.rst to add:
- guidance on using WLAN.config(pm=WLAN.PM_NONE) for reliable
  espnow performance while also connected to a wifi access point;
- guidance on receiving encrypted messages;
- correction for default value of "encrypt" parameter (add_peer());
- guidance on use of ESPNow.irq(): recommand users readout all messages
  in the buffer each time the callback is called.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2023-05-19 21:48:08 +10:00
Damien George ea7031faff py/runtime: If inplace binop fails then try corresponding normal binop.
The code that handles inplace-operator to normal-binary-operator fallback
is moved in this commit from py/objtype.c to py/runtime.c, making it apply
to all types, not just user classes.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-19 13:44:00 +10:00
Damien George 4b57330465 py/objstr: Return unsupported binop instead of raising TypeError.
So that user types can implement reverse operators and have them work with
str on the left-hand-side, eg `"a" + UserType()`.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-19 13:42:35 +10:00
Damien George ca9068e0ef py/objarray: Disallow memoryview addition.
Following CPython.  This is important for subsequent commits to work
correctly.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-19 13:33:54 +10:00
Damien George 9accb7dd44 tests/basics: Add more tests for hashing of various types.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-19 12:35:12 +10:00
David Lechner 2fe6d4eb86 py/objdict: Fix __hash__ for dict_view types.
This adds a unary_op implementation for the dict_view type that makes
the implementation of `hash()` for these types compatible with CPython.

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-19 12:06:17 +10:00
David Lechner 8491eb190f py/objslice: Ensure slice is not hashable.
As per https://bugs.python.org/issue408326, the slice object should not be
hashable.  Since MicroPython has an implicit fallback when the unary_op
slot is empty, we need to fill this slot.

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-19 12:06:06 +10:00
David Lechner eaccaa3677 py/obj: Remove mp_generic_unary_op().
Since converting to variable sized slots in mp_obj_type_t, we can now
reduce the code size a bit by removing mp_generic_unary_op() and the
corresponding slots where it is used. Instead we just implement the
generic `__hash__` operation in the runtime.

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-19 12:04:44 +10:00
Damien George 53cb073571 esp32,esp8266: Change network.WLAN from a function to a type.
When the network module was first introduced in the esp8266 port in
ee3fec3167 there was only one interface (STA)
and, to save flash, the WLAN object was aliased to the network module,
which had just static methods for WLAN operations.  This was subsequently
changed in 9e8396accb when the AP interface
was introduced, and the WLAN object became a true class.

But, network.WLAN remained a function that returned either the STA or AP
object and was never upgraded to the type itself.  This scheme was then
copied over to the esp32 port when it was first introduced.

This commit changes network.WLAN from a function to a reference to the WLAN
type.  This makes it consistent with other ports and network objects, and
allows accessing constants of network.WLAN without creating an instance.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-18 14:52:28 +10:00
Jim Mussared 17127bbee5 tests/run-tests.py: Ensure correct cwd for mpy tests.
Previously when using --via-mpy, the file was compiled to tests/<tmp>.mpy
and then run using `micropython -m <tmp>` in the current cwd
(usually tests/).  This meant that an import in the test would be resolved
relative to tests/.

This is different to regular (non-via-mpy) tests, where we run (for
example) `micropython basics/test.py` which means that an import would be
resolved relative to basics/.

Now --via-mpy matches the .py behavior.  This is important because:
a) It makes it so import tests do the right thing.
b) There are directory names in tests/ that match built-in module names.

Furthermore, it always ensures the cwd (for both micropython and cpython)
is the test directory (e.g. basics/) rather than being left unset.  This
also makes it clearer inside the test that e.g. file access is relative to
the Python file.

Updated tests with file paths to match.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-18 13:48:21 +10:00
Damien George ab3f9ecb59 github/workflows: Force use of Ubuntu-20.04 for unix 32-bit builds.
To be able to install libffi-dev:i386.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-18 13:12:40 +10:00
Ondrej Wisniewski 29401a719f rp2/mphalport: Only use CYW43 MAC for WLAN0 interface.
Building the Pico-W needs the MICROPY_PY_NETWORK_CYW43 flag to be set in
order to include building the CYW43 Wifi driver.  But then mp_hal_get_mac()
handles the MAC assignment for all nics the "CYW43 way", copying the real
MAC provided by the WiFi hardware.  This will fail for all other NIC types,
resulting in an invalid MAC address.

The solution in this commit is to add a check for the NIC type parameter
idx and handle the MAC address respectively.
2023-05-18 13:06:06 +10:00
Phil Howard 4ce360fa83 rp2/CMakeLists: Allow relative MICROPY_BOARD_DIR when invoking cmake.
Convert to an absolute path to always reliably locate manifest.py.  This is
already done in Makefile, but is also needed in CMakeLists.txt if cmake is
invoked directly.

Signed-off-by: Phil Howard <phil@pimoroni.com>
2023-05-18 12:51:36 +10:00
Adam Green f9958417d8 rp2: Make rp2_state_machine_exec accept integers.
Currently rp2.StateMachine.exec(instr_in) requires that the instr_in
parameter be a string representing the PIO assembly language instruction
to be encoded by rp2.asm_pio_encode(). This commit allows the parameter
to also be of integral type. This is useful if the exec() method is
being called often where the use of pre-encoded machine code is
desireable.

This commit still supports calls like:
    sm.exec("set(0, 1)")

It also now supports calls like:
    # Performed once earlier, maybe in __init__()
    assembled_instr = rp2.asm_pio_encode("out(y, 8)", 0)
    # Performed multiple times later as the PIO state machine is
    # configured for its next run.
    sm.exec(assembled_instr)

The existing examples/rp2/pio_exec.py and examples/rp2/pio_pwm.py that
exercise the rp2.StateMachine.exec() method still work with this change.

Signed-off-by: Adam Green <adamgrym@yahoo.com>
2023-05-18 12:33:02 +10:00
Takeo Takahashi 3229791b60 renesas-ra: Add a macro definition to avoid compile error of FSP v4.4.0.
FSP v4.4.0 refers to CMSIS V5.4.1, and __COMPILER_BARRIER() is used in bsp.
On the other hand, lib/cmsis is V5.1.0 and the macro is not defined.
Therefore, compile error happens.
As the workaround, the macro definition is added.
If lib/cmsis is updated in the future, this addition can be removed.

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-05-11 16:18:39 +10:00
Takeo Takahashi b4834e5cba renesas-ra: Update boards and ra directory files to support FSP v4.4.0.
* Update boards and ra files
* Remove unreferenced files, board_init.c and board_leds.c, from Makefile
* Remove unreferenced FSP instances from ra_gen/*.[ch]
* Remove unreferenced FSP config files ra_cfg/*.h
* e2 studio generates FSP instances but renesas-ra uses only followings:
  lpm, flash, ioport

Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-05-11 16:18:39 +10:00
Takeo Takahashi 0c58e29074 lib/fsp: Update FSP for renesas-ra to the latest version v4.4.0.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
2023-05-11 16:18:39 +10:00
David Lechner 6a4a9bc147 windows/Makefile: Allow variants to add QSTR_DEFS.
This modifies the windows port Makefile to use += for QSTR_DEFS and
QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if
needed (similar to stm32 port).

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-11 14:34:15 +10:00
David Lechner 6836acf3dc unix/Makefile: Allow variants to add QSTR_DEFS.
This modifies the unix port Makefile to use += for QSTR_DEFS and
QSTR_GLOBAL_DEPENDENCIES so that variants can add additional files if
needed (similar to stm32 port).

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-11 14:34:01 +10:00
David Lechner 3e64d76122 docs/reference/mpyfiles: Add release info on v6.1.
This documents when MPY v6.1 was released.

Also add some clarification on how the version is encoded in the header.

Signed-off-by: David Lechner <david@pybricks.com>
2023-05-11 14:30:34 +10:00
Christian Clauss 4e4bdbd191 top: Add ruff to pre-commit.
This does not align with the other pre-commit jobs with are local custom
code but it should run accurately and quickly.

Signed-off-by: Christian Clauss <cclauss@me.com>
2023-05-10 09:57:26 +10:00
Christian Clauss a000c61d5d tools/pyboard.py: Import errno to fix undefined name in PyboardError.
This will keep line 96 from raising a NameError.

Signed-off-by: Christian Clauss <cclauss@me.com>
2023-05-09 18:49:23 +10:00
robert-hh 65d376b11d mimxrt/machine_pin: Perform full configuration in machine_pin_set_mode.
machine_pin_set_mode() is used by the internal mp_hal_pin_xxx() set of
functions to configure pins.
2023-05-09 16:15:05 +10:00
robert-hh 14b862f70f mimxrt/machine_spi: Ignore transfers with len=0.
It was treated as an error before.  The error surfaced when using the
NINAW10 drivers for WiFi support.  Even if this is a bad behavior of the
NINA driver, machine_spi can be forgiving in that situation.
2023-05-09 16:14:40 +10:00
robert-hh d2a02dcee3 mimxrt: Add missing UART defintion and remove obsolete config.
Changes in this commit:
- Add a missing UART defintion for MIMXRT1010_EVK.
- Remove an obsolete line from mpconfigport.h.
2023-05-09 16:13:51 +10:00
robert-hh facc51f3ea mimxrt/mpconfigport: Add back lost uos.urandom().
It got lost in a clean-up session recently.
2023-05-09 16:13:27 +10:00
Philipp Ebensberger a3f3b9045c mimxrt/flash: Separate low level driver code from flash object.
Separate low level flash access from mimxrt flash driver object.  Allows
better abstraction from hardware for testing and reuse in other areas (e.g.
bootloader).

Signed-off-by: Philipp Ebensberger <philipp.ebensberger@3bricks-software.de>
2023-05-09 15:18:36 +10:00
Jim Lipsey 7333c06d05 stm32/boards/ARDUINO_PORTENTA_H7: Enable FDCAN.
Add pin definitions to enable FDCAN support using the pyb.CAN() class.
2023-05-09 13:25:03 +10:00
David Lechner 468ed218c9 py/gc: Make improvements to MICROPY_GC_HOOK_LOOP.
Changes in this commit:
- Add MICROPY_GC_HOOK_LOOP to gc_info() and gc_alloc().  Both of these can
  be long running (many milliseconds) which is too long to be blocking in
  some applications.
- Pass loop variable to MICROPY_GC_HOOK_LOOP(i) macro so that implementers
  can use it, e.g. to improve performance by only calling a function every
  X number of iterations.
- Drop outer call to MICROPY_GC_HOOK_LOOP in gc_mark_subtree().
2023-05-09 12:44:14 +10:00
Damien George 7c645b52e3 CODECONVENTIONS: Require that commits be signed-off by the author.
And use "must" instead of "should" where appropriate in related text.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-08 12:20:56 +10:00
Damien George a31e3de400 extmod/network_cyw43: Add power management constants.
And allow querying the current power management mode.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-08 11:56:31 +10:00
glenn20 1093dea709 esp32,esp8266: Add support to set/get power saving mode of WLAN.
For esp32 and esp8266 this commit adds:
- a 'pm' option to WLAN.config() to set/get the wifi power saving mode; and
- PM_NONE, PM_PERFORMANCE and PM_POWERSAVE constants to the WLAN class.

This API should be general enough to use with all WLAN drivers.

Documentation is also added.
2023-05-06 13:51:00 +10:00
robert-hh 786013d467 docs/samd: Make use of pin names more consistent in examples.
This keeps up with the changed Pin naming scheme.
2023-05-04 13:19:19 +10:00
Damien George 38243cd8e0 extmod/machine_pwm: Remove PWM_INIT and PWM_DUTY_U16_NS config options.
All ports that enable MICROPY_PY_MACHINE_PWM now enable these two
sub-options, so remove these sub-options altogether to force consistency in
new ports that implement machine.PWM.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-04 13:19:19 +10:00
robert-hh 7952694a3c rp2/machine_pwm: Add duty_x() checks and return 0 if PWM is not started.
Changes in this commit:
- Limit duty_u16() to 65535 and duty_ns() to the period duration.
- Return 0 for pwm.freq() if the frequency has not been set yet.
- Return 0 for pwm.duty_us16() and duty_ns() unless both frequency and
  duty cycle have been set.
- Initialize the pin to PWM at the very end of the constructor, to avoid
  possible glitches on the pin when setting up the PWM.
2023-05-04 13:18:58 +10:00
robert-hh 0b3b508d1d rp2/machine_pwm: Add support for inverting a PWM channel output.
Using the invert=True|False keyword option with the constructor or init().
2023-05-04 13:18:47 +10:00
robert-hh 2ac643c15b esp8266/machine_pwm: Implement duty_u16() and duty_ns() for consistency.
Also adds these keyword arguments to the constructor and init method.
2023-05-04 13:17:55 +10:00
robert-hh dc8f9d22ca docs: Update the PWM examples based on recent API improvements.
This adds the freq and duty_u16 keyword settings to the constructor, and
sometimes other details in the PWM section.

For mimxrt a clarification regarding the PWM invert argument was added, and
for rp2 a few words were spent on PWM output pairs of a channel/slice.
2023-05-04 13:15:55 +10:00
robert-hh 84302b2854 rp2/machine_pwm: Enable keyword args in constructor and add init method.
This adds support for freq/duty_u16/duty_ns keyword arguments in the PWM
constructor, and adds the PWM.init() method.  Using init() without
arguments enables a previously deinit-ed PWM again.

Further changes in this commit:
- Do not start PWM output if only duty was set.
- Stop all PWM slices on soft-reset.
- Fix a bug when changing the freq on a channel pair with duty_ns set.
2023-05-04 13:13:05 +10:00
robert-hh 250757716a samd/machine_pwm: Add init() method to PWM and simplify the PWM code.
The PWM.init() method has been added.  Calling init() without arguments
restarts a PWM channel stopped with deinit().  Otherwise single parameters
except for "device=n" can be changed again.  The device can only be
specified once, either in the constructor or the first init() call.

Also simplify get_pwm_config() and get_adc_config(), and shrink the PWM
object.
2023-05-04 13:10:38 +10:00
robert-hh 9c7ad68165 mimxrt/machine_pwm: Start PWM only if freq and duty are set.
And also fix/improve the following:
- Simplify the duty handling a little bit.
- Allow duty_u16(65536), which sets the output high.
- Rename machine_pwm_start() to mp_machine_pwm_start(), in preparation for
  a possible start/stop method pair.
2023-05-04 13:09:39 +10:00
Damien George 0264465585 tools/pyboard.py: Import serial.tools.list_ports.
This import is needed by newer versions of pyserial.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-04 12:12:29 +10:00
Damien George f1c6cb7725 py/stackctrl: Add gcc pragmas to ignore dangling-pointer warning.
This warning became apparent in gcc 13.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-04 10:08:12 +10:00
Carlosgg 61b8e1b2d8 lib/mbedtls: Update to mbedtls v2.28.3.
This is the latest release in the 2.28 long-time support branch.

Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-05-03 17:33:38 +10:00
Damien George 1b980c9dbe py/compile: Remove over-eager optimisation of tuples as if condition.
When a tuple is the condition of an if statement, it's only possible to
optimise that tuple away when it is a constant tuple (ie all its elements
are constants), because if it's not constant then the elements must be
evaluated in case they have side effects (even though the resulting tuple
will always be "true").

The code before this change handled the empty tuple OK (because it doesn't
need to be evaluated), but it discarded non-empty tuples without evaluating
them, which is incorrect behaviour (as show by the updated test).

This optimisation is anyway rarely applied because it's not common Python
coding practice to write things like `if (): ...` and `if (1, 2): ...`, so
removing this optimisation completely won't affect much code, if any.

Furthermore, when MICROPY_COMP_CONST_TUPLE is enabled, constant tuples are
already optimised by the parser, so expression with constant tuples like
`if (): ...` and `if (1, 2): ...` will continue to be optimised properly
(and so when this option is enabled the code that's deleted in this commit
is actually unreachable when the if condition is a constant tuple).

Signed-off-by: Damien George <damien@micropython.org>
2023-05-03 13:21:18 +10:00
Damien George 957bd51184 py/parse: Fix build when COMP_CONST_FOLDING=0 and COMP_MODULE_CONST=1.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-03 13:12:54 +10:00
Christian Clauss 78a1aa1711 github/workflows: Add GitHub Action to lint Python code with ruff.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-02 23:52:11 +10:00