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"
44 virtual uint8_t *Checkout(uint8_t output,
unsigned int length) = 0;
45 virtual uint8_t *Checkout(uint8_t output,
47 unsigned int latch_bytes) = 0;
48 virtual void Commit(uint8_t output) = 0;
50 virtual std::string DevicePath()
const = 0;
52 virtual bool Init() = 0;
55 static const char SPI_DROP_VAR[];
56 static const char SPI_DROP_VAR_KEY[];
69 std::vector<uint8_t> gpio_pins;
79 uint8_t *Checkout(uint8_t output,
unsigned int length) {
80 return Checkout(output, length, 0);
83 uint8_t *Checkout(uint8_t output,
85 unsigned int latch_bytes);
86 void Commit(uint8_t output);
88 std::string DevicePath()
const {
return m_spi_writer->DevicePath(); }
98 m_write_pending(false),
104 ~OutputData() {
delete[] m_data; }
106 uint8_t *Resize(
unsigned int length);
107 void SetLatchBytes(
unsigned int latch_bytes);
109 bool IsPending()
const {
return m_write_pending; }
110 void ResetPending() { m_write_pending =
false; }
111 const uint8_t *GetData()
const {
return m_data; }
112 unsigned int Size()
const {
return m_size; }
114 OutputData& operator=(
const OutputData &other);
118 bool m_write_pending;
120 unsigned int m_actual_size;
121 unsigned int m_latch_bytes;
123 OutputData(
const OutputData&);
126 typedef std::vector<int> GPIOFds;
127 typedef std::vector<OutputData*> Outputs;
129 SPIWriterInterface *m_spi_writer;
131 const uint8_t m_output_count;
136 Outputs m_output_data;
140 const std::vector<uint8_t> m_gpio_pins;
141 std::vector<bool> m_gpio_pin_state;
143 void SetupOutputs(Outputs *outputs);
144 void WriteOutput(uint8_t output_id, OutputData *output);
169 explicit Options() : outputs(1), sync_output(0) {}
179 uint8_t *Checkout(uint8_t output,
unsigned int length) {
180 return Checkout(output, length, 0);
183 uint8_t *Checkout(uint8_t output,
185 unsigned int latch_bytes);
186 void Commit(uint8_t output);
188 std::string DevicePath()
const {
return m_spi_writer->DevicePath(); }
194 SPIWriterInterface *m_spi_writer;
198 bool m_write_pending;
201 const int16_t m_sync_output;
202 std::vector<unsigned int> m_output_sizes;
203 std::vector<unsigned int> m_latch_bytes;
205 unsigned int m_length;
218 uint8_t *Checkout(uint8_t output,
unsigned int length) {
219 return Checkout(output, length, 0);
222 uint8_t *Checkout(uint8_t output,
224 unsigned int latch_bytes);
226 void Commit(uint8_t output);
227 const uint8_t *GetData(uint8_t output,
unsigned int *length);
229 std::string DevicePath()
const {
return "/dev/test"; }
231 bool Init() {
return true; }
233 unsigned int Writes(uint8_t output)
const;
238 Output() : data(NULL), length(0), writes(0) {}
239 ~Output() {
delete[] data; }
246 typedef std::vector<Output*> Outputs;
252 #endif // PLUGINS_SPI_SPIBACKEND_H_