ClearCore Library
Loading...
Searching...
No Matches
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
45namespace ClearCore {
46
67 friend class StatusManager;
68 friend class SysManager;
69
70public:
102
103#ifndef HIDE_FROM_DOXYGEN
111#endif
112
124 virtual ConnectorModes Mode() override {
125 return Connector::Mode();
126 }
127
151 bool Mode(ConnectorModes newMode) override;
152
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
335 void ToneUpdate();
336#endif
337
338private:
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__
Base class for all connector classes.
ClearCore Digital Output Connector class.
Defines the Peripheral Route structure, used in HardwareMapping.
LED shift register access class.
ClearCorePins
ClearCore PIN definitions.
Definition SysConnectors.h:54
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
@ H_BRIDGE_TYPE
Definition Connector.h:247
ClearCore H-Bridge digital output connector class.
Definition DigitalInOutHBridge.h:66
bool IsWritable() override
Get R/W status of the connector.
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
int16_t State() override
Get connector's last sampled value.
bool Mode(ConnectorModes newMode) override
Set the connector's operational mode.
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.
ToneState
Possible states of the tone generator.
Definition DigitalInOutHBridge.h:78
@ TONE_CONTINUOUS
Definition DigitalInOutHBridge.h:86
@ TONE_PERIODIC_ON
Definition DigitalInOutHBridge.h:95
@ TONE_TIMED
Definition DigitalInOutHBridge.h:90
@ TONE_PERIODIC_OFF
Definition DigitalInOutHBridge.h:100
@ TONE_OFF
Definition DigitalInOutHBridge.h:82
void TonePeriodic(uint16_t frequency, uint32_t timeOn, uint32_t timeOff)
Output a periodic tone from the H-Bridge.
void ToneContinuous(uint16_t frequency)
Output a continuous tone from the H-Bridge.
volatile const ToneState & ToneActiveState()
Accessor for the state of the tone currently active on the H-Bridge.
Definition DigitalInOutHBridge.h:259
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInOutHBridge.h:124
bool State(int16_t newState) override
Set the state of the Connector.
ClearCore digital output connector class.
Definition DigitalInOut.h:60
ClearCore Status Register Manager class.
Definition StatusManager.h:37
ClearCore Board Supervisory System Manager.
Definition SysManager.h:58
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36