Skip to content

Commit d22d8af

Browse files
author
Deepika
committed
Corrected handling of format/frequency
1 parent de89be3 commit d22d8af

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/SPI.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,28 @@ void SPI::format(int bits, int mode) {
4343
lock();
4444
_bits = bits;
4545
_mode = mode;
46-
spi_format(&_spi, _bits, _mode, 0);
47-
_owner = this;
46+
// If changing format while you are the owner than just
47+
// update format, but if owner is changed than even frequency should be
48+
// updated which is done by acquire.
49+
if (_owner == this) {
50+
spi_format(&_spi, _bits, _mode, 0);
51+
} else {
52+
_acquire();
53+
}
4854
unlock();
4955
}
5056

5157
void SPI::frequency(int hz) {
5258
lock();
5359
_hz = hz;
54-
spi_frequency(&_spi, _hz);
55-
_owner = this;
60+
// If changing format while you are the owner than just
61+
// update frequency, but if owner is changed than even frequency should be
62+
// updated which is done by acquire.
63+
if (_owner == this) {
64+
spi_frequency(&_spi, _hz);
65+
} else {
66+
_acquire();
67+
}
5668
unlock();
5769
}
5870

0 commit comments

Comments
 (0)