Skip to content

Commit c0964e8

Browse files
committed
Update SPI.h - Add transfer_out
An alternative "output only" transfer that doesn't destroy the source buffer with the bytes returned from the slave device. Some code simplifications and const enforcement of input variables Tested in ATMEGA328p (UNO) * no speed changes noticed (comparing the the original function) * writing/reading to an SPI RAM returns the correct values
1 parent cd9a6ec commit c0964e8

File tree

1 file changed

+15
-0
lines changed
  • hardware/arduino/avr/libraries/SPI

1 file changed

+15
-0
lines changed

hardware/arduino/avr/libraries/SPI/SPI.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,21 @@ class SPIClass {
255255
while (!(SPSR & _BV(SPIF))) ;
256256
*p = SPDR;
257257
}
258+
/*
259+
* An alternative "output only" transfer that doesn't destroy the
260+
* contents of the source buffer with the bytes returned from the
261+
* slave device.
262+
* Some code simplifications and const enforcement
263+
* by Pedro Ribeiro pamribeirox@gmail.com
264+
*/
265+
inline static void transfer_out(const void *buf, size_t count) {
266+
if (count == 0) return;
267+
uint8_t *p = (uint8_t *)buf;
268+
while (count-- > 0) {
269+
SPDR = *p++;
270+
while (!(SPSR & _BV(SPIF))) ;
271+
}
272+
}
258273
// After performing a group of transfers and releasing the chip select
259274
// signal, this function allows others to access the SPI bus
260275
inline static void endTransaction(void) {

0 commit comments

Comments
 (0)