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:
Wed Nov 25 11:59:37 2015 +0000
Revision:
1:b78dab6d2c58
Parent:
0:92706998571a
Child:
2:3ed992ffeada
+ Implemented all the StepperMotor's APIs.

Who changed what in which revision?

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