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
_acquire() function added & no duplication in format/freq calls
1. Private _acquire() function is added to avoid multiple locking/unlocking
2. format and frequency functions updated to use appropriate function calls
instead of a aquire()
SPI::_owner = NULL; // Not that elegant, but works. rmeyer
47
-
aquire();
46
+
spi_format(&_spi, _bits, _mode, 0);
47
+
_owner = this;
48
48
unlock();
49
49
}
50
50
51
51
voidSPI::frequency(int hz) {
52
52
lock();
53
53
_hz = hz;
54
-
SPI::_owner = NULL; // Not that elegant, but works. rmeyer
55
-
aquire();
54
+
spi_frequency(&_spi, _hz);
55
+
_owner = this;
56
56
unlock();
57
57
}
58
58
@@ -70,17 +70,26 @@ void SPI::aquire() {
70
70
unlock();
71
71
}
72
72
73
+
// Note: Private function with no locking
74
+
voidSPI::_acquire() {
75
+
if (_owner != this) {
76
+
spi_format(&_spi, _bits, _mode, 0);
77
+
spi_frequency(&_spi, _hz);
78
+
_owner = this;
79
+
}
80
+
}
81
+
73
82
intSPI::write(int value) {
74
83
lock();
75
-
aquire();
84
+
_acquire();
76
85
int ret = spi_master_write(&_spi, value);
77
86
unlock();
78
87
return ret;
79
88
}
80
89
81
90
intSPI::write(constchar *tx_buffer, int tx_length, char *rx_buffer, int rx_length) {
82
91
lock();
83
-
aquire();
92
+
_acquire();
84
93
int ret = spi_master_block_write(&_spi, tx_buffer, tx_length, rx_buffer, rx_length);
85
94
unlock();
86
95
return ret;
@@ -167,7 +176,7 @@ int SPI::queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, i
167
176
168
177
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