Davide Aliprandi / X_NUCLEO_IHM04A1

Dependencies:   ST_INTERFACES

Fork of X_NUCLEO_IHM04A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers l6206_class.cpp Source File

l6206_class.cpp

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    l6206_class.cpp
00004   * @author  IPC Rennes
00005   * @version V1.1.0
00006   * @date    March 02, 2016
00007   * @brief   L6206 driver (dual full bridge driver)
00008   * @note     (C) COPYRIGHT 2015 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 /* 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-SPN4/trunk/Drivers/BSP/Components/l6206/l6206.c
00048     Revision:         0
00049 */
00050 
00051 /* Includes ------------------------------------------------------------------*/
00052 #include "l6206_class.h"
00053 #include "l6206.h"
00054 #include "string.h"
00055 
00056 
00057 /** @addtogroup BSP
00058   * @{
00059   */   
00060   
00061 /** @addtogroup Components
00062   * @{
00063   */  
00064    
00065 /** @addtogroup L6206
00066   * @{
00067   */   
00068 
00069 /* Private constants  ---------------------------------------------------------*/
00070     
00071     
00072 /* Private variables ---------------------------------------------------------*/
00073 
00074 /** @defgroup L6206_Private_Variables L6206 Private Variables
00075   * @{
00076   */   
00077 static uint8_t l6206ArrayNbMaxMotorsByConfig[PARALLELING_END_ENUM] = {2,3,3,4,2,3,2,3,2,1,2,1,1};
00078  /**
00079   * @}
00080   */
00081 
00082 /* Private constant ---------------------------------------------------------*/
00083 
00084 
00085 /* Public Function prototypes -----------------------------------------------*/
00086 
00087 
00088 
00089 /* Private function prototypes -----------------------------------------------*/
00090 
00091 /** @defgroup L6206_Private_functions L6206 Private functions
00092   * @{
00093   */  
00094   
00095 
00096 /******************************************************//**
00097  * @brief  Attaches a user callback to the error Handler.
00098  * The call back will be then called each time the library 
00099  * detects an error
00100  * @param[in] callback Name of the callback to attach 
00101  * to the error Hanlder
00102  * @retval None
00103  **********************************************************/
00104 void L6206::L6206_AttachErrorHandler(void (*callback)(uint16_t error))
00105 {
00106     errorHandlerCallback = (void (*)(uint16_t error)) callback;
00107 }
00108 
00109 /******************************************************//**
00110  * @brief  Attaches a user callback to the flag Interrupt
00111  * The call back will be then called each time the status 
00112  * flag pin will be pulled down due to the occurrence of 
00113  * a programmed alarms ( OCD, thermal alert)
00114  * @param[in] callback Name of the callback to attach 
00115  * to the Flag Interrupt
00116  * @retval None
00117  **********************************************************/
00118 void L6206::L6206_AttachFlagInterrupt(void (*callback)(void))
00119 {
00120     flagInterruptCallback = (void (*)(void))callback;
00121 }
00122 
00123 /******************************************************//**
00124  * @brief Disable the specified bridge
00125  * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
00126  * @retval None
00127  * @note  When input of different brigdes are parallelized 
00128  * together, the disabling of one bridge leads to the disabling
00129  * of the second one
00130  **********************************************************/
00131 void L6206::L6206_DisableBridge(uint8_t bridgeId)
00132 {
00133   L6206_Board_DisableBridge(bridgeId);
00134 
00135   devicePrm.bridgeEnabled[bridgeId] = FALSE;
00136   if (devicePrm.config >= PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR)
00137   {
00138     if (bridgeId == BRIDGE_A) 
00139     {
00140       L6206_Board_DisableBridge(BRIDGE_B);
00141       devicePrm.bridgeEnabled[BRIDGE_B] = FALSE;
00142     }
00143     else 
00144     {
00145       L6206_Board_DisableBridge(BRIDGE_A);
00146       devicePrm.bridgeEnabled[BRIDGE_A] = FALSE;
00147     }    
00148   }  
00149 }
00150 
00151 /******************************************************//**
00152  * @brief Enable the specified bridge
00153  * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
00154  * @retval None
00155  * @note  When input of different brigdes are parallelized 
00156  * together, the enabling of one bridge leads to the enabling
00157  * of the second one
00158  **********************************************************/
00159 void L6206::L6206_EnableBridge(uint8_t bridgeId)
00160 {
00161   devicePrm.bridgeEnabled[bridgeId] = TRUE;
00162   if (devicePrm.config >= PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR)
00163   {
00164     L6206_Board_EnableBridge(bridgeId, 0);
00165     if (bridgeId == BRIDGE_A) 
00166     {
00167       L6206_Board_EnableBridge(BRIDGE_B, 1);
00168       devicePrm.bridgeEnabled[BRIDGE_B] = TRUE;
00169     }
00170     else 
00171     {
00172       L6206_Board_EnableBridge(BRIDGE_A, 1);
00173       devicePrm.bridgeEnabled[BRIDGE_A] = TRUE;
00174     }    
00175   }
00176   else
00177   {
00178     L6206_Board_EnableBridge(bridgeId, 1);
00179   }
00180 }
00181 
00182 /******************************************************//**
00183  * @brief Start the L6206 library
00184  * @param[in] init pointer to the initialization data
00185  * @retval None
00186  **********************************************************/
00187 Status_t L6206::L6206_Init(void *init)
00188 {
00189     deviceInstance++;
00190 
00191     /* Initialise the GPIOs */
00192     L6206_Board_GpioInit();
00193 
00194     if (init == NULL)
00195     {
00196         /* Set context variables to the predefined values from l6206_target_config.h */
00197         /* Set GPIO according to these values */
00198         L6206_SetDeviceParamsToPredefinedValues();
00199     }
00200     else
00201     {
00202         L6206_SetDeviceParamsToGivenValues((L6206_Init_t*) init);
00203     }
00204 
00205     /* Initialise input bridges PWMs */
00206     L6206_SetDualFullBridgeConfig(devicePrm.config);
00207 
00208     return COMPONENT_OK;
00209 }
00210 
00211 /******************************************************//**
00212  * @brief  Get the PWM frequency of the specified bridge 
00213  * @param[in] bridgeId 0 for bridge A, 1 for bridge B
00214  * @retval Freq in Hz
00215  **********************************************************/
00216 uint32_t L6206::L6206_GetBridgeInputPwmFreq(uint8_t bridgeId)
00217 {
00218     return (devicePrm.pwmFreq[(bridgeId << 1)]);
00219 }
00220 
00221 /******************************************************//**
00222  * @brief  Returns the current speed of the specified motor
00223  * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00224  * @retval current speed in % from 0 to 100
00225  **********************************************************/
00226 uint16_t L6206::L6206_GetCurrentSpeed(uint8_t motorId)
00227 {                                                  
00228     uint16_t speed = 0;
00229 
00230   if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
00231   {
00232     L6206_ErrorHandler(L6206_ERROR_1);
00233   }
00234   else if (devicePrm.motionState[motorId] != INACTIVE)
00235   {
00236     speed = devicePrm.speed[motorId];
00237   }
00238   
00239   return (speed);
00240 }
00241 
00242 /******************************************************//**
00243  * @brief Returns the device state
00244  * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00245  * @retval State (STEADY or INACTIVE)
00246  **********************************************************/
00247 motorState_t L6206::L6206_GetDeviceState(uint8_t motorId)
00248 {
00249     motorState_t state =  INACTIVE;
00250 
00251   if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
00252   {
00253     L6206_ErrorHandler(L6206_ERROR_1);
00254   }
00255   else
00256   {
00257     state =  devicePrm.motionState[motorId];
00258   }
00259   return (state);  
00260 }
00261 
00262 /******************************************************//**
00263  * @brief Returns the FW version of the library
00264  * @retval L6206_FW_VERSION
00265  **********************************************************/
00266 uint8_t L6206::L6206_GetFwVersion(void)
00267 {
00268   return (L6206_FW_VERSION);
00269 }
00270 
00271 /******************************************************//**
00272  * @brief  Returns the max  speed of the specified motor
00273  * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00274  * @retval maxSpeed in % from 0 to 100
00275  **********************************************************/
00276 uint16_t L6206::L6206_GetMaxSpeed(uint8_t motorId)
00277 {
00278     uint16_t speed = 0;
00279   if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
00280   {
00281     L6206_ErrorHandler(L6206_ERROR_1);
00282   }
00283   else
00284   {
00285     speed =  devicePrm.speed[motorId];
00286   }
00287   return (speed);
00288 }
00289 
00290 
00291 /******************************************************//**
00292  * @brief  Get the status of the bridge enabling of the corresponding bridge
00293  * @param[in] bridgeId from 0 for bridge A to 1 for bridge B
00294  * @retval State of the Enable&Flag pin of the corresponding bridge (1 set, 0 for reset)
00295   **********************************************************/
00296 uint16_t L6206::L6206_GetBridgeStatus(uint8_t bridgeId)
00297 {
00298   uint16_t status = L6206_Board_GetFlagPinState(bridgeId);
00299   
00300   return (status);
00301 }
00302 
00303 /******************************************************//**
00304  * @brief  Immediatly stops the motor and disable the power bridge
00305  * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00306  * @retval None
00307  * @note  if two motors uses the same power bridge, the 
00308  * power bridge will be disable only if the two motors are
00309  * stopped
00310  **********************************************************/
00311 void L6206::L6206_HardHiz(uint8_t motorId)
00312 {
00313     if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
00314   {
00315     L6206_ErrorHandler(L6206_ERROR_1);
00316   }
00317   else
00318   {
00319      /* Get bridge Id of the corresponding motor */
00320     uint8_t bridgeId = L6206_GetBridgeIdUsedByMotorId(motorId);
00321     
00322     if (devicePrm.bridgeEnabled[bridgeId] != FALSE)
00323     {
00324       bool skip = FALSE;
00325 
00326       /* Check if another motor is currently running by using the same bridge */
00327       switch (devicePrm.config)
00328       {
00329         case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00330           if ((motorId > 0) && (devicePrm.motionState[1] == STEADY) && (devicePrm.motionState[2] == STEADY))
00331           {
00332             skip = TRUE;
00333           }
00334           break;
00335         case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00336           if ((motorId < 2) && (devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))
00337           {
00338             skip = TRUE;
00339           }
00340           break;          
00341         case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00342           if (((motorId < 2) && (devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))||
00343               ((motorId > 1) && (devicePrm.motionState[2] == STEADY) && (devicePrm.motionState[3] == STEADY)))
00344           {
00345             skip = TRUE;
00346           }
00347           break;          
00348         case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00349           if ((motorId > 0) && (devicePrm.motionState[1] == STEADY) && (devicePrm.motionState[2] == STEADY))
00350           {
00351             skip = TRUE;
00352           }
00353           break;          
00354         case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00355           if ((motorId < 2) && (devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))
00356           {
00357             skip = TRUE;
00358           }
00359           break;          
00360         case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
00361           if ((devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))
00362           {
00363             skip = TRUE;
00364           }
00365           break;          
00366         default:
00367           break;
00368       }      
00369 
00370       if (skip == FALSE)
00371       {
00372         /* Disable the bridge */
00373         L6206_DisableBridge(bridgeId);
00374       }  
00375     }
00376     /* Disable the PWM */
00377     L6206_HardStop(motorId);
00378   }
00379 }
00380 
00381 /******************************************************//**
00382  * @brief  Stops the motor without disabling the bridge
00383  * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00384  * @retval none
00385  **********************************************************/
00386 void L6206::L6206_HardStop(uint8_t motorId)
00387 {   
00388     if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
00389     {
00390         L6206_ErrorHandler(L6206_ERROR_1);
00391     }
00392     else if (devicePrm.motionState[motorId] != INACTIVE)
00393     {
00394         uint8_t bridgeInput;
00395     
00396         /* Get bridge input of the corresponding motor */
00397         bridgeInput = L6206_GetBridgeInputUsedByMotorId(motorId);
00398     
00399         /* Disable corresponding PWM */
00400         L6206_Board_PwmStop(bridgeInput);
00401 
00402         /* for bidirectionnal motor, disable second PWM*/
00403         if (L6206_IsBidirectionnalMotor(motorId))
00404         {
00405             bridgeInput = L6206_GetSecondBridgeInputUsedByMotorId(motorId);
00406             L6206_Board_PwmStop(bridgeInput);
00407         }
00408         /* Set inactive state */
00409         devicePrm.motionState[motorId] = INACTIVE;
00410     }
00411 }
00412 
00413 /******************************************************//**
00414  * @brief Read id
00415  * @retval Id of the l6206 Driver Instance
00416  **********************************************************/
00417 Status_t L6206::L6206_ReadId(uint8_t *id)
00418 {
00419     *id = deviceInstance;
00420 
00421     return COMPONENT_OK;
00422 }
00423 
00424 /******************************************************//**
00425  * @brief  Runs the motor
00426  * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00427  * @param[in] direction FORWARD or BACKWARD
00428  * @retval None
00429  * @note  For unidirectionnal motor, direction parameter has 
00430  * no effect
00431  **********************************************************/
00432 void L6206::L6206_Run(uint8_t motorId, motorDir_t direction)
00433 {
00434     if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
00435   {
00436     L6206_ErrorHandler(L6206_ERROR_1);
00437   }  
00438   else if ((devicePrm.motionState[motorId] == INACTIVE) ||
00439            (devicePrm.direction[motorId] != direction))
00440   {
00441     uint8_t bridgeId;
00442     uint8_t bridgeInput;
00443     
00444     /* Eventually deactivate motor */
00445     if (devicePrm.motionState[motorId] != INACTIVE)
00446     {
00447       L6206_HardStop(motorId);
00448     }
00449    
00450     /* Store new direction */
00451     devicePrm.direction[motorId] = direction;
00452     
00453     /* Switch to steady state */
00454     devicePrm.motionState[motorId] = STEADY;
00455     
00456    /* Get bridge Id of the corresponding motor */
00457     bridgeId = L6206_GetBridgeIdUsedByMotorId(motorId);
00458         
00459     /* Get bridge input of the corresponding motor */
00460     bridgeInput = L6206_GetBridgeInputUsedByMotorId(motorId);
00461     
00462     /* Enable bridge */
00463     L6206_EnableBridge(bridgeId);
00464     
00465     /* Set PWM */
00466     if (L6206_IsBidirectionnalMotor(motorId))
00467     {
00468       /* for bidirectionnal motor */
00469       L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],(100 - devicePrm.speed[motorId]));
00470       bridgeInput = L6206_GetSecondBridgeInputUsedByMotorId(motorId);
00471       L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],100);
00472     }
00473     else
00474     {
00475       /* for unidirectionnal motor */
00476       L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],devicePrm.speed[motorId]);
00477     }
00478   }
00479 }
00480 /******************************************************//**
00481  * @brief Set dual full bridge parallelling configuration
00482  * @param[in] newConfig bridge configuration to apply from 
00483  * dualFullBridgeConfig_t enum
00484  * @retval None
00485  **********************************************************/
00486 void L6206::L6206_SetDualFullBridgeConfig(uint8_t newConfig)
00487 {
00488     devicePrm.config = (dualFullBridgeConfig_t)newConfig;
00489 
00490   /* Start to reset all else if several inits are used successively */
00491   /* they will fail */
00492   L6206_Board_PwmDeInit(INPUT_1A);
00493   L6206_Board_PwmDeInit(INPUT_2A);
00494   L6206_Board_PwmDeInit(INPUT_1B);
00495   L6206_Board_PwmDeInit(INPUT_2B);
00496   
00497   
00498   /* Initialise the bridges inputs PWMs --------------------------------------*/
00499   switch (devicePrm.config)
00500   {
00501     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00502     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:   
00503     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:  
00504     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:      
00505         L6206_Board_PwmInit(INPUT_1A);
00506         L6206_Board_PwmInit(INPUT_2A);
00507         L6206_Board_PwmInit(INPUT_1B);
00508         L6206_Board_PwmInit(INPUT_2B);
00509       break;
00510     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00511     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00512         L6206_Board_PwmDeInit(INPUT_2A);
00513         L6206_Board_PwmInit(INPUT_1A);
00514         L6206_Board_PwmInit(INPUT_1B);
00515         L6206_Board_PwmInit(INPUT_2B);
00516       break;         
00517     case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00518     case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00519         L6206_Board_PwmDeInit(INPUT_2B);
00520         L6206_Board_PwmInit(INPUT_1A);
00521         L6206_Board_PwmInit(INPUT_2A);
00522         L6206_Board_PwmInit(INPUT_1B);
00523       break;      
00524     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00525     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
00526         L6206_Board_PwmDeInit(INPUT_2A);
00527         L6206_Board_PwmDeInit(INPUT_2B);
00528         L6206_Board_PwmInit(INPUT_1A);
00529         L6206_Board_PwmInit(INPUT_1B);
00530       break;       
00531     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
00532     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
00533         L6206_Board_PwmDeInit(INPUT_1B);
00534         L6206_Board_PwmDeInit(INPUT_2B);
00535         L6206_Board_PwmInit(INPUT_1A);
00536         L6206_Board_PwmInit(INPUT_2A);
00537       break;      
00538     case PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
00539         L6206_Board_PwmDeInit(INPUT_2A);
00540         L6206_Board_PwmDeInit(INPUT_1B);
00541         L6206_Board_PwmDeInit(INPUT_2B);
00542         L6206_Board_PwmInit(INPUT_1A);
00543       break;
00544     default:
00545     break;       
00546   }  
00547 }
00548 /******************************************************//**
00549  * @brief  Changes the max speed of the specified device
00550  * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00551  * @param[in] newMaxSpeed in % from 0 to 100
00552  * @retval true if the command is successfully executed, else false
00553  **********************************************************/
00554 bool L6206::L6206_SetMaxSpeed(uint8_t motorId, uint16_t newMaxSpeed)
00555 {
00556     bool cmdExecuted = FALSE;
00557 
00558   if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
00559   {
00560     L6206_ErrorHandler(L6206_ERROR_1);
00561   }
00562   else
00563   {
00564     devicePrm.speed[motorId] = newMaxSpeed;
00565     if (devicePrm.motionState[motorId] != INACTIVE)
00566     {
00567       uint8_t bridgeInput;
00568           
00569       /* Get Bridge input of the corresponding motor */
00570       bridgeInput = L6206_GetBridgeInputUsedByMotorId(motorId);
00571       
00572       /* Set PWM frequency*/
00573       if (L6206_IsBidirectionnalMotor(motorId))
00574       {
00575         /* for bidirectionnal motor */
00576         L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],(100 - devicePrm.speed[motorId]));
00577       }
00578       else
00579       {
00580         /* for unidirectionnal motor */
00581         L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],devicePrm.speed[motorId]);
00582       }      
00583     }
00584     cmdExecuted = TRUE;
00585   }
00586   return cmdExecuted;
00587 }                                                     
00588 
00589 /******************************************************//**
00590  * @brief  Changes the PWM frequency of the bridge input
00591  * @param[in] bridgeId 0 for bridge A, 1 for bridge B
00592  * @param[in] newFreq in Hz
00593  * @retval None
00594  **********************************************************/
00595 void L6206::L6206_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq)
00596 {
00597     uint8_t loop;
00598   
00599   if (newFreq > L6206_MAX_PWM_FREQ)
00600   {
00601     newFreq = L6206_MAX_PWM_FREQ;
00602   }
00603   for (loop = 0; loop < 2;loop ++)
00604   {
00605     uint8_t motorId;
00606     uint8_t bridgeInput = (bridgeId << 1) + loop; 
00607     devicePrm.pwmFreq[bridgeInput] = newFreq;
00608     
00609     /* Get motor Id using this bridge */
00610     motorId = L6206_GetMotorIdUsingbridgeInput(bridgeInput);
00611 
00612     /* Immediatly update frequency if motor is running */
00613     if (devicePrm.motionState[motorId] != INACTIVE)
00614     {
00615       /* Test if motor is bidir */
00616       if (L6206_IsBidirectionnalMotor(motorId))
00617       {
00618         if (bridgeInput !=  L6206_GetSecondBridgeInputUsedByMotorId(motorId))
00619         {
00620         /* Set PWM frequency for bidirectionnal motor of the first bridge*/
00621         L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],(100 - devicePrm.speed[motorId]));
00622         }
00623         else
00624         {
00625           /* Set PWM frequency for bidirectionnal motor of the second bridge */
00626           L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],100);
00627         }
00628       }
00629       else
00630       {
00631         /* Set PWM frequency  for unidirectionnal motor */
00632         L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],devicePrm.speed[motorId]);
00633       }
00634     }
00635   }
00636 }
00637 /******************************************************//**
00638  * @brief  Sets the number of devices to be used
00639  * @param[in] nbDevices (from 1 to MAX_NUMBER_OF_DEVICES)
00640  * @retval TRUE if successfull, FALSE if failure, attempt to set a number of
00641  * devices greater than MAX_NUMBER_OF_DEVICES
00642  **********************************************************/
00643 bool L6206::L6206_SetNbDevices(uint8_t nbDevices)
00644 {
00645   if (nbDevices <= MAX_NUMBER_OF_DEVICES)
00646   {
00647     return TRUE;
00648   }
00649   else
00650   {
00651     return FALSE;
00652   }
00653 }
00654 
00655 
00656 /******************************************************//**
00657  * @brief Error handler which calls the user callback (if defined)
00658  * @param[in] error Number of the error
00659  * @retval None
00660  **********************************************************/
00661 void L6206::L6206_ErrorHandler(uint16_t error)
00662 {
00663     if (errorHandlerCallback != 0)
00664   {
00665     (void) errorHandlerCallback(error);
00666   }
00667   else   
00668   {
00669     while(1)
00670     {
00671       /* Infinite loop */
00672     }
00673   }
00674 }
00675 
00676 /******************************************************//**
00677  * @brief  Handlers of the flag interrupt which calls the user callback (if defined)
00678  * @retval None
00679  **********************************************************/
00680 void L6206::L6206_FlagInterruptHandler(void)
00681 {
00682     bool status;
00683   
00684   status = L6206_GetBridgeStatus(BRIDGE_A);
00685   if (status != devicePrm.bridgeEnabled[BRIDGE_A])
00686   {
00687     devicePrm.bridgeEnabled[BRIDGE_A] = status;
00688   }
00689   
00690   status = L6206_GetBridgeStatus(BRIDGE_B);
00691   if (status != devicePrm.bridgeEnabled[BRIDGE_B])
00692   {
00693     devicePrm.bridgeEnabled[BRIDGE_B] = status;
00694   }  
00695   
00696   if (flagInterruptCallback != 0)
00697   {
00698       flagInterruptCallback();
00699   }
00700 }
00701 
00702 /******************************************************//**
00703  * @brief  Get the bridges Id used by a given motor
00704  * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00705  * @retval bridgeId 0 for bridge A , 1 for bridge B
00706  **********************************************************/
00707 uint8_t L6206::L6206_GetBridgeIdUsedByMotorId(uint8_t motorId)
00708 {
00709     uint8_t bridgeId;
00710 
00711   switch (devicePrm.config)
00712   {
00713     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00714     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:        
00715     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00716     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00717     case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00718     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00719       if (motorId == 0)
00720       {
00721         bridgeId = 0;
00722       }
00723       else
00724       {
00725         bridgeId = 1;
00726       }
00727       break;  
00728     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00729     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00730     case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00731       if (motorId < 2)
00732       {
00733         bridgeId = 0;
00734       }
00735       else
00736       {
00737         bridgeId = 1;
00738       }
00739       break;          
00740     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
00741     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
00742     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
00743     case PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
00744     default:
00745         bridgeId = 0;
00746       break;        
00747   }  
00748   return (bridgeId);
00749 }
00750 
00751 /******************************************************//**
00752  * @brief  Get the motor Id which is using the specified bridge input
00753  * @param bridgeInput 0 for bridgeInput 1A, 1 for 2A, 2 for 1B, 3 for 3B
00754  * @retval bridgeId 0 for bridge A , 1 for bridge B
00755  **********************************************************/
00756 uint8_t L6206::L6206_GetMotorIdUsingbridgeInput(uint8_t bridgeInput)
00757 {
00758     uint8_t motorId;
00759   
00760   switch (devicePrm.config)
00761   {
00762     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00763     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:      
00764     case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00765     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:      
00766       if (bridgeInput >= INPUT_1B) 
00767       {
00768         motorId = 1;
00769       }
00770       else
00771       {
00772         motorId = 0;
00773       }
00774       break;  
00775     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00776     case   PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:      
00777       if (bridgeInput == INPUT_2B) 
00778       {
00779         motorId = 2;
00780       }
00781       else if (bridgeInput == INPUT_1B) 
00782       {
00783         motorId = 1;
00784       }
00785       else
00786       {
00787         motorId = 0;
00788       }      
00789       break;        
00790     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00791     case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:      
00792       if (bridgeInput >= INPUT_1B) 
00793       {
00794         motorId = 2;
00795       }
00796       else if (bridgeInput == INPUT_2A) 
00797       {
00798         motorId = 1;
00799       }
00800       else
00801       {
00802         motorId = 0;
00803       }      
00804       break;           
00805     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00806       if (bridgeInput == INPUT_2B) 
00807       {
00808         motorId = 3;
00809       }
00810       else if (bridgeInput == INPUT_1B) 
00811       {
00812         motorId = 2;
00813       }
00814       else if (bridgeInput == INPUT_2A) 
00815       {
00816         motorId = 1;
00817       }      
00818       else
00819       {
00820         motorId = 0;
00821       }      
00822       break;           
00823     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
00824       if ((bridgeInput == INPUT_2A) || (bridgeInput == INPUT_2B))
00825       {
00826         motorId = 1;
00827       }
00828       else
00829       {
00830         motorId = 0;
00831       }    
00832       break;
00833     case   PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
00834     case   PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
00835     case   PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
00836     default:
00837       motorId = 0;  
00838       break;        
00839   }
00840   
00841   return (motorId);
00842 }
00843 /******************************************************//**
00844  * @brief  Get the PWM input used by a given motor
00845  * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
00846  * @retval PWM input 0 for 1A, 1 for 2A, 2 for 1B, 3 for 3B
00847  **********************************************************/
00848 uint8_t L6206::L6206_GetBridgeInputUsedByMotorId(uint8_t motorId)
00849 {
00850     uint8_t bridgeInput;
00851 
00852   switch (devicePrm.config)
00853   {
00854     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00855       if  (motorId == 0)
00856       { 
00857          if (devicePrm.direction[0] == FORWARD)
00858          {
00859            bridgeInput = INPUT_1A;
00860          }
00861          else
00862          {
00863            bridgeInput = INPUT_2A;
00864          }
00865       }
00866       else
00867       { 
00868          if (devicePrm.direction[1] == FORWARD)
00869          {
00870            bridgeInput = INPUT_1B;
00871          }
00872          else
00873          {
00874            bridgeInput = INPUT_2B;
00875          }
00876       }  
00877       break;
00878     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00879       if  (motorId == 0)
00880       { 
00881          if (devicePrm.direction[0] == FORWARD)
00882          {
00883            bridgeInput = INPUT_1A;
00884          }
00885          else
00886          {
00887            bridgeInput = INPUT_2A;
00888          }
00889       }
00890       else if  (motorId == 1)
00891       { 
00892         
00893         bridgeInput = INPUT_1B;
00894       }
00895       else
00896       {
00897         bridgeInput = INPUT_2B;        
00898       }
00899       break;        
00900     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00901       if  (motorId == 0)
00902       { 
00903         bridgeInput = INPUT_1A;
00904       }
00905       else if (motorId == 1)
00906       {   
00907         bridgeInput = INPUT_2A;
00908       }
00909       else 
00910       { 
00911          if (devicePrm.direction[2] == FORWARD)
00912          {
00913            bridgeInput = INPUT_1B;
00914          }
00915          else
00916          {
00917            bridgeInput = INPUT_2B;
00918          }        
00919       }
00920       break;   
00921     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00922       if  (motorId == 0)
00923       { 
00924         bridgeInput = INPUT_1A;
00925       }
00926       else if (motorId == 1)
00927       {   
00928         bridgeInput = INPUT_2A;
00929       }
00930       else if  (motorId == 2)
00931       { 
00932         bridgeInput = INPUT_1B;
00933       }
00934       else
00935       {
00936         bridgeInput = INPUT_2B;
00937       }        
00938       break;     
00939     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
00940       if  (motorId == 0)
00941       { 
00942         bridgeInput = INPUT_1A;
00943       }
00944       else 
00945       {  
00946          if (devicePrm.direction[1] == FORWARD)
00947         {   
00948           bridgeInput = INPUT_1B;
00949         }
00950         else
00951         {   
00952           bridgeInput = INPUT_2B;
00953         }
00954       }
00955       break;     
00956     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
00957       if  (motorId == 0)
00958       { 
00959         bridgeInput = INPUT_1A;
00960       }
00961       else if  (motorId == 1)
00962       {  
00963         bridgeInput = INPUT_1B;
00964       }
00965       else
00966       {   
00967         bridgeInput = INPUT_2B;
00968       }
00969       break;         
00970     case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00971       if  (motorId == 0)
00972       { 
00973          if (devicePrm.direction[0] == FORWARD)
00974          {
00975            bridgeInput = INPUT_1A;
00976          }
00977          else
00978          {
00979            bridgeInput = INPUT_2A;
00980          }
00981       }
00982       else
00983       { 
00984         bridgeInput = INPUT_1B;
00985       }  
00986       break;
00987     case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
00988       if  (motorId == 0)
00989       { 
00990         bridgeInput = INPUT_1A;        
00991       }
00992       else if  (motorId == 1)
00993       { 
00994         bridgeInput = INPUT_2A;        
00995       }        
00996       else
00997       {
00998         bridgeInput = INPUT_1B;        
00999       }
01000       break;      
01001     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
01002       if  (motorId == 0)
01003       { 
01004         bridgeInput = INPUT_1A;        
01005       }
01006       else
01007       {
01008         bridgeInput = INPUT_1B;        
01009       }
01010       break;      
01011     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
01012       if (devicePrm.direction[0] == FORWARD)
01013        {
01014          bridgeInput = INPUT_1A;
01015        }
01016        else
01017        {
01018          bridgeInput = INPUT_1B;
01019        }
01020       break;       
01021     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
01022       if (motorId == 0)
01023       {
01024         bridgeInput = INPUT_1A;
01025       }
01026       else
01027       {
01028         bridgeInput = INPUT_2A;
01029       }      
01030       break;
01031     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
01032       if (devicePrm.direction[0] == FORWARD)
01033       {
01034         bridgeInput = INPUT_1A;
01035       }
01036       else
01037       {
01038         bridgeInput = INPUT_2A;
01039       }  
01040       break;      
01041     case PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
01042     default:
01043       bridgeInput = INPUT_1A;
01044       break;       
01045   }  
01046   return (bridgeInput);
01047 }
01048 
01049 /******************************************************//**
01050  * @brief  Get the second PWM input used by a given bidirectionnal motor
01051  * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
01052  * @retval PWM input 0 for 1A, 1 for 2A, 2 for 1B, 3 for 3B
01053  **********************************************************/
01054 uint8_t L6206::L6206_GetSecondBridgeInputUsedByMotorId(uint8_t motorId)
01055 {
01056     uint8_t bridgeInput = 0xFF;
01057   
01058   switch (devicePrm.config)
01059   {
01060     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
01061       if  (motorId == 0)
01062       { 
01063          if (devicePrm.direction[0] == FORWARD)
01064          {
01065            bridgeInput = INPUT_2A;
01066          }
01067          else
01068          {
01069            bridgeInput = INPUT_1A;
01070          }
01071       }
01072       else
01073       { 
01074          if (devicePrm.direction[1] == FORWARD)
01075          {
01076            bridgeInput = INPUT_2B;
01077          }
01078          else
01079          {
01080            bridgeInput = INPUT_1B;
01081          }
01082       }  
01083       break;
01084     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
01085       if  (motorId == 0)
01086       { 
01087          if (devicePrm.direction[0] == FORWARD)
01088          {
01089            bridgeInput = INPUT_2A;
01090          }
01091          else
01092          {
01093            bridgeInput = INPUT_1A;
01094          }
01095       }
01096       break;        
01097     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
01098       if (motorId == 2)
01099       { 
01100          if (devicePrm.direction[2] == FORWARD)
01101          {
01102            bridgeInput = INPUT_2B;
01103          }
01104          else
01105          {
01106            bridgeInput = INPUT_1B;
01107          }        
01108       }
01109       break;   
01110 
01111     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
01112       if  (motorId == 1)
01113       {  
01114          if (devicePrm.direction[1] == FORWARD)
01115         {   
01116           bridgeInput = INPUT_2B;
01117         }
01118         else
01119         {   
01120           bridgeInput = INPUT_1B;
01121         }
01122       }
01123       break;     
01124 
01125     case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
01126       if  (motorId == 0)
01127       { 
01128          if (devicePrm.direction[0] == FORWARD)
01129          {
01130            bridgeInput = INPUT_2A;
01131          }
01132          else
01133          {
01134            bridgeInput = INPUT_1A;
01135          }
01136       }
01137       break;
01138     case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
01139       if (devicePrm.direction[0] == FORWARD)
01140        {
01141          bridgeInput = INPUT_1B;
01142        }
01143        else
01144        {
01145          bridgeInput = INPUT_1A;
01146        }
01147       break;       
01148     
01149     case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
01150       if (devicePrm.direction[0] == FORWARD)
01151       {
01152         bridgeInput = INPUT_2A;
01153       }
01154       else
01155       {
01156         bridgeInput = INPUT_1A;
01157       }  
01158       break;      
01159     default:
01160       bridgeInput = 0XFF;
01161       break;       
01162   }  
01163   if (bridgeInput == 0XFF)
01164   {
01165     L6206_ErrorHandler(L6206_ERROR_2);
01166   }
01167   
01168   return (bridgeInput);
01169 }        
01170         
01171 /******************************************************//**
01172  * @brief  Test if motor is bidirectionnal
01173  * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 
01174  * @retval True if motor is bidirectionnal, else false
01175  **********************************************************/
01176 bool L6206::L6206_IsBidirectionnalMotor(uint8_t motorId)
01177 {
01178     bool isBiDir = FALSE;
01179 
01180   switch (devicePrm.config)
01181   {
01182       case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
01183       case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
01184       case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
01185         isBiDir = TRUE;
01186       break;      
01187   
01188     case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
01189     case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
01190       if  (motorId == 0)
01191       { 
01192         isBiDir = TRUE;
01193       }
01194       break;        
01195     case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
01196       if  (motorId == 2)
01197       { 
01198         isBiDir = TRUE;
01199       }
01200       break;   
01201     case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
01202       if  (motorId == 1)
01203       { 
01204         isBiDir = TRUE;
01205       }
01206       break;     
01207   
01208     default:
01209       break;       
01210   }    
01211   
01212   return (isBiDir);
01213 }
01214 
01215 
01216 /******************************************************//**
01217  * @brief  Sets the parameters of the device to predefined values
01218  * from l6206_target_config.h
01219  * @retval None
01220  **********************************************************/
01221 void L6206::L6206_SetDeviceParamsToPredefinedValues(void)
01222 {
01223     uint32_t i;
01224 
01225   memset(&devicePrm, 0, sizeof(devicePrm));
01226 
01227   devicePrm.config = L6206_CONF_PARAM_PARALLE_BRIDGES;
01228 
01229   devicePrm.pwmFreq[INPUT_1A] = L6206_CONF_PARAM_FREQ_PWM1A;
01230   devicePrm.pwmFreq[INPUT_2A] = L6206_CONF_PARAM_FREQ_PWM2A;
01231   devicePrm.pwmFreq[INPUT_1B] = L6206_CONF_PARAM_FREQ_PWM1B;
01232   devicePrm.pwmFreq[INPUT_2B] = L6206_CONF_PARAM_FREQ_PWM2B;
01233   
01234   for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++)
01235   {
01236     devicePrm.speed[i] = 100;
01237     devicePrm.direction[i] = FORWARD;
01238     devicePrm.motionState[i] = INACTIVE;
01239   }
01240   for (i = 0; i < L6206_NB_MAX_BRIDGES; i++)
01241   {  
01242     devicePrm.bridgeEnabled[i] = FALSE;
01243   }
01244 }
01245 
01246 
01247 /******************************************************//**
01248  * @brief  Set the parameters of the device to values of initDevicePrm structure
01249  * Set GPIO according to these values
01250  * @param initDevicePrm structure containing values to initialize the device
01251  * parameters
01252  * @retval None
01253  **********************************************************/
01254 void L6206::L6206_SetDeviceParamsToGivenValues(L6206_Init_t* initDevicePrm)
01255 {
01256     memcpy(&devicePrm, initDevicePrm, sizeof(devicePrm));
01257 }
01258 
01259  /**
01260   * @}
01261   */
01262   
01263   
01264   
01265   
01266    /**
01267   * @}
01268   */
01269   
01270    /**
01271   * @}
01272   */
01273   
01274    /**
01275   * @}
01276   */
01277 
01278 
01279 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
01280 
01281 
01282