Merge pull request #14102 from MrKevinWeiss/pr/test/spi/defaultcs

tests/periph_spi: Expose default SPI CS pins
This commit is contained in:
Koen Zandberg 2020-05-20 12:09:06 +02:00 committed by GitHub
commit ae88f1e079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View File

@ -6,3 +6,9 @@ as master or slave, and to send and receive data via SPI.
Background
==========
Test for the low-level SPI driver.
## Default SPI CS pin
To overwrite the optional default cs pin CFLAGS can be used:
`CFLAGS="-DDEFAULT_SPI_CS_PORT=<my_port_int> -DDEFAULT_SPI_CS_PIN=<my_pin_int>" BOARD=<my_board> make flash term`

View File

@ -30,6 +30,20 @@
#include "schedstatistics.h"
#include "thread.h"
/**
* @brief Default port number used for the CS pin if unassigned
*/
#ifndef DEFAULT_SPI_CS_PORT
#define DEFAULT_SPI_CS_PORT 0
#endif
/**
* @brief Default port number used for the CS pin if unassigned
*/
#ifndef DEFAULT_SPI_CS_PIN
#define DEFAULT_SPI_CS_PIN 0
#endif
/**
* @brief Some parameters used for benchmarking
*/
@ -106,8 +120,8 @@ int cmd_init(int argc, char **argv)
{
int dev, mode, clk, port, pin, tmp;
if (argc < 5) {
printf("usage: %s <dev> <mode> <clk> <cs port> <cs pin>\n", argv[0]);
if (argc < 4) {
printf("usage: %s <dev> <mode> <clk> [cs port] [cs pin]\n", argv[0]);
puts("\tdev:");
for (int i = 0; i < (int)SPI_NUMOF; i++) {
printf("\t\t%i: SPI_DEV(%i)\n", i, i);
@ -165,8 +179,20 @@ int cmd_init(int argc, char **argv)
}
/* parse chip select port and pin */
port = atoi(argv[4]);
pin = atoi(argv[5]);
if (argc > 5) {
pin = atoi(argv[5]);
}
else {
pin = DEFAULT_SPI_CS_PIN;
}
if (argc > 4) {
port = atoi(argv[4]);
}
else {
port = DEFAULT_SPI_CS_PORT;
}
if (pin < 0 || port < -1) {
puts("error: invalid CS port/pin combination specified");
}