Files
pip/libs/main/io_devices/pispi.h
Бычков Андрей d13e68c206 threadedRead now const uchar *
pipacketextractor Header mode now more flexible
fix splitTime mode
more refactoring
add virtual override to functions
remove piforeach
replace 0 to nullptr
iterate over pimap via iterators
replace CONNECTU to CONNECT# with compile time check
2022-07-26 17:18:08 +03:00

86 lines
2.6 KiB
C++

/*! \file pispi.h
* \ingroup IO
* \~\brief
* \~english SPI device
* \~russian Устройство SPI
*/
/*
PIP - Platform Independent Primitives
SPI
Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PISPI_H
#define PISPI_H
#include "piiodevice.h"
class PIP_EXPORT PISPI: public PIIODevice
{
PIIODEVICE(PISPI, "spi");
public:
explicit PISPI(const PIString & path = PIString(), uint speed_hz = 1000000, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
virtual ~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:
virtual bool openDevice() override;
virtual bool closeDevice() override;
virtual int readDevice(void * read_to, int max_size) override;
virtual int writeDevice(const void * data, int max_size) override;
virtual PIString constructFullPathDevice() const override;
virtual void configureFromFullPathDevice(const PIString & full_path) override;
virtual PIPropertyStorage constructVariantDevice() const override;
virtual void configureFromVariantDevice(const PIPropertyStorage & d) override;
virtual DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential;}
private:
uint spi_speed;
uchar spi_mode;
uchar spi_bits;
PIByteArray tx_buf, rx_buf;
PIByteArray recv_buf;
PRIVATE_DECLARATION(PIP_EXPORT)
};
#endif // PISPI_H