ClearCore Library
InputManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Teknic, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
32 #ifndef __INPUTMANAGER_H__
33 #define __INPUTMANAGER_H__
34 
35 #include "PeripheralRoute.h"
36 #include "SysConnectors.h"
37 
38 namespace ClearCore {
39 
40 typedef void (*voidFuncPtr)(void);
41 
48 class InputManager {
49  friend class DigitalIn;
50  friend class SerialBase;
51  friend class TestIO;
52 public:
58  typedef enum {
59  NONE = -1,
60  LOW = 0,
61  HIGH = 1,
62  CHANGE = 2,
63  FALLING = 3,
64  RISING = 4,
66 
67 #ifndef HIDE_FROM_DOXYGEN
68 
71  static InputManager &Instance();
72 #endif
73 
99 
128 
147  SysConnectorState InputsRT(SysConnectorState mask = UINT32_MAX);
148 
149 #ifndef HIDE_FROM_DOXYGEN
150 
161  void InterruptEnable(int8_t extInt, bool enable, bool clearPending = false);
162 #endif
163 
179  void InterruptsEnabled(bool enable);
180 
196  return m_interruptsEnabled;
197  }
198 
199 #ifndef HIDE_FROM_DOXYGEN
200 
215  bool InterruptHandlerSet(int8_t extInt,
216  voidFuncPtr callback = nullptr,
217  InterruptTrigger trigger = RISING,
218  bool enable = true,
219  bool oneTime = false);
220 
224  void Initialize();
225 
230  void UpdateBegin();
231 
235  void UpdateEnd();
236 
240  void EIC_Handler(uint8_t index);
241 #endif
242 private:
243  // State of the unfiltered input port registers from the DSP.
244  volatile uint32_t *m_inputPtrs[CLEARCORE_PORT_MAX];
245  uint32_t m_inputsUnfiltered[CLEARCORE_PORT_MAX];
246  uint32_t m_inputsUnfilteredChanges[CLEARCORE_PORT_MAX];
247 
248  // Filtered input registers
249  // Real Time register for FILTERED values
250  SysConnectorState m_inputRegRT;
251  // Last sample time register for FILTERED values
252  SysConnectorState m_inputRegLast;
253  // Rising Edge register for FILTERED values
254  SysConnectorState m_inputRegRisen;
255  // Falling Edge register for FILTERED values
256  SysConnectorState m_inputRegFallen;
257  // End input registers
258 
259  // A mask representing all connectors with registered ISRs.
260  uint32_t m_interruptsMask;
261  // Are interrupts enabled across the board?
262  bool m_interruptsEnabled;
263  // Registered interrupt service routines
264  voidFuncPtr m_interruptServiceRoutines[EIC_NUMBER_OF_INTERRUPTS];
265  // Bitmask indicating which interrupt handlers disable after triggerring
266  uint16_t m_oneTimeFlags;
267 
268 #ifndef HIDE_FROM_DOXYGEN
269 
272  InputManager();
273 
274  // Configure the addresses to read the inputs from
275  void SetInputRegisters(volatile uint32_t *a,
276  volatile uint32_t *b,
277  volatile uint32_t *c);
278 
282  uint32_t EicSense(InterruptTrigger trigger);
283 
284 #endif // !HIDE_FROM_DOXYGEN
285 }; // InputManager
286 
287 } // ClearCore namespace
288 
289 #endif /* __INPUTMANAGER_H__ */
SysConnectorState InputsRT(SysConnectorState mask=UINT32_MAX)
Current state of the on-board ClearCore inputs.
ClearCore ARM Serial Port base class.
Definition: SerialBase.h:66
bool InterruptsEnabled()
Current enable state of digital interrupts.
Definition: InputManager.h:195
Defines the Peripheral Route structure, used in HardwareMapping.
ClearCore digital input connector class.
Definition: DigitalIn.h:70
SysConnectorState InputsFallen(SysConnectorState mask=UINT32_MAX)
Clear on read accessor for inputs that have fallen (transitioned from asserted to deasserted) sometim...
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36
Definition: SysConnectors.h:174
SysConnectorState InputsRisen(SysConnectorState mask=UINT32_MAX)
Clear on read accessor for inputs that have risen (transitioned from deasserted to asserted) sometime...
InterruptTrigger
The possible input state conditions to trigger an interrupt on.
Definition: InputManager.h:58
void(* voidFuncPtr)(void)
Definition: DigitalIn.h:43
ClearCore input state access.
Definition: InputManager.h:48