@@ -163,7 +163,7 @@ void SPIClass::setClockDivider(uint8_t divider)
163
163
*/
164
164
uint8_t SPIClass::transfer (uint8_t data, bool skipReceive)
165
165
{
166
- spi_transfer (&_spi, &data, sizeof ( uint8_t ), skipReceive );
166
+ spi_transfer (&_spi, &data, (!skipReceive) ? &data : NULL , sizeof ( uint8_t ) );
167
167
return data;
168
168
}
169
169
@@ -184,7 +184,7 @@ uint16_t SPIClass::transfer16(uint16_t data, bool skipReceive)
184
184
tmp = ((data & 0xff00 ) >> 8 ) | ((data & 0xff ) << 8 );
185
185
data = tmp;
186
186
}
187
- spi_transfer (&_spi, (uint8_t *)&data, sizeof ( uint16_t ), skipReceive );
187
+ spi_transfer (&_spi, (uint8_t *)&data, (!skipReceive) ? ( uint8_t *)&data : NULL , sizeof ( uint16_t ) );
188
188
189
189
if (_spiSettings.bitOrder ) {
190
190
tmp = ((data & 0xff00 ) >> 8 ) | ((data & 0xff ) << 8 );
@@ -206,11 +206,33 @@ uint16_t SPIClass::transfer16(uint16_t data, bool skipReceive)
206
206
*/
207
207
void SPIClass::transfer (void *buf, size_t count, bool skipReceive)
208
208
{
209
- if ((count != 0 ) && (buf != NULL )) {
210
- spi_transfer (&_spi, ((uint8_t *)buf), count, skipReceive);
209
+ spi_transfer (&_spi, (uint8_t *)buf, (!skipReceive) ? (uint8_t *)buf : NULL , count);
210
+
211
+ }
212
+
213
+ /* *
214
+ * @brief Transfer several bytes. One constant buffer used to send and
215
+ * one to receive data.
216
+ * begin() or beginTransaction() must be called at least once before.
217
+ * @param tx_buf: array of Tx bytes that is filled by the user before starting
218
+ * the SPI transfer. If NULL, default dummy 0xFF bytes will be
219
+ * clocked out.
220
+ * @param rx_buf: array of Rx bytes that will be filled by the slave during
221
+ * the SPI transfer. If NULL, the received data will be discarded.
222
+ * @param count: number of bytes to send/receive.
223
+ */
224
+ void SPIClass::transfer (const void *tx_buf, void *rx_buf, size_t count)
225
+ {
226
+ if (tx_buf) {
227
+ spi_transfer (&_spi, ((const uint8_t *)tx_buf), ((uint8_t *)rx_buf), count);
228
+ } else {
229
+ uint8_t dummy_buf[count];
230
+ memset (dummy_buf, 0XFF , count);
231
+ spi_transfer (&_spi, dummy_buf, ((uint8_t *)rx_buf), count);
211
232
}
212
233
}
213
234
235
+
214
236
/* *
215
237
* @brief Not implemented.
216
238
*/
0 commit comments