Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_IHM02A1 by ST

Committer:
Davidroid
Date:
Thu Nov 26 16:24:17 2015 +0000
Revision:
4:381d76f5b0b4
Parent:
2:3ed992ffeada
Child:
7:3bb27256c3ed
+ Updated with the new structure of the Stm32CubeTOO tool.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:92706998571a 1 /**
Davidroid 4:381d76f5b0b4 2 ******************************************************************************
Davidroid 4:381d76f5b0b4 3 * @file l6470_class.h
Davidroid 4:381d76f5b0b4 4 * @author Davide Aliprandi, STMicrolectronics
Davidroid 4:381d76f5b0b4 5 * @version V1.0.0
Davidroid 4:381d76f5b0b4 6 * @date November 12th, 2015
Davidroid 4:381d76f5b0b4 7 * @brief This file contains the class of an L6470 Motor Control component.
Davidroid 4:381d76f5b0b4 8 ******************************************************************************
Davidroid 4:381d76f5b0b4 9 *
Davidroid 4:381d76f5b0b4 10 * COPYRIGHT(c) 2014 STMicroelectronics
Davidroid 4:381d76f5b0b4 11 *
Davidroid 4:381d76f5b0b4 12 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 4:381d76f5b0b4 13 * are permitted provided that the following conditions are met:
Davidroid 4:381d76f5b0b4 14 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 4:381d76f5b0b4 15 * this list of conditions and the following disclaimer.
Davidroid 4:381d76f5b0b4 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 4:381d76f5b0b4 17 * this list of conditions and the following disclaimer in the documentation
Davidroid 4:381d76f5b0b4 18 * and/or other materials provided with the distribution.
Davidroid 4:381d76f5b0b4 19 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 4:381d76f5b0b4 20 * may be used to endorse or promote products derived from this software
Davidroid 4:381d76f5b0b4 21 * without specific prior written permission.
Davidroid 4:381d76f5b0b4 22 *
Davidroid 4:381d76f5b0b4 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 4:381d76f5b0b4 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 4:381d76f5b0b4 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 4:381d76f5b0b4 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 4:381d76f5b0b4 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 4:381d76f5b0b4 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 4:381d76f5b0b4 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 4:381d76f5b0b4 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 4:381d76f5b0b4 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 4:381d76f5b0b4 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 4:381d76f5b0b4 33 *
Davidroid 4:381d76f5b0b4 34 ******************************************************************************
Davidroid 4:381d76f5b0b4 35 */
Davidroid 0:92706998571a 36
Davidroid 0:92706998571a 37
Davidroid 0:92706998571a 38 /* Generated with Stm32CubeTOO -----------------------------------------------*/
Davidroid 0:92706998571a 39
Davidroid 0:92706998571a 40
Davidroid 0:92706998571a 41 /* Revision ------------------------------------------------------------------*/
Davidroid 0:92706998571a 42 /*
Davidroid 0:92706998571a 43 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
Davidroid 0:92706998571a 44 Branch/Trunk/Tag: trunk
Davidroid 0:92706998571a 45 Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.h
Davidroid 0:92706998571a 46 Revision: 0
Davidroid 0:92706998571a 47 */
Davidroid 0:92706998571a 48
Davidroid 0:92706998571a 49
Davidroid 0:92706998571a 50 /* Define to prevent recursive inclusion -------------------------------------*/
Davidroid 0:92706998571a 51
Davidroid 0:92706998571a 52 #ifndef __L6470_CLASS_H
Davidroid 0:92706998571a 53 #define __L6470_CLASS_H
Davidroid 0:92706998571a 54
Davidroid 0:92706998571a 55
Davidroid 0:92706998571a 56 /* Includes ------------------------------------------------------------------*/
Davidroid 0:92706998571a 57
Davidroid 0:92706998571a 58 /* ACTION 1 ------------------------------------------------------------------*
Davidroid 0:92706998571a 59 * Include here platform specific header files. *
Davidroid 0:92706998571a 60 *----------------------------------------------------------------------------*/
Davidroid 0:92706998571a 61 #include "mbed.h"
Davidroid 0:92706998571a 62 #include "DevSPI.h"
Davidroid 0:92706998571a 63 /* ACTION 2 ------------------------------------------------------------------*
Davidroid 0:92706998571a 64 * Include here component specific header files. *
Davidroid 0:92706998571a 65 *----------------------------------------------------------------------------*/
Davidroid 0:92706998571a 66 #include "l6470.h"
Davidroid 0:92706998571a 67 /* ACTION 3 ------------------------------------------------------------------*
Davidroid 0:92706998571a 68 * Include here interface specific header files. *
Davidroid 0:92706998571a 69 * *
Davidroid 0:92706998571a 70 * Example: *
Davidroid 0:92706998571a 71 * #include "../Interfaces/Humidity_class.h" *
Davidroid 0:92706998571a 72 * #include "../Interfaces/Temperature_class.h" *
Davidroid 0:92706998571a 73 *----------------------------------------------------------------------------*/
Davidroid 0:92706998571a 74 #include "../Interfaces/StepperMotor_class.h"
Davidroid 0:92706998571a 75
Davidroid 0:92706998571a 76
Davidroid 0:92706998571a 77 /* Classes -------------------------------------------------------------------*/
Davidroid 0:92706998571a 78
Davidroid 0:92706998571a 79 /** Class representing a L6470 component.
Davidroid 0:92706998571a 80 */
Davidroid 0:92706998571a 81 class L6470 : public StepperMotor
Davidroid 0:92706998571a 82 {
Davidroid 0:92706998571a 83 public:
Davidroid 0:92706998571a 84
Davidroid 1:b78dab6d2c58 85 /*** Public Component Related Types ***/
Davidroid 1:b78dab6d2c58 86
Davidroid 1:b78dab6d2c58 87 /**
Davidroid 1:b78dab6d2c58 88 * @brief Prepared Actions.
Davidroid 1:b78dab6d2c58 89 */
Davidroid 1:b78dab6d2c58 90 typedef enum
Davidroid 1:b78dab6d2c58 91 {
Davidroid 1:b78dab6d2c58 92 PREPARED_NO_ACTION = 0,
Davidroid 1:b78dab6d2c58 93 PREPARED_GET_POSITION,
Davidroid 1:b78dab6d2c58 94 PREPARED_GET_MARK,
Davidroid 1:b78dab6d2c58 95 PREPARED_GET_SPEED,
Davidroid 1:b78dab6d2c58 96 PREPARED_GET_MAX_SPEED,
Davidroid 1:b78dab6d2c58 97 PREPARED_GET_MIN_SPEED,
Davidroid 1:b78dab6d2c58 98 PREPARED_GET_ACCELERATION,
Davidroid 1:b78dab6d2c58 99 PREPARED_GET_DECELERATION,
Davidroid 1:b78dab6d2c58 100 PREPARED_GET_DIRECTION,
Davidroid 1:b78dab6d2c58 101 PREPARED_SET_MARK
Davidroid 1:b78dab6d2c58 102 } prepared_action_t;
Davidroid 1:b78dab6d2c58 103
Davidroid 1:b78dab6d2c58 104
Davidroid 0:92706998571a 105 /*** Constructor and Destructor Methods ***/
Davidroid 0:92706998571a 106
Davidroid 0:92706998571a 107 /**
Davidroid 0:92706998571a 108 * @brief Constructor.
Davidroid 0:92706998571a 109 * @param flag_irq pin name of the FLAG pin of the component.
Davidroid 1:b78dab6d2c58 110 * @param busy_irq pin name of the BUSY pin of the component.
Davidroid 0:92706998571a 111 * @param standby_reset pin name of the STBY\RST pin of the component.
Davidroid 0:92706998571a 112 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication.
Davidroid 0:92706998571a 113 * @param spi SPI device to be used for communication.
Davidroid 0:92706998571a 114 */
Davidroid 1:b78dab6d2c58 115 L6470(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), busy_irq(busy_irq), standby_reset(standby_reset), ssel(ssel), dev_spi(spi)
Davidroid 0:92706998571a 116 {
Davidroid 0:92706998571a 117 /* ACTION 4 ----------------------------------------------------------*
Davidroid 0:92706998571a 118 * Initialize here the component's member variables, one variable per *
Davidroid 0:92706998571a 119 * line. *
Davidroid 0:92706998571a 120 * *
Davidroid 0:92706998571a 121 * Example: *
Davidroid 0:92706998571a 122 * T0_out = 0; *
Davidroid 0:92706998571a 123 * T1_out = 0; *
Davidroid 0:92706998571a 124 * T0_degC = 0; *
Davidroid 0:92706998571a 125 * T1_degC = 0; *
Davidroid 0:92706998571a 126 *--------------------------------------------------------------------*/
Davidroid 0:92706998571a 127 L6470_Register = &_L6470_Register[0];
Davidroid 0:92706998571a 128 L6470_ApplicationCommand = &_L6470_ApplicationCommand[0];
Davidroid 0:92706998571a 129 L6470_Direction = &_L6470_Direction[0];
Davidroid 0:92706998571a 130 L6470_ACT = &_L6470_ACT[0];
Davidroid 0:92706998571a 131 pL6470_StatusRegister = &L6470_StatusRegister;
Davidroid 1:b78dab6d2c58 132 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 133 L6470_Id = number_of_devices++;
Davidroid 0:92706998571a 134 L6470_DaisyChain_HalfPrepared = ZERO_F;
Davidroid 0:92706998571a 135 memset(L6470_AppCmdPkg, 0, L6470DAISYCHAINSIZE * sizeof(sL6470_AppCmdPkg_t));
Davidroid 0:92706998571a 136 memset(L6470_DaisyChainSpiTxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
Davidroid 0:92706998571a 137 memset(L6470_DaisyChainSpiRxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
Davidroid 0:92706998571a 138 }
Davidroid 0:92706998571a 139
Davidroid 0:92706998571a 140 /**
Davidroid 0:92706998571a 141 * @brief Destructor.
Davidroid 0:92706998571a 142 */
Davidroid 0:92706998571a 143 virtual ~L6470(void) {}
Davidroid 0:92706998571a 144
Davidroid 0:92706998571a 145
Davidroid 0:92706998571a 146 /*** Public Component Related Methods ***/
Davidroid 0:92706998571a 147
Davidroid 0:92706998571a 148 /* ACTION 5 --------------------------------------------------------------*
Davidroid 0:92706998571a 149 * Implement here the component's public methods, as wrappers of the C *
Davidroid 0:92706998571a 150 * component's functions. *
Davidroid 0:92706998571a 151 * They should be: *
Davidroid 0:92706998571a 152 * + Methods with the same name of the C component's virtual table's *
Davidroid 0:92706998571a 153 * functions (1); *
Davidroid 0:92706998571a 154 * + Methods with the same name of the C component's extended virtual *
Davidroid 0:92706998571a 155 * table's functions, if any (2). *
Davidroid 0:92706998571a 156 * *
Davidroid 0:92706998571a 157 * Example: *
Davidroid 0:92706998571a 158 * virtual int GetValue(float *pData) //(1) *
Davidroid 0:92706998571a 159 * { *
Davidroid 0:92706998571a 160 * return COMPONENT_GetValue(float *pfData); *
Davidroid 0:92706998571a 161 * } *
Davidroid 0:92706998571a 162 * *
Davidroid 0:92706998571a 163 * virtual int EnableFeature(void) //(2) *
Davidroid 0:92706998571a 164 * { *
Davidroid 0:92706998571a 165 * return COMPONENT_EnableFeature(); *
Davidroid 0:92706998571a 166 * } *
Davidroid 0:92706998571a 167 *------------------------------------------------------------------------*/
Davidroid 1:b78dab6d2c58 168 /**
Davidroid 1:b78dab6d2c58 169 * @brief Initializing the component.
Davidroid 1:b78dab6d2c58 170 * @param init Pointer to device specific initalization structure.
Davidroid 1:b78dab6d2c58 171 * @retval "0" in case of success, an error code otherwise.
Davidroid 1:b78dab6d2c58 172 */
Davidroid 0:92706998571a 173 virtual int Init(void *init)
Davidroid 0:92706998571a 174 {
Davidroid 0:92706998571a 175 return (int) L6470_Config((MICROSTEPPING_MOTOR_InitTypeDef *) init);
Davidroid 0:92706998571a 176 }
Davidroid 0:92706998571a 177
Davidroid 1:b78dab6d2c58 178 /**
Davidroid 1:b78dab6d2c58 179 * @brief Getting the ID of the component.
Davidroid 1:b78dab6d2c58 180 * @param id Pointer to an allocated variable to store the ID into.
Davidroid 1:b78dab6d2c58 181 * @retval "0" in case of success, an error code otherwise.
Davidroid 1:b78dab6d2c58 182 */
Davidroid 0:92706998571a 183 virtual int ReadID(uint8_t *id)
Davidroid 0:92706998571a 184 {
Davidroid 0:92706998571a 185 return (int) 0;
Davidroid 0:92706998571a 186 }
Davidroid 0:92706998571a 187
Davidroid 1:b78dab6d2c58 188 /**
Davidroid 1:b78dab6d2c58 189 * @brief Getting the status.
Davidroid 1:b78dab6d2c58 190 * @param None.
Davidroid 1:b78dab6d2c58 191 * @retval The status.
Davidroid 1:b78dab6d2c58 192 */
Davidroid 0:92706998571a 193 virtual unsigned int GetStatus(void)
Davidroid 0:92706998571a 194 {
Davidroid 0:92706998571a 195 return (unsigned int) L6470_GetStatus();
Davidroid 0:92706998571a 196 }
Davidroid 1:b78dab6d2c58 197
Davidroid 1:b78dab6d2c58 198 /**
Davidroid 1:b78dab6d2c58 199 * @brief Getting a parameter.
Davidroid 1:b78dab6d2c58 200 * @param parameter The parameter's identifier (or its register address).
Davidroid 1:b78dab6d2c58 201 * @retval The parameter's value.
Davidroid 1:b78dab6d2c58 202 */
Davidroid 0:92706998571a 203 virtual unsigned int GetParameter(unsigned int parameter)
Davidroid 0:92706998571a 204 {
Davidroid 0:92706998571a 205 return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter);
Davidroid 0:92706998571a 206 }
Davidroid 0:92706998571a 207
Davidroid 1:b78dab6d2c58 208 /**
Davidroid 1:b78dab6d2c58 209 * @brief Getting the position.
Davidroid 1:b78dab6d2c58 210 * @param None.
Davidroid 1:b78dab6d2c58 211 * @retval The position.
Davidroid 1:b78dab6d2c58 212 */
Davidroid 0:92706998571a 213 virtual signed int GetPosition(void)
Davidroid 0:92706998571a 214 {
Davidroid 1:b78dab6d2c58 215 return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
Davidroid 0:92706998571a 216 }
Davidroid 0:92706998571a 217
Davidroid 1:b78dab6d2c58 218 /**
Davidroid 1:b78dab6d2c58 219 * @brief Getting the marked position.
Davidroid 1:b78dab6d2c58 220 * @param None.
Davidroid 1:b78dab6d2c58 221 * @retval The marked position.
Davidroid 1:b78dab6d2c58 222 */
Davidroid 0:92706998571a 223 virtual signed int GetMark(void)
Davidroid 0:92706998571a 224 {
Davidroid 1:b78dab6d2c58 225 return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID));
Davidroid 0:92706998571a 226 }
Davidroid 0:92706998571a 227
Davidroid 1:b78dab6d2c58 228 /**
Davidroid 1:b78dab6d2c58 229 * @brief Getting the current speed in pps.
Davidroid 1:b78dab6d2c58 230 * @param None.
Davidroid 1:b78dab6d2c58 231 * @retval The current speed in pps.
Davidroid 1:b78dab6d2c58 232 */
Davidroid 0:92706998571a 233 virtual unsigned int GetSpeed(void)
Davidroid 0:92706998571a 234 {
Davidroid 1:b78dab6d2c58 235 return round(L6470_Speed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID)));
Davidroid 0:92706998571a 236 }
Davidroid 0:92706998571a 237
Davidroid 1:b78dab6d2c58 238 /**
Davidroid 1:b78dab6d2c58 239 * @brief Getting the maximum speed in pps.
Davidroid 1:b78dab6d2c58 240 * @param None.
Davidroid 1:b78dab6d2c58 241 * @retval The maximum speed in pps.
Davidroid 1:b78dab6d2c58 242 */
Davidroid 0:92706998571a 243 virtual unsigned int GetMaxSpeed(void)
Davidroid 0:92706998571a 244 {
Davidroid 1:b78dab6d2c58 245 return round(L6470_MaxSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID)));
Davidroid 0:92706998571a 246 }
Davidroid 0:92706998571a 247
Davidroid 1:b78dab6d2c58 248 /**
Davidroid 1:b78dab6d2c58 249 * @brief Getting the minimum speed in pps.
Davidroid 1:b78dab6d2c58 250 * @param None.
Davidroid 1:b78dab6d2c58 251 * @retval The minimum speed in pps.
Davidroid 1:b78dab6d2c58 252 */
Davidroid 0:92706998571a 253 virtual unsigned int GetMinSpeed(void)
Davidroid 0:92706998571a 254 {
Davidroid 1:b78dab6d2c58 255 return round(L6470_MinSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID)));
Davidroid 0:92706998571a 256 }
Davidroid 0:92706998571a 257
Davidroid 1:b78dab6d2c58 258 /**
Davidroid 1:b78dab6d2c58 259 * @brief Getting the acceleration in pps^2.
Davidroid 1:b78dab6d2c58 260 * @param None.
Davidroid 1:b78dab6d2c58 261 * @retval The acceleration in pps^2.
Davidroid 1:b78dab6d2c58 262 */
Davidroid 0:92706998571a 263 virtual unsigned int GetAcceleration(void)
Davidroid 0:92706998571a 264 {
Davidroid 1:b78dab6d2c58 265 return round(L6470_Acc_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID)));
Davidroid 0:92706998571a 266 }
Davidroid 0:92706998571a 267
Davidroid 1:b78dab6d2c58 268 /**
Davidroid 1:b78dab6d2c58 269 * @brief Getting the deceleration in pps^2.
Davidroid 1:b78dab6d2c58 270 * @param None.
Davidroid 1:b78dab6d2c58 271 * @retval The deceleration in pps^2.
Davidroid 1:b78dab6d2c58 272 */
Davidroid 0:92706998571a 273 virtual unsigned int GetDeceleration(void)
Davidroid 0:92706998571a 274 {
Davidroid 1:b78dab6d2c58 275 return round(L6470_Dec_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID)));
Davidroid 0:92706998571a 276 }
Davidroid 0:92706998571a 277
Davidroid 1:b78dab6d2c58 278 /**
Davidroid 1:b78dab6d2c58 279 * @brief Getting the direction of rotation.
Davidroid 1:b78dab6d2c58 280 * @param None.
Davidroid 1:b78dab6d2c58 281 * @retval The direction of rotation.
Davidroid 1:b78dab6d2c58 282 */
Davidroid 0:92706998571a 283 virtual direction_t GetDirection(void)
Davidroid 0:92706998571a 284 {
Davidroid 0:92706998571a 285 return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
Davidroid 0:92706998571a 286 }
Davidroid 0:92706998571a 287
Davidroid 1:b78dab6d2c58 288 /**
Davidroid 1:b78dab6d2c58 289 * @brief Setting a parameter.
Davidroid 1:b78dab6d2c58 290 * @param parameter The parameter's identifier (or its register address).
Davidroid 1:b78dab6d2c58 291 * @param value The parameter's value.
Davidroid 1:b78dab6d2c58 292 * @retval None.
Davidroid 1:b78dab6d2c58 293 */
Davidroid 0:92706998571a 294 virtual void SetParameter(unsigned int parameter, unsigned int value)
Davidroid 0:92706998571a 295 {
Davidroid 0:92706998571a 296 L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value);
Davidroid 0:92706998571a 297 }
Davidroid 0:92706998571a 298
Davidroid 1:b78dab6d2c58 299 /**
Davidroid 1:b78dab6d2c58 300 * @brief Setting the current position to be the home position.
Davidroid 1:b78dab6d2c58 301 * @param None.
Davidroid 1:b78dab6d2c58 302 * @retval None.
Davidroid 1:b78dab6d2c58 303 */
Davidroid 0:92706998571a 304 virtual void SetHome(void)
Davidroid 0:92706998571a 305 {
Davidroid 0:92706998571a 306 L6470_ResetPos();
Davidroid 0:92706998571a 307 }
Davidroid 0:92706998571a 308
Davidroid 1:b78dab6d2c58 309 /**
Davidroid 1:b78dab6d2c58 310 * @brief Setting the current position to be the marked position.
Davidroid 1:b78dab6d2c58 311 * @param None.
Davidroid 1:b78dab6d2c58 312 * @retval None.
Davidroid 1:b78dab6d2c58 313 */
Davidroid 0:92706998571a 314 virtual void SetMark(void)
Davidroid 0:92706998571a 315 {
Davidroid 0:92706998571a 316 L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
Davidroid 0:92706998571a 317 }
Davidroid 0:92706998571a 318
Davidroid 1:b78dab6d2c58 319 /**
Davidroid 1:b78dab6d2c58 320 * @brief Setting the current position to be the marked position.
Davidroid 1:b78dab6d2c58 321 * @param position The given position.
Davidroid 1:b78dab6d2c58 322 * @retval None.
Davidroid 1:b78dab6d2c58 323 */
Davidroid 1:b78dab6d2c58 324 virtual void SetMark(signed int position)
Davidroid 1:b78dab6d2c58 325 {
Davidroid 1:b78dab6d2c58 326 L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 1:b78dab6d2c58 327 }
Davidroid 1:b78dab6d2c58 328
Davidroid 1:b78dab6d2c58 329 /**
Davidroid 1:b78dab6d2c58 330 * @brief Setting the maximum speed in pps.
Davidroid 1:b78dab6d2c58 331 * @param speed The maximum speed in pps.
Davidroid 1:b78dab6d2c58 332 * @retval None.
Davidroid 1:b78dab6d2c58 333 */
Davidroid 0:92706998571a 334 virtual void SetMaxSpeed(unsigned int speed)
Davidroid 0:92706998571a 335 {
Davidroid 1:b78dab6d2c58 336 L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
Davidroid 0:92706998571a 337 }
Davidroid 0:92706998571a 338
Davidroid 1:b78dab6d2c58 339 /**
Davidroid 1:b78dab6d2c58 340 * @brief Setting the minimum speed in pps.
Davidroid 1:b78dab6d2c58 341 * @param speed The minimum speed in pps.
Davidroid 1:b78dab6d2c58 342 * @retval None.
Davidroid 1:b78dab6d2c58 343 */
Davidroid 0:92706998571a 344 virtual void SetMinSpeed(unsigned int speed)
Davidroid 0:92706998571a 345 {
Davidroid 1:b78dab6d2c58 346 L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
Davidroid 0:92706998571a 347 }
Davidroid 0:92706998571a 348
Davidroid 1:b78dab6d2c58 349 /**
Davidroid 1:b78dab6d2c58 350 * @brief Setting the acceleration in pps^2.
Davidroid 1:b78dab6d2c58 351 * @param acceleration The acceleration in pps^2.
Davidroid 1:b78dab6d2c58 352 * @retval None.
Davidroid 1:b78dab6d2c58 353 */
Davidroid 0:92706998571a 354 virtual void SetAcceleration(unsigned int acceleration)
Davidroid 0:92706998571a 355 {
Davidroid 1:b78dab6d2c58 356 L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
Davidroid 0:92706998571a 357 }
Davidroid 0:92706998571a 358
Davidroid 1:b78dab6d2c58 359 /**
Davidroid 1:b78dab6d2c58 360 * @brief Setting the deceleration in pps^2.
Davidroid 1:b78dab6d2c58 361 * @param deceleration The deceleration in pps^2.
Davidroid 1:b78dab6d2c58 362 * @retval None.
Davidroid 1:b78dab6d2c58 363 */
Davidroid 0:92706998571a 364 virtual void SetDeceleration(unsigned int deceleration)
Davidroid 0:92706998571a 365 {
Davidroid 1:b78dab6d2c58 366 L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
Davidroid 0:92706998571a 367 }
Davidroid 0:92706998571a 368
Davidroid 1:b78dab6d2c58 369 /**
Davidroid 1:b78dab6d2c58 370 * @brief Going to a specified position through the shortest path.
Davidroid 1:b78dab6d2c58 371 * @param position The desired position.
Davidroid 1:b78dab6d2c58 372 * @retval None.
Davidroid 1:b78dab6d2c58 373 */
Davidroid 0:92706998571a 374 virtual void GoTo(signed int position)
Davidroid 0:92706998571a 375 {
Davidroid 1:b78dab6d2c58 376 L6470_GoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 0:92706998571a 377 }
Davidroid 0:92706998571a 378
Davidroid 1:b78dab6d2c58 379 /**
Davidroid 1:b78dab6d2c58 380 * @brief Going to a specified position imposing the desired direction.
Davidroid 1:b78dab6d2c58 381 * @param position The desired position.
Davidroid 1:b78dab6d2c58 382 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 383 * @retval None.
Davidroid 1:b78dab6d2c58 384 */
Davidroid 0:92706998571a 385 virtual void GoTo(signed int position, direction_t direction)
Davidroid 0:92706998571a 386 {
Davidroid 1:b78dab6d2c58 387 L6470_GoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 0:92706998571a 388 }
Davidroid 0:92706998571a 389
Davidroid 1:b78dab6d2c58 390 /**
Davidroid 1:b78dab6d2c58 391 * @brief Going to the home position.
Davidroid 1:b78dab6d2c58 392 * @param None.
Davidroid 1:b78dab6d2c58 393 * @retval None.
Davidroid 1:b78dab6d2c58 394 */
Davidroid 0:92706998571a 395 virtual void GoHome(void)
Davidroid 0:92706998571a 396 {
Davidroid 0:92706998571a 397 L6470_GoHome();
Davidroid 0:92706998571a 398 }
Davidroid 0:92706998571a 399
Davidroid 1:b78dab6d2c58 400 /**
Davidroid 1:b78dab6d2c58 401 * @brief Going to the marked position.
Davidroid 1:b78dab6d2c58 402 * @param None.
Davidroid 1:b78dab6d2c58 403 * @retval None.
Davidroid 1:b78dab6d2c58 404 */
Davidroid 0:92706998571a 405 virtual void GoMark(void)
Davidroid 0:92706998571a 406 {
Davidroid 0:92706998571a 407 L6470_GoMark();
Davidroid 0:92706998571a 408 }
Davidroid 0:92706998571a 409
Davidroid 1:b78dab6d2c58 410 /**
Davidroid 1:b78dab6d2c58 411 * @brief Running at the given speed imposing the desired direction until
Davidroid 1:b78dab6d2c58 412 * an external switch turn-on event occurs.
Davidroid 1:b78dab6d2c58 413 * @param action The identifier of the action about the absolute position.
Davidroid 1:b78dab6d2c58 414 * @param position The desired position.
Davidroid 1:b78dab6d2c58 415 * @param speed The speed value in pps.
Davidroid 1:b78dab6d2c58 416 * @retval None.
Davidroid 1:b78dab6d2c58 417 * @note The identifier of the action about the absolute position can be
Davidroid 1:b78dab6d2c58 418 * one of the following:
Davidroid 1:b78dab6d2c58 419 * + L6470_ACT_RST_ID: the absolute position is reset;
Davidroid 1:b78dab6d2c58 420 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
Davidroid 1:b78dab6d2c58 421 */
Davidroid 1:b78dab6d2c58 422 virtual void GoUntil(eL6470_ActId_t action, direction_t direction, unsigned int speed)
Davidroid 0:92706998571a 423 {
Davidroid 1:b78dab6d2c58 424 L6470_GoUntil((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed));
Davidroid 0:92706998571a 425 }
Davidroid 0:92706998571a 426
Davidroid 1:b78dab6d2c58 427 /**
Davidroid 1:b78dab6d2c58 428 * @brief Running towards a specified direction.
Davidroid 1:b78dab6d2c58 429 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 430 * @retval None.
Davidroid 1:b78dab6d2c58 431 */
Davidroid 0:92706998571a 432 virtual void Run(direction_t direction)
Davidroid 0:92706998571a 433 {
Davidroid 0:92706998571a 434 L6470_Run((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID));
Davidroid 0:92706998571a 435 }
Davidroid 0:92706998571a 436
Davidroid 1:b78dab6d2c58 437 /**
Davidroid 1:b78dab6d2c58 438 * @brief Running towards a specified direction at the given speed.
Davidroid 1:b78dab6d2c58 439 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 440 * @param speed The speed value in pps.
Davidroid 1:b78dab6d2c58 441 * @retval None.
Davidroid 1:b78dab6d2c58 442 */
Davidroid 0:92706998571a 443 virtual void Run(direction_t direction, unsigned int speed)
Davidroid 0:92706998571a 444 {
Davidroid 1:b78dab6d2c58 445 L6470_Run((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed));
Davidroid 0:92706998571a 446 }
Davidroid 0:92706998571a 447
Davidroid 1:b78dab6d2c58 448 /**
Davidroid 1:b78dab6d2c58 449 * @brief Moving towards a specified direction for a certain number of steps.
Davidroid 1:b78dab6d2c58 450 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 451 * @param steps The desired number of steps.
Davidroid 1:b78dab6d2c58 452 * @retval None.
Davidroid 1:b78dab6d2c58 453 */
Davidroid 0:92706998571a 454 virtual void Move(direction_t direction, unsigned int steps)
Davidroid 0:92706998571a 455 {
Davidroid 0:92706998571a 456 L6470_Move((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
Davidroid 0:92706998571a 457 }
Davidroid 0:92706998571a 458
Davidroid 1:b78dab6d2c58 459 /**
Davidroid 1:b78dab6d2c58 460 * @brief Stopping the motor through an immediate deceleration up to zero speed.
Davidroid 1:b78dab6d2c58 461 * The used deceleration value is the one stored in the "DEC" register.
Davidroid 1:b78dab6d2c58 462 * @param None.
Davidroid 1:b78dab6d2c58 463 * @retval None.
Davidroid 1:b78dab6d2c58 464 */
Davidroid 0:92706998571a 465 virtual void SoftStop(void)
Davidroid 0:92706998571a 466 {
Davidroid 0:92706998571a 467 L6470_SoftStop();
Davidroid 0:92706998571a 468 }
Davidroid 0:92706998571a 469
Davidroid 1:b78dab6d2c58 470 /**
Davidroid 1:b78dab6d2c58 471 * @brief Stopping the motor through an immediate infinite deceleration.
Davidroid 1:b78dab6d2c58 472 * @param None.
Davidroid 1:b78dab6d2c58 473 * @retval None.
Davidroid 1:b78dab6d2c58 474 */
Davidroid 0:92706998571a 475 virtual void HardStop(void)
Davidroid 0:92706998571a 476 {
Davidroid 0:92706998571a 477 L6470_HardStop();
Davidroid 0:92706998571a 478 }
Davidroid 0:92706998571a 479
Davidroid 1:b78dab6d2c58 480 /**
Davidroid 1:b78dab6d2c58 481 * @brief Disabling the power bridge after performing a deceleration to zero.
Davidroid 1:b78dab6d2c58 482 * The used deceleration value is the one stored in the "DEC" register.
Davidroid 1:b78dab6d2c58 483 * @param None.
Davidroid 1:b78dab6d2c58 484 * @retval None.
Davidroid 1:b78dab6d2c58 485 */
Davidroid 1:b78dab6d2c58 486 virtual void SoftHiZ(void)
Davidroid 1:b78dab6d2c58 487 {
Davidroid 1:b78dab6d2c58 488 L6470_SoftHiZ();
Davidroid 1:b78dab6d2c58 489 }
Davidroid 1:b78dab6d2c58 490
Davidroid 1:b78dab6d2c58 491 /**
Davidroid 1:b78dab6d2c58 492 * @brief Disabling the power bridge immediately.
Davidroid 1:b78dab6d2c58 493 * @param None.
Davidroid 1:b78dab6d2c58 494 * @retval None.
Davidroid 1:b78dab6d2c58 495 */
Davidroid 1:b78dab6d2c58 496 virtual void HardHiZ(void)
Davidroid 1:b78dab6d2c58 497 {
Davidroid 1:b78dab6d2c58 498 L6470_HardHiZ();
Davidroid 1:b78dab6d2c58 499 }
Davidroid 1:b78dab6d2c58 500
Davidroid 1:b78dab6d2c58 501 /**
Davidroid 1:b78dab6d2c58 502 * @brief Waiting while the motor is active.
Davidroid 1:b78dab6d2c58 503 * @param None.
Davidroid 1:b78dab6d2c58 504 * @retval None.
Davidroid 1:b78dab6d2c58 505 */
Davidroid 0:92706998571a 506 virtual void WaitWhileActive(void)
Davidroid 0:92706998571a 507 {
Davidroid 0:92706998571a 508 while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0);
Davidroid 0:92706998571a 509 }
Davidroid 0:92706998571a 510
Davidroid 1:b78dab6d2c58 511 /**
Davidroid 1:b78dab6d2c58 512 * @brief Switching to step-clock mode.
Davidroid 1:b78dab6d2c58 513 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 514 * @retval None.
Davidroid 1:b78dab6d2c58 515 */
Davidroid 0:92706998571a 516 virtual void StepClock(direction_t direction)
Davidroid 0:92706998571a 517 {
Davidroid 0:92706998571a 518 L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
Davidroid 0:92706998571a 519 }
Davidroid 0:92706998571a 520
Davidroid 1:b78dab6d2c58 521 /**
Davidroid 1:b78dab6d2c58 522 * @brief Doing a motion at minimum speed imposing a specified direction
Davidroid 1:b78dab6d2c58 523 * until the SW is released.
Davidroid 1:b78dab6d2c58 524 * @param action The identifier of the action about the absolute position.
Davidroid 1:b78dab6d2c58 525 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 526 * @note The identifier of the action about the absolute position can be
Davidroid 1:b78dab6d2c58 527 * one of the following:
Davidroid 1:b78dab6d2c58 528 * + L6470_ACT_RST_ID: the absolute position is reset;
Davidroid 1:b78dab6d2c58 529 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
Davidroid 1:b78dab6d2c58 530 */
Davidroid 1:b78dab6d2c58 531 virtual void ReleaseSW(eL6470_ActId_t action, direction_t direction)
Davidroid 0:92706998571a 532 {
Davidroid 1:b78dab6d2c58 533 L6470_ReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
Davidroid 0:92706998571a 534 }
Davidroid 0:92706998571a 535
Davidroid 1:b78dab6d2c58 536 /**
Davidroid 1:b78dab6d2c58 537 * @brief Resetting the device to power-up conditions.
Davidroid 1:b78dab6d2c58 538 * @param None.
Davidroid 1:b78dab6d2c58 539 * @retval None.
Davidroid 1:b78dab6d2c58 540 */
Davidroid 0:92706998571a 541 virtual void ResetDevice(void)
Davidroid 0:92706998571a 542 {
Davidroid 0:92706998571a 543 L6470_ResetDevice();
Davidroid 0:92706998571a 544 }
Davidroid 0:92706998571a 545
Davidroid 1:b78dab6d2c58 546 /**
Davidroid 1:b78dab6d2c58 547 * @brief Preparing the command to get the status.
Davidroid 1:b78dab6d2c58 548 * @param None.
Davidroid 1:b78dab6d2c58 549 * @retval None.
Davidroid 1:b78dab6d2c58 550 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 551 */
Davidroid 0:92706998571a 552 virtual void PrepareGetStatus(void)
Davidroid 0:92706998571a 553 {
Davidroid 0:92706998571a 554 L6470_PrepareGetStatus();
Davidroid 1:b78dab6d2c58 555 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 556 }
Davidroid 0:92706998571a 557
Davidroid 1:b78dab6d2c58 558 /**
Davidroid 1:b78dab6d2c58 559 * @brief Preparing the command to get a parameter.
Davidroid 1:b78dab6d2c58 560 * @param parameter The parameter's identifier (or its register address).
Davidroid 1:b78dab6d2c58 561 * @retval None.
Davidroid 1:b78dab6d2c58 562 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 563 */
Davidroid 0:92706998571a 564 virtual void PrepareGetParameter(unsigned int parameter)
Davidroid 0:92706998571a 565 {
Davidroid 0:92706998571a 566 L6470_PrepareGetParam((eL6470_RegId_t) parameter);
Davidroid 1:b78dab6d2c58 567 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 568 }
Davidroid 0:92706998571a 569
Davidroid 1:b78dab6d2c58 570 /**
Davidroid 1:b78dab6d2c58 571 * @brief Preparing the command to get the position.
Davidroid 1:b78dab6d2c58 572 * @param None.
Davidroid 1:b78dab6d2c58 573 * @retval None.
Davidroid 1:b78dab6d2c58 574 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 575 */
Davidroid 0:92706998571a 576 virtual void PrepareGetPosition(void)
Davidroid 0:92706998571a 577 {
Davidroid 0:92706998571a 578 L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID);
Davidroid 1:b78dab6d2c58 579 prepared_action = PREPARED_GET_POSITION;
Davidroid 0:92706998571a 580 }
Davidroid 0:92706998571a 581
Davidroid 1:b78dab6d2c58 582 /**
Davidroid 1:b78dab6d2c58 583 * @brief Preparing the command to get the marked position.
Davidroid 1:b78dab6d2c58 584 * @param None.
Davidroid 1:b78dab6d2c58 585 * @retval None.
Davidroid 1:b78dab6d2c58 586 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 587 */
Davidroid 0:92706998571a 588 virtual void PrepareGetMark(void)
Davidroid 0:92706998571a 589 {
Davidroid 0:92706998571a 590 L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID);
Davidroid 1:b78dab6d2c58 591 prepared_action = PREPARED_GET_MARK;
Davidroid 0:92706998571a 592 }
Davidroid 0:92706998571a 593
Davidroid 1:b78dab6d2c58 594 /**
Davidroid 1:b78dab6d2c58 595 * @brief Preparing the command to get the current speed in pps.
Davidroid 1:b78dab6d2c58 596 * @param None.
Davidroid 1:b78dab6d2c58 597 * @retval None.
Davidroid 1:b78dab6d2c58 598 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 599 */
Davidroid 0:92706998571a 600 virtual void PrepareGetSpeed(void)
Davidroid 0:92706998571a 601 {
Davidroid 1:b78dab6d2c58 602 L6470_PrepareGetParam((eL6470_RegId_t) L6470_SPEED_ID);
Davidroid 1:b78dab6d2c58 603 prepared_action = PREPARED_GET_SPEED;
Davidroid 0:92706998571a 604 }
Davidroid 0:92706998571a 605
Davidroid 1:b78dab6d2c58 606 /**
Davidroid 1:b78dab6d2c58 607 * @brief Preparing the command to get the maximum speed in pps.
Davidroid 1:b78dab6d2c58 608 * @param None.
Davidroid 1:b78dab6d2c58 609 * @retval None.
Davidroid 1:b78dab6d2c58 610 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 611 */
Davidroid 0:92706998571a 612 virtual void PrepareGetMaxSpeed(void)
Davidroid 0:92706998571a 613 {
Davidroid 0:92706998571a 614 L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID);
Davidroid 1:b78dab6d2c58 615 prepared_action = PREPARED_GET_MAX_SPEED;
Davidroid 0:92706998571a 616 }
Davidroid 0:92706998571a 617
Davidroid 1:b78dab6d2c58 618 /**
Davidroid 1:b78dab6d2c58 619 * @brief Preparing the command to get the minimum speed in pps.
Davidroid 1:b78dab6d2c58 620 * @param None.
Davidroid 1:b78dab6d2c58 621 * @retval None.
Davidroid 1:b78dab6d2c58 622 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 623 */
Davidroid 0:92706998571a 624 virtual void PrepareGetMinSpeed(void)
Davidroid 0:92706998571a 625 {
Davidroid 0:92706998571a 626 L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID);
Davidroid 1:b78dab6d2c58 627 prepared_action = PREPARED_GET_MIN_SPEED;
Davidroid 0:92706998571a 628 }
Davidroid 0:92706998571a 629
Davidroid 1:b78dab6d2c58 630 /**
Davidroid 1:b78dab6d2c58 631 * @brief Preparing the command to get the acceleration in pps^2.
Davidroid 1:b78dab6d2c58 632 * @param None.
Davidroid 1:b78dab6d2c58 633 * @retval None.
Davidroid 1:b78dab6d2c58 634 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 635 */
Davidroid 0:92706998571a 636 virtual void PrepareGetAcceleration(void)
Davidroid 0:92706998571a 637 {
Davidroid 0:92706998571a 638 L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID);
Davidroid 1:b78dab6d2c58 639 prepared_action = PREPARED_GET_ACCELERATION;
Davidroid 0:92706998571a 640 }
Davidroid 0:92706998571a 641
Davidroid 1:b78dab6d2c58 642 /**
Davidroid 1:b78dab6d2c58 643 * @brief Preparing the command to get the deceleration in pps^2.
Davidroid 1:b78dab6d2c58 644 * @param None.
Davidroid 1:b78dab6d2c58 645 * @retval None.
Davidroid 1:b78dab6d2c58 646 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 647 */
Davidroid 0:92706998571a 648 virtual void PrepareGetDeceleration(void)
Davidroid 0:92706998571a 649 {
Davidroid 0:92706998571a 650 L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID);
Davidroid 1:b78dab6d2c58 651 prepared_action = PREPARED_GET_DECELERATION;
Davidroid 0:92706998571a 652 }
Davidroid 0:92706998571a 653
Davidroid 1:b78dab6d2c58 654 /**
Davidroid 1:b78dab6d2c58 655 * @brief Preparing the command to get the direction of rotation.
Davidroid 1:b78dab6d2c58 656 * @param None.
Davidroid 1:b78dab6d2c58 657 * @retval None.
Davidroid 1:b78dab6d2c58 658 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 659 */
Davidroid 1:b78dab6d2c58 660 virtual void PrepareGetDirection(void)
Davidroid 0:92706998571a 661 {
Davidroid 1:b78dab6d2c58 662 if (!L6470_DaisyChain_HalfPrepared)
Davidroid 1:b78dab6d2c58 663 {
Davidroid 1:b78dab6d2c58 664 /* To avoid deleting the previous entered command. */
Davidroid 1:b78dab6d2c58 665 L6470_DaisyChain_HalfPrepared = ONE_F;
Davidroid 1:b78dab6d2c58 666 /* Resetting commands. */
Davidroid 1:b78dab6d2c58 667 L6470_ResetAppCmdPkg(L6470_AppCmdPkg);
Davidroid 1:b78dab6d2c58 668 }
Davidroid 1:b78dab6d2c58 669 prepared_action = PREPARED_GET_DIRECTION;
Davidroid 0:92706998571a 670 }
Davidroid 0:92706998571a 671
Davidroid 1:b78dab6d2c58 672 /**
Davidroid 1:b78dab6d2c58 673 * @brief Preparing the command to set a parameter.
Davidroid 1:b78dab6d2c58 674 * @param parameter The parameter's identifier (or its register address).
Davidroid 1:b78dab6d2c58 675 * @param value The parameter's value.
Davidroid 1:b78dab6d2c58 676 * @retval None.
Davidroid 1:b78dab6d2c58 677 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 678 */
Davidroid 0:92706998571a 679 virtual void PrepareSetParameter(unsigned int parameter, unsigned int value)
Davidroid 0:92706998571a 680 {
Davidroid 0:92706998571a 681 L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value);
Davidroid 1:b78dab6d2c58 682 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 683 }
Davidroid 0:92706998571a 684
Davidroid 1:b78dab6d2c58 685 /**
Davidroid 1:b78dab6d2c58 686 * @brief Preparing the command to set the current position to be
Davidroid 1:b78dab6d2c58 687 * the home position.
Davidroid 1:b78dab6d2c58 688 * @param None.
Davidroid 1:b78dab6d2c58 689 * @retval None.
Davidroid 1:b78dab6d2c58 690 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 691 */
Davidroid 0:92706998571a 692 virtual void PrepareSetHome(void)
Davidroid 0:92706998571a 693 {
Davidroid 0:92706998571a 694 L6470_PrepareResetPos();
Davidroid 1:b78dab6d2c58 695 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 696 }
Davidroid 0:92706998571a 697
Davidroid 1:b78dab6d2c58 698 /**
Davidroid 1:b78dab6d2c58 699 * @brief Preparing the command to set the current position to be
Davidroid 1:b78dab6d2c58 700 * the marked position.
Davidroid 1:b78dab6d2c58 701 * @param None.
Davidroid 1:b78dab6d2c58 702 * @retval None.
Davidroid 1:b78dab6d2c58 703 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 704 */
Davidroid 0:92706998571a 705 virtual void PrepareSetMark(void)
Davidroid 0:92706998571a 706 {
Davidroid 1:b78dab6d2c58 707 /*
Davidroid 1:b78dab6d2c58 708 Set "0" now as marked position. This value will be replaced by the
Davidroid 1:b78dab6d2c58 709 actual position read at the time when the prepared actions will be
Davidroid 1:b78dab6d2c58 710 performed.
Davidroid 1:b78dab6d2c58 711 */
Davidroid 1:b78dab6d2c58 712 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0);
Davidroid 1:b78dab6d2c58 713 prepared_action = PREPARED_SET_MARK;
Davidroid 0:92706998571a 714 }
Davidroid 0:92706998571a 715
Davidroid 1:b78dab6d2c58 716 /**
Davidroid 1:b78dab6d2c58 717 * @brief Preparing the command to set the given position to be
Davidroid 1:b78dab6d2c58 718 * the marked position.
Davidroid 1:b78dab6d2c58 719 * @param position The given position.
Davidroid 1:b78dab6d2c58 720 * @retval None.
Davidroid 1:b78dab6d2c58 721 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 722 */
Davidroid 1:b78dab6d2c58 723 virtual void PrepareSetMark(signed int position)
Davidroid 1:b78dab6d2c58 724 {
Davidroid 1:b78dab6d2c58 725 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 1:b78dab6d2c58 726 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 727 }
Davidroid 1:b78dab6d2c58 728
Davidroid 1:b78dab6d2c58 729 /**
Davidroid 1:b78dab6d2c58 730 * @brief Preparing the command to set the current speed in pps.
Davidroid 1:b78dab6d2c58 731 * @param speed The current speed in pps.
Davidroid 1:b78dab6d2c58 732 * @retval None.
Davidroid 1:b78dab6d2c58 733 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 734 */
Davidroid 1:b78dab6d2c58 735 virtual void PrepareSetSpeed(unsigned int speed)
Davidroid 1:b78dab6d2c58 736 {
Davidroid 1:b78dab6d2c58 737 L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed));
Davidroid 1:b78dab6d2c58 738 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 739 }
Davidroid 1:b78dab6d2c58 740
Davidroid 1:b78dab6d2c58 741 /**
Davidroid 1:b78dab6d2c58 742 * @brief Preparing the command to set the maximum speed in pps.
Davidroid 1:b78dab6d2c58 743 * @param speed The maximum speed in pps.
Davidroid 1:b78dab6d2c58 744 * @retval None.
Davidroid 1:b78dab6d2c58 745 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 746 */
Davidroid 0:92706998571a 747 virtual void PrepareSetMaxSpeed(unsigned int speed)
Davidroid 0:92706998571a 748 {
Davidroid 1:b78dab6d2c58 749 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
Davidroid 1:b78dab6d2c58 750 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 751 }
Davidroid 0:92706998571a 752
Davidroid 1:b78dab6d2c58 753 /**
Davidroid 1:b78dab6d2c58 754 * @brief Preparing the command to set the minimum speed in pps.
Davidroid 1:b78dab6d2c58 755 * @param speed The minimum speed in pps.
Davidroid 1:b78dab6d2c58 756 * @retval None.
Davidroid 1:b78dab6d2c58 757 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 758 */
Davidroid 1:b78dab6d2c58 759 virtual void PrepareSetMinSpeed(unsigned int speed)
Davidroid 1:b78dab6d2c58 760 {
Davidroid 1:b78dab6d2c58 761 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
Davidroid 1:b78dab6d2c58 762 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 763 }
Davidroid 1:b78dab6d2c58 764
Davidroid 1:b78dab6d2c58 765 /**
Davidroid 1:b78dab6d2c58 766 * @brief Preparing the command to set the acceleration in pps^2.
Davidroid 1:b78dab6d2c58 767 * @param acceleration The acceleration in pps^2.
Davidroid 1:b78dab6d2c58 768 * @retval None.
Davidroid 1:b78dab6d2c58 769 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 770 */
Davidroid 0:92706998571a 771 virtual void PrepareSetAcceleration(unsigned int acceleration)
Davidroid 0:92706998571a 772 {
Davidroid 1:b78dab6d2c58 773 L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
Davidroid 1:b78dab6d2c58 774 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 775 }
Davidroid 0:92706998571a 776
Davidroid 1:b78dab6d2c58 777 /**
Davidroid 1:b78dab6d2c58 778 * @brief Preparing the command to set the deceleration in pps^2.
Davidroid 1:b78dab6d2c58 779 * @param deceleration The deceleration in pps^2.
Davidroid 1:b78dab6d2c58 780 * @retval None.
Davidroid 1:b78dab6d2c58 781 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 782 */
Davidroid 1:b78dab6d2c58 783 virtual void PrepareSetDeceleration(unsigned int deceleration)
Davidroid 0:92706998571a 784 {
Davidroid 1:b78dab6d2c58 785 L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
Davidroid 1:b78dab6d2c58 786 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 787 }
Davidroid 0:92706998571a 788
Davidroid 1:b78dab6d2c58 789 /**
Davidroid 1:b78dab6d2c58 790 * @brief Preparing the command to go to a specified position.
Davidroid 1:b78dab6d2c58 791 * @param position The desired position.
Davidroid 1:b78dab6d2c58 792 * @retval None.
Davidroid 1:b78dab6d2c58 793 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 794 */
Davidroid 1:b78dab6d2c58 795 virtual void PrepareGoTo(signed int position)
Davidroid 1:b78dab6d2c58 796 {
Davidroid 1:b78dab6d2c58 797 L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 1:b78dab6d2c58 798 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 799 }
Davidroid 1:b78dab6d2c58 800
Davidroid 1:b78dab6d2c58 801 /**
Davidroid 1:b78dab6d2c58 802 * @brief Preparing the command to go to a specified position
Davidroid 1:b78dab6d2c58 803 * imposing the desired direction.
Davidroid 1:b78dab6d2c58 804 * @param position The desired position.
Davidroid 1:b78dab6d2c58 805 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 806 * @retval None.
Davidroid 1:b78dab6d2c58 807 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 808 */
Davidroid 0:92706998571a 809 virtual void PrepareGoTo(signed int position, direction_t direction)
Davidroid 0:92706998571a 810 {
Davidroid 1:b78dab6d2c58 811 L6470_PrepareGoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 1:b78dab6d2c58 812 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 813 }
Davidroid 0:92706998571a 814
Davidroid 1:b78dab6d2c58 815 /**
Davidroid 1:b78dab6d2c58 816 * @brief Preparing the command to go to the home position.
Davidroid 1:b78dab6d2c58 817 * @param None.
Davidroid 1:b78dab6d2c58 818 * @retval None.
Davidroid 1:b78dab6d2c58 819 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 820 */
Davidroid 0:92706998571a 821 virtual void PrepareGoHome(void)
Davidroid 0:92706998571a 822 {
Davidroid 0:92706998571a 823 L6470_PrepareGoHome();
Davidroid 1:b78dab6d2c58 824 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 825 }
Davidroid 0:92706998571a 826
Davidroid 1:b78dab6d2c58 827 /**
Davidroid 1:b78dab6d2c58 828 * @brief Preparing the command to go to the marked position.
Davidroid 1:b78dab6d2c58 829 * @param None.
Davidroid 1:b78dab6d2c58 830 * @retval None.
Davidroid 1:b78dab6d2c58 831 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 832 */
Davidroid 0:92706998571a 833 virtual void PrepareGoMark(void)
Davidroid 0:92706998571a 834 {
Davidroid 0:92706998571a 835 L6470_PrepareGoMark();
Davidroid 1:b78dab6d2c58 836 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 837 }
Davidroid 0:92706998571a 838
Davidroid 1:b78dab6d2c58 839 /**
Davidroid 1:b78dab6d2c58 840 * @brief Preparing the command to run at the given speed imposing the desired
Davidroid 1:b78dab6d2c58 841 * direction until an external switch turn-on event occurs.
Davidroid 1:b78dab6d2c58 842 * @param action The identifier of the action about the absolute position.
Davidroid 1:b78dab6d2c58 843 * @param position The desired position.
Davidroid 1:b78dab6d2c58 844 * @param speed The speed value in pps.
Davidroid 1:b78dab6d2c58 845 * @retval None.
Davidroid 1:b78dab6d2c58 846 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 847 * The identifier of the action about the absolute position can be
Davidroid 1:b78dab6d2c58 848 * one of the following:
Davidroid 1:b78dab6d2c58 849 * + L6470_ACT_RST_ID: the absolute position is reset;
Davidroid 1:b78dab6d2c58 850 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
Davidroid 1:b78dab6d2c58 851 */
Davidroid 0:92706998571a 852 virtual void PrepareGoUntil(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed)
Davidroid 0:92706998571a 853 {
Davidroid 1:b78dab6d2c58 854 L6470_PrepareGoUntil((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed));
Davidroid 1:b78dab6d2c58 855 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 856 }
Davidroid 0:92706998571a 857
Davidroid 1:b78dab6d2c58 858 /**
Davidroid 1:b78dab6d2c58 859 * @brief Preparing the command to run towards a specified direction
Davidroid 1:b78dab6d2c58 860 * at the maximum speed.
Davidroid 1:b78dab6d2c58 861 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 862 * @retval None.
Davidroid 1:b78dab6d2c58 863 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 864 */
Davidroid 0:92706998571a 865 virtual void PrepareRun(direction_t direction)
Davidroid 0:92706998571a 866 {
Davidroid 0:92706998571a 867 L6470_PrepareRun((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID));
Davidroid 1:b78dab6d2c58 868 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 869 }
Davidroid 0:92706998571a 870
Davidroid 1:b78dab6d2c58 871 /**
Davidroid 1:b78dab6d2c58 872 * @brief Preparing the command to run towards a specified direction
Davidroid 1:b78dab6d2c58 873 * at the given speed.
Davidroid 1:b78dab6d2c58 874 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 875 * @param speed The speed value in pps.
Davidroid 1:b78dab6d2c58 876 * @retval None.
Davidroid 1:b78dab6d2c58 877 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 878 */
Davidroid 0:92706998571a 879 virtual void PrepareRun(direction_t direction, unsigned int speed)
Davidroid 0:92706998571a 880 {
Davidroid 1:b78dab6d2c58 881 L6470_PrepareRun((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed));
Davidroid 1:b78dab6d2c58 882 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 883 }
Davidroid 0:92706998571a 884
Davidroid 1:b78dab6d2c58 885 /**
Davidroid 1:b78dab6d2c58 886 * @brief Preparing the command to move towards a specified direction
Davidroid 1:b78dab6d2c58 887 * for a certain number of steps.
Davidroid 1:b78dab6d2c58 888 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 889 * @param steps The desired number of steps.
Davidroid 1:b78dab6d2c58 890 * @retval None.
Davidroid 1:b78dab6d2c58 891 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 892 */
Davidroid 0:92706998571a 893 virtual void PrepareMove(direction_t direction, unsigned int steps)
Davidroid 0:92706998571a 894 {
Davidroid 0:92706998571a 895 L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
Davidroid 1:b78dab6d2c58 896 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 897 }
Davidroid 0:92706998571a 898
Davidroid 1:b78dab6d2c58 899 /**
Davidroid 1:b78dab6d2c58 900 * @brief Preparing the command to stop the motor.
Davidroid 1:b78dab6d2c58 901 * @param None.
Davidroid 1:b78dab6d2c58 902 * @retval None.
Davidroid 1:b78dab6d2c58 903 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 904 */
Davidroid 0:92706998571a 905 virtual void PrepareSoftStop(void)
Davidroid 0:92706998571a 906 {
Davidroid 0:92706998571a 907 L6470_PrepareSoftStop();
Davidroid 1:b78dab6d2c58 908 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 909 }
Davidroid 0:92706998571a 910
Davidroid 1:b78dab6d2c58 911 /**
Davidroid 1:b78dab6d2c58 912 * @brief Preparing the command to stop the motor and disabling the power bridge.
Davidroid 1:b78dab6d2c58 913 * @param None.
Davidroid 1:b78dab6d2c58 914 * @retval None.
Davidroid 1:b78dab6d2c58 915 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 916 */
Davidroid 0:92706998571a 917 virtual void PrepareHardStop(void)
Davidroid 0:92706998571a 918 {
Davidroid 0:92706998571a 919 L6470_PrepareHardStop();
Davidroid 1:b78dab6d2c58 920 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 921 }
Davidroid 0:92706998571a 922
Davidroid 1:b78dab6d2c58 923 /**
Davidroid 1:b78dab6d2c58 924 * @brief Preparing the command to disable the power bridge after performing
Davidroid 1:b78dab6d2c58 925 * a deceleration to zero.
Davidroid 1:b78dab6d2c58 926 * The used deceleration value is the one stored in the "DEC" register.
Davidroid 1:b78dab6d2c58 927 * @param None.
Davidroid 1:b78dab6d2c58 928 * @retval None.
Davidroid 1:b78dab6d2c58 929 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 930 */
Davidroid 0:92706998571a 931 virtual void PrepareSoftHiZ(void)
Davidroid 0:92706998571a 932 {
Davidroid 0:92706998571a 933 L6470_PrepareSoftHiZ();
Davidroid 1:b78dab6d2c58 934 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 935 }
Davidroid 0:92706998571a 936
Davidroid 1:b78dab6d2c58 937 /**
Davidroid 1:b78dab6d2c58 938 * @brief Preparing the command to disable the power bridge immediately.
Davidroid 1:b78dab6d2c58 939 * @param None.
Davidroid 1:b78dab6d2c58 940 * @retval None.
Davidroid 1:b78dab6d2c58 941 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 942 */
Davidroid 0:92706998571a 943 virtual void PrepareHardHiZ(void)
Davidroid 0:92706998571a 944 {
Davidroid 0:92706998571a 945 L6470_PrepareHardHiZ();
Davidroid 1:b78dab6d2c58 946 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 947 }
Davidroid 1:b78dab6d2c58 948
Davidroid 1:b78dab6d2c58 949 /**
Davidroid 1:b78dab6d2c58 950 * @brief Preparing the command to switch to step-clock mode.
Davidroid 1:b78dab6d2c58 951 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 952 * @retval None.
Davidroid 1:b78dab6d2c58 953 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 954 */
Davidroid 1:b78dab6d2c58 955 virtual void PrepareStepClock(direction_t direction)
Davidroid 1:b78dab6d2c58 956 {
Davidroid 1:b78dab6d2c58 957 L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
Davidroid 1:b78dab6d2c58 958 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 959 }
Davidroid 0:92706998571a 960
Davidroid 1:b78dab6d2c58 961 /**
Davidroid 1:b78dab6d2c58 962 * @brief Preparing the command to do a motion at minimum speed
Davidroid 1:b78dab6d2c58 963 * imposing a specified direction until the SW is released.
Davidroid 1:b78dab6d2c58 964 * @param action The identifier of the action about the absolute position.
Davidroid 1:b78dab6d2c58 965 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 966 * @retval None.
Davidroid 1:b78dab6d2c58 967 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 968 * The identifier of the action about the absolute position can be
Davidroid 1:b78dab6d2c58 969 * one of the following:
Davidroid 1:b78dab6d2c58 970 * + L6470_ACT_RST_ID: the absolute position is reset;
Davidroid 1:b78dab6d2c58 971 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
Davidroid 1:b78dab6d2c58 972 */
Davidroid 1:b78dab6d2c58 973 virtual void PrepareReleaseSW(eL6470_ActId_t action, direction_t direction)
Davidroid 0:92706998571a 974 {
Davidroid 1:b78dab6d2c58 975 L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
Davidroid 1:b78dab6d2c58 976 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 977 }
Davidroid 1:b78dab6d2c58 978
Davidroid 1:b78dab6d2c58 979 /**
Davidroid 1:b78dab6d2c58 980 * @brief Preparing the command to reset the device to power-up conditions.
Davidroid 1:b78dab6d2c58 981 * @param None.
Davidroid 1:b78dab6d2c58 982 * @retval None.
Davidroid 1:b78dab6d2c58 983 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 984 */
Davidroid 1:b78dab6d2c58 985 virtual void PrepareResetDevice(void)
Davidroid 1:b78dab6d2c58 986 {
Davidroid 1:b78dab6d2c58 987 L6470_PrepareResetDevice();
Davidroid 1:b78dab6d2c58 988 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 989 }
Davidroid 0:92706998571a 990
Davidroid 1:b78dab6d2c58 991 /**
Davidroid 1:b78dab6d2c58 992 * @brief Performing all the actions prepared on the components
Davidroid 1:b78dab6d2c58 993 * of the daisy-chain.
Davidroid 1:b78dab6d2c58 994 * @param None.
Davidroid 1:b78dab6d2c58 995 * @retval The raw data returned by the components.
Davidroid 1:b78dab6d2c58 996 */
Davidroid 1:b78dab6d2c58 997 uint8_t* PerformPreparedActions(void)
Davidroid 0:92706998571a 998 {
Davidroid 1:b78dab6d2c58 999 return L6470_PerformPreparedApplicationCommand();
Davidroid 1:b78dab6d2c58 1000 }
Davidroid 1:b78dab6d2c58 1001
Davidroid 1:b78dab6d2c58 1002 /**
Davidroid 1:b78dab6d2c58 1003 * @brief Getting the prepared action.
Davidroid 1:b78dab6d2c58 1004 * @param None
Davidroid 1:b78dab6d2c58 1005 * @retval The prepared action.
Davidroid 1:b78dab6d2c58 1006 */
Davidroid 1:b78dab6d2c58 1007 prepared_action_t GetPreparedAction(void)
Davidroid 1:b78dab6d2c58 1008 {
Davidroid 1:b78dab6d2c58 1009 return prepared_action;
Davidroid 0:92706998571a 1010 }
Davidroid 0:92706998571a 1011
Davidroid 1:b78dab6d2c58 1012 /**
Davidroid 1:b78dab6d2c58 1013 * @brief Converting the raw data received by the component according to
Davidroid 1:b78dab6d2c58 1014 * the action performed on it.
Davidroid 1:b78dab6d2c58 1015 * @param raw_data The received raw data.
Davidroid 1:b78dab6d2c58 1016 * @retval The result of the action performed.
Davidroid 1:b78dab6d2c58 1017 */
Davidroid 1:b78dab6d2c58 1018 int32_t GetResult(uint8_t *raw_data)
Davidroid 0:92706998571a 1019 {
Davidroid 1:b78dab6d2c58 1020 switch (prepared_action)
Davidroid 1:b78dab6d2c58 1021 {
Davidroid 1:b78dab6d2c58 1022 case PREPARED_GET_POSITION:
Davidroid 1:b78dab6d2c58 1023 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte));
Davidroid 1:b78dab6d2c58 1024
Davidroid 1:b78dab6d2c58 1025 case PREPARED_GET_MARK:
Davidroid 1:b78dab6d2c58 1026 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte));
Davidroid 0:92706998571a 1027
Davidroid 1:b78dab6d2c58 1028 case PREPARED_GET_SPEED:
Davidroid 1:b78dab6d2c58 1029 return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1030
Davidroid 1:b78dab6d2c58 1031 case PREPARED_GET_MAX_SPEED:
Davidroid 1:b78dab6d2c58 1032 return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1033
Davidroid 1:b78dab6d2c58 1034 case PREPARED_GET_MIN_SPEED:
Davidroid 1:b78dab6d2c58 1035 return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1036
Davidroid 1:b78dab6d2c58 1037 case PREPARED_GET_ACCELERATION:
Davidroid 1:b78dab6d2c58 1038 return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1039
Davidroid 1:b78dab6d2c58 1040 case PREPARED_GET_DECELERATION:
Davidroid 1:b78dab6d2c58 1041 return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1042
Davidroid 1:b78dab6d2c58 1043 case PREPARED_GET_DIRECTION:
Davidroid 1:b78dab6d2c58 1044 return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
Davidroid 1:b78dab6d2c58 1045
Davidroid 1:b78dab6d2c58 1046 default:
Davidroid 1:b78dab6d2c58 1047 case PREPARED_NO_ACTION:
Davidroid 1:b78dab6d2c58 1048 return 0;
Davidroid 1:b78dab6d2c58 1049 }
Davidroid 0:92706998571a 1050 }
Davidroid 0:92706998571a 1051
Davidroid 0:92706998571a 1052
Davidroid 0:92706998571a 1053 /*** Public Interrupt Related Methods ***/
Davidroid 0:92706998571a 1054
Davidroid 0:92706998571a 1055 /* ACTION 6 --------------------------------------------------------------*
Davidroid 0:92706998571a 1056 * Implement here interrupt related methods, if any. *
Davidroid 0:92706998571a 1057 * Note that interrupt handling is platform dependent, e.g.: *
Davidroid 0:92706998571a 1058 * + mbed: *
Davidroid 0:92706998571a 1059 * InterruptIn feature_irq(pin); //Interrupt object. *
Davidroid 0:92706998571a 1060 * feature_irq.rise(callback); //Attach a callback. *
Davidroid 0:92706998571a 1061 * feature_irq.mode(PullNone); //Set interrupt mode. *
Davidroid 0:92706998571a 1062 * feature_irq.enable_irq(); //Enable interrupt. *
Davidroid 0:92706998571a 1063 * feature_irq.disable_irq(); //Disable interrupt. *
Davidroid 0:92706998571a 1064 * + Arduino: *
Davidroid 0:92706998571a 1065 * attachInterrupt(pin, callback, RISING); //Attach a callback. *
Davidroid 0:92706998571a 1066 * detachInterrupt(pin); //Detach a callback. *
Davidroid 0:92706998571a 1067 * *
Davidroid 0:92706998571a 1068 * Example (mbed): *
Davidroid 0:92706998571a 1069 * void AttachFeatureIRQ(void (*fptr) (void)) *
Davidroid 0:92706998571a 1070 * { *
Davidroid 0:92706998571a 1071 * feature_irq.rise(fptr); *
Davidroid 0:92706998571a 1072 * } *
Davidroid 0:92706998571a 1073 * *
Davidroid 0:92706998571a 1074 * void EnableFeatureIRQ(void) *
Davidroid 0:92706998571a 1075 * { *
Davidroid 0:92706998571a 1076 * feature_irq.enable_irq(); *
Davidroid 0:92706998571a 1077 * } *
Davidroid 0:92706998571a 1078 * *
Davidroid 0:92706998571a 1079 * void DisableFeatureIRQ(void) *
Davidroid 0:92706998571a 1080 * { *
Davidroid 0:92706998571a 1081 * feature_irq.disable_irq(); *
Davidroid 0:92706998571a 1082 * } *
Davidroid 0:92706998571a 1083 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1084 /**
Davidroid 1:b78dab6d2c58 1085 * @brief Attaching an interrupt handler to the FLAG interrupt.
Davidroid 1:b78dab6d2c58 1086 * @param fptr An interrupt handler.
Davidroid 0:92706998571a 1087 * @retval None.
Davidroid 0:92706998571a 1088 */
Davidroid 0:92706998571a 1089 void AttachFlagIRQ(void (*fptr)(void))
Davidroid 0:92706998571a 1090 {
Davidroid 0:92706998571a 1091 flag_irq.rise(fptr);
Davidroid 0:92706998571a 1092 }
Davidroid 0:92706998571a 1093
Davidroid 0:92706998571a 1094 /**
Davidroid 1:b78dab6d2c58 1095 * @brief Enabling the FLAG interrupt handling.
Davidroid 0:92706998571a 1096 * @param None.
Davidroid 0:92706998571a 1097 * @retval None.
Davidroid 0:92706998571a 1098 */
Davidroid 0:92706998571a 1099 void EnableFlagIRQ(void)
Davidroid 0:92706998571a 1100 {
Davidroid 0:92706998571a 1101 flag_irq.enable_irq();
Davidroid 0:92706998571a 1102 }
Davidroid 0:92706998571a 1103
Davidroid 0:92706998571a 1104 /**
Davidroid 1:b78dab6d2c58 1105 * @brief Disabling the FLAG interrupt handling.
Davidroid 0:92706998571a 1106 * @param None.
Davidroid 0:92706998571a 1107 * @retval None.
Davidroid 0:92706998571a 1108 */
Davidroid 0:92706998571a 1109 void DisableFlagIRQ(void)
Davidroid 0:92706998571a 1110 {
Davidroid 0:92706998571a 1111 flag_irq.disable_irq();
Davidroid 0:92706998571a 1112 }
Davidroid 0:92706998571a 1113
Davidroid 1:b78dab6d2c58 1114 /**
Davidroid 1:b78dab6d2c58 1115 * @brief Attaching an interrupt handler to the BUSY interrupt.
Davidroid 1:b78dab6d2c58 1116 * @param fptr An interrupt handler.
Davidroid 1:b78dab6d2c58 1117 * @retval None.
Davidroid 1:b78dab6d2c58 1118 */
Davidroid 1:b78dab6d2c58 1119 void AttachBusyIRQ(void (*fptr)(void))
Davidroid 1:b78dab6d2c58 1120 {
Davidroid 1:b78dab6d2c58 1121 busy_irq.rise(fptr);
Davidroid 1:b78dab6d2c58 1122 }
Davidroid 1:b78dab6d2c58 1123
Davidroid 1:b78dab6d2c58 1124 /**
Davidroid 1:b78dab6d2c58 1125 * @brief Enabling the BUSY interrupt handling.
Davidroid 1:b78dab6d2c58 1126 * @param None.
Davidroid 1:b78dab6d2c58 1127 * @retval None.
Davidroid 1:b78dab6d2c58 1128 */
Davidroid 1:b78dab6d2c58 1129 void EnableBusyIRQ(void)
Davidroid 1:b78dab6d2c58 1130 {
Davidroid 1:b78dab6d2c58 1131 busy_irq.enable_irq();
Davidroid 1:b78dab6d2c58 1132 }
Davidroid 1:b78dab6d2c58 1133
Davidroid 1:b78dab6d2c58 1134 /**
Davidroid 1:b78dab6d2c58 1135 * @brief Disabling the BUSY interrupt handling.
Davidroid 1:b78dab6d2c58 1136 * @param None.
Davidroid 1:b78dab6d2c58 1137 * @retval None.
Davidroid 1:b78dab6d2c58 1138 */
Davidroid 1:b78dab6d2c58 1139 void DisableBusyIRQ(void)
Davidroid 1:b78dab6d2c58 1140 {
Davidroid 1:b78dab6d2c58 1141 busy_irq.disable_irq();
Davidroid 1:b78dab6d2c58 1142 }
Davidroid 1:b78dab6d2c58 1143
Davidroid 0:92706998571a 1144
Davidroid 0:92706998571a 1145 protected:
Davidroid 0:92706998571a 1146
Davidroid 0:92706998571a 1147 /*** Protected Component Related Methods ***/
Davidroid 0:92706998571a 1148
Davidroid 0:92706998571a 1149 /* ACTION 7 --------------------------------------------------------------*
Davidroid 0:92706998571a 1150 * Declare here the component's specific methods. *
Davidroid 0:92706998571a 1151 * They should be: *
Davidroid 0:92706998571a 1152 * + Methods with the same name of the C component's virtual table's *
Davidroid 0:92706998571a 1153 * functions (1); *
Davidroid 0:92706998571a 1154 * + Methods with the same name of the C component's extended virtual *
Davidroid 0:92706998571a 1155 * table's functions, if any (2); *
Davidroid 0:92706998571a 1156 * + Helper methods, if any, like functions declared in the component's *
Davidroid 0:92706998571a 1157 * source files but not pointed by the component's virtual table (3). *
Davidroid 0:92706998571a 1158 * *
Davidroid 0:92706998571a 1159 * Example: *
Davidroid 0:92706998571a 1160 * DrvStatusTypeDef COMPONENT_GetValue(float* pfData); //(1) *
Davidroid 0:92706998571a 1161 * DrvStatusTypeDef COMPONENT_EnableFeature(void); //(2) *
Davidroid 0:92706998571a 1162 * DrvStatusTypeDef COMPONENT_ComputeAverage(void); //(3) *
Davidroid 0:92706998571a 1163 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1164 int32_t L6470_AbsPos_2_Position(uint32_t AbsPos);
Davidroid 0:92706998571a 1165 uint32_t L6470_Position_2_AbsPos(int32_t Position);
Davidroid 0:92706998571a 1166 float L6470_Speed_2_Step_s(uint32_t Speed);
Davidroid 0:92706998571a 1167 uint32_t L6470_Step_s_2_Speed(float Step_s);
Davidroid 0:92706998571a 1168 float L6470_Acc_2_Step_s2(uint16_t Acc);
Davidroid 0:92706998571a 1169 uint16_t L6470_Step_s2_2_Acc(float Step_s2);
Davidroid 0:92706998571a 1170 float L6470_Dec_2_Step_s2(uint16_t Dec);
Davidroid 0:92706998571a 1171 uint16_t L6470_Step_s2_2_Dec(float Step_s2);
Davidroid 0:92706998571a 1172 float L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed);
Davidroid 0:92706998571a 1173 uint16_t L6470_Step_s_2_MaxSpeed(float Step_s);
Davidroid 0:92706998571a 1174 float L6470_MinSpeed_2_Step_s(uint16_t MinSpeed);
Davidroid 0:92706998571a 1175 uint16_t L6470_Step_s_2_MinSpeed(float Step_s);
Davidroid 0:92706998571a 1176 float L6470_FsSpd_2_Step_s(uint16_t FsSpd);
Davidroid 0:92706998571a 1177 uint16_t L6470_Step_s_2_FsSpd(float Step_s);
Davidroid 0:92706998571a 1178 float L6470_IntSpeed_2_Step_s(uint16_t IntSpeed);
Davidroid 0:92706998571a 1179 uint16_t L6470_Step_s_2_IntSpeed(float Step_s);
Davidroid 0:92706998571a 1180 float L6470_StSlp_2_s_Step(uint8_t StSlp);
Davidroid 0:92706998571a 1181 uint8_t L6470_s_Step_2_StSlp(float s_Step);
Davidroid 0:92706998571a 1182 float L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc);
Davidroid 0:92706998571a 1183 uint8_t L6470_s_Step_2_FnSlpAcc(float s_Step);
Davidroid 0:92706998571a 1184 float L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec);
Davidroid 0:92706998571a 1185 uint8_t L6470_s_Step_2_FnSlpDec(float s_Step);
Davidroid 0:92706998571a 1186 float L6470_OcdTh_2_mA(uint8_t OcdTh);
Davidroid 0:92706998571a 1187 uint8_t L6470_mA_2_OcdTh(float mA);
Davidroid 0:92706998571a 1188 float L6470_StallTh_2_mA(uint8_t StallTh);
Davidroid 0:92706998571a 1189 uint8_t L6470_mA_2_StallTh(float mA);
Davidroid 0:92706998571a 1190 DrvStatusTypeDef L6470_Config(MICROSTEPPING_MOTOR_InitTypeDef *MotorParameterData);
Davidroid 0:92706998571a 1191 void L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
Davidroid 0:92706998571a 1192 uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId);
Davidroid 0:92706998571a 1193 void L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1194 void L6470_StepClock(eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1195 void L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
Davidroid 0:92706998571a 1196 void L6470_GoTo(uint32_t AbsPos);
Davidroid 0:92706998571a 1197 void L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
Davidroid 0:92706998571a 1198 void L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1199 void L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1200 void L6470_GoHome(void);
Davidroid 0:92706998571a 1201 void L6470_GoMark(void);
Davidroid 0:92706998571a 1202 void L6470_ResetPos(void);
Davidroid 0:92706998571a 1203 void L6470_ResetDevice(void);
Davidroid 0:92706998571a 1204 void L6470_SoftStop(void);
Davidroid 0:92706998571a 1205 void L6470_HardStop(void);
Davidroid 0:92706998571a 1206 void L6470_SoftHiZ(void);
Davidroid 0:92706998571a 1207 void L6470_HardHiZ(void);
Davidroid 0:92706998571a 1208 uint16_t L6470_GetStatus(void);
Davidroid 0:92706998571a 1209 void L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
Davidroid 0:92706998571a 1210 void L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId);
Davidroid 0:92706998571a 1211 void L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1212 void L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1213 void L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
Davidroid 0:92706998571a 1214 void L6470_PrepareGoTo(uint32_t AbsPos);
Davidroid 0:92706998571a 1215 void L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
Davidroid 0:92706998571a 1216 void L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1217 void L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1218 void L6470_PrepareGoHome(void);
Davidroid 0:92706998571a 1219 void L6470_PrepareGoMark(void);
Davidroid 0:92706998571a 1220 void L6470_PrepareResetPos(void);
Davidroid 0:92706998571a 1221 void L6470_PrepareResetDevice(void);
Davidroid 0:92706998571a 1222 void L6470_PrepareSoftStop(void);
Davidroid 0:92706998571a 1223 void L6470_PrepareHardStop(void);
Davidroid 0:92706998571a 1224 void L6470_PrepareSoftHiZ(void);
Davidroid 0:92706998571a 1225 void L6470_PrepareHardHiZ(void);
Davidroid 0:92706998571a 1226 void L6470_PrepareGetStatus(void);
Davidroid 0:92706998571a 1227 uint8_t* L6470_PerformPreparedApplicationCommand(void);
Davidroid 0:92706998571a 1228 void L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 1229 uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
Davidroid 0:92706998571a 1230 uint8_t L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId);
Davidroid 0:92706998571a 1231 uint8_t* L6470_GetRegisterName(uint8_t id);
Davidroid 0:92706998571a 1232 void L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg);
Davidroid 0:92706998571a 1233 void L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
Davidroid 0:92706998571a 1234 void L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
Davidroid 0:92706998571a 1235 void L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 1236
Davidroid 1:b78dab6d2c58 1237 /**
Davidroid 1:b78dab6d2c58 1238 * @brief Rounding a floating point number to the nearest unsigned integer number.
Davidroid 1:b78dab6d2c58 1239 * @param f The floating point number.
Davidroid 1:b78dab6d2c58 1240 * @retval The nearest unsigned integer number.
Davidroid 1:b78dab6d2c58 1241 */
Davidroid 1:b78dab6d2c58 1242 int round(float f)
Davidroid 1:b78dab6d2c58 1243 {
Davidroid 1:b78dab6d2c58 1244 if (f >= 0)
Davidroid 1:b78dab6d2c58 1245 return (int) f + (f - (int) f < 0.5f ? 0 : 1);
Davidroid 1:b78dab6d2c58 1246 else
Davidroid 1:b78dab6d2c58 1247 return (int) f - (f - (int) f < -0.5f ? 1 : 0);
Davidroid 1:b78dab6d2c58 1248 }
Davidroid 1:b78dab6d2c58 1249
Davidroid 0:92706998571a 1250
Davidroid 0:92706998571a 1251 /*** Component's I/O Methods ***/
Davidroid 0:92706998571a 1252
Davidroid 0:92706998571a 1253 /**
Davidroid 0:92706998571a 1254 * @brief Utility function to read data from L6470.
Davidroid 0:92706998571a 1255 * @param[out] pBuffer pointer to the buffer to read data into.
Davidroid 0:92706998571a 1256 * @param[in] NumBytesToRead number of bytes to read.
Davidroid 0:92706998571a 1257 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
Davidroid 0:92706998571a 1258 */
Davidroid 0:92706998571a 1259 DrvStatusTypeDef Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
Davidroid 0:92706998571a 1260 {
Davidroid 0:92706998571a 1261 if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0)
Davidroid 0:92706998571a 1262 return COMPONENT_ERROR;
Davidroid 0:92706998571a 1263 return COMPONENT_OK;
Davidroid 0:92706998571a 1264 }
Davidroid 0:92706998571a 1265
Davidroid 0:92706998571a 1266 /**
Davidroid 0:92706998571a 1267 * @brief Utility function to write data to L6470.
Davidroid 0:92706998571a 1268 * @param[in] pBuffer pointer to the buffer of data to send.
Davidroid 0:92706998571a 1269 * @param[in] NumBytesToWrite number of bytes to write.
Davidroid 0:92706998571a 1270 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
Davidroid 0:92706998571a 1271 */
Davidroid 0:92706998571a 1272 DrvStatusTypeDef Write(uint8_t* pBuffer, uint16_t NumBytesToWrite)
Davidroid 0:92706998571a 1273 {
Davidroid 0:92706998571a 1274 if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0)
Davidroid 0:92706998571a 1275 return COMPONENT_ERROR;
Davidroid 0:92706998571a 1276 return COMPONENT_OK;
Davidroid 0:92706998571a 1277 }
Davidroid 0:92706998571a 1278
Davidroid 0:92706998571a 1279 /**
Davidroid 0:92706998571a 1280 * @brief Utility function to read and write data from/to L6470 at the same time.
Davidroid 0:92706998571a 1281 * @param[out] pBufferToRead pointer to the buffer to read data into.
Davidroid 0:92706998571a 1282 * @param[in] pBufferToWrite pointer to the buffer of data to send.
Davidroid 0:92706998571a 1283 * @param[in] NumBytes number of bytes to read and write.
Davidroid 0:92706998571a 1284 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
Davidroid 0:92706998571a 1285 */
Davidroid 0:92706998571a 1286 DrvStatusTypeDef ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
Davidroid 0:92706998571a 1287 {
Davidroid 0:92706998571a 1288 if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0)
Davidroid 0:92706998571a 1289 return COMPONENT_ERROR;
Davidroid 0:92706998571a 1290 return COMPONENT_OK;
Davidroid 0:92706998571a 1291 }
Davidroid 0:92706998571a 1292
Davidroid 0:92706998571a 1293 /* ACTION 8 --------------------------------------------------------------*
Davidroid 0:92706998571a 1294 * Implement here other I/O methods beyond those already implemented *
Davidroid 0:92706998571a 1295 * above, which are declared extern within the component's header file. *
Davidroid 0:92706998571a 1296 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1297 /*
Davidroid 0:92706998571a 1298 * Puts the device in standby mode.
Davidroid 0:92706998571a 1299 */
Davidroid 0:92706998571a 1300 void L6470_ENABLE(void)
Davidroid 0:92706998571a 1301 {
Davidroid 0:92706998571a 1302 /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
Davidroid 0:92706998571a 1303 standby_reset = 1;
Davidroid 0:92706998571a 1304 }
Davidroid 0:92706998571a 1305
Davidroid 0:92706998571a 1306 /*
Davidroid 0:92706998571a 1307 * Puts the device in reset mode.
Davidroid 0:92706998571a 1308 */
Davidroid 0:92706998571a 1309 void L6470_DISABLE(void)
Davidroid 0:92706998571a 1310 {
Davidroid 0:92706998571a 1311 /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
Davidroid 0:92706998571a 1312 standby_reset = 0;
Davidroid 0:92706998571a 1313 }
Davidroid 0:92706998571a 1314
Davidroid 0:92706998571a 1315 /*
Davidroid 0:92706998571a 1316 * Write and read bytes to/from the component through the SPI at the same time.
Davidroid 0:92706998571a 1317 */
Davidroid 0:92706998571a 1318 void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
Davidroid 0:92706998571a 1319 {
Davidroid 0:92706998571a 1320 /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
Davidroid 0:92706998571a 1321 ReadWrite(pRxData, pTxData, Size);
Davidroid 0:92706998571a 1322 }
Davidroid 0:92706998571a 1323
Davidroid 0:92706998571a 1324
Davidroid 0:92706998571a 1325 /*** Component's Instance Variables ***/
Davidroid 0:92706998571a 1326
Davidroid 0:92706998571a 1327 /* ACTION 9 --------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1328 * Declare here interrupt related variables, if needed. *
Davidroid 1:b78dab6d2c58 1329 * Note that interrupt handling is platform dependent, see *
Davidroid 1:b78dab6d2c58 1330 * "Interrupt Related Methods" above. *
Davidroid 1:b78dab6d2c58 1331 * *
Davidroid 1:b78dab6d2c58 1332 * Example: *
Davidroid 1:b78dab6d2c58 1333 * + mbed: *
Davidroid 1:b78dab6d2c58 1334 * InterruptIn feature_irq; *
Davidroid 0:92706998571a 1335 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1336 /* Flag Interrupt. */
Davidroid 0:92706998571a 1337 InterruptIn flag_irq;
Davidroid 0:92706998571a 1338
Davidroid 1:b78dab6d2c58 1339 /* Busy Interrupt. */
Davidroid 1:b78dab6d2c58 1340 InterruptIn busy_irq;
Davidroid 1:b78dab6d2c58 1341
Davidroid 1:b78dab6d2c58 1342 /* ACTION 10 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1343 * Declare here other pin related variables, if needed. *
Davidroid 1:b78dab6d2c58 1344 * *
Davidroid 1:b78dab6d2c58 1345 * Example: *
Davidroid 1:b78dab6d2c58 1346 * + mbed: *
Davidroid 1:b78dab6d2c58 1347 * DigitalOut standby_reset; *
Davidroid 1:b78dab6d2c58 1348 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1349 /* Standby/reset pin. */
Davidroid 0:92706998571a 1350 DigitalOut standby_reset;
Davidroid 0:92706998571a 1351
Davidroid 1:b78dab6d2c58 1352 /* ACTION 11 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1353 * Declare here communication related variables, if needed. *
Davidroid 1:b78dab6d2c58 1354 * *
Davidroid 1:b78dab6d2c58 1355 * Example: *
Davidroid 1:b78dab6d2c58 1356 * + mbed: *
Davidroid 1:b78dab6d2c58 1357 * DigitalOut ssel; *
Davidroid 1:b78dab6d2c58 1358 * DevSPI &dev_spi; *
Davidroid 1:b78dab6d2c58 1359 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1360 /* Configuration. */
Davidroid 0:92706998571a 1361 DigitalOut ssel;
Davidroid 0:92706998571a 1362
Davidroid 0:92706998571a 1363 /* IO Device. */
Davidroid 0:92706998571a 1364 DevSPI &dev_spi;
Davidroid 0:92706998571a 1365
Davidroid 1:b78dab6d2c58 1366 /* ACTION 12 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1367 * Declare here identity related variables, if needed. *
Davidroid 1:b78dab6d2c58 1368 * Note that there should be only a unique identifier for each component, *
Davidroid 1:b78dab6d2c58 1369 * which should be the "who_am_i" parameter. *
Davidroid 1:b78dab6d2c58 1370 *------------------------------------------------------------------------*/
Davidroid 1:b78dab6d2c58 1371 /* Identity */
Davidroid 1:b78dab6d2c58 1372 uint8_t who_am_i;
Davidroid 1:b78dab6d2c58 1373
Davidroid 1:b78dab6d2c58 1374 /* ACTION 13 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1375 * Declare here the component's static and non-static data, one variable *
Davidroid 1:b78dab6d2c58 1376 * per line. *
Davidroid 0:92706998571a 1377 * *
Davidroid 0:92706998571a 1378 * Example: *
Davidroid 1:b78dab6d2c58 1379 * float measure; *
Davidroid 1:b78dab6d2c58 1380 * int instance_id; *
Davidroid 1:b78dab6d2c58 1381 * static int number_of_instances; *
Davidroid 0:92706998571a 1382 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1383 /* Data. */
Davidroid 0:92706998571a 1384 uint8_t L6470_Id;
Davidroid 0:92706998571a 1385 const sL6470_Register_t *L6470_Register;
Davidroid 0:92706998571a 1386 const sL6470_ApplicationCommand_t *L6470_ApplicationCommand;
Davidroid 0:92706998571a 1387 const sL6470_Direction_t *L6470_Direction;
Davidroid 0:92706998571a 1388 const sL6470_ACT_t *L6470_ACT;
Davidroid 0:92706998571a 1389 sL6470_StatusRegister_t L6470_StatusRegister;
Davidroid 0:92706998571a 1390 sL6470_StatusRegister_t *pL6470_StatusRegister;
Davidroid 0:92706998571a 1391 StepperMotorRegister_t StepperMotorRegister;
Davidroid 1:b78dab6d2c58 1392 prepared_action_t prepared_action;
Davidroid 0:92706998571a 1393
Davidroid 0:92706998571a 1394 /* Static data. */
Davidroid 0:92706998571a 1395 static uint8_t number_of_devices;
Davidroid 0:92706998571a 1396 static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE];
Davidroid 0:92706998571a 1397 static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE];
Davidroid 0:92706998571a 1398 static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE];
Davidroid 0:92706998571a 1399 static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE];
Davidroid 0:92706998571a 1400 static eFlagStatus_t L6470_DaisyChain_HalfPrepared;
Davidroid 0:92706998571a 1401 static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 1402 static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 1403 static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 1404 };
Davidroid 0:92706998571a 1405
Davidroid 0:92706998571a 1406 #endif // __L6470_CLASS_H
Davidroid 0:92706998571a 1407
Davidroid 0:92706998571a 1408 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/