Suggestions for SPI api

I noticed one is working on the SPI api's. I thought this is the moment to post some remarks.

  1. Both SPI begin() api's, reset the data mode, bit order and divider to their defaults. This invalidates any previous calls to setDataMode(), setBitOrder() and setClockDivider(). The doc does not state that you should call these setters after begin(), and that would be counter intuitive too. Also there is avr code out there that calls the setters before begin(). Better would be to have begin() set data mode and friends from the values recorded in the mode[], ... data fields. (and initialize these correctly).

  2. I find the following a bit counter intuitive:

 static const uint8_t SS   = BOARD_SPI_SS0;

I relate the names MISO, MOSI and SCK to SS and therefore I would expect that e.g. SPI.setBitorder(SS, order) is the as SPI.setBitOrder(order), which is not the case.

I would suggest this:

static const uint8_t SS0   = BOARD_SPI_SS0;
static const uint8_t SS  = BOARD_SPI_DEFAULT_SS ;

(I know it would break some sketches, but now it can still be changed)

  1. What about two macro's:
    for sam:
#define SPI_CLOCK_MIN 1
#define SPI_CLOCK_MAX 255

for avr:

#define SPI_CLOCK_MIN SPI_CLOCK_DIV4
#define SPI_CLOCK_MAX SPI_CLOCK_DIV128

Nothing world shocking but a sketch that just wants to be conservative could use SPI_CLOCK_MAX ant that would compile for sam and avr.