Wykres commitów

21 Commity (master)

Autor SHA1 Wiadomość Data
Angus Gratton decf8e6a8b all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a.  The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.

This STATIC feature is rarely (if ever) used.  And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.

So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing.  For example, newcomers don't have
to learn what the STATIC macro is and why it exists.  Reading the code is
also less "loud" with a lowercase static.

One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.

Methodology for this commit was:

1) git ls-files | egrep '\.[ch]$' | \
   xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"

2) Do some manual cleanup in the diff by searching for the word STATIC in
   comments and changing those back.

3) "git-grep STATIC docs/", manually fixed those cases.

4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-07 14:20:42 +11:00
Nicko van Someren 1da45e887a rp2: Provide direct memory access to PIO and SPI FIFOs via proxy arrays.
Signed-off-by: Nicko van Someren <nicko@nicko.org>
2024-01-07 18:27:01 +11:00
Angus Gratton 28529351ae rp2: Switch rp2 and drivers to use new event functions.
This commit changes all uses in the rp2 port, and drivers that are
optionally supported by that port.

The old MICROPY_EVENT_POLL_HOOK and MICROPY_EVENT_POLL_HOOK_FAST macros are
no longer used for rp2 builds and are removed (C user code will need to be
changed to suit).

Also take the opportunity to change some timeouts that used 64-bit
arithmetic to 32-bit, to hopefully claw back a little code size.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:49:43 +11: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
Damien George 0afe60b876 rp2/rp2_pio: Track use of PIO resources and free them on soft reset.
Prior to this commit, on Pico W (where the CYW43 driver is enabled) the PIO
instruction memory was not released on soft reset, so using PIO after a
soft reset would eventually (after a few soft resets) lead to ENOMEM when
allocating a PIO program.

This commit fixes that by tracking the use of PIO memory by this module and
freeing it on soft reset.

Similarly, use of the state machines themselves are tracked and released on
soft reset.

Fixes issue #9003.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-07 14:52:36 +11:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:15 +10:00
Jim Mussared 9dce82776d all: Remove unnecessary locals_dict cast.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 662b9761b3 all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
robert-hh 0c45a28d24 rp2/rp2_pio: Fix StateMachine.restart when PIO program is shared.
The state machines were not properly restarted in the case that the same
PIO program was shared among multiple StateMachine instances.  This is
because only the first StateMachine to use the program would set the
rp2_state_machine_initial_pc variable.

See https://forum.micropython.org/viewtopic.php?f=21&t=12776&p=69464#p69464
2022-07-26 02:00:01 +10:00
David Lechner ffa22b8f97 rp2: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register all port-specific root
pointers in the rp2 port.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:34 +10:00
Damien George 85be3d3da8 rp2/mpconfigport: Factor core event handling to EVENT_POLL_HOOK_FAST.
Signed-off-by: Damien George <damien@micropython.org>
2022-07-05 16:11:42 +10:00
Damien George 50e46552c0 rp2: Integrate CYW43xx WiFi driver.
This includes:
- Configuration file for the cyw43-driver.
- Integration of cyw43-driver into the build, using lwIP.
- Enhancements to machine.Pin to support extension IO pins provided by the
  CYW43xx.
- More mp-hal pin helper functions.
- mp_hal_get_mac_ascii MAC address helper function.
- Addition of rp2.country() function to set the country code.

A board can enable this driver by setting MICROPY_PY_NETWORK_CYW43 in their
cmake snippet.

Work done in collaboration with Graham Sanderson and Peter Harper.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-30 17:03:51 +10:00
oli 0a9335ecaa rp2/rp2_pio: Support exec with sideset.
The rp2.StateMachine.exec errors when supplying a sideset action.  This
commit passes the sideset_opt from the StateMachine though to the parser.
It also adds some value validation to the sideset operator.

Additionally, the "word" method is added to the exec to allow any other
unsupported opcodes.

Fixes issue #7924.
2021-11-19 13:35:28 +11:00
Damien George 136369d72f all: Update to point to files in new shared/ directory.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 17:08:10 +10:00
Tim Radvan f842a40df4 rp2/rp2_pio: Add fifo_join support for PIO.
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>
2021-04-17 00:45:38 +10:00
robert-hh 22554cf8e2 rp2/rp2_pio: Add StateMachine restart,rx_fifo,tx_fifo helper functions.
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.
2021-04-11 22:41:54 +10:00
Damien George 2c9af1c1d7 rp2/rp2_pio: Validate state machine frequency in constructor.
Fixes issue #7025.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-09 18:06:10 +10:00
robert-hh 0461640983 rp2/rp2_pio: Fix sm.get(buf) to not wait after getting last item.
sm.get(buf) was waiting for one item more than the length of the supplied
buffer.  Even if this item was not stored, sm_get would block trying to get
an item from the RX fifo.

As part of the fix, the edge case for a zero length buffer was moved up to
the section where the function arguments are handled.  In case of a zero
length buffer, sm.get() now returns immediately that buffer.
2021-03-12 00:39:26 +11:00
robert-hh a075e0b7d8 rp2/rp2_pio: Allow more than 8 consecutive pins for PIO out/set/sideset.
The bitmasks supplied for initialization of out/set/sideset were only 8 bit
instead of 32.  This resulted in an error, that not more than 8 consecutive
pins would get initialized.

Fixes issue #6933.
2021-03-12 00:26:32 +11:00
Tim Radvan 7a9027fd5d rp2/rp2_pio: Add JMP PIN support for PIO.
PIO state machines can make a conditional jump on the state of a pin: the
`JMP PIN` command.  This requires the pin to be configured with
`sm_config_set_jmp_pin`, but until now we didn't have a way of doing that
in MicroPython.

This commit adds a new `jmp_pin=None` argument to `StateMachine`.  If it is
not `None` then we try to interpret it as a Pin, and pass its value to
`sm_config_set_jmp_pin`.

Signed-off-by: Tim Radvan <tim@tjvr.org>
2021-02-02 11:32:48 +11:00
Damien George 469345e728 rp2: Add new port to Raspberry Pi RP2 microcontroller.
This commit adds a new port "rp2" which targets the new Raspberry Pi RP2040
microcontroller.

The build system uses pure cmake (with a small Makefile wrapper for
convenience).  The USB driver is TinyUSB, and there is a machine module
with most of the standard classes implemented.  Some examples are provided
in the examples/rp2/ directory.

Work done in collaboration with Graham Sanderson.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-30 00:42:29 +11:00