22 #ifndef PLUGINS_SPI_SPIBACKEND_H_
23 #define PLUGINS_SPI_SPIBACKEND_H_
26 #include <ola/thread/Mutex.h>
27 #include <ola/thread/Thread.h>
31 #include "plugins/spi/SPIWriter.h"
47 virtual uint8_t *Checkout(uint8_t output,
unsigned int length) = 0;
48 virtual uint8_t *Checkout(uint8_t output,
50 unsigned int latch_bytes) = 0;
51 virtual void Commit(uint8_t output) = 0;
53 virtual string DevicePath()
const = 0;
55 virtual bool Init() = 0;
58 static const char SPI_DROP_VAR[];
59 static const char SPI_DROP_VAR_KEY[];
72 vector<uint8_t> gpio_pins;
82 uint8_t *Checkout(uint8_t output,
unsigned int length) {
83 return Checkout(output, length, 0);
86 uint8_t *Checkout(uint8_t output,
88 unsigned int latch_bytes);
89 void Commit(uint8_t output);
91 string DevicePath()
const {
return m_spi_writer->DevicePath(); }
101 m_write_pending(false),
107 ~OutputData() {
delete[] m_data; }
109 uint8_t *Resize(
unsigned int length);
110 void SetLatchBytes(
unsigned int latch_bytes);
112 bool IsPending()
const {
return m_write_pending; }
113 void ResetPending() { m_write_pending =
false; }
114 const uint8_t *GetData()
const {
return m_data; }
115 unsigned int Size()
const {
return m_size; }
117 OutputData& operator=(
const OutputData &other);
121 bool m_write_pending;
123 unsigned int m_actual_size;
124 unsigned int m_latch_bytes;
126 OutputData(
const OutputData&);
129 typedef vector<int> GPIOFds;
130 typedef vector<OutputData*> Outputs;
132 SPIWriterInterface *m_spi_writer;
134 const uint8_t m_output_count;
139 Outputs m_output_data;
143 const vector<uint8_t> m_gpio_pins;
144 vector<bool> m_gpio_pin_state;
146 void SetupOutputs(Outputs *outputs);
147 void WriteOutput(uint8_t output_id, OutputData *output);
172 explicit Options() : outputs(1), sync_output(0) {}
182 uint8_t *Checkout(uint8_t output,
unsigned int length) {
183 return Checkout(output, length, 0);
186 uint8_t *Checkout(uint8_t output,
188 unsigned int latch_bytes);
189 void Commit(uint8_t output);
191 string DevicePath()
const {
return m_spi_writer->DevicePath(); }
197 SPIWriterInterface *m_spi_writer;
201 bool m_write_pending;
204 const int16_t m_sync_output;
205 vector<unsigned int> m_output_sizes;
206 vector<unsigned int> m_latch_bytes;
208 unsigned int m_length;
209 unsigned int m_buffer_size;
222 uint8_t *Checkout(uint8_t output,
unsigned int length) {
223 return Checkout(output, length, 0);
226 uint8_t *Checkout(uint8_t output,
228 unsigned int latch_bytes);
230 void Commit(uint8_t output);
231 const uint8_t *GetData(uint8_t output,
unsigned int *length);
233 string DevicePath()
const {
return "/dev/test"; }
235 bool Init() {
return true; }
237 unsigned int Writes(uint8_t output)
const;
242 Output() : data(NULL), length(0), writes(0) {}
243 ~Output() {
delete[] data; }
250 typedef vector<Output*> Outputs;
256 #endif // PLUGINS_SPI_SPIBACKEND_H_