You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SPI::_owner = NULL; // Not that elegant, but works. rmeyer
47
-
aquire();
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
+
}
48
54
unlock();
49
55
}
50
56
51
57
voidSPI::frequency(int hz) {
52
58
lock();
53
59
_hz = hz;
54
-
SPI::_owner = NULL; // Not that elegant, but works. rmeyer
55
-
aquire();
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
+
}
56
68
unlock();
57
69
}
58
70
@@ -70,17 +82,26 @@ void SPI::aquire() {
70
82
unlock();
71
83
}
72
84
85
+
// Note: Private function with no locking
86
+
voidSPI::_acquire() {
87
+
if (_owner != this) {
88
+
spi_format(&_spi, _bits, _mode, 0);
89
+
spi_frequency(&_spi, _hz);
90
+
_owner = this;
91
+
}
92
+
}
93
+
73
94
intSPI::write(int value) {
74
95
lock();
75
-
aquire();
96
+
_acquire();
76
97
int ret = spi_master_write(&_spi, value);
77
98
unlock();
78
99
return ret;
79
100
}
80
101
81
102
intSPI::write(constchar *tx_buffer, int tx_length, char *rx_buffer, int rx_length) {
82
103
lock();
83
-
aquire();
104
+
_acquire();
84
105
int ret = spi_master_block_write(&_spi, tx_buffer, tx_length, rx_buffer, rx_length);
85
106
unlock();
86
107
return ret;
@@ -167,7 +188,7 @@ int SPI::queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, i
167
188
168
189
voidSPI::start_transfer(constvoid *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsignedchar bit_width, constevent_callback_t& callback, int event)
0 commit comments