ClearCore Library
DigitalInOutHBridge.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 
35 #ifndef __DIGITALINOUTHBRIDGE_H__
36 #define __DIGITALINOUTHBRIDGE_H__
37 
38 #include <stdint.h>
39 #include "Connector.h"
40 #include "DigitalInOut.h"
41 #include "PeripheralRoute.h"
42 #include "ShiftRegister.h"
43 #include "StatusManager.h"
44 
45 namespace ClearCore {
46 
67  friend class StatusManager;
68  friend class SysManager;
69 
70 public:
78  typedef enum {
82  TONE_OFF = 0,
101  } ToneState;
102 
103 #ifndef HIDE_FROM_DOXYGEN
104 
110  DigitalInOutHBridge() {};
111 #endif
112 
124  virtual ConnectorModes Mode() override {
125  return Connector::Mode();
126  }
127 
151  bool Mode(ConnectorModes newMode) override;
152 
167  }
168 
179  void ToneAmplitude(int16_t amplitude);
180 
191  void ToneContinuous(uint16_t frequency);
192 
218  void ToneTimed(uint16_t frequency, uint32_t duration,
219  bool blocking = false, bool forceDuration = false);
220 
234  void TonePeriodic(uint16_t frequency, uint32_t timeOn, uint32_t timeOff);
235 
244  void ToneStop();
245 
259  volatile const ToneState &ToneActiveState() {
260  return m_toneState;
261  }
262 
289  int16_t State() override;
290 
315  bool State(int16_t newState) override;
316 
329  bool IsWritable() override;
330 
331 #ifndef HIDE_FROM_DOXYGEN
332 
335  void ToneUpdate();
336 #endif
337 
338 private:
339  // Tone values
340  int16_t m_amplitude;
341  int16_t m_sinStep;
342  int16_t m_angle;
343  uint32_t m_toneStartTick;
344  uint32_t m_toneOnTicks;
345  uint32_t m_toneOffTicks;
346  ToneState m_toneState;
347 
348  //Port, Pin, and Timer/Counter values
349  const PeripheralRoute *m_pwmAInfo;
350  const PeripheralRoute *m_pwmBInfo;
351 
352  Tcc *m_tcc;
353  IRQn_Type m_tccIrq;
354 
355  bool m_inFault;
356  bool m_forceToneDuration;
357 
361  void Initialize(ClearCorePins clearCorePin) override;
362 
371  void Refresh() override;
372 
378  inline void ToneFrequency(uint16_t frequency);
379 
385  void FaultState(bool isFaulted);
386 
390  DigitalInOutHBridge(ShiftRegister::Masks ledMask,
391  const PeripheralRoute *inputInfo,
392  const PeripheralRoute *outputInfo,
393  const PeripheralRoute *pwmAInfo,
394  const PeripheralRoute *pwmBInfo,
395  IRQn_Type tccIrq,
396  bool invertDigitalLogic);
397 }; // DigitalInOutHBridge
398 
399 } // ClearCore namespace
400 
401 #endif // __HBRIDGE_H__
Definition: DigitalInOutHBridge.h:100
Defines the Peripheral Route structure, used in HardwareMapping.
virtual ConnectorModes Mode() override
Get the connector&#39;s operational mode.
Definition: DigitalInOutHBridge.h:124
volatile const ToneState & ToneActiveState()
Accessor for the state of the tone currently active on the H-Bridge.
Definition: DigitalInOutHBridge.h:259
ClearCore Digital Output Connector class.
Definition: DigitalInOutHBridge.h:82
void ToneTimed(uint16_t frequency, uint32_t duration, bool blocking=false, bool forceDuration=false)
Output a tone from the H-Bridge for the specified duration.
Definition: Connector.h:247
void ToneContinuous(uint16_t frequency)
Output a continuous tone from the H-Bridge.
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36
LED shift register access class.
Base class for all connector classes.
ClearCore Status Register Manager class.
Definition: StatusManager.h:37
ConnectorModes
All possible operational modes for a connector.
Definition: Connector.h:74
int16_t State() override
Get connector&#39;s last sampled value.
bool IsWritable() override
Get R/W status of the connector.
Definition: DigitalInOutHBridge.h:95
void ToneAmplitude(int16_t amplitude)
Set the amplitude of a PWM output for tone generation.
Connector::ConnectorTypes Type() override
Get connector type.
Definition: DigitalInOutHBridge.h:165
ToneState
Possible states of the tone generator.
Definition: DigitalInOutHBridge.h:78
ClearCore digital output connector class.
Definition: DigitalInOut.h:60
ClearCore Board Supervisory System Manager.
Definition: SysManager.h:58
void TonePeriodic(uint16_t frequency, uint32_t timeOn, uint32_t timeOff)
Output a periodic tone from the H-Bridge.
Definition: DigitalInOutHBridge.h:90
ClearCorePins
ClearCore PIN definitions.
Definition: SysConnectors.h:54
Definition: DigitalInOutHBridge.h:86
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
ClearCore H-Bridge digital output connector class.
Definition: DigitalInOutHBridge.h:66