Fabian Scherrer / X_NUCLEO_IHM02A1

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   SpleisserProgramm SpleisserProgramm_v2 SpleisserProgramm_v5 SpleisserProgramm_V7 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers L6470.h Source File

L6470.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    L6470.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_def.h"
00067 /* ACTION 3 ------------------------------------------------------------------*
00068  * Include here interface specific header files.                              *
00069  *                                                                            *
00070  * Example:                                                                   *
00071  *   #include "HumiditySensor.h"                                              *
00072  *   #include "TemperatureSensor.h"                                           *
00073  *----------------------------------------------------------------------------*/
00074 #include "StepperMotor.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++;
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 get_value(float *p_data) //(1)                           *
00158      *   {                                                                    *
00159      *     return COMPONENT_get_value(float *pf_data);                        *
00160      *   }                                                                    *
00161      *                                                                        *
00162      *   virtual int enable_feature(void) //(2)                               *
00163      *   {                                                                    *
00164      *     return COMPONENT_enable_feature();                                 *
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 read_id(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 get_status(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 get_parameter(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 get_position(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 get_mark(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 get_speed(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 get_max_speed(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 get_min_speed(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 get_acceleration(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 get_deceleration(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 get_direction(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 soft_hiz() 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 set_parameter(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 set_home(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 set_mark(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 set_mark(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 set_max_speed(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 set_min_speed(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 set_acceleration(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 set_deceleration(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 soft_hiz() 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 set_step_mode(step_mode_t step_mode)
00457     {
00458         if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128) {
00459             return false;
00460         }
00461         soft_hiz();
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 go_to(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 go_to(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 go_home(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 go_mark(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 go_until(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 soft_stop(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 hard_stop(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 soft_hiz(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 hard_hiz(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 wait_while_active(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 soft_hiz() method.
00614      */
00615     virtual void step_clock(direction_t direction)
00616     {
00617         soft_hiz();
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 release_sw(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 reset_device(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 "perform_action()".
00651      */
00652     virtual void prepare_get_status(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 "perform_action()".
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 prepare_get_parameter(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 "perform_action()".
00701      */
00702     virtual void prepare_get_position(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 "perform_action()".
00713      */
00714     virtual void prepare_get_mark(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 "perform_action()".
00725      */
00726     virtual void prepare_get_speed(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 "perform_action()".
00737      */
00738     virtual void prepare_get_max_speed(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 "perform_action()".
00749      */
00750     virtual void prepare_get_min_speed(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 "perform_action()".
00761      */
00762     virtual void prepare_get_acceleration(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 "perform_action()".
00773      */
00774     virtual void prepare_get_deceleration(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 "perform_action()".
00785      */
00786     virtual void prepare_get_direction(void)
00787     {
00788         if (!L6470_DaisyChain_HalfPrepared) {
00789             /* To avoid deleting the previous entered command. */
00790             L6470_DaisyChain_HalfPrepared = ONE_F;
00791             /* Resetting commands. */
00792             L6470_ResetAppCmdPkg(L6470_AppCmdPkg);
00793         }
00794         prepared_action = PREPARED_GET_DIRECTION;
00795     }
00796 
00797     /**
00798      * @brief  Preparing the command to set a parameter.
00799      * @param  parameter A parameter's register address.
00800      * @param  value The parameter's value.
00801      * @retval None.
00802      * @note   The command will be sent by issuing "perform_action()".
00803      *         The parameter can be one of the following:
00804      *           + L6470_ABS_POS_ID
00805      *           + L6470_EL_POS_ID
00806      *           + L6470_MARK_ID
00807      *           + L6470_SPEED_ID
00808      *           + L6470_ACC_ID
00809      *           + L6470_DEC_ID
00810      *           + L6470_MAX_SPEED_ID
00811      *           + L6470_MIN_SPEED_ID
00812      *           + L6470_FS_SPD_ID
00813      *           + L6470_KVAL_HOLD_ID
00814      *           + L6470_KVAL_RUN_ID
00815      *           + L6470_KVAL_ACC_ID
00816      *           + L6470_KVAL_DEC_ID
00817      *           + L6470_INT_SPEED_ID
00818      *           + L6470_ST_SLP_ID
00819      *           + L6470_FN_SLP_ACC_ID
00820      *           + L6470_FN_SLP_DEC_ID
00821      *           + L6470_K_THERM_ID
00822      *           + L6470_ADC_OUT_ID
00823      *           + L6470_OCD_TH_ID
00824      *           + L6470_STALL_TH_ID
00825      *           + L6470_STEP_MODE_ID
00826      *           + L6470_ALARM_EN_ID
00827      *           + L6470_CONFIG_ID
00828      *           + L6470_STATUS_ID
00829      * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
00830      *          Any attempt to write one of those registers when the conditions are not satisfied
00831      *          causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
00832      *          last argument byte. Any attempt to set an inexistent register (wrong address value)
00833      *          causes the command to be ignored and the WRONG_CMD flag to rise.
00834      *          For example, setting some parameters requires first to disable the power bridge;
00835      *          this can be done through the soft_hiz() method.
00836      *          They are the following:
00837      *           + L6470_ABS_POS_ID
00838      *           + L6470_EL_POS_ID
00839      *           + L6470_SPEED_ID
00840      *           + L6470_ACC_ID
00841      *           + L6470_DEC_ID
00842      *           + L6470_MAX_SPEED_ID
00843      *           + L6470_MIN_SPEED_ID
00844      *           + L6470_INT_SPEED_ID
00845      *           + L6470_ST_SLP_ID
00846      *           + L6470_FN_SLP_ACC_ID
00847      *           + L6470_FN_SLP_DEC_ID
00848      *           + L6470_ADC_OUT_ID
00849      *           + L6470_STEP_MODE_ID
00850      *           + L6470_CONFIG_ID
00851      *           + L6470_STATUS_ID
00852      */
00853     virtual void prepare_set_parameter(unsigned int parameter, unsigned int value)
00854     {
00855         L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value);
00856         prepared_action = PREPARED_NO_ACTION;
00857     }
00858 
00859     /**
00860      * @brief  Preparing the command to set the current position to be
00861      *         the home position.
00862      * @param  None.
00863      * @retval None.
00864      * @note   The command will be sent by issuing "perform_action()".
00865      */
00866     virtual void prepare_set_home(void)
00867     {
00868         L6470_PrepareResetPos();
00869         prepared_action = PREPARED_NO_ACTION;
00870     }
00871 
00872     /**
00873      * @brief  Preparing the command to set the current position to be
00874      *         the marked position.
00875      * @param  None.
00876      * @retval None.
00877      * @note   The command will be sent by issuing "perform_action()".
00878      */
00879     virtual void prepare_set_mark(void)
00880     {
00881         /*
00882            Set "0" now as marked position. This value will be replaced by the
00883            actual position read at the time when the prepared actions will be
00884            performed.
00885         */
00886         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0);
00887         prepared_action = PREPARED_SET_MARK;
00888     }
00889 
00890     /**
00891      * @brief  Preparing the command to set the given position to be
00892      *         the marked position.
00893      * @param  position The given position.
00894      * @retval None.
00895      * @note   The command will be sent by issuing "perform_action()".
00896      */
00897     virtual void prepare_set_mark(signed int position)
00898     {
00899         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
00900         prepared_action = PREPARED_NO_ACTION;
00901     }
00902 
00903     /**
00904      * @brief  Preparing the command to set the current speed in pps.
00905      * @param  speed The current speed in pps.
00906      * @retval None.
00907      * @note   The command will be sent by issuing "perform_action()".
00908      */
00909     virtual void prepare_set_speed(unsigned int speed)
00910     {
00911         L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed));
00912         prepared_action = PREPARED_NO_ACTION;
00913     }
00914 
00915     /**
00916      * @brief  Preparing the command to set the maximum speed in pps.
00917      * @param  speed The maximum speed in pps.
00918      * @retval None.
00919      * @note   The command will be sent by issuing "perform_action()".
00920      */
00921     virtual void prepare_set_max_speed(unsigned int speed)
00922     {
00923         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
00924         prepared_action = PREPARED_NO_ACTION;
00925     }
00926 
00927     /**
00928      * @brief  Preparing the command to set the minimum speed in pps.
00929      * @param  speed The minimum speed in pps.
00930      * @retval None.
00931      * @note   The command will be sent by issuing "perform_action()".
00932      */
00933     virtual void prepare_set_min_speed(unsigned int speed)
00934     {
00935         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
00936         prepared_action = PREPARED_NO_ACTION;
00937     }
00938 
00939     /**
00940      * @brief  Preparing the command to set the acceleration in pps^2.
00941      * @param  acceleration The acceleration in pps^2.
00942      * @retval None.
00943      * @note   The command will be sent by issuing "perform_action()".
00944      */
00945     virtual void prepare_set_acceleration(unsigned int acceleration)
00946     {
00947         L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
00948         prepared_action = PREPARED_NO_ACTION;
00949     }
00950 
00951     /**
00952      * @brief  Preparing the command to set the deceleration in pps^2.
00953      * @param  deceleration The deceleration in pps^2.
00954      * @retval None.
00955      * @note   The command will be sent by issuing "perform_action()".
00956      */
00957     virtual void prepare_set_deceleration(unsigned int deceleration)
00958     {
00959         L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
00960         prepared_action = PREPARED_NO_ACTION;
00961     }
00962 
00963     /**
00964      * @brief  Preparing the command to go to a specified position.
00965      * @param  position The desired position.
00966      * @retval None.
00967      * @note   The command will be sent by issuing "perform_action()".
00968      */
00969     virtual void prepare_go_to(signed int position)
00970     {
00971         L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
00972         prepared_action = PREPARED_NO_ACTION;
00973     }
00974 
00975     /**
00976      * @brief  Preparing the command to go to a specified position
00977      *         imposing the desired direction.
00978      * @param  position The desired position.
00979      * @param  direction The direction of rotation.
00980      * @retval None.
00981      * @note   The command will be sent by issuing "perform_action()".
00982      */
00983     virtual void prepare_go_to(signed int position, direction_t direction)
00984     {
00985         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));
00986         prepared_action = PREPARED_NO_ACTION;
00987     }
00988 
00989     /**
00990      * @brief  Preparing the command to go to the home position.
00991      * @param  None.
00992      * @retval None.
00993      * @note   The command will be sent by issuing "perform_action()".
00994      */
00995     virtual void prepare_go_home(void)
00996     {
00997         L6470_PrepareGoHome();
00998         prepared_action = PREPARED_NO_ACTION;
00999     }
01000 
01001     /**
01002      * @brief  Preparing the command to go to the marked position.
01003      * @param  None.
01004      * @retval None.
01005      * @note   The command will be sent by issuing "perform_action()".
01006      */
01007     virtual void prepare_go_mark(void)
01008     {
01009         L6470_PrepareGoMark();
01010         prepared_action = PREPARED_NO_ACTION;
01011     }
01012 
01013     /**
01014      * @brief  Preparing the command to run at the given speed imposing the desired
01015      *         direction until an external switch turn-on event occurs.
01016      * @param  action The identifier of the action about the absolute position.
01017      * @param  position The desired position.
01018      * @param  speed The speed value in pps.
01019      * @retval None.
01020      * @note   The command will be sent by issuing "perform_action()".
01021      *         The identifier of the action about the absolute position can be
01022      *         one of the following:
01023      *           + L6470_ACT_RST_ID: the absolute position is reset;
01024      *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
01025      */
01026     virtual void prepare_go_until(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed)
01027     {
01028         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));
01029         prepared_action = PREPARED_NO_ACTION;
01030     }
01031 
01032     /**
01033      * @brief  Preparing the command to run towards a specified direction
01034      *         at the maximum speed.
01035      * @param  direction The direction of rotation.
01036      * @retval None.
01037      * @note   The command will be sent by issuing "perform_action()".
01038      */
01039     virtual void prepare_run(direction_t direction)
01040     {
01041         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));
01042         prepared_action = PREPARED_NO_ACTION;
01043     }
01044 
01045     /**
01046      * @brief  Preparing the command to run towards a specified direction
01047      *         at the given speed.
01048      * @param  direction The direction of rotation.
01049      * @param  speed The speed value in pps.
01050      * @retval None.
01051      * @note   The command will be sent by issuing "perform_action()".
01052      */
01053     virtual void prepare_run(direction_t direction, unsigned int speed)
01054     {
01055         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));
01056         prepared_action = PREPARED_NO_ACTION;
01057     }
01058 
01059     /**
01060      * @brief  Preparing the command to move towards a specified direction
01061      *         for a certain number of steps.
01062      * @param  direction The direction of rotation.
01063      * @param  steps The desired number of steps.
01064      * @retval None.
01065      * @note   The command will be sent by issuing "perform_action()".
01066      */
01067     virtual void prepare_move(direction_t direction, unsigned int steps)
01068     {
01069         L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
01070         prepared_action = PREPARED_NO_ACTION;
01071     }
01072 
01073     /**
01074      * @brief  Preparing the command to stop the motor.
01075      * @param  None.
01076      * @retval None.
01077      * @note   The command will be sent by issuing "perform_action()".
01078      */
01079     virtual void prepare_soft_stop(void)
01080     {
01081         L6470_PrepareSoftStop();
01082         prepared_action = PREPARED_NO_ACTION;
01083     }
01084 
01085     /**
01086      * @brief  Preparing the command to stop the motor and disabling the power bridge.
01087      * @param  None.
01088      * @retval None.
01089      * @note   The command will be sent by issuing "perform_action()".
01090      */
01091     virtual void prepare_hard_stop(void)
01092     {
01093         L6470_PrepareHardStop();
01094         prepared_action = PREPARED_NO_ACTION;
01095     }
01096 
01097     /**
01098      * @brief  Preparing the command to disable the power bridge after performing
01099      *         a deceleration to zero.
01100      *         The used deceleration value is the one stored in the "DEC" register.
01101      * @param  None.
01102      * @retval None.
01103      * @note   The command will be sent by issuing "perform_action()".
01104      */
01105     virtual void prepare_soft_hiz(void)
01106     {
01107         L6470_PrepareSoftHiZ();
01108         prepared_action = PREPARED_NO_ACTION;
01109     }
01110 
01111     /**
01112      * @brief  Preparing the command to disable the power bridge immediately.
01113      * @param  None.
01114      * @retval None.
01115      * @note   The command will be sent by issuing "perform_action()".
01116      */
01117     virtual void prepare_hard_hiz(void)
01118     {
01119         L6470_PrepareHardHiZ();
01120         prepared_action = PREPARED_NO_ACTION;
01121     }
01122 
01123     /**
01124      * @brief   Preparing the command to switch to step-clock mode.
01125      * @param   direction The direction of rotation.
01126      * @retval  None.
01127      * @warning Setting the step-clock mode requires an explicit action by the user to first
01128      *          disable the power bridge through the soft_hiz() method.
01129      * @note    The command will be sent by issuing "perform_action()".
01130      */
01131     virtual void prepare_step_clock(direction_t direction)
01132     {
01133         L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
01134         prepared_action = PREPARED_NO_ACTION;
01135     }
01136 
01137     /**
01138       * @brief  Preparing the command to do a motion at minimum speed
01139       *         imposing a specified direction until the SW is released.
01140       * @param  action The identifier of the action about the absolute position.
01141       * @param  direction The direction of rotation.
01142       * @retval None.
01143       * @note   The command will be sent by issuing "perform_action()".
01144       *         The identifier of the action about the absolute position can be
01145       *         one of the following:
01146       *           + L6470_ACT_RST_ID: the absolute position is reset;
01147       *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
01148       */
01149     virtual void prepare_release_sw(eL6470_ActId_t action, direction_t direction)
01150     {
01151         L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
01152         prepared_action = PREPARED_NO_ACTION;
01153     }
01154 
01155     /**
01156       * @brief  Preparing the command to reset the device to power-up conditions.
01157       * @param  None.
01158       * @retval None.
01159       * @note   The command will be sent by issuing "perform_action()".
01160       */
01161     virtual void prepare_reset_device(void)
01162     {
01163         L6470_PrepareResetDevice();
01164         prepared_action = PREPARED_NO_ACTION;
01165     }
01166 
01167     /**
01168       * @brief    Performing all the actions prepared on the components
01169       *           of the daisy-chain.
01170       * @param    None.
01171       * @retval   The raw data returned by the components.
01172       */
01173     uint8_t* perform_prepared_actions(void)
01174     {
01175         return L6470_PerformPreparedApplicationCommand();
01176     }
01177 
01178     /**
01179       * @brief    Getting the prepared action.
01180       * @param    None
01181       * @retval   The prepared action.
01182       */
01183     prepared_action_t get_prepared_action(void)
01184     {
01185         return prepared_action;
01186     }
01187 
01188     /**
01189       * @brief    Converting the raw data received by the component according to
01190       *           the action performed on it.
01191       * @param    raw_data The received raw data.
01192       * @retval   The result of the action performed.
01193       */
01194     int32_t get_result(uint8_t *raw_data)
01195     {
01196         switch (prepared_action) {
01197             case PREPARED_GET_POSITION:
01198                 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte));
01199 
01200             case PREPARED_GET_MARK:
01201                 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte));
01202 
01203             case PREPARED_GET_SPEED:
01204                 return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte)));
01205     
01206             case PREPARED_GET_MAX_SPEED:
01207                 return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte)));
01208     
01209             case PREPARED_GET_MIN_SPEED:
01210                 return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte)));
01211     
01212             case PREPARED_GET_ACCELERATION:
01213                 return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte)));
01214     
01215             case PREPARED_GET_DECELERATION:
01216                 return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte)));
01217 
01218             case PREPARED_GET_DIRECTION:
01219                 return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
01220 
01221             default:
01222             case PREPARED_NO_ACTION:
01223                 return 0;
01224         }
01225     }
01226 
01227 
01228     /*** Public Interrupt Related Methods ***/
01229 
01230     /* ACTION 6 --------------------------------------------------------------*
01231      * Implement here interrupt related methods, if any.                      *
01232      * Note that interrupt handling is platform dependent, e.g.:              *
01233      *   + mbed:                                                              *
01234      *     InterruptIn feature_irq(pin); //Interrupt object.                  *
01235      *     feature_irq.rise(callback);   //Attach a callback.                 *
01236      *     feature_irq.mode(PullNone);   //Set interrupt mode.                *
01237      *     feature_irq.enable_irq();     //Enable interrupt.                  *
01238      *     feature_irq.disable_irq();    //Disable interrupt.                 *
01239      *   + Arduino:                                                           *
01240      *     attachInterrupt(pin, callback, RISING); //Attach a callback.       *
01241      *     detachInterrupt(pin);                   //Detach a callback.       *
01242      *                                                                        *
01243      * Example (mbed):                                                        *
01244      *   void attach_feature_irq(void (*fptr) (void))                         *
01245      *   {                                                                    *
01246      *     feature_irq.rise(fptr);                                            *
01247      *   }                                                                    *
01248      *                                                                        *
01249      *   void enable_feature_irq(void)                                        *
01250      *   {                                                                    *
01251      *     feature_irq.enable_irq();                                          *
01252      *   }                                                                    *
01253      *                                                                        *
01254      *   void disable_feature_irq(void)                                       *
01255      *   {                                                                    *
01256      *     feature_irq.disable_irq();                                         *
01257      *   }                                                                    *
01258      *------------------------------------------------------------------------*/
01259     /**
01260      * @brief  Attaching an interrupt handler to the FLAG interrupt.
01261      * @param  fptr An interrupt handler.
01262      * @retval None.
01263      */
01264     void attach_flag_irq(void (*fptr)(void))
01265     {
01266         flag_irq.fall(fptr);
01267     }
01268     
01269     /**
01270      * @brief  Enabling the FLAG interrupt handling.
01271      * @param  None.
01272      * @retval None.
01273      */
01274     void enable_flag_irq(void)
01275     {
01276         flag_irq.enable_irq();
01277     }
01278     
01279     /**
01280      * @brief  Disabling the FLAG interrupt handling.
01281      * @param  None.
01282      * @retval None.
01283      */
01284     void disable_flag_irq(void)
01285     {
01286         flag_irq.disable_irq();
01287     }
01288 
01289     /**
01290      * @brief  Attaching an interrupt handler to the BUSY interrupt.
01291      * @param  fptr An interrupt handler.
01292      * @retval None.
01293      */
01294     void attach_busy_irq(void (*fptr)(void))
01295     {
01296         busy_irq.fall(fptr);
01297     }
01298     
01299     /**
01300      * @brief  Enabling the BUSY interrupt handling.
01301      * @param  None.
01302      * @retval None.
01303      */
01304     void enable_busy_irq(void)
01305     {
01306         busy_irq.enable_irq();
01307     }
01308 
01309     /**
01310      * @brief  Disabling the BUSY interrupt handling.
01311      * @param  None.
01312      * @retval None.
01313      */
01314     void disable_busy_irq(void)
01315     {
01316         busy_irq.disable_irq();
01317     }
01318 
01319 
01320 protected:
01321 
01322     /*** Protected Component Related Methods ***/
01323 
01324     /* ACTION 7 --------------------------------------------------------------*
01325      * Declare here the component's specific methods.                         *
01326      * They should be:                                                        *
01327      *   + Methods with the same name of the C component's virtual table's    *
01328      *     functions (1);                                                     *
01329      *   + Methods with the same name of the C component's extended virtual   *
01330      *     table's functions, if any (2);                                     *
01331      *   + Helper methods, if any, like functions declared in the component's *
01332      *     source files but not pointed by the component's virtual table (3). *
01333      *                                                                        *
01334      * Example:                                                               *
01335      *   status_t COMPONENT_get_value(float *f);   //(1)                      *
01336      *   status_t COMPONENT_enable_feature(void);  //(2)                      *
01337      *   status_t COMPONENT_compute_average(void); //(3)                      *
01338      *------------------------------------------------------------------------*/
01339     int32_t  L6470_AbsPos_2_Position(uint32_t AbsPos);
01340     uint32_t L6470_Position_2_AbsPos(int32_t Position);
01341     float    L6470_Speed_2_Step_s(uint32_t Speed);
01342     uint32_t L6470_Step_s_2_Speed(float Step_s);
01343     float    L6470_Acc_2_Step_s2(uint16_t Acc);
01344     uint16_t L6470_Step_s2_2_Acc(float Step_s2);
01345     float    L6470_Dec_2_Step_s2(uint16_t Dec);
01346     uint16_t L6470_Step_s2_2_Dec(float Step_s2);
01347     float    L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed);
01348     uint16_t L6470_Step_s_2_MaxSpeed(float Step_s);
01349     float    L6470_MinSpeed_2_Step_s(uint16_t MinSpeed);
01350     uint16_t L6470_Step_s_2_MinSpeed(float Step_s);
01351     float    L6470_FsSpd_2_Step_s(uint16_t FsSpd);
01352     uint16_t L6470_Step_s_2_FsSpd(float Step_s);
01353     float    L6470_IntSpeed_2_Step_s(uint16_t IntSpeed);
01354     uint16_t L6470_Step_s_2_IntSpeed(float Step_s);
01355     float    L6470_StSlp_2_s_Step(uint8_t StSlp);
01356     uint8_t  L6470_s_Step_2_StSlp(float s_Step);
01357     float    L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc);
01358     uint8_t  L6470_s_Step_2_FnSlpAcc(float s_Step);
01359     float    L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec);
01360     uint8_t  L6470_s_Step_2_FnSlpDec(float s_Step);
01361     float    L6470_OcdTh_2_mA(uint8_t OcdTh);
01362     uint8_t  L6470_mA_2_OcdTh(float mA);
01363     float    L6470_StallTh_2_mA(uint8_t StallTh);
01364     uint8_t  L6470_mA_2_StallTh(float mA);
01365     status_t L6470_Config(void *init);
01366     void     L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
01367     uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId);
01368     void     L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed);
01369     void     L6470_StepClock(eL6470_DirId_t L6470_DirId);
01370     void     L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
01371     void     L6470_GoTo(uint32_t AbsPos);
01372     void     L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
01373     void     L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
01374     void     L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
01375     void     L6470_GoHome(void);
01376     void     L6470_GoMark(void);
01377     void     L6470_ResetPos(void);
01378     void     L6470_ResetDevice(void);
01379     void     L6470_SoftStop(void);
01380     void     L6470_HardStop(void);
01381     void     L6470_SoftHiZ(void);
01382     void     L6470_HardHiZ(void);
01383     uint16_t L6470_GetStatus(void);
01384     void     L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
01385     void     L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId);
01386     void     L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed);
01387     void     L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId);
01388     void     L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
01389     void     L6470_PrepareGoTo(uint32_t AbsPos);
01390     void     L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
01391     void     L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
01392     void     L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
01393     void     L6470_PrepareGoHome(void);
01394     void     L6470_PrepareGoMark(void);
01395     void     L6470_PrepareResetPos(void);
01396     void     L6470_PrepareResetDevice(void);
01397     void     L6470_PrepareSoftStop(void);
01398     void     L6470_PrepareHardStop(void);
01399     void     L6470_PrepareSoftHiZ(void);
01400     void     L6470_PrepareHardHiZ(void);
01401     void     L6470_PrepareGetStatus(void);
01402     uint8_t* L6470_PerformPreparedApplicationCommand(void);
01403     void     L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct);
01404     uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
01405     uint8_t  L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId);
01406     uint8_t* L6470_GetRegisterName(uint8_t id);
01407     void     L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg);
01408     void     L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
01409     void     L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
01410     void     L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct);
01411 
01412     /**
01413      * @brief  Rounding a floating point number to the nearest unsigned integer number.
01414      * @param  f The floating point number.
01415      * @retval The nearest unsigned integer number.
01416      */
01417     int round(float f)
01418     {
01419         if (f >= 0) {
01420             return (int) f + (f - (int) f < 0.5f ? 0 : 1);
01421         } else {
01422             return (int) f - (f - (int) f < -0.5f ? 1 : 0);
01423         }
01424     }
01425 
01426 
01427     /*** Component's I/O Methods ***/
01428 
01429     /**
01430      * @brief      Utility function to read data from L6470.
01431      * @param[out] pBuffer pointer to the buffer to read data into.
01432      * @param[in]  NumBytesToRead number of bytes to read.
01433      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
01434      */
01435     status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
01436     {
01437         if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) {
01438             return COMPONENT_ERROR;
01439         }
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         }
01454         return COMPONENT_OK;
01455     }
01456 
01457     /**
01458      * @brief      Utility function to read and write data from/to L6470 at the same time.
01459      * @param[out] pBufferToRead pointer to the buffer to read data into.
01460      * @param[in]  pBufferToWrite pointer to the buffer of data to send.
01461      * @param[in]  NumBytes number of bytes to read and write.
01462      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
01463      */
01464     status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
01465     {
01466         if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) {
01467             return COMPONENT_ERROR;
01468         }
01469         return COMPONENT_OK;
01470     }
01471 
01472     /* ACTION 8 --------------------------------------------------------------*
01473      * Implement here other I/O methods beyond those already implemented      *
01474      * above, which are declared extern within the component's header file.   *
01475      *------------------------------------------------------------------------*/
01476     /*
01477      * Puts the device in standby mode.
01478      */
01479     void L6470_ENABLE(void)
01480     {
01481         standby_reset = 1;
01482     }
01483 
01484     /*
01485      * Puts the device in reset mode.
01486      */
01487     void L6470_DISABLE(void)
01488     {
01489         standby_reset = 0;
01490     }
01491 
01492     /*
01493      * Write and read bytes to/from the component through the SPI at the same time.
01494      */
01495     void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
01496     {
01497         ReadWrite(pRxData, pTxData, Size);
01498     }
01499 
01500 
01501     /*** Component's Instance Variables ***/
01502 
01503     /* ACTION 9 --------------------------------------------------------------*
01504      * Declare here interrupt related variables, if needed.                   *
01505      * Note that interrupt handling is platform dependent, see                *
01506      * "Interrupt Related Methods" above.                                     *
01507      *                                                                        *
01508      * Example:                                                               *
01509      *   + mbed:                                                              *
01510      *     InterruptIn feature_irq;                                           *
01511      *------------------------------------------------------------------------*/
01512     /* Flag Interrupt. */
01513     InterruptIn flag_irq;
01514 
01515     /* Busy Interrupt. */
01516     InterruptIn busy_irq;
01517 
01518     /* ACTION 10 -------------------------------------------------------------*
01519      * Declare here other pin related variables, if needed.                   *
01520      *                                                                        *
01521      * Example:                                                               *
01522      *   + mbed:                                                              *
01523      *     DigitalOut standby_reset;                                          *
01524      *------------------------------------------------------------------------*/
01525     /* Standby/reset pin. */
01526     DigitalOut standby_reset;
01527 
01528     /* ACTION 11 -------------------------------------------------------------*
01529      * Declare here communication related variables, if needed.               *
01530      *                                                                        *
01531      * Example:                                                               *
01532      *   + mbed:                                                              *
01533      *     DigitalOut ssel;                                                   *
01534      *     DevSPI &dev_spi;                                                   *
01535      *------------------------------------------------------------------------*/
01536     /* Configuration. */
01537     DigitalOut ssel;
01538 
01539     /* IO Device. */
01540     DevSPI &dev_spi;
01541 
01542     /* ACTION 12 -------------------------------------------------------------*
01543      * Declare here identity related variables, if needed.                    *
01544      * Note that there should be only a unique identifier for each component, *
01545      * which should be the "who_am_i" parameter.                              *
01546      *------------------------------------------------------------------------*/
01547     /* Identity */
01548     uint8_t who_am_i;
01549 
01550     /* ACTION 13 -------------------------------------------------------------*
01551      * Declare here the component's static and non-static data, one variable  *
01552      * per line.                                                              *
01553      *                                                                        *
01554      * Example:                                                               *
01555      *   float measure;                                                       *
01556      *   int instance_id;                                                     *
01557      *   static int number_of_instances;                                      *
01558      *------------------------------------------------------------------------*/
01559     /* Data. */
01560     uint8_t L6470_Id;
01561     const sL6470_Register_t *L6470_Register;
01562     const sL6470_ApplicationCommand_t *L6470_ApplicationCommand;
01563     const sL6470_Direction_t *L6470_Direction;
01564     const sL6470_ACT_t *L6470_ACT;
01565     sL6470_StatusRegister_t L6470_StatusRegister;
01566     sL6470_StatusRegister_t *pL6470_StatusRegister; 
01567     StepperMotorRegister_t StepperMotorRegister;
01568     prepared_action_t prepared_action;
01569 
01570     /* Static data. */
01571     static uint8_t number_of_devices;
01572     static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE];
01573     static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE];
01574     static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE];
01575     static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE];
01576     static eFlagStatus_t L6470_DaisyChain_HalfPrepared;
01577     static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
01578     static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
01579     static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
01580 };
01581 
01582 //////////////////////////////////////////////////////////////////////////////////////////////Fabian
01583 /**
01584  * @brief Class representing a L6470 component.
01585  */
01586 class L6470B : public StepperMotor
01587 {
01588 public:
01589 
01590     /*** Public Component Related Types ***/
01591 
01592     /**
01593      * @brief Prepared Actions.
01594      */
01595     typedef enum
01596     {
01597         PREPARED_NO_ACTION = 0,
01598         PREPARED_GET_POSITION,
01599         PREPARED_GET_MARK,
01600         PREPARED_GET_SPEED,
01601         PREPARED_GET_MAX_SPEED,
01602         PREPARED_GET_MIN_SPEED,
01603         PREPARED_GET_ACCELERATION,
01604         PREPARED_GET_DECELERATION,
01605         PREPARED_GET_DIRECTION,
01606         PREPARED_SET_MARK
01607     } prepared_action_t;
01608 
01609 
01610     /*** Constructor and Destructor Methods ***/
01611 
01612     /**
01613      * @brief Constructor.
01614      * @param flag_irq      pin name of the FLAG pin of the component.
01615      * @param busy_irq      pin name of the BUSY pin of the component.
01616      * @param standby_reset pin name of the STBY\RST pin of the component.
01617      * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
01618      * @param spi           SPI device to be used for communication.
01619      */
01620     L6470B(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)
01621     {
01622         /* ACTION 4 ----------------------------------------------------------*
01623          * Initialize here the component's member variables, one variable per *
01624          * line.                                                              *
01625          *                                                                    *
01626          * Example:                                                           *
01627          *   measure = 0;                                                     *
01628          *   instance_id = number_of_instances++;                             *
01629          *--------------------------------------------------------------------*/
01630         L6470_Register = &_L6470_Register[0];
01631         L6470_ApplicationCommand = &_L6470_ApplicationCommand[0];
01632         L6470_Direction = &_L6470_Direction[0];
01633         L6470_ACT = &_L6470_ACT[0];
01634         pL6470_StatusRegister = &L6470_StatusRegister;
01635         prepared_action = PREPARED_NO_ACTION;
01636         L6470_Id = number_of_devices1++;
01637         L6470_DaisyChain_HalfPrepared = ZERO_F;
01638         memset(L6470_AppCmdPkg, 0, L6470DAISYCHAINSIZE * sizeof(sL6470_AppCmdPkg_t));
01639         memset(L6470_DaisyChainSpiTxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
01640         memset(L6470_DaisyChainSpiRxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
01641     }
01642 
01643     /**
01644      * @brief Destructor.
01645      */
01646     virtual ~L6470B(void) {}
01647 
01648 
01649     /*** Public Component Related Methods ***/
01650 
01651     /* ACTION 5 --------------------------------------------------------------*
01652      * Implement here the component's public methods, as wrappers of the C    *
01653      * component's functions.                                                 *
01654      * They should be:                                                        *
01655      *   + Methods with the same name of the C component's virtual table's    *
01656      *     functions (1);                                                     *
01657      *   + Methods with the same name of the C component's extended virtual   *
01658      *     table's functions, if any (2).                                     *
01659      *                                                                        *
01660      * Example:                                                               *
01661      *   virtual int get_value(float *p_data) //(1)                           *
01662      *   {                                                                    *
01663      *     return COMPONENT_get_value(float *pf_data);                        *
01664      *   }                                                                    *
01665      *                                                                        *
01666      *   virtual int enable_feature(void) //(2)                               *
01667      *   {                                                                    *
01668      *     return COMPONENT_enable_feature();                                 *
01669      *   }                                                                    *
01670      *------------------------------------------------------------------------*/
01671     /**
01672      * @brief  Initializing the component.
01673      * @param  init Pointer to device specific initalization structure.
01674      * @retval "0" in case of success, an error code otherwise.
01675      */
01676     virtual int init(void *init)
01677     {
01678         return (int) L6470_Config((void *) init);
01679     }
01680 
01681     /**
01682      * @brief  Getting the ID of the component.
01683      * @param  id Pointer to an allocated variable to store the ID into.
01684      * @retval "0" in case of success, an error code otherwise.
01685      */
01686     virtual int read_id(uint8_t *id)
01687     {
01688         return (int) 0;
01689     }
01690 
01691     /**
01692      * @brief  Getting the status.
01693      * @param  None.
01694      * @retval The status.
01695      */
01696     virtual unsigned int get_status(void)
01697     {
01698         return (unsigned int) L6470_GetStatus();
01699     }
01700 
01701     /**
01702      * @brief  Getting a parameter.
01703      * @param  parameter A parameter's register address.
01704      * @retval The parameter's value.
01705      * @note   The parameter can be one of the following:
01706      *           + L6470_ABS_POS_ID
01707      *           + L6470_EL_POS_ID
01708      *           + L6470_MARK_ID
01709      *           + L6470_SPEED_ID
01710      *           + L6470_ACC_ID
01711      *           + L6470_DEC_ID
01712      *           + L6470_MAX_SPEED_ID
01713      *           + L6470_MIN_SPEED_ID
01714      *           + L6470_FS_SPD_ID
01715      *           + L6470_KVAL_HOLD_ID
01716      *           + L6470_KVAL_RUN_ID
01717      *           + L6470_KVAL_ACC_ID
01718      *           + L6470_KVAL_DEC_ID
01719      *           + L6470_INT_SPEED_ID
01720      *           + L6470_ST_SLP_ID
01721      *           + L6470_FN_SLP_ACC_ID
01722      *           + L6470_FN_SLP_DEC_ID
01723      *           + L6470_K_THERM_ID
01724      *           + L6470_ADC_OUT_ID
01725      *           + L6470_OCD_TH_ID
01726      *           + L6470_STALL_TH_ID
01727      *           + L6470_STEP_MODE_ID
01728      *           + L6470_ALARM_EN_ID
01729      *           + L6470_CONFIG_ID
01730      *           + L6470_STATUS_ID
01731      */
01732     virtual unsigned int get_parameter(unsigned int parameter)
01733     {
01734         return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter);
01735     }
01736 
01737     /**
01738      * @brief  Getting the position.
01739      * @param  None.
01740      * @retval The position.
01741      */
01742     virtual signed int get_position(void)
01743     {
01744         return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
01745     }
01746 
01747     /**
01748      * @brief  Getting the marked position.
01749      * @param  None.
01750      * @retval The marked position.
01751      */
01752     virtual signed int get_mark(void)
01753     {
01754         return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID));
01755     }
01756 
01757     /**
01758      * @brief  Getting the current speed in pps.
01759      * @param  None.
01760      * @retval The current speed in pps.
01761      */
01762     virtual unsigned int get_speed(void)
01763     {
01764         return round(L6470_Speed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID)));
01765     }
01766 
01767     /**
01768      * @brief  Getting the maximum speed in pps.
01769      * @param  None.
01770      * @retval The maximum speed in pps.
01771      */
01772     virtual unsigned int get_max_speed(void)
01773     {
01774         return round(L6470_MaxSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID)));
01775     }
01776 
01777     /**
01778      * @brief  Getting the minimum speed in pps.
01779      * @param  None.
01780      * @retval The minimum speed in pps.
01781      */
01782     virtual unsigned int get_min_speed(void)
01783     {
01784         return round(L6470_MinSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID)));
01785     }
01786 
01787     /**
01788      * @brief  Getting the acceleration in pps^2.
01789      * @param  None.
01790      * @retval The acceleration in pps^2.
01791      */
01792     virtual unsigned int get_acceleration(void)
01793     {
01794         return round(L6470_Acc_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID)));
01795     }
01796 
01797     /**
01798      * @brief  Getting the deceleration in pps^2.
01799      * @param  None.
01800      * @retval The deceleration in pps^2.
01801      */
01802     virtual unsigned int get_deceleration(void)
01803     {
01804         return round(L6470_Dec_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID)));
01805     }
01806 
01807     /**
01808      * @brief  Getting the direction of rotation.
01809      * @param  None.
01810      * @retval The direction of rotation.
01811      */
01812     virtual direction_t get_direction(void)
01813     {
01814         return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
01815     }
01816 
01817     /**
01818      * @brief   Setting a parameter.
01819      * @param   parameter A parameter's register address.
01820      * @param   value The parameter's value.
01821      * @retval  None.
01822      * @note    The parameter can be one of the following:
01823      *           + L6470_ABS_POS_ID
01824      *           + L6470_EL_POS_ID
01825      *           + L6470_MARK_ID
01826      *           + L6470_SPEED_ID
01827      *           + L6470_ACC_ID
01828      *           + L6470_DEC_ID
01829      *           + L6470_MAX_SPEED_ID
01830      *           + L6470_MIN_SPEED_ID
01831      *           + L6470_FS_SPD_ID
01832      *           + L6470_KVAL_HOLD_ID
01833      *           + L6470_KVAL_RUN_ID
01834      *           + L6470_KVAL_ACC_ID
01835      *           + L6470_KVAL_DEC_ID
01836      *           + L6470_INT_SPEED_ID
01837      *           + L6470_ST_SLP_ID
01838      *           + L6470_FN_SLP_ACC_ID
01839      *           + L6470_FN_SLP_DEC_ID
01840      *           + L6470_K_THERM_ID
01841      *           + L6470_ADC_OUT_ID
01842      *           + L6470_OCD_TH_ID
01843      *           + L6470_STALL_TH_ID
01844      *           + L6470_STEP_MODE_ID
01845      *           + L6470_ALARM_EN_ID
01846      *           + L6470_CONFIG_ID
01847      *           + L6470_STATUS_ID
01848      * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
01849      *          Any attempt to write one of those registers when the conditions are not satisfied
01850      *          causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
01851      *          last argument byte. Any attempt to set an inexistent register (wrong address value)
01852      *          causes the command to be ignored and the WRONG_CMD flag to rise.
01853      *          For example, setting some parameters requires first to disable the power bridge;
01854      *          this can be done through the soft_hiz() method.
01855      *          They are the following:
01856      *           + L6470_ABS_POS_ID
01857      *           + L6470_EL_POS_ID
01858      *           + L6470_SPEED_ID
01859      *           + L6470_ACC_ID
01860      *           + L6470_DEC_ID
01861      *           + L6470_MAX_SPEED_ID
01862      *           + L6470_MIN_SPEED_ID
01863      *           + L6470_INT_SPEED_ID
01864      *           + L6470_ST_SLP_ID
01865      *           + L6470_FN_SLP_ACC_ID
01866      *           + L6470_FN_SLP_DEC_ID
01867      *           + L6470_ADC_OUT_ID
01868      *           + L6470_STEP_MODE_ID
01869      *           + L6470_CONFIG_ID
01870      *           + L6470_STATUS_ID
01871      */
01872     virtual void set_parameter(unsigned int parameter, unsigned int value)
01873     {
01874         L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value);
01875     }
01876 
01877     /**
01878      * @brief  Setting the current position to be the home position.
01879      * @param  None.
01880      * @retval None.
01881      */
01882     virtual void set_home(void)
01883     {
01884         L6470_ResetPos();
01885     }
01886 
01887     /**
01888      * @brief  Setting the current position to be the marked position.
01889      * @param  None.
01890      * @retval None.
01891      */
01892     virtual void set_mark(void)
01893     {
01894         L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
01895     }
01896 
01897     /**
01898      * @brief  Setting the current position to be the marked position.
01899      * @param  position The given position.
01900      * @retval None.
01901      */
01902     virtual void set_mark(signed int position)
01903     {
01904         L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
01905     }
01906 
01907     /**
01908      * @brief  Setting the maximum speed in pps.
01909      * @param  speed The maximum speed in pps.
01910      * @retval "true" in case of success, "false" otherwise.
01911      */
01912     virtual bool set_max_speed(unsigned int speed)
01913     {
01914         L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
01915         return true;
01916     }
01917 
01918     /**
01919      * @brief  Setting the minimum speed in pps.
01920      * @param  speed The minimum speed in pps.
01921      * @retval "true" in case of success, "false" otherwise.
01922      */
01923     virtual bool set_min_speed(unsigned int speed)
01924     {
01925         L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
01926         return true;
01927     }
01928 
01929     /**
01930      * @brief  Setting the acceleration in pps^2.
01931      * @param  acceleration The acceleration in pps^2.
01932      * @retval "true" in case of success, "false" otherwise.
01933      */
01934     virtual bool set_acceleration(unsigned int acceleration)
01935     {
01936         L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
01937         return true;
01938     }
01939 
01940     /**
01941      * @brief  Setting the deceleration in pps^2.
01942      * @param  deceleration The deceleration in pps^2.
01943      * @retval "true" in case of success, "false" otherwise.
01944      */
01945     virtual bool set_deceleration(unsigned int deceleration)
01946     {
01947         L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
01948         return true;
01949     }
01950 
01951     /**
01952      * @brief   Setting the Step Mode.
01953      * @param   step_mode The Step Mode.
01954      * @retval "true" in case of success, "false" otherwise.
01955      * @warning Setting the step mode implies first disabling the power bridge through
01956      *          the soft_hiz() method.
01957      * @warning Every time step mode is changed, the values of the home
01958      *          and mark positions lose meaning and are reset.
01959      */
01960     virtual bool set_step_mode(step_mode_t step_mode)
01961     {
01962         if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128) {
01963             return false;
01964         }
01965         soft_hiz();
01966         L6470_SetParam((eL6470_RegId_t) L6470_STEP_MODE_ID, (eMotorStepMode_t) step_mode);
01967         return true;
01968     }
01969 
01970     /**
01971      * @brief  Going to a specified position through the shortest path.
01972      * @param  position The desired position.
01973      * @retval None.
01974      */
01975     virtual void go_to(signed int position)
01976     {
01977         L6470_GoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
01978     }
01979 
01980     /**
01981      * @brief  Going to a specified position imposing the desired direction.
01982      * @param  position The desired position.
01983      * @param  direction The direction of rotation.
01984      * @retval None.
01985      */
01986     virtual void go_to(signed int position, direction_t direction)
01987     {
01988         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));
01989     }
01990 
01991     /**
01992      * @brief  Going to the home position.
01993      * @param  None.
01994      * @retval None.
01995      */
01996     virtual void go_home(void)
01997     {
01998         L6470_GoHome();
01999     }
02000 
02001     /**
02002      * @brief  Going to the marked position.
02003      * @param  None.
02004      * @retval None.
02005      */
02006     virtual void go_mark(void)
02007     {
02008         L6470_GoMark();
02009     }
02010 
02011     /**
02012      * @brief  Running at the given speed imposing the desired direction until
02013      *         an external switch turn-on event occurs.
02014      * @param  action The identifier of the action about the absolute position.
02015      * @param  position The desired position.
02016      * @param  speed The speed value in pps.
02017      * @retval None.
02018      * @note   The identifier of the action about the absolute position can be
02019      *         one of the following:
02020      *           + L6470_ACT_RST_ID: the absolute position is reset;
02021      *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
02022      */
02023     virtual void go_until(eL6470_ActId_t action, direction_t direction, unsigned int speed)
02024     {
02025         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));
02026     }
02027 
02028     /**
02029      * @brief  Running towards a specified direction.
02030      * @param  direction The direction of rotation.
02031      * @retval None.
02032      */
02033     virtual void run(direction_t direction)
02034     {
02035         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));
02036     }
02037 
02038     /**
02039      * @brief  Running towards a specified direction at the given speed.
02040      * @param  direction The direction of rotation.
02041      * @param  speed The speed value in pps.
02042      * @retval None.
02043      */
02044     virtual void run(direction_t direction, unsigned int speed)
02045     {
02046         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));
02047     }
02048 
02049     /**
02050      * @brief  Moving towards a specified direction for a certain number of steps.
02051      * @param  direction The direction of rotation.
02052      * @param  steps The desired number of steps.
02053      * @retval None.
02054      */
02055     virtual void move(direction_t direction, unsigned int steps)
02056     {
02057         L6470_Move((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
02058     }
02059 
02060     /**
02061      * @brief  Stopping the motor through an immediate deceleration up to zero speed.
02062      *         The used deceleration value is the one stored in the "DEC" register.
02063      * @param  None.
02064      * @retval None.
02065      */
02066     virtual void soft_stop(void)
02067     {
02068         L6470_SoftStop();
02069     }
02070 
02071     /**
02072      * @brief  Stopping the motor through an immediate infinite deceleration.
02073      * @param  None.
02074      * @retval None.
02075      */
02076     virtual void hard_stop(void)
02077     {
02078         L6470_HardStop();
02079     }
02080 
02081     /**
02082      * @brief  Disabling the power bridge after performing a deceleration to zero.
02083      *         The used deceleration value is the one stored in the "DEC" register.
02084      * @param  None.
02085      * @retval None.
02086      */
02087     virtual void soft_hiz(void)
02088     {
02089         L6470_SoftHiZ();
02090     }
02091 
02092     /**
02093      * @brief  Disabling the power bridge immediately.
02094      * @param  None.
02095      * @retval None.
02096      */
02097     virtual void hard_hiz(void)
02098     {
02099         L6470_HardHiZ();
02100     }
02101 
02102     /**
02103      * @brief  Waiting while the motor is active.
02104      * @param  None.
02105      * @retval None.
02106      */
02107     virtual void wait_while_active(void)
02108     {
02109         while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0);
02110     }
02111 
02112     /**
02113      * @brief   Switching to step-clock mode.
02114      * @param   direction The direction of rotation.
02115      * @retval  None.
02116      * @warning Setting the step-clock mode implies first disabling the power bridge through
02117      *          the soft_hiz() method.
02118      */
02119     virtual void step_clock(direction_t direction)
02120     {
02121         soft_hiz();
02122         L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
02123     }
02124 
02125     /**
02126       * @brief  Doing a motion at minimum speed imposing a specified direction
02127       *         until the SW is released.
02128       * @param  action The identifier of the action about the absolute position.
02129       * @param  direction The direction of rotation.
02130       * @note   The identifier of the action about the absolute position can be
02131       *         one of the following:
02132       *           + L6470_ACT_RST_ID: the absolute position is reset;
02133       *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
02134       */
02135     virtual void release_sw(eL6470_ActId_t action, direction_t direction)
02136     {
02137         L6470_ReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
02138     }
02139 
02140     /**
02141       * @brief  Resetting the device to power-up conditions.
02142       * @param  None.
02143       * @retval None.
02144       */
02145     virtual void reset_device(void)
02146     {
02147         L6470_ResetDevice();
02148     }
02149 
02150     /**
02151      * @brief  Preparing the command to get the status.
02152      * @param  None.
02153      * @retval None.
02154      * @note   The command will be sent by issuing "perform_action()".
02155      */
02156     virtual void prepare_get_status(void)
02157     {
02158         L6470_PrepareGetStatus();
02159         prepared_action = PREPARED_NO_ACTION;
02160     }
02161 
02162     /**
02163      * @brief  Preparing the command to get a parameter.
02164      * @param  parameter A parameter's register address.
02165      * @retval None.
02166      * @note   The command will be sent by issuing "perform_action()".
02167      *         The parameter can be one of the following:
02168      *           + L6470_ABS_POS_ID
02169      *           + L6470_EL_POS_ID
02170      *           + L6470_MARK_ID
02171      *           + L6470_SPEED_ID
02172      *           + L6470_ACC_ID
02173      *           + L6470_DEC_ID
02174      *           + L6470_MAX_SPEED_ID
02175      *           + L6470_MIN_SPEED_ID
02176      *           + L6470_FS_SPD_ID
02177      *           + L6470_KVAL_HOLD_ID
02178      *           + L6470_KVAL_RUN_ID
02179      *           + L6470_KVAL_ACC_ID
02180      *           + L6470_KVAL_DEC_ID
02181      *           + L6470_INT_SPEED_ID
02182      *           + L6470_ST_SLP_ID
02183      *           + L6470_FN_SLP_ACC_ID
02184      *           + L6470_FN_SLP_DEC_ID
02185      *           + L6470_K_THERM_ID
02186      *           + L6470_ADC_OUT_ID
02187      *           + L6470_OCD_TH_ID
02188      *           + L6470_STALL_TH_ID
02189      *           + L6470_STEP_MODE_ID
02190      *           + L6470_ALARM_EN_ID
02191      *           + L6470_CONFIG_ID
02192      *           + L6470_STATUS_ID
02193      */
02194     virtual void prepare_get_parameter(unsigned int parameter)
02195     {
02196         L6470_PrepareGetParam((eL6470_RegId_t) parameter);
02197         prepared_action = PREPARED_NO_ACTION;
02198     }
02199 
02200     /**
02201      * @brief  Preparing the command to get the position.
02202      * @param  None.
02203      * @retval None.
02204      * @note   The command will be sent by issuing "perform_action()".
02205      */
02206     virtual void prepare_get_position(void)
02207     {
02208         L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID);
02209         prepared_action = PREPARED_GET_POSITION;
02210     }
02211 
02212     /**
02213      * @brief  Preparing the command to get the marked position.
02214      * @param  None.
02215      * @retval None.
02216      * @note   The command will be sent by issuing "perform_action()".
02217      */
02218     virtual void prepare_get_mark(void)
02219     {
02220         L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID);
02221         prepared_action = PREPARED_GET_MARK;
02222     }
02223 
02224     /**
02225      * @brief  Preparing the command to get the current speed in pps.
02226      * @param  None.
02227      * @retval None.
02228      * @note   The command will be sent by issuing "perform_action()".
02229      */
02230     virtual void prepare_get_speed(void)
02231     {
02232         L6470_PrepareGetParam((eL6470_RegId_t) L6470_SPEED_ID);
02233         prepared_action = PREPARED_GET_SPEED;
02234     }
02235 
02236     /**
02237      * @brief  Preparing the command to get the maximum speed in pps.
02238      * @param  None.
02239      * @retval None.
02240      * @note   The command will be sent by issuing "perform_action()".
02241      */
02242     virtual void prepare_get_max_speed(void)
02243     {
02244         L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID);
02245         prepared_action = PREPARED_GET_MAX_SPEED;
02246     }
02247 
02248     /**
02249      * @brief  Preparing the command to get the minimum speed in pps.
02250      * @param  None.
02251      * @retval None.
02252      * @note   The command will be sent by issuing "perform_action()".
02253      */
02254     virtual void prepare_get_min_speed(void)
02255     {
02256         L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID);
02257         prepared_action = PREPARED_GET_MIN_SPEED;
02258     }
02259 
02260     /**
02261      * @brief  Preparing the command to get the acceleration in pps^2.
02262      * @param  None.
02263      * @retval None.
02264      * @note   The command will be sent by issuing "perform_action()".
02265      */
02266     virtual void prepare_get_acceleration(void)
02267     {
02268         L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID);
02269         prepared_action = PREPARED_GET_ACCELERATION;
02270     }
02271 
02272     /**
02273      * @brief  Preparing the command to get the deceleration in pps^2.
02274      * @param  None.
02275      * @retval None.
02276      * @note   The command will be sent by issuing "perform_action()".
02277      */
02278     virtual void prepare_get_deceleration(void)
02279     {
02280         L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID);
02281         prepared_action = PREPARED_GET_DECELERATION;
02282     }
02283 
02284     /**
02285      * @brief  Preparing the command to get the direction of rotation.
02286      * @param  None.
02287      * @retval None.
02288      * @note   The command will be sent by issuing "perform_action()".
02289      */
02290     virtual void prepare_get_direction(void)
02291     {
02292         if (!L6470_DaisyChain_HalfPrepared) {
02293             /* To avoid deleting the previous entered command. */
02294             L6470_DaisyChain_HalfPrepared = ONE_F;
02295             /* Resetting commands. */
02296             L6470_ResetAppCmdPkg(L6470_AppCmdPkg);
02297         }
02298         prepared_action = PREPARED_GET_DIRECTION;
02299     }
02300 
02301     /**
02302      * @brief  Preparing the command to set a parameter.
02303      * @param  parameter A parameter's register address.
02304      * @param  value The parameter's value.
02305      * @retval None.
02306      * @note   The command will be sent by issuing "perform_action()".
02307      *         The parameter can be one of the following:
02308      *           + L6470_ABS_POS_ID
02309      *           + L6470_EL_POS_ID
02310      *           + L6470_MARK_ID
02311      *           + L6470_SPEED_ID
02312      *           + L6470_ACC_ID
02313      *           + L6470_DEC_ID
02314      *           + L6470_MAX_SPEED_ID
02315      *           + L6470_MIN_SPEED_ID
02316      *           + L6470_FS_SPD_ID
02317      *           + L6470_KVAL_HOLD_ID
02318      *           + L6470_KVAL_RUN_ID
02319      *           + L6470_KVAL_ACC_ID
02320      *           + L6470_KVAL_DEC_ID
02321      *           + L6470_INT_SPEED_ID
02322      *           + L6470_ST_SLP_ID
02323      *           + L6470_FN_SLP_ACC_ID
02324      *           + L6470_FN_SLP_DEC_ID
02325      *           + L6470_K_THERM_ID
02326      *           + L6470_ADC_OUT_ID
02327      *           + L6470_OCD_TH_ID
02328      *           + L6470_STALL_TH_ID
02329      *           + L6470_STEP_MODE_ID
02330      *           + L6470_ALARM_EN_ID
02331      *           + L6470_CONFIG_ID
02332      *           + L6470_STATUS_ID
02333      * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
02334      *          Any attempt to write one of those registers when the conditions are not satisfied
02335      *          causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
02336      *          last argument byte. Any attempt to set an inexistent register (wrong address value)
02337      *          causes the command to be ignored and the WRONG_CMD flag to rise.
02338      *          For example, setting some parameters requires first to disable the power bridge;
02339      *          this can be done through the soft_hiz() method.
02340      *          They are the following:
02341      *           + L6470_ABS_POS_ID
02342      *           + L6470_EL_POS_ID
02343      *           + L6470_SPEED_ID
02344      *           + L6470_ACC_ID
02345      *           + L6470_DEC_ID
02346      *           + L6470_MAX_SPEED_ID
02347      *           + L6470_MIN_SPEED_ID
02348      *           + L6470_INT_SPEED_ID
02349      *           + L6470_ST_SLP_ID
02350      *           + L6470_FN_SLP_ACC_ID
02351      *           + L6470_FN_SLP_DEC_ID
02352      *           + L6470_ADC_OUT_ID
02353      *           + L6470_STEP_MODE_ID
02354      *           + L6470_CONFIG_ID
02355      *           + L6470_STATUS_ID
02356      */
02357     virtual void prepare_set_parameter(unsigned int parameter, unsigned int value)
02358     {
02359         L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value);
02360         prepared_action = PREPARED_NO_ACTION;
02361     }
02362 
02363     /**
02364      * @brief  Preparing the command to set the current position to be
02365      *         the home position.
02366      * @param  None.
02367      * @retval None.
02368      * @note   The command will be sent by issuing "perform_action()".
02369      */
02370     virtual void prepare_set_home(void)
02371     {
02372         L6470_PrepareResetPos();
02373         prepared_action = PREPARED_NO_ACTION;
02374     }
02375 
02376     /**
02377      * @brief  Preparing the command to set the current position to be
02378      *         the marked position.
02379      * @param  None.
02380      * @retval None.
02381      * @note   The command will be sent by issuing "perform_action()".
02382      */
02383     virtual void prepare_set_mark(void)
02384     {
02385         /*
02386            Set "0" now as marked position. This value will be replaced by the
02387            actual position read at the time when the prepared actions will be
02388            performed.
02389         */
02390         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0);
02391         prepared_action = PREPARED_SET_MARK;
02392     }
02393 
02394     /**
02395      * @brief  Preparing the command to set the given position to be
02396      *         the marked position.
02397      * @param  position The given position.
02398      * @retval None.
02399      * @note   The command will be sent by issuing "perform_action()".
02400      */
02401     virtual void prepare_set_mark(signed int position)
02402     {
02403         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
02404         prepared_action = PREPARED_NO_ACTION;
02405     }
02406 
02407     /**
02408      * @brief  Preparing the command to set the current speed in pps.
02409      * @param  speed The current speed in pps.
02410      * @retval None.
02411      * @note   The command will be sent by issuing "perform_action()".
02412      */
02413     virtual void prepare_set_speed(unsigned int speed)
02414     {
02415         L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed));
02416         prepared_action = PREPARED_NO_ACTION;
02417     }
02418 
02419     /**
02420      * @brief  Preparing the command to set the maximum speed in pps.
02421      * @param  speed The maximum speed in pps.
02422      * @retval None.
02423      * @note   The command will be sent by issuing "perform_action()".
02424      */
02425     virtual void prepare_set_max_speed(unsigned int speed)
02426     {
02427         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
02428         prepared_action = PREPARED_NO_ACTION;
02429     }
02430 
02431     /**
02432      * @brief  Preparing the command to set the minimum speed in pps.
02433      * @param  speed The minimum speed in pps.
02434      * @retval None.
02435      * @note   The command will be sent by issuing "perform_action()".
02436      */
02437     virtual void prepare_set_min_speed(unsigned int speed)
02438     {
02439         L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
02440         prepared_action = PREPARED_NO_ACTION;
02441     }
02442 
02443     /**
02444      * @brief  Preparing the command to set the acceleration in pps^2.
02445      * @param  acceleration The acceleration in pps^2.
02446      * @retval None.
02447      * @note   The command will be sent by issuing "perform_action()".
02448      */
02449     virtual void prepare_set_acceleration(unsigned int acceleration)
02450     {
02451         L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
02452         prepared_action = PREPARED_NO_ACTION;
02453     }
02454 
02455     /**
02456      * @brief  Preparing the command to set the deceleration in pps^2.
02457      * @param  deceleration The deceleration in pps^2.
02458      * @retval None.
02459      * @note   The command will be sent by issuing "perform_action()".
02460      */
02461     virtual void prepare_set_deceleration(unsigned int deceleration)
02462     {
02463         L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
02464         prepared_action = PREPARED_NO_ACTION;
02465     }
02466 
02467     /**
02468      * @brief  Preparing the command to go to a specified position.
02469      * @param  position The desired position.
02470      * @retval None.
02471      * @note   The command will be sent by issuing "perform_action()".
02472      */
02473     virtual void prepare_go_to(signed int position)
02474     {
02475         L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
02476         prepared_action = PREPARED_NO_ACTION;
02477     }
02478 
02479     /**
02480      * @brief  Preparing the command to go to a specified position
02481      *         imposing the desired direction.
02482      * @param  position The desired position.
02483      * @param  direction The direction of rotation.
02484      * @retval None.
02485      * @note   The command will be sent by issuing "perform_action()".
02486      */
02487     virtual void prepare_go_to(signed int position, direction_t direction)
02488     {
02489         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));
02490         prepared_action = PREPARED_NO_ACTION;
02491     }
02492 
02493     /**
02494      * @brief  Preparing the command to go to the home position.
02495      * @param  None.
02496      * @retval None.
02497      * @note   The command will be sent by issuing "perform_action()".
02498      */
02499     virtual void prepare_go_home(void)
02500     {
02501         L6470_PrepareGoHome();
02502         prepared_action = PREPARED_NO_ACTION;
02503     }
02504 
02505     /**
02506      * @brief  Preparing the command to go to the marked position.
02507      * @param  None.
02508      * @retval None.
02509      * @note   The command will be sent by issuing "perform_action()".
02510      */
02511     virtual void prepare_go_mark(void)
02512     {
02513         L6470_PrepareGoMark();
02514         prepared_action = PREPARED_NO_ACTION;
02515     }
02516 
02517     /**
02518      * @brief  Preparing the command to run at the given speed imposing the desired
02519      *         direction until an external switch turn-on event occurs.
02520      * @param  action The identifier of the action about the absolute position.
02521      * @param  position The desired position.
02522      * @param  speed The speed value in pps.
02523      * @retval None.
02524      * @note   The command will be sent by issuing "perform_action()".
02525      *         The identifier of the action about the absolute position can be
02526      *         one of the following:
02527      *           + L6470_ACT_RST_ID: the absolute position is reset;
02528      *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
02529      */
02530     virtual void prepare_go_until(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed)
02531     {
02532         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));
02533         prepared_action = PREPARED_NO_ACTION;
02534     }
02535 
02536     /**
02537      * @brief  Preparing the command to run towards a specified direction
02538      *         at the maximum speed.
02539      * @param  direction The direction of rotation.
02540      * @retval None.
02541      * @note   The command will be sent by issuing "perform_action()".
02542      */
02543     virtual void prepare_run(direction_t direction)
02544     {
02545         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));
02546         prepared_action = PREPARED_NO_ACTION;
02547     }
02548 
02549     /**
02550      * @brief  Preparing the command to run towards a specified direction
02551      *         at the given speed.
02552      * @param  direction The direction of rotation.
02553      * @param  speed The speed value in pps.
02554      * @retval None.
02555      * @note   The command will be sent by issuing "perform_action()".
02556      */
02557     virtual void prepare_run(direction_t direction, unsigned int speed)
02558     {
02559         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));
02560         prepared_action = PREPARED_NO_ACTION;
02561     }
02562 
02563     /**
02564      * @brief  Preparing the command to move towards a specified direction
02565      *         for a certain number of steps.
02566      * @param  direction The direction of rotation.
02567      * @param  steps The desired number of steps.
02568      * @retval None.
02569      * @note   The command will be sent by issuing "perform_action()".
02570      */
02571     virtual void prepare_move(direction_t direction, unsigned int steps)
02572     {
02573         L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
02574         prepared_action = PREPARED_NO_ACTION;
02575     }
02576 
02577     /**
02578      * @brief  Preparing the command to stop the motor.
02579      * @param  None.
02580      * @retval None.
02581      * @note   The command will be sent by issuing "perform_action()".
02582      */
02583     virtual void prepare_soft_stop(void)
02584     {
02585         L6470_PrepareSoftStop();
02586         prepared_action = PREPARED_NO_ACTION;
02587     }
02588 
02589     /**
02590      * @brief  Preparing the command to stop the motor and disabling the power bridge.
02591      * @param  None.
02592      * @retval None.
02593      * @note   The command will be sent by issuing "perform_action()".
02594      */
02595     virtual void prepare_hard_stop(void)
02596     {
02597         L6470_PrepareHardStop();
02598         prepared_action = PREPARED_NO_ACTION;
02599     }
02600 
02601     /**
02602      * @brief  Preparing the command to disable the power bridge after performing
02603      *         a deceleration to zero.
02604      *         The used deceleration value is the one stored in the "DEC" register.
02605      * @param  None.
02606      * @retval None.
02607      * @note   The command will be sent by issuing "perform_action()".
02608      */
02609     virtual void prepare_soft_hiz(void)
02610     {
02611         L6470_PrepareSoftHiZ();
02612         prepared_action = PREPARED_NO_ACTION;
02613     }
02614 
02615     /**
02616      * @brief  Preparing the command to disable the power bridge immediately.
02617      * @param  None.
02618      * @retval None.
02619      * @note   The command will be sent by issuing "perform_action()".
02620      */
02621     virtual void prepare_hard_hiz(void)
02622     {
02623         L6470_PrepareHardHiZ();
02624         prepared_action = PREPARED_NO_ACTION;
02625     }
02626 
02627     /**
02628      * @brief   Preparing the command to switch to step-clock mode.
02629      * @param   direction The direction of rotation.
02630      * @retval  None.
02631      * @warning Setting the step-clock mode requires an explicit action by the user to first
02632      *          disable the power bridge through the soft_hiz() method.
02633      * @note    The command will be sent by issuing "perform_action()".
02634      */
02635     virtual void prepare_step_clock(direction_t direction)
02636     {
02637         L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
02638         prepared_action = PREPARED_NO_ACTION;
02639     }
02640 
02641     /**
02642       * @brief  Preparing the command to do a motion at minimum speed
02643       *         imposing a specified direction until the SW is released.
02644       * @param  action The identifier of the action about the absolute position.
02645       * @param  direction The direction of rotation.
02646       * @retval None.
02647       * @note   The command will be sent by issuing "perform_action()".
02648       *         The identifier of the action about the absolute position can be
02649       *         one of the following:
02650       *           + L6470_ACT_RST_ID: the absolute position is reset;
02651       *           + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
02652       */
02653     virtual void prepare_release_sw(eL6470_ActId_t action, direction_t direction)
02654     {
02655         L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
02656         prepared_action = PREPARED_NO_ACTION;
02657     }
02658 
02659     /**
02660       * @brief  Preparing the command to reset the device to power-up conditions.
02661       * @param  None.
02662       * @retval None.
02663       * @note   The command will be sent by issuing "perform_action()".
02664       */
02665     virtual void prepare_reset_device(void)
02666     {
02667         L6470_PrepareResetDevice();
02668         prepared_action = PREPARED_NO_ACTION;
02669     }
02670 
02671     /**
02672       * @brief    Performing all the actions prepared on the components
02673       *           of the daisy-chain.
02674       * @param    None.
02675       * @retval   The raw data returned by the components.
02676       */
02677     uint8_t* perform_prepared_actions(void)
02678     {
02679         return L6470_PerformPreparedApplicationCommand();
02680     }
02681 
02682     /**
02683       * @brief    Getting the prepared action.
02684       * @param    None
02685       * @retval   The prepared action.
02686       */
02687     prepared_action_t get_prepared_action(void)
02688     {
02689         return prepared_action;
02690     }
02691 
02692     /**
02693       * @brief    Converting the raw data received by the component according to
02694       *           the action performed on it.
02695       * @param    raw_data The received raw data.
02696       * @retval   The result of the action performed.
02697       */
02698     int32_t get_result(uint8_t *raw_data)
02699     {
02700         switch (prepared_action) {
02701             case PREPARED_GET_POSITION:
02702                 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte));
02703 
02704             case PREPARED_GET_MARK:
02705                 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte));
02706 
02707             case PREPARED_GET_SPEED:
02708                 return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte)));
02709     
02710             case PREPARED_GET_MAX_SPEED:
02711                 return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte)));
02712     
02713             case PREPARED_GET_MIN_SPEED:
02714                 return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte)));
02715     
02716             case PREPARED_GET_ACCELERATION:
02717                 return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte)));
02718     
02719             case PREPARED_GET_DECELERATION:
02720                 return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte)));
02721 
02722             case PREPARED_GET_DIRECTION:
02723                 return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
02724 
02725             default:
02726             case PREPARED_NO_ACTION:
02727                 return 0;
02728         }
02729     }
02730 
02731 
02732     /*** Public Interrupt Related Methods ***/
02733 
02734     /* ACTION 6 --------------------------------------------------------------*
02735      * Implement here interrupt related methods, if any.                      *
02736      * Note that interrupt handling is platform dependent, e.g.:              *
02737      *   + mbed:                                                              *
02738      *     InterruptIn feature_irq(pin); //Interrupt object.                  *
02739      *     feature_irq.rise(callback);   //Attach a callback.                 *
02740      *     feature_irq.mode(PullNone);   //Set interrupt mode.                *
02741      *     feature_irq.enable_irq();     //Enable interrupt.                  *
02742      *     feature_irq.disable_irq();    //Disable interrupt.                 *
02743      *   + Arduino:                                                           *
02744      *     attachInterrupt(pin, callback, RISING); //Attach a callback.       *
02745      *     detachInterrupt(pin);                   //Detach a callback.       *
02746      *                                                                        *
02747      * Example (mbed):                                                        *
02748      *   void attach_feature_irq(void (*fptr) (void))                         *
02749      *   {                                                                    *
02750      *     feature_irq.rise(fptr);                                            *
02751      *   }                                                                    *
02752      *                                                                        *
02753      *   void enable_feature_irq(void)                                        *
02754      *   {                                                                    *
02755      *     feature_irq.enable_irq();                                          *
02756      *   }                                                                    *
02757      *                                                                        *
02758      *   void disable_feature_irq(void)                                       *
02759      *   {                                                                    *
02760      *     feature_irq.disable_irq();                                         *
02761      *   }                                                                    *
02762      *------------------------------------------------------------------------*/
02763     /**
02764      * @brief  Attaching an interrupt handler to the FLAG interrupt.
02765      * @param  fptr An interrupt handler.
02766      * @retval None.
02767      */
02768     void attach_flag_irq(void (*fptr)(void))
02769     {
02770         flag_irq.fall(fptr);
02771     }
02772     
02773     /**
02774      * @brief  Enabling the FLAG interrupt handling.
02775      * @param  None.
02776      * @retval None.
02777      */
02778     void enable_flag_irq(void)
02779     {
02780         flag_irq.enable_irq();
02781     }
02782     
02783     /**
02784      * @brief  Disabling the FLAG interrupt handling.
02785      * @param  None.
02786      * @retval None.
02787      */
02788     void disable_flag_irq(void)
02789     {
02790         flag_irq.disable_irq();
02791     }
02792 
02793     /**
02794      * @brief  Attaching an interrupt handler to the BUSY interrupt.
02795      * @param  fptr An interrupt handler.
02796      * @retval None.
02797      */
02798     void attach_busy_irq(void (*fptr)(void))
02799     {
02800         busy_irq.fall(fptr);
02801     }
02802     
02803     /**
02804      * @brief  Enabling the BUSY interrupt handling.
02805      * @param  None.
02806      * @retval None.
02807      */
02808     void enable_busy_irq(void)
02809     {
02810         busy_irq.enable_irq();
02811     }
02812 
02813     /**
02814      * @brief  Disabling the BUSY interrupt handling.
02815      * @param  None.
02816      * @retval None.
02817      */
02818     void disable_busy_irq(void)
02819     {
02820         busy_irq.disable_irq();
02821     }
02822 
02823 
02824 protected:
02825 
02826     /*** Protected Component Related Methods ***/
02827 
02828     /* ACTION 7 --------------------------------------------------------------*
02829      * Declare here the component's specific methods.                         *
02830      * They should be:                                                        *
02831      *   + Methods with the same name of the C component's virtual table's    *
02832      *     functions (1);                                                     *
02833      *   + Methods with the same name of the C component's extended virtual   *
02834      *     table's functions, if any (2);                                     *
02835      *   + Helper methods, if any, like functions declared in the component's *
02836      *     source files but not pointed by the component's virtual table (3). *
02837      *                                                                        *
02838      * Example:                                                               *
02839      *   status_t COMPONENT_get_value(float *f);   //(1)                      *
02840      *   status_t COMPONENT_enable_feature(void);  //(2)                      *
02841      *   status_t COMPONENT_compute_average(void); //(3)                      *
02842      *------------------------------------------------------------------------*/
02843     int32_t  L6470_AbsPos_2_Position(uint32_t AbsPos);
02844     uint32_t L6470_Position_2_AbsPos(int32_t Position);
02845     float    L6470_Speed_2_Step_s(uint32_t Speed);
02846     uint32_t L6470_Step_s_2_Speed(float Step_s);
02847     float    L6470_Acc_2_Step_s2(uint16_t Acc);
02848     uint16_t L6470_Step_s2_2_Acc(float Step_s2);
02849     float    L6470_Dec_2_Step_s2(uint16_t Dec);
02850     uint16_t L6470_Step_s2_2_Dec(float Step_s2);
02851     float    L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed);
02852     uint16_t L6470_Step_s_2_MaxSpeed(float Step_s);
02853     float    L6470_MinSpeed_2_Step_s(uint16_t MinSpeed);
02854     uint16_t L6470_Step_s_2_MinSpeed(float Step_s);
02855     float    L6470_FsSpd_2_Step_s(uint16_t FsSpd);
02856     uint16_t L6470_Step_s_2_FsSpd(float Step_s);
02857     float    L6470_IntSpeed_2_Step_s(uint16_t IntSpeed);
02858     uint16_t L6470_Step_s_2_IntSpeed(float Step_s);
02859     float    L6470_StSlp_2_s_Step(uint8_t StSlp);
02860     uint8_t  L6470_s_Step_2_StSlp(float s_Step);
02861     float    L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc);
02862     uint8_t  L6470_s_Step_2_FnSlpAcc(float s_Step);
02863     float    L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec);
02864     uint8_t  L6470_s_Step_2_FnSlpDec(float s_Step);
02865     float    L6470_OcdTh_2_mA(uint8_t OcdTh);
02866     uint8_t  L6470_mA_2_OcdTh(float mA);
02867     float    L6470_StallTh_2_mA(uint8_t StallTh);
02868     uint8_t  L6470_mA_2_StallTh(float mA);
02869     status_t L6470_Config(void *init);
02870     void     L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
02871     uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId);
02872     void     L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed);
02873     void     L6470_StepClock(eL6470_DirId_t L6470_DirId);
02874     void     L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
02875     void     L6470_GoTo(uint32_t AbsPos);
02876     void     L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
02877     void     L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
02878     void     L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
02879     void     L6470_GoHome(void);
02880     void     L6470_GoMark(void);
02881     void     L6470_ResetPos(void);
02882     void     L6470_ResetDevice(void);
02883     void     L6470_SoftStop(void);
02884     void     L6470_HardStop(void);
02885     void     L6470_SoftHiZ(void);
02886     void     L6470_HardHiZ(void);
02887     uint16_t L6470_GetStatus(void);
02888     void     L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
02889     void     L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId);
02890     void     L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed);
02891     void     L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId);
02892     void     L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
02893     void     L6470_PrepareGoTo(uint32_t AbsPos);
02894     void     L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
02895     void     L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
02896     void     L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
02897     void     L6470_PrepareGoHome(void);
02898     void     L6470_PrepareGoMark(void);
02899     void     L6470_PrepareResetPos(void);
02900     void     L6470_PrepareResetDevice(void);
02901     void     L6470_PrepareSoftStop(void);
02902     void     L6470_PrepareHardStop(void);
02903     void     L6470_PrepareSoftHiZ(void);
02904     void     L6470_PrepareHardHiZ(void);
02905     void     L6470_PrepareGetStatus(void);
02906     uint8_t* L6470_PerformPreparedApplicationCommand(void);
02907     void     L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct);
02908     uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
02909     uint8_t  L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId);
02910     uint8_t* L6470_GetRegisterName(uint8_t id);
02911     void     L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg);
02912     void     L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
02913     void     L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
02914     void     L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct);
02915 
02916     /**
02917      * @brief  Rounding a floating point number to the nearest unsigned integer number.
02918      * @param  f The floating point number.
02919      * @retval The nearest unsigned integer number.
02920      */
02921     int round(float f)
02922     {
02923         if (f >= 0) {
02924             return (int) f + (f - (int) f < 0.5f ? 0 : 1);
02925         } else {
02926             return (int) f - (f - (int) f < -0.5f ? 1 : 0);
02927         }
02928     }
02929 
02930 
02931     /*** Component's I/O Methods ***/
02932 
02933     /**
02934      * @brief      Utility function to read data from L6470.
02935      * @param[out] pBuffer pointer to the buffer to read data into.
02936      * @param[in]  NumBytesToRead number of bytes to read.
02937      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
02938      */
02939     status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
02940     {
02941         if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) {
02942             return COMPONENT_ERROR;
02943         }
02944         return COMPONENT_OK;
02945     }
02946     
02947     /**
02948      * @brief      Utility function to write data to L6470.
02949      * @param[in]  pBuffer pointer to the buffer of data to send.
02950      * @param[in]  NumBytesToWrite number of bytes to write.
02951      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
02952      */
02953     status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite)
02954     {
02955         if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) {
02956             return COMPONENT_ERROR;
02957         }
02958         return COMPONENT_OK;
02959     }
02960 
02961     /**
02962      * @brief      Utility function to read and write data from/to L6470 at the same time.
02963      * @param[out] pBufferToRead pointer to the buffer to read data into.
02964      * @param[in]  pBufferToWrite pointer to the buffer of data to send.
02965      * @param[in]  NumBytes number of bytes to read and write.
02966      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
02967      */
02968     status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
02969     {
02970         if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) {
02971             return COMPONENT_ERROR;
02972         }
02973         return COMPONENT_OK;
02974     }
02975 
02976     /* ACTION 8 --------------------------------------------------------------*
02977      * Implement here other I/O methods beyond those already implemented      *
02978      * above, which are declared extern within the component's header file.   *
02979      *------------------------------------------------------------------------*/
02980     /*
02981      * Puts the device in standby mode.
02982      */
02983     void L6470_ENABLE(void)
02984     {
02985         standby_reset = 1;
02986     }
02987 
02988     /*
02989      * Puts the device in reset mode.
02990      */
02991     void L6470_DISABLE(void)
02992     {
02993         standby_reset = 0;
02994     }
02995 
02996     /*
02997      * Write and read bytes to/from the component through the SPI at the same time.
02998      */
02999     void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
03000     {
03001         ReadWrite(pRxData, pTxData, Size);
03002     }
03003 
03004 
03005     /*** Component's Instance Variables ***/
03006 
03007     /* ACTION 9 --------------------------------------------------------------*
03008      * Declare here interrupt related variables, if needed.                   *
03009      * Note that interrupt handling is platform dependent, see                *
03010      * "Interrupt Related Methods" above.                                     *
03011      *                                                                        *
03012      * Example:                                                               *
03013      *   + mbed:                                                              *
03014      *     InterruptIn feature_irq;                                           *
03015      *------------------------------------------------------------------------*/
03016     /* Flag Interrupt. */
03017     InterruptIn flag_irq;
03018 
03019     /* Busy Interrupt. */
03020     InterruptIn busy_irq;
03021 
03022     /* ACTION 10 -------------------------------------------------------------*
03023      * Declare here other pin related variables, if needed.                   *
03024      *                                                                        *
03025      * Example:                                                               *
03026      *   + mbed:                                                              *
03027      *     DigitalOut standby_reset;                                          *
03028      *------------------------------------------------------------------------*/
03029     /* Standby/reset pin. */
03030     DigitalOut standby_reset;
03031 
03032     /* ACTION 11 -------------------------------------------------------------*
03033      * Declare here communication related variables, if needed.               *
03034      *                                                                        *
03035      * Example:                                                               *
03036      *   + mbed:                                                              *
03037      *     DigitalOut ssel;                                                   *
03038      *     DevSPI &dev_spi;                                                   *
03039      *------------------------------------------------------------------------*/
03040     /* Configuration. */
03041     DigitalOut ssel;
03042 
03043     /* IO Device. */
03044     DevSPI &dev_spi;
03045 
03046     /* ACTION 12 -------------------------------------------------------------*
03047      * Declare here identity related variables, if needed.                    *
03048      * Note that there should be only a unique identifier for each component, *
03049      * which should be the "who_am_i" parameter.                              *
03050      *------------------------------------------------------------------------*/
03051     /* Identity */
03052     uint8_t who_am_i;
03053 
03054     /* ACTION 13 -------------------------------------------------------------*
03055      * Declare here the component's static and non-static data, one variable  *
03056      * per line.                                                              *
03057      *                                                                        *
03058      * Example:                                                               *
03059      *   float measure;                                                       *
03060      *   int instance_id;                                                     *
03061      *   static int number_of_instances;                                      *
03062      *------------------------------------------------------------------------*/
03063     /* Data. */
03064     uint8_t L6470_Id;
03065     const sL6470_Register_t *L6470_Register;
03066     const sL6470_ApplicationCommand_t *L6470_ApplicationCommand;
03067     const sL6470_Direction_t *L6470_Direction;
03068     const sL6470_ACT_t *L6470_ACT;
03069     sL6470_StatusRegister_t L6470_StatusRegister;
03070     sL6470_StatusRegister_t *pL6470_StatusRegister; 
03071     StepperMotorRegister_t StepperMotorRegister;
03072     prepared_action_t prepared_action;
03073 
03074     /* Static data. */
03075     static uint8_t number_of_devices1;
03076     static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE];
03077     static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE];
03078     static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE];
03079     static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE];
03080     static eFlagStatus_t L6470_DaisyChain_HalfPrepared;
03081     static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
03082     static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
03083     static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
03084 };
03085 
03086 #endif /* __L6470_CLASS_H */
03087 
03088 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/