diff options
author | Damien George <damien.p.george@gmail.com> | 2014-09-30 22:26:59 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-09-30 22:36:47 +0100 |
commit | bfa7b480a7a537fc5496c8d9ffbf560f3a02314d (patch) | |
tree | 2b43899291c8b95c69fac45aed09f6fccbcc511f | |
parent | 8b03d944e2ae64f7987116ff342fbd1cc3b97b71 (diff) | |
download | micropython-bfa7b480a7a537fc5496c8d9ffbf560f3a02314d.tar.gz micropython-bfa7b480a7a537fc5496c8d9ffbf560f3a02314d.zip |
stmhal: For spi_init, add argument to select if NSS pin is enabled.
Most of the time you don't use the NSS pin of the SPI bus, and so it
shouldn't be enabled by default (this gave some bugs in the past).
-rw-r--r-- | drivers/cc3000/src/ccspi.c | 2 | ||||
-rw-r--r-- | stmhal/lcd.c | 2 | ||||
-rw-r--r-- | stmhal/spi.c | 6 | ||||
-rw-r--r-- | stmhal/spi.h | 2 |
4 files changed, 6 insertions, 6 deletions
diff --git a/drivers/cc3000/src/ccspi.c b/drivers/cc3000/src/ccspi.c index 2abc637fee..81ea5628df 100644 --- a/drivers/cc3000/src/ccspi.c +++ b/drivers/cc3000/src/ccspi.c @@ -153,7 +153,7 @@ void SpiOpen(gcSpiHandleRx pfRxHandler) SPI_HANDLE->Init.TIMode = SPI_TIMODE_DISABLED; SPI_HANDLE->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; SPI_HANDLE->Init.CRCPolynomial = 7; - spi_init(SPI_HANDLE); + spi_init(SPI_HANDLE, false); // configure wlan CS and EN pins GPIO_InitTypeDef GPIO_InitStructure; diff --git a/stmhal/lcd.c b/stmhal/lcd.c index ea7699be7d..a47fffcd94 100644 --- a/stmhal/lcd.c +++ b/stmhal/lcd.c @@ -263,7 +263,7 @@ STATIC mp_obj_t pyb_lcd_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n init->CRCPolynomial = 0; // init the SPI bus - spi_init(lcd->spi); + spi_init(lcd->spi, false); // set the pins to default values lcd->pin_cs1->gpio->BSRRL = lcd->pin_cs1->pin_mask; diff --git a/stmhal/spi.c b/stmhal/spi.c index 0b825ce1df..007f22daf8 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -86,7 +86,7 @@ void spi_init0(void) { } // TODO allow to take a list of pins to use -void spi_init(SPI_HandleTypeDef *spi) { +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; @@ -130,7 +130,7 @@ void spi_init(SPI_HandleTypeDef *spi) { return; } - for (uint i = 0; i < 4; i++) { + for (uint i = (enable_nss_pin ? 0 : 1); i < 4; i++) { GPIO_InitStructure.Pin = pins[i]->pin_mask; HAL_GPIO_Init(pins[i]->gpio, &GPIO_InitStructure); } @@ -297,7 +297,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args, } // init the SPI bus - spi_init(self->spi); + spi_init(self->spi, init->NSS != SPI_NSS_SOFT); return mp_const_none; } diff --git a/stmhal/spi.h b/stmhal/spi.h index 1f6e7e7b2d..9f81552525 100644 --- a/stmhal/spi.h +++ b/stmhal/spi.h @@ -30,5 +30,5 @@ extern SPI_HandleTypeDef SPIHandle3; extern const mp_obj_type_t pyb_spi_type; void spi_init0(void); -void spi_init(SPI_HandleTypeDef *spi); +void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin); SPI_HandleTypeDef *spi_get_handle(mp_obj_t o); |