X-CUBE-SPN1-20150128 example source code for one motor compiled under mbed. Tested OK on Nucleo F401. l6474.cpp is modified from original with defines in l6474_target_config.h to select the original behaviour (motor de-energised when halted), or new mode to continue powering with a (reduced) current in the coils (braking/position hold capability). On F401 avoid using mbed's InterruptIn on pins 10-15 (any port). Beware of other conflicts! L0 & F0 are included but untested.

Dependencies:   mbed

Committer:
gregeric
Date:
Tue Oct 13 10:46:01 2015 +0000
Revision:
6:19c1b4a04c24
Parent:
0:b9444a40a999
Ensure bridge is disabled before resetting the L6474.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gregeric 0:b9444a40a999 1 /**
gregeric 0:b9444a40a999 2 ******************************************************************************
gregeric 0:b9444a40a999 3 * @file motorcontrol.c
gregeric 0:b9444a40a999 4 * @author IPC Rennes
gregeric 0:b9444a40a999 5 * @version V1.0.0
gregeric 0:b9444a40a999 6 * @date 12-November-2014
gregeric 0:b9444a40a999 7 * @brief This file provides common functions for motor control
gregeric 0:b9444a40a999 8 ******************************************************************************
gregeric 0:b9444a40a999 9 * @attention
gregeric 0:b9444a40a999 10 *
gregeric 0:b9444a40a999 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
gregeric 0:b9444a40a999 12 *
gregeric 0:b9444a40a999 13 * Redistribution and use in source and binary forms, with or without modification,
gregeric 0:b9444a40a999 14 * are permitted provided that the following conditions are met:
gregeric 0:b9444a40a999 15 * 1. Redistributions of source code must retain the above copyright notice,
gregeric 0:b9444a40a999 16 * this list of conditions and the following disclaimer.
gregeric 0:b9444a40a999 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
gregeric 0:b9444a40a999 18 * this list of conditions and the following disclaimer in the documentation
gregeric 0:b9444a40a999 19 * and/or other materials provided with the distribution.
gregeric 0:b9444a40a999 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
gregeric 0:b9444a40a999 21 * may be used to endorse or promote products derived from this software
gregeric 0:b9444a40a999 22 * without specific prior written permission.
gregeric 0:b9444a40a999 23 *
gregeric 0:b9444a40a999 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
gregeric 0:b9444a40a999 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
gregeric 0:b9444a40a999 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
gregeric 0:b9444a40a999 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
gregeric 0:b9444a40a999 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
gregeric 0:b9444a40a999 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
gregeric 0:b9444a40a999 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
gregeric 0:b9444a40a999 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
gregeric 0:b9444a40a999 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
gregeric 0:b9444a40a999 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gregeric 0:b9444a40a999 34 *
gregeric 0:b9444a40a999 35 ******************************************************************************
gregeric 0:b9444a40a999 36 */
gregeric 0:b9444a40a999 37 /* Includes ------------------------------------------------------------------*/
gregeric 0:b9444a40a999 38 #include "motorcontrol.h"
gregeric 0:b9444a40a999 39
gregeric 0:b9444a40a999 40 /** @addtogroup BSP
gregeric 0:b9444a40a999 41 * @{
gregeric 0:b9444a40a999 42 */
gregeric 0:b9444a40a999 43
gregeric 0:b9444a40a999 44 /** @defgroup MOTOR_CONTROL
gregeric 0:b9444a40a999 45 * @{
gregeric 0:b9444a40a999 46 */
gregeric 0:b9444a40a999 47
gregeric 0:b9444a40a999 48 /** @defgroup MOTOR_CONTROL_Private_Types_Definitions
gregeric 0:b9444a40a999 49 * @{
gregeric 0:b9444a40a999 50 */
gregeric 0:b9444a40a999 51
gregeric 0:b9444a40a999 52 /**
gregeric 0:b9444a40a999 53 * @}
gregeric 0:b9444a40a999 54 */
gregeric 0:b9444a40a999 55
gregeric 0:b9444a40a999 56
gregeric 0:b9444a40a999 57 /** @defgroup MOTOR_CONTROL_Private_Defines
gregeric 0:b9444a40a999 58 * @{
gregeric 0:b9444a40a999 59 */
gregeric 0:b9444a40a999 60 /**
gregeric 0:b9444a40a999 61 * @}
gregeric 0:b9444a40a999 62 */
gregeric 0:b9444a40a999 63
gregeric 0:b9444a40a999 64 /** @defgroup MOTOR_CONTROL_Private_Constants
gregeric 0:b9444a40a999 65 * @{
gregeric 0:b9444a40a999 66 */
gregeric 0:b9444a40a999 67 /// Error when trying to call undefined functions via motorDrvHandle
gregeric 0:b9444a40a999 68 #define MOTOR_CONTROL_ERROR_0 (0x0800)
gregeric 0:b9444a40a999 69
gregeric 0:b9444a40a999 70 /**
gregeric 0:b9444a40a999 71 * @}
gregeric 0:b9444a40a999 72 */
gregeric 0:b9444a40a999 73
gregeric 0:b9444a40a999 74 /** @defgroup MOTOR_CONTROL_Private_Macros
gregeric 0:b9444a40a999 75 * @{
gregeric 0:b9444a40a999 76 */
gregeric 0:b9444a40a999 77 /// Error when trying to call undefined functions via motorDrvHandle
gregeric 0:b9444a40a999 78 #define MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(errorNb) (BSP_MotorControl_ErrorHandler(MOTOR_CONTROL_ERROR_0|(errorNb)))
gregeric 0:b9444a40a999 79
gregeric 0:b9444a40a999 80 /**
gregeric 0:b9444a40a999 81 * @}
gregeric 0:b9444a40a999 82 */
gregeric 0:b9444a40a999 83
gregeric 0:b9444a40a999 84 /** @defgroup MOTOR_CONTROL_Private_Variables
gregeric 0:b9444a40a999 85 * @{
gregeric 0:b9444a40a999 86 */
gregeric 0:b9444a40a999 87
gregeric 0:b9444a40a999 88 static motorDrv_t *motorDrvHandle = 0;
gregeric 0:b9444a40a999 89 static uint16_t MotorControlBoardId;
gregeric 0:b9444a40a999 90 /**
gregeric 0:b9444a40a999 91 * @}
gregeric 0:b9444a40a999 92 */
gregeric 0:b9444a40a999 93
gregeric 0:b9444a40a999 94 /** @defgroup MOTOR_CONTROL_Weak_Private_Functions
gregeric 0:b9444a40a999 95 * @{
gregeric 0:b9444a40a999 96 */
gregeric 0:b9444a40a999 97 /// Get motor handle for L6474
gregeric 0:b9444a40a999 98 __weak motorDrv_t* L6474_GetMotorHandle(void){return ((motorDrv_t* )0);}
gregeric 0:b9444a40a999 99 /// Get motor handle for Powerstep
gregeric 0:b9444a40a999 100 __weak motorDrv_t* Powerstep01_GetMotorHandle(void){return ((motorDrv_t* )0);}
gregeric 0:b9444a40a999 101
gregeric 0:b9444a40a999 102
gregeric 0:b9444a40a999 103 /**
gregeric 0:b9444a40a999 104 * @}
gregeric 0:b9444a40a999 105 */
gregeric 0:b9444a40a999 106
gregeric 0:b9444a40a999 107 /** @defgroup MOTOR_CONTROL_Private_Functions
gregeric 0:b9444a40a999 108 * @{
gregeric 0:b9444a40a999 109 */
gregeric 0:b9444a40a999 110
gregeric 0:b9444a40a999 111 /******************************************************//**
gregeric 0:b9444a40a999 112 * @brief Attaches a user callback to the error Handler.
gregeric 0:b9444a40a999 113 * The call back will be then called each time the library
gregeric 0:b9444a40a999 114 * detects an error
gregeric 0:b9444a40a999 115 * @param[in] callback Name of the callback to attach
gregeric 0:b9444a40a999 116 * to the error Hanlder
gregeric 0:b9444a40a999 117 * @retval None
gregeric 0:b9444a40a999 118 **********************************************************/
gregeric 0:b9444a40a999 119 void BSP_MotorControl_AttachErrorHandler(void (*callback)(uint16_t))
gregeric 0:b9444a40a999 120 {
gregeric 0:b9444a40a999 121 if ((motorDrvHandle != 0)&&(motorDrvHandle->AttachErrorHandler != 0))
gregeric 0:b9444a40a999 122 {
gregeric 0:b9444a40a999 123 motorDrvHandle->AttachErrorHandler(callback);
gregeric 0:b9444a40a999 124 }
gregeric 0:b9444a40a999 125 else
gregeric 0:b9444a40a999 126 {
gregeric 0:b9444a40a999 127 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(1);
gregeric 0:b9444a40a999 128 }
gregeric 0:b9444a40a999 129 }
gregeric 0:b9444a40a999 130
gregeric 0:b9444a40a999 131 /******************************************************//**
gregeric 0:b9444a40a999 132 * @brief Attaches a user callback to the Flag interrupt Handler.
gregeric 0:b9444a40a999 133 * The call back will be then called each time the library
gregeric 0:b9444a40a999 134 * detects a FLAG signal falling edge.
gregeric 0:b9444a40a999 135 * @param[in] callback Name of the callback to attach
gregeric 0:b9444a40a999 136 * to the Flag interrupt Hanlder
gregeric 0:b9444a40a999 137 * @retval None
gregeric 0:b9444a40a999 138 **********************************************************/
gregeric 0:b9444a40a999 139 void BSP_MotorControl_AttachFlagInterrupt(void (*callback)(void))
gregeric 0:b9444a40a999 140 {
gregeric 0:b9444a40a999 141 if ((motorDrvHandle != 0)&&(motorDrvHandle->AttachFlagInterrupt != 0))
gregeric 0:b9444a40a999 142 {
gregeric 0:b9444a40a999 143 motorDrvHandle->AttachFlagInterrupt(callback);
gregeric 0:b9444a40a999 144 }
gregeric 0:b9444a40a999 145 else
gregeric 0:b9444a40a999 146 {
gregeric 0:b9444a40a999 147 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(2);
gregeric 0:b9444a40a999 148 }
gregeric 0:b9444a40a999 149 }
gregeric 0:b9444a40a999 150
gregeric 0:b9444a40a999 151 /******************************************************//**
gregeric 0:b9444a40a999 152 * @brief Attaches a user callback to the Busy interrupt Handler.
gregeric 0:b9444a40a999 153 * The call back will be then called each time the library
gregeric 0:b9444a40a999 154 * detects a BUSY signal falling edge.
gregeric 0:b9444a40a999 155 * @param[in] callback Name of the callback to attach
gregeric 0:b9444a40a999 156 * to the Busy interrupt Hanlder
gregeric 0:b9444a40a999 157 * @retval None
gregeric 0:b9444a40a999 158 **********************************************************/
gregeric 0:b9444a40a999 159 void BSP_MotorControl_AttachBusyInterrupt(void (*callback)(void))
gregeric 0:b9444a40a999 160 {
gregeric 0:b9444a40a999 161 if ((motorDrvHandle != 0)&&(motorDrvHandle->AttachBusyInterrupt != 0))
gregeric 0:b9444a40a999 162 {
gregeric 0:b9444a40a999 163 motorDrvHandle->AttachBusyInterrupt(callback);
gregeric 0:b9444a40a999 164 }
gregeric 0:b9444a40a999 165 else
gregeric 0:b9444a40a999 166 {
gregeric 0:b9444a40a999 167 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(3);
gregeric 0:b9444a40a999 168 }
gregeric 0:b9444a40a999 169 }
gregeric 0:b9444a40a999 170
gregeric 0:b9444a40a999 171 /******************************************************//**
gregeric 0:b9444a40a999 172 * @brief Motor control error handler
gregeric 0:b9444a40a999 173 * @param[in] error number of the error
gregeric 0:b9444a40a999 174 * @retval None
gregeric 0:b9444a40a999 175 **********************************************************/
gregeric 0:b9444a40a999 176 void BSP_MotorControl_ErrorHandler(uint16_t error)
gregeric 0:b9444a40a999 177 {
gregeric 0:b9444a40a999 178 if ((motorDrvHandle != 0)&&(motorDrvHandle->ErrorHandler != 0))
gregeric 0:b9444a40a999 179 {
gregeric 0:b9444a40a999 180 motorDrvHandle->ErrorHandler(error);
gregeric 0:b9444a40a999 181 }
gregeric 0:b9444a40a999 182 else
gregeric 0:b9444a40a999 183 {
gregeric 0:b9444a40a999 184 while(1)
gregeric 0:b9444a40a999 185 {
gregeric 0:b9444a40a999 186 /* Infinite loop as Error handler must be defined*/
gregeric 0:b9444a40a999 187 }
gregeric 0:b9444a40a999 188 }
gregeric 0:b9444a40a999 189 }
gregeric 0:b9444a40a999 190 /******************************************************//**
gregeric 0:b9444a40a999 191 * @brief Initialises the motor driver
gregeric 0:b9444a40a999 192 * @param[in] id Component Id (L6474, Powerstep01,...)
gregeric 0:b9444a40a999 193 * @param[in] nbDevices Number of motor devices to use (from 1 to 3)
gregeric 0:b9444a40a999 194 * @retval None
gregeric 0:b9444a40a999 195 **********************************************************/
gregeric 0:b9444a40a999 196 void BSP_MotorControl_Init(uint16_t id, uint8_t nbDevices)
gregeric 0:b9444a40a999 197 {
gregeric 0:b9444a40a999 198 MotorControlBoardId = id;
gregeric 0:b9444a40a999 199
gregeric 0:b9444a40a999 200 if (id == BSP_MOTOR_CONTROL_BOARD_ID_L6474)
gregeric 0:b9444a40a999 201 {
gregeric 0:b9444a40a999 202 motorDrvHandle = L6474_GetMotorHandle();
gregeric 0:b9444a40a999 203 }
gregeric 0:b9444a40a999 204 else if (id == BSP_MOTOR_CONTROL_BOARD_ID_POWERSTEP01)
gregeric 0:b9444a40a999 205 {
gregeric 0:b9444a40a999 206 motorDrvHandle = Powerstep01_GetMotorHandle();
gregeric 0:b9444a40a999 207 }
gregeric 0:b9444a40a999 208 else
gregeric 0:b9444a40a999 209 {
gregeric 0:b9444a40a999 210 motorDrvHandle = 0;
gregeric 0:b9444a40a999 211 }
gregeric 0:b9444a40a999 212
gregeric 0:b9444a40a999 213 if ((motorDrvHandle != 0)&&(motorDrvHandle->Init != 0))
gregeric 0:b9444a40a999 214 {
gregeric 0:b9444a40a999 215 motorDrvHandle->Init(nbDevices);
gregeric 0:b9444a40a999 216 }
gregeric 0:b9444a40a999 217 else
gregeric 0:b9444a40a999 218 {
gregeric 0:b9444a40a999 219 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(4);
gregeric 0:b9444a40a999 220 }
gregeric 0:b9444a40a999 221 }
gregeric 0:b9444a40a999 222
gregeric 0:b9444a40a999 223 /******************************************************//**
gregeric 0:b9444a40a999 224 * @brief Handlers of the flag interrupt which calls the user callback (if defined)
gregeric 0:b9444a40a999 225 * @param None
gregeric 0:b9444a40a999 226 * @retval None
gregeric 0:b9444a40a999 227 **********************************************************/
gregeric 0:b9444a40a999 228 void BSP_MotorControl_FlagInterruptHandler(void)
gregeric 0:b9444a40a999 229 {
gregeric 0:b9444a40a999 230 if ((motorDrvHandle != 0)&&(motorDrvHandle->FlagInterruptHandler != 0))
gregeric 0:b9444a40a999 231 {
gregeric 0:b9444a40a999 232 motorDrvHandle->FlagInterruptHandler();
gregeric 0:b9444a40a999 233 }
gregeric 0:b9444a40a999 234 else
gregeric 0:b9444a40a999 235 {
gregeric 0:b9444a40a999 236 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(5);
gregeric 0:b9444a40a999 237 }
gregeric 0:b9444a40a999 238 }
gregeric 0:b9444a40a999 239 /******************************************************//**
gregeric 0:b9444a40a999 240 * @brief Returns the acceleration of the specified device
gregeric 0:b9444a40a999 241 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 242 * @retval Acceleration in pps^2
gregeric 0:b9444a40a999 243 **********************************************************/
gregeric 0:b9444a40a999 244 uint16_t BSP_MotorControl_GetAcceleration(uint8_t deviceId)
gregeric 0:b9444a40a999 245 {
gregeric 0:b9444a40a999 246 uint16_t acceleration = 0;
gregeric 0:b9444a40a999 247
gregeric 0:b9444a40a999 248 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetAcceleration != 0))
gregeric 0:b9444a40a999 249 {
gregeric 0:b9444a40a999 250 acceleration = motorDrvHandle->GetAcceleration(deviceId);
gregeric 0:b9444a40a999 251 }
gregeric 0:b9444a40a999 252 else
gregeric 0:b9444a40a999 253 {
gregeric 0:b9444a40a999 254 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(6);
gregeric 0:b9444a40a999 255 }
gregeric 0:b9444a40a999 256 return(acceleration);
gregeric 0:b9444a40a999 257 }
gregeric 0:b9444a40a999 258
gregeric 0:b9444a40a999 259 /******************************************************//**
gregeric 0:b9444a40a999 260 * @brief Get board Id the motor driver
gregeric 0:b9444a40a999 261 * @param None
gregeric 0:b9444a40a999 262 * @retval Motor control board Id
gregeric 0:b9444a40a999 263 **********************************************************/
gregeric 0:b9444a40a999 264 uint16_t BSP_MotorControl_GetBoardId(void)
gregeric 0:b9444a40a999 265 {
gregeric 0:b9444a40a999 266 return (MotorControlBoardId);
gregeric 0:b9444a40a999 267 }
gregeric 0:b9444a40a999 268 /******************************************************//**
gregeric 0:b9444a40a999 269 * @brief Returns the current speed of the specified device
gregeric 0:b9444a40a999 270 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 271 * @retval Speed in pps
gregeric 0:b9444a40a999 272 **********************************************************/
gregeric 0:b9444a40a999 273 uint16_t BSP_MotorControl_GetCurrentSpeed(uint8_t deviceId)
gregeric 0:b9444a40a999 274 {
gregeric 0:b9444a40a999 275 uint16_t currentSpeed = 0;
gregeric 0:b9444a40a999 276 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetCurrentSpeed != 0))
gregeric 0:b9444a40a999 277 {
gregeric 0:b9444a40a999 278 currentSpeed = motorDrvHandle->GetCurrentSpeed(deviceId);
gregeric 0:b9444a40a999 279 }
gregeric 0:b9444a40a999 280 else
gregeric 0:b9444a40a999 281 {
gregeric 0:b9444a40a999 282 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(7);
gregeric 0:b9444a40a999 283 }
gregeric 0:b9444a40a999 284 return(currentSpeed);
gregeric 0:b9444a40a999 285 }
gregeric 0:b9444a40a999 286
gregeric 0:b9444a40a999 287 /******************************************************//**
gregeric 0:b9444a40a999 288 * @brief Returns the deceleration of the specified device
gregeric 0:b9444a40a999 289 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 290 * @retval Deceleration in pps^2
gregeric 0:b9444a40a999 291 **********************************************************/
gregeric 0:b9444a40a999 292 uint16_t BSP_MotorControl_GetDeceleration(uint8_t deviceId)
gregeric 0:b9444a40a999 293 {
gregeric 0:b9444a40a999 294 uint16_t deceleration = 0;
gregeric 0:b9444a40a999 295
gregeric 0:b9444a40a999 296 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetDeceleration != 0))
gregeric 0:b9444a40a999 297 {
gregeric 0:b9444a40a999 298 deceleration = motorDrvHandle->GetDeceleration(deviceId);
gregeric 0:b9444a40a999 299 }
gregeric 0:b9444a40a999 300 else
gregeric 0:b9444a40a999 301 {
gregeric 0:b9444a40a999 302 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(8);
gregeric 0:b9444a40a999 303 }
gregeric 0:b9444a40a999 304 return(deceleration);
gregeric 0:b9444a40a999 305 }
gregeric 0:b9444a40a999 306
gregeric 0:b9444a40a999 307 /******************************************************//**
gregeric 0:b9444a40a999 308 * @brief Returns the device state
gregeric 0:b9444a40a999 309 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 310 * @retval State (ACCELERATING, DECELERATING, STEADY or INACTIVE)
gregeric 0:b9444a40a999 311 **********************************************************/
gregeric 0:b9444a40a999 312 motorState_t BSP_MotorControl_GetDeviceState(uint8_t deviceId)
gregeric 0:b9444a40a999 313 {
gregeric 0:b9444a40a999 314 motorState_t state = INACTIVE;
gregeric 0:b9444a40a999 315
gregeric 0:b9444a40a999 316 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetDeviceState != 0))
gregeric 0:b9444a40a999 317 {
gregeric 0:b9444a40a999 318 state = motorDrvHandle->GetDeviceState(deviceId);
gregeric 0:b9444a40a999 319 }
gregeric 0:b9444a40a999 320 else
gregeric 0:b9444a40a999 321 {
gregeric 0:b9444a40a999 322 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(9);
gregeric 0:b9444a40a999 323 }
gregeric 0:b9444a40a999 324 return(state);
gregeric 0:b9444a40a999 325 }
gregeric 0:b9444a40a999 326
gregeric 0:b9444a40a999 327 /******************************************************//**
gregeric 0:b9444a40a999 328 * @brief Returns the FW version of the library
gregeric 0:b9444a40a999 329 * @param None
gregeric 0:b9444a40a999 330 * @retval BSP_MotorControl_FW_VERSION
gregeric 0:b9444a40a999 331 **********************************************************/
gregeric 0:b9444a40a999 332 uint8_t BSP_MotorControl_GetFwVersion(void)
gregeric 0:b9444a40a999 333 {
gregeric 0:b9444a40a999 334 uint8_t version = 0;
gregeric 0:b9444a40a999 335
gregeric 0:b9444a40a999 336 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetFwVersion != 0))
gregeric 0:b9444a40a999 337 {
gregeric 0:b9444a40a999 338 version = motorDrvHandle->GetFwVersion();
gregeric 0:b9444a40a999 339 }
gregeric 0:b9444a40a999 340 else
gregeric 0:b9444a40a999 341 {
gregeric 0:b9444a40a999 342 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(10);
gregeric 0:b9444a40a999 343 }
gregeric 0:b9444a40a999 344 return(version);
gregeric 0:b9444a40a999 345 }
gregeric 0:b9444a40a999 346
gregeric 0:b9444a40a999 347 /******************************************************//**
gregeric 0:b9444a40a999 348 * @brief Returns the mark position of the specified device
gregeric 0:b9444a40a999 349 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 350 * @retval Mark register value converted in a 32b signed integer
gregeric 0:b9444a40a999 351 **********************************************************/
gregeric 0:b9444a40a999 352 int32_t BSP_MotorControl_GetMark(uint8_t deviceId)
gregeric 0:b9444a40a999 353 {
gregeric 0:b9444a40a999 354 int32_t mark = 0;
gregeric 0:b9444a40a999 355
gregeric 0:b9444a40a999 356 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetMark != 0))
gregeric 0:b9444a40a999 357 {
gregeric 0:b9444a40a999 358 mark = motorDrvHandle->GetMark(deviceId);
gregeric 0:b9444a40a999 359 }
gregeric 0:b9444a40a999 360 else
gregeric 0:b9444a40a999 361 {
gregeric 0:b9444a40a999 362 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(11);
gregeric 0:b9444a40a999 363 }
gregeric 0:b9444a40a999 364 return(mark);
gregeric 0:b9444a40a999 365 }
gregeric 0:b9444a40a999 366
gregeric 0:b9444a40a999 367 /******************************************************//**
gregeric 0:b9444a40a999 368 * @brief Returns the max speed of the specified device
gregeric 0:b9444a40a999 369 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 370 * @retval maxSpeed in pps
gregeric 0:b9444a40a999 371 **********************************************************/
gregeric 0:b9444a40a999 372 uint16_t BSP_MotorControl_GetMaxSpeed(uint8_t deviceId)
gregeric 0:b9444a40a999 373 {
gregeric 0:b9444a40a999 374 uint16_t maxSpeed = 0;
gregeric 0:b9444a40a999 375 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetMaxSpeed != 0))
gregeric 0:b9444a40a999 376 {
gregeric 0:b9444a40a999 377 maxSpeed = motorDrvHandle->GetMaxSpeed(deviceId);
gregeric 0:b9444a40a999 378 }
gregeric 0:b9444a40a999 379 else
gregeric 0:b9444a40a999 380 {
gregeric 0:b9444a40a999 381 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(12);
gregeric 0:b9444a40a999 382 }
gregeric 0:b9444a40a999 383 return(maxSpeed);
gregeric 0:b9444a40a999 384 }
gregeric 0:b9444a40a999 385
gregeric 0:b9444a40a999 386 /******************************************************//**
gregeric 0:b9444a40a999 387 * @brief Returns the min speed of the specified device
gregeric 0:b9444a40a999 388 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 389 * @retval minSpeed in pps
gregeric 0:b9444a40a999 390 **********************************************************/
gregeric 0:b9444a40a999 391 uint16_t BSP_MotorControl_GetMinSpeed(uint8_t deviceId)
gregeric 0:b9444a40a999 392 {
gregeric 0:b9444a40a999 393 uint16_t minSpeed = 0;
gregeric 0:b9444a40a999 394
gregeric 0:b9444a40a999 395 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetMinSpeed != 0))
gregeric 0:b9444a40a999 396 {
gregeric 0:b9444a40a999 397 minSpeed = motorDrvHandle->GetMinSpeed(deviceId);
gregeric 0:b9444a40a999 398 }
gregeric 0:b9444a40a999 399 else
gregeric 0:b9444a40a999 400 {
gregeric 0:b9444a40a999 401 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(13);
gregeric 0:b9444a40a999 402 }
gregeric 0:b9444a40a999 403 return(minSpeed);
gregeric 0:b9444a40a999 404 }
gregeric 0:b9444a40a999 405
gregeric 0:b9444a40a999 406 /******************************************************//**
gregeric 0:b9444a40a999 407 * @brief Returns the ABS_POSITION of the specified device
gregeric 0:b9444a40a999 408 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 409 * @retval ABS_POSITION register value converted in a 32b signed integer
gregeric 0:b9444a40a999 410 **********************************************************/
gregeric 0:b9444a40a999 411 int32_t BSP_MotorControl_GetPosition(uint8_t deviceId)
gregeric 0:b9444a40a999 412 {
gregeric 0:b9444a40a999 413 int32_t pos = 0;
gregeric 0:b9444a40a999 414
gregeric 0:b9444a40a999 415 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetPosition != 0))
gregeric 0:b9444a40a999 416 {
gregeric 0:b9444a40a999 417 pos = motorDrvHandle->GetPosition(deviceId);
gregeric 0:b9444a40a999 418 }
gregeric 0:b9444a40a999 419 else
gregeric 0:b9444a40a999 420 {
gregeric 0:b9444a40a999 421 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(14);
gregeric 0:b9444a40a999 422 }
gregeric 0:b9444a40a999 423 return(pos);
gregeric 0:b9444a40a999 424 }
gregeric 0:b9444a40a999 425
gregeric 0:b9444a40a999 426 /******************************************************//**
gregeric 0:b9444a40a999 427 * @brief Requests the motor to move to the home position (ABS_POSITION = 0)
gregeric 0:b9444a40a999 428 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 429 * @retval None
gregeric 0:b9444a40a999 430 **********************************************************/
gregeric 0:b9444a40a999 431 void BSP_MotorControl_GoHome(uint8_t deviceId)
gregeric 0:b9444a40a999 432 {
gregeric 0:b9444a40a999 433 if ((motorDrvHandle != 0)&&(motorDrvHandle->GoHome != 0))
gregeric 0:b9444a40a999 434 {
gregeric 0:b9444a40a999 435 motorDrvHandle->GoHome(deviceId);
gregeric 0:b9444a40a999 436 }
gregeric 0:b9444a40a999 437 else
gregeric 0:b9444a40a999 438 {
gregeric 0:b9444a40a999 439 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(15);
gregeric 0:b9444a40a999 440 }
gregeric 0:b9444a40a999 441 }
gregeric 0:b9444a40a999 442
gregeric 0:b9444a40a999 443 /******************************************************//**
gregeric 0:b9444a40a999 444 * @brief Requests the motor to move to the mark position
gregeric 0:b9444a40a999 445 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 446 * @retval None
gregeric 0:b9444a40a999 447 **********************************************************/
gregeric 0:b9444a40a999 448 void BSP_MotorControl_GoMark(uint8_t deviceId)
gregeric 0:b9444a40a999 449 {
gregeric 0:b9444a40a999 450 if ((motorDrvHandle != 0)&&(motorDrvHandle->GoMark != 0))
gregeric 0:b9444a40a999 451 {
gregeric 0:b9444a40a999 452 motorDrvHandle->GoMark(deviceId);
gregeric 0:b9444a40a999 453 }
gregeric 0:b9444a40a999 454 else
gregeric 0:b9444a40a999 455 {
gregeric 0:b9444a40a999 456 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(16);
gregeric 0:b9444a40a999 457 }
gregeric 0:b9444a40a999 458 }
gregeric 0:b9444a40a999 459
gregeric 0:b9444a40a999 460 /******************************************************//**
gregeric 0:b9444a40a999 461 * @brief Requests the motor to move to the specified position
gregeric 0:b9444a40a999 462 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 463 * @param[in] targetPosition absolute position in steps
gregeric 0:b9444a40a999 464 * @retval None
gregeric 0:b9444a40a999 465 **********************************************************/
gregeric 0:b9444a40a999 466 void BSP_MotorControl_GoTo(uint8_t deviceId, int32_t targetPosition)
gregeric 0:b9444a40a999 467 {
gregeric 0:b9444a40a999 468 if ((motorDrvHandle != 0)&&(motorDrvHandle->GoTo != 0))
gregeric 0:b9444a40a999 469 {
gregeric 0:b9444a40a999 470 motorDrvHandle->GoTo(deviceId, targetPosition);
gregeric 0:b9444a40a999 471 }
gregeric 0:b9444a40a999 472 else
gregeric 0:b9444a40a999 473 {
gregeric 0:b9444a40a999 474 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(17);
gregeric 0:b9444a40a999 475 }
gregeric 0:b9444a40a999 476 }
gregeric 0:b9444a40a999 477
gregeric 0:b9444a40a999 478 /******************************************************//**
gregeric 0:b9444a40a999 479 * @brief Immediatly stops the motor and disable the power bridge
gregeric 0:b9444a40a999 480 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 481 * @retval None
gregeric 0:b9444a40a999 482 **********************************************************/
gregeric 0:b9444a40a999 483 void BSP_MotorControl_HardStop(uint8_t deviceId)
gregeric 0:b9444a40a999 484 {
gregeric 0:b9444a40a999 485 if ((motorDrvHandle != 0)&&(motorDrvHandle->HardStop != 0))
gregeric 0:b9444a40a999 486 {
gregeric 0:b9444a40a999 487 motorDrvHandle->HardStop(deviceId);
gregeric 0:b9444a40a999 488 }
gregeric 0:b9444a40a999 489 else
gregeric 0:b9444a40a999 490 {
gregeric 0:b9444a40a999 491 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(18);
gregeric 0:b9444a40a999 492 }
gregeric 0:b9444a40a999 493 }
gregeric 0:b9444a40a999 494
gregeric 0:b9444a40a999 495 /******************************************************//**
gregeric 0:b9444a40a999 496 * @brief Moves the motor of the specified number of steps
gregeric 0:b9444a40a999 497 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 498 * @param[in] direction FORWARD or BACKWARD
gregeric 0:b9444a40a999 499 * @param[in] stepCount Number of steps to perform
gregeric 0:b9444a40a999 500 * @retval None
gregeric 0:b9444a40a999 501 **********************************************************/
gregeric 0:b9444a40a999 502 void BSP_MotorControl_Move(uint8_t deviceId, motorDir_t direction, uint32_t stepCount)
gregeric 0:b9444a40a999 503 {
gregeric 0:b9444a40a999 504 if ((motorDrvHandle != 0)&&(motorDrvHandle->Move != 0))
gregeric 0:b9444a40a999 505 {
gregeric 0:b9444a40a999 506 motorDrvHandle->Move(deviceId, direction, stepCount);
gregeric 0:b9444a40a999 507 }
gregeric 0:b9444a40a999 508 else
gregeric 0:b9444a40a999 509 {
gregeric 0:b9444a40a999 510 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(19);
gregeric 0:b9444a40a999 511 }
gregeric 0:b9444a40a999 512 }
gregeric 0:b9444a40a999 513
gregeric 0:b9444a40a999 514 /******************************************************//**
gregeric 0:b9444a40a999 515 * @brief Resets all motor driver devices
gregeric 0:b9444a40a999 516 * @param None
gregeric 0:b9444a40a999 517 * @retval None
gregeric 0:b9444a40a999 518 **********************************************************/
gregeric 0:b9444a40a999 519 void BSP_MotorControl_ResetAllDevices(void)
gregeric 0:b9444a40a999 520 {
gregeric 0:b9444a40a999 521 if ((motorDrvHandle != 0)&&(motorDrvHandle->ResetAllDevices != 0))
gregeric 0:b9444a40a999 522 {
gregeric 0:b9444a40a999 523 motorDrvHandle->ResetAllDevices();
gregeric 0:b9444a40a999 524 }
gregeric 0:b9444a40a999 525 else
gregeric 0:b9444a40a999 526 {
gregeric 0:b9444a40a999 527 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(20);
gregeric 0:b9444a40a999 528 }
gregeric 0:b9444a40a999 529 }
gregeric 0:b9444a40a999 530
gregeric 0:b9444a40a999 531 /******************************************************//**
gregeric 0:b9444a40a999 532 * @brief Runs the motor. It will accelerate from the min
gregeric 0:b9444a40a999 533 * speed up to the max speed by using the device acceleration.
gregeric 0:b9444a40a999 534 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 535 * @param[in] direction FORWARD or BACKWARD
gregeric 0:b9444a40a999 536 * @retval None
gregeric 0:b9444a40a999 537 **********************************************************/
gregeric 0:b9444a40a999 538 void BSP_MotorControl_Run(uint8_t deviceId, motorDir_t direction)
gregeric 0:b9444a40a999 539 {
gregeric 0:b9444a40a999 540 if ((motorDrvHandle != 0)&&(motorDrvHandle->Run != 0))
gregeric 0:b9444a40a999 541 {
gregeric 0:b9444a40a999 542 motorDrvHandle->Run(deviceId, direction);
gregeric 0:b9444a40a999 543 }
gregeric 0:b9444a40a999 544 else
gregeric 0:b9444a40a999 545 {
gregeric 0:b9444a40a999 546 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(21);
gregeric 0:b9444a40a999 547 }
gregeric 0:b9444a40a999 548 }
gregeric 0:b9444a40a999 549 /******************************************************//**
gregeric 0:b9444a40a999 550 * @brief Changes the acceleration of the specified device
gregeric 0:b9444a40a999 551 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 552 * @param[in] newAcc New acceleration to apply in pps^2
gregeric 0:b9444a40a999 553 * @retval true if the command is successfully executed, else false
gregeric 0:b9444a40a999 554 * @note The command is not performed is the device is executing
gregeric 0:b9444a40a999 555 * a MOVE or GOTO command (but it can be used during a RUN command)
gregeric 0:b9444a40a999 556 **********************************************************/
gregeric 0:b9444a40a999 557 bool BSP_MotorControl_SetAcceleration(uint8_t deviceId,uint16_t newAcc)
gregeric 0:b9444a40a999 558 {
gregeric 0:b9444a40a999 559 bool status = FALSE;
gregeric 0:b9444a40a999 560 if ((motorDrvHandle != 0)&&(motorDrvHandle->SetAcceleration != 0))
gregeric 0:b9444a40a999 561 {
gregeric 0:b9444a40a999 562 status = motorDrvHandle->SetAcceleration(deviceId, newAcc);
gregeric 0:b9444a40a999 563 }
gregeric 0:b9444a40a999 564 else
gregeric 0:b9444a40a999 565 {
gregeric 0:b9444a40a999 566 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(22);
gregeric 0:b9444a40a999 567 }
gregeric 0:b9444a40a999 568 return (status);
gregeric 0:b9444a40a999 569 }
gregeric 0:b9444a40a999 570
gregeric 0:b9444a40a999 571 /******************************************************//**
gregeric 0:b9444a40a999 572 * @brief Changes the deceleration of the specified device
gregeric 0:b9444a40a999 573 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 574 * @param[in] newDec New deceleration to apply in pps^2
gregeric 0:b9444a40a999 575 * @retval true if the command is successfully executed, else false
gregeric 0:b9444a40a999 576 * @note The command is not performed is the device is executing
gregeric 0:b9444a40a999 577 * a MOVE or GOTO command (but it can be used during a RUN command)
gregeric 0:b9444a40a999 578 **********************************************************/
gregeric 0:b9444a40a999 579 bool BSP_MotorControl_SetDeceleration(uint8_t deviceId, uint16_t newDec)
gregeric 0:b9444a40a999 580 {
gregeric 0:b9444a40a999 581 bool status = FALSE;
gregeric 0:b9444a40a999 582 if ((motorDrvHandle != 0)&&(motorDrvHandle->SetDeceleration != 0))
gregeric 0:b9444a40a999 583 {
gregeric 0:b9444a40a999 584 status = motorDrvHandle->SetDeceleration(deviceId, newDec);
gregeric 0:b9444a40a999 585 }
gregeric 0:b9444a40a999 586 else
gregeric 0:b9444a40a999 587 {
gregeric 0:b9444a40a999 588 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(23);
gregeric 0:b9444a40a999 589 }
gregeric 0:b9444a40a999 590 return (status);
gregeric 0:b9444a40a999 591 }
gregeric 0:b9444a40a999 592
gregeric 0:b9444a40a999 593 /******************************************************//**
gregeric 0:b9444a40a999 594 * @brief Set current position to be the Home position (ABS pos set to 0)
gregeric 0:b9444a40a999 595 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 596 * @retval None
gregeric 0:b9444a40a999 597 **********************************************************/
gregeric 0:b9444a40a999 598 void BSP_MotorControl_SetHome(uint8_t deviceId)
gregeric 0:b9444a40a999 599 {
gregeric 0:b9444a40a999 600 if ((motorDrvHandle != 0)&&(motorDrvHandle->SetHome != 0))
gregeric 0:b9444a40a999 601 {
gregeric 0:b9444a40a999 602 motorDrvHandle->SetHome(deviceId);
gregeric 0:b9444a40a999 603 }
gregeric 0:b9444a40a999 604 else
gregeric 0:b9444a40a999 605 {
gregeric 0:b9444a40a999 606 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(24);
gregeric 0:b9444a40a999 607 }
gregeric 0:b9444a40a999 608 }
gregeric 0:b9444a40a999 609
gregeric 0:b9444a40a999 610 /******************************************************//**
gregeric 0:b9444a40a999 611 * @brief Sets current position to be the Mark position
gregeric 0:b9444a40a999 612 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 613 * @retval None
gregeric 0:b9444a40a999 614 **********************************************************/
gregeric 0:b9444a40a999 615 void BSP_MotorControl_SetMark(uint8_t deviceId)
gregeric 0:b9444a40a999 616 {
gregeric 0:b9444a40a999 617 if ((motorDrvHandle != 0)&&(motorDrvHandle->SetMark != 0))
gregeric 0:b9444a40a999 618 {
gregeric 0:b9444a40a999 619 motorDrvHandle->SetMark(deviceId);
gregeric 0:b9444a40a999 620 }
gregeric 0:b9444a40a999 621 else
gregeric 0:b9444a40a999 622 {
gregeric 0:b9444a40a999 623 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(25);
gregeric 0:b9444a40a999 624 }
gregeric 0:b9444a40a999 625 }
gregeric 0:b9444a40a999 626
gregeric 0:b9444a40a999 627 /******************************************************//**
gregeric 0:b9444a40a999 628 * @brief Changes the max speed of the specified device
gregeric 0:b9444a40a999 629 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 630 * @param[in] newMaxSpeed New max speed to apply in pps
gregeric 0:b9444a40a999 631 * @retval true if the command is successfully executed, else false
gregeric 0:b9444a40a999 632 * @note The command is not performed is the device is executing
gregeric 0:b9444a40a999 633 * a MOVE or GOTO command (but it can be used during a RUN command).
gregeric 0:b9444a40a999 634 **********************************************************/
gregeric 0:b9444a40a999 635 bool BSP_MotorControl_SetMaxSpeed(uint8_t deviceId, uint16_t newMaxSpeed)
gregeric 0:b9444a40a999 636 {
gregeric 0:b9444a40a999 637 bool status = FALSE;
gregeric 0:b9444a40a999 638 if ((motorDrvHandle != 0)&&(motorDrvHandle->SetMaxSpeed != 0))
gregeric 0:b9444a40a999 639 {
gregeric 0:b9444a40a999 640 status = motorDrvHandle->SetMaxSpeed(deviceId, newMaxSpeed);
gregeric 0:b9444a40a999 641 }
gregeric 0:b9444a40a999 642 else
gregeric 0:b9444a40a999 643 {
gregeric 0:b9444a40a999 644 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(26);
gregeric 0:b9444a40a999 645 }
gregeric 0:b9444a40a999 646 return (status);
gregeric 0:b9444a40a999 647 }
gregeric 0:b9444a40a999 648
gregeric 0:b9444a40a999 649 /******************************************************//**
gregeric 0:b9444a40a999 650 * @brief Changes the min speed of the specified device
gregeric 0:b9444a40a999 651 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 652 * @param[in] newMinSpeed New min speed to apply in pps
gregeric 0:b9444a40a999 653 * @retval true if the command is successfully executed, else false
gregeric 0:b9444a40a999 654 * @note The command is not performed is the device is executing
gregeric 0:b9444a40a999 655 * a MOVE or GOTO command (but it can be used during a RUN command).
gregeric 0:b9444a40a999 656 **********************************************************/
gregeric 0:b9444a40a999 657 bool BSP_MotorControl_SetMinSpeed(uint8_t deviceId, uint16_t newMinSpeed)
gregeric 0:b9444a40a999 658 {
gregeric 0:b9444a40a999 659 bool status = FALSE;
gregeric 0:b9444a40a999 660 if ((motorDrvHandle != 0)&&(motorDrvHandle->SetMinSpeed != 0))
gregeric 0:b9444a40a999 661 {
gregeric 0:b9444a40a999 662 status = motorDrvHandle->SetMinSpeed(deviceId, newMinSpeed);
gregeric 0:b9444a40a999 663 }
gregeric 0:b9444a40a999 664 else
gregeric 0:b9444a40a999 665 {
gregeric 0:b9444a40a999 666 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(27);
gregeric 0:b9444a40a999 667 }
gregeric 0:b9444a40a999 668
gregeric 0:b9444a40a999 669 return (status);
gregeric 0:b9444a40a999 670 }
gregeric 0:b9444a40a999 671
gregeric 0:b9444a40a999 672 /******************************************************//**
gregeric 0:b9444a40a999 673 * @brief Stops the motor by using the device deceleration
gregeric 0:b9444a40a999 674 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 675 * @retval true if the command is successfully executed, else false
gregeric 0:b9444a40a999 676 * @note The command is not performed is the device is in INACTIVE state.
gregeric 0:b9444a40a999 677 **********************************************************/
gregeric 0:b9444a40a999 678 bool BSP_MotorControl_SoftStop(uint8_t deviceId)
gregeric 0:b9444a40a999 679 {
gregeric 0:b9444a40a999 680 bool status = FALSE;
gregeric 0:b9444a40a999 681 if ((motorDrvHandle != 0)&&(motorDrvHandle->SoftStop != 0))
gregeric 0:b9444a40a999 682 {
gregeric 0:b9444a40a999 683 status = motorDrvHandle->SoftStop(deviceId);
gregeric 0:b9444a40a999 684 }
gregeric 0:b9444a40a999 685 else
gregeric 0:b9444a40a999 686 {
gregeric 0:b9444a40a999 687 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(28);
gregeric 0:b9444a40a999 688 }
gregeric 0:b9444a40a999 689 return (status);
gregeric 0:b9444a40a999 690 }
gregeric 0:b9444a40a999 691
gregeric 0:b9444a40a999 692 /******************************************************//**
gregeric 0:b9444a40a999 693 * @brief Handles the device state machine at each ste
gregeric 0:b9444a40a999 694 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 695 * @retval None
gregeric 0:b9444a40a999 696 * @note Must only be called by the timer ISR
gregeric 0:b9444a40a999 697 **********************************************************/
gregeric 0:b9444a40a999 698 void BSP_MotorControl_StepClockHandler(uint8_t deviceId)
gregeric 0:b9444a40a999 699 {
gregeric 0:b9444a40a999 700 if ((motorDrvHandle != 0)&&(motorDrvHandle->StepClockHandler != 0))
gregeric 0:b9444a40a999 701 {
gregeric 0:b9444a40a999 702 motorDrvHandle->StepClockHandler(deviceId);
gregeric 0:b9444a40a999 703 }
gregeric 0:b9444a40a999 704 else
gregeric 0:b9444a40a999 705 {
gregeric 0:b9444a40a999 706 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(29);
gregeric 0:b9444a40a999 707 }
gregeric 0:b9444a40a999 708 }
gregeric 0:b9444a40a999 709 /******************************************************//**
gregeric 0:b9444a40a999 710 * @brief Locks until the device state becomes Inactive
gregeric 0:b9444a40a999 711 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 712 * @retval None
gregeric 0:b9444a40a999 713 **********************************************************/
gregeric 0:b9444a40a999 714 void BSP_MotorControl_WaitWhileActive(uint8_t deviceId)
gregeric 0:b9444a40a999 715 {
gregeric 0:b9444a40a999 716 if ((motorDrvHandle != 0)&&(motorDrvHandle->WaitWhileActive != 0))
gregeric 0:b9444a40a999 717 {
gregeric 0:b9444a40a999 718 motorDrvHandle->WaitWhileActive(deviceId);
gregeric 0:b9444a40a999 719 }
gregeric 0:b9444a40a999 720 else
gregeric 0:b9444a40a999 721 {
gregeric 0:b9444a40a999 722 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(30);
gregeric 0:b9444a40a999 723 }
gregeric 0:b9444a40a999 724 }
gregeric 0:b9444a40a999 725
gregeric 0:b9444a40a999 726 /**
gregeric 0:b9444a40a999 727 * @}
gregeric 0:b9444a40a999 728 */
gregeric 0:b9444a40a999 729
gregeric 0:b9444a40a999 730 /** @defgroup BSP_MotorControl_Control_Functions
gregeric 0:b9444a40a999 731 * @{
gregeric 0:b9444a40a999 732 */
gregeric 0:b9444a40a999 733
gregeric 0:b9444a40a999 734 /******************************************************//**
gregeric 0:b9444a40a999 735 * @brief Issue the Disable command to the motor driver of the specified device
gregeric 0:b9444a40a999 736 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 737 * @retval None
gregeric 0:b9444a40a999 738 **********************************************************/
gregeric 0:b9444a40a999 739 void BSP_MotorControl_CmdDisable(uint8_t deviceId)
gregeric 0:b9444a40a999 740 {
gregeric 0:b9444a40a999 741 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdDisable != 0))
gregeric 0:b9444a40a999 742 {
gregeric 0:b9444a40a999 743 motorDrvHandle->CmdDisable(deviceId);
gregeric 0:b9444a40a999 744 }
gregeric 0:b9444a40a999 745 else
gregeric 0:b9444a40a999 746 {
gregeric 0:b9444a40a999 747 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(31);
gregeric 0:b9444a40a999 748 }
gregeric 0:b9444a40a999 749 }
gregeric 0:b9444a40a999 750
gregeric 0:b9444a40a999 751 /******************************************************//**
gregeric 0:b9444a40a999 752 * @brief Issues the Enable command to the motor driver of the specified device
gregeric 0:b9444a40a999 753 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 754 * @retval None
gregeric 0:b9444a40a999 755 **********************************************************/
gregeric 0:b9444a40a999 756 void BSP_MotorControl_CmdEnable(uint8_t deviceId)
gregeric 0:b9444a40a999 757 {
gregeric 0:b9444a40a999 758 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdEnable != 0))
gregeric 0:b9444a40a999 759 {
gregeric 0:b9444a40a999 760 motorDrvHandle->CmdEnable(deviceId);
gregeric 0:b9444a40a999 761 }
gregeric 0:b9444a40a999 762 else
gregeric 0:b9444a40a999 763 {
gregeric 0:b9444a40a999 764 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(32);
gregeric 0:b9444a40a999 765 }
gregeric 0:b9444a40a999 766 }
gregeric 0:b9444a40a999 767
gregeric 0:b9444a40a999 768 /******************************************************//**
gregeric 0:b9444a40a999 769 * @brief Issues the GetParam command to the motor driver of the specified device
gregeric 0:b9444a40a999 770 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 771 * @param[in] param Register adress (BSP_MotorControl_ABS_POS, BSP_MotorControl_MARK,...)
gregeric 0:b9444a40a999 772 * @retval Register value
gregeric 0:b9444a40a999 773 **********************************************************/
gregeric 0:b9444a40a999 774 uint32_t BSP_MotorControl_CmdGetParam(uint8_t deviceId,
gregeric 0:b9444a40a999 775 uint32_t param)
gregeric 0:b9444a40a999 776 {
gregeric 0:b9444a40a999 777 uint32_t value = 0;
gregeric 0:b9444a40a999 778 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGetParam != 0))
gregeric 0:b9444a40a999 779 {
gregeric 0:b9444a40a999 780 value = motorDrvHandle->CmdGetParam(deviceId, param);
gregeric 0:b9444a40a999 781 }
gregeric 0:b9444a40a999 782 else
gregeric 0:b9444a40a999 783 {
gregeric 0:b9444a40a999 784 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(33);
gregeric 0:b9444a40a999 785 }
gregeric 0:b9444a40a999 786 return (value);
gregeric 0:b9444a40a999 787 }
gregeric 0:b9444a40a999 788
gregeric 0:b9444a40a999 789 /******************************************************//**
gregeric 0:b9444a40a999 790 * @brief Issues the GetStatus command to the motor driver of the specified device
gregeric 0:b9444a40a999 791 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 792 * @retval Status Register value
gregeric 0:b9444a40a999 793 * @note Once the GetStatus command is performed, the flags of the status register
gregeric 0:b9444a40a999 794 * are reset. This is not the case when the status register is read with the
gregeric 0:b9444a40a999 795 * GetParam command (via the functions ReadStatusRegister or CmdGetParam).
gregeric 0:b9444a40a999 796 **********************************************************/
gregeric 0:b9444a40a999 797 uint16_t BSP_MotorControl_CmdGetStatus(uint8_t deviceId)
gregeric 0:b9444a40a999 798 {
gregeric 0:b9444a40a999 799 uint16_t status = 0;
gregeric 0:b9444a40a999 800 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGetStatus != 0))
gregeric 0:b9444a40a999 801 {
gregeric 0:b9444a40a999 802 status = motorDrvHandle->CmdGetStatus(deviceId);
gregeric 0:b9444a40a999 803 }
gregeric 0:b9444a40a999 804 else
gregeric 0:b9444a40a999 805 {
gregeric 0:b9444a40a999 806 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(34);
gregeric 0:b9444a40a999 807 }
gregeric 0:b9444a40a999 808 return (status);
gregeric 0:b9444a40a999 809 }
gregeric 0:b9444a40a999 810
gregeric 0:b9444a40a999 811 /******************************************************//**
gregeric 0:b9444a40a999 812 * @brief Issues the Nop command to the motor driver of the specified device
gregeric 0:b9444a40a999 813 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 814 * @retval None
gregeric 0:b9444a40a999 815 **********************************************************/
gregeric 0:b9444a40a999 816 void BSP_MotorControl_CmdNop(uint8_t deviceId)
gregeric 0:b9444a40a999 817 {
gregeric 0:b9444a40a999 818 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdNop != 0))
gregeric 0:b9444a40a999 819 {
gregeric 0:b9444a40a999 820 motorDrvHandle->CmdNop(deviceId);
gregeric 0:b9444a40a999 821 }
gregeric 0:b9444a40a999 822 else
gregeric 0:b9444a40a999 823 {
gregeric 0:b9444a40a999 824 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(35);
gregeric 0:b9444a40a999 825 }
gregeric 0:b9444a40a999 826 }
gregeric 0:b9444a40a999 827
gregeric 0:b9444a40a999 828 /******************************************************//**
gregeric 0:b9444a40a999 829 * @brief Issues the SetParam command to the motor driver of the specified device
gregeric 0:b9444a40a999 830 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 831 * @param[in] param Register adress (BSP_MotorControl_ABS_POS, BSP_MotorControl_MARK,...)
gregeric 0:b9444a40a999 832 * @param[in] value Value to set in the register
gregeric 0:b9444a40a999 833 * @retval None
gregeric 0:b9444a40a999 834 **********************************************************/
gregeric 0:b9444a40a999 835 void BSP_MotorControl_CmdSetParam(uint8_t deviceId,
gregeric 0:b9444a40a999 836 uint32_t param,
gregeric 0:b9444a40a999 837 uint32_t value)
gregeric 0:b9444a40a999 838 {
gregeric 0:b9444a40a999 839 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdSetParam != 0))
gregeric 0:b9444a40a999 840 {
gregeric 0:b9444a40a999 841 motorDrvHandle->CmdSetParam(deviceId, param, value);
gregeric 0:b9444a40a999 842 }
gregeric 0:b9444a40a999 843 else
gregeric 0:b9444a40a999 844 {
gregeric 0:b9444a40a999 845 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(36);
gregeric 0:b9444a40a999 846 }
gregeric 0:b9444a40a999 847 }
gregeric 0:b9444a40a999 848
gregeric 0:b9444a40a999 849 /******************************************************//**
gregeric 0:b9444a40a999 850 * @brief Reads the Status Register value
gregeric 0:b9444a40a999 851 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 852 * @retval Status register valued
gregeric 0:b9444a40a999 853 * @note The status register flags are not cleared
gregeric 0:b9444a40a999 854 * at the difference with CmdGetStatus()
gregeric 0:b9444a40a999 855 **********************************************************/
gregeric 0:b9444a40a999 856 uint16_t BSP_MotorControl_ReadStatusRegister(uint8_t deviceId)
gregeric 0:b9444a40a999 857 {
gregeric 0:b9444a40a999 858 uint16_t status = 0;
gregeric 0:b9444a40a999 859 if ((motorDrvHandle != 0)&&(motorDrvHandle->ReadStatusRegister != 0))
gregeric 0:b9444a40a999 860 {
gregeric 0:b9444a40a999 861 status = motorDrvHandle->ReadStatusRegister(deviceId);
gregeric 0:b9444a40a999 862 }
gregeric 0:b9444a40a999 863 else
gregeric 0:b9444a40a999 864 {
gregeric 0:b9444a40a999 865 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(37);
gregeric 0:b9444a40a999 866 }
gregeric 0:b9444a40a999 867 return (status);
gregeric 0:b9444a40a999 868 }
gregeric 0:b9444a40a999 869
gregeric 0:b9444a40a999 870 /******************************************************//**
gregeric 0:b9444a40a999 871 * @brief Releases the motor driver (pin set to High) of all devices
gregeric 0:b9444a40a999 872 * @param None
gregeric 0:b9444a40a999 873 * @retval None
gregeric 0:b9444a40a999 874 **********************************************************/
gregeric 0:b9444a40a999 875 void BSP_MotorControl_ReleaseReset(void)
gregeric 0:b9444a40a999 876 {
gregeric 0:b9444a40a999 877 if ((motorDrvHandle != 0)&&(motorDrvHandle->ReleaseReset != 0))
gregeric 0:b9444a40a999 878 {
gregeric 0:b9444a40a999 879 motorDrvHandle->ReleaseReset();
gregeric 0:b9444a40a999 880 }
gregeric 0:b9444a40a999 881 else
gregeric 0:b9444a40a999 882 {
gregeric 0:b9444a40a999 883 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(38);
gregeric 0:b9444a40a999 884 }
gregeric 0:b9444a40a999 885 }
gregeric 0:b9444a40a999 886
gregeric 0:b9444a40a999 887 /******************************************************//**
gregeric 0:b9444a40a999 888 * @brief Resets the motor driver (reset pin set to low) of all devices
gregeric 0:b9444a40a999 889 * @param None
gregeric 0:b9444a40a999 890 * @retval None
gregeric 0:b9444a40a999 891 **********************************************************/
gregeric 0:b9444a40a999 892 void BSP_MotorControl_Reset(void)
gregeric 0:b9444a40a999 893 {
gregeric 0:b9444a40a999 894 if ((motorDrvHandle != 0)&&(motorDrvHandle->Reset != 0))
gregeric 0:b9444a40a999 895 {
gregeric 0:b9444a40a999 896 motorDrvHandle->Reset();
gregeric 0:b9444a40a999 897 }
gregeric 0:b9444a40a999 898 else
gregeric 0:b9444a40a999 899 {
gregeric 0:b9444a40a999 900 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(39);
gregeric 0:b9444a40a999 901 }
gregeric 0:b9444a40a999 902 }
gregeric 0:b9444a40a999 903
gregeric 0:b9444a40a999 904 /******************************************************//**
gregeric 0:b9444a40a999 905 * @brief Set the stepping mode
gregeric 0:b9444a40a999 906 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 907 * @param[in] stepMod from full step to 1/16 microstep as specified in enum BSP_MotorControl_STEP_SEL_t
gregeric 0:b9444a40a999 908 * @retval None
gregeric 0:b9444a40a999 909 **********************************************************/
gregeric 0:b9444a40a999 910 void BSP_MotorControl_SelectStepMode(uint8_t deviceId, motorStepMode_t stepMod)
gregeric 0:b9444a40a999 911 {
gregeric 0:b9444a40a999 912 if ((motorDrvHandle != 0)&&(motorDrvHandle->SelectStepMode != 0))
gregeric 0:b9444a40a999 913 {
gregeric 0:b9444a40a999 914 motorDrvHandle->SelectStepMode(deviceId, stepMod);
gregeric 0:b9444a40a999 915 }
gregeric 0:b9444a40a999 916 else
gregeric 0:b9444a40a999 917 {
gregeric 0:b9444a40a999 918 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(40);
gregeric 0:b9444a40a999 919 }
gregeric 0:b9444a40a999 920 }
gregeric 0:b9444a40a999 921
gregeric 0:b9444a40a999 922 /******************************************************//**
gregeric 0:b9444a40a999 923 * @brief Specifies the direction
gregeric 0:b9444a40a999 924 * @param[in] deviceId (from 0 to 2)
gregeric 0:b9444a40a999 925 * @param[in] dir FORWARD or BACKWARD
gregeric 0:b9444a40a999 926 * @note The direction change is only applied if the device
gregeric 0:b9444a40a999 927 * is in INACTIVE state
gregeric 0:b9444a40a999 928 * @retval None
gregeric 0:b9444a40a999 929 **********************************************************/
gregeric 0:b9444a40a999 930 void BSP_MotorControl_SetDirection(uint8_t deviceId, motorDir_t dir)
gregeric 0:b9444a40a999 931 {
gregeric 0:b9444a40a999 932 if ((motorDrvHandle != 0)&&(motorDrvHandle->SetDirection != 0))
gregeric 0:b9444a40a999 933 {
gregeric 0:b9444a40a999 934 motorDrvHandle->SetDirection(deviceId, dir);
gregeric 0:b9444a40a999 935 }
gregeric 0:b9444a40a999 936 else
gregeric 0:b9444a40a999 937 {
gregeric 0:b9444a40a999 938 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(41);
gregeric 0:b9444a40a999 939 }
gregeric 0:b9444a40a999 940 }
gregeric 0:b9444a40a999 941
gregeric 0:b9444a40a999 942 /******************************************************//**
gregeric 0:b9444a40a999 943 * @brief Issues Go To Dir command
gregeric 0:b9444a40a999 944 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 945 * @param[in] dir movement direction
gregeric 0:b9444a40a999 946 * @param[in] abs_pos absolute position where requested to move
gregeric 0:b9444a40a999 947 * @retval None
gregeric 0:b9444a40a999 948 **********************************************************/
gregeric 0:b9444a40a999 949 void BSP_MotorControl_CmdGoToDir(uint8_t deviceId, motorDir_t dir, int32_t abs_pos)
gregeric 0:b9444a40a999 950 {
gregeric 0:b9444a40a999 951 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGoToDir != 0))
gregeric 0:b9444a40a999 952 {
gregeric 0:b9444a40a999 953 motorDrvHandle->CmdGoToDir(deviceId, dir, abs_pos);
gregeric 0:b9444a40a999 954 }
gregeric 0:b9444a40a999 955 else
gregeric 0:b9444a40a999 956 {
gregeric 0:b9444a40a999 957 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(42);
gregeric 0:b9444a40a999 958 }
gregeric 0:b9444a40a999 959 }
gregeric 0:b9444a40a999 960
gregeric 0:b9444a40a999 961 /******************************************************//**
gregeric 0:b9444a40a999 962 * @brief Checks if at least one device is busy by checking
gregeric 0:b9444a40a999 963 * busy pin position.
gregeric 0:b9444a40a999 964 * The busy pin is shared between all devices.
gregeric 0:b9444a40a999 965 * @param None
gregeric 0:b9444a40a999 966 * @retval One if at least one device is busy, otherwise zero
gregeric 0:b9444a40a999 967 **********************************************************/
gregeric 0:b9444a40a999 968 uint8_t BSP_MotorControl_CheckBusyHw(void)
gregeric 0:b9444a40a999 969 {
gregeric 0:b9444a40a999 970 uint8_t value = 0;
gregeric 0:b9444a40a999 971 if ((motorDrvHandle != 0)&&(motorDrvHandle->CheckBusyHw != 0))
gregeric 0:b9444a40a999 972 {
gregeric 0:b9444a40a999 973 value = motorDrvHandle->CheckBusyHw();
gregeric 0:b9444a40a999 974 }
gregeric 0:b9444a40a999 975 else
gregeric 0:b9444a40a999 976 {
gregeric 0:b9444a40a999 977 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(43);
gregeric 0:b9444a40a999 978 }
gregeric 0:b9444a40a999 979 return (value);
gregeric 0:b9444a40a999 980 }
gregeric 0:b9444a40a999 981
gregeric 0:b9444a40a999 982 /******************************************************//**
gregeric 0:b9444a40a999 983 * @brief Checks if at least one device has an alarm flag set
gregeric 0:b9444a40a999 984 * by reading flag pin position.
gregeric 0:b9444a40a999 985 * The flag pin is shared between all devices.
gregeric 0:b9444a40a999 986 * @param None
gregeric 0:b9444a40a999 987 * @retval One if at least one device has an alarm flag set ,
gregeric 0:b9444a40a999 988 * otherwise zero
gregeric 0:b9444a40a999 989 **********************************************************/
gregeric 0:b9444a40a999 990 uint8_t BSP_MotorControl_CheckStatusHw(void)
gregeric 0:b9444a40a999 991 {
gregeric 0:b9444a40a999 992 uint8_t value = 0;
gregeric 0:b9444a40a999 993 if ((motorDrvHandle != 0)&&(motorDrvHandle->CheckStatusHw != 0))
gregeric 0:b9444a40a999 994 {
gregeric 0:b9444a40a999 995 value = motorDrvHandle->CheckStatusHw();
gregeric 0:b9444a40a999 996 }
gregeric 0:b9444a40a999 997 else
gregeric 0:b9444a40a999 998 {
gregeric 0:b9444a40a999 999 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(44);
gregeric 0:b9444a40a999 1000 }
gregeric 0:b9444a40a999 1001 return (value);
gregeric 0:b9444a40a999 1002 }
gregeric 0:b9444a40a999 1003
gregeric 0:b9444a40a999 1004 /******************************************************//**
gregeric 0:b9444a40a999 1005 * @brief Issues Go Until command
gregeric 0:b9444a40a999 1006 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1007 * @param[in] action ACTION_RESET or ACTION_COPY
gregeric 0:b9444a40a999 1008 * @param[in] dir movement direction
gregeric 0:b9444a40a999 1009 * @param[in] speed
gregeric 0:b9444a40a999 1010 * @retval None
gregeric 0:b9444a40a999 1011 **********************************************************/
gregeric 0:b9444a40a999 1012 void BSP_MotorControl_CmdGoUntil(uint8_t deviceId, motorAction_t action, motorDir_t dir, uint32_t speed)
gregeric 0:b9444a40a999 1013 {
gregeric 0:b9444a40a999 1014 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGoUntil != 0))
gregeric 0:b9444a40a999 1015 {
gregeric 0:b9444a40a999 1016 motorDrvHandle->CmdGoUntil(deviceId, action, dir, speed);
gregeric 0:b9444a40a999 1017 }
gregeric 0:b9444a40a999 1018 else
gregeric 0:b9444a40a999 1019 {
gregeric 0:b9444a40a999 1020 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(45);
gregeric 0:b9444a40a999 1021 }
gregeric 0:b9444a40a999 1022 }
gregeric 0:b9444a40a999 1023
gregeric 0:b9444a40a999 1024 /******************************************************//**
gregeric 0:b9444a40a999 1025 * @brief Issues Hard HiZ command
gregeric 0:b9444a40a999 1026 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1027 * @retval None
gregeric 0:b9444a40a999 1028 **********************************************************/
gregeric 0:b9444a40a999 1029 void BSP_MotorControl_CmdHardHiZ(uint8_t deviceId)
gregeric 0:b9444a40a999 1030 {
gregeric 0:b9444a40a999 1031 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdHardHiZ != 0))
gregeric 0:b9444a40a999 1032 {
gregeric 0:b9444a40a999 1033 motorDrvHandle->CmdHardHiZ(deviceId);
gregeric 0:b9444a40a999 1034 }
gregeric 0:b9444a40a999 1035 else
gregeric 0:b9444a40a999 1036 {
gregeric 0:b9444a40a999 1037 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(46);
gregeric 0:b9444a40a999 1038 }
gregeric 0:b9444a40a999 1039 }
gregeric 0:b9444a40a999 1040
gregeric 0:b9444a40a999 1041 /******************************************************//**
gregeric 0:b9444a40a999 1042 * @brief Issues Release SW command
gregeric 0:b9444a40a999 1043 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1044 * @param[in] action
gregeric 0:b9444a40a999 1045 * @param[in] dir movement direction
gregeric 0:b9444a40a999 1046 * @retval None
gregeric 0:b9444a40a999 1047 **********************************************************/
gregeric 0:b9444a40a999 1048 void BSP_MotorControl_CmdReleaseSw(uint8_t deviceId, motorAction_t action, motorDir_t dir)
gregeric 0:b9444a40a999 1049 {
gregeric 0:b9444a40a999 1050 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdReleaseSw != 0))
gregeric 0:b9444a40a999 1051 {
gregeric 0:b9444a40a999 1052 motorDrvHandle->CmdReleaseSw(deviceId, action, dir);
gregeric 0:b9444a40a999 1053 }
gregeric 0:b9444a40a999 1054 else
gregeric 0:b9444a40a999 1055 {
gregeric 0:b9444a40a999 1056 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(47);
gregeric 0:b9444a40a999 1057 }
gregeric 0:b9444a40a999 1058 }
gregeric 0:b9444a40a999 1059
gregeric 0:b9444a40a999 1060 /******************************************************//**
gregeric 0:b9444a40a999 1061 * @brief Issues Reset Device command
gregeric 0:b9444a40a999 1062 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1063 * @retval None
gregeric 0:b9444a40a999 1064 **********************************************************/
gregeric 0:b9444a40a999 1065 void BSP_MotorControl_CmdResetDevice(uint8_t deviceId)
gregeric 0:b9444a40a999 1066 {
gregeric 0:b9444a40a999 1067 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdResetDevice != 0))
gregeric 0:b9444a40a999 1068 {
gregeric 0:b9444a40a999 1069 motorDrvHandle->CmdResetDevice(deviceId);
gregeric 0:b9444a40a999 1070 }
gregeric 0:b9444a40a999 1071 else
gregeric 0:b9444a40a999 1072 {
gregeric 0:b9444a40a999 1073 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(48);
gregeric 0:b9444a40a999 1074 }
gregeric 0:b9444a40a999 1075 }
gregeric 0:b9444a40a999 1076
gregeric 0:b9444a40a999 1077 /******************************************************//**
gregeric 0:b9444a40a999 1078 * @brief Issues Reset Pos command
gregeric 0:b9444a40a999 1079 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1080 * @retval None
gregeric 0:b9444a40a999 1081 **********************************************************/
gregeric 0:b9444a40a999 1082 void BSP_MotorControl_CmdResetPos(uint8_t deviceId)
gregeric 0:b9444a40a999 1083 {
gregeric 0:b9444a40a999 1084 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdResetPos != 0))
gregeric 0:b9444a40a999 1085 {
gregeric 0:b9444a40a999 1086 motorDrvHandle->CmdResetPos(deviceId);
gregeric 0:b9444a40a999 1087 }
gregeric 0:b9444a40a999 1088 else
gregeric 0:b9444a40a999 1089 {
gregeric 0:b9444a40a999 1090 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(49);
gregeric 0:b9444a40a999 1091 }
gregeric 0:b9444a40a999 1092 }
gregeric 0:b9444a40a999 1093
gregeric 0:b9444a40a999 1094 /******************************************************//**
gregeric 0:b9444a40a999 1095 * @brief Issues Run command
gregeric 0:b9444a40a999 1096 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1097 * @param[in] dir Movement direction (FORWARD, BACKWARD)
gregeric 0:b9444a40a999 1098 * @param[in] speed in steps/s
gregeric 0:b9444a40a999 1099 * @retval None
gregeric 0:b9444a40a999 1100 **********************************************************/
gregeric 0:b9444a40a999 1101 void BSP_MotorControl_CmdRun(uint8_t deviceId, motorDir_t dir, uint32_t speed)
gregeric 0:b9444a40a999 1102 {
gregeric 0:b9444a40a999 1103 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdRun != 0))
gregeric 0:b9444a40a999 1104 {
gregeric 0:b9444a40a999 1105 motorDrvHandle->CmdRun(deviceId, dir, speed);
gregeric 0:b9444a40a999 1106 }
gregeric 0:b9444a40a999 1107 else
gregeric 0:b9444a40a999 1108 {
gregeric 0:b9444a40a999 1109 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(50);
gregeric 0:b9444a40a999 1110 }
gregeric 0:b9444a40a999 1111 }
gregeric 0:b9444a40a999 1112
gregeric 0:b9444a40a999 1113 /******************************************************//**
gregeric 0:b9444a40a999 1114 * @brief Issues Soft HiZ command
gregeric 0:b9444a40a999 1115 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1116 * @retval None
gregeric 0:b9444a40a999 1117 **********************************************************/
gregeric 0:b9444a40a999 1118 void BSP_MotorControl_CmdSoftHiZ(uint8_t deviceId)
gregeric 0:b9444a40a999 1119 {
gregeric 0:b9444a40a999 1120 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdSoftHiZ != 0))
gregeric 0:b9444a40a999 1121 {
gregeric 0:b9444a40a999 1122 motorDrvHandle->CmdSoftHiZ(deviceId);
gregeric 0:b9444a40a999 1123 }
gregeric 0:b9444a40a999 1124 else
gregeric 0:b9444a40a999 1125 {
gregeric 0:b9444a40a999 1126 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(51);
gregeric 0:b9444a40a999 1127 }
gregeric 0:b9444a40a999 1128 }
gregeric 0:b9444a40a999 1129
gregeric 0:b9444a40a999 1130 /******************************************************//**
gregeric 0:b9444a40a999 1131 * @brief Issues Step Clock command
gregeric 0:b9444a40a999 1132 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1133 * @param[in] dir Movement direction (FORWARD, BACKWARD)
gregeric 0:b9444a40a999 1134 * @retval None
gregeric 0:b9444a40a999 1135 **********************************************************/
gregeric 0:b9444a40a999 1136 void BSP_MotorControl_CmdStepClock(uint8_t deviceId, motorDir_t dir)
gregeric 0:b9444a40a999 1137 {
gregeric 0:b9444a40a999 1138 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdStepClock != 0))
gregeric 0:b9444a40a999 1139 {
gregeric 0:b9444a40a999 1140 motorDrvHandle->CmdStepClock(deviceId, dir);
gregeric 0:b9444a40a999 1141 }
gregeric 0:b9444a40a999 1142 else
gregeric 0:b9444a40a999 1143 {
gregeric 0:b9444a40a999 1144 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(52);
gregeric 0:b9444a40a999 1145 }
gregeric 0:b9444a40a999 1146 }
gregeric 0:b9444a40a999 1147
gregeric 0:b9444a40a999 1148 /******************************************************//**
gregeric 0:b9444a40a999 1149 * @brief Fetch and clear status flags of all devices
gregeric 0:b9444a40a999 1150 * by issuing a GET_STATUS command simultaneously
gregeric 0:b9444a40a999 1151 * to all devices.
gregeric 0:b9444a40a999 1152 * Then, the fetched status of each device can be retrieved
gregeric 0:b9444a40a999 1153 * by using the BSP_MotorControl_GetFetchedStatus function
gregeric 0:b9444a40a999 1154 * provided there is no other calls to functions which
gregeric 0:b9444a40a999 1155 * use the SPI in between.
gregeric 0:b9444a40a999 1156 * @param None
gregeric 0:b9444a40a999 1157 * @retval None
gregeric 0:b9444a40a999 1158 **********************************************************/
gregeric 0:b9444a40a999 1159 void BSP_MotorControl_FetchAndClearAllStatus(void)
gregeric 0:b9444a40a999 1160 {
gregeric 0:b9444a40a999 1161 if ((motorDrvHandle != 0)&&(motorDrvHandle->FetchAndClearAllStatus != 0))
gregeric 0:b9444a40a999 1162 {
gregeric 0:b9444a40a999 1163 motorDrvHandle->FetchAndClearAllStatus();
gregeric 0:b9444a40a999 1164 }
gregeric 0:b9444a40a999 1165 else
gregeric 0:b9444a40a999 1166 {
gregeric 0:b9444a40a999 1167 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(53);
gregeric 0:b9444a40a999 1168 }
gregeric 0:b9444a40a999 1169 }
gregeric 0:b9444a40a999 1170
gregeric 0:b9444a40a999 1171 /******************************************************//**
gregeric 0:b9444a40a999 1172 * @brief Get the value of the STATUS register which was
gregeric 0:b9444a40a999 1173 * fetched by using BSP_MotorControl_FetchAndClearAllStatus.
gregeric 0:b9444a40a999 1174 * The fetched values are available as long as there
gregeric 0:b9444a40a999 1175 * no other calls to functions which use the SPI.
gregeric 0:b9444a40a999 1176 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1177 * @retval Last fetched value of the STATUS register
gregeric 0:b9444a40a999 1178 **********************************************************/
gregeric 0:b9444a40a999 1179 uint16_t BSP_MotorControl_GetFetchedStatus(uint8_t deviceId)
gregeric 0:b9444a40a999 1180 {
gregeric 0:b9444a40a999 1181 uint16_t value = 0;
gregeric 0:b9444a40a999 1182 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetFetchedStatus != 0))
gregeric 0:b9444a40a999 1183 {
gregeric 0:b9444a40a999 1184 value = motorDrvHandle->GetFetchedStatus(deviceId);
gregeric 0:b9444a40a999 1185 }
gregeric 0:b9444a40a999 1186 else
gregeric 0:b9444a40a999 1187 {
gregeric 0:b9444a40a999 1188 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(54);
gregeric 0:b9444a40a999 1189 }
gregeric 0:b9444a40a999 1190 return (value);
gregeric 0:b9444a40a999 1191 }
gregeric 0:b9444a40a999 1192
gregeric 0:b9444a40a999 1193 /******************************************************//**
gregeric 0:b9444a40a999 1194 * @brief Return the number of devices in the daisy chain
gregeric 0:b9444a40a999 1195 * @param None
gregeric 0:b9444a40a999 1196 * @retval number of devices from 1 to MAX_NUMBER_OF_DEVICES
gregeric 0:b9444a40a999 1197 **********************************************************/
gregeric 0:b9444a40a999 1198 uint8_t BSP_MotorControl_GetNbDevices(void)
gregeric 0:b9444a40a999 1199 {
gregeric 0:b9444a40a999 1200 uint8_t value = 0;
gregeric 0:b9444a40a999 1201 if ((motorDrvHandle != 0)&&(motorDrvHandle->GetNbDevices != 0))
gregeric 0:b9444a40a999 1202 {
gregeric 0:b9444a40a999 1203 value = motorDrvHandle->GetNbDevices();
gregeric 0:b9444a40a999 1204 }
gregeric 0:b9444a40a999 1205 else
gregeric 0:b9444a40a999 1206 {
gregeric 0:b9444a40a999 1207 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(55);
gregeric 0:b9444a40a999 1208 }
gregeric 0:b9444a40a999 1209 return (value);
gregeric 0:b9444a40a999 1210 }
gregeric 0:b9444a40a999 1211
gregeric 0:b9444a40a999 1212 /******************************************************//**
gregeric 0:b9444a40a999 1213 * @brief Checks if the specified device is busy
gregeric 0:b9444a40a999 1214 * by reading the Busy flag bit ot its status Register
gregeric 0:b9444a40a999 1215 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1216 * @retval true if device is busy, false zero
gregeric 0:b9444a40a999 1217 **********************************************************/
gregeric 0:b9444a40a999 1218 bool BSP_MotorControl_IsDeviceBusy(uint8_t deviceId)
gregeric 0:b9444a40a999 1219 {
gregeric 0:b9444a40a999 1220 bool value = 0;
gregeric 0:b9444a40a999 1221 if ((motorDrvHandle != 0)&&(motorDrvHandle->IsDeviceBusy != 0))
gregeric 0:b9444a40a999 1222 {
gregeric 0:b9444a40a999 1223 value = motorDrvHandle->IsDeviceBusy(deviceId);
gregeric 0:b9444a40a999 1224 }
gregeric 0:b9444a40a999 1225 else
gregeric 0:b9444a40a999 1226 {
gregeric 0:b9444a40a999 1227 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(56);
gregeric 0:b9444a40a999 1228 }
gregeric 0:b9444a40a999 1229 return (value);
gregeric 0:b9444a40a999 1230 }
gregeric 0:b9444a40a999 1231
gregeric 0:b9444a40a999 1232 /******************************************************//**
gregeric 0:b9444a40a999 1233 * @brief Sends commands stored in the queue by previously
gregeric 0:b9444a40a999 1234 * Powerstep01_QueueCommands
gregeric 0:b9444a40a999 1235 * @param None
gregeric 0:b9444a40a999 1236 * @retval None
gregeric 0:b9444a40a999 1237 *********************************************************/
gregeric 0:b9444a40a999 1238 void BSP_MotorControl_SendQueuedCommands(void)
gregeric 0:b9444a40a999 1239 {
gregeric 0:b9444a40a999 1240 if ((motorDrvHandle != 0)&&(motorDrvHandle->SendQueuedCommands != 0))
gregeric 0:b9444a40a999 1241 {
gregeric 0:b9444a40a999 1242 motorDrvHandle->SendQueuedCommands();
gregeric 0:b9444a40a999 1243 }
gregeric 0:b9444a40a999 1244 else
gregeric 0:b9444a40a999 1245 {
gregeric 0:b9444a40a999 1246 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(57);
gregeric 0:b9444a40a999 1247 }
gregeric 0:b9444a40a999 1248 }
gregeric 0:b9444a40a999 1249
gregeric 0:b9444a40a999 1250 /******************************************************//**
gregeric 0:b9444a40a999 1251 * @brief Put commands in queue before synchronous sending
gregeric 0:b9444a40a999 1252 * done by calling BSP_MotorControl_SendQueuedCommands.
gregeric 0:b9444a40a999 1253 * Any call to functions that use the SPI between the calls of
gregeric 0:b9444a40a999 1254 * BSP_MotorControl_QueueCommands and BSP_MotorControl_SendQueuedCommands
gregeric 0:b9444a40a999 1255 * will corrupt the queue.
gregeric 0:b9444a40a999 1256 * A command for each device of the daisy chain must be
gregeric 0:b9444a40a999 1257 * specified before calling BSP_MotorControl_SendQueuedCommands.
gregeric 0:b9444a40a999 1258 * @param[in] deviceId deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1259 * @param[in] param Command to queue (all BSP_MotorControl commmands
gregeric 0:b9444a40a999 1260 * except SET_PARAM, GET_PARAM, GET_STATUS)
gregeric 0:b9444a40a999 1261 * @param[in] value argument of the command to queue
gregeric 0:b9444a40a999 1262 * @retval None
gregeric 0:b9444a40a999 1263 *********************************************************/
gregeric 0:b9444a40a999 1264 void BSP_MotorControl_QueueCommands(uint8_t deviceId, uint8_t param, uint32_t value)
gregeric 0:b9444a40a999 1265 {
gregeric 0:b9444a40a999 1266 if ((motorDrvHandle != 0)&&(motorDrvHandle->QueueCommands != 0))
gregeric 0:b9444a40a999 1267 {
gregeric 0:b9444a40a999 1268 motorDrvHandle->QueueCommands(deviceId, param, value);
gregeric 0:b9444a40a999 1269 }
gregeric 0:b9444a40a999 1270 else
gregeric 0:b9444a40a999 1271 {
gregeric 0:b9444a40a999 1272 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(58);
gregeric 0:b9444a40a999 1273 }
gregeric 0:b9444a40a999 1274 }
gregeric 0:b9444a40a999 1275
gregeric 0:b9444a40a999 1276 /******************************************************//**
gregeric 0:b9444a40a999 1277 * @brief Locks until all devices become not busy
gregeric 0:b9444a40a999 1278 * @param None
gregeric 0:b9444a40a999 1279 * @retval None
gregeric 0:b9444a40a999 1280 **********************************************************/
gregeric 0:b9444a40a999 1281 void BSP_MotorControl_WaitForAllDevicesNotBusy(void)
gregeric 0:b9444a40a999 1282 {
gregeric 0:b9444a40a999 1283 if ((motorDrvHandle != 0)&&(motorDrvHandle->WaitForAllDevicesNotBusy != 0))
gregeric 0:b9444a40a999 1284 {
gregeric 0:b9444a40a999 1285 motorDrvHandle->WaitForAllDevicesNotBusy();
gregeric 0:b9444a40a999 1286 }
gregeric 0:b9444a40a999 1287 else
gregeric 0:b9444a40a999 1288 {
gregeric 0:b9444a40a999 1289 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(59);
gregeric 0:b9444a40a999 1290 }
gregeric 0:b9444a40a999 1291 }
gregeric 0:b9444a40a999 1292
gregeric 0:b9444a40a999 1293 /******************************************************//**
gregeric 0:b9444a40a999 1294 * @brief Handler of the busy interrupt which calls the user callback (if defined)
gregeric 0:b9444a40a999 1295 * @param None
gregeric 0:b9444a40a999 1296 * @retval None
gregeric 0:b9444a40a999 1297 **********************************************************/
gregeric 0:b9444a40a999 1298 void BSP_MotorControl_BusyInterruptHandler(void)
gregeric 0:b9444a40a999 1299 {
gregeric 0:b9444a40a999 1300 if ((motorDrvHandle != 0)&&(motorDrvHandle->BusyInterruptHandler != 0))
gregeric 0:b9444a40a999 1301 {
gregeric 0:b9444a40a999 1302 motorDrvHandle->BusyInterruptHandler();
gregeric 0:b9444a40a999 1303 }
gregeric 0:b9444a40a999 1304 else
gregeric 0:b9444a40a999 1305 {
gregeric 0:b9444a40a999 1306 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(60);
gregeric 0:b9444a40a999 1307 }
gregeric 0:b9444a40a999 1308 }
gregeric 0:b9444a40a999 1309
gregeric 0:b9444a40a999 1310 /******************************************************//**
gregeric 0:b9444a40a999 1311 * @brief Issues PowerStep01 Soft Stop command
gregeric 0:b9444a40a999 1312 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
gregeric 0:b9444a40a999 1313 * @retval None
gregeric 0:b9444a40a999 1314 **********************************************************/
gregeric 0:b9444a40a999 1315 void BSP_MotorControl_CmdSoftStop(uint8_t deviceId)
gregeric 0:b9444a40a999 1316 {
gregeric 0:b9444a40a999 1317 if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdSoftStop != 0))
gregeric 0:b9444a40a999 1318 {
gregeric 0:b9444a40a999 1319 motorDrvHandle->CmdSoftStop(deviceId);
gregeric 0:b9444a40a999 1320 }
gregeric 0:b9444a40a999 1321 else
gregeric 0:b9444a40a999 1322 {
gregeric 0:b9444a40a999 1323 MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(61);
gregeric 0:b9444a40a999 1324 }
gregeric 0:b9444a40a999 1325 }
gregeric 0:b9444a40a999 1326
gregeric 0:b9444a40a999 1327 /**
gregeric 0:b9444a40a999 1328 * @}
gregeric 0:b9444a40a999 1329 */
gregeric 0:b9444a40a999 1330
gregeric 0:b9444a40a999 1331 /**
gregeric 0:b9444a40a999 1332 * @}
gregeric 0:b9444a40a999 1333 */
gregeric 0:b9444a40a999 1334
gregeric 0:b9444a40a999 1335 /**
gregeric 0:b9444a40a999 1336 * @}
gregeric 0:b9444a40a999 1337 */
gregeric 0:b9444a40a999 1338
gregeric 0:b9444a40a999 1339 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/