ClearCore Library
Loading...
Searching...
No Matches
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
39namespace ClearCore {
40
59 friend class SysManager;
60
61public:
66 static const uint16_t ANALOG_INPUT_FILTER_TC_MS_DEFAULT = 2;
67
68#ifndef HIDE_FROM_DOXYGEN
76#endif
77
89 virtual ConnectorModes Mode() override {
90 return Connector::Mode();
91 }
92
111 bool Mode(ConnectorModes newMode) override;
112
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
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
204 bool State(int16_t newState) override {
205 // ignore attempts to write state
206 (void)newState;
207 return false;
208 }
209#endif
210private:
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
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__
ADC Peripheral Manager for the ClearCore Board.
Base class for all connector classes.
ClearCore Digital Input Connector class.
Defines the Peripheral Route structure, used in HardwareMapping.
LED shift register access class.
ClearCorePins
ClearCore PIN definitions.
Definition SysConnectors.h:54
AdcChannels
Definition AdcManager.h:57
FilterUnits
Units for the filter time constant.
Definition AdcManager.h:75
virtual ConnectorModes Mode()
Get the connector's operational mode.
Definition Connector.h:309
ConnectorModes
All possible operational modes for a connector.
Definition Connector.h:74
ConnectorTypes
The different types of ClearCore connectors.
Definition Connector.h:172
@ ANALOG_IN_DIGITAL_IN_TYPE
Definition Connector.h:218
ClearCore analog input connector class.
Definition DigitalInAnalogIn.h:58
int16_t State() override
Get the connector's last majority-filtered sampled value.
Connector::ConnectorTypes Type() override
Get connector type.
Definition DigitalInAnalogIn.h:124
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInAnalogIn.h:89
bool IsWritable() override
Is this connector able to be written to?
Definition DigitalInAnalogIn.h:139
static const uint16_t ANALOG_INPUT_FILTER_TC_MS_DEFAULT
Definition DigitalInAnalogIn.h:66
bool Mode(ConnectorModes newMode) override
Set the connector's operational mode.
bool FilterTc(uint16_t tc, AdcManager::FilterUnits theUnits)
Set the time constant for the analog input filter.
float AnalogVoltage()
Returns the analog voltage of the connector in volts.
Definition DigitalInAnalogIn.h:186
ClearCore digital input connector class.
Definition DigitalIn.h:70
ClearCore Board Supervisory System Manager.
Definition SysManager.h:58
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36