Added ST_INTERFACES library.

Dependencies:   ST_INTERFACES

Fork of X-NUCLEO-IHM05A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers l6208_class.h Source File

l6208_class.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    l6208_class.h
00004  * @author  IPC Rennes
00005  * @version V1.0.0
00006  * @date    March 18th, 2016
00007  * @brief   This file contains the class of a L6208 Motor Control component.
00008  * @note    (C) COPYRIGHT 2016 STMicroelectronics
00009  ******************************************************************************
00010  * @attention
00011  *
00012  * <h2><center>&copy; COPYRIGHT(c) 2016 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 /* Define to prevent recursive inclusion -------------------------------------*/
00041 
00042 #ifndef __L6208_CLASS_H
00043 #define __L6208_CLASS_H
00044 
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 
00048 /* ACTION 1 ------------------------------------------------------------------*
00049  * Include here platform specific header files.                               *
00050  *----------------------------------------------------------------------------*/        
00051 #include "mbed.h"
00052 
00053 /* ACTION 2 ------------------------------------------------------------------*
00054  * Include here component specific header files.                              *
00055  *----------------------------------------------------------------------------*/        
00056 #include "l6208.h"
00057 /* ACTION 3 ------------------------------------------------------------------*
00058  * Include here interface specific header files.                              *
00059  *                                                                            *
00060  * Example:                                                                   *
00061  *   #include "Humidity_class.h"                                              *
00062  *   #include "Temperature_class.h"                                           *
00063  *----------------------------------------------------------------------------*/
00064 #include "StepperMotor.h"
00065 
00066 
00067 /* Classes -------------------------------------------------------------------*/
00068 
00069 /**
00070  * @brief Class representing a L6208 component.
00071  */
00072 class L6208 : public StepperMotor
00073 {
00074 public:
00075     /*** Constructor and Destructor Methods ***/
00076 
00077     /**
00078      * @brief Constructor.
00079      * @param flag_and_enable_pin   pin name of the EN pin of the component.
00080      * @param reset_pin             pin name of the RESET pin of the component.
00081      * @param direction_pin         pin name of the CW_CCW pin of the component.
00082      * @param half_full_pin         pin name of the HALF_FULL pin of the component.
00083      * @param control_pin           pin name of the CONTROL pin of the component.
00084      * @param clock_pin             pin name of the CLOCK pin of the component.
00085      * @param vrefA_pwm_pin         pin name of the PWM connected to the VREFA pin of the component.
00086      * @param vrefB_pwm_pin         pin name of the PWM connected to the VREFB pin of the component.
00087      */
00088     L6208(PinName flag_and_enable_pin, PinName reset_pin, PinName direction_pin, PinName half_full_pin, PinName control_pin, PinName clock_pin, PinName vrefA_pwm_pin, PinName vrefB_pwm_pin) : StepperMotor(),
00089                                                                                                                                                          flag_and_enable(flag_and_enable_pin),
00090                                                                                                                                                          reset(reset_pin),
00091                                                                                                                                                          direction(direction_pin),
00092                                                                                                                                                          half_full(half_full_pin),
00093                                                                                                                                                          control(control_pin),
00094                                                                                                                                                          clock(clock_pin),
00095                                                                                                                                                          vrefA_pwm(vrefA_pwm_pin),
00096                                                                                                                                                          vrefB_pwm(vrefB_pwm_pin)
00097     {
00098         /* Checking stackability. */
00099         if (numberOfDevices!=0)
00100             error("Instantiation of the L6208 component failed: it can't be stacked on itself.\r\n");
00101 
00102         /* ACTION 4 ----------------------------------------------------------*
00103          * Initialize here the component's member variables, one variable per *
00104          * line.                                                              *
00105          *                                                                    *
00106          * Example:                                                           *
00107          *   measure = 0;                                                     *
00108          *   instance_id = number_of_instances++;                             *
00109          *--------------------------------------------------------------------*/
00110         errorHandlerCallback = 0;
00111         deviceInstance = numberOfDevices++;
00112         /* default tick frequency */
00113         tickFreq = TIMER_TICK_FREQUENCY;
00114         /* waveform microstepping PWM period sample array, 90 deg shifted */
00115         pMicroTable2 = &(microTable1[16]);
00116     }
00117     
00118     /**
00119      * @brief Destructor.
00120      */
00121     virtual ~L6208(void) {}
00122     
00123 
00124     /*** Public Component Related Methods ***/
00125 
00126     /* ACTION 5 --------------------------------------------------------------*
00127      * Implement here the component's public methods, as wrappers of the C    *
00128      * component's functions.                                                 *
00129      * They should be:                                                        *
00130      *   + Methods with the same name of the C component's virtual table's    *
00131      *     functions (1);                                                     *
00132      *   + Methods with the same name of the C component's extended virtual   *
00133      *     table's functions, if any (2).                                     *
00134      *                                                                        *
00135      * Example:                                                               *
00136      *   virtual int GetValue(float *pData) //(1)                             *
00137      *   {                                                                    *
00138      *     return COMPONENT_GetValue(float *pfData);                          *
00139      *   }                                                                    *
00140      *                                                                        *
00141      *   virtual int EnableFeature(void) //(2)                                *
00142      *   {                                                                    *
00143      *     return COMPONENT_EnableFeature();                                  *
00144      *   }                                                                    *
00145      *------------------------------------------------------------------------*/
00146 
00147     /**
00148      * @brief Public functions inherited from the Component Class
00149      */
00150 
00151     /**
00152      * @brief  Initialize the component.
00153      * @param  init Pointer to device specific initalization structure.
00154      * @retval "0" in case of success, an error code otherwise.
00155      */
00156     virtual int Init(void *init = NULL)
00157     {
00158         return (int) L6208_Init((void *) init);
00159     }
00160 
00161     /**
00162      * @brief  Getting the ID of the component.
00163      * @param  id Pointer to an allocated variable to store the ID into.
00164      * @retval "0" in case of success, an error code otherwise.
00165      */
00166     virtual int ReadID(uint8_t *id = NULL)
00167     {
00168         return (int) L6208_ReadID((uint8_t *) id);
00169     }
00170 
00171     /**
00172      * @brief Public functions inherited from the StepperMotor Class
00173      */
00174 
00175     /**
00176      * @brief  Getting the value of the motor state .
00177      * @param  None.
00178      * @retval The motor state accoring to motorState_t in motor.h
00179      */
00180     virtual unsigned int GetStatus(void)
00181     {
00182         return (unsigned int) L6208_GetMotionState();
00183     }
00184 
00185     /**
00186      * @brief  Getting the position.
00187      * @param  None.
00188      * @retval The position.
00189      */
00190     virtual signed int GetPosition(void)
00191     {
00192         return (signed int)L6208_GetPosition();
00193     }
00194 
00195     /**
00196      * @brief  Getting the marked position.
00197      * @param  None.
00198      * @retval The marked position.
00199      */
00200     virtual signed int GetMark(void)
00201     {
00202         return (signed int)L6208_GetMark();
00203     }
00204 
00205     /**
00206      * @brief  Getting the current speed in pps.
00207      * @param  None.
00208      * @retval The current speed in pps.
00209      */
00210     virtual unsigned int GetSpeed(void)
00211     {
00212         return (unsigned int)L6208_GetCurrentSpeed();
00213     }
00214 
00215     /**
00216      * @brief  Getting the maximum speed in pps.
00217      * @param  None.
00218      * @retval The maximum speed in pps.
00219      */
00220     virtual unsigned int GetMaxSpeed(void)
00221     {
00222         return (unsigned int)L6208_GetMaxSpeed();
00223     }
00224 
00225     /**
00226      * @brief  Getting the minimum speed in pps.
00227      * @param  None.
00228      * @retval The minimum speed in pps.
00229      */
00230     virtual unsigned int GetMinSpeed(void)
00231     {
00232         return (unsigned int)L6208_GetMinSpeed();
00233     }
00234 
00235     /**
00236      * @brief  Getting the acceleration in pps^2.
00237      * @param  None.
00238      * @retval The acceleration in pps^2.
00239      */
00240     virtual unsigned int GetAcceleration(void)
00241     {
00242         return (unsigned int)L6208_GetAcceleration();
00243     }
00244 
00245     /**
00246      * @brief  Getting the deceleration in pps^2.
00247      * @param  None.
00248      * @retval The deceleration in pps^2.
00249      */
00250     virtual unsigned int GetDeceleration(void)
00251     {
00252         return (unsigned int)L6208_GetDeceleration();
00253     }
00254     
00255     /**
00256      * @brief  Getting the direction of rotation.
00257      * @param  None.
00258      * @retval The direction of rotation.
00259      */
00260     virtual direction_t GetDirection(void)
00261     {
00262         if (L6208_GetDirection()!=BACKWARD)
00263         {
00264             return FWD;
00265         }
00266         else
00267         {
00268             return BWD;
00269         }
00270     }
00271     
00272     /**
00273      * @brief  Setting the current position to be the home position.
00274      * @param  None.
00275      * @retval None.
00276      */
00277     virtual void SetHome(void)
00278     {
00279         L6208_SetHome();
00280     }
00281 
00282     /**
00283      * @brief  Setting the current position to be the marked position.
00284      * @param  None.
00285      * @retval None.
00286      */
00287     virtual void SetMark(void)
00288     {
00289         L6208_SetMark();
00290     }
00291 
00292     /**
00293      * @brief  Setting the maximum speed in pps.
00294      * @param  speed The maximum speed in pps.
00295      * @retval "true" in case of success, "false" otherwise.
00296      */
00297     virtual bool SetMaxSpeed(unsigned int speed)
00298     {
00299         if (speed <= 0xFFFF)
00300         {
00301             return L6208_SetMaxSpeed((uint16_t) speed);
00302         }
00303         else
00304         {
00305             return false;
00306         }
00307     }
00308 
00309     /**
00310      * @brief  Setting the minimum speed in pps.
00311      * @param  speed The minimum speed in pps.
00312      * @retval "true" in case of success, "false" otherwise.
00313      */
00314     virtual bool SetMinSpeed(unsigned int speed)
00315     {
00316         if (speed <= 0xFFFF)
00317         {
00318             return L6208_SetMinSpeed((uint16_t) speed);
00319         }
00320         else
00321         {
00322             return false;
00323         }
00324     }
00325 
00326     /**
00327      * @brief  Setting the acceleration in pps^2.
00328      * @param  acceleration The acceleration in pps/s^2.
00329      * @retval "true" in case of success, "false" otherwise.
00330      */
00331     virtual bool SetAcceleration(unsigned int acceleration)
00332     {
00333         if (acceleration <= 0xFFFF)
00334         {
00335             return L6208_SetAcceleration((uint16_t) acceleration);
00336         }
00337         else
00338         {
00339             return false;
00340         }
00341     }
00342 
00343     /**
00344      * @brief  Setting the deceleration in pps^2.
00345      * @param  deceleration The deceleration in pps^2.
00346      * @retval "true" in case of success, "false" otherwise.
00347      */
00348     virtual bool SetDeceleration(unsigned int deceleration)
00349     {
00350         if (deceleration <= 0xFFFF)
00351         {
00352             return L6208_SetDeceleration((uint16_t) deceleration);
00353         }
00354         else
00355         {
00356             return false;
00357         }
00358     }
00359 
00360     /**
00361      * @brief  Setting the Step Mode.
00362      * @param  step_mode The Step Mode.
00363      * @retval "true" in case of success, "false" otherwise.
00364      * @note   step_mode can be one of the following:
00365      *           + STEP_MODE_FULL
00366      *           + STEP_MODE_WAVE
00367      *           + STEP_MODE_HALF
00368      *           + STEP_MODE_1_4
00369      *           + STEP_MODE_1_8
00370      *           + STEP_MODE_1_16
00371      */
00372     virtual bool SetStepMode(step_mode_t step_mode)
00373     {
00374         return L6208_SetStepMode((motorStepMode_t) step_mode);
00375     }
00376 
00377     /**
00378      * @brief  Going to a specified position.
00379      * @param  position The desired position.
00380      * @retval None.
00381      */
00382     virtual void GoTo(signed int position)
00383     {
00384         L6208_GoTo((int32_t)position);
00385     }
00386 
00387     /**
00388      * @brief  Going to the home position.
00389      * @param  None.
00390      * @retval None.
00391      */
00392     virtual void GoHome(void)
00393     {
00394         L6208_GoHome();
00395     }
00396 
00397     /**
00398      * @brief  Going to the marked position.
00399      * @param  None.
00400      * @retval None.
00401      */
00402     virtual void GoMark(void)
00403     {
00404         L6208_GoMark();
00405     }
00406 
00407     /**
00408      * @brief  Running the motor towards a specified direction.
00409      * @param  direction The direction of rotation.
00410      * @retval None.
00411      */
00412     virtual void Run(direction_t direction)
00413     {
00414         L6208_Run((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD));
00415     }
00416 
00417     /**
00418      * @brief  Moving the motor towards a specified direction for a certain number of steps.
00419      * @param  direction The direction of rotation.
00420      * @param  steps The desired number of steps.
00421      * @retval None.
00422      */
00423     virtual void Move(direction_t direction, unsigned int steps)
00424     {
00425         L6208_Move((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD), (uint32_t)steps);
00426     }
00427 
00428     /**
00429      * @brief  Stopping the motor through an immediate deceleration up to zero speed.
00430      * @param  None.
00431      * @retval None.
00432      */
00433     virtual void SoftStop(void)
00434     {
00435         L6208_SoftStop();
00436     }
00437 
00438     /**
00439      * @brief  Stopping the motor through an immediate infinite deceleration.
00440      * @param  None.
00441      * @retval None.
00442      */
00443     virtual void HardStop(void)
00444     {
00445         L6208_HardStop();
00446     }
00447 
00448     /**
00449      * @brief  Disabling the power bridge after performing a deceleration to zero.
00450      * @param  None.
00451      * @retval None.
00452      */
00453     virtual void SoftHiZ(void)
00454     {
00455         motorStopMode_t stopMode = L6208_GetStopMode();
00456         if (stopMode==HIZ_MODE)
00457         {
00458             L6208_SoftStop();
00459         }
00460         else
00461         {
00462             L6208_SetStopMode(HIZ_MODE);
00463             L6208_SoftStop();
00464             L6208_SetStopMode(stopMode);
00465         }
00466     }
00467 
00468     /**
00469      * @brief  Disabling the power bridge immediately.
00470      * @param  None.
00471      * @retval None.
00472      */
00473     virtual void HardHiZ(void)
00474     {
00475         L6208_HardHiZ();
00476     }
00477 
00478     /**
00479      * @brief  Waiting while the motor is active.
00480      * @param  None.
00481      * @retval None.
00482      */
00483     virtual void WaitWhileActive(void)
00484     {
00485         L6208_WaitWhileActive();
00486     }  
00487 
00488     /**
00489      * @brief Public functions NOT inherited
00490      */
00491      
00492     /**
00493      * @brief  Attaching an error handler.
00494      * @param  fptr An error handler.
00495      * @retval None.
00496      */
00497     virtual void AttachErrorHandler(void (*fptr)(uint16_t error))
00498     {
00499         L6208_AttachErrorHandler((void (*)(uint16_t error)) fptr);
00500     }
00501 
00502     /**
00503      * @brief  Checks if the device is disabled or/and has an alarm flag set 
00504      * by reading the EN pin position.
00505      * @param  None.
00506      * @retval One if the EN pin is low (the device is disabled or/and 
00507      * has an alarm flag set), otherwise zero.
00508      */
00509     virtual unsigned int CheckStatusHw(void)
00510     {
00511         if (!flag_and_enable.read()) return 0x01;
00512         else return 0x00;
00513     }
00514     
00515     /**
00516      * @brief  Disabling the device.
00517      * @param  None.
00518      * @retval None.
00519      */
00520     virtual void Disable(void)
00521     {
00522         L6208_Disable();
00523     }
00524     
00525     /**
00526      * @brief  Enabling the device.
00527      * @param  None.
00528      * @retval None.
00529      */
00530     virtual void Enable(void)
00531     {
00532         L6208_Enable();
00533     }
00534     
00535     /**
00536      * @brief  Getting the motor decay mode.
00537      * @param  None.
00538      * @retval The motor decay mode.
00539      */
00540     virtual motorDecayMode_t GetDecayMode()
00541     {
00542          return L6208_GetDecayMode();
00543     }
00544     
00545     /**
00546      * @brief  Set the frequency of the VREFA and VREFB PWM
00547      * @param  frequency in Hz
00548      * @retval None.
00549      */  
00550     virtual uint32_t GetFreqVrefPwm(void)
00551     {
00552         return L6208_VrefPwmGetFreq();
00553     }    
00554     
00555     /**
00556      * @brief  Getting the version of the firmware.
00557      * @param  None.
00558      * @retval The version of the firmware.
00559      */
00560     virtual unsigned int GetFwVersion(void)
00561     {
00562         return (unsigned int) L6208_GetFwVersion();
00563     }
00564     
00565     /**
00566      * @brief  Getting the motor step mode.
00567      * @param  None.
00568      * @retval The motor step mode.
00569      */
00570     virtual step_mode_t GetStepMode(void)
00571     {
00572       return (step_mode_t) L6208_GetStepMode();
00573     }
00574     
00575     /**
00576      * @brief  Getting the motor stop mode.
00577      * @param  None.
00578      * @retval The motor stop mode.
00579      */  
00580     virtual motorStopMode_t GetStopMode(void)
00581     {
00582       return L6208_GetStopMode();
00583     }
00584     
00585     /**
00586      * @brief  Going to a specified position with a specificied direction.
00587      * @param  direction The desired direction.
00588      * @param  position The desired position.
00589      * @retval None.
00590      */
00591     virtual void GoTo(direction_t direction, signed int position)
00592     {
00593         L6208_GoToDir((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD),(int32_t)position);
00594     }
00595 
00596     /**
00597      * @brief  Release the L6208 reset (Reset pin set to high level).
00598      * @param  None.
00599      * @retval None.
00600      */    
00601     virtual void ReleaseReset(void)
00602     {
00603         L6208_ReleaseReset();
00604     }
00605 
00606     /**
00607      * @brief  Reset the device with current step mode, resets current speed,
00608      * positions and microstep variables.
00609      * @param  None.
00610      * @retval None.
00611      */    
00612     virtual void Reset(void)
00613     {
00614         L6208_Reset();
00615     }
00616     
00617     /**
00618      * @brief  Reset the L6208 (Reset pin set to low level).
00619      * @param  None.
00620      * @retval None.
00621      */    
00622     virtual void ResetDevice(void)
00623     {
00624         L6208_ResetDevice();
00625     }
00626    
00627     /**
00628      * @brief  Set the motor decay mode.
00629      * @param  decayMode The desired decay mode (SLOW_DECAY or FAST_DECAY).
00630      * @retval None.
00631      */    
00632     virtual void SetDecayMode(motorDecayMode_t decayMode)
00633     {
00634         L6208_SetDecayMode(decayMode);
00635     }
00636 
00637     /**
00638      * @brief  Set the motor direction.
00639      * @param  direction The desired direction.
00640      * @retval None.
00641      */
00642     virtual void SetDirection(direction_t direction)
00643     { 
00644         L6208_SetDirection((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD));
00645     }
00646 
00647     /**
00648      * @brief  Set the frequency of the VREFA and VREFB PWM
00649      * @param  frequency in Hz
00650      * @retval None.
00651      */  
00652     virtual void SetFreqVrefPwm(uint32_t frequency)
00653     {
00654         L6208_VrefPwmSetFreq(frequency);
00655     }
00656 
00657     /**
00658      * @brief  Set the motor stop mode.
00659      * @param  stopMode The desired stop mode (HOLD_MODE or HIZ_MODE).
00660      * @retval None.
00661      */       
00662     virtual void SetStopMode(motorStopMode_t stopMode)
00663     {
00664         L6208_SetStopMode(stopMode);
00665     }
00666    
00667     /*** Public Interrupt Related Methods ***/
00668 
00669     /* ACTION 6 --------------------------------------------------------------*
00670      * Implement here interrupt related methods, if any.                      *
00671      * Note that interrupt handling is platform dependent, e.g.:              *
00672      *   + mbed:                                                              *
00673      *     InterruptIn feature_irq(pin); //Interrupt object.                  *
00674      *     feature_irq.rise(callback);   //Attach a callback.                 *
00675      *     feature_irq.mode(PullNone);   //Set interrupt mode.                *
00676      *     feature_irq.enable_irq();     //Enable interrupt.                  *
00677      *     feature_irq.disable_irq();    //Disable interrupt.                 *
00678      *   + Arduino:                                                           *
00679      *     attachInterrupt(pin, callback, RISING); //Attach a callback.       *
00680      *     detachInterrupt(pin);                   //Detach a callback.       *
00681      *                                                                        *
00682      * Example (mbed):                                                        *
00683      *   void AttachFeatureIRQ(void (*fptr) (void))                           *
00684      *   {                                                                    *
00685      *     feature_irq.rise(fptr);                                            *
00686      *   }                                                                    *
00687      *                                                                        *
00688      *   void EnableFeatureIRQ(void)                                          *
00689      *   {                                                                    *
00690      *     feature_irq.enable_irq();                                          *
00691      *   }                                                                    *
00692      *                                                                        *
00693      *   void DisableFeatureIRQ(void)                                         *
00694      *   {                                                                    *
00695      *     feature_irq.disable_irq();                                         *
00696      *   }                                                                    *
00697      *------------------------------------------------------------------------*/
00698     /**
00699      * @brief  Attaching an interrupt handler to the FLAG interrupt.
00700      * @param  fptr An interrupt handler.
00701      * @retval None.
00702      */
00703      
00704     void AttachFlagIRQ(void (*fptr)(void))
00705     {
00706         flag_and_enable.mode(PullDown);
00707         flag_and_enable.fall(fptr);
00708     }
00709     
00710     /**
00711      * @brief  Enabling the FLAG interrupt handling.
00712      * @param  None.
00713      * @retval None.
00714      */
00715     void EnableFlagIRQ(void)
00716     {
00717         flag_and_enable.enable_irq();
00718     }
00719     
00720 protected:
00721 
00722     /*** Protected Component Related Methods ***/
00723 
00724     /* ACTION 7 --------------------------------------------------------------*
00725      * Declare here the component's specific methods.                         *
00726      * They should be:                                                        *
00727      *   + Methods with the same name of the C component's virtual table's    *
00728      *     functions (1);                                                     *
00729      *   + Methods with the same name of the C component's extended virtual   *
00730      *     table's functions, if any (2);                                     *
00731      *   + Helper methods, if any, like functions declared in the component's *
00732      *     source files but not pointed by the component's virtual table (3). *
00733      *                                                                        *
00734      * Example:                                                               *
00735      *   Status_t COMPONENT_GetValue(float *f);   //(1)                       *
00736      *   Status_t COMPONENT_EnableFeature(void);  //(2)                       *
00737      *   Status_t COMPONENT_ComputeAverage(void); //(3)                       *
00738      *------------------------------------------------------------------------*/
00739     Status_t L6208_Init(void *init);
00740     Status_t L6208_ReadID(uint8_t *id);
00741     void L6208_AttachErrorHandler(void (*callback)(uint16_t error));
00742     void L6208_Disable(void);
00743     void L6208_ErrorHandler(uint16_t error);
00744     void L6208_Enable(void);
00745     uint16_t L6208_GetAcceleration(void);
00746     uint16_t L6208_GetCurrentSpeed(void);
00747     uint16_t L6208_GetDeceleration(void);
00748     motorDecayMode_t L6208_GetDecayMode(void);
00749     motorDir_t L6208_GetDirection(void);
00750     uint32_t L6208_GetFwVersion(void);
00751     int32_t L6208_GetMark(void);
00752     uint16_t L6208_GetMaxSpeed(void);
00753     uint16_t L6208_GetMinSpeed(void);
00754     motorState_t L6208_GetMotionState(void);
00755     int32_t L6208_GetPosition(void);
00756     motorStepMode_t L6208_GetStepMode(void);
00757     motorStopMode_t L6208_GetStopMode(void);    
00758     void L6208_GoHome(void);  
00759     void L6208_GoMark(void);
00760     void L6208_GoTo(int32_t targetPosition);
00761     void L6208_GoToDir(motorDir_t direction, int32_t targetPosition);   
00762     void L6208_HardHiZ(void);
00763     void L6208_HardStop(void);
00764     void L6208_Move(motorDir_t direction, uint32_t stepCount);
00765     void L6208_ReleaseReset(void);
00766     void L6208_Reset(void);
00767     void L6208_ResetDevice(void);  
00768     void L6208_Run(motorDir_t direction);
00769     bool L6208_SetAcceleration(uint16_t newAcc);
00770     void L6208_SetDecayMode(motorDecayMode_t decayMode);
00771     bool L6208_SetDeceleration(uint16_t newDec);
00772     void L6208_SetDirection(motorDir_t direction);
00773     void L6208_SetHome(void);
00774     void L6208_SetMark(void);
00775     bool L6208_SetMaxSpeed(uint16_t volatile newSpeed);
00776     bool L6208_SetMinSpeed(uint16_t volatile newSpeed);    
00777     bool L6208_SetStepMode(motorStepMode_t stepMode);
00778     void L6208_SetStopMode(motorStopMode_t stopMode);    
00779     bool L6208_SoftStop(void);
00780     void L6208_TickHandler(void);
00781     uint32_t L6208_VrefPwmGetFreq(void);
00782     void L6208_VrefPwmSetFreq(uint32_t newFreq);
00783     void L6208_WaitWhileActive(void);
00784     
00785     /*** Functions intended to be used only internally ***/
00786     
00787     void L6208_ClearSysFlag(uint32_t mask);
00788     uint32_t L6208_ComputeNbAccOrDecSteps(uint16_t accOrDecRate);
00789     uint16_t L6208_ConvertAcceDecelRateValue(uint16_t newAccOrDecRate);
00790     void L6208_DoAccel(void);
00791     void L6208_DoDecel(void);
00792     void L6208_DoRun(void);
00793     uint8_t L6208_GetMicrostepSample2Scale(void);
00794     void L6208_Indexmodeinit(void);
00795     bool L6208_IsSysFlag(uint32_t mask);
00796     void L6208_ResetSteps(void);
00797     uint32_t L6208_ScaleWaveformSample(uint8_t sampleIndex);
00798     void L6208_ScaleWaveformTable(void);
00799     void L6208_SetDeviceParamsToGivenValues(l6208_Init_t* pInitDevicePrm);
00800     void L6208_SetDeviceParamsToPredefinedValues(void);
00801     void L6208_SetMicrostepSample2Scale(uint8_t value);
00802     void L6208_SetMicrostepSample2Update(uint8_t value);
00803     void L6208_SetMotionState(motorState_t newMotionState);
00804     bool L6208_SetSpeed(uint16_t newSpeed, uint32_t volatile *pSpeed);
00805     void L6208_SetSysFlag(uint32_t mask);
00806     bool L6208_StartMovement(void);
00807     void L6208_UpdateScanWaveformTable(void);
00808     void L6208_UstepWaveformHandling(void);
00809     bool L6208_VectorCalc(uint8_t newTorque);
00810     bool L6208_VrefPwmComputePulseWidth(uint8_t bridgeId, uint16_t value, bool valueIsPwmDutyCycle);
00811     void L6208_VrefPwmUpdatePulseWidth(void);
00812     
00813     /*** Component's I/O Methods ***/
00814 
00815     /* ACTION 8 --------------------------------------------------------------*
00816      * Implement here other I/O methods beyond those already implemented      *
00817      * above, which are declared extern within the component's header file.   *
00818      *------------------------------------------------------------------------*/
00819     /**
00820      * @brief  Reset the clock pin.
00821      * @param  None.
00822      * @retval None.
00823      */    
00824     void L6208_Board_CLOCK_PIN_Reset(void)
00825     {
00826         clock = 0;
00827     }    
00828     /**
00829      * @brief  Set the clock pin.
00830      * @param  None.
00831      * @retval None.
00832      */
00833     void L6208_Board_CLOCK_PIN_Set(void)
00834     {
00835         clock = 1;
00836     }
00837 
00838     /**
00839      * @brief  Set the control pin.
00840      * @param  None.
00841      * @retval None.
00842      */
00843     void L6208_Board_CONTROL_PIN_Set(void)
00844     {
00845         control = 1;
00846     }
00847 
00848     /**
00849      * @brief  Reset the control pin.
00850      * @param  None.
00851      * @retval None.
00852      */
00853     void L6208_Board_CONTROL_PIN_Reset(void)
00854     {
00855         control = 0;
00856     }
00857     
00858     /**
00859      * @brief  Making the CPU wait.
00860      * @param  None.
00861      * @retval None.
00862      */
00863     void L6208_Board_Delay(uint32_t delay)
00864     {
00865         wait_ms(delay);
00866     }
00867     
00868     /**
00869      * @brief  Reset the dir pin.
00870      * @param  None.
00871      * @retval None.
00872      */
00873     void L6208_Board_DIR_PIN_Reset(void)
00874     {
00875         direction = 0;
00876     }
00877         
00878     /**
00879      * @brief  Set the dir pin.
00880      * @param  None.
00881      * @retval None.
00882      */
00883     void L6208_Board_DIR_PIN_Set(void)
00884     {
00885         direction = 1;
00886     }
00887     
00888     /**
00889      * @brief  Disable the power bridges (leave the output bridges HiZ).
00890      * @param  None.
00891      * @retval None.
00892      */
00893     void L6208_Board_Disable(void)
00894     {
00895         flag_and_enable.disable_irq();
00896         flag_and_enable.mode(PullDown);
00897     }
00898 
00899     /**
00900      * @brief  Disabling interrupts.
00901      * @param  None.
00902      * @retval None.
00903      */
00904     void L6208_Board_DisableIrq(void)
00905     {
00906         __disable_irq();
00907     }
00908     
00909     /**
00910      * @brief  Enable the power bridges (leave the output bridges HiZ).
00911      * @param  None.
00912      * @retval None.
00913      */
00914     void L6208_Board_Enable(void)
00915     {     
00916         flag_and_enable.mode(PullUp);
00917         flag_and_enable.enable_irq();
00918     }
00919     
00920     /**
00921      * @brief  Enabling interrupts.
00922      * @param  None.
00923      * @retval None.
00924      */
00925     void L6208_Board_EnableIrq(void)
00926     {
00927         __enable_irq();
00928     }
00929     
00930     /**
00931      * @brief  Reset the half full pin.
00932      * @param  None.
00933      * @retval None.
00934      */
00935     void L6208_Board_HALF_FULL_PIN_Reset(void)
00936     {
00937         half_full = 0;
00938     }
00939     
00940     /**
00941      * @brief  Set the half full pin.
00942      * @param  None.
00943      * @retval None.
00944      */
00945     void L6208_Board_HALF_FULL_PIN_Set(void)
00946     {
00947         half_full = 1;
00948     }
00949 
00950     /**
00951      * @brief  Initialising the the VREFA or VREFB PWM.
00952      * @param  None.
00953      * @retval None.
00954      */
00955     void L6208_Board_VrefPwmInit(uint8_t bridgeId, uint32_t pwmFreq) {}
00956         
00957     /**
00958      * @brief  Exit the device from reset mode.
00959      * @param  None.
00960      * @retval None.
00961      */
00962     void L6208_Board_ReleaseReset(void)
00963     {
00964         reset = 1;
00965     }
00966 
00967     /**
00968      * @brief  Put the device in reset mode.
00969      * @param  None.
00970      * @retval None.
00971      */
00972     void L6208_Board_Reset(void)
00973     {
00974         reset = 0;
00975     }
00976 
00977     /**
00978      * @brief  Get the tick timer frequency in Hz.
00979      * @param  None.
00980      * @retval The tick timer frequency in Hz.
00981      */    
00982     uint32_t L6208_Board_TickGetFreq(void)
00983     {
00984        return TIMER_TICK_FREQUENCY;
00985     }
00986 
00987     /**
00988      * @brief  Initialising the tick.
00989      * @param  None.
00990      * @retval None.
00991      */
00992     void L6208_Board_TickInit(void) {}
00993 
00994     /**
00995      * @brief  Starting the tick timer, setting its frequency
00996      * and attaching a tick handler function to it.
00997      * @param  frequency the frequency of the tick.
00998      * @retval None.
00999      */
01000     void L6208_Board_TickStart(uint16_t frequency)
01001     {
01002         /* Computing the period of the tick. */
01003         double period = 1.0f / frequency;
01004         
01005         /* Attaching a tick handler function which updates */
01006         /* the state machine every elapsed period time. */
01007         ticker.attach(this, &L6208::L6208_TickHandler, period);
01008     }
01009 
01010     /**
01011      * @brief  Stopping the tick.
01012      * @param  None.
01013      * @retval None.
01014      */
01015     void L6208_Board_TickStop(void)
01016     {
01017         ticker.detach();
01018     }
01019 
01020     /**
01021      * @brief Set the pulse width of the VREFA PWM.
01022      * @param[in] pulseWidthInUs pulse width of the PWM in microsecond.
01023      * @retval None.
01024      */     
01025     void L6208_Board_VrefPwmSetPulseWidthA(uint8_t pulseWidthInUs)
01026     {
01027       vrefA_pwm.pulsewidth_us(pulseWidthInUs);
01028     }
01029  
01030     /**
01031      * @brief Set the pulse width of the VREFB PWM.
01032      * @param[in] pulseWidthInUs pulse width of the PWM in microsecond.
01033      * @retval None.
01034      */       
01035     void L6208_Board_VrefPwmSetPulseWidthB(uint8_t pulseWidthInUs)
01036     {
01037       vrefB_pwm.pulsewidth_us(pulseWidthInUs);
01038     }    
01039     
01040     /**
01041      * @brief  Start the timer for the VREFA or VREFB PWM.
01042      * @param[in] bridgeId
01043      *            0 for BRIDGE_A
01044      *            1 for BRIDGE_B
01045      * @param[in] pwmPeriod period of the PWM used to generate the reference
01046      * voltage for the bridge.
01047      * @retval "true" in case of success, "false" otherwise.
01048      * @note the unit is 1/256th of a microsecond. The VREFA PWM must be started
01049      * before the VREFB PWM.
01050      */   
01051     bool L6208_Board_VrefPwmStart(uint8_t bridgeId, uint16_t pwmPeriod)
01052     { 
01053         pwmPeriod>>=8;
01054         /* Setting the period and the duty-cycle of PWM. */
01055         if (bridgeId == 0)
01056         {
01057             vrefA_pwm.period_us(pwmPeriod);         
01058         }
01059         else if (bridgeId == 1)
01060         {
01061             vrefB_pwm.period_us(pwmPeriod);
01062         }
01063         else return false;
01064         return true;
01065     }
01066     
01067     /**
01068      * @brief  Stop the timer for the VREFA or VREFB PWM.
01069      * @param[in] bridgeId
01070      *            0 for BRIDGE_A
01071      *            1 for BRIDGE_B
01072      * @retval "true" in case of success, "false" otherwise.
01073      */       
01074     bool L6208_Board_VrefPwmStop(uint8_t bridgeId)
01075     {
01076         if (bridgeId == 0)
01077         {
01078             vrefA_pwm.period_us(0);
01079         }
01080         else if (bridgeId == 1)
01081         {
01082             vrefB_pwm.period_us(0);
01083         }
01084         else return false;
01085         return true;
01086     }
01087 
01088 protected:
01089 
01090     /*** Component's Instance Variables ***/
01091 
01092     /* ACTION 9 --------------------------------------------------------------*
01093      * Declare here interrupt related variables, if needed.                   *
01094      * Note that interrupt handling is platform dependent, see                *
01095      * "Interrupt Related Methods" above.                                     *
01096      *                                                                        *
01097      * Example:                                                               *
01098      *   + mbed:                                                              *
01099      *     InterruptIn feature_irq;                                           *
01100      *------------------------------------------------------------------------*/
01101     /* Flag Interrupt and chip enable. */
01102     InterruptIn flag_and_enable;
01103 
01104     /* ACTION 10 -------------------------------------------------------------*
01105      * Declare here other pin related variables, if needed.                   *
01106      *                                                                        *
01107      * Example:                                                               *
01108      *   + mbed:                                                              *
01109      *     DigitalOut standby_reset;                                          *
01110      *------------------------------------------------------------------------*/
01111     /* RESET pin. */
01112     DigitalOut reset;
01113     /* CW_CCW pin. */
01114     DigitalOut direction;
01115     /* HALF_FULL pin */
01116     DigitalOut half_full;
01117     /* CONTROL pin */
01118     DigitalOut control;
01119     /* CLOCK pin */
01120     DigitalOut clock;
01121 
01122     /* Pulse Width Modulation pin for VREFA pin */
01123     PwmOut vrefA_pwm;
01124     /* Pulse Width Modulation pin for VREFA pin */
01125     PwmOut vrefB_pwm;
01126     
01127     /* Timer for the tick */
01128     Ticker ticker;
01129     
01130     /* ACTION 11 -------------------------------------------------------------*
01131      * Declare here communication related variables, if needed.               *
01132      *                                                                        *
01133      * Example:                                                               *
01134      *   + mbed:                                                              *
01135      *     DigitalOut ssel;                                                   *
01136      *     DevSPI &dev_spi;                                                   *
01137      *------------------------------------------------------------------------*/
01138     /* Configuration. */
01139 
01140     /* IO Device. */
01141 
01142     /* ACTION 12 -------------------------------------------------------------*
01143      * Declare here identity related variables, if needed.                    *
01144      * Note that there should be only a unique identifier for each component, *
01145      * which should be the "who_am_i" parameter.                              *
01146      *------------------------------------------------------------------------*/
01147     /* Identity */
01148     uint8_t who_am_i;
01149 
01150     /* ACTION 13 -------------------------------------------------------------*
01151      * Declare here the component's static and non-static data, one variable  *
01152      * per line.                                                              *
01153      *                                                                        *
01154      * Example:                                                               *
01155      *   float measure;                                                       *
01156      *   int instance_id;                                                     *
01157      *   static int number_of_instances;                                      *
01158      *------------------------------------------------------------------------*/
01159     /* Data. */
01160     void (*errorHandlerCallback)(uint16_t error);
01161     deviceParams_t devicePrm;
01162     uint8_t deviceInstance;
01163     uint32_t tickFreq;
01164     /// microstepping PWM period and torque scaled waveform samples array
01165     uint16_t updatedMicroTable[L6208_USTEPS_PER_QUARTER_PERIOD+1];
01166     /// waveform scanning microstepping PWM period sample arrays for VREFA wave
01167     uint16_t microTable1[L6208_USTEPS_PER_QUARTER_PERIOD*3+1];
01168     /// waveform scanning microstepping PWM period sample array for VREFB wave
01169     uint16_t *pMicroTable2;
01170 
01171     /* Static data. */
01172     static uint8_t numberOfDevices;
01173     static const uint16_t RefMicroTable[L6208_USTEPS_PER_QUARTER_PERIOD*3];
01174 
01175 public:
01176 
01177     /* Static data. */
01178     
01179 };
01180 
01181 #endif // __L6208_CLASS_H
01182 
01183 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/