ClearCore Library
Loading...
Searching...
No Matches
SerialDriver.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
34#ifndef __SERIALDRIVER_H__
35#define __SERIALDRIVER_H__
36
37#include <stdint.h>
38#include "Connector.h"
39#include "SerialBase.h"
40#include "ShiftRegister.h"
41
42namespace ClearCore {
43
55class SerialDriver : public SerialBase, public Connector {
56 friend class SysManager;
57 friend class CcioBoardManager;
58 friend class TestIO;
59
60public:
61#ifndef HIDE_FROM_DOXYGEN
66 SerialDriver() {};
67#endif
68
80 virtual ConnectorModes Mode() override {
81 return Connector::Mode();
82 }
83
100 bool Mode(ConnectorModes newMode) override;
101
110
116 bool IsWritable() override {
117 return PortIsOpen();
118 };
119
120#ifndef HIDE_FROM_DOXYGEN
126 int16_t State() override {
127 return PortIsOpen();
128 }
129
137 bool State(int16_t newState) override {
138 if (newState) {
139 PortOpen();
140 }
141 else {
142 PortClose();
143 }
144 return true;
145 }
146
147 bool IsInHwFault() override {
148 return false;
149 }
150#endif
151
159 bool Speed(uint32_t bitsPerSecond) override {
160 bool retVal = SerialBase::Speed(bitsPerSecond);
161 // Delay to allow the port polarity to be written to the shift
162 // register and settle for a full character time before sending data
163 if (m_portOpen) {
164 WaitOneCharTime();
165 }
166 return retVal;
167 }
168
172 void PortOpen() override;
173
177 void PortClose() override;
178
179private:
180 // Index of this instance
181 uint8_t m_index;
182 // Feedback LED
183 ShiftRegister::Masks m_ledMask;
184 // Control bit in shift register
185 ShiftRegister::Masks m_controlMask;
186 // Inverter bit in shift register
187 ShiftRegister::Masks m_polarityMask;
188
189#ifndef HIDE_FROM_DOXYGEN
193 SerialDriver(uint16_t index,
194 ShiftRegister::Masks feedBackLedMask,
195 ShiftRegister::Masks controlMask,
196 ShiftRegister::Masks polarityMask,
197 const PeripheralRoute *ctsMisoInfo,
198 const PeripheralRoute *rtsSsInfo,
199 const PeripheralRoute *rxSckInfo,
200 const PeripheralRoute *txMosiInfo,
201 uint8_t peripheral);
202#endif
206 void Initialize(ClearCorePins clearCorePin) override;
207
211 void Refresh() override {};
212}; // SerialDriver
213
214} // ClearCore namespace
215
216#endif // __SERIALDRIVER_H__
Base class for all connector classes.
LED shift register access class.
ClearCorePins
ClearCore PIN definitions.
Definition SysConnectors.h:54
ClearCore I/O Expansion Board Manager Class.
Definition CcioBoardManager.h:91
Base class for interacting with all ClearCore connector objects.
Definition Connector.h:62
virtual bool IsInHwFault()=0
Get whether the connector is in a hardware fault state.
virtual ConnectorModes Mode()
Get the connector's operational mode.
Definition Connector.h:309
virtual int16_t State()=0
Get the connector's last sampled value.
ConnectorModes
All possible operational modes for a connector.
Definition Connector.h:74
ConnectorTypes
The different types of ClearCore connectors.
Definition Connector.h:172
@ SERIAL_TYPE
Definition Connector.h:277
ClearCore ARM Serial Port base class.
Definition SerialBase.h:66
virtual uint32_t Speed() override
Gets the baud rate of the port.
Definition SerialBase.h:231
bool PortIsOpen() override
Return whether or not the port is open.
ClearCore Serial UART/SPI Connector class.
Definition SerialDriver.h:55
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition SerialDriver.h:80
Connector::ConnectorTypes Type() override
Get connector type.
Definition SerialDriver.h:107
void PortOpen() override
bool IsWritable() override
Get R/W status of the connector.
Definition SerialDriver.h:116
bool Mode(ConnectorModes newMode) override
Set the connector's operational mode.
void PortClose() override
bool Speed(uint32_t bitsPerSecond) override
Change the baud rate for the port.
Definition SerialDriver.h:159
ClearCore Board Supervisory System Manager.
Definition SysManager.h:58
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36