ClearCore Library
CcioPin.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 
30 #ifndef __CCIOPIN_H__
31 #define __CCIOPIN_H__
32 
33 #include <sam.h>
34 #include <stdint.h>
35 
36 #include "Connector.h"
37 #include "SysConnectors.h"
38 
39 namespace ClearCore {
40 
53 class CcioPin : public Connector {
54  friend class CcioBoardManager;
55 
56 public:
57 
71  virtual ConnectorModes Mode() override {
72  return Connector::Mode();
73  }
74 
91  virtual bool Mode(ConnectorModes newMode) override;
92 
106  }
107 
120  bool IsWritable() override {
121  return m_mode == OUTPUT_DIGITAL;
122  }
123 
137  int16_t State() override;
150  bool State(int16_t newState) override;
151 
170  void FilterLength(uint16_t samples) {
171  m_filterLength = samples;
172  m_filterTicksLeft = samples;
173  }
174 
189  void Filter_ms(uint16_t len);
190 
202  bool IsInHwFault() override;
203 
216  bool InputRisen();
217 
230  bool InputFallen();
231 
257  void OutputPulsesStart(uint32_t onTime, uint32_t offTime,
258  uint16_t pulseCount = 0, bool blockUntilDone = false);
259 
275  void OutputPulsesStop(bool stopImmediately = true);
276 
277 protected:
278 #ifndef HIDE_FROM_DOXYGEN
279 
282  CcioPin();
283 
287  void Initialize(ClearCorePins ccioPin) override;
288 
297  void Refresh() override {}
298 #endif
299 
300 private:
301  // Port access
302  uint64_t m_dataBit;
303 
304  // Stability filter
305  uint16_t m_filterLength;
306  // Set to filter length on input change
307  uint16_t m_filterTicksLeft;
308  // Consecutive sample filter for tripping overload conditions
309  uint16_t m_overloadTripCnt;
310  // Overload condition output throttling
311  uint16_t m_overloadFoldbackCnt;
312 
313  uint32_t m_pulseOnTicks;
314  uint32_t m_pulseOffTicks;
315  uint32_t m_pulseTicksRemaining;
316  uint16_t m_pulseStopCount;
317  uint16_t m_pulseCounter;
318 };
319 
320 } // ClearCore namespace
321 
322 #endif // __CCIOPIN_H__
bool IsWritable() override
Get R/W status of the connector.
Definition: CcioPin.h:120
virtual ConnectorModes Mode() override
Get the connector&#39;s operational mode.
Definition: CcioPin.h:71
void OutputPulsesStop(bool stopImmediately=true)
Stop an output pulse.
bool IsInHwFault() override
Check whether the connector is in a hardware fault state.
ClearCore I/O Expansion Board Manager Class.
Definition: CcioBoardManager.h:91
Base class for interacting with all ClearCore connector objects.
Definition: Connector.h:62
Definition: Connector.h:98
void FilterLength(uint16_t samples)
Set the connector&#39;s digital filter length in samples. The default is 3 samples.
Definition: CcioPin.h:170
void OutputPulsesStart(uint32_t onTime, uint32_t offTime, uint16_t pulseCount=0, bool blockUntilDone=false)
Start an output pulse.
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36
Connector class for an individual CCIO-8 pin.
Definition: CcioPin.h:53
Base class for all connector classes.
bool InputFallen()
Clear on read accessor for this connector&#39;s falling input state.
ConnectorModes
All possible operational modes for a connector.
Definition: Connector.h:74
Connector::ConnectorTypes Type() override
Get connector type.
Definition: CcioPin.h:104
int16_t State() override
In input mode, get the connector&#39;s last filtered sampled value. In output mode, get the connector&#39;s o...
void Filter_ms(uint16_t len)
Set the connector&#39;s digital filter length in ms.
ClearCorePins
ClearCore PIN definitions.
Definition: SysConnectors.h:54
bool InputRisen()
Clear on read accessor for this connector&#39;s rising input state.
virtual ConnectorModes Mode()
Get the connector&#39;s operational mode.
Definition: Connector.h:309
ConnectorTypes
The different types of ClearCore connectors.
Definition: Connector.h:172