Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "spi.h"
#include <string.h>

// Constructor
// Opens the SPI device and sets up some default values
Expand Down Expand Up @@ -97,13 +98,15 @@ uint16_t SPI::getDelayUsecs() {
// Transfer some data
bool SPI::transfer(uint8_t *tx, uint8_t *rx, int length) {
struct spi_ioc_transfer tr;


memset(&tr,0,sizeof(tr));
tr.tx_buf = (unsigned long)tx; //tx and rx MUST be the same length!
tr.rx_buf = (unsigned long)rx;
tr.len = length;
tr.delay_usecs = this->delay;
tr.speed_hz = this->speed;
tr.bits_per_word = this->bits;
tr.cs_change = 0;

int ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret == 1) {
Expand All @@ -116,4 +119,4 @@ bool SPI::transfer(uint8_t *tx, uint8_t *rx, int length) {
// Close the bus
void SPI::close() {
::close(this->fd);
}
}