Reorder pins in bi_pins_with_names to be correct #1858

Merged
will-v-pi merged 1 commit from bi-pins-reorder into develop 2024-08-22 11:56:16 -05:00
will-v-pi commented 2024-08-21 09:08:02 -05:00 (Migrated from github.com)

Alternative to #1791 - instead of asserting when the order is incorrect, reorder the names so they are in the correct order for the pin mask

Requires more pre-processor stuff, but doesn't break existing code with the pins in the wrong order, so pico-examples/524 would no longer be required

Has been tested using the following python code to generate all permutations of bi_decls which are then copied and compiled into a binary, and then checked with picotool info to ensure pins are all named correctly

import itertools

pins = [
    'PICO_DEFAULT_SPI_RX_PIN, "SPI RX"',
    'PICO_DEFAULT_SPI_TX_PIN, "SPI TX"',
    'PICO_DEFAULT_SPI_SCK_PIN, "SPI SCK"',
    'PICO_DEFAULT_SPI_CSN_PIN, "SPI CS"'
]

pinperms = itertools.permutations(pins, 2)
for p in pinperms:
    print(f"bi_decl(bi_2pins_with_names({p[0]}, {p[1]}));")

pinperms = itertools.permutations(pins, 3)
for p in pinperms:
    print(f"bi_decl(bi_3pins_with_names({p[0]}, {p[1]}, {p[2]}));")

pinperms = itertools.permutations(pins, 4)
for p in pinperms:
    print(f"bi_decl(bi_4pins_with_names({p[0]}, {p[1]}, {p[2]}, {p[3]}));")
Alternative to #1791 - instead of asserting when the order is incorrect, reorder the names so they are in the correct order for the pin mask Requires more pre-processor stuff, but doesn't break existing code with the pins in the wrong order, so [pico-examples/524](https://github.com/raspberrypi/pico-examples/pull/524) would no longer be required Has been tested using the following python code to generate all permutations of `bi_decls` which are then copied and compiled into a binary, and then checked with `picotool info` to ensure pins are all named correctly ```python import itertools pins = [ 'PICO_DEFAULT_SPI_RX_PIN, "SPI RX"', 'PICO_DEFAULT_SPI_TX_PIN, "SPI TX"', 'PICO_DEFAULT_SPI_SCK_PIN, "SPI SCK"', 'PICO_DEFAULT_SPI_CSN_PIN, "SPI CS"' ] pinperms = itertools.permutations(pins, 2) for p in pinperms: print(f"bi_decl(bi_2pins_with_names({p[0]}, {p[1]}));") pinperms = itertools.permutations(pins, 3) for p in pinperms: print(f"bi_decl(bi_3pins_with_names({p[0]}, {p[1]}, {p[2]}));") pinperms = itertools.permutations(pins, 4) for p in pinperms: print(f"bi_decl(bi_4pins_with_names({p[0]}, {p[1]}, {p[2]}, {p[3]}));") ```
lurch (Migrated from github.com) reviewed 2024-08-21 09:08:02 -05:00
lurch commented 2024-08-21 10:48:49 -05:00 (Migrated from github.com)

ZOMG! 🤯 As long as you've tested this, I'll assume it's okay 😉

Although I guess your tests could be simplified to use e.g. pinperms = itertools.permutations(pins[:2], 2) instead?

ZOMG! :exploding_head: As long as you've tested this, I'll assume it's okay :wink: Although I guess your tests could be simplified to use e.g. `pinperms = itertools.permutations(pins[:2], 2)` instead?
kilograham commented 2024-08-21 11:35:26 -05:00 (Migrated from github.com)

Yeah, it is a bit scary; i was wondering if we should do a recursive implementation, but

  1. that means splitting out a separate macro for the string part
  2. I don't know that it is significantly simpler

So unless anyone has any fantastic ideas i say we take this as is ;-)

Yeah, it is a bit scary; i was wondering if we should do a recursive implementation, but 1. that means splitting out a separate macro for the string part 2. I don't know that it is significantly simpler So unless anyone has any fantastic ideas i say we take this as is ;-)
lurch commented 2024-08-21 11:59:29 -05:00 (Migrated from github.com)

So unless anyone has any fantastic ideas i say we take this as is ;-)

https://github.com/svpv/qsort 🤣

> So unless anyone has any fantastic ideas i say we take this as is ;-) https://github.com/svpv/qsort :rofl:
kilograham (Migrated from github.com) approved these changes 2024-08-22 11:56:09 -05:00
kilograham (Migrated from github.com) left a comment

I'm gonna believe you!

I'm gonna believe you!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!1858
No description provided.