2013-11-01 23:48:39 +01:00
|
|
|
#pragma once
|
2023-04-13 13:32:04 +02:00
|
|
|
#include "HyperionConfig.h"
|
2013-11-01 23:48:39 +01:00
|
|
|
|
2023-04-13 13:32:04 +02:00
|
|
|
#ifdef ENABLE_DEV_SPI
|
|
|
|
// Linux-SPI includes
|
|
|
|
#include <linux/spi/spidev.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_DEV_FTDI
|
|
|
|
#include <ftdi.h>
|
|
|
|
#endif
|
2013-11-01 23:48:39 +01:00
|
|
|
|
|
|
|
// Hyperion includes
|
2013-12-17 19:50:15 +01:00
|
|
|
#include <leddevice/LedDevice.h>
|
2013-11-01 23:48:39 +01:00
|
|
|
|
2023-04-13 13:32:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
enum SpiImplementation { SPIDEV, FTDI };
|
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
/// The ProviderSpi implements an abstract base-class for LedDevices using the SPI-device.
|
2013-11-01 23:48:39 +01:00
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
class ProviderSpi : public LedDevice
|
2013-11-01 23:48:39 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
2016-08-23 20:07:12 +02:00
|
|
|
/// Constructs specific LedDevice
|
2013-11-01 23:48:39 +01:00
|
|
|
///
|
2020-08-08 00:21:19 +02:00
|
|
|
ProviderSpi(const QJsonObject &deviceConfig);
|
2016-08-13 19:54:08 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
2020-08-08 23:12:43 +02:00
|
|
|
bool init(const QJsonObject &deviceConfig) override;
|
2013-11-01 23:48:39 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Destructor of the LedDevice; closes the output device if it is open
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
~ProviderSpi() override;
|
2013-11-01 23:48:39 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Opens and configures the output device
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int open() override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2021-04-24 19:37:29 +02:00
|
|
|
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
|
|
|
///
|
|
|
|
/// @return A JSON structure holding a list of devices found
|
|
|
|
///
|
|
|
|
QJsonObject discover(const QJsonObject& params) override;
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
public slots:
|
|
|
|
///
|
|
|
|
/// Closes the output device.
|
|
|
|
/// Includes switching-off the device and stopping refreshes
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int close() override;
|
2013-11-01 23:48:39 +01:00
|
|
|
|
2013-11-02 06:51:41 +01:00
|
|
|
protected:
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
|
|
|
/// Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the
|
|
|
|
/// values are latched.
|
|
|
|
///
|
|
|
|
/// @param[in[ size The length of the data
|
|
|
|
/// @param[in] data The data
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success, else negative
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
int writeBytes(unsigned size, const uint8_t *data);
|
2013-11-02 06:51:41 +01:00
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
/// The name of the output device
|
2017-03-04 22:17:42 +01:00
|
|
|
QString _deviceName;
|
2016-08-14 10:46:44 +02:00
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
/// The used baudrate of the output device
|
2016-08-23 20:07:12 +02:00
|
|
|
int _baudRate_Hz;
|
2023-04-13 13:32:04 +02:00
|
|
|
#ifdef ENABLE_DEV_SPI
|
2013-11-01 23:48:39 +01:00
|
|
|
/// The File Identifier of the opened output device (or -1 if not opened)
|
2016-08-14 10:46:44 +02:00
|
|
|
int _fid;
|
2016-08-13 19:54:08 +02:00
|
|
|
|
|
|
|
/// which spi clock mode do we use? (0..3)
|
2016-08-14 10:46:44 +02:00
|
|
|
int _spiMode;
|
2016-08-13 19:54:08 +02:00
|
|
|
|
|
|
|
/// 1=>invert the data pattern
|
2016-08-14 10:46:44 +02:00
|
|
|
bool _spiDataInvert;
|
2016-08-13 19:54:08 +02:00
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
/// The transfer structure for writing to the spi-device
|
2016-08-14 10:46:44 +02:00
|
|
|
spi_ioc_transfer _spi;
|
2023-04-13 13:32:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_DEV_FTDI
|
|
|
|
/// The Ftdi serial-device
|
|
|
|
struct ftdi_context *_ftdic;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SpiImplementation _spiImplementation;
|
2013-11-01 23:48:39 +01:00
|
|
|
};
|