ClearCore Library
MotorManager.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 __MOTORMANAGER_H__
28 #define __MOTORMANAGER_H__
29 
30 #include <stdint.h>
31 #include "HardwareMapping.h"
32 #include "MotorDriver.h"
33 
34 namespace ClearCore {
35 
46 class MotorManager {
47 public:
51  typedef enum {
65 
69  typedef enum {
86  } MotorPair;
87 
88 #ifndef HIDE_FROM_DOXYGEN
89 
92  static MotorManager &Instance();
93 
97  void Initialize();
98 #endif
99 
118  bool MotorInputClocking(MotorClockRates newRate);
119 
143  bool MotorModeSet(MotorPair motorPair, Connector::ConnectorModes newMode);
144 
145 protected:
146  uint8_t m_gclkIndex;
147  MotorClockRates m_clockRate;
148  ClearCorePorts m_stepPorts[NUM_MOTOR_PAIRS];
149  uint32_t m_stepDataBits[NUM_MOTOR_PAIRS];
151 
152 private:
153 #define CPM_CLOCK_RATE_LOW_HZ \
154  (100000 / _CLEARCORE_SAMPLE_RATE_HZ * _CLEARCORE_SAMPLE_RATE_HZ)
155 #define CPM_CLOCK_RATE_NORMAL_HZ \
156  (500000 / _CLEARCORE_SAMPLE_RATE_HZ * _CLEARCORE_SAMPLE_RATE_HZ)
157 #define CPM_CLOCK_RATE_HIGH_HZ \
158  (2000000 / _CLEARCORE_SAMPLE_RATE_HZ * _CLEARCORE_SAMPLE_RATE_HZ)
159 
160  bool m_initialized;
161 
165  MotorManager();
166 
167  void PinMuxSet();
168 };
169 
170 } // ClearCore namespace
171 
172 #endif // __MOTORMANAGER_H__
bool MotorModeSet(MotorPair motorPair, Connector::ConnectorModes newMode)
Sets the operational mode for the specified MotorDriver connectors.
MotorClockRates
Definition: MotorManager.h:51
MotorPair
Definition: MotorManager.h:69
Definition: MotorManager.h:77
Definition: MotorManager.h:81
bool MotorInputClocking(MotorClockRates newRate)
Sets the output step rate for the motor step generators.
Definition: MotorManager.h:85
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36
ConnectorModes
All possible operational modes for a connector.
Definition: Connector.h:74
Definition: MotorManager.h:73
ClearCore motor-connector manager.
Definition: MotorManager.h:46
Definition: MotorManager.h:59
ClearCorePorts
Definition: PeripheralRoute.h:34
Definition: MotorManager.h:55
Definition: MotorManager.h:63