Pages: [1]   Go Down
Author Topic: Suggestions for SPI api  (Read 360 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 9
Posts: 116
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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:
Code:
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)
 
3. What about two macro's:
for sam:
 
Code:
#define SPI_CLOCK_MIN 1
#define SPI_CLOCK_MAX 255
for avr:
 
Code:
#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.


Logged

Pages: [1]   Go Up
Jump to: