diff --git a/boards/frdm-k22f/include/periph_conf.h b/boards/frdm-k22f/include/periph_conf.h index 7e9ea7aa6e..a4f5908887 100644 --- a/boards/frdm-k22f/include/periph_conf.h +++ b/boards/frdm-k22f/include/periph_conf.h @@ -241,9 +241,9 @@ static const spi_conf_t spi_config[] = { .pin_cs = { GPIO_PIN(PORT_C, 4), GPIO_PIN(PORT_D, 4), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI0_MASK diff --git a/boards/frdm-k64f/include/periph_conf.h b/boards/frdm-k64f/include/periph_conf.h index 3afa5c7e30..bc94d95423 100644 --- a/boards/frdm-k64f/include/periph_conf.h +++ b/boards/frdm-k64f/include/periph_conf.h @@ -237,10 +237,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_D, 1), .pin_cs = { GPIO_PIN(PORT_D, 0), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI0_MASK diff --git a/boards/frdm-kw41z/include/periph_conf.h b/boards/frdm-kw41z/include/periph_conf.h index ed054ea0b6..2d1f26c32f 100644 --- a/boards/frdm-kw41z/include/periph_conf.h +++ b/boards/frdm-kw41z/include/periph_conf.h @@ -40,10 +40,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_C, 16), .pin_cs = { GPIO_PIN(PORT_C, 19), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI0_MASK @@ -55,10 +55,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_A, 18), .pin_cs = { GPIO_PIN(PORT_A, 19), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI1_MASK diff --git a/boards/mulle/include/periph_conf.h b/boards/mulle/include/periph_conf.h index 303ddfd2c3..220ea1de7e 100644 --- a/boards/mulle/include/periph_conf.h +++ b/boards/mulle/include/periph_conf.h @@ -312,7 +312,7 @@ static const spi_conf_t spi_config[] = { GPIO_PIN(PORT_D, 4), GPIO_PIN(PORT_D, 5), GPIO_PIN(PORT_D, 6), - GPIO_UNDEF + SPI_CS_UNDEF, }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI0_MASK @@ -324,10 +324,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_E, 2), .pin_cs = { GPIO_PIN(PORT_E, 4), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI1_MASK diff --git a/boards/openlabs-kw41z-mini/include/periph_conf.h b/boards/openlabs-kw41z-mini/include/periph_conf.h index 3278c172bf..80df305cff 100644 --- a/boards/openlabs-kw41z-mini/include/periph_conf.h +++ b/boards/openlabs-kw41z-mini/include/periph_conf.h @@ -315,10 +315,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_C, 16), .pin_cs = { GPIO_PIN(PORT_C, 19), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, }, .pcr = (gpio_pcr_t)(GPIO_AF_2 | GPIO_IN_PU), .simmask = SIM_SCGC6_SPI0_MASK diff --git a/boards/pba-d-01-kw2x/include/periph_conf.h b/boards/pba-d-01-kw2x/include/periph_conf.h index 1466491b40..0bf510be48 100644 --- a/boards/pba-d-01-kw2x/include/periph_conf.h +++ b/boards/pba-d-01-kw2x/include/periph_conf.h @@ -223,10 +223,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_C, 5), .pin_cs = { GPIO_PIN(PORT_C, 4), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI0_MASK @@ -238,10 +238,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_B, 11), .pin_cs = { GPIO_PIN(PORT_B, 10), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI1_MASK diff --git a/boards/phynode-kw41z/include/periph_conf.h b/boards/phynode-kw41z/include/periph_conf.h index 9b4cbb037d..808f0623a6 100644 --- a/boards/phynode-kw41z/include/periph_conf.h +++ b/boards/phynode-kw41z/include/periph_conf.h @@ -42,10 +42,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_A, 18), .pin_cs = { GPIO_PIN(PORT_A, 19), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI1_MASK diff --git a/boards/usb-kw41z/include/periph_conf.h b/boards/usb-kw41z/include/periph_conf.h index c607b38394..46b09271e6 100644 --- a/boards/usb-kw41z/include/periph_conf.h +++ b/boards/usb-kw41z/include/periph_conf.h @@ -39,10 +39,10 @@ static const spi_conf_t spi_config[] = { .pin_clk = GPIO_PIN(PORT_A, 18), .pin_cs = { GPIO_PIN(PORT_A, 19), - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF, - GPIO_UNDEF + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, + SPI_CS_UNDEF, }, .pcr = GPIO_AF_2, .simmask = SIM_SCGC6_SPI1_MASK diff --git a/cpu/kinetis/include/periph_cpu.h b/cpu/kinetis/include/periph_cpu.h index 6cec6d6c23..5c17ab1824 100644 --- a/cpu/kinetis/include/periph_cpu.h +++ b/cpu/kinetis/include/periph_cpu.h @@ -115,6 +115,21 @@ typedef uint16_t gpio_t; */ #define SPI_HWCS_NUMOF (5) +/** + * @brief Define value for unused CS line + */ +#define SPI_CS_UNDEF (GPIO_UNDEF) + +#ifndef DOXYGEN +/** + * @brief Overwrite the default spi_cs_t type definition + * @{ + */ +#define HAVE_SPI_CS_T +typedef uint32_t spi_cs_t; +/** @} */ +#endif + /** * @name This CPU makes use of the following shared SPI functions * @{ @@ -454,7 +469,7 @@ typedef struct { gpio_t pin_miso; /**< MISO pin used */ gpio_t pin_mosi; /**< MOSI pin used */ gpio_t pin_clk; /**< CLK pin used */ - gpio_t pin_cs[SPI_HWCS_NUMOF]; /**< pins used for HW cs lines */ + spi_cs_t pin_cs[SPI_HWCS_NUMOF]; /**< pins used for HW cs lines */ #ifdef KINETIS_HAVE_PCR gpio_pcr_t pcr; /**< alternate pin function values */ #endif /* KINETIS_HAVE_PCR */ diff --git a/cpu/kinetis/periph/spi.c b/cpu/kinetis/periph/spi.c index 52da320b2f..193277f01d 100644 --- a/cpu/kinetis/periph/spi.c +++ b/cpu/kinetis/periph/spi.c @@ -30,6 +30,7 @@ #include "cpu.h" #include "mutex.h" +#include "periph/gpio.h" #include "periph/spi.h" #define ENABLE_DEBUG 0 @@ -135,8 +136,7 @@ int spi_init_cs(spi_t bus, spi_cs_t cs) gpio_init((gpio_t)cs, GPIO_OUT); } else { - if ((cs >= SPI_HWCS_NUMOF) || - (spi_config[bus].pin_cs[cs] == GPIO_UNDEF)) { + if ((cs >= SPI_HWCS_NUMOF) || !gpio_is_valid(spi_config[bus].pin_cs[cs])) { return SPI_NOCS; } gpio_init_port(spi_config[bus].pin_cs[cs], spi_config[bus].pcr);