Luca Istorico / X_NUCLEO_IHM02A1

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_IHM02A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers l6470_class.h Source File

l6470_class.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    l6470_class.h
00004  * @author  Davide Aliprandi, STMicroelectronics
00005  * @version V1.0.0
00006  * @date    November 12th, 2015
00007  * @brief   This file contains the class of an L6470 Motor Control component.
00008  ******************************************************************************
00009  *
00010  * COPYRIGHT(c) 2014 STMicroelectronics
00011  *
00012  * Redistribution and use in source and binary forms, with or without modification,
00013  * are permitted provided that the following conditions are met:
00014  *   1. Redistributions of source code must retain the above copyright notice,
00015  *      this list of conditions and the following disclaimer.
00016  *   2. Redistributions in binary form must reproduce the above copyright notice,
00017  *      this list of conditions and the following disclaimer in the documentation
00018  *      and/or other materials provided with the distribution.
00019  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00020  *      may be used to endorse or promote products derived from this software
00021  *      without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  ******************************************************************************
00035  */
00036 
00037 
00038 /* Generated with STM32CubeTOO -----------------------------------------------*/
00039 
00040 
00041 /* Revision ------------------------------------------------------------------*/
00042 /*
00043     Repository:       http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
00044     Branch/Trunk/Tag: trunk
00045     Based on:         X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.h
00046     Revision:         0
00047 */
00048 
00049 
00050 /* Define to prevent recursive inclusion -------------------------------------*/
00051 
00052 #ifndef __L6470_CLASS_H
00053 #define __L6470_CLASS_H
00054 
00055 
00056 /* Includes ------------------------------------------------------------------*/
00057 
00058 /* ACTION 1 ------------------------------------------------------------------*
00059  * Include here platform specific header files.                               *
00060  *----------------------------------------------------------------------------*/
00061 #include "mbed.h"
00062 #include "DevSPI.h"
00063 /* ACTION 2 ------------------------------------------------------------------*
00064  * Include here component specific header files.                              *
00065  *----------------------------------------------------------------------------*/
00066 #include "l6470.h"
00067 /* ACTION 3 ------------------------------------------------------------------*
00068  * Include here interface specific header files.                              *
00069  *                                                                            *
00070  * Example:                                                                   *
00071  *   #include "../Interfaces/Humidity_class.h"                                *
00072  *   #include "../Interfaces/Temperature_class.h"                             *
00073  *----------------------------------------------------------------------------*/
00074 #include "../Interfaces/StepperMotor_class.h"
00075 
00076 
00077 /* Classes -------------------------------------------------------------------*/
00078 
00079 /**
00080  * @brief Class representing a L6470 component.
00081  */
00082 class L6470 : public StepperMotor
00083 {
00084 public:
00085 
00086     /*** Public Component Related Types ***/
00087 
00088     /**
00089      * @brief Prepared Actions.
00090      */
00091     typedef enum
00092     {
00093         PREPARED_NO_ACTION = 0,
00094         PREPARED_GET_POSITION,
00095         PREPARED_GET_MARK,
00096         PREPARED_GET_SPEED,
00097         PREPARED_GET_MAX_SPEED,
00098         PREPARED_GET_MIN_SPEED,
00099         PREPARED_GET_ACCELERATION,
00100         PREPARED_GET_DECELERATION,
00101         PREPARED_GET_DIRECTION,
00102         PREPARED_SET_MARK
00103     } prepared_action_t;
00104 
00105 
00106     /*** Constructor and Destructor Methods ***/
00107 
00108     /**
00109      * @brief Constructor.
00110      * @param flag_irq      pin name of the FLAG pin of the component.
00111      * @param busy_irq      pin name of the BUSY pin of the component.
00112      * @param standby_reset pin name of the STBY\RST pin of the component.
00113      * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
00114      * @param spi           SPI device to be used for communication.
00115      */
00116     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)
00117     {
00118         /* ACTION 4 ----------------------------------------------------------*
00119          * Initialize here the component's member variables, one variable per *
00120          * line.                                                              *
00121          *                                                                    *
00122          * Example:                                                           *
00123          *   measure = 0;                                                     *
00124          *   instance_id = number_of_instances++;                             *
00125          *--------------------------------------------------------------------*/
00126         L6470_Register = &_L6470_Register[0];
00127         L6470_ApplicationCommand = &_L6470_ApplicationCommand[0];
00128         L6470_Direction = &_L6470_Direction[0];
00129         L6470_ACT = &_L6470_ACT[0];
00130         pL6470_StatusRegister = &L6470_StatusRegister;
00131         prepared_action = PREPARED_NO_ACTION;
00132         L6470_Id = (number_of_devices++)%(L6470DAISYCHAINSIZE);
00133         L6470_DaisyChain_HalfPrepared = ZERO_F;
00134         memset(L6470_AppCmdPkg, 0, L6470DAISYCHAINSIZE * sizeof(sL6470_AppCmdPkg_t));
00135         memset(L6470_DaisyChainSpiTxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
00136         memset(L6470_DaisyChainSpiRxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
00137     }
00138 
00139     /**
00140      * @brief Destructor.
00141      */
00142     virtual ~L6470(void) {}
00143 
00144 
00145     /*** Public Component Related Methods ***/
00146 
00147     /* ACTION 5 --------------------------------------------------------------*
00148      * Implement here the component's public methods, as wrappers of the C    *
00149      * component's functions.                                                 *
00150      * They should be:                                                        *
00151      *   + Methods with the same name of the C component's virtual table's    *
00152      *     functions (1);                                                     *
00153      *   + Methods with the same name of the C component's extended virtual   *
00154      *     table's functions, if any (2).                                     *
00155      *                                                                        *
00156      * Example:                                                               *
00157      *   virtual int GetValue(float *f)  //(1)                                *
00158      *   {                                                                    *
00159      *     return COMPONENT_GetValue(float *f);                               *
00160      *   }                                                                    *
00161      *                                                                        *
00162      *   virtual int EnableFeature(void) //(2)                                *
00163      *   {                                                                    *
00164      *     return COMPONENT_EnableFeature();                                  *
00165      *   }                                                                    *
00166      *------------------------------------------------------------------------*/
00167     /**
00168      * @brief  Initializing the component.
00169      * @param  init Pointer to device specific initalization structure.
00170      * @retval "0" in case of success, an error code otherwise.
00171      */
00172     virtual int Init(void *init)
00173     {
00174         return (int) L6470_Config((void *) init);
00175     }
00176 
00177     /**
00178      * @brief  Getting the ID of the component.
00179      * @param  id Pointer to an allocated variable to store the ID into.
00180      * @retval "0" in case of success, an error code otherwise.
00181      */
00182     virtual int ReadID(uint8_t *id)
00183     {
00184         return (int) 0;
00185     }
00186 
00187     /**
00188      * @brief  Getting the status.
00189      * @param  None.
00190      * @retval The status.
00191      */
00192     virtual unsigned int GetStatus(void)
00193     {
00194         return (unsigned int) L6470_GetStatus();
00195     }
00196 
00197     /**
00198      * @brief  Getting a parameter.
00199      * @param  parameter A parameter's register address.
00200      * @retval The parameter's value.
00201      * @note   The parameter can be one of the following:
00202      *           + L6470_ABS_POS_ID
00203      *           + L6470_EL_POS_ID
00204      *           + L6470_MARK_ID
00205      *           + L6470_SPEED_ID
00206      *           + L6470_ACC_ID
00207      *           + L6470_DEC_ID
00208      *           + L6470_MAX_SPEED_ID
00209      *           + L6470_MIN_SPEED_ID
00210      *           + L6470_FS_SPD_ID
00211      *           + L6470_KVAL_HOLD_ID
00212      *           + L6470_KVAL_RUN_ID
00213      *           + L6470_KVAL_ACC_ID
00214      *           + L6470_KVAL_DEC_ID
00215      *           + L6470_INT_SPEED_ID
00216      *           + L6470_ST_SLP_ID
00217      *           + L6470_FN_SLP_ACC_ID
00218      *           + L6470_FN_SLP_DEC_ID
00219      *           + L6470_K_THERM_ID
00220      *           + L6470_ADC_OUT_ID
00221      *           + L6470_OCD_TH_ID
00222      *           + L6470_STALL_TH_ID
00223      *           + L6470_STEP_MODE_ID
00224      *           + L6470_ALARM_EN_ID
00225      *           + L6470_CONFIG_ID
00226      *           + L6470_STATUS_ID
00227      */
00228     virtual unsigned int GetParameter(unsigned int parameter)
00229     {
00230         return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter);
00231     }
00232 
00233     /**
00234      * @brief  Getting the position.
00235      * @param  None.
00236      * @retval The position.
00237      */
00238     virtual signed int GetPosition(void)
00239     {
00240         return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
00241     }
00242 
00243     /**
00244      * @brief  Getting the marked position.
00245      * @param  None.
00246      * @retval The marked position.
00247      */
00248     virtual signed int GetMark(void)
00249     {
00250         return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID));
00251     }
00252 
00253     /**
00254      * @brief  Getting the current speed in pps.
00255      * @param  None.
00256      * @retval The current speed in pps.
00257      */
00258     virtual unsigned int GetSpeed(void)
00259     {
00260         return round(L6470_Speed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID)));
00261     }
00262 
00263     /**
00264      * @brief  Getting the maximum speed in pps.
00265      * @param  None.
00266      * @retval The maximum speed in pps.
00267      */
00268     virtual unsigned int GetMaxSpeed(void)
00269     {
00270         return round(L6470_MaxSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID)));
00271     }
00272 
00273     /**
00274      * @brief  Getting the minimum speed in pps.
00275      * @param  None.
00276      * @retval The minimum speed in pps.
00277      */
00278     virtual unsigned int GetMinSpeed(void)
00279     {
00280         return round(L6470_MinSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID)));
00281     }
00282 
00283     /**
00284      * @brief  Getting the acceleration in pps^2.
00285      * @param  None.
00286      * @retval The acceleration in pps^2.
00287      */
00288     virtual unsigned int GetAcceleration(void)
00289     {
00290         return round(L6470_Acc_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID)));
00291     }
00292 
00293     /**
00294      * @brief  Getting the deceleration in pps^2.
00295      * @param  None.
00296      * @retval The deceleration in pps^2.
00297      */
00298     virtual unsigned int GetDeceleration(void)
00299     {
00300         return round(L6470_Dec_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID)));
00301     }
00302 
00303     /**
00304      * @brief  Getting the direction of rotation.
00305      * @param  None.
00306      * @retval The direction of rotation.
00307      */
00308     virtual direction_t GetDirection(void)
00309     {
00310         return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
00311     }
00312 
00313     /**
00314      * @brief   Setting a parameter.
00315      * @param   parameter A parameter's register address.
00316      * @param   value The parameter's value.
00317      * @retval  None.
00318      * @note    The parameter can be one of the following:
00319      *           + L6470_ABS_POS_ID
00320      *           + L6470_EL_POS_ID
00321      *           + L6470_MARK_ID
00322      *           + L6470_SPEED_ID
00323      *           + L6470_ACC_ID
00324      *           + L6470_DEC_ID
00325      *           + L6470_MAX_SPEED_ID
00326      *           + L6470_MIN_SPEED_ID
00327      *           + L6470_FS_SPD_ID
00328      *           + L6470_KVAL_HOLD_ID
00329      *           + L6470_KVAL_RUN_ID
00330      *           + L6470_KVAL_ACC_ID
00331      *           + L6470_KVAL_DEC_ID
00332      *           + L6470_INT_SPEED_ID
00333      *           + L6470_ST_SLP_ID
00334      *           + L6470_FN_SLP_ACC_ID
00335      *           + L6470_FN_SLP_DEC_ID
00336      *           + L6470_K_THERM_ID
00337      *           + L6470_ADC_OUT_ID
00338      *           + L6470_OCD_TH_ID
00339      *           + L6470_STALL_TH_ID
00340      *           + L6470_STEP_MODE_ID
00341      *           + L6470_ALARM_EN_ID
00342      *           + L6470_CONFIG_ID
00343      *           + L6470_STATUS_ID
00344      * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
00345      *          Any attempt to write one of those registers when the conditions are not satisfied
00346      *          causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
00347      *          last argument byte. Any attempt to set an inexistent register (wrong address value)
00348      *          causes the command to be ignored and the WRONG_CMD flag to rise.
00349      *          For example, setting some parameters requires first to disable the power bridge;
00350      *          this can be done through the SoftHiZ() method.
00351      *          They are the following:
00352      *           + L6470_ABS_POS_ID
00353      *           + L6470_EL_POS_ID
00354      *           + L6470_SPEED_ID
00355      *           + L6470_ACC_ID
00356      *           + L6470_DEC_ID
00357      *           + L6470_MAX_SPEED_ID
00358      *           + L6470_MIN_SPEED_ID
00359      *           + L6470_INT_SPEED_ID
00360      *           + L6470_ST_SLP_ID
00361      *           + L6470_FN_SLP_ACC_ID
00362      *           + L6470_FN_SLP_DEC_ID
00363      *           + L6470_ADC_OUT_ID
00364      *           + L6470_STEP_MODE_ID
00365      *           + L6470_CONFIG_ID
00366      *           + L6470_STATUS_ID
00367      */
00368     virtual void SetParameter(unsigned int parameter, unsigned int value)
00369     {
00370         L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value);
00371     }
00372 
00373     /**
00374      * @brief  Setting the current position to be the home position.
00375      * @param  None.
00376      * @retval None.
00377      */
00378     virtual void SetHome(void)
00379     {
00380         L6470_ResetPos();
00381     }
00382 
00383     /**
00384      * @brief  Setting the current position to be the marked position.
00385      * @param  None.
00386      * @retval None.
00387      */
00388     virtual void SetMark(void)
00389     {
00390         L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
00391     }
00392 
00393     /**
00394      * @brief  Setting the current position to be the marked position.
00395      * @param  position The given position.
00396      * @retval None.
00397      */
00398     virtual void SetMark(signed int position)
00399     {
00400         L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
00401     }
00402 
00403     /**
00404      * @brief  Setting the maximum speed in pps.
00405      * @param  speed The maximum speed in pps.
00406      * @retval "true" in case of success, "false" otherwise.
00407      */
00408     virtual bool SetMaxSpeed(unsigned int speed)
00409     {
00410         L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
00411         return true;
00412     }
00413 
00414     /**
00415      * @brief  Setting the minimum speed in pps.
00416      * @param  speed The minimum speed in pps.
00417      * @retval "true" in case of success, "false" otherwise.
00418      */
00419     virtual bool SetMinSpeed(unsigned int speed)
00420     {
00421         L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
00422         return true;
00423     }
00424 
00425     /**
00426      * @brief  Setting the acceleration in pps^2.
00427      * @param  acceleration The acceleration in pps^2.
00428      * @retval "true" in case of success, "false" otherwise.
00429      */
00430     virtual bool SetAcceleration(unsigned int acceleration)
00431     {
00432         L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
00433         return true;
00434     }
00435 
00436     /**
00437      * @brief  Setting the deceleration in pps^2.
00438      * @param  deceleration The deceleration in pps^2.
00439      * @retval "true" in case of success, "false" otherwise.
00440      */
00441     virtual bool SetDeceleration(unsigned int deceleration)
00442     {
00443         L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
00444         return true;
00445     }
00446 
00447     /**
00448      * @brief   Setting the Step Mode.
00449      * @param   step_mode The Step Mode.
00450      * @retval "true" in case of success, "false" otherwise.
00451      * @warning Setting the step mode implies first disabling the power bridge through
00452      *          the SoftHiZ() method.
00453      * @warning Every time step mode is changed, the values of the home
00454      *          and mark positions lose meaning and are reset.
00455      */
00456     virtual bool SetStepMode(step_mode_t step_mode)
00457     {
00458         if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128)
00459             return false;
00460 
00461         SoftHiZ();
00462         L6470_SetParam((eL6470_RegId_t) L6470_STEP_MODE_ID, (eMotorStepMode_t) step_mode);
00463         return true;
00464     }
00465 
00466     /**
00467      * @brief  Going to a specified position through the shortest path.
00468      * @param  position The desired position.
00469      * @retval None.
00470      */
00471     virtual void GoTo(signed int position)
00472     {
00473         L6470_GoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
00474     }
00475 
00476     /**
00477      * @brief  Going to a specified position imposing the desired direction.
00478      * @param  position The desired position.
00479      * @param  direction The direction of rotation.
00480      * @retval None.
00481      */
00482     virtual void GoTo(signed int position, direction_t direction)
00483     {
00484         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));
00485     }
00486 
00487     /**
00488      * @brief  Going to the home position.
00489      * @param  None.
00490      * @retval None.
00491      */
00492     virtual void GoHome(void)
00493     {
00494         L6470_GoHome();
00495     }
00496 
00497     /**
00498      * @brief  Going to the marked position.
00499      * @param  None.
00500      * @retval None.
00501      */
00502     virtual void GoMark(void)
00503     {
00504         L6470_GoMark();
00505     }
00506 
00507     /**
00508      * @brief  Running at the given speed imposing the desired direction until
00509      *         an external switch turn-on event occurs.
00510      * @param  action The identifier of the action about the absolute position.
00511      * @param  position The desired position.
00512      * @param  speed The speed value in pps.
00513      * @retval None.
00514      * @note   The identifier of the action about the absolute position can be
00515      *         one of the following:
00516      *           + L6470_ACT_RST_ID: the absolute position is reset;
00517      *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
00518      */
00519     virtual void GoUntil(eL6470_ActId_t action, direction_t direction, unsigned int speed)
00520     {
00521         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));
00522     }
00523 
00524     /**
00525      * @brief  Running towards a specified direction.
00526      * @param  direction The direction of rotation.
00527      * @retval None.
00528      */
00529     virtual void Run(direction_t direction)
00530     {
00531         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));
00532     }
00533 
00534     /**
00535      * @brief  Running towards a specified direction at the given speed.
00536      * @param  direction The direction of rotation.
00537      * @param  speed The speed value in pps.
00538      * @retval None.
00539      */
00540     virtual void Run(direction_t direction, unsigned int speed)
00541     {
00542         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));
00543     }
00544 
00545     /**
00546      * @brief  Moving towards a specified direction for a certain number of steps.
00547      * @param  direction The direction of rotation.
00548      * @param  steps The desired number of steps.
00549      * @retval None.
00550      */
00551     virtual void Move(direction_t direction, unsigned int steps)
00552     {
00553         L6470_Move((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
00554     }
00555 
00556     /**
00557      * @brief  Stopping the motor through an immediate deceleration up to zero speed.
00558      *         The used deceleration value is the one stored in the "DEC" register.
00559      * @param  None.
00560      * @retval None.
00561      */
00562     virtual void SoftStop(void)
00563     {
00564         L6470_SoftStop();
00565     }
00566 
00567     /**
00568      * @brief  Stopping the motor through an immediate infinite deceleration.
00569      * @param  None.
00570      * @retval None.
00571      */
00572     virtual void HardStop(void)
00573     {
00574         L6470_HardStop();
00575     }
00576 
00577     /**
00578      * @brief  Disabling the power bridge after performing a deceleration to zero.
00579      *         The used deceleration value is the one stored in the "DEC" register.
00580      * @param  None.
00581      * @retval None.
00582      */
00583     virtual void SoftHiZ(void)
00584     {
00585         L6470_SoftHiZ();
00586     }
00587 
00588     /**
00589      * @brief  Disabling the power bridge immediately.
00590      * @param  None.
00591      * @retval None.
00592      */
00593     virtual void HardHiZ(void)
00594     {
00595         L6470_HardHiZ();
00596     }
00597 
00598     /**
00599      * @brief  Waiting while the motor is active.
00600      * @param  None.
00601      * @retval None.
00602      */
00603     virtual void WaitWhileActive(void)
00604     {
00605         while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0);
00606     }
00607 
00608     /**
00609      * @brief   Switching to step-clock mode.
00610      * @param   direction The direction of rotation.
00611      * @retval  None.
00612      * @warning Setting the step-clock mode implies first disabling the power bridge through
00613      *          the SoftHiZ() method.
00614      */
00615     virtual void StepClock(direction_t direction)
00616     {
00617         SoftHiZ();
00618         L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
00619     }
00620 
00621     /**
00622       * @brief  Doing a motion at minimum speed imposing a specified direction
00623       *         until the SW is released.
00624       * @param  action The identifier of the action about the absolute position.
00625       * @param  direction The direction of rotation.
00626       * @note   The identifier of the action about the absolute position can be
00627       *         one of the following:
00628       *           + L6470_ACT_RST_ID: the absolute position is reset;
00629       *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
00630       */
00631     virtual void ReleaseSW(eL6470_ActId_t action, direction_t direction)
00632     {
00633         L6470_ReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
00634     }
00635 
00636     /**
00637       * @brief  Resetting the device to power-up conditions.
00638       * @param  None.
00639       * @retval None.
00640       */
00641     virtual void ResetDevice(void)
00642     {
00643         L6470_ResetDevice();
00644     }
00645 
00646     /**
00647      * @brief  Preparing the command to get the status.
00648      * @param  None.
00649      * @retval None.
00650      * @note   The command will be sent by issuing "PerformAction()".
00651      */
00652     virtual void PrepareGetStatus(void)
00653     {
00654         L6470_PrepareGetStatus();
00655         prepared_action = PREPARED_NO_ACTION;
00656     }
00657 
00658     /**
00659      * @brief  Preparing the command to get a parameter.
00660      * @param  parameter A parameter's register address.
00661      * @retval None.
00662      * @note   The command will be sent by issuing "PerformAction()".
00663      *         The parameter can be one of the following:
00664      *           + L6470_ABS_POS_ID
00665      *           + L6470_EL_POS_ID
00666      *           + L6470_MARK_ID
00667      *           + L6470_SPEED_ID
00668      *           + L6470_ACC_ID
00669      *           + L6470_DEC_ID
00670      *           + L6470_MAX_SPEED_ID
00671      *           + L6470_MIN_SPEED_ID
00672      *           + L6470_FS_SPD_ID
00673      *           + L6470_KVAL_HOLD_ID
00674      *           + L6470_KVAL_RUN_ID
00675      *           + L6470_KVAL_ACC_ID
00676      *           + L6470_KVAL_DEC_ID
00677      *           + L6470_INT_SPEED_ID
00678      *           + L6470_ST_SLP_ID
00679      *           + L6470_FN_SLP_ACC_ID
00680      *           + L6470_FN_SLP_DEC_ID
00681      *           + L6470_K_THERM_ID
00682      *           + L6470_ADC_OUT_ID
00683      *           + L6470_OCD_TH_ID
00684      *           + L6470_STALL_TH_ID
00685      *           + L6470_STEP_MODE_ID
00686      *           + L6470_ALARM_EN_ID
00687      *           + L6470_CONFIG_ID
00688      *           + L6470_STATUS_ID
00689      */
00690     virtual void PrepareGetParameter(unsigned int parameter)
00691     {
00692         L6470_PrepareGetParam((eL6470_RegId_t) parameter);
00693         prepared_action = PREPARED_NO_ACTION;
00694     }
00695 
00696     /**
00697      * @brief  Preparing the command to get the position.
00698      * @param  None.
00699      * @retval None.
00700      * @note   The command will be sent by issuing "PerformAction()".
00701      */
00702     virtual void PrepareGetPosition(void)
00703     {
00704         L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID);
00705         prepared_action = PREPARED_GET_POSITION;
00706     }
00707 
00708     /**
00709      * @brief  Preparing the command to get the marked position.
00710      * @param  None.
00711      * @retval None.
00712      * @note   The command will be sent by issuing "PerformAction()".
00713      */
00714     virtual void PrepareGetMark(void)
00715     {
00716         L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID);
00717         prepared_action = PREPARED_GET_MARK;
00718     }
00719 
00720     /**
00721      * @brief  Preparing the command to get the current speed in pps.
00722      * @param  None.
00723      * @retval None.
00724      * @note   The command will be sent by issuing "PerformAction()".
00725      */
00726     virtual void PrepareGetSpeed(void)
00727     {
00728         L6470_PrepareGetParam((eL6470_RegId_t) L6470_SPEED_ID);
00729         prepared_action = PREPARED_GET_SPEED;
00730     }
00731 
00732     /**
00733      * @brief  Preparing the command to get the maximum speed in pps.
00734      * @param  None.
00735      * @retval None.
00736      * @note   The command will be sent by issuing "PerformAction()".
00737      */
00738     virtual void PrepareGetMaxSpeed(void)
00739     {
00740         L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID);
00741         prepared_action = PREPARED_GET_MAX_SPEED;
00742     }
00743 
00744     /**
00745      * @brief  Preparing the command to get the minimum speed in pps.
00746      * @param  None.
00747      * @retval None.
00748      * @note   The command will be sent by issuing "PerformAction()".
00749      */
00750     virtual void PrepareGetMinSpeed(void)
00751     {
00752         L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID);
00753         prepared_action = PREPARED_GET_MIN_SPEED;
00754     }
00755 
00756     /**
00757      * @brief  Preparing the command to get the acceleration in pps^2.
00758      * @param  None.
00759      * @retval None.
00760      * @note   The command will be sent by issuing "PerformAction()".
00761      */
00762     virtual void PrepareGetAcceleration(void)
00763     {
00764         L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID);
00765         prepared_action = PREPARED_GET_ACCELERATION;
00766     }
00767 
00768     /**
00769      * @brief  Preparing the command to get the deceleration in pps^2.
00770      * @param  None.
00771      * @retval None.
00772      * @note   The command will be sent by issuing "PerformAction()".
00773      */
00774     virtual void PrepareGetDeceleration(void)
00775     {
00776         L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID);
00777         prepared_action = PREPARED_GET_DECELERATION;
00778     }
00779 
00780     /**
00781      * @brief  Preparing the command to get the direction of rotation.
00782      * @param  None.
00783      * @retval None.
00784      * @note   The command will be sent by issuing "PerformAction()".
00785      */
00786     virtual void PrepareGetDirection(void)
00787     {
00788         if (!L6470_DaisyChain_HalfPrepared)
00789         {
00790             /* To avoid deleting the previous entered command. */
00791             L6470_DaisyChain_HalfPrepared = ONE_F;
00792             /* Resetting commands. */
00793             L6470_ResetAppCmdPkg(L6470_AppCmdPkg);
00794         }
00795         prepared_action = PREPARED_GET_DIRECTION;
00796     }
00797 
00798     /**
00799      * @brief  Preparing the command to set a parameter.
00800      * @param  parameter A parameter's register address.
00801      * @param  value The parameter's value.
00802      * @retval None.
00803      * @note   The command will be sent by issuing "PerformAction()".
00804      *         The parameter can be one of the following:
00805      *           + L6470_ABS_POS_ID
00806      *           + L6470_EL_POS_ID
00807      *           + L6470_MARK_ID
00808      *           + L6470_SPEED_ID
00809      *           + L6470_ACC_ID
00810      *           + L6470_DEC_ID
00811      *           + L6470_MAX_SPEED_ID
00812      *           + L6470_MIN_SPEED_ID
00813      *           + L6470_FS_SPD_ID
00814      *           + L6470_KVAL_HOLD_ID
00815      *           + L6470_KVAL_RUN_ID
00816      *           + L6470_KVAL_ACC_ID
00817      *           + L6470_KVAL_DEC_ID
00818      *           + L6470_INT_SPEED_ID
00819      *           + L6470_ST_SLP_ID
00820      *           + L6470_FN_SLP_ACC_ID
00821      *           + L6470_FN_SLP_DEC_ID
00822      *           + L6470_K_THERM_ID
00823      *           + L6470_ADC_OUT_ID
00824      *           + L6470_OCD_TH_ID
00825      *           + L6470_STALL_TH_ID
00826      *           + L6470_STEP_MODE_ID
00827      *           + L6470_ALARM_EN_ID
00828      *           + L6470_CONFIG_ID
00829      *           + L6470_STATUS_ID
00830      * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
00831      *          Any attempt to write one of those registers when the conditions are not satisfied
00832      *          causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
00833      *          last argument byte. Any attempt to set an inexistent register (wrong address value)
00834      *          causes the command to be ignored and the WRONG_CMD flag to rise.
00835      *          For example, setting some parameters requires first to disable the power bridge;
00836      *          this can be done through the SoftHiZ() method.
00837      *          They are the following:
00838      *           + L6470_ABS_POS_ID
00839      *           + L6470_EL_POS_ID
00840      *           + L6470_SPEED_ID
00841      *           + L6470_ACC_ID
00842      *           + L6470_DEC_ID
00843      *           + L6470_MAX_SPEED_ID
00844      *           + L6470_MIN_SPEED_ID
00845      *           + L6470_INT_SPEED_ID
00846      *           + L6470_ST_SLP_ID
00847      *           + L6470_FN_SLP_ACC_ID
00848      *           + L6470_FN_SLP_DEC_ID
00849      *           + L6470_ADC_OUT_ID
00850      *           + L6470_STEP_MODE_ID
00851      *           + L6470_CONFIG_ID
00852      *           + L6470_STATUS_ID
00853      */
00854     virtual void PrepareSetParameter(unsigned int parameter, unsigned int value)
00855     {
00856         L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value);
00857         prepared_action = PREPARED_NO_ACTION;
00858     }
00859 
00860     /**
00861      * @brief  Preparing the command to set the current position to be
00862      *         the home position.
00863      * @param  None.
00864      * @retval None.
00865      * @note   The command will be sent by issuing "PerformAction()".
00866      */
00867     virtual void PrepareSetHome(void)
00868     {
00869         L6470_PrepareResetPos();
00870         prepared_action = PREPARED_NO_ACTION;
00871     }
00872 
00873     /**
00874      * @brief  Preparing the command to set the current position to be
00875      *         the marked position.
00876      * @param  None.
00877      * @retval None.
00878      * @note   The command will be sent by issuing "PerformAction()".
00879      */
00880     virtual void PrepareSetMark(void)
00881     {
00882         /*
00883            Set "0" now as marked position. This value will be replaced by the
00884            actual position read at the time when the prepared actions will be
00885            performed.
00886         */
00887         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0);
00888         prepared_action = PREPARED_SET_MARK;
00889     }
00890 
00891     /**
00892      * @brief  Preparing the command to set the given position to be
00893      *         the marked position.
00894      * @param  position The given position.
00895      * @retval None.
00896      * @note   The command will be sent by issuing "PerformAction()".
00897      */
00898     virtual void PrepareSetMark(signed int position)
00899     {
00900         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
00901         prepared_action = PREPARED_NO_ACTION;
00902     }
00903 
00904     /**
00905      * @brief  Preparing the command to set the current speed in pps.
00906      * @param  speed The current speed in pps.
00907      * @retval None.
00908      * @note   The command will be sent by issuing "PerformAction()".
00909      */
00910     virtual void PrepareSetSpeed(unsigned int speed)
00911     {
00912         L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed));
00913         prepared_action = PREPARED_NO_ACTION;
00914     }
00915 
00916     /**
00917      * @brief  Preparing the command to set the maximum speed in pps.
00918      * @param  speed The maximum speed in pps.
00919      * @retval None.
00920      * @note   The command will be sent by issuing "PerformAction()".
00921      */
00922     virtual void PrepareSetMaxSpeed(unsigned int speed)
00923     {
00924         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
00925         prepared_action = PREPARED_NO_ACTION;
00926     }
00927 
00928     /**
00929      * @brief  Preparing the command to set the minimum speed in pps.
00930      * @param  speed The minimum speed in pps.
00931      * @retval None.
00932      * @note   The command will be sent by issuing "PerformAction()".
00933      */
00934     virtual void PrepareSetMinSpeed(unsigned int speed)
00935     {
00936         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
00937         prepared_action = PREPARED_NO_ACTION;
00938     }
00939 
00940     /**
00941      * @brief  Preparing the command to set the acceleration in pps^2.
00942      * @param  acceleration The acceleration in pps^2.
00943      * @retval None.
00944      * @note   The command will be sent by issuing "PerformAction()".
00945      */
00946     virtual void PrepareSetAcceleration(unsigned int acceleration)
00947     {
00948         L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
00949         prepared_action = PREPARED_NO_ACTION;
00950     }
00951 
00952     /**
00953      * @brief  Preparing the command to set the deceleration in pps^2.
00954      * @param  deceleration The deceleration in pps^2.
00955      * @retval None.
00956      * @note   The command will be sent by issuing "PerformAction()".
00957      */
00958     virtual void PrepareSetDeceleration(unsigned int deceleration)
00959     {
00960         L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
00961         prepared_action = PREPARED_NO_ACTION;
00962     }
00963 
00964     /**
00965      * @brief  Preparing the command to go to a specified position.
00966      * @param  position The desired position.
00967      * @retval None.
00968      * @note   The command will be sent by issuing "PerformAction()".
00969      */
00970     virtual void PrepareGoTo(signed int position)
00971     {
00972         L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
00973         prepared_action = PREPARED_NO_ACTION;
00974     }
00975 
00976     /**
00977      * @brief  Preparing the command to go to a specified position
00978      *         imposing the desired direction.
00979      * @param  position The desired position.
00980      * @param  direction The direction of rotation.
00981      * @retval None.
00982      * @note   The command will be sent by issuing "PerformAction()".
00983      */
00984     virtual void PrepareGoTo(signed int position, direction_t direction)
00985     {
00986         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));
00987         prepared_action = PREPARED_NO_ACTION;
00988     }
00989 
00990     /**
00991      * @brief  Preparing the command to go to the home position.
00992      * @param  None.
00993      * @retval None.
00994      * @note   The command will be sent by issuing "PerformAction()".
00995      */
00996     virtual void PrepareGoHome(void)
00997     {
00998         L6470_PrepareGoHome();
00999         prepared_action = PREPARED_NO_ACTION;
01000     }
01001 
01002     /**
01003      * @brief  Preparing the command to go to the marked position.
01004      * @param  None.
01005      * @retval None.
01006      * @note   The command will be sent by issuing "PerformAction()".
01007      */
01008     virtual void PrepareGoMark(void)
01009     {
01010         L6470_PrepareGoMark();
01011         prepared_action = PREPARED_NO_ACTION;
01012     }
01013 
01014     /**
01015      * @brief  Preparing the command to run at the given speed imposing the desired
01016      *         direction until an external switch turn-on event occurs.
01017      * @param  action The identifier of the action about the absolute position.
01018      * @param  position The desired position.
01019      * @param  speed The speed value in pps.
01020      * @retval None.
01021      * @note   The command will be sent by issuing "PerformAction()".
01022      *         The identifier of the action about the absolute position can be
01023      *         one of the following:
01024      *           + L6470_ACT_RST_ID: the absolute position is reset;
01025      *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
01026      */
01027     virtual void PrepareGoUntil(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed)
01028     {
01029         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));
01030         prepared_action = PREPARED_NO_ACTION;
01031     }
01032 
01033     /**
01034      * @brief  Preparing the command to run towards a specified direction
01035      *         at the maximum speed.
01036      * @param  direction The direction of rotation.
01037      * @retval None.
01038      * @note   The command will be sent by issuing "PerformAction()".
01039      */
01040     virtual void PrepareRun(direction_t direction)
01041     {
01042         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));
01043         prepared_action = PREPARED_NO_ACTION;
01044     }
01045 
01046     /**
01047      * @brief  Preparing the command to run towards a specified direction
01048      *         at the given speed.
01049      * @param  direction The direction of rotation.
01050      * @param  speed The speed value in pps.
01051      * @retval None.
01052      * @note   The command will be sent by issuing "PerformAction()".
01053      */
01054     virtual void PrepareRun(direction_t direction, unsigned int speed)
01055     {
01056         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));
01057         prepared_action = PREPARED_NO_ACTION;
01058     }
01059 
01060     /**
01061      * @brief  Preparing the command to move towards a specified direction
01062      *         for a certain number of steps.
01063      * @param  direction The direction of rotation.
01064      * @param  steps The desired number of steps.
01065      * @retval None.
01066      * @note   The command will be sent by issuing "PerformAction()".
01067      */
01068     virtual void PrepareMove(direction_t direction, unsigned int steps)
01069     {
01070         L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
01071         prepared_action = PREPARED_NO_ACTION;
01072     }
01073 
01074     /**
01075      * @brief  Preparing the command to stop the motor.
01076      * @param  None.
01077      * @retval None.
01078      * @note   The command will be sent by issuing "PerformAction()".
01079      */
01080     virtual void PrepareSoftStop(void)
01081     {
01082         L6470_PrepareSoftStop();
01083         prepared_action = PREPARED_NO_ACTION;
01084     }
01085 
01086     /**
01087      * @brief  Preparing the command to stop the motor and disabling the power bridge.
01088      * @param  None.
01089      * @retval None.
01090      * @note   The command will be sent by issuing "PerformAction()".
01091      */
01092     virtual void PrepareHardStop(void)
01093     {
01094         L6470_PrepareHardStop();
01095         prepared_action = PREPARED_NO_ACTION;
01096     }
01097 
01098     /**
01099      * @brief  Preparing the command to disable the power bridge after performing
01100      *         a deceleration to zero.
01101      *         The used deceleration value is the one stored in the "DEC" register.
01102      * @param  None.
01103      * @retval None.
01104      * @note   The command will be sent by issuing "PerformAction()".
01105      */
01106     virtual void PrepareSoftHiZ(void)
01107     {
01108         L6470_PrepareSoftHiZ();
01109         prepared_action = PREPARED_NO_ACTION;
01110     }
01111 
01112     /**
01113      * @brief  Preparing the command to disable the power bridge immediately.
01114      * @param  None.
01115      * @retval None.
01116      * @note   The command will be sent by issuing "PerformAction()".
01117      */
01118     virtual void PrepareHardHiZ(void)
01119     {
01120         L6470_PrepareHardHiZ();
01121         prepared_action = PREPARED_NO_ACTION;
01122     }
01123 
01124     /**
01125      * @brief   Preparing the command to switch to step-clock mode.
01126      * @param   direction The direction of rotation.
01127      * @retval  None.
01128      * @warning Setting the step-clock mode requires an explicit action by the user to first
01129      *          disable the power bridge through the SoftHiZ() method.
01130      * @note    The command will be sent by issuing "PerformAction()".
01131      */
01132     virtual void PrepareStepClock(direction_t direction)
01133     {
01134         L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
01135         prepared_action = PREPARED_NO_ACTION;
01136     }
01137 
01138     /**
01139       * @brief  Preparing the command to do a motion at minimum speed
01140       *         imposing a specified direction until the SW is released.
01141       * @param  action The identifier of the action about the absolute position.
01142       * @param  direction The direction of rotation.
01143       * @retval None.
01144       * @note   The command will be sent by issuing "PerformAction()".
01145       *         The identifier of the action about the absolute position can be
01146       *         one of the following:
01147       *           + L6470_ACT_RST_ID: the absolute position is reset;
01148       *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
01149       */
01150     virtual void PrepareReleaseSW(eL6470_ActId_t action, direction_t direction)
01151     {
01152         L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
01153         prepared_action = PREPARED_NO_ACTION;
01154     }
01155 
01156     /**
01157       * @brief  Preparing the command to reset the device to power-up conditions.
01158       * @param  None.
01159       * @retval None.
01160       * @note   The command will be sent by issuing "PerformAction()".
01161       */
01162     virtual void PrepareResetDevice(void)
01163     {
01164         L6470_PrepareResetDevice();
01165         prepared_action = PREPARED_NO_ACTION;
01166     }
01167 
01168     /**
01169       * @brief    Performing all the actions prepared on the components
01170       *           of the daisy-chain.
01171       * @param    None.
01172       * @retval   The raw data returned by the components.
01173       */
01174     uint8_t* PerformPreparedActions(void)
01175     {
01176         return L6470_PerformPreparedApplicationCommand();
01177     }
01178 
01179     /**
01180       * @brief    Getting the prepared action.
01181       * @param    None
01182       * @retval   The prepared action.
01183       */
01184     prepared_action_t GetPreparedAction(void)
01185     {
01186         return prepared_action;
01187     }
01188 
01189     /**
01190       * @brief    Converting the raw data received by the component according to
01191       *           the action performed on it.
01192       * @param    raw_data The received raw data.
01193       * @retval   The result of the action performed.
01194       */
01195     int32_t GetResult(uint8_t *raw_data)
01196     {
01197         switch (prepared_action)
01198         {
01199             case PREPARED_GET_POSITION:
01200                 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte));
01201 
01202             case PREPARED_GET_MARK:
01203                 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte));
01204 
01205             case PREPARED_GET_SPEED:
01206                 return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte)));
01207     
01208             case PREPARED_GET_MAX_SPEED:
01209                 return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte)));
01210     
01211             case PREPARED_GET_MIN_SPEED:
01212                 return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte)));
01213     
01214             case PREPARED_GET_ACCELERATION:
01215                 return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte)));
01216     
01217             case PREPARED_GET_DECELERATION:
01218                 return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte)));
01219 
01220             case PREPARED_GET_DIRECTION:
01221                 return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
01222 
01223             default:
01224             case PREPARED_NO_ACTION:
01225                 return 0;
01226         }
01227     }
01228 
01229 
01230     /*** Public Interrupt Related Methods ***/
01231 
01232     /* ACTION 6 --------------------------------------------------------------*
01233      * Implement here interrupt related methods, if any.                      *
01234      * Note that interrupt handling is platform dependent, e.g.:              *
01235      *   + mbed:                                                              *
01236      *     InterruptIn feature_irq(pin);           //Interrupt object.        *
01237      *     feature_irq.fall(callback);             //Attach a callback.       *
01238      *     feature_irq.mode(PullNone);             //Set interrupt mode.      *
01239      *     feature_irq.enable_irq();               //Enable interrupt.        *
01240      *     feature_irq.disable_irq();              //Disable interrupt.       *
01241      *   + Arduino:                                                           *
01242      *     attachInterrupt(pin, callback, RISING); //Attach a callback.       *
01243      *     detachInterrupt(pin);                   //Detach a callback.       *
01244      *                                                                        *
01245      * Example (mbed):                                                        *
01246      *   void AttachFeatureIRQ(void (*fptr) (void))                           *
01247      *   {                                                                    *
01248      *     feature_irq.fall(fptr);                                            *
01249      *   }                                                                    *
01250      *                                                                        *
01251      *   void EnableFeatureIRQ(void)                                          *
01252      *   {                                                                    *
01253      *     feature_irq.enable_irq();                                          *
01254      *   }                                                                    *
01255      *                                                                        *
01256      *   void DisableFeatureIRQ(void)                                         *
01257      *   {                                                                    *
01258      *     feature_irq.disable_irq();                                         *
01259      *   }                                                                    *
01260      *------------------------------------------------------------------------*/
01261     /**
01262      * @brief  Attaching an interrupt handler to the FLAG interrupt.
01263      * @param  fptr An interrupt handler.
01264      * @retval None.
01265      */
01266     void AttachFlagIRQ(void (*fptr)(void))
01267     {
01268         flag_irq.fall(fptr);
01269     }
01270     
01271     /**
01272      * @brief  Enabling the FLAG interrupt handling.
01273      * @param  None.
01274      * @retval None.
01275      */
01276     void EnableFlagIRQ(void)
01277     {
01278         flag_irq.enable_irq();
01279     }
01280     
01281     /**
01282      * @brief  Disabling the FLAG interrupt handling.
01283      * @param  None.
01284      * @retval None.
01285      */
01286     void DisableFlagIRQ(void)
01287     {
01288         flag_irq.disable_irq();
01289     }
01290 
01291     /**
01292      * @brief  Attaching an interrupt handler to the BUSY interrupt.
01293      * @param  fptr An interrupt handler.
01294      * @retval None.
01295      */
01296     void AttachBusyIRQ(void (*fptr)(void))
01297     {
01298         busy_irq.fall(fptr);
01299     }
01300     
01301     /**
01302      * @brief  Enabling the BUSY interrupt handling.
01303      * @param  None.
01304      * @retval None.
01305      */
01306     void EnableBusyIRQ(void)
01307     {
01308         busy_irq.enable_irq();
01309     }
01310 
01311     /**
01312      * @brief  Disabling the BUSY interrupt handling.
01313      * @param  None.
01314      * @retval None.
01315      */
01316     void DisableBusyIRQ(void)
01317     {
01318         busy_irq.disable_irq();
01319     }
01320 
01321 
01322 protected:
01323 
01324     /*** Protected Component Related Methods ***/
01325 
01326     /* ACTION 7 --------------------------------------------------------------*
01327      * Declare here the component's specific methods.                         *
01328      * They should be:                                                        *
01329      *   + Methods with the same name of the C component's virtual table's    *
01330      *     functions (1);                                                     *
01331      *   + Methods with the same name of the C component's extended virtual   *
01332      *     table's functions, if any (2);                                     *
01333      *   + Helper methods, if any, like functions declared in the component's *
01334      *     source files but not pointed by the component's virtual table (3). *
01335      *                                                                        *
01336      * Example:                                                               *
01337      *   Status_t COMPONENT_GetValue(float *f);   //(1)                       *
01338      *   Status_t COMPONENT_EnableFeature(void);  //(2)                       *
01339      *   Status_t COMPONENT_ComputeAverage(void); //(3)                       *
01340      *------------------------------------------------------------------------*/
01341     int32_t  L6470_AbsPos_2_Position(uint32_t AbsPos);
01342     uint32_t L6470_Position_2_AbsPos(int32_t Position);
01343     float    L6470_Speed_2_Step_s(uint32_t Speed);
01344     uint32_t L6470_Step_s_2_Speed(float Step_s);
01345     float    L6470_Acc_2_Step_s2(uint16_t Acc);
01346     uint16_t L6470_Step_s2_2_Acc(float Step_s2);
01347     float    L6470_Dec_2_Step_s2(uint16_t Dec);
01348     uint16_t L6470_Step_s2_2_Dec(float Step_s2);
01349     float    L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed);
01350     uint16_t L6470_Step_s_2_MaxSpeed(float Step_s);
01351     float    L6470_MinSpeed_2_Step_s(uint16_t MinSpeed);
01352     uint16_t L6470_Step_s_2_MinSpeed(float Step_s);
01353     float    L6470_FsSpd_2_Step_s(uint16_t FsSpd);
01354     uint16_t L6470_Step_s_2_FsSpd(float Step_s);
01355     float    L6470_IntSpeed_2_Step_s(uint16_t IntSpeed);
01356     uint16_t L6470_Step_s_2_IntSpeed(float Step_s);
01357     float    L6470_StSlp_2_s_Step(uint8_t StSlp);
01358     uint8_t  L6470_s_Step_2_StSlp(float s_Step);
01359     float    L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc);
01360     uint8_t  L6470_s_Step_2_FnSlpAcc(float s_Step);
01361     float    L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec);
01362     uint8_t  L6470_s_Step_2_FnSlpDec(float s_Step);
01363     float    L6470_OcdTh_2_mA(uint8_t OcdTh);
01364     uint8_t  L6470_mA_2_OcdTh(float mA);
01365     float    L6470_StallTh_2_mA(uint8_t StallTh);
01366     uint8_t  L6470_mA_2_StallTh(float mA);
01367     Status_t L6470_Config(void *init);
01368     void     L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
01369     uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId);
01370     void     L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed);
01371     void     L6470_StepClock(eL6470_DirId_t L6470_DirId);
01372     void     L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
01373     void     L6470_GoTo(uint32_t AbsPos);
01374     void     L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
01375     void     L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
01376     void     L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
01377     void     L6470_GoHome(void);
01378     void     L6470_GoMark(void);
01379     void     L6470_ResetPos(void);
01380     void     L6470_ResetDevice(void);
01381     void     L6470_SoftStop(void);
01382     void     L6470_HardStop(void);
01383     void     L6470_SoftHiZ(void);
01384     void     L6470_HardHiZ(void);
01385     uint16_t L6470_GetStatus(void);
01386     void     L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
01387     void     L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId);
01388     void     L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed);
01389     void     L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId);
01390     void     L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
01391     void     L6470_PrepareGoTo(uint32_t AbsPos);
01392     void     L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
01393     void     L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
01394     void     L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
01395     void     L6470_PrepareGoHome(void);
01396     void     L6470_PrepareGoMark(void);
01397     void     L6470_PrepareResetPos(void);
01398     void     L6470_PrepareResetDevice(void);
01399     void     L6470_PrepareSoftStop(void);
01400     void     L6470_PrepareHardStop(void);
01401     void     L6470_PrepareSoftHiZ(void);
01402     void     L6470_PrepareHardHiZ(void);
01403     void     L6470_PrepareGetStatus(void);
01404     uint8_t* L6470_PerformPreparedApplicationCommand(void);
01405     void     L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct);
01406     uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
01407     uint8_t  L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId);
01408     uint8_t* L6470_GetRegisterName(uint8_t id);
01409     void     L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg);
01410     void     L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
01411     void     L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
01412     void     L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct);
01413 
01414     /**
01415      * @brief  Rounding a floating point number to the nearest unsigned integer number.
01416      * @param  f The floating point number.
01417      * @retval The nearest unsigned integer number.
01418      */
01419     int round(float f)
01420     {
01421         if (f >= 0)
01422             return (int) f + (f - (int) f < 0.5f ? 0 : 1);
01423         else
01424             return (int) f - (f - (int) f < -0.5f ? 1 : 0);
01425     }
01426 
01427 
01428     /*** Component's I/O Methods ***/
01429 
01430     /**
01431      * @brief      Utility function to read data from L6470.
01432      * @param[out] pBuffer pointer to the buffer to read data into.
01433      * @param[in]  NumBytesToRead number of bytes to read.
01434      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
01435      */
01436     Status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
01437     {
01438         if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0)
01439             return COMPONENT_ERROR;
01440         return COMPONENT_OK;
01441     }
01442     
01443     /**
01444      * @brief      Utility function to write data to L6470.
01445      * @param[in]  pBuffer pointer to the buffer of data to send.
01446      * @param[in]  NumBytesToWrite number of bytes to write.
01447      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
01448      */
01449     Status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite)
01450     {
01451         if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0)
01452             return COMPONENT_ERROR;
01453         return COMPONENT_OK;
01454     }
01455 
01456     /**
01457      * @brief      Utility function to read and write data from/to L6470 at the same time.
01458      * @param[out] pBufferToRead pointer to the buffer to read data into.
01459      * @param[in]  pBufferToWrite pointer to the buffer of data to send.
01460      * @param[in]  NumBytes number of bytes to read and write.
01461      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
01462      */
01463     Status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
01464     {
01465         if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0)
01466             return COMPONENT_ERROR;
01467         return COMPONENT_OK;
01468     }
01469 
01470     /* ACTION 8 --------------------------------------------------------------*
01471      * Implement here other I/O methods beyond those already implemented      *
01472      * above, which are declared extern within the component's header file.   *
01473      *------------------------------------------------------------------------*/
01474     /*
01475      * Puts the device in standby mode.
01476      */
01477     void L6470_ENABLE(void)
01478     {
01479         standby_reset = 1;
01480     }
01481 
01482     /*
01483      * Puts the device in reset mode.
01484      */
01485     void L6470_DISABLE(void)
01486     {
01487         standby_reset = 0;
01488     }
01489 
01490     /*
01491      * Write and read bytes to/from the component through the SPI at the same time.
01492      */
01493     void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
01494     {
01495         ReadWrite(pRxData, pTxData, Size);
01496     }
01497 
01498 
01499     /*** Component's Instance Variables ***/
01500 
01501     /* ACTION 9 --------------------------------------------------------------*
01502      * Declare here interrupt related variables, if needed.                   *
01503      * Note that interrupt handling is platform dependent, see                *
01504      * "Interrupt Related Methods" above.                                     *
01505      *                                                                        *
01506      * Example:                                                               *
01507      *   + mbed:                                                              *
01508      *     InterruptIn feature_irq;                                           *
01509      *------------------------------------------------------------------------*/
01510     /* Flag Interrupt. */
01511     InterruptIn flag_irq;
01512 
01513     /* Busy Interrupt. */
01514     InterruptIn busy_irq;
01515 
01516     /* ACTION 10 -------------------------------------------------------------*
01517      * Declare here other pin related variables, if needed.                   *
01518      *                                                                        *
01519      * Example:                                                               *
01520      *   + mbed:                                                              *
01521      *     DigitalOut standby_reset;                                          *
01522      *------------------------------------------------------------------------*/
01523     /* Standby/reset pin. */
01524     DigitalOut standby_reset;
01525 
01526     /* ACTION 11 -------------------------------------------------------------*
01527      * Declare here communication related variables, if needed.               *
01528      *                                                                        *
01529      * Example:                                                               *
01530      *   + mbed:                                                              *
01531      *     DigitalOut ssel;                                                   *
01532      *     DevSPI &dev_spi;                                                   *
01533      *------------------------------------------------------------------------*/
01534     /* Configuration. */
01535     DigitalOut ssel;
01536 
01537     /* IO Device. */
01538     DevSPI &dev_spi;
01539 
01540     /* ACTION 12 -------------------------------------------------------------*
01541      * Declare here identity related variables, if needed.                    *
01542      * Note that there should be only a unique identifier for each component, *
01543      * which should be the "who_am_i" parameter.                              *
01544      *------------------------------------------------------------------------*/
01545     /* Identity */
01546     uint8_t who_am_i;
01547 
01548     /* ACTION 13 -------------------------------------------------------------*
01549      * Declare here the component's static and non-static data, one variable  *
01550      * per line.                                                              *
01551      *                                                                        *
01552      * Example:                                                               *
01553      *   float measure;                                                       *
01554      *   int instance_id;                                                     *
01555      *   static int number_of_instances;                                      *
01556      *------------------------------------------------------------------------*/
01557     /* Data. */
01558     uint8_t L6470_Id;
01559     const sL6470_Register_t *L6470_Register;
01560     const sL6470_ApplicationCommand_t *L6470_ApplicationCommand;
01561     const sL6470_Direction_t *L6470_Direction;
01562     const sL6470_ACT_t *L6470_ACT;
01563     sL6470_StatusRegister_t L6470_StatusRegister;
01564     sL6470_StatusRegister_t *pL6470_StatusRegister; 
01565     StepperMotorRegister_t StepperMotorRegister;
01566     prepared_action_t prepared_action;
01567 
01568     /* Static data. */
01569     static uint8_t number_of_devices;
01570     static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE];
01571     static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE];
01572     static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE];
01573     static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE];
01574     static eFlagStatus_t L6470_DaisyChain_HalfPrepared;
01575     static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
01576     static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
01577     static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
01578 };
01579 
01580 #endif /* __L6470_CLASS_H */
01581 
01582 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/