git-svn-id: svn://db.shs.com.ru/pip@632 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
59
src_main/io_devices/pispi.h
Normal file
59
src_main/io_devices/pispi.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef PISPI_H
|
||||
#define PISPI_H
|
||||
|
||||
#include "piiodevice.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PISPI: public PIIODevice
|
||||
{
|
||||
PIIODEVICE(PISPI)
|
||||
public:
|
||||
explicit PISPI(const PIString & path = PIString(), uint speed_hz = 1000000, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||
~PISPI() {}
|
||||
|
||||
//! \brief Parameters of PISPI
|
||||
enum Parameters {
|
||||
ClockInverse /*! SPI clk polarity control*/ = 0x1,
|
||||
ClockPhaseShift /*! SPI clk phase control */ = 0x2,
|
||||
};
|
||||
|
||||
void setSpeed(uint speed_hz);
|
||||
uint speed() const {return spi_speed;}
|
||||
|
||||
void setBits(uchar bits = 8);
|
||||
uchar bits() const {return spi_bits;}
|
||||
|
||||
//! Set parameters to "parameters_"
|
||||
void setParameters(PIFlags<PISPI::Parameters> parameters_) {spi_mode = (int)parameters_;}
|
||||
|
||||
//! Set parameter "parameter" to "on" state
|
||||
void setParameter(PISPI::Parameters parameter, bool on = true);
|
||||
|
||||
//! Returns if parameter "parameter" is set
|
||||
bool isParameterSet(PISPI::Parameters parameter) const;
|
||||
|
||||
//! Returns parameters
|
||||
PIFlags<PISPI::Parameters> parameters() const {return spi_mode;}
|
||||
|
||||
|
||||
protected:
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
int readDevice(void * read_to, int max_size);
|
||||
int writeDevice(const void * data, int max_size);
|
||||
|
||||
PIString fullPathPrefix() const {return PIStringAscii("spi");}
|
||||
PIString constructFullPathDevice() const;
|
||||
void configureFromFullPathDevice(const PIString & full_path);
|
||||
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;}
|
||||
|
||||
private:
|
||||
uint spi_speed;
|
||||
uchar spi_mode;
|
||||
uchar spi_bits;
|
||||
PIByteArray tx_buf, rx_buf;
|
||||
PIByteArray recv_buf;
|
||||
PRIVATE_DECLARATION
|
||||
};
|
||||
|
||||
#endif // PISPI_H
|
||||
Reference in New Issue
Block a user