1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #17531 from fjmolinas/pr_spi_gpio_init_reference

drivers/periph_spi: spi_init_with_gpio_mode mode by reference
This commit is contained in:
Alexandre Abadie 2022-01-18 18:44:54 +01:00 committed by GitHub
commit 5e599a82dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -192,7 +192,7 @@ int spi_init_cs(spi_t bus, spi_cs_t cs)
}
#ifdef MODULE_PERIPH_SPI_GPIO_MODE
int spi_init_with_gpio_mode(spi_t bus, spi_gpio_mode_t mode)
int spi_init_with_gpio_mode(spi_t bus, const spi_gpio_mode_t* mode)
{
assert(bus < SPI_NUMOF);
@ -203,17 +203,17 @@ int spi_init_with_gpio_mode(spi_t bus, spi_gpio_mode_t mode)
return ret;
#else
if (gpio_is_valid(spi_config[bus].mosi_pin)) {
ret += gpio_init(spi_config[bus].mosi_pin, mode.mosi);
ret += gpio_init(spi_config[bus].mosi_pin, mode->mosi);
gpio_init_af(spi_config[bus].mosi_pin, spi_config[bus].mosi_af);
}
if (gpio_is_valid(spi_config[bus].miso_pin)) {
ret += gpio_init(spi_config[bus].miso_pin, mode.miso);
ret += gpio_init(spi_config[bus].miso_pin, mode->miso);
gpio_init_af(spi_config[bus].miso_pin, spi_config[bus].miso_af);
}
if (gpio_is_valid(spi_config[bus].sclk_pin)) {
ret += gpio_init(spi_config[bus].sclk_pin, mode.sclk);
ret += gpio_init(spi_config[bus].sclk_pin, mode->sclk);
gpio_init_af(spi_config[bus].sclk_pin, spi_config[bus].sclk_af);
}
return ret;

View File

@ -324,12 +324,13 @@ typedef struct {
* @brief Initialize MOSI/MISO/SCLK pins with adapted GPIO modes
*
* @param[in] bus SPI device that is used with the given CS line
* @param[in] mode a struct containing the 3 modes to use on each pin
* @param[in] mode a pointer to a truct containing the 3 modes to use on
* each pin
*
* @retval 0 success
* @retval <0 error
*/
int spi_init_with_gpio_mode(spi_t bus, spi_gpio_mode_t mode);
int spi_init_with_gpio_mode(spi_t bus, const spi_gpio_mode_t* mode);
#endif
/**

View File

@ -350,7 +350,7 @@ static int _init_spi(sx127x_t *dev)
.miso = (SX127X_DIO_PULL_MODE),
.sclk = (GPIO_OUT | SX127X_DIO_PULL_MODE),
};
res += spi_init_with_gpio_mode(dev->params.spi, gpio_modes);
res += spi_init_with_gpio_mode(dev->params.spi, &gpio_modes);
#endif
if (res != SPI_OK) {