Expansion SW library to control a bipolar stepper motor using X-NUCLEO-IHM05A1 expansion board based on L6208.

Dependencies:   ST_INTERFACES

Dependents:   HelloWorld_IHM05A1 TAU_ROTATING_PLATFORM_IHM05A1 Amaldi_13_Exercise_IHM05A1 Amaldi_13_Exercise_IHM05A1motore ... more

Fork of X-NUCLEO-IHM05A1 by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motor_def.h Source File

motor_def.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    motor_def.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_def.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 (*read_id) (void *handle, uint8_t *id);                      *
00233    *------------------------------------------------------------------------*/
00234   /* Generic */
00235   status_t (*init)(void *handle, void *init);
00236   status_t (*read_id)(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 attach_error_handler
00247   void (*attach_error_handler)(void *handle, void (*callback)(void *handle, uint16_t error));
00248   /// Function pointer to attach_flag_interrupt
00249   void (*attach_flag_interrupt)(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 get_acceleration
00264   uint16_t (*get_acceleration)(void *handle); 
00265   /// Function pointer to GetCurrentSpeed
00266   uint16_t (*GetCurrentSpeed)(void *handle); 
00267   /// Function pointer to get_deceleration
00268   uint16_t (*get_deceleration)(void *handle); 
00269   /// Function pointer to get_device_state
00270   motorState_t(*get_device_state)(void *handle); 
00271   /// Function pointer to get_fw_version
00272   uint8_t (*get_fw_version)(void *handle); 
00273   /// Function pointer to get_mark
00274   int32_t (*get_mark)(void *handle); 
00275   /// Function pointer to get_max_speed
00276   uint16_t (*get_max_speed)(void *handle); 
00277   /// Function pointer to get_min_speed
00278   uint16_t (*get_min_speed)(void *handle); 
00279   /// Function pointer to get_position
00280   int32_t (*get_position)(void *handle);
00281   /// Function pointer to go_home
00282   void (*go_home)(void *handle); 
00283   /// Function pointer to go_mark
00284   void (*go_mark)(void *handle); 
00285   /// Function pointer to go_to
00286   void (*go_to)(void *handle, int32_t targetPosition); 
00287   /// Function pointer to hard_stop
00288   void (*hard_stop)(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 set_acceleration
00296   bool (*set_acceleration)(void *handle, uint16_t newAcc);
00297   /// Function pointer to set_deceleration
00298   bool (*set_deceleration)(void *handle, uint16_t newDec);
00299   /// Function pointer to set_home
00300   void (*set_home)(void *handle); 
00301   /// Function pointer to set_mark
00302   void (*set_mark)(void *handle); 
00303   /// Function pointer to set_max_speed
00304   bool (*set_max_speed)(void *handle, uint16_t newMaxSpeed); 
00305   /// Function pointer to set_min_speed
00306   bool (*set_min_speed)(void *handle, uint16_t newMinSpeed); 
00307   /// Function pointer to soft_stop
00308   bool (*soft_stop)(void *handle); 
00309   /// Function pointer to StepClockHandler
00310   void (*StepClockHandler)(void *handle);  
00311   /// Function pointer to wait_while_active
00312   void (*wait_while_active)(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 read_status_register
00326   uint16_t (*read_status_register)(void *handle); 
00327   /// Function pointer to release_reset
00328   void (*release_reset)(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 set_direction
00334   void (*set_direction)(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 check_busy_hw
00338   uint8_t (*check_busy_hw)(void *handle);
00339   /// Function pointer to check_status_hw
00340   uint8_t (*check_status_hw)(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 fetch_and_clear_all_status
00358   void (*fetch_and_clear_all_status)(void *handle);
00359   /// Function pointer to get_fetched_status
00360   uint16_t (*get_fetched_status)(void *handle);
00361   /// Function pointer to get_nb_devices
00362   uint8_t (*get_nb_devices)(void *handle);
00363   /// Function pointer to is_device_busy
00364   bool (*is_device_busy)(void *handle);
00365   /// Function pointer to send_queued_commands
00366   void (*send_queued_commands)(void *handle);
00367   /// Function pointer to queue_commands
00368   void (*queue_commands)(void *handle, uint8_t command, int32_t value);
00369   /// Function pointer to WaitForAllDevicesNotBusy
00370   void (*WaitForAllDevicesNotBusy)(void *handle);
00371   /// Function pointer to error_handler
00372   void (*error_handler)(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 set_dual_full_bridge_config
00382   void (*set_dual_full_bridge_config)(void *handle, uint8_t config);
00383   /// Function pointer to get_bridge_input_pwm_freq
00384   uint32_t (*get_bridge_input_pwm_freq)(void *handle);
00385   /// Function pointer to set_bridge_input_pwm_freq
00386   void (*set_bridge_input_pwm_freq)(void *handle, uint32_t newFreq);
00387   /// Function pointer to set_stop_mode
00388   void (*set_stop_mode)(void *handle, motorStopMode_t stopMode);
00389   /// Function pointer to get_stop_mode
00390   motorStopMode_t (*get_stop_mode)(void *handle);
00391   /// Function pointer to set_decay_mode
00392   void (*set_decay_mode)(void *handle, motorDecayMode_t decayMode);
00393   /// Function pointer to get_decay_mode
00394   motorDecayMode_t (*get_decay_mode)(void *handle);
00395   /// Function pointer to get_step_mode
00396   motorStepMode_t (*get_step_mode)(void *handle);
00397   /// Function pointer to get_direction
00398   motorDir_t (*get_direction)(void *handle);
00399   /// Function pointer to ExitDeviceFromReset
00400   void (*ExitDeviceFromReset)(void *handle);
00401   /// Function pointer to set_torque
00402   void (*set_torque)(void *handle, motorTorqueMode_t torqueMode, uint8_t torqueValue);
00403   /// Function pointer to get_torque
00404   uint8_t (*get_torque)(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 set_nb_devices
00414   bool (*set_nb_devices)(void *handle, uint8_t nbDevices);
00415   /// Function pointer to set a parameter
00416   bool (*set_analog_value)(void *handle, uint32_t param, float value);
00417   /// Function pointer to get a parameter 
00418   float (*get_analog_value)(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****/