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>
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.
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.
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.
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.
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.
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>
This fixes:
- type-comparison (E721): do not compare types, use isinstance().
- string-dot-format-missing-arguments (F524): .format call is missing
argument(s) for placeholder(s): {message}.
- f-string-missing-placeholders (F541).
- is-literal (F632): Use != to compare constant literals.
The last one is fixed by just comparing for truthfulness of `state`.
ESP-NOW is a proprietary wireless communication protocol which supports
connectionless communication between ESP32 and ESP8266 devices, using
vendor specific WiFi frames. This commit adds support for this protocol
through a new `espnow` module.
This commit builds on original work done by @nickzoic, @shawwwn and with
contributions from @zoland. Features include:
- Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO.
- Signal strength (RSSI) monitoring.
- Core support in `_espnow` C module, extended by `espnow.py` module.
- Asyncio support via `aioespnow.py` module (separate to this commit).
- Docs provided at `docs/library/espnow.rst`.
Methods available in espnow.ESPNow class are:
- active(True/False)
- config(): set rx buffer size, read timeout and tx rate
- recv()/irecv()/recvinto() to read incoming messages from peers
- send() to send messages to peer devices
- any() to test if a message is ready to read
- irq() to set callback for received messages
- stats() returns transfer stats:
(tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts)
- add_peer(mac, ...) registers a peer before sending messages
- get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt)
- mod_peer(mac, ...) changes peer info parameters
- get_peers() returns all peer info tuples
- peers_table supports RSSI signal monitoring for received messages:
{peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...}
ESP8266 is a pared down version of the ESP32 ESPNow support due to code
size restrictions and differences in the low-level API. See docs for
details.
Also included is a test suite in tests/multi_espnow. This tests basic
espnow data transfer, multiple transfers, various message sizes, encrypted
messages (pmk and lmk), and asyncio support.
Initial work is from https://github.com/micropython/micropython/pull/4115.
Initial import of code is from:
https://github.com/nickzoic/micropython/tree/espnow-4115.
This allows updating mp_mbedtls_errors.c for the other mbedtls based ports
based on mbedTLS v2.28.1. This esp32-specific file will not be required
after updating IDF support to >= v4.4.1.
Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
This should have been updated as part of commit
7d73b9ff99, when mbedtls was changed to the
LTS branch v2.16.
Signed-off-by: Damien George <damien@micropython.org>
API change: time.time_ns() is added, but it just returns 0.
No API or functional change to existing time functions.
Signed-off-by: Damien George <damien@micropython.org>
API additions;
- time.sleep() is added
- time.ticks_cpu() is added, but it just returns 0
No API or functional change to existing time functions.
Signed-off-by: Damien George <damien@micropython.org>
API change: time.time_ns() is added, but it just returns 0.
No API or functional change to existing time functions.
Signed-off-by: Damien George <damien@micropython.org>
Based on extmod/utime_mphal.c, with:
- a globals dict added
- time.localtime wrapper added
- time.time wrapper added
- time.time_ns function added
New configuration options are added for this module:
- MICROPY_PY_UTIME (enabled at basic features level)
- MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME
- MICROPY_PY_UTIME_TIME_TIME_NS
Signed-off-by: Damien George <damien@micropython.org>
Changes in this commit:
- Change MICROPY_HW_BOARD_NAME definition to match the product name.
- Rename board folder's name to match the product name style.
- Change related files like Makefile, document descriptions, test cases, CI
and tools.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
Instead of doing the shallow checkout followed by an unshallow-with-tags,
just set fetch-depth=0 to get the full history to start with.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>