ClearCore Library
DigitalInOut.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 
29 #ifndef __DIGITALINOUT_H__
30 #define __DIGITALINOUT_H__
31 
32 #include <stdint.h>
33 #include <sam.h>
34 #include "Connector.h"
35 #include "DigitalIn.h"
36 #include "ShiftRegister.h"
37 #include "SysUtils.h"
38 
39 namespace ClearCore {
40 
60 class DigitalInOut : public DigitalIn {
61  friend class SysManager;
62 
63 public:
64 #ifndef HIDE_FROM_DOXYGEN
65 
71  DigitalInOut() {};
72 #endif
73 
85  virtual ConnectorModes Mode() override {
86  return Connector::Mode();
87  }
88 
104  virtual bool Mode(ConnectorModes newMode) override;
105 
119  }
120 
132  bool IsWritable() override {
133  return m_mode == OUTPUT_DIGITAL || m_mode == OUTPUT_PWM;
134  }
135 
159  int16_t State() override;
160 
182  bool State(int16_t newState) override;
183 
187  bool IsInHwFault() override {
188  return (volatile bool &)m_isInFault;
189  }
190 
215  void OutputPulsesStart(uint32_t onTime, uint32_t offTime,
216  uint16_t pulseCount = 0,
217  bool blockUntilDone = false);
218 
234  void OutputPulsesStop(bool stopImmediately = true);
235 
250  volatile const bool &OutputPulsesActive() {
251  return m_pulseActive;
252  }
253 
272  bool PwmDuty(uint8_t newDuty);
273 
274 protected:
275  // Port access
276  uint32_t m_outputPort;
277  uint32_t m_outputDataBit;
278  uint32_t m_outputDataMask;
279  bool m_logicInversion;
280 
281  bool m_isInFault;
282 
283  Tc *m_tc;
284  uint8_t m_tcPadNum;
285 
286 #ifndef HIDE_FROM_DOXYGEN
287 
290  DigitalInOut(enum ShiftRegister::Masks ledMask,
291  const PeripheralRoute *inputInfo,
292  const PeripheralRoute *outputInfo,
293  bool logicInversion);
294 
303  void Refresh() override;
304 
308  void Initialize(ClearCorePins clearCorePin) override;
309 #endif
310 private:
311  bool m_outState;
312  // Pulse control variables
313  uint32_t m_pulseOnTicks;
314  uint32_t m_pulseOffTicks;
315  uint32_t m_pulseStart;
316  uint16_t m_pulseStopCount;
317  uint16_t m_pulseCounter;
318  uint8_t m_overloadTripCnt;
319  bool m_pulseActive;
320  bool m_pulseValue;
321  bool m_pulseStopPending;
322  uint16_t m_overloadFoldbackCnt;
323 
324  void OutputPin(bool val) {
325  DATA_OUTPUT_STATE(m_outputPort, m_outputDataMask,
326  val != m_logicInversion);
327  }
328 
334  void IsInHwFault(bool inFault);
335 };
336 
337 } // ClearCore namespace
338 
339 #endif // __DIGITALINOUT_H__
bool IsWritable() override
Get R/W status of the connector.
Definition: DigitalInOut.h:132
volatile const bool & OutputPulsesActive()
Check the output pulse state.
Definition: DigitalInOut.h:250
bool PwmDuty(uint8_t newDuty)
Set the PWM duty on the I/O pin.
ClearCore digital input connector class.
Definition: DigitalIn.h:70
#define DATA_OUTPUT_STATE(GPIO_PORT, DATA_MASK, STATE)
Definition: SysUtils.h:86
void OutputPulsesStart(uint32_t onTime, uint32_t offTime, uint16_t pulseCount=0, bool blockUntilDone=false)
Start an output pulse.
virtual ConnectorModes Mode() override
Get the connector&#39;s operational mode.
Definition: DigitalInOut.h:85
int16_t State() override
Get the connector&#39;s last majority-filtered sampled value.
Connector::ConnectorTypes Type() override
Get connector type.
Definition: DigitalInOut.h:117
Definition: Connector.h:98
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36
LED shift register access class.
Base class for all connector classes.
void OutputPulsesStop(bool stopImmediately=true)
Stop an output pulse.
ConnectorModes
All possible operational modes for a connector.
Definition: Connector.h:74
ClearCore Digital Input Connector class.
ClearCore digital output connector class.
Definition: DigitalInOut.h:60
ClearCore Board Supervisory System Manager.
Definition: SysManager.h:58
ClearCorePins
ClearCore PIN definitions.
Definition: SysConnectors.h:54
ClearCore common utility functions.
Definition: Connector.h:106
virtual ConnectorModes Mode()
Get the connector&#39;s operational mode.
Definition: Connector.h:309
bool IsInHwFault() override
Get whether the connector is in a hardware fault state.
Definition: DigitalInOut.h:187
ConnectorTypes
The different types of ClearCore connectors.
Definition: Connector.h:172