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>
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>
To keep things neat and tidy, we ensure that each file has 1 and only 1
newline at the end of each file.
Signed-off-by: David Lechner <david@pybricks.com>
Flash erase/program functions disable the XIP bit. If any code runs from
flash at the same time (eg an IRQ or code it calls) it will fail and cause
a lockup.
Prior to this fix, if the UART hardware FIFO had a few chars but still
below the FIFO trigger threshold, and the ringbuf was empty, the read
function would timeout if timeout==0 (the default timeout).
This fix follows the suggestion of @iabdalkader.
The RX IRQ does not trigger if the FIFO is less than the trigger level, in
which case characters may be available in the FIFO, yet not in the ringbuf,
and the ioctl returns false.
These warnings appear with GCC 11. Keep them as warnings but not as
compiler errors so they can be dealt with properly in the future.
Signed-off-by: Damien George <damien@micropython.org>
Calculating the weekday each time you want to set a date is error prone and
tiresome. MicroPython can do it on its own - hardware on some ports do not
support storing weekday in hardware and always computes it on the fly,
ignoring the value given to the constructor.
During discussion for #7432 the conclusion was that there seems to be no
obvious reason to let user set the weekday to an incorrect value so it
makes sense to just ignore the provided weekday value and always compute
the correct value. This patch introduces this change for the rp2 port.
Signed-off-by: Krzysztof Adamski <k@japko.eu>
The RTC in rp2 can store any, even wrong, number as a weekday in RTC. It
was, however, discussed in #7394 that we would like to unify all ports and
use 0 as Monday, not Sunday in the machine.RTC implementation.
This patch makes sure that the default date set in RTC is adheres to this
convention. It also fixes the example in quickref to use proper weekday to
avoid confusion.
Signed-off-by: Krzysztof Adamski <k@japko.eu>
The rtc_set_datetime() from pico-sdk will validate the values in the
datetime_t structure and refuse to set the time if they aren't valid. It
makes sense to raise an exception if this happens instead of failing
silently which might be confusing (as an example, see:
https://github.com/micropython/micropython/pull/6928#issuecomment-860166044
).
Initial support for machine.RTC on rp2 port. It only supports datetime()
method and nothing else. The method gets/returns a tuple of 8 items, just
like esp32 port, for example, but the usec parameter is ignored as the RP2
RTC only works up to seconds precision.
The Pico RTC isn't very useful as the time is lost during reset and there
seems to be no way to easily power up just the RTC clock with a low current
voltage, but still there seems to be use-cases for that, see issues #6831,
and a Thonny issue #1592. It was also requested for inclusion on v1.15
roadmap on #6832.
Signed-off-by: Krzysztof Adamski <k@japko.eu>
Any code running on core1 should be stopped on soft-reset (the GC heap is
reset so if code continues to run on core1 it will see corrupt memory).
Signed-off-by: Damien George <damien@micropython.org>
The number shown in the USB id is now the same as that returned by
machine.unique_id(). All 8 bytes are inserted as hex into the USB id. A
usb id at /dev/serial/by-id then looks like:
usb-MicroPython_Board_in_FS_mode_e469b03567342f37-if00
The PIO state machines on the RP2040 have 4 word deep TX and RX FIFOs. If
you only need one direction, you can "merge" them into either a single 8
word deep TX or RX FIFO.
We simply add constants to the PIO object, and set the appropriate bits in
`shiftctrl`.
Resolves#6854.
Signed-off-by: Tim Radvan <tim@tjvr.org>
This change allows to build firmware for different rp2-based boards,
following how it is done in other ports like stm32 and esp32. So far only
the original Pico and Adafruit Feather RP2040 are added. Board names
should match (sans case) those in pico-sdk/src/boards/include/boards/.
Usage: Pico firmware can be build either using make as previously (it is
the default board) or by `make BOARD=PICO`. Feather is built by `make
BOARD=ADAFRUIT_FEATHER_RP2040`. Only the board name and flash drive size
is set, pin definition is taken from the appropriate pico-sdk board
definition. Firmware is saved in the directory build-BOARD_NAME.
Instantiation and init now support the rxbuf and txbuf keywords for setting
the buffer size. The default size is 256 bytes. The minimum and maximum
sizes are 32 and 32766 respectively.
uart.write() still includes checks for timeout, even if it is very unlikely
to happen due to a) lack of flow control support and b) the minimal timeout
values being longer than the time it needs to send a byte.
StateMachine.restart: Restarts the state machine
StateMachine.rx_fifo: Return the number of RX FIFO items, 0 if empty
StateMachine.tx_fifo: Return the number of TX FIFO items, 0 if empty
restart() seems to be the most useful one, as it resets the state machine
to the initial state without the need to re-initialise/re-create. It also
makes PIO code easier, because then stalling as an error state can be
unlocked.
rx_fifo() is also useful, for MP code to check for data and timeout if no
data arrived. Complex logic is easier handled in Python code than in PIO
code.
tx_fifo() can be useful to check states where data is not processed, and is
mostly for symmetry.
The implementation samples rosc.randombits at a frequency lower than the
oscillator frequency. This gives better random values. In addition, for
an 8-bit value 8 samples are taken and fed through a 8-bit CRC,
distributing the sampling over the byte. The resulting sampling rate is
about 120k/sec.
The RNG does not include testing of error conditions, like the ROSC being
in sync with the sampling or completely failing. Making the interim value
static causes it to perform a little bit better in short sync or drop-out
situations.
The output of uos.urandom() performs well with the NIST800-22 test suite.
In my trial it passed all tests of the sts 2.1.2 test suite. I also ran a
test of the random data with the Common Criteria test suite AIS 31, and it
passed all tests too.