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:
Fri Jan 15 17:05:43 2016 +0000
Revision:
12:a942d51c488b
Parent:
11:1aca63b2f034
Child:
13:25a579b9b7c3
+ Typos corrected.

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