Open Lighting Architecture: plugins/spi/SPIWriter.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
SPIWriter.h
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * SPIWriter.h
17 * This writes data to a SPI device.
18 * Copyright (C) 2013 Simon Newton
19 */
20
21#ifndef PLUGINS_SPI_SPIWRITER_H_
22#define PLUGINS_SPI_SPIWRITER_H_
23
24#include <ola/ExportMap.h>
25#include <ola/thread/Mutex.h>
26#include <stdint.h>
27#include <string>
28
29namespace ola {
30namespace plugin {
31namespace spi {
32
36 class SPIWriterInterface {
37 public:
38 virtual ~SPIWriterInterface() {}
39
40 virtual std::string DevicePath() const = 0;
41 virtual bool Init() = 0;
42 virtual bool WriteSPIData(const uint8_t *data, unsigned int length) = 0;
43};
44
48 class SPIWriter : public SPIWriterInterface {
49 public:
53 struct Options {
54 uint32_t spi_speed;
55 bool cs_enable_high;
56
57 Options() : spi_speed(1000000), cs_enable_high(false) {}
58 };
59
60 SPIWriter(const std::string &spi_device, const Options &options,
61 ExportMap *export_map);
62 ~SPIWriter();
63
64 std::string DevicePath() const { return m_device_path; }
65
70 bool Init();
71
72 bool WriteSPIData(const uint8_t *data, unsigned int length);
73
74 private:
75 const std::string m_device_path;
76 const uint32_t m_spi_speed;
77 const bool m_cs_enable_high;
78 int m_fd;
79 UIntMap *m_error_map_var;
80 UIntMap *m_write_map_var;
81
82 static const uint8_t SPI_MODE;
83 static const uint8_t SPI_BITS_PER_WORD;
84 static const char SPI_DEVICE_KEY[];
85 static const char SPI_ERROR_VAR[];
86 static const char SPI_WRITE_VAR[];
87};
88} // namespace spi
89} // namespace plugin
90} // namespace ola
91#endif // PLUGINS_SPI_SPIWRITER_H_
ExportMap.h
Export variables on the http server.
ola::ExportMap
A container for the exported variables.
Definition ExportMap.h:324
ola::UIntMap
Definition ExportMap.h:242
ola::plugin::spi::SPIWriter::Init
bool Init()
Definition SPIWriter.cpp:76
ola::plugin::spi::SPIWriterInterface
Definition SPIWriter.h:36
ola::plugin::spi
Code for SPI devices.
ola::plugin
Code for supported devices and protocols.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::plugin::spi::SPIWriter::Options
Definition SPIWriter.h:53