forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
1 changed file
with
80 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters