Hans Meier / Mbed 2 deprecated MyHelloWorld_IHM04A1

Dependencies:   FastPWM mbed ST_INTERFACES

Fork of HelloWorld_IHM04A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers L6206.cpp Source File

L6206.cpp

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