OpenSourceSimWheelESP32
Open-source wireless steering wheel/button box for ESP32 boards
Loading...
Searching...
No Matches
InputSpecification.hpp
Go to the documentation of this file.
1
14#pragma once
15
16//-------------------------------------------------------------------
17// Imports
18//-------------------------------------------------------------------
19
20#include "SimWheelTypes.hpp"
21#include <cstdint>
22#include <stdexcept>
23#include <vector>
24#include <map>
25#include <array>
26
27//-------------------------------------------------------------------
28// Input specification: Button matrix
29//-------------------------------------------------------------------
30
35typedef std::map<OutputGPIO, std::map<InputGPIO, InputNumber>> ButtonMatrix;
36
46 ButtonMatrix &matrix,
47 const OutputGPIOCollection selectors,
49 const InputNumber first)
50{
51 uint8_t in = (uint8_t)first;
52 for (auto row : selectors)
53 for (auto col : inputs)
54 matrix[row][col] = in++;
55}
56
57//-------------------------------------------------------------------
58// Input specification: analog multiplexers
59//-------------------------------------------------------------------
60
66enum class Mux8Pin
67{
68 A0 = 0,
69 A1,
70 A2,
71 A3,
72 A4,
73 A5,
74 A6,
75 A7
76};
77
83enum class Mux16Pin
84{
85 I0 = 0,
86 I1,
87 I2,
88 I3,
89 I4,
90 I5,
91 I6,
92 I7,
93 I8,
94 I9,
95 I10,
96 I11,
97 I12,
98 I13,
99 I14,
100 I15,
101};
102
108enum class Mux32Pin
109{
110 S1 = 0,
111 S2,
112 S3,
113 S4,
114 S5,
115 S6,
116 S7,
117 S8,
118 S9,
119 S10,
120 S11,
121 S12,
122 S13,
123 S14,
124 S15,
125 S16,
126 S17,
127 S18,
128 S19,
129 S20,
130 S21,
131 S22,
132 S23,
133 S24,
134 S25,
135 S26,
136 S27,
137 S28,
138 S29,
139 S30,
140 S31,
141 S32
142};
143
149template <typename PinTags>
150struct AnalogMultiplexerChip : public std::map<PinTags, InputNumber>
151{
152public:
159 : std::map<PinTags, InputNumber>(), inputGPIO{inputPin} {}
160
163
166
169
172
179 {
180 inputGPIO.reserve();
181 for (auto i = this->begin(); i != this->end(); i++)
182 i->second.book();
183 }
184
190 inline InputGPIO getInputGPIO() { return inputGPIO; }
191
192private:
193 InputGPIO inputGPIO;
194};
195
201
207
213
219template <typename PinTags>
220using AnalogMultiplexerGroup = std::vector<AnalogMultiplexerChip<PinTags>>;
221
222//-------------------------------------------------------------------
223// Input specification: GPIO Expanders
224//-------------------------------------------------------------------
225
230enum class MCP23017Pin
231{
232 GPA0 = 0,
233 GPA1,
234 GPA2,
235 GPA3,
236 GPA4,
237 GPA5,
238 GPA6,
239 GPA7,
240 GPB0,
241 GPB1,
242 GPB2,
243 GPB3,
244 GPB4,
245 GPB5,
246 GPB6,
247 GPB7
248};
249
254enum class PCF8574Pin
255{
256 P0 = 0,
257 P1,
258 P2,
259 P3,
260 P4,
261 P5,
262 P6,
263 P7
264};
265
271template <typename PinTags>
272using GPIOExpanderChip = std::map<PinTags, InputNumber>;
273
279
285
286//-------------------------------------------------------------------
287// Input specification: PISO Shift registers
288//-------------------------------------------------------------------
289
294enum class SR8Pin
295{
296 H = 0,
297 G,
298 F,
299 E,
300 D,
301 C,
302 B,
303 A
304};
305
310typedef std::map<SR8Pin, InputNumber> ShiftRegisterChip;
311
321typedef std::vector<ShiftRegisterChip> ShiftRegisterChain;
322
323//-------------------------------------------------------------------
324// Input specification: binary-coded switches
325//-------------------------------------------------------------------
326
331typedef std::array<InputNumber, 8> CodedSwitch8;
332
337typedef std::array<InputNumber, 16> CodedSwitch16;
338
343typedef std::array<InputNumber, 32> CodedSwitch32;
AnalogMultiplexerChip< Mux8Pin > AnalogMultiplexerChip8
8-channel analog multiplexer chip
std::map< PinTags, InputNumber > GPIOExpanderChip
Generic GPIO expander chip.
PCF8574Pin
MCP23017 pin tags for switches.
std::map< SR8Pin, InputNumber > ShiftRegisterChip
PISO shift register chip.
void populateButtonMatrix(ButtonMatrix &matrix, const OutputGPIOCollection selectors, const InputGPIOCollection inputs, const InputNumber first)
Populate a button matrix with sequential input numbers.
std::array< InputNumber, 32 > CodedSwitch32
Rotary coded switch up to 32 positions.
Mux16Pin
CD74HCx4067 pin tags for switches or any other 16-channel multiplexer.
Mux8Pin
74HC4051N pin tags for switches or any other 8-channel multiplexer
AnalogMultiplexerChip< Mux32Pin > AnalogMultiplexerChip32
32-channel analog multiplexer chip
GPIOExpanderChip< PCF8574Pin > PCF8574Expander
PCF8574 GPIO Expander for switches.
std::array< InputNumber, 8 > CodedSwitch8
Rotary coded switch up to 8 positions.
std::vector< AnalogMultiplexerChip< PinTags > > AnalogMultiplexerGroup
Group of analog multiplexer chips sharing the same selector pins.
MCP23017Pin
MCP23017 pin tags for switches.
SR8Pin
74HC165N pin tags for switches
std::vector< ShiftRegisterChip > ShiftRegisterChain
Chain of PISO shift registers for switches.
AnalogMultiplexerChip< Mux16Pin > AnalogMultiplexerChip16
16-channel analog multiplexer chip
Mux32Pin
ADG732 pin tags for switches or any other 32-channel multiplexer.
std::array< InputNumber, 16 > CodedSwitch16
Rotary coded switch up to 16 positions.
std::map< OutputGPIO, std::map< InputGPIO, InputNumber > > ButtonMatrix
Button matrix specification.
GPIOExpanderChip< MCP23017Pin > MCP23017Expander
MCP23017 GPIO Expander for switches.
Types and constants required for custom firmware setup.
std::set< InputGPIO > InputGPIOCollection
Collection of input GPIOs.
std::set< OutputGPIO > OutputGPIOCollection
Collection of output GPIOs.
Everything related to hardware inputs and their events.
Definition SimWheel.hpp:31
Generic analog multiplexer chip.
AnalogMultiplexerChip & operator=(AnalogMultiplexerChip &&)=default
Move-assignment (default)
AnalogMultiplexerChip(InputGPIO inputPin)
Construct a new Analog Multiplexer Chip object.
void reserve_and_book()
Reserve the input pin and book all input numbers.
AnalogMultiplexerChip(const AnalogMultiplexerChip &)=default
Copy constructor (default)
AnalogMultiplexerChip & operator=(const AnalogMultiplexerChip &)=default
Copy-assignment (default)
InputGPIO getInputGPIO()
Get the input GPIO pin.
AnalogMultiplexerChip(AnalogMultiplexerChip &&)=default
Move constructor (default)
void reserve() const
Reserve this GPIO for exclusive use.
Input-capable GPIO pin number.
Firmware-defined input numbers in the range [0,127] or unspecified.