summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/spi.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-11-11 17:53:45 +1100
committerDamien George <damien.p.george@gmail.com>2016-11-11 17:53:45 +1100
commit1375c52772ad4f07d4bce40bfa114a0f2f0e6cfc (patch)
tree12cb3458f2d09395d656d52d146d01fd8ad94099 /stmhal/spi.c
parent74fb5d6932c835f92c6985799e30ea28b6449705 (diff)
downloadmicropython-1375c52772ad4f07d4bce40bfa114a0f2f0e6cfc.tar.gz
micropython-1375c52772ad4f07d4bce40bfa114a0f2f0e6cfc.zip
stmhal: Rename mp_hal_pin_set_af to _config_alt, to simplify alt config.
This way the caller doesn't need to initialise a big GPIO_InitTypeDef struct, and HAL_GPIO_Init is no longer called.
Diffstat (limited to 'stmhal/spi.c')
-rw-r--r--stmhal/spi.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/stmhal/spi.c b/stmhal/spi.c
index e72810d287..12a261afbb 100644
--- a/stmhal/spi.c
+++ b/stmhal/spi.c
@@ -243,12 +243,6 @@ STATIC void spi_set_params(SPI_HandleTypeDef *spi, uint32_t prescale, int32_t ba
// TODO allow to take a list of pins to use
void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
- // init the GPIO lines
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
- GPIO_InitStructure.Pull = spi->Init.CLKPolarity == SPI_POLARITY_LOW ? GPIO_PULLDOWN : GPIO_PULLUP;
-
const pyb_spi_obj_t *self;
const pin_obj_t *pins[4];
pins[0] = NULL;
@@ -331,8 +325,11 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
return;
}
+ // init the GPIO lines
+ uint32_t mode = MP_HAL_PIN_MODE_ALT;
+ uint32_t pull = spi->Init.CLKPolarity == SPI_POLARITY_LOW ? MP_HAL_PIN_PULL_DOWN : MP_HAL_PIN_PULL_UP;
for (uint i = (enable_nss_pin && pins[0] ? 0 : 1); i < 4; i++) {
- mp_hal_pin_set_af(pins[i], &GPIO_InitStructure, AF_FN_SPI, (self - &pyb_spi_obj[0]) + 1);
+ mp_hal_pin_config_alt(pins[i], mode, pull, AF_FN_SPI, (self - &pyb_spi_obj[0]) + 1);
}
// init the SPI device