DHCOM_HAL
Hardware-abstraction library (HAL) for multiple targets, including DHCOM modules
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions
dhcom::SPI Class Reference

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.
 

Detailed Description

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.

Member Enumeration Documentation

CS signal enumeration (in fact, only cs0 is supported by DHCOM hardware)

Enumerator:
CS_0 

Select spi slave 1.

CS_1 

Select spi slave 2.

CS_2 

Select spi slave 3.

SPI bus enumeration.

Enumerator:
DEVICE_SPI1 

SPI1 is used.

DEVICE_SPI2 

SPI2 is used.

SPI mode enumeration.

Enumerator:
MODE_0 
MODE_1 
MODE_2 
MODE_3 

Constructor & Destructor Documentation

dhcom::SPI::SPI ( SPI::DEVICE  device,
SPI::CHIPSELECT  chipSelect 
)

Constructs the SPI device object.

Parameters
device- the SPI bus device to open.
chipSelect- the slave chip select to use (on DHCOM must be 0 for any of the two SPI buses).
dhcom::SPI::~SPI ( )

Destructs the SPI device object, closing it if it was open.

Member Function Documentation

STATUS dhcom::SPI::close ( )

Closes the SPI device.

Returns
STATUS_SUCCESS.
bool dhcom::SPI::isOpen ( ) const

Checks if the SPI device is open.

Returns
true if the device is open.
STATUS dhcom::SPI::open ( )

Opens the SPI device for I/O.

Returns
can return STATUS_DEVICE_ALREADY_OPEN, STATUS_DEVICE_OPEN_FAILED or STATUS_SUCCESS.
STATUS dhcom::SPI::setCommParams ( SPI::MODE  mode,
uint8_t  bits,
uint32_t  freqHZ 
)

Sets the communication parameters of the SPI device.

Parameters
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.
Returns
can return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_CONFIG_FAILED or STATUS_SUCCESS.
int dhcom::SPI::transceive ( const uint8_t outputBuffer,
uint8_t inputBuffer,
uint32_t  count,
STATUS status = NULL 
)

Provides two-way communication over SPI.

Parameters
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.
Returns
the number of bytes done, or -1 for an error.

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