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.
This commit is contained in:
parent
8d9cc3f7e6
commit
867df82ced
@ -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`
|
||||
|
||||
@ -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 <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);
|
||||
@ -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");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user