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 <cstring> // For memset()
26#include <array>
27
28//-------------------------------------------------------------------
29// Input specification: Button matrix
30//-------------------------------------------------------------------
31
36typedef std::map<OutputGPIO, std::map<InputGPIO, InputNumber>> ButtonMatrix;
37
47 ButtonMatrix &matrix,
48 const OutputGPIOCollection selectors,
50 const InputNumber first)
51{
52 uint8_t in = (uint8_t)first;
53 for (auto row : selectors)
54 for (auto col : inputs)
55 matrix[row][col] = in++;
56}
57
58//-------------------------------------------------------------------
59// Input specification: analog multiplexers
60//-------------------------------------------------------------------
61
67enum class Mux8Pin
68{
69 A0 = 0,
70 A1,
71 A2,
72 A3,
73 A4,
74 A5,
75 A6,
76 A7
77};
78
84enum class Mux16Pin
85{
86 I0 = 0,
87 I1,
88 I2,
89 I3,
90 I4,
91 I5,
92 I6,
93 I7,
94 I8,
95 I9,
96 I10,
97 I11,
98 I12,
99 I13,
100 I14,
101 I15,
102};
103
109enum class Mux32Pin
110{
111 S1 = 0,
112 S2,
113 S3,
114 S4,
115 S5,
116 S6,
117 S7,
118 S8,
119 S9,
120 S10,
121 S11,
122 S12,
123 S13,
124 S14,
125 S15,
126 S16,
127 S17,
128 S18,
129 S19,
130 S20,
131 S21,
132 S22,
133 S23,
134 S24,
135 S25,
136 S26,
137 S27,
138 S28,
139 S29,
140 S30,
141 S31,
142 S32
143};
144
150template <typename PinTags>
151struct AnalogMultiplexerChip : public std::map<PinTags, InputNumber>
152{
153public:
160 : std::map<PinTags, InputNumber>(), inputGPIO{inputPin} {}
161
168 {
169 inputGPIO.reserve();
170 for (auto i = this->begin(); i != this->end(); i++)
171 i->second.book();
172 }
173
179 inline InputGPIO getInputGPIO() { return inputGPIO; }
180
181private:
182 InputGPIO inputGPIO;
183};
184
190
196
202
208template <typename PinTags>
209using AnalogMultiplexerGroup = std::vector<AnalogMultiplexerChip<PinTags>>;
210
211//-------------------------------------------------------------------
212// Input specification: GPIO Expanders
213//-------------------------------------------------------------------
214
219enum class MCP23017Pin
220{
221 GPA0 = 0,
222 GPA1,
223 GPA2,
224 GPA3,
225 GPA4,
226 GPA5,
227 GPA6,
228 GPA7,
229 GPB0,
230 GPB1,
231 GPB2,
232 GPB3,
233 GPB4,
234 GPB5,
235 GPB6,
236 GPB7
237};
238
243enum class PCF8574Pin
244{
245 P0 = 0,
246 P1,
247 P2,
248 P3,
249 P4,
250 P5,
251 P6,
252 P7
253};
254
260template <typename PinTags>
261using GPIOExpanderChip = std::map<PinTags, InputNumber>;
262
268
274
275//-------------------------------------------------------------------
276// Input specification: PISO Shift registers
277//-------------------------------------------------------------------
278
283enum class SR8Pin
284{
285 H = 0,
286 G,
287 F,
288 E,
289 D,
290 C,
291 B,
292 A
293};
294
299typedef std::map<SR8Pin, InputNumber> ShiftRegisterChip;
300
310typedef std::vector<ShiftRegisterChip> ShiftRegisterChain;
311
312//-------------------------------------------------------------------
313// Input specification: binary-coded switches
314//-------------------------------------------------------------------
315
321typedef std::map<uint8_t, InputNumber> RotaryCodedSwitch;
322
327typedef std::array<InputNumber, 8> CodedSwitch8;
328
333typedef std::array<InputNumber, 16> CodedSwitch16;
334
339typedef 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::map< uint8_t, InputNumber > RotaryCodedSwitch
Rotary coded switch.
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::vector< InputGPIO > InputGPIOCollection
Collection of input GPIOs.
std::vector< OutputGPIO > OutputGPIOCollection
Collection of output GPIOs.
Everything related to hardware inputs and their events.
Definition SimWheel.hpp:31
Generic analog multiplexer chip.
AnalogMultiplexerChip(InputGPIO inputPin)
Construct a new Analog Multiplexer Chip object.
void reserve_and_book()
Reserve the input pin and book all input numbers.
InputGPIO getInputGPIO()
Get the input GPIO pin.
void reserve() const
Reserve this GPIO for exclusive use.
Input-capable GPIO pin number.
Firmware-defined input numbers in the range [0,63] or unspecified.