Added ST_INTERFACES library.

Dependencies:   ST_INTERFACES

Fork of X-NUCLEO-IHM05A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motor.h Source File

motor.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    motor.h
00004   * @author  IPC Rennes
00005   * @version V1.5.0
00006   * @date    January 25, 2016
00007   * @brief   This file contains all the functions prototypes for motor drivers.   
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */ 
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __MOTOR_H
00040 #define __MOTOR_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif 
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include <stdint.h>
00048 #include "component.h"
00049 
00050 /* Definitions ---------------------------------------------------------------*/
00051 /// boolean for false condition 
00052 #ifndef FALSE
00053 #define FALSE (0)
00054 #endif
00055 /// boolean for true condition 
00056 #ifndef TRUE
00057 #define TRUE  (1)
00058 #endif
00059 
00060 /* Types ---------------------------------------------------------------------*/
00061 /** @addtogroup BSP
00062   * @{
00063   */
00064 
00065 /** @addtogroup Components
00066   * @{
00067   */ 
00068 
00069 /** @defgroup Motor Motor
00070   * @{
00071   */
00072    
00073 /** @defgroup Motor_Exported_Types Motor Exported Types
00074   * @{
00075   */
00076    
00077 /** @defgroup Device_Direction_Options Device Direction Options
00078   * @{
00079   */
00080 /// Direction options
00081 typedef enum {
00082   BACKWARD = 0,
00083   FORWARD = 1,
00084   UNKNOW_DIR = ((uint8_t)0xFF)
00085 } motorDir_t;
00086 /**
00087   * @}
00088   */
00089   
00090 /** @defgroup Device_Action_Options Device Action Options
00091   * @{
00092   */
00093 /// Action options
00094 typedef enum {
00095   ACTION_RESET = ((uint8_t)0x00),
00096   ACTION_COPY  = ((uint8_t)0x08)
00097 } motorAction_t;
00098 /**
00099   * @}
00100   */  
00101 
00102 /** @defgroup Device_States Device States
00103   * @{
00104   */
00105 /// Device states
00106 typedef enum {
00107   ACCELERATING       = 0,
00108   DECELERATINGTOSTOP = 1,  
00109   DECELERATING       = 2, 
00110   STEADY             = 3,
00111   INDEX_ACCEL        = 4,
00112   INDEX_RUN          = 5,
00113   INDEX_DECEL        = 6,
00114   INDEX_DWELL        = 7,
00115   INACTIVE           = 8,
00116   STANDBY            = 9,
00117   STANDBYTOINACTIVE  = 10
00118 } motorState_t;
00119 /**
00120   * @}
00121   */   
00122 
00123 /** @defgroup Device_Step_mode Device Step mode
00124   * @{
00125   */
00126  /// Stepping options 
00127 typedef enum {
00128   STEP_MODE_FULL   = ((uint8_t)0x00), 
00129   STEP_MODE_HALF   = ((uint8_t)0x01),
00130   STEP_MODE_1_4    = ((uint8_t)0x02),
00131   STEP_MODE_1_8    = ((uint8_t)0x03),
00132   STEP_MODE_1_16   = ((uint8_t)0x04),
00133   STEP_MODE_1_32   = ((uint8_t)0x05),
00134   STEP_MODE_1_64   = ((uint8_t)0x06),
00135   STEP_MODE_1_128  = ((uint8_t)0x07),
00136   STEP_MODE_1_256  = ((uint8_t)0x08),
00137   STEP_MODE_UNKNOW = ((uint8_t)0xFE),
00138   STEP_MODE_WAVE   = ((uint8_t)0xFF)  
00139 } motorStepMode_t;
00140 
00141 /**
00142   * @}
00143   */
00144   
00145 /** @defgroup Decay_mode Decay mode
00146   * @{
00147   */
00148 /// Decay Mode 
00149 typedef enum {
00150   SLOW_DECAY = 0,
00151   FAST_DECAY = 1,
00152   UNKNOW_DECAY = ((uint8_t)0xFF)
00153 } motorDecayMode_t;
00154 /**
00155   * @}
00156   */
00157   
00158 /** @defgroup Stop_mode Stop mode
00159   * @{
00160   */
00161 /// Stop mode
00162 typedef enum
00163 { 
00164   HOLD_MODE = 0,
00165   HIZ_MODE = 1,
00166   STANDBY_MODE = 2,
00167   UNKNOW_STOP_MODE = ((uint8_t)0xFF)
00168 } motorStopMode_t;
00169 /**
00170   * @}
00171   */  
00172 
00173 /** @defgroup Torque_mode Torque mode
00174   * @{
00175   */
00176 /// Torque mode
00177 typedef enum
00178 { 
00179   ACC_TORQUE = 0,
00180   DEC_TORQUE = 1,
00181   RUN_TORQUE = 2,
00182   HOLD_TORQUE = 3,
00183   CURRENT_TORQUE = 4,
00184   UNKNOW_TORQUE = ((uint8_t)0xFF)
00185 } motorTorqueMode_t;
00186 /**
00187   * @}
00188   */  
00189     
00190 /** @defgroup Dual_Full_Bridge_Configuration Dual Full Bridge Configuration
00191   * @{
00192   */
00193 ///Dual full bridge configurations for brush DC motors
00194 typedef enum {
00195   PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 0,
00196   PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 1,
00197   PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 2,
00198   PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 3,
00199   PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 4,
00200   PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 5,
00201   PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 6,
00202   PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 7,
00203   PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 8,
00204   PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR = 9,
00205   PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A = 10,
00206   PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR = 11,
00207   PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR = 12,
00208   PARALLELING_END_ENUM = 13 
00209 } dualFullBridgeConfig_t;
00210 /**
00211   * @}
00212   */
00213 
00214 /** @defgroup Motor_Driver_Structure Motor Driver Structure
00215   * @{
00216   */
00217 /** 
00218  * @brief  MOTOR driver virtual table structure definition.
00219  */  
00220 typedef struct
00221 {
00222   /* ACTION ----------------------------------------------------------------*
00223    * Declare here the component's generic functions.                        *
00224    * Tag this group of functions with the " Generic " C-style comment.      *
00225    * A component's interface has to define at least the two generic         *
00226    * functions provided here below within the "Example" section, as the     *
00227    * first and second functions of its Virtual Table. They have to be       *
00228    * specified exactly in the given way.                                    *
00229    *                                                                        *
00230    * Example:                                                               *
00231    *   Status_t (*Init)   (void *handle, void *init);                       *
00232    *   Status_t (*ReadID) (void *handle, uint8_t *id);                      *
00233    *------------------------------------------------------------------------*/
00234   /* Generic */
00235   Status_t (*Init)(void *handle, void *init);
00236   Status_t (*ReadID)(void *handle, uint8_t *id);
00237   /* ACTION ----------------------------------------------------------------*
00238    * Declare here the component's interrupts related functions.             *
00239    * Tag this group of functions with the " Interrupts " C-style comment.   *
00240    * Do not specify any function if not required.                           *
00241    *                                                                        *
00242    * Example:                                                               *
00243    *   void     (*ConfigIT) (void *handle, int a);                          *
00244    *------------------------------------------------------------------------*/
00245   /* Interrupts */
00246   /// Function pointer to AttachErrorHandler
00247   void (*AttachErrorHandler)(void *handle, void (*callback)(void *handle, uint16_t error));
00248   /// Function pointer to AttachFlagInterrupt
00249   void (*AttachFlagInterrupt)(void *handle, void (*callback)(void *handle));
00250   /// Function pointer to AttachBusyInterrupt
00251   void (*AttachBusyInterrupt)(void *handle, void (*callback)(void *handle));
00252   /// Function pointer to FlagInterruptHandler
00253   void (*FlagInterruptHandler)(void *handle);
00254   /* ACTION ----------------------------------------------------------------*
00255    * Declare here the component's specific functions.                       *
00256    * Tag this group of functions with the " Specific " C-style comment.     *
00257    * Do not specify any function if not required.                           *
00258    *                                                                        *
00259    * Example:                                                               *
00260    *   Status_t (*GetValue) (void *handle, float *f);                       *
00261    *------------------------------------------------------------------------*/
00262   /* Specific */  
00263   /// Function pointer to GetAcceleration
00264   uint16_t (*GetAcceleration)(void *handle); 
00265   /// Function pointer to GetCurrentSpeed
00266   uint16_t (*GetCurrentSpeed)(void *handle); 
00267   /// Function pointer to GetDeceleration
00268   uint16_t (*GetDeceleration)(void *handle); 
00269   /// Function pointer to GetDeviceState
00270   motorState_t(*GetDeviceState)(void *handle); 
00271   /// Function pointer to GetFwVersion
00272   uint8_t (*GetFwVersion)(void *handle); 
00273   /// Function pointer to GetMark
00274   int32_t (*GetMark)(void *handle); 
00275   /// Function pointer to GetMaxSpeed
00276   uint16_t (*GetMaxSpeed)(void *handle); 
00277   /// Function pointer to GetMinSpeed
00278   uint16_t (*GetMinSpeed)(void *handle); 
00279   /// Function pointer to GetPosition
00280   int32_t (*GetPosition)(void *handle);
00281   /// Function pointer to GoHome
00282   void (*GoHome)(void *handle); 
00283   /// Function pointer to GoMark
00284   void (*GoMark)(void *handle); 
00285   /// Function pointer to GoTo
00286   void (*GoTo)(void *handle, int32_t targetPosition); 
00287   /// Function pointer to HardStop
00288   void (*HardStop)(void *handle); 
00289   /// Function pointer to Move
00290   void (*Move)(void *handle, motorDir_t direction, uint32_t stepCount); 
00291   /// Function pointer to ResetAllDevices
00292   //void (*ResetAllDevices)(void *handle); 
00293   /// Function pointer to Run
00294   void (*Run)(void *handle, motorDir_t direction);
00295   /// Function pointer to SetAcceleration
00296   bool (*SetAcceleration)(void *handle, uint16_t newAcc);
00297   /// Function pointer to SetDeceleration
00298   bool (*SetDeceleration)(void *handle, uint16_t newDec);
00299   /// Function pointer to SetHome
00300   void (*SetHome)(void *handle); 
00301   /// Function pointer to SetMark
00302   void (*SetMark)(void *handle); 
00303   /// Function pointer to SetMaxSpeed
00304   bool (*SetMaxSpeed)(void *handle, uint16_t newMaxSpeed); 
00305   /// Function pointer to SetMinSpeed
00306   bool (*SetMinSpeed)(void *handle, uint16_t newMinSpeed); 
00307   /// Function pointer to SoftStop
00308   bool (*SoftStop)(void *handle); 
00309   /// Function pointer to StepClockHandler
00310   void (*StepClockHandler)(void *handle);  
00311   /// Function pointer to WaitWhileActive
00312   void (*WaitWhileActive)(void *handle);
00313   /// Function pointer to CmdDisable
00314   void (*CmdDisable)(void *handle); 
00315   /// Function pointer to CmdEnable
00316   void (*CmdEnable)(void *handle);
00317   /// Function pointer to CmdGetParam
00318   uint32_t (*CmdGetParam)(void *handle, uint32_t param);
00319   /// Function pointer to CmdGetStatus
00320   uint16_t (*CmdGetStatus)(void *handle); 
00321   /// Function pointer to CmdNop
00322   void (*CmdNop)(void *handle); 
00323   /// Function pointer to CmdSetParam
00324   void (*CmdSetParam)(void *handle, uint32_t param, uint32_t value);
00325   /// Function pointer to ReadStatusRegister
00326   uint16_t (*ReadStatusRegister)(void *handle); 
00327   /// Function pointer to ReleaseReset
00328   void (*ReleaseReset)(void *handle);
00329   /// Function pointer to Reset
00330   void (*Reset)(void *handle); 
00331   /// Function pointer to SelectStepMode
00332   void (*SelectStepMode)(void *handle, motorStepMode_t);
00333   /// Function pointer to SetDirection
00334   void (*SetDirection)(void *handle, motorDir_t direction);
00335   /// Function pointer to CmdGoToDir
00336   void (*CmdGoToDir)(void *handle, motorDir_t direction, int32_t targetPosition);
00337   /// Function pointer to CheckBusyHw
00338   uint8_t (*CheckBusyHw)(void *handle);
00339   /// Function pointer to CheckStatusHw
00340   uint8_t (*CheckStatusHw)(void *handle);
00341   /// Function pointer to CmdGoUntil
00342   void (*CmdGoUntil)(void *handle, motorAction_t action, motorDir_t direction, uint32_t targetPosition);
00343   /// Function pointer to CmdHardHiZ
00344   void (*CmdHardHiZ)(void *handle);
00345   /// Function pointer to CmdReleaseSw
00346   void (*CmdReleaseSw)(void *handle, motorAction_t action, motorDir_t direction);
00347   /// Function pointer to CmdResetDevice
00348   void (*CmdResetDevice)(void *handle);
00349   /// Function pointer to CmdResetPos
00350   void (*CmdResetPos)(void *handle);
00351   /// Function pointer to CmdRun
00352   void (*CmdRun)(void *handle, motorDir_t direction, uint32_t targetPosition);
00353   /// Function pointer to CmdSoftHiZ
00354   void (*CmdSoftHiZ)(void *handle);
00355   /// Function pointer to CmdStepClock
00356   void (*CmdStepClock)(void *handle, motorDir_t direction);
00357   /// Function pointer to FetchAndClearAllStatus
00358   void (*FetchAndClearAllStatus)(void *handle);
00359   /// Function pointer to GetFetchedStatus
00360   uint16_t (*GetFetchedStatus)(void *handle);
00361   /// Function pointer to GetNbDevices
00362   uint8_t (*GetNbDevices)(void *handle);
00363   /// Function pointer to IsDeviceBusy
00364   bool (*IsDeviceBusy)(void *handle);
00365   /// Function pointer to SendQueuedCommands
00366   void (*SendQueuedCommands)(void *handle);
00367   /// Function pointer to QueueCommands
00368   void (*QueueCommands)(void *handle, uint8_t command, int32_t value);
00369   /// Function pointer to WaitForAllDevicesNotBusy
00370   void (*WaitForAllDevicesNotBusy)(void *handle);
00371   /// Function pointer to ErrorHandler
00372   void (*ErrorHandler)(void *handle, uint16_t error);
00373   /// Function pointer to BusyInterruptHandler
00374   void (*BusyInterruptHandler)(void *handle);
00375   /// Function pointer to CmdSoftStop
00376   void (*CmdSoftStop)(void *handle);
00377   /// Function pointer to StartStepClock
00378   void (*StartStepClock)(void *handle, uint16_t newFreq);
00379   /// Function pointer to StopStepClock
00380   void (*StopStepClock)(void *handle);
00381   /// Function pointer to SetDualFullBridgeConfig
00382   void (*SetDualFullBridgeConfig)(void *handle, uint8_t config);
00383   /// Function pointer to GetBridgeInputPwmFreq
00384   uint32_t (*GetBridgeInputPwmFreq)(void *handle);
00385   /// Function pointer to SetBridgeInputPwmFreq
00386   void (*SetBridgeInputPwmFreq)(void *handle, uint32_t newFreq);
00387   /// Function pointer to SetStopMode
00388   void (*SetStopMode)(void *handle, motorStopMode_t stopMode);
00389   /// Function pointer to GetStopMode
00390   motorStopMode_t (*GetStopMode)(void *handle);
00391   /// Function pointer to SetDecayMode
00392   void (*SetDecayMode)(void *handle, motorDecayMode_t decayMode);
00393   /// Function pointer to GetDecayMode
00394   motorDecayMode_t (*GetDecayMode)(void *handle);
00395   /// Function pointer to GetStepMode
00396   motorStepMode_t (*GetStepMode)(void *handle);
00397   /// Function pointer to GetDirection
00398   motorDir_t (*GetDirection)(void *handle);
00399   /// Function pointer to ExitDeviceFromReset
00400   void (*ExitDeviceFromReset)(void *handle);
00401   /// Function pointer to SetTorque
00402   void (*SetTorque)(void *handle, motorTorqueMode_t torqueMode, uint8_t torqueValue);
00403   /// Function pointer to GetTorque
00404   uint8_t (*GetTorque)(void *handle, motorTorqueMode_t torqueMode);
00405   /// Function pointer to SetVRefFreq
00406   void (*SetRefFreq)(void *handle, uint32_t newFreq);
00407   /// Function pointer to GetVRefFreq
00408   uint32_t (*GetRefFreq)(void *handle);
00409   /// Function pointer to SetVRefDc
00410   void (*SetRefDc)(void *handle, uint8_t newDc);
00411   /// Function pointer to GetVRefDc
00412   uint8_t (*GetRefDc)(void *handle);
00413   /// Function pointer to SetNbDevices
00414   bool (*SetNbDevices)(void *handle, uint8_t nbDevices);
00415   /// Function pointer to set a parameter
00416   bool (*SetAnalogValue)(void *handle, uint32_t param, float value);
00417   /// Function pointer to get a parameter 
00418   float (*GetAnalogValue)(void *handle, uint32_t param); 
00419 } MOTOR_VTable_t;
00420 /**
00421 * @}
00422   */
00423 
00424 /**
00425   * @}
00426   */ 
00427 
00428 /**
00429   * @}
00430   */
00431   
00432 /**
00433   * @}
00434   */ 
00435 
00436 /**
00437   * @}
00438   */ 
00439 
00440 #ifdef __cplusplus
00441 }
00442 #endif
00443 
00444 #endif /* __MOTOR_H */
00445 
00446 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/