Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
motor_def.h
00001 /** 00002 ****************************************************************************** 00003 * @file motor_def.h 00004 * @author STM 00005 * @version V1.7.0 00006 * @date August 7th, 2017 00007 * @brief This file contains all the functions prototypes for motor drivers. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© 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 00039 /* Define to prevent recursive inclusion -------------------------------------*/ 00040 00041 #ifndef __MOTOR_H 00042 #define __MOTOR_H 00043 00044 #ifdef __cplusplus 00045 extern "C" { 00046 #endif 00047 00048 00049 /* Includes ------------------------------------------------------------------*/ 00050 00051 #include <stdint.h> 00052 #include "component_def.h" 00053 00054 /** @addtogroup BSP 00055 * @{ 00056 */ 00057 00058 /** @addtogroup Components 00059 * @{ 00060 */ 00061 00062 /** @defgroup Motor Motor 00063 * @{ 00064 */ 00065 00066 /** @defgroup Motor_Exported_Constants Motor Exported Constants 00067 * @{ 00068 */ 00069 00070 00071 /// boolean for false condition 00072 #ifndef FALSE 00073 #define FALSE (0) 00074 #endif 00075 /// boolean for true condition 00076 #ifndef TRUE 00077 #define TRUE (1) 00078 #endif 00079 00080 /** 00081 * @} 00082 */ 00083 00084 /** @defgroup Motor_Exported_Types Motor Exported Types 00085 * @{ 00086 */ 00087 00088 /** @defgroup Motor_Boolean_Type Motor Boolean Type 00089 * @{ 00090 */ 00091 ///bool Type 00092 typedef uint8_t bool; 00093 /** 00094 * @} 00095 */ 00096 00097 /** @defgroup Device_Direction_Options Device Direction Options 00098 * @{ 00099 */ 00100 /// Direction options 00101 typedef enum { 00102 BACKWARD = 0, 00103 FORWARD = 1, 00104 UNKNOW_DIR = ((uint8_t)0xFF) 00105 } motor_direction_t; 00106 /** 00107 * @} 00108 */ 00109 00110 /** @defgroup Device_Action_Options Device Action Options 00111 * @{ 00112 */ 00113 /// Action options 00114 typedef enum { 00115 ACTION_RESET = ((uint8_t)0x00), 00116 ACTION_COPY = ((uint8_t)0x08) 00117 } motor_action_t; 00118 /** 00119 * @} 00120 */ 00121 00122 /** @defgroup Device_States Device States 00123 * @{ 00124 */ 00125 /// Device states 00126 typedef enum { 00127 ACCELERATING = 0, 00128 DECELERATINGTOSTOP = 1, 00129 DECELERATING = 2, 00130 STEADY = 3, 00131 INDEX_ACCEL = 4, 00132 INDEX_RUN = 5, 00133 INDEX_DECEL = 6, 00134 INDEX_DWELL = 7, 00135 INACTIVE = 8, 00136 STANDBY = 9, 00137 STANDBYTOINACTIVE = 10 00138 } motor_state_t; 00139 /** 00140 * @} 00141 */ 00142 00143 /** @defgroup Device_Step_mode Device Step mode 00144 * @{ 00145 */ 00146 /// Stepping options 00147 typedef enum { 00148 STEP_MODE_FULL = ((uint8_t)0x00), 00149 STEP_MODE_HALF = ((uint8_t)0x01), 00150 STEP_MODE_1_4 = ((uint8_t)0x02), 00151 STEP_MODE_1_8 = ((uint8_t)0x03), 00152 STEP_MODE_1_16 = ((uint8_t)0x04), 00153 STEP_MODE_1_32 = ((uint8_t)0x05), 00154 STEP_MODE_1_64 = ((uint8_t)0x06), 00155 STEP_MODE_1_128 = ((uint8_t)0x07), 00156 STEP_MODE_1_256 = ((uint8_t)0x08), 00157 STEP_MODE_UNKNOW = ((uint8_t)0xFE), 00158 STEP_MODE_WAVE = ((uint8_t)0xFF) 00159 } motor_step_mode_t; 00160 00161 /** 00162 * @} 00163 */ 00164 00165 /** @defgroup Decay_mode Decay mode 00166 * @{ 00167 */ 00168 /// Decay Mode 00169 typedef enum { 00170 SLOW_DECAY = 0, 00171 FAST_DECAY = 1, 00172 MIXED_DECAY = 2, 00173 UNKNOW_DECAY = ((uint8_t)0xFF) 00174 } motor_decay_mode_t; 00175 /** 00176 * @} 00177 */ 00178 00179 /** @defgroup Stop_mode Stop mode 00180 * @{ 00181 */ 00182 /// Stop mode 00183 typedef enum 00184 { 00185 HOLD_MODE = 0, 00186 HIZ_MODE = 1, 00187 STANDBY_MODE = 2, 00188 UNKNOW_STOP_MODE = ((uint8_t)0xFF) 00189 } motor_stop_mode_t; 00190 /** 00191 * @} 00192 */ 00193 00194 /** @defgroup Torque_mode Torque mode 00195 * @{ 00196 */ 00197 /// Torque mode 00198 typedef enum 00199 { 00200 ACC_TORQUE = 0, 00201 DEC_TORQUE = 1, 00202 RUN_TORQUE = 2, 00203 HOLD_TORQUE = 3, 00204 CURRENT_TORQUE = 4, 00205 UNKNOW_TORQUE = ((uint8_t)0xFF) 00206 } motor_torque_mode_t; 00207 /** 00208 * @} 00209 */ 00210 00211 /** @defgroup Dual_Full_Bridge_Configuration Dual Full Bridge Configuration 00212 * @{ 00213 */ 00214 ///Dual full bridge configurations for brush DC motors 00215 typedef enum { 00216 PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 0, 00217 PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 1, 00218 PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 2, 00219 PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 3, 00220 PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 4, 00221 PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 5, 00222 PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 6, 00223 PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 7, 00224 PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 8, 00225 PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR = 9, 00226 PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A = 10, 00227 PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR = 11, 00228 PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR = 12, 00229 PARALLELING_END_ENUM = 13 00230 } dual_full_bridge_config_t; 00231 /** 00232 * @} 00233 */ 00234 00235 /** @defgroup Motor_Driver_Structure Motor Driver Structure 00236 * @{ 00237 */ 00238 /// Motor driver structure definition 00239 typedef struct 00240 { 00241 /* ACTION ----------------------------------------------------------------* 00242 * Declare here the component's generic functions. * 00243 * Tag this group of functions with the " Generic " C-style comment. * 00244 * A component's interface has to define at least the two generic * 00245 * functions provided here below within the "Example" section, as the * 00246 * first and second functions of its Virtual Table. They have to be * 00247 * specified exactly in the given way. * 00248 * * 00249 * Example: * 00250 * status_t (*Init) (void *handle, void *init); * 00251 * status_t (*ReadID) (void *handle, uint8_t *id); * 00252 *------------------------------------------------------------------------*/ 00253 /* Generic */ 00254 /// Function pointer to Init 00255 status_t (*Init)(void *handle, void *init); 00256 /// Function pointer to ReadID 00257 status_t (*ReadID)(void *handle, uint8_t *id); 00258 00259 /* ACTION ----------------------------------------------------------------* 00260 * Declare here the component's interrupts related functions. * 00261 * Tag this group of functions with the " Interrupts " C-style comment. * 00262 * Do not specify any function if not required. * 00263 * * 00264 * Example: * 00265 * void (*ConfigIT) (void *handle, int a); * 00266 *------------------------------------------------------------------------*/ 00267 /* Interrupts */ 00268 /// Function pointer to AttachErrorHandler 00269 void(*AttachErrorHandler)(void *handle, void (*callback)(void *handle, uint16_t error)); 00270 /// Function pointer to AttachFlagInterrupt 00271 void (*AttachFlagInterrupt)(void *handle, void (*callback)(void *handle)); 00272 /// Function pointer to AttachBusyInterrupt 00273 void (*AttachBusyInterrupt)(void *handle, void (*callback)(void *handle)); 00274 /// Function pointer to FlagInterruptHandler 00275 void (*FlagInterruptHandler)(void *handle); 00276 00277 /* ACTION ----------------------------------------------------------------* 00278 * Declare here the component's specific functions. * 00279 * Tag this group of functions with the " Specific " C-style comment. * 00280 * Do not specify any function if not required. * 00281 * * 00282 * Example: * 00283 * status_t (*GetValue) (void *handle, float *f); * 00284 *------------------------------------------------------------------------*/ 00285 /* Specific */ 00286 /// Function pointer to GetAcceleration 00287 uint16_t (*GetAcceleration)(void *handle, uint8_t deviceId); 00288 /// Function pointer to GetCurrentSpeed 00289 uint16_t (*GetCurrentSpeed)(void *handle, uint8_t deviceId); 00290 /// Function pointer to GetDeceleration 00291 uint16_t (*GetDeceleration)(void *handle, uint8_t deviceId); 00292 /// Function pointer to GetDeviceState 00293 motor_state_t(*GetDeviceState)(void *handle, uint8_t deviceId); 00294 /// Function pointer to GetFwVersion 00295 uint32_t (*GetFwVersion)(void *handle); 00296 /// Function pointer to GetMark 00297 int32_t (*GetMark)(void *handle, uint8_t deviceId); 00298 /// Function pointer to GetMaxSpeed 00299 uint16_t (*GetMaxSpeed)(void *handle, uint8_t deviceId); 00300 /// Function pointer to GetMinSpeed 00301 uint16_t (*GetMinSpeed)(void *handle, uint8_t deviceId); 00302 /// Function pointer to GetPosition 00303 int32_t (*GetPosition)(void *handle, uint8_t deviceId); 00304 /// Function pointer to GoHome 00305 void (*GoHome)(void *handle, uint8_t deviceId); 00306 /// Function pointer to GoMark 00307 void (*GoMark)(void *handle, uint8_t deviceId); 00308 /// Function pointer to GoTo 00309 void (*GoTo)(void *handle, uint8_t deviceId, int32_t targetPosition); 00310 /// Function pointer to HardStop 00311 void (*HardStop)(void *handle, uint8_t deviceId); 00312 /// Function pointer to Move 00313 void (*Move)(void *handle, uint8_t deviceId, motor_direction_t direction, uint32_t stepCount); 00314 /// Function pointer to ResetAllDevices 00315 void (*ResetAllDevices)(void *handle); 00316 /// Function pointer to Run 00317 void (*Run)(void *handle, uint8_t deviceId, motor_direction_t direction); 00318 /// Function pointer to SetAcceleration 00319 bool(*SetAcceleration)(void *handle, uint8_t deviceId, uint16_t newAcc); 00320 /// Function pointer to SetDeceleration 00321 bool(*SetDeceleration)(void *handle, uint8_t deviceId, uint16_t newDec); 00322 /// Function pointer to SetHome 00323 void (*SetHome)(void *handle, uint8_t deviceId); 00324 /// Function pointer to SetMark 00325 void (*SetMark)(void *handle, uint8_t deviceId); 00326 /// Function pointer to SetMaxSpeed 00327 bool (*SetMaxSpeed)(void *handle, uint8_t deviceId, uint16_t newMaxSpeed); 00328 /// Function pointer to SetMinSpeed 00329 bool (*SetMinSpeed)(void *handle, uint8_t deviceId, uint16_t newMinSpeed); 00330 /// Function pointer to SoftStop 00331 bool (*SoftStop)(void *handle, uint8_t deviceId); 00332 /// Function pointer to StepClockHandler 00333 void (*StepClockHandler)(void *handle, uint8_t deviceId); 00334 /// Function pointer to WaitWhileActive 00335 void (*WaitWhileActive)(void *handle, uint8_t deviceId); 00336 /// Function pointer to CmdDisable 00337 void (*CmdDisable)(void *handle, uint8_t deviceId); 00338 /// Function pointer to CmdEnable 00339 void (*CmdEnable)(void *handle, uint8_t deviceId); 00340 /// Function pointer to CmdGetParam 00341 uint32_t (*CmdGetParam)(void *handle, uint8_t deviceId, uint32_t cmd); 00342 /// Function pointer to CmdGetStatus 00343 uint16_t (*CmdGetStatus)(void *handle, uint8_t deviceId); 00344 /// Function pointer to CmdNop 00345 void (*CmdNop)(void *handle, uint8_t deviceId); 00346 /// Function pointer to CmdSetParam 00347 void (*CmdSetParam)(void *handle, uint8_t deviceId, uint32_t cmd, uint32_t param); 00348 /// Function pointer to ReadStatusRegister 00349 uint16_t (*ReadStatusRegister)(void *handle, uint8_t deviceId); 00350 /// Function pointer to ReleaseReset 00351 void (*ReleaseReset)(void *handle, uint8_t deviceId); 00352 /// Function pointer to Reset 00353 void (*Reset)(void *handle, uint8_t deviceId); 00354 /// Function pointer to SelectStepMode 00355 bool (*SelectStepMode)(void *handle, uint8_t deviceId, motor_step_mode_t stepMode); 00356 /// Function pointer to SetDirection 00357 void (*SetDirection)(void *handle, uint8_t deviceId, motor_direction_t direction); 00358 /// Function pointer to CmdGoToDir 00359 void (*CmdGoToDir)(void *handle, uint8_t deviceId, motor_direction_t direction, int32_t targetPosition); 00360 /// Function pointer to CheckBusyHw 00361 uint8_t (*CheckBusyHw)(void *handle); 00362 /// Function pointer to CheckStatusHw 00363 uint8_t (*CheckStatusHw)(void *handle); 00364 /// Function pointer to CmdGoUntil 00365 void (*CmdGoUntil)(void *handle, uint8_t deviceId, motor_action_t action, motor_direction_t direction, uint32_t position); 00366 /// Function pointer to CmdHardHiZ 00367 void (*CmdHardHiZ)(void *handle, uint8_t deviceId); 00368 /// Function pointer to CmdReleaseSw 00369 void (*CmdReleaseSw)(void *handle, uint8_t deviceId, motor_action_t action, motor_direction_t direction); 00370 /// Function pointer to CmdResetDevice 00371 void (*CmdResetDevice)(void *handle, uint8_t deviceId); 00372 /// Function pointer to CmdResetPos 00373 void (*CmdResetPos)(void *handle, uint8_t deviceId); 00374 /// Function pointer to CmdRun 00375 void (*CmdRun)(void *handle, uint8_t deviceId, motor_direction_t position, uint32_t p); 00376 /// Function pointer to CmdSoftHiZ 00377 void (*CmdSoftHiZ)(void *handle, uint8_t deviceId); 00378 /// Function pointer to CmdStepClock 00379 void (*CmdStepClock)(void *handle, uint8_t deviceId, motor_direction_t direction); 00380 /// Function pointer to FetchAndClearAllStatus 00381 void (*FetchAndClearAllStatus)(void *handle); 00382 /// Function pointer to GetFetchedStatus 00383 uint16_t (*GetFetchedStatus)(void *handle, uint8_t deviceId); 00384 /// Function pointer to GetNbDevices 00385 uint8_t (*GetNbDevices)(void *handle); 00386 /// Function pointer to IsDeviceBusy 00387 bool (*IsDeviceBusy)(void *handle, uint8_t deviceId); 00388 /// Function pointer to SendQueuedCommands 00389 void (*SendQueuedCommands)(void *handle); 00390 /// Function pointer to QueueCommands 00391 void (*QueueCommands)(void *handle, uint8_t deviceId, uint8_t p1, int32_t p2); 00392 /// Function pointer to WaitForAllDevicesNotBusy 00393 void (*WaitForAllDevicesNotBusy)(void *handle); 00394 /// Function pointer to ErrorHandler 00395 void (*ErrorHandler)(void *handle, uint16_t error); 00396 /// Function pointer to BusyInterruptHandler 00397 void (*BusyInterruptHandler)(void *handle); 00398 /// Function pointer to CmdSoftStop 00399 void (*CmdSoftStop)(void *handle, uint8_t deviceId); 00400 /// Function pointer to StartStepClock 00401 void (*StartStepClock)(void *handle, uint16_t p); 00402 /// Function pointer to StopStepClock 00403 void (*StopStepClock)(void *handle); 00404 /// Function pointer to SetDualFullBridgeConfig 00405 void (*SetDualFullBridgeConfig)(void *handle, uint8_t deviceId); 00406 /// Function pointer to GetBridgeInputPwmFreq 00407 uint32_t (*GetBridgeInputPwmFreq)(void *handle, uint8_t deviceId); 00408 /// Function pointer to SetBridgeInputPwmFreq 00409 void (*SetBridgeInputPwmFreq)(void *handle, uint8_t deviceId, uint32_t newFreq); 00410 /// Function pointer to SetStopMode 00411 void (*SetStopMode)(void *handle, uint8_t deviceId, motor_stop_mode_t stopMode); 00412 /// Function pointer to GetStopMode 00413 motor_stop_mode_t (*GetStopMode)(void *handle, uint8_t deviceId); 00414 /// Function pointer to SetDecayMode 00415 void (*SetDecayMode)(void *handle, uint8_t deviceId, motor_decay_mode_t decayMode); 00416 /// Function pointer to GetDecayMode 00417 motor_decay_mode_t (*GetDecayMode)(void *handle, uint8_t deviceId); 00418 /// Function pointer to GetStepMode 00419 motor_step_mode_t (*GetStepMode)(void *handle, uint8_t deviceId); 00420 /// Function pointer to GetDirection 00421 motor_direction_t (*GetDirection)(void *handle, uint8_t deviceId); 00422 /// Function pointer to ExitDeviceFromReset 00423 void (*ExitDeviceFromReset)(void *handle, uint8_t deviceId); 00424 /// Function pointer to SetTorque 00425 void (*SetTorque)(void *handle, uint8_t deviceId, motor_torque_mode_t torqueMode, uint8_t torqueValue); 00426 /// Function pointer to GetTorque 00427 uint8_t (*GetTorque)(void *handle, uint8_t deviceId, motor_torque_mode_t torqueMode); 00428 /// Function pointer to SetVRefFreq 00429 void (*SetRefFreq)(void *handle, uint8_t deviceId, uint32_t refFreq); 00430 /// Function pointer to GetVRefFreq 00431 uint32_t (*GetRefFreq)(void *handle, uint8_t deviceId); 00432 /// Function pointer to SetVRefDc 00433 void (*SetRefDc)(void *handle, uint8_t deviceId, uint8_t refDc); 00434 /// Function pointer to GetVRefDc 00435 uint8_t (*GetRefDc)(void *handle, uint8_t deviceId); 00436 /// Function pointer to SetNbDevices 00437 bool (*SetNbDevices)(void *handle, uint8_t deviceId); 00438 /// Function pointer to SetAnalogValue 00439 bool (*SetAnalogValue)(void *handle, uint8_t deviceId, uint32_t param, float value); 00440 /// Function pointer to GetAnalogValue 00441 float (*GetAnalogValue)(void *handle, uint8_t deviceId, uint32_t param); 00442 /// Function pointer to SetTorqueBoostEnable 00443 void (*SetTorqueBoostEnable)(void *handle, uint8_t deviceId, bool enable); 00444 /// Function pointer to GetTorqueBoostEnable 00445 bool (*GetTorqueBoostEnable)(void *handle, uint8_t deviceId); 00446 /// Function pointer to SetTorqueBoostThreshold 00447 void (*SetTorqueBoostThreshold)(void *handle, uint8_t deviceId, uint16_t speedThreshold); 00448 /// Function pointer to GetTorqueBoostThreshold 00449 uint16_t (*GetTorqueBoostThreshold)(void *handle, uint8_t deviceId); 00450 } MOTOR_vt_t; 00451 00452 /** 00453 00454 * @} 00455 */ 00456 00457 /** 00458 * @} 00459 */ 00460 00461 /** 00462 * @} 00463 */ 00464 00465 /** 00466 * @} 00467 */ 00468 00469 /** 00470 * @} 00471 */ 00472 00473 #ifdef __cplusplus 00474 } 00475 #endif 00476 00477 #endif /* __MOTOR_H */ 00478 00479 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Sat Jul 16 2022 06:19:57 by
1.7.2