mraa  0.6.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Pages
Public Member Functions
Spi Class Reference

Detailed Description

This file defines the SPI interface for libmraa

mraa::Spi* spi;
spi = new mraa::Spi(0);
uint8_t data[] = {0x00, 100};
uint8_t rxBuf[2];
uint8_t *recv;
while (running == 0) {
int i;
for (i = 90; i < 130; i++) {
data[1] = i;
recv = spi->write(data, 2);
printf("Writing -%i",i);
if (recv) {
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
free(recv);
}
usleep(100000);
}
for (i = 130; i > 90; i--) {
data[1] = i;
if (spi->transfer(data, rxBuf, 2) == MRAA_SUCCESS) {
printf("Writing -%i",i);
printf("RECIVED-%i-%i\n",rxBuf[0],rxBuf[1]);
}
usleep(100000);
}
}
delete spi;

Public Member Functions

 Spi (int bus)
 
 ~Spi ()
 
mraa_result_t mode (Spi_Mode mode)
 
mraa_result_t frequency (int hz)
 
uint8_t writeByte (uint8_t data)
 
uint8_t * write (uint8_t *txBuf, int length)
 
mraa_result_t transfer (uint8_t *txBuf, uint8_t *rxBuf, int length)
 
mraa_result_t lsbmode (bool lsb)
 
mraa_result_t bitPerWord (unsigned int bits)
 

Constructor & Destructor Documentation

Spi ( int  bus)
inline

Initialise SPI object using the board mapping to set muxes

Parameters
busto use, as listed in the platform definition, normally 0

Here is the call graph for this function:

~Spi ( )
inline

Closes spi bus

Here is the call graph for this function:

Member Function Documentation

mraa_result_t mode ( Spi_Mode  mode)
inline

Set the SPI device mode. see spidev0-3

Parameters
modethe mode. See Linux spidev doc
Returns
Result of operation

Here is the call graph for this function:

mraa_result_t frequency ( int  hz)
inline

Set the SPI device operating clock frequency

Parameters
hzthe frequency to set in hz
Returns
Result of operation

Here is the call graph for this function:

uint8_t writeByte ( uint8_t  data)
inline

Write single byte to the SPI device

Parameters
datathe byte to send
Returns
data received on the miso line

Here is the call graph for this function:

uint8_t* write ( uint8_t *  txBuf,
int  length 
)
inline

Write buffer of bytes to SPI device The pointer return has to be free'd by the caller. It will return a NULL pointer in cases of error

@param txBuf buffer to send
@param length size of buffer to send
@return uint8_t* data received on the miso line. Same length as passed in

Here is the call graph for this function:

mraa_result_t transfer ( uint8_t *  txBuf,
uint8_t *  rxBuf,
int  length 
)
inline

Transfer data to and from SPI device Receive pointer may be null if return data is not needed.

Parameters
databuffer to send
rxBufbuffer to optionally receive data from spi device
lengthsize of buffer to send
Returns
Result of operation

Here is the call graph for this function:

mraa_result_t lsbmode ( bool  lsb)
inline

Change the SPI lsb mode

Parameters
lsbUse least significant bit transmission - 0 for msbi
Returns
Result of operation

Here is the call graph for this function:

mraa_result_t bitPerWord ( unsigned int  bits)
inline

Set bits per mode on transaction, default is 8

Parameters
bitsbits per word
Returns
Result of operation

Here is the call graph for this function:


The documentation for this class was generated from the following file: