Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SPIDevice.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * SPIDevice.h
17  * The SPI Device class
18  * Copyright (C) 2013 Simon Newton
19  */
20 
21 #ifndef PLUGINS_SPI_SPIDEVICE_H_
22 #define PLUGINS_SPI_SPIDEVICE_H_
23 
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "olad/Device.h"
29 #include "ola/io/SelectServer.h"
30 #include "ola/rdm/UIDAllocator.h"
31 #include "ola/rdm/UID.h"
32 #include "plugins/spi/SPIBackend.h"
33 #include "plugins/spi/SPIWriter.h"
34 
35 namespace ola {
36 namespace plugin {
37 namespace spi {
38 
39 using std::auto_ptr;
40 
41 class SPIDevice: public ola::Device {
42  public:
43  SPIDevice(class SPIPlugin *owner,
44  class Preferences *preferences,
45  class PluginAdaptor *plugin_adaptor,
46  const string &spi_device,
47  ola::rdm::UIDAllocator *uid_allocator);
48 
49  string DeviceId() const;
50 
51  bool AllowMultiPortPatching() const { return true; }
52 
53  protected:
54  bool StartHook();
55  void PrePortStop();
56 
57  private:
58  typedef std::vector<class SPIOutputPort*> SPIPorts;
59 
60  auto_ptr<SPIWriterInterface> m_writer;
61  auto_ptr<SPIBackendInterface> m_backend;
62  class Preferences *m_preferences;
63  class PluginAdaptor *m_plugin_adaptor;
64  SPIPorts m_spi_ports;
65  string m_spi_device_name;
66 
67  // Per device options
68  string SPIBackendKey() const;
69  string SPISpeedKey() const;
70  string SPICEKey() const;
71  string PortCountKey() const;
72  string SyncPortKey() const;
73  string GPIOPinKey() const;
74 
75  // Per port options
76  string PersonalityKey(uint8_t port) const;
77  string PixelCountKey(uint8_t port) const;
78  string StartAddressKey(uint8_t port) const;
79  string GetPortKey(const string &suffix, uint8_t port) const;
80 
81  void SetDefaults();
82  void PopulateHardwareBackendOptions(HardwareBackend::Options *options);
83  void PopulateSoftwareBackendOptions(SoftwareBackend::Options *options);
84  void PopulateWriterOptions(SPIWriter::Options *options);
85 
86  static const char SPI_DEVICE_NAME[];
87  static const char HARDWARE_BACKEND[];
88  static const char SOFTWARE_BACKEND[];
89  static const uint8_t MAX_GPIO_PIN = 25;
90 };
91 } // namespace spi
92 } // namespace plugin
93 } // namespace ola
94 #endif // PLUGINS_SPI_SPIDEVICE_H_