Davide Aliprandi / X_NUCLEO_IHM14A1

Dependencies:   ST_INTERFACES

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers STSPIN820.h Source File

STSPIN820.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    STSPIN820.h
00004   * @author  STM
00005   * @version V1.0.0
00006   * @date    August 7th, 2017
00007   * @brief   STSPIN820 driver (fully integrated microstepping motor driver)
00008   * @note    (C) COPYRIGHT 2017 STMicroelectronics
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */
00038 
00039 
00040 /* Generated with STM32CubeTOO -----------------------------------------------*/
00041 
00042 
00043 /* Revision ------------------------------------------------------------------*/
00044 /*
00045     Repository:       http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
00046     Branch/Trunk/Tag: trunk
00047     Based on:         X-CUBE-SPN14/trunk/Drivers/BSP/Components/STSPIN820/STSPIN820.h
00048     Revision:         0
00049 */
00050 
00051 
00052 /* Define to prevent recursive inclusion -------------------------------------*/
00053 
00054 #ifndef __STSPIN820_CLASS_H
00055 #define __STSPIN820_CLASS_H
00056 
00057 
00058 /* Includes ------------------------------------------------------------------*/
00059 
00060 /* ACTION 1 ------------------------------------------------------------------*
00061  * Include here platform specific header files.                               *
00062  *----------------------------------------------------------------------------*/        
00063 #include "mbed.h"
00064 #include "DevSPI.h"
00065 /* ACTION 2 ------------------------------------------------------------------*
00066  * Include here component specific header files.                              *
00067  *----------------------------------------------------------------------------*/        
00068 #include "STSPIN820_def.h"
00069 /* ACTION 3 ------------------------------------------------------------------*
00070  * Include here interface specific header files.                              *
00071  *                                                                            *
00072  * Example:                                                                   *
00073  *   #include "../Interfaces/Humidity.h"                                *
00074  *   #include "../Interfaces/Temperature.h"                             *
00075  *----------------------------------------------------------------------------*/
00076 #include "../Interfaces/Motor.h"
00077 
00078 
00079 /* Classes -------------------------------------------------------------------*/
00080 
00081 /**
00082  * @brief Class representing a STSPIN820 component.
00083  */
00084 class STSPIN820 : public Motor
00085 {
00086 public:
00087 
00088     /*** Constructor and Destructor Methods ***/
00089 
00090     /**
00091      * @brief Constructor.
00092      * @param ssel pin name of the SSEL pin of the SPI device to be used for communication.
00093      * @param spi  SPI device to be used for communication.
00094      */
00095     STSPIN820(PinName ssel, DevSPI &spi) : Motor(), ssel(ssel), dev_spi(spi)
00096     {
00097         /* ACTION 4 ----------------------------------------------------------*
00098          * Initialize here the component's member variables, one variable per *
00099          * line.                                                              *
00100          *                                                                    *
00101          * Example:                                                           *
00102          *   measure = 0;                                                     *
00103          *   instance_id = number_of_instances++;                             *
00104          *--------------------------------------------------------------------*/
00105         flag_interrupt_callback = 0;
00106         error_handler_callback = 0;
00107         toggle_odd = 0;
00108         device_prm = 0;
00109         number_of_devices = 0;
00110         device_instance = 0;
00111     }
00112     
00113     /**
00114      * @brief Destructor.
00115      */
00116     virtual ~STSPIN820(void) {}
00117     
00118 
00119     /*** Public Component Related Methods ***/
00120 
00121     /* ACTION 5 --------------------------------------------------------------*
00122      * Implement here the component's public methods, as wrappers of the C    *
00123      * component's functions.                                                 *
00124      * They should be:                                                        *
00125      *   + Methods with the same name of the C component's virtual table's    *
00126      *     functions (1);                                                     *
00127      *   + Methods with the same name of the C component's extended virtual   *
00128      *     table's functions, if any (2).                                     *
00129      *                                                                        *
00130      * Example:                                                               *
00131      *   virtual int get_value(float *p_data) //(1)                           *
00132      *   {                                                                    *
00133      *     return COMPONENT_get_value(float *pf_data);                        *
00134      *   }                                                                    *
00135      *                                                                        *
00136      *   virtual int enable_feature(void) //(2)                               *
00137      *   {                                                                    *
00138      *     return COMPONENT_enable_feature();                                 *
00139      *   }                                                                    *
00140      *------------------------------------------------------------------------*/
00141     virtual int init(void *init = NULL)
00142     {
00143         return (int) STSPIN820_Init((void *) init);
00144     }
00145 
00146     virtual int read_id(uint8_t *id = NULL)
00147     {
00148         return (int) STSPIN820_ReadId((uint8_t *) id);
00149     }
00150 
00151     virtual void attach_error_handler(void (*callback)(uint16_t error))
00152     {
00153         STSPIN820_AttachErrorHandler((void (*)(uint16_t error)) callback);
00154     }
00155 
00156     virtual void attach_flag_interrupt(void (*callback)(void))
00157     {
00158         STSPIN820_AttachFlagInterrupt((void (*)(void)) callback);
00159     }
00160 
00161     virtual void flag_interrupt_handler(void)
00162     {
00163         STSPIN820_FlagInterruptHandler();
00164     }
00165 
00166     virtual uint16_t get_acceleration(uint8_t deviceId)
00167     {
00168         return (uint16_t) STSPIN820_GetAcceleration((uint8_t) deviceId);
00169     }
00170 
00171     virtual uint16_t get_current_speed(uint8_t deviceId)
00172     {
00173         return (uint16_t) STSPIN820_GetCurrentSpeed((uint8_t) deviceId);
00174     }
00175 
00176     virtual uint16_t get_deceleration(uint8_t deviceId)
00177     {
00178         return (uint16_t) STSPIN820_GetDeceleration((uint8_t) deviceId);
00179     }
00180 
00181     virtual motor_state_t get_device_state(uint8_t deviceId)
00182     {
00183         return (motor_state_t) STSPIN820_GetDeviceState((uint8_t) deviceId);
00184     }
00185 
00186     virtual uint32_t get_fw_version(void)
00187     {
00188         return (uint32_t) STSPIN820_GetFwVersion();
00189     }
00190 
00191     virtual int32_t get_mark(uint8_t deviceId)
00192     {
00193         return (int32_t) STSPIN820_GetMark((uint8_t) deviceId);
00194     }
00195 
00196     virtual uint16_t get_max_speed(uint8_t deviceId)
00197     {
00198         return (uint16_t) STSPIN820_GetMaxSpeed((uint8_t) deviceId);
00199     }
00200 
00201     virtual uint16_t get_min_speed(uint8_t deviceId)
00202     {
00203         return (uint16_t) STSPIN820_GetMinSpeed((uint8_t) deviceId);
00204     }
00205 
00206     virtual int32_t get_position(uint8_t deviceId)
00207     {
00208         return (int32_t) STSPIN820_GetPosition((uint8_t) deviceId);
00209     }
00210 
00211     virtual void go_home(uint8_t deviceId)
00212     {
00213         STSPIN820_GoHome((uint8_t) deviceId);
00214     }
00215 
00216     virtual void go_mark(uint8_t deviceId)
00217     {
00218         STSPIN820_GoMark((uint8_t) deviceId);
00219     }
00220 
00221     virtual void go_to(uint8_t deviceId, int32_t targetPosition)
00222     {
00223         STSPIN820_GoTo((uint8_t) deviceId, (int32_t) targetPosition);
00224     }
00225 
00226     virtual void hard_stop(uint8_t deviceId)
00227     {
00228         STSPIN820_HardStop((uint8_t) deviceId);
00229     }
00230 
00231     virtual void move(uint8_t deviceId, motor_direction_t direction, uint32_t stepCount)
00232     {
00233         STSPIN820_Move((uint8_t) deviceId, (motor_direction_t) direction, (uint32_t) stepCount);
00234     }
00235 
00236     virtual void run(uint8_t deviceId, motor_direction_t direction)
00237     {
00238         STSPIN820_Run((uint8_t) deviceId, (motor_direction_t) direction);
00239     }
00240 
00241     virtual bool set_acceleration(uint8_t deviceId, uint16_t newAcc)
00242     {
00243         return (bool) STSPIN820_SetAcceleration((uint8_t) deviceId, (uint16_t) newAcc);
00244     }
00245 
00246     virtual bool set_deceleration(uint8_t deviceId, uint16_t newDec)
00247     {
00248         return (bool) STSPIN820_SetDeceleration((uint8_t) deviceId, (uint16_t) newDec);
00249     }
00250 
00251     virtual void set_home(uint8_t deviceId)
00252     {
00253         STSPIN820_SetHome((uint8_t) deviceId);
00254     }
00255 
00256     virtual void set_mark(uint8_t deviceId)
00257     {
00258         STSPIN820_SetMark((uint8_t) deviceId);
00259     }
00260 
00261     virtual bool set_max_speed(uint8_t deviceId, uint16_t newMaxSpeed)
00262     {
00263         return (bool) STSPIN820_SetMaxSpeed((uint8_t) deviceId, (uint16_t) newMaxSpeed);
00264     }
00265 
00266     virtual bool set_min_speed(uint8_t deviceId, uint16_t newMinSpeed)
00267     {
00268         return (bool) STSPIN820_SetMinSpeed((uint8_t) deviceId, (uint16_t) newMinSpeed);
00269     }
00270 
00271     virtual bool soft_stop(uint8_t deviceId)
00272     {
00273         return (bool) STSPIN820_SoftStop((uint8_t) deviceId);
00274     }
00275 
00276     virtual void step_clock_handler(uint8_t deviceId)
00277     {
00278         STSPIN820_StepClockHandler((uint8_t) deviceId);
00279     }
00280 
00281     virtual void wait_while_active(uint8_t deviceId)
00282     {
00283         STSPIN820_WaitWhileActive((uint8_t) deviceId);
00284     }
00285 
00286     virtual void cmd_disable(uint8_t deviceId)
00287     {
00288         STSPIN820_Disable((uint8_t) deviceId);
00289     }
00290 
00291     virtual void cmd_enable(uint8_t deviceId)
00292     {
00293         STSPIN820_Enable((uint8_t) deviceId);
00294     }
00295 
00296     virtual bool select_step_mode(uint8_t deviceId, motor_step_mode_t stepMode)
00297     {
00298         return (bool) STSPIN820_SetStepMode((uint8_t) deviceId, (motor_step_mode_t) stepMode);
00299     }
00300 
00301     virtual void set_direction(uint8_t deviceId, motor_direction_t direction)
00302     {
00303         STSPIN820_SetDirection((uint8_t) deviceId, (motor_direction_t) direction);
00304     }
00305 
00306     virtual void cmd_go_to_dir(uint8_t deviceId, motor_direction_t direction, int32_t targetPosition)
00307     {
00308         STSPIN820_GoToDir((uint8_t) deviceId, (motor_direction_t) direction, (int32_t) targetPosition);
00309     }
00310 
00311     virtual uint8_t check_status_hw(void)
00312     {
00313         return (uint8_t) STSPIN820_CheckStatusHw();
00314     }
00315 
00316     virtual void cmd_reset_device(uint8_t deviceId)
00317     {
00318         STSPIN820_PutDeviceInStandby((uint8_t) deviceId);
00319     }
00320 
00321     virtual uint8_t get_nb_devices(void)
00322     {
00323         return (uint8_t) STSPIN820_GetNbDevices();
00324     }
00325 
00326     virtual void error_handler(uint16_t error)
00327     {
00328         STSPIN820_ErrorHandler((uint16_t) error);
00329     }
00330 
00331     virtual uint32_t get_bridge_input_pwm_freq(uint8_t deviceId)
00332     {
00333         return (uint32_t) STSPIN820_VrefPwmGetFreq((uint8_t) deviceId);
00334     }
00335 
00336     virtual void set_bridge_input_pwm_freq(uint8_t deviceId, uint32_t newFreq)
00337     {
00338         STSPIN820_VrefPwmSetFreq((uint8_t) deviceId, (uint32_t) newFreq);
00339     }
00340 
00341     virtual void set_stop_mode(uint8_t deviceId, motor_stop_mode_t stopMode)
00342     {
00343         STSPIN820_SetStopMode((uint8_t) deviceId, (motor_stop_mode_t) stopMode);
00344     }
00345 
00346     virtual motor_stop_mode_t get_stop_mode(uint8_t deviceId)
00347     {
00348         return (motor_stop_mode_t) STSPIN820_GetStopMode((uint8_t) deviceId);
00349     }
00350 
00351     virtual void set_decay_mode(uint8_t deviceId, motor_decay_mode_t decayMode)
00352     {
00353         STSPIN820_SetDecayMode((uint8_t) deviceId, (motor_decay_mode_t) decayMode);
00354     }
00355 
00356     virtual motor_decay_mode_t get_decay_mode(uint8_t deviceId)
00357     {
00358         return (motor_decay_mode_t) STSPIN820_GetDecayMode((uint8_t) deviceId);
00359     }
00360 
00361     virtual motor_step_mode_t get_step_mode(uint8_t deviceId)
00362     {
00363         return (motor_step_mode_t) STSPIN820_GetStepMode((uint8_t) deviceId);
00364     }
00365 
00366     virtual motor_direction_t get_direction(uint8_t deviceId)
00367     {
00368         return (motor_direction_t) STSPIN820_GetDirection((uint8_t) deviceId);
00369     }
00370 
00371     virtual void exit_device_from_reset(uint8_t deviceId)
00372     {
00373         STSPIN820_ExitDeviceFromStandby((uint8_t) deviceId);
00374     }
00375 
00376     virtual void set_torque(uint8_t deviceId, motor_torque_mode_t torqueMode, uint8_t torqueValue)
00377     {
00378         STSPIN820_SetTorque((uint8_t) deviceId, (motor_torque_mode_t) torqueMode, (uint8_t) torqueValue);
00379     }
00380 
00381     virtual uint8_t get_torque(uint8_t deviceId, motor_torque_mode_t torqueMode)
00382     {
00383         return (uint8_t) STSPIN820_GetTorque((uint8_t) deviceId, (motor_torque_mode_t) torqueMode);
00384     }
00385 
00386     virtual bool set_nb_devices(uint8_t deviceId)
00387     {
00388         return (bool) STSPIN820_SetNbDevices((uint8_t) deviceId);
00389     }
00390 
00391     virtual void set_torque_boost_enable(uint8_t deviceId, bool enable)
00392     {
00393         STSPIN820_SetTorqueBoostEnable((uint8_t) deviceId, (bool) enable);
00394     }
00395 
00396     virtual bool get_torque_boost_enable(uint8_t deviceId)
00397     {
00398         return (bool) STSPIN820_GetTorqueBoostEnable((uint8_t) deviceId);
00399     }
00400 
00401     virtual void set_torque_boost_threshold(uint8_t deviceId, uint16_t speedThreshold)
00402     {
00403         STSPIN820_SetTorqueBoostThreshold((uint8_t) deviceId, (uint16_t) speedThreshold);
00404     }
00405 
00406     virtual uint16_t get_torque_boost_threshold(uint8_t deviceId)
00407     {
00408         return (uint16_t) STSPIN820_GetTorqueBoostThreshold((uint8_t) deviceId);
00409     }
00410 
00411 
00412     /*** Public Interrupt Related Methods ***/
00413 
00414     /* ACTION 6 --------------------------------------------------------------*
00415      * Implement here interrupt related methods, if any.                      *
00416      * Note that interrupt handling is platform dependent, e.g.:              *
00417      *   + mbed:                                                              *
00418      *     InterruptIn feature_irq(pin); //Interrupt object.                  *
00419      *     feature_irq.rise(callback);   //Attach a callback.                 *
00420      *     feature_irq.mode(PullNone);   //Set interrupt mode.                *
00421      *     feature_irq.enable_irq();     //Enable interrupt.                  *
00422      *     feature_irq.disable_irq();    //Disable interrupt.                 *
00423      *   + Arduino:                                                           *
00424      *     attachInterrupt(pin, callback, RISING); //Attach a callback.       *
00425      *     detachInterrupt(pin);                   //Detach a callback.       *
00426      *                                                                        *
00427      * Example (mbed):                                                        *
00428      *   void attach_feature_irq(void (*fptr) (void))                         *
00429      *   {                                                                    *
00430      *     feature_irq.rise(fptr);                                            *
00431      *   }                                                                    *
00432      *                                                                        *
00433      *   void enable_feature_irq(void)                                        *
00434      *   {                                                                    *
00435      *     feature_irq.enable_irq();                                          *
00436      *   }                                                                    *
00437      *                                                                        *
00438      *   void disable_feature_irq(void)                                       *
00439      *   {                                                                    *
00440      *     feature_irq.disable_irq();                                         *
00441      *   }                                                                    *
00442      *------------------------------------------------------------------------*/
00443 
00444 
00445 protected:
00446 
00447     /*** Protected Component Related Methods ***/
00448 
00449     /* ACTION 7 --------------------------------------------------------------*
00450      * Declare here the component's specific methods.                         *
00451      * They should be:                                                        *
00452      *   + Methods with the same name of the C component's virtual table's    *
00453      *     functions (1);                                                     *
00454      *   + Methods with the same name of the C component's extended virtual   *
00455      *     table's functions, if any (2);                                     *
00456      *   + Helper methods, if any, like functions declared in the component's *
00457      *     source files but not pointed by the component's virtual table (3). *
00458      *                                                                        *
00459      * Example:                                                               *
00460      *   status_t COMPONENT_get_value(float *f);   //(1)                      *
00461      *   status_t COMPONENT_enable_feature(void);  //(2)                      *
00462      *   status_t COMPONENT_compute_average(void); //(3)                      *
00463      *------------------------------------------------------------------------*/
00464     void STSPIN820_ApplySpeed(uint8_t pwmId, uint16_t newSpeed);
00465     void STSPIN820_ApplyTorque(uint8_t deviceId, motor_torque_mode_t torqueMode);
00466     void STSPIN820_ComputeSpeedProfile(uint8_t deviceId, uint32_t nbSteps);
00467     void STSPIN820_FlagInterruptHandler(void);
00468     void STSPIN820_SetDeviceParamsOtherValues(void);
00469     void STSPIN820_SetDeviceParamsToGivenValues(STSPIN820_init_t* initDevicePrm);
00470     void STSPIN820_SetDeviceParamsToPredefinedValues(void);
00471     void STSPIN820_StartMovement(uint8_t deviceId);
00472     void STSPIN820_StepClockHandler(uint8_t deviceId);
00473     MOTOR_vt_t* STSPIN820_GetMotorHandle(void);                                    //Return handle of the motor driver handle
00474     void STSPIN820_Init(void* pInit);                                //Start the STSPIN820 library
00475     uint16_t STSPIN820_ReadId(void);                                       //Read Id to get driver instance
00476     void STSPIN820_AttachErrorHandler(void (*callback)(uint16_t));   //Attach a user callback to the error handler
00477     void STSPIN820_AttachFlagInterrupt(void (*callback)(void));      //Attach a user callback to the flag Interrupt
00478     uint8_t STSPIN820_CheckStatusHw(void);                                 //Check if STSPIN820 has a fault by reading EN pin position
00479     void STSPIN820_Disable(uint8_t deviceId);                        //Disable the power stage of the specified device
00480     void STSPIN820_Enable(uint8_t deviceId);                         //Enable the power stage of the specified device
00481     void STSPIN820_ErrorHandler(uint16_t error);                     //Error handler which calls the user callback
00482     void STSPIN820_ExitDeviceFromStandby(uint8_t deviceId);          //Exit STSPIN820 device from standby 
00483     uint16_t STSPIN820_GetAcceleration(uint8_t deviceId);            //Return the acceleration in pps^2
00484     uint16_t STSPIN820_GetCurrentSpeed(uint8_t deviceId);            //Return the current speed in pps
00485     motor_decay_mode_t STSPIN820_GetDecayMode(uint8_t deviceId);     //Return the device decay mode
00486     uint16_t STSPIN820_GetDeceleration(uint8_t deviceId);            //Return the deceleration in pps^2
00487     motor_state_t STSPIN820_GetDeviceState(uint8_t deviceId);        //Return the device state
00488     motor_direction_t STSPIN820_GetDirection(uint8_t deviceId);      //Get the motor current direction
00489     uint32_t STSPIN820_GetFwVersion(void);                                 //Return the FW version
00490     int32_t STSPIN820_GetMark(uint8_t deviceId);                     //Return the mark position 
00491     uint16_t STSPIN820_GetMaxSpeed(uint8_t deviceId);                //Return the max speed in pps
00492     uint16_t STSPIN820_GetMinSpeed(uint8_t deviceId);                //Return the min speed in pps
00493     uint8_t STSPIN820_GetNbDevices(void);                                  //Return the nupber of devices
00494     int32_t STSPIN820_GetPosition(uint8_t deviceId);                 //Return the ABS_POSITION (32b signed)
00495     motor_step_mode_t STSPIN820_GetStepMode(uint8_t deviceId);       //Get the motor step mode
00496     motor_stop_mode_t STSPIN820_GetStopMode(uint8_t deviceId);       //Get the selected mode to stop the motor
00497     uint8_t STSPIN820_GetTorque(uint8_t deviceId, motor_torque_mode_t torqueMode);
00498     bool STSPIN820_GetTorqueBoostEnable(uint8_t deviceId);           //Get the torque boost feature status
00499     uint16_t STSPIN820_GetTorqueBoostThreshold(uint8_t deviceId);    //Get the torque boost threshold
00500     void STSPIN820_GoHome(uint8_t deviceId);                         //Move to the home position
00501     void STSPIN820_GoMark(uint8_t deviceId);                         //Move to the Mark position
00502     void STSPIN820_GoTo(uint8_t deviceId, int32_t targetPosition);   //Go to the specified position
00503     void STSPIN820_GoToDir(uint8_t deviceId, motor_direction_t direction, int32_t targetPosition); //Go to the specified position using the specified direction
00504     void STSPIN820_HardStop(uint8_t deviceId);                       //Stop the motor and keep holding torque
00505     void STSPIN820_HardHiZ(uint8_t deviceId);                        //Stop the motor and disable the power bridge
00506     void STSPIN820_Move(uint8_t deviceId, motor_direction_t direction, uint32_t stepCount); //Move the motor of the specified number of steps
00507     void STSPIN820_PutDeviceInStandby(uint8_t deviceId);              //Put STSPIN820 device in standby (low power consumption)
00508     void STSPIN820_Run(uint8_t deviceId, motor_direction_t direction);       //Run the motor 
00509     bool STSPIN820_SetAcceleration(uint8_t deviceId,uint16_t newAcc); //Set the acceleration in pps^2
00510     bool STSPIN820_SetDeceleration(uint8_t deviceId,uint16_t newDec); //Set the deceleration in pps^2
00511     void STSPIN820_SetDecayMode(uint8_t deviceId, motor_decay_mode_t decay); //Set the STSPIN820 decay mode pin
00512     void STSPIN820_SetDirection(uint8_t deviceId, motor_direction_t direction); //Set the STSPIN820 direction pin
00513     void STSPIN820_SetHome(uint8_t deviceId);                         //Set current position to be the home position
00514     void STSPIN820_SetMark(uint8_t deviceId);                         //Set current position to be the Markposition
00515     bool STSPIN820_SetMaxSpeed(uint8_t deviceId,uint16_t newMaxSpeed);//Set the max speed in pps
00516     bool STSPIN820_SetMinSpeed(uint8_t deviceId,uint16_t newMinSpeed);//Set the min speed in pps
00517     bool STSPIN820_SetNbDevices(uint8_t nbDevices);
00518     bool STSPIN820_SetStepMode(uint8_t deviceId, motor_step_mode_t stepMode); // Step mode selection
00519     void STSPIN820_SetStopMode(uint8_t deviceId, motor_stop_mode_t stopMode); //Select the mode to stop the motor
00520     void STSPIN820_SetTorque(uint8_t deviceId, motor_torque_mode_t torqueMode, uint8_t torqueValue);
00521     void STSPIN820_SetTorqueBoostEnable(uint8_t deviceId, bool enable); // Enable or disable the torque boost feature
00522     void STSPIN820_SetTorqueBoostThreshold(uint8_t deviceId, uint16_t speedThreshold); //Set the torque boost threshold
00523     bool STSPIN820_SoftStop(uint8_t deviceId);                        //Progressively stop the motor by using the device deceleration and set deceleration torque
00524     uint32_t STSPIN820_VrefPwmGetFreq(uint8_t deviceId);              //Get the frequency of REF PWM of the specified device
00525     void STSPIN820_VrefPwmSetFreq(uint8_t deviceId, uint32_t newFreq);//Set the frequency of REF PWM of the specified device
00526     void STSPIN820_WaitWhileActive(uint8_t deviceId);                 //Wait for the device state becomes Inactive
00527 
00528 
00529     /*** Component's I/O Methods ***/
00530 
00531     /**
00532      * @brief      Utility function to read data from STSPIN820.
00533      * @param[out] pBuffer pointer to the buffer to read data into.
00534      * @param[in]  NumBytesToRead number of bytes to read.
00535      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
00536      */
00537     status_t read(uint8_t* pBuffer, uint16_t NumBytesToRead)
00538     {
00539         if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0)
00540             return COMPONENT_ERROR;
00541         return COMPONENT_OK;
00542     }
00543     
00544     /**
00545      * @brief      Utility function to write data to STSPIN820.
00546      * @param[in]  pBuffer pointer to the buffer of data to send.
00547      * @param[in]  NumBytesToWrite number of bytes to write.
00548      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
00549      */
00550     status_t write(uint8_t* pBuffer, uint16_t NumBytesToWrite)
00551     {
00552         if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0)
00553             return COMPONENT_ERROR;
00554         return COMPONENT_OK;
00555     }
00556 
00557     /**
00558      * @brief      Utility function to read and write data from/to STSPIN820 at the same time.
00559      * @param[out] pBufferToRead pointer to the buffer to read data into.
00560      * @param[in]  pBufferToWrite pointer to the buffer of data to send.
00561      * @param[in]  NumBytes number of bytes to read and write.
00562      * @retval     COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
00563      */
00564     status_t read_write(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
00565     {
00566         if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0)
00567             return COMPONENT_ERROR;
00568         return COMPONENT_OK;
00569     }
00570 
00571     /* ACTION 8 --------------------------------------------------------------*
00572      * Implement here other I/O methods beyond those already implemented      *
00573      * above, which are declared extern within the component's header file.   *
00574      *------------------------------------------------------------------------*/
00575     void STSPIN820_Board_Delay(uint32_t delay)
00576     {
00577         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00578     }
00579 
00580     void STSPIN820_Board_Disable(void)
00581     {
00582         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00583     }
00584 
00585     void STSPIN820_Board_DisableIrq(void)
00586     {
00587         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00588     }
00589 
00590     uint32_t STSPIN820_Board_EN_AND_FAULT_PIN_GetState(void)
00591     {
00592         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00593         return (uint32_t) 0;
00594     }
00595 
00596     void STSPIN820_Board_Enable(void)
00597     {
00598         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00599     }
00600 
00601     void STSPIN820_Board_EnableIrq(void)
00602     {
00603         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00604     }
00605 
00606     void STSPIN820_Board_GpioInit(void)
00607     {
00608         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00609     }
00610 
00611     void STSPIN820_Board_PwmRefInit(void)
00612     {
00613         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00614     }
00615 
00616     void STSPIN820_Board_PwmRefSetFreqAndDutyCycle(uint32_t newFreq, uint8_t dutyCycle)
00617     {
00618         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00619     }
00620 
00621     void STSPIN820_Board_PwmRefStart(void)
00622     {
00623         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00624     }
00625 
00626     void STSPIN820_Board_PwmRefStop(void)
00627     {
00628         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00629     }
00630 
00631     void STSPIN820_Board_ReleaseReset(void)
00632     {
00633         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00634     }
00635 
00636     void STSPIN820_Board_Reset(void)
00637     {
00638         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00639     }
00640 
00641     void STSPIN820_Board_SetDecayGpio(uint8_t gpioState)
00642     {
00643         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00644     }
00645 
00646     uint8_t STSPIN820_Board_GetDecayGpio(void)
00647     {
00648         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00649         return (uint8_t) 0;
00650     }
00651 
00652     void STSPIN820_Board_SetDirectionGpio(uint8_t gpioState)
00653     {
00654         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00655     }
00656 
00657     void STSPIN820_Board_SetFullStep(void)
00658     {
00659         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00660     }
00661 
00662     bool STSPIN820_Board_SetModePins(uint8_t modePin1Level, uint8_t modePin2Level, uint8_t modePin3Level)
00663     {
00664         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00665         return (bool) 0;
00666     }
00667 
00668     void STSPIN820_Board_TimStckCompareInit(void)
00669     {
00670         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00671     }
00672 
00673     void STSPIN820_Board_TimStckDeInit(void)
00674     {
00675         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00676     }
00677 
00678     void STSPIN820_Board_TimStckInit(void)
00679     {
00680         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00681     }
00682 
00683     void STSPIN820_Board_TimStckSetFreq(uint16_t newFreq)
00684     {
00685         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00686     }
00687 
00688     void STSPIN820_Board_TimStckStart(void)
00689     {
00690         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00691     }
00692 
00693     uint8_t STSPIN820_Board_TimStckStop(uint8_t *pToggleOdd)
00694     {
00695         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00696         return (uint8_t) 0;
00697     }
00698 
00699     void STSPIN820_Board_UnsetFullStep(void)
00700     {
00701         /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
00702     }
00703 
00704 
00705     /*** Component's Instance Variables ***/
00706 
00707     /* ACTION 9 --------------------------------------------------------------*
00708      * Declare here interrupt related variables, if needed.                   *
00709      * Note that interrupt handling is platform dependent, see                *
00710      * "Interrupt Related Methods" above.                                     *
00711      *                                                                        *
00712      * Example:                                                               *
00713      *   + mbed:                                                              *
00714      *     InterruptIn feature_irq;                                           *
00715      *------------------------------------------------------------------------*/
00716 
00717     /* ACTION 10 -------------------------------------------------------------*
00718      * Declare here other pin related variables, if needed.                   *
00719      *                                                                        *
00720      * Example:                                                               *
00721      *   + mbed:                                                              *
00722      *     DigitalOut standby_reset;                                          *
00723      *------------------------------------------------------------------------*/
00724 
00725     /* ACTION 11 -------------------------------------------------------------*
00726      * Declare here communication related variables, if needed.               *
00727      *                                                                        *
00728      * Example:                                                               *
00729      *   + mbed:                                                              *
00730      *     DigitalOut ssel;                                                   *
00731      *     DevSPI &dev_spi;                                                   *
00732      *------------------------------------------------------------------------*/
00733     /* Configuration. */
00734     DigitalOut ssel;
00735 
00736     /* IO Device. */
00737     DevSPI &dev_spi;
00738 
00739     /* ACTION 12 -------------------------------------------------------------*
00740      * Declare here identity related variables, if needed.                    *
00741      * Note that there should be only a unique identifier for each component, *
00742      * which should be the "who_am_i" parameter.                              *
00743      *------------------------------------------------------------------------*/
00744     /* Identity */
00745     uint8_t who_am_i;
00746 
00747     /* ACTION 13 -------------------------------------------------------------*
00748      * Declare here the component's static and non-static data, one variable  *
00749      * per line.                                                              *
00750      *                                                                        *
00751      * Example:                                                               *
00752      *   float measure;                                                       *
00753      *   int instance_id;                                                     *
00754      *   static int number_of_instances;                                      *
00755      *------------------------------------------------------------------------*/
00756     void (*flag_interrupt_callback)(void);
00757     void (*error_handler_callback)(uint16_t error);
00758     uint8_t toggle_odd;
00759     device_params_t device_prm;
00760     uint8_t number_of_devices;
00761     uint8_t device_instance;
00762 };
00763 
00764 #endif /* __STSPIN820_CLASS_H */
00765 
00766 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/