micropython/ports
Trent Piepho 31e131bd71 esp32/machine_hw_spi: Combine argument parsing for constructor and init.
This combines the argument parsing and checking for the machine.SPI.init()
and machine.SPI() interfaces.

The only real difference was unspecified arguments in init() mean to keep
the same value, while in new they get default values.

Behavior has changed for passing the "id" argument to init().  On other
ports this isn't allowed.  But on esp32 it would change the SPI controller
of the static SPI instance to the new id.  This results in multiple static
spi objects for the same controller and they would fight over which one has
inconsistent mpy vs esp-idf state.  This has been changed to not allow "id"
with init(), like other ports.

In a few causes, a loop is used over arguments that are handled the same
way instead of cut & pasting the same stanza of code for each argument.

The init_internal function had a lot of arguments, which is not efficient
to pass.  Pass the args mp_arg_val_t array instead as a single argument.
This reduced both the number of C lines and the compiled code size.

Summary of code size change:  Two argument lists of 72 bytes are replaced
by a single shared 72 byte list.  New shared argument parsing code is small
enough to be inlined, but is still efficient enough to shrink the overall
code size by 349 bytes of the three argument handlering functions.

add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-349 (-349)
Function                                     old     new   delta
machine_hw_spi_make_new                      255     203     -52
machine_hw_spi_init                          122      67     -55
machine_hw_spi_init_internal                 698     456    -242
Total: Before=1227667, After=1227318, chg -0.03%
add/remove: 2/0 grow/shrink: 0/2 up/down: 92/-144 (-52)
Data                                         old     new   delta
spi_allowed_args                               -      72     +72
defaults$0                                     -      20     +20
allowed_args$1                               240     168     -72
allowed_args$0                              1080    1008     -72
Total: Before=165430, After=165378, chg -0.03%
add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-02-20 16:55:09 +11:00
..
bare-arm
cc3200 all: Use mp_obj_malloc_with_finaliser everywhere it's applicable. 2024-02-20 10:32:55 +11:00
embed py/emitglue: Introduce mp_proto_fun_t as a more general mp_raw_code_t. 2024-02-16 14:17:01 +11:00
esp32 esp32/machine_hw_spi: Combine argument parsing for constructor and init. 2024-02-20 16:55:09 +11:00
esp8266
mimxrt
minimal minimal: Use printf instead of echo -e. 2024-02-15 16:36:22 +11:00
nrf py/obj: Change sizeof to offsetof in mp_obj_malloc_var macro. 2024-02-19 23:40:54 +11:00
pic16bit
powerpc
qemu-arm
renesas-ra
rp2 all: Use mp_obj_malloc_with_finaliser everywhere it's applicable. 2024-02-20 10:32:55 +11:00
samd
stm32 stm32/mboot: Generate FLASH_LAYOUT_STR at runtime on H5 MCUs. 2024-02-20 12:32:45 +11:00
unix py/obj: Change sizeof to offsetof in mp_obj_malloc_var macro. 2024-02-19 23:40:54 +11:00
webassembly
windows
zephyr all: Use mp_obj_malloc_with_finaliser everywhere it's applicable. 2024-02-20 10:32:55 +11:00