adafruit / Adafruit_NeoPixel_ZeroDMA

DMA-based NeoPixel library for SAMD microcontrollers (Feather M0, M4, Arduino Zero, etc.)
MIT License
39 stars 13 forks source link

Free PIN selection #1

Closed Adminius closed 6 years ago

Adminius commented 6 years ago

Hi, first of all, i know what you mean with:

/ This table contains the available pins and their corresponding SERCOMs and DMA-related registers and such. M0 can actually handle SPI DMA on more pins than are indicated here, but the code design INTENTIONALLY limits it to specific pins. This is not a technical limit, but a documentation issue. There are usually multiple pins available for each SERCOM, but each SERCOM can have only one active MOSI pin. Rather than try to document "If you use in X, then pins Y and Z can't be used" (and repeating this explanation for up to four SERCOMs, and that the specific pins can vary for each board), it's 10,000X SIMPLER to explain and use if one specific pin has been preselected for each SERCOM. I tried to pick pins that are nicely spaced around the board and don't knock out other vital peripherals. SERCOM pin selection is NOT a fun process, believe me, it's much easier this way... /

SERCOM <> PIN-relations described here: https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-spi

is it possible to add a new constructor(?) (for experienced user) with sercom and pin parameters, so user can define his own sercom/pin configuration?

e.g. instead of:

Adafruit_NeoPixel_ZeroDMA strip(NUM_PIXELS, PIN, NEO_GRB); something like that: Adafruit_NeoPixel_ZeroDMA strip(NUM_PIXELS, &sercom5, SERCOM5, SERCOM5_DMAC_ID_TX, A5, 6, 7, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT, NEO_GRB);

another possibility to define sercomTable[] in a user sketch instead of library and use it (pointer ?) for sercom-definition.

Another question: for example user uses A5 for MOSI, pins 6 and 7 are used for MISO and SCK, that also means, that user can't use pins 6 and 7 for other stuff (like digitalWrite), right?

ladyada commented 6 years ago

for the first question, probably not likely we'll add it but feel free to fork and do yourself :) for the second question, the other pins are free and unused, you just can't use them for the SERCOM

Adminius commented 6 years ago

@ladyada i've forked ;) i made a new line in sercomTable: &sercom4, SERCOM4, SERCOM4_DMAC_ID_TX, 22, 23, 24, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT, // pins 22 / 23 and the other stuff swapped. i need it in this way and it works like a charm

i can make a PR for this line. but i think it's better to do it in flexible way, so power users can easier do it, without to add a new line until next library update...

i see this ways of doing it: Adafruit_NeoPixel_ZeroDMA strip(NUM_PIXELS, &sercom5, SERCOM5, SERCOM5_DMAC_ID_TX, A5, 6, 7, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT, NEO_GRB);

or the normal Adafruit_NeoPixel_ZeroDMA strip(NUM_PIXELS, PIN, NEO_GRB); but Adafruit_NeoPixel::begin(*sercom, *sercomBase, dmacID, mosi, miso, sck, padTX, padRX, pinFunc);

I think the second one is better. should i do a PR for it? what are you prefer? copy-paste whole begin function https://github.com/adafruit/Adafruit_NeoPixel_ZeroDMA/blob/master/Adafruit_NeoPixel_ZeroDMA.cpp#L114-L175 or make an internalBegin() for selected stuff so that we don't have a copy-paste code?