@@ -163,7 +163,7 @@ void SPIClass::setClockDivider(uint8_t divider)
163163 */
164164uint8_t SPIClass::transfer (uint8_t data, bool skipReceive)
165165{
166- spi_transfer (&_spi, &data, sizeof ( uint8_t ), skipReceive );
166+ spi_transfer (&_spi, &data, (!skipReceive) ? &data : NULL , sizeof ( uint8_t ) );
167167 return data;
168168}
169169
@@ -184,7 +184,7 @@ uint16_t SPIClass::transfer16(uint16_t data, bool skipReceive)
184184 tmp = ((data & 0xff00 ) >> 8 ) | ((data & 0xff ) << 8 );
185185 data = tmp;
186186 }
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 ) );
188188
189189 if (_spiSettings.bitOrder ) {
190190 tmp = ((data & 0xff00 ) >> 8 ) | ((data & 0xff ) << 8 );
@@ -206,11 +206,33 @@ uint16_t SPIClass::transfer16(uint16_t data, bool skipReceive)
206206 */
207207void SPIClass::transfer (void *buf, size_t count, bool skipReceive)
208208{
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);
211232 }
212233}
213234
235+
214236/* *
215237 * @brief Not implemented.
216238 */
0 commit comments