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.
Fork of X_NUCLEO_IHM04A1 by
motor.h
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>© 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 /** @addtogroup BSP 00051 * @{ 00052 */ 00053 00054 /** @addtogroup Components 00055 * @{ 00056 */ 00057 00058 /** @defgroup Motor Motor 00059 * @{ 00060 */ 00061 00062 /** @defgroup Motor_Exported_Constants Motor Exported Constants 00063 * @{ 00064 */ 00065 00066 /// boolean for false condition 00067 #ifndef FALSE 00068 #define FALSE (0) 00069 #endif 00070 /// boolean for true condition 00071 #ifndef TRUE 00072 #define TRUE (1) 00073 #endif 00074 00075 /** 00076 * @} 00077 */ 00078 00079 /** @defgroup Motor_Exported_Types Motor Exported Types 00080 * @{ 00081 */ 00082 00083 /** @defgroup Motor_Boolean_Type Motor Boolean Type 00084 * @{ 00085 */ 00086 ///bool Type 00087 //typedef uint8_t bool; 00088 /** 00089 * @} 00090 */ 00091 00092 /** @defgroup Device_Direction_Options Device Direction Options 00093 * @{ 00094 */ 00095 /// Direction options 00096 typedef enum { 00097 BACKWARD = 0, 00098 FORWARD = 1, 00099 UNKNOW_DIR = ((uint8_t)0xFF) 00100 } motorDir_t; 00101 /** 00102 * @} 00103 */ 00104 00105 /** @defgroup Device_Action_Options Device Action Options 00106 * @{ 00107 */ 00108 /// Action options 00109 typedef enum { 00110 ACTION_RESET = ((uint8_t)0x00), 00111 ACTION_COPY = ((uint8_t)0x08) 00112 } motorAction_t; 00113 /** 00114 * @} 00115 */ 00116 00117 /** @defgroup Device_States Device States 00118 * @{ 00119 */ 00120 /// Device states 00121 typedef enum { 00122 ACCELERATING = 0, 00123 DECELERATINGTOSTOP = 1, 00124 DECELERATING = 2, 00125 STEADY = 3, 00126 INDEX_ACCEL = 4, 00127 INDEX_RUN = 5, 00128 INDEX_DECEL = 6, 00129 INDEX_DWELL = 7, 00130 INACTIVE = 8, 00131 STANDBY = 9, 00132 STANDBYTOINACTIVE = 10 00133 } motorState_t; 00134 /** 00135 * @} 00136 */ 00137 00138 /** @defgroup Device_Step_mode Device Step mode 00139 * @{ 00140 */ 00141 /// Stepping options 00142 typedef enum { 00143 STEP_MODE_FULL = ((uint8_t)0x00), 00144 STEP_MODE_HALF = ((uint8_t)0x01), 00145 STEP_MODE_1_4 = ((uint8_t)0x02), 00146 STEP_MODE_1_8 = ((uint8_t)0x03), 00147 STEP_MODE_1_16 = ((uint8_t)0x04), 00148 STEP_MODE_1_32 = ((uint8_t)0x05), 00149 STEP_MODE_1_64 = ((uint8_t)0x06), 00150 STEP_MODE_1_128 = ((uint8_t)0x07), 00151 STEP_MODE_1_256 = ((uint8_t)0x08), 00152 STEP_MODE_UNKNOW = ((uint8_t)0xFE), 00153 STEP_MODE_WAVE = ((uint8_t)0xFF) 00154 } motorStepMode_t; 00155 00156 /** 00157 * @} 00158 */ 00159 00160 /** @defgroup Decay_mode Decay mode 00161 * @{ 00162 */ 00163 /// Decay Mode 00164 typedef enum { 00165 SLOW_DECAY = 0, 00166 FAST_DECAY = 1, 00167 UNKNOW_DECAY = ((uint8_t)0xFF) 00168 } motorDecayMode_t; 00169 /** 00170 * @} 00171 */ 00172 00173 /** @defgroup Stop_mode Stop mode 00174 * @{ 00175 */ 00176 /// Stop mode 00177 typedef enum 00178 { 00179 HOLD_MODE = 0, 00180 HIZ_MODE = 1, 00181 STANDBY_MODE = 2, 00182 UNKNOW_STOP_MODE = ((uint8_t)0xFF) 00183 } motorStopMode_t; 00184 /** 00185 * @} 00186 */ 00187 00188 /** @defgroup Torque_mode Torque mode 00189 * @{ 00190 */ 00191 /// Torque mode 00192 typedef enum 00193 { 00194 ACC_TORQUE = 0, 00195 DEC_TORQUE = 1, 00196 RUN_TORQUE = 2, 00197 HOLD_TORQUE = 3, 00198 CURRENT_TORQUE = 4, 00199 UNKNOW_TORQUE = ((uint8_t)0xFF) 00200 } motorTorqueMode_t; 00201 /** 00202 * @} 00203 */ 00204 00205 /** @defgroup Dual_Full_Bridge_Configuration Dual Full Bridge Configuration 00206 * @{ 00207 */ 00208 ///Dual full bridge configurations for brush DC motors 00209 typedef enum { 00210 PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 0, 00211 PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 1, 00212 PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 2, 00213 PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 3, 00214 PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 4, 00215 PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 5, 00216 PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 6, 00217 PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 7, 00218 PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 8, 00219 PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR = 9, 00220 PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A = 10, 00221 PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR = 11, 00222 PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR = 12, 00223 PARALLELING_END_ENUM = 13 00224 } dualFullBridgeConfig_t; 00225 /** 00226 * @} 00227 */ 00228 00229 /** @defgroup Motor_Driver_Structure Motor Driver Structure 00230 * @{ 00231 */ 00232 /// Motor driver structure definition 00233 typedef struct 00234 { 00235 00236 /* Generic */ 00237 Status_t (*Init)(void *handle, void *init); 00238 Status_t (*ReadID)(void *handle, uint8_t *id); 00239 00240 /* Interrupts */ 00241 /// Function pointer to AttachErrorHandler 00242 void(*AttachErrorHandler)(void *handle, void (*callback)(void *handle, uint16_t error)); 00243 /// Function pointer to AttachFlagInterrupt 00244 void (*AttachFlagInterrupt)(void *handle, void (*callback)(void *handle)); 00245 /// Function pointer to AttachBusyInterrupt 00246 void (*AttachBusyInterrupt)(void *handle, void (*callback)(void *handle)); 00247 /// Function pointer to FlagInterruptHandler 00248 void (*FlagInterruptHandler)(void *handle); 00249 00250 /* Specific */ 00251 /// Function pointer to GetAcceleration 00252 uint16_t (*GetAcceleration)(void *handle); 00253 /// Function pointer to GetCurrentSpeed 00254 uint16_t (*GetCurrentSpeed)(void *handle, uint8_t motorId); 00255 /// Function pointer to GetDeceleration 00256 uint16_t (*GetDeceleration)(void *handle); 00257 /// Function pointer to GetDeviceState 00258 motorState_t(*GetDeviceState)(void *handle, uint8_t motorId); 00259 /// Function pointer to GetFwVersion 00260 uint8_t (*GetFwVersion)(void *handle); 00261 /// Function pointer to GetMark 00262 int32_t (*GetMark)(void *handle); 00263 /// Function pointer to GetMaxSpeed 00264 uint16_t (*GetMaxSpeed)(void *handle, uint8_t motorId); 00265 /// Function pointer to GetMinSpeed 00266 uint16_t (*GetMinSpeed)(void *handle, uint8_t motorId); 00267 /// Function pointer to GetPosition 00268 int32_t (*GetPosition)(void *handle); 00269 /// Function pointer to GoHome 00270 void (*GoHome)(void *handle); 00271 /// Function pointer to GoMark 00272 void (*GoMark)(void *handle); 00273 /// Function pointer to GoTo 00274 void (*GoTo)(void *handle, uint8_t deviceId, int32_t motorId); 00275 /// Function pointer to HardStop 00276 void (*HardStop)(void *handle, uint8_t motorId); 00277 /// Function pointer to Move 00278 void (*Move)(void *handle, motorDir_t direction, uint32_t stepCount); 00279 /// Function pointer to ResetAllDevices 00280 void (*ResetAllDevices)(void *handle); 00281 /// Function pointer to Run 00282 void (*Run)(void *handle, uint8_t stepCount, motorDir_t direction); 00283 /// Function pointer to SetAcceleration 00284 bool(*SetAcceleration)(void *handle, uint16_t newAcc); 00285 /// Function pointer to SetDeceleration 00286 bool(*SetDeceleration)(void *handle, uint16_t newDec); 00287 /// Function pointer to SetHome 00288 void (*SetHome)(void *handle); 00289 /// Function pointer to SetMark 00290 void (*SetMark)(void *handle); 00291 /// Function pointer to SetMaxSpeed 00292 bool (*SetMaxSpeed)(void *handle, uint8_t motorId, uint16_t newMaxSpeed); 00293 /// Function pointer to SetMinSpeed 00294 bool (*SetMinSpeed)(void *handle, uint8_t motorId, uint16_t newMinSpeed); 00295 /// Function pointer to SoftStop 00296 bool (*SoftStop)(void *handle); 00297 /// Function pointer to StepClockHandler 00298 void (*StepClockHandler)(void *handle); 00299 /// Function pointer to WaitWhileActive 00300 void (*WaitWhileActive)(void *handle); 00301 /// Function pointer to CmdDisable 00302 void (*CmdDisable)(void *handle, uint8_t bridgeId); 00303 /// Function pointer to CmdEnable 00304 void (*CmdEnable)(void *handle, uint8_t bridgeId); 00305 /// Function pointer to CmdGetParam 00306 uint32_t (*CmdGetParam)(void *handle, uint32_t param); 00307 /// Function pointer to CmdGetStatus 00308 uint16_t (*CmdGetStatus)(void *handle, uint8_t bridgeId); 00309 /// Function pointer to CmdNop 00310 void (*CmdNop)(void *handle); 00311 /// Function pointer to CmdSetParam 00312 void (*CmdSetParam)(void *handle, uint32_t param, uint32_t value); 00313 /// Function pointer to ReadStatusRegister 00314 uint16_t (*ReadStatusRegister)(void *handle); 00315 /// Function pointer to ReleaseReset 00316 void (*ReleaseReset)(void *handle); 00317 /// Function pointer to Reset 00318 void (*Reset)(void *handle); 00319 /// Function pointer to SelectStepMode 00320 void (*SelectStepMode)(void *handle, motorStepMode_t stepMode); 00321 /// Function pointer to SetDirection 00322 void (*SetDirection)(void *handle, motorDir_t direction); 00323 /// Function pointer to CmdGoToDir 00324 void (*CmdGoToDir)(void *handle, motorDir_t direction, int32_t abs_pos); 00325 /// Function pointer to CheckBusyHw 00326 uint8_t (*CheckBusyHw)(void *handle); 00327 /// Function pointer to CheckStatusHw 00328 uint8_t (*CheckStatusHw)(void *handle); 00329 /// Function pointer to CmdGoUntil 00330 void (*CmdGoUntil)(void *handle, motorAction_t action, motorDir_t direction, uint32_t speed); 00331 /// Function pointer to CmdHardHiZ 00332 void (*CmdHardHiZ)(void *handle, uint8_t motorId); 00333 /// Function pointer to CmdReleaseSw 00334 void (*CmdReleaseSw)(void *handle, motorAction_t action, motorDir_t direction); 00335 /// Function pointer to CmdResetDevice 00336 void (*CmdResetDevice)(void *handle); 00337 /// Function pointer to CmdResetPos 00338 void (*CmdResetPos)(void *handle); 00339 /// Function pointer to CmdRun 00340 void (*CmdRun)(void *handle, motorDir_t direction, uint32_t speed); 00341 /// Function pointer to CmdSoftHiZ 00342 void (*CmdSoftHiZ)(void *handle); 00343 /// Function pointer to CmdStepClock 00344 void (*CmdStepClock)(void *handle, motorDir_t direction); 00345 /// Function pointer to FetchAndClearAllStatus 00346 void (*FetchAndClearAllStatus)(void *handle); 00347 /// Function pointer to GetFetchedStatus 00348 uint16_t (*GetFetchedStatus)(void *handle); 00349 /// Function pointer to GetNbDevices 00350 uint8_t (*GetNbDevices)(void *handle); 00351 /// Function pointer to IsDeviceBusy 00352 bool (*IsDeviceBusy)(void *handle); 00353 /// Function pointer to SendQueuedCommands 00354 void (*SendQueuedCommands)(void *handle); 00355 /// Function pointer to QueueCommands 00356 void (*QueueCommands)(void *handle, uint8_t param, int32_t value); 00357 /// Function pointer to WaitForAllDevicesNotBusy 00358 void (*WaitForAllDevicesNotBusy)(void *handle); 00359 /// Function pointer to ErrorHandler 00360 void (*ErrorHandler)(void *handle, uint16_t error); 00361 /// Function pointer to BusyInterruptHandler 00362 void (*BusyInterruptHandler)(void *handle); 00363 /// Function pointer to CmdSoftStop 00364 void (*CmdSoftStop)(void *handle); 00365 /// Function pointer to StartStepClock 00366 void (*StartStepClock)(void *handle); 00367 /// Function pointer to StopStepClock 00368 void (*StopStepClock)(void *handle); 00369 /// Function pointer to SetDualFullBridgeConfig 00370 void (*SetDualFullBridgeConfig)(void *handle, uint8_t newConfig); 00371 /// Function pointer to GetBridgeInputPwmFreq 00372 uint32_t (*GetBridgeInputPwmFreq)(void *handle, uint8_t bridgeId); 00373 /// Function pointer to SetBridgeInputPwmFreq 00374 void (*SetBridgeInputPwmFreq)(void *handle, uint8_t bridgeId, uint32_t newFreq); 00375 /// Function pointer to SetStopMode 00376 void (*SetStopMode)(void *handle, motorStopMode_t stopMode); 00377 /// Function pointer to GetStopMode 00378 motorStopMode_t (*GetStopMode)(void *handle); 00379 /// Function pointer to SetDecayMode 00380 void (*SetDecayMode)(void *handle, motorDecayMode_t decayMode); 00381 /// Function pointer to GetDecayMode 00382 motorDecayMode_t (*GetDecayMode)(void *handle); 00383 /// Function pointer to GetStepMode 00384 motorStepMode_t (*GetStepMode)(void *handle); 00385 /// Function pointer to GetDirection 00386 motorDir_t (*GetDirection)(void *handle); 00387 /// Function pointer to ExitDeviceFromReset 00388 void (*ExitDeviceFromReset)(void *handle); 00389 /// Function pointer to SetTorque 00390 void (*SetTorque)(void *handle, motorTorqueMode_t torqueMode, uint8_t torqueValue); 00391 /// Function pointer to GetTorque 00392 uint8_t (*GetTorque)(void *handle, motorTorqueMode_t torqueMode); 00393 /// Function pointer to SetVRefFreq 00394 void (*SetRefFreq)(void *handle, uint32_t freq); 00395 /// Function pointer to GetVRefFreq 00396 uint32_t (*GetRefFreq)(void *handle); 00397 /// Function pointer to SetVRefDc 00398 void (*SetRefDc)(void *handle, uint8_t RefDc); 00399 /// Function pointer to GetVRefDc 00400 uint8_t (*GetRefDc)(void *handle); 00401 /// Function pointer to SetNbDevices 00402 bool (*SetNbDevices)(void *handle, uint8_t nbDevices); 00403 /// Function pointer to set a parameter 00404 bool (*SetAnalogValue)(void *handle, uint32_t param, float value); 00405 /// Function pointer to get a parameter 00406 float (*GetAnalogValue)(void *handle, uint32_t param); 00407 } MOTOR_VTable_t; 00408 00409 /** 00410 00411 * @} 00412 */ 00413 00414 /** 00415 * @} 00416 */ 00417 00418 /** 00419 * @} 00420 */ 00421 00422 /** 00423 * @} 00424 */ 00425 00426 /** 00427 * @} 00428 */ 00429 00430 #ifdef __cplusplus 00431 } 00432 #endif 00433 00434 #endif /* __MOTOR_H */ 00435 00436 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00437
Generated on Fri Jul 15 2022 09:11:13 by
1.7.2
