mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Cleanup SPI constructor and add destructor
_acquire() is not required in constructor, since we are not performing
any operation on SPI bus yet. Just initialize the pins/hw
Destructor is required to clear _owner else SPI format/frequency will not be
set if object is recreated. We do not free SPI bus, but init again in hardware
may or may not change frequency/format.
```
{
    SPI spi1(...);
    spi1.transfer(...);
}
{
    SPI spi1(...);
    spi1.transfer(...);
}
```
			
			
				pull/8090/head
			
			
		
							parent
							
								
									920db63453
								
							
						
					
					
						commit
						0a9ff20658
					
				| 
						 | 
				
			
			@ -41,9 +41,14 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
 | 
			
		|||
    _write_fill(SPI_FILL_CHAR)
 | 
			
		||||
{
 | 
			
		||||
    // No lock needed in the constructor
 | 
			
		||||
 | 
			
		||||
    spi_init(&_spi, mosi, miso, sclk, ssel);
 | 
			
		||||
    _acquire();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SPI::~SPI()
 | 
			
		||||
{
 | 
			
		||||
    if (_owner == this) {
 | 
			
		||||
        _owner = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SPI::format(int bits, int mode)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,6 +87,7 @@ public:
 | 
			
		|||
     *  @param ssel SPI chip select pin
 | 
			
		||||
     */
 | 
			
		||||
    SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel = NC);
 | 
			
		||||
    virtual ~SPI();
 | 
			
		||||
 | 
			
		||||
    /** Configure the data transmission format
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			@ -272,11 +273,6 @@ private:
 | 
			
		|||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    virtual ~SPI()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    spi_t _spi;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue