SPI: Properly aquire peripheral in constructor

Prevent mismatch between _owner and peripheral configuration. In the previous
implementation, the following code would leave the peripheral in an inconsistent
state:

```
SPI spi1(...);      // _owner is NULL, peripheral config is 1
spi1.transfer(...); // _owner is 1, config is 1
SPI spi2(...);      // _owner is 1, config is 2
spi1.transfer(...)  // 1 thinks it still owns peripheral, doesn't reconfigure
```
pull/2092/head
Aksel Skauge Mellbye 2016-06-15 11:05:04 +01:00
parent 07958da38b
commit b09a87ffb8
1 changed files with 1 additions and 2 deletions

View File

@ -36,8 +36,7 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
// No lock needed in the constructor
spi_init(&_spi, mosi, miso, sclk, ssel);
spi_format(&_spi, _bits, _mode, 0);
spi_frequency(&_spi, _hz);
aquire();
}
void SPI::format(int bits, int mode) {