From bb3ef7995f37d905f20f2d9dc2f224c8fefaebb7 Mon Sep 17 00:00:00 2001 From: Deepika Date: Mon, 26 Jun 2017 14:34:13 -0500 Subject: [PATCH] Corrected handling of format/frequency --- drivers/SPI.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/SPI.cpp b/drivers/SPI.cpp index 50f4dffeb1..465594dcdd 100644 --- a/drivers/SPI.cpp +++ b/drivers/SPI.cpp @@ -43,16 +43,28 @@ void SPI::format(int bits, int mode) { lock(); _bits = bits; _mode = mode; - spi_format(&_spi, _bits, _mode, 0); - _owner = this; + // If changing format while you are the owner than just + // update format, but if owner is changed than even frequency should be + // updated which is done by acquire. + if (_owner == this) { + spi_format(&_spi, _bits, _mode, 0); + } else { + _acquire(); + } unlock(); } void SPI::frequency(int hz) { lock(); _hz = hz; - spi_frequency(&_spi, _hz); - _owner = this; + // If changing format while you are the owner than just + // update frequency, but if owner is changed than even frequency should be + // updated which is done by acquire. + if (_owner == this) { + spi_frequency(&_spi, _hz); + } else { + _acquire(); + } unlock(); }