ClearCore Library
DigitalInAnalogIn.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 
27 #ifndef __DIGITALINANALOGIN_H__
28 #define __DIGITALINANALOGIN_H__
29 
30 #include <stdint.h>
31 #include <sam.h>
32 #include "AdcManager.h"
33 #include "Connector.h"
34 #include "DigitalIn.h"
35 #include "IirFilter.h"
36 #include "PeripheralRoute.h"
37 #include "ShiftRegister.h"
38 
39 namespace ClearCore {
40 
58 class DigitalInAnalogIn : public DigitalIn {
59  friend class SysManager;
60 
61 public:
66  static const uint16_t ANALOG_INPUT_FILTER_TC_MS_DEFAULT = 2;
67 
68 #ifndef HIDE_FROM_DOXYGEN
69 
75  DigitalInAnalogIn() {};
76 #endif
77 
89  virtual ConnectorModes Mode() override {
90  return Connector::Mode();
91  }
92 
111  bool Mode(ConnectorModes newMode) override;
112 
126  }
127 
139  bool IsWritable() override {
140  return false;
141  }
142 
159  bool FilterTc(uint16_t tc, AdcManager::FilterUnits theUnits);
160 
174  int16_t State() override;
175 
186  float AnalogVoltage() {
187  // If there is not a valid reading available, return zero.
188  if (!m_analogValid) {
189  return 0;
190  }
191  return AdcManager::Instance().AnalogVoltage(m_adcChannel);
192  }
193 
194 #ifndef HIDE_FROM_DOXYGEN
195 
204  bool State(int16_t newState) override {
205  // ignore attempts to write state
206  (void)newState;
207  return false;
208  }
209 #endif
210 private:
211  // Control bit for the analog input circuit
212  ShiftRegister::Masks m_modeControlBitMask;
213 
214  AdcManager::AdcChannels m_adcChannel;
215 
216  volatile const uint16_t *m_adcResultConvertedPtr;
217  volatile const uint16_t *m_adcResultConvertedFilteredPtr;
218  volatile bool m_analogValid;
219 
220 #ifndef HIDE_FROM_DOXYGEN
221 
224  DigitalInAnalogIn(enum ShiftRegister::Masks ledMask,
225  enum ShiftRegister::Masks modeControlMask,
226  const PeripheralRoute *inputInfo,
227  AdcManager::AdcChannels adcChannel);
228 #endif
229 
238  void Refresh() override;
239 
246  void Initialize(ClearCorePins clearCorePin) override;
247 
248 }; // DigitalInAnalogIn
249 
250 } // ClearCore namespace
251 
252 #endif // __ANALOGINDIGITALIN_H__
static const uint16_t ANALOG_INPUT_FILTER_TC_MS_DEFAULT
Definition: DigitalInAnalogIn.h:66
AdcChannels
Definition: AdcManager.h:57
Defines the Peripheral Route structure, used in HardwareMapping.
ClearCore digital input connector class.
Definition: DigitalIn.h:70
float AnalogVoltage()
Returns the analog voltage of the connector in volts.
Definition: DigitalInAnalogIn.h:186
bool FilterTc(uint16_t tc, AdcManager::FilterUnits theUnits)
Set the time constant for the analog input filter.
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36
bool IsWritable() override
Is this connector able to be written to?
Definition: DigitalInAnalogIn.h:139
LED shift register access class.
Base class for all connector classes.
ConnectorModes
All possible operational modes for a connector.
Definition: Connector.h:74
ClearCore Digital Input Connector class.
FilterUnits
Units for the filter time constant.
Definition: AdcManager.h:75
Connector::ConnectorTypes Type() override
Get connector type.
Definition: DigitalInAnalogIn.h:124
ClearCore analog input connector class.
Definition: DigitalInAnalogIn.h:58
ADC Peripheral Manager for the ClearCore Board.
int16_t State() override
Get the connector&#39;s last majority-filtered sampled value.
ClearCore Board Supervisory System Manager.
Definition: SysManager.h:58
virtual ConnectorModes Mode() override
Get the connector&#39;s operational mode.
Definition: DigitalInAnalogIn.h:89
ClearCorePins
ClearCore PIN definitions.
Definition: SysConnectors.h:54
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