DHCOM_HAL
Hardware-abstraction library (HAL) for multiple targets, including DHCOM modules
|
SPI master device class. The class covers communication with SPI slave devices from DHCOM. The reading and writing happens simultaneously - as the byte is shifted in from the bus, the other byte is shifted out to the bus. The class provides no protection from any simultaneous use of the same SPI port, normally this is done by linux kernel. More...
#include <SPI.h>
Public Types | |
enum | DEVICE { DEVICE_SPI1 = 1, DEVICE_SPI2 = 2 } |
SPI bus enumeration. More... | |
enum | CHIPSELECT { CS_0 = 0, CS_1 = 1, CS_2 = 2 } |
CS signal enumeration (in fact, only cs0 is supported by DHCOM hardware) More... | |
enum | MODE { MODE_0, MODE_1, MODE_2, MODE_3 } |
SPI mode enumeration. More... | |
Public Member Functions | |
SPI (DEVICE device, CHIPSELECT chipSelect) | |
Constructs the SPI device object. | |
~SPI () | |
Destructs the SPI device object, closing it if it was open. | |
STATUS | open () |
Opens the SPI device for I/O. | |
STATUS | close () |
Closes the SPI device. | |
bool | isOpen () const |
Checks if the SPI device is open. | |
STATUS | setCommParams (MODE mode, uint8_t bits, uint32_t freqHZ) |
Sets the communication parameters of the SPI device. | |
int | transceive (const uint8_t *outputBuffer, uint8_t *inputBuffer, uint32_t count, STATUS *status=NULL) |
Provides two-way communication over SPI. | |
SPI master device class. The class covers communication with SPI slave devices from DHCOM. The reading and writing happens simultaneously - as the byte is shifted in from the bus, the other byte is shifted out to the bus. The class provides no protection from any simultaneous use of the same SPI port, normally this is done by linux kernel.
enum dhcom::SPI::DEVICE |
SPI bus enumeration.
enum dhcom::SPI::MODE |
SPI mode enumeration.
dhcom::SPI::SPI | ( | SPI::DEVICE | device, |
SPI::CHIPSELECT | chipSelect | ||
) |
dhcom::SPI::~SPI | ( | ) |
Destructs the SPI device object, closing it if it was open.
bool dhcom::SPI::isOpen | ( | ) | const |
Checks if the SPI device is open.
STATUS dhcom::SPI::open | ( | ) |
Opens the SPI device for I/O.
Sets the communication parameters of the SPI device.
mode | - the mode of the spi communication, which determines the rules about the phase and polarity of the CLK signal. |
bits | - the number of bits in the SPI word. |
freqHZ | - frequency of SPI communication (in Hertz) This call also implicitly sets the MSb to come first. |
int dhcom::SPI::transceive | ( | const uint8_t * | outputBuffer, |
uint8_t * | inputBuffer, | ||
uint32_t | count, | ||
STATUS * | status = NULL |
||
) |
Provides two-way communication over SPI.
outputBuffer | - the buffer from which the data is taken to be sent. |
inputBuffer | - the buffer into which the incoming data is received. |
count | - the number of bytes in the buffers. |
status | - if NULL, status is not returned, otherwise may be set to STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_WRITE_FAILED or STATUS_SUCCESS. |