From 867df82ced7b8aecba30eb4f68f864d5613d601b Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 19 May 2020 17:07:11 +0200 Subject: [PATCH] tests/periph_spi: Expose default SPI CS pins Expose the option to use default cs pins defined as DEFAULT_SPI_CS_PORT and DEFAULT_SPI_CS_PIN. This is used if a wiring environment is already defined. CFLAGS can be used to define the CS pin from the environment provided allowing easier automation of tests. --- tests/periph_spi/README.md | 6 ++++++ tests/periph_spi/main.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tests/periph_spi/README.md b/tests/periph_spi/README.md index 543b51d09b..102adee3a5 100644 --- a/tests/periph_spi/README.md +++ b/tests/periph_spi/README.md @@ -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= -DDEFAULT_SPI_CS_PIN=" BOARD= make flash term` diff --git a/tests/periph_spi/main.c b/tests/periph_spi/main.c index 98f6b15930..d5163eaaf8 100644 --- a/tests/periph_spi/main.c +++ b/tests/periph_spi/main.c @@ -28,6 +28,20 @@ #include "shell.h" #include "periph/spi.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 */ @@ -83,8 +97,8 @@ int cmd_init(int argc, char **argv) { int dev, mode, clk, port, pin, tmp; - if (argc < 5) { - printf("usage: %s \n", argv[0]); + if (argc < 4) { + printf("usage: %s [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); @@ -142,8 +156,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"); }