Personal fork of the library for direct control instead of library control
Dependents: Thesis_Rotating_Platform
Fork of X_NUCLEO_IHM01A1 by
motor.h
00001 /** 00002 ****************************************************************************** 00003 * @file motor.h 00004 * @author IPC Rennes 00005 * @version V1.3.0 00006 * @date November 12, 2014 00007 * @brief This file contains all the functions prototypes for motor drivers. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2014 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.h" 00053 00054 00055 /* Definitions ---------------------------------------------------------------*/ 00056 00057 /// boolean for false condition 00058 #ifndef FALSE 00059 #define FALSE (0) 00060 #endif 00061 /// boolean for true condition 00062 #ifndef TRUE 00063 #define TRUE (1) 00064 #endif 00065 00066 00067 /* Types ---------------------------------------------------------------------*/ 00068 00069 /** @addtogroup BSP 00070 * @{ 00071 */ 00072 00073 /** @addtogroup Components 00074 * @{ 00075 */ 00076 00077 /** @addtogroup MOTOR 00078 * @{ 00079 */ 00080 00081 /** @defgroup MOTOR_Exported_Types 00082 * @{ 00083 */ 00084 00085 /** @defgroup Device_Direction_Options 00086 * @{ 00087 */ 00088 /// Direction options 00089 typedef enum { 00090 BACKWARD = 0, 00091 FORWARD = 1 00092 } motorDir_t; 00093 00094 /** 00095 * @} 00096 */ 00097 00098 /** @defgroup Device_Action_Options 00099 * @{ 00100 */ 00101 /// Action options 00102 typedef enum { 00103 ACTION_RESET = ((uint8_t)0x00), 00104 ACTION_COPY = ((uint8_t)0x08) 00105 } motorAction_t; 00106 /** 00107 * @} 00108 */ 00109 00110 /** @defgroup Device_States 00111 * @{ 00112 */ 00113 /// Device states 00114 typedef enum { 00115 ACCELERATING = 0, 00116 DECELERATING = 1, 00117 STEADY = 2, 00118 INACTIVE= 3 00119 } motorState_t; 00120 /** 00121 * @} 00122 */ 00123 00124 /** @defgroup Device_Step_mode 00125 * @{ 00126 */ 00127 /// Stepping options 00128 typedef enum { 00129 STEP_MODE_FULL = ((uint8_t)0x00), 00130 STEP_MODE_HALF = ((uint8_t)0x01), 00131 STEP_MODE_1_4 = ((uint8_t)0x02), 00132 STEP_MODE_1_8 = ((uint8_t)0x03), 00133 STEP_MODE_1_16 = ((uint8_t)0x04), 00134 STEP_MODE_1_32 = ((uint8_t)0x05), 00135 STEP_MODE_1_64 = ((uint8_t)0x06), 00136 STEP_MODE_1_128 = ((uint8_t)0x07) 00137 } motorStepMode_t; 00138 /** 00139 * @} 00140 */ 00141 00142 /** @defgroup Device_Commands 00143 * @{ 00144 */ 00145 /// Device commands 00146 typedef enum { 00147 RUN_CMD, 00148 MOVE_CMD, 00149 SOFT_STOP_CMD, 00150 NO_CMD 00151 } deviceCommand_t; 00152 /** 00153 * @} 00154 */ 00155 00156 /** @defgroup Device_Parameters 00157 * @{ 00158 */ 00159 /// Device Parameters Structure Type 00160 typedef struct { 00161 /// accumulator used to store speed increase smaller than 1 pps 00162 volatile uint32_t accu; 00163 /// Position in steps at the start of the goto or move commands 00164 volatile int32_t currentPosition; 00165 /// position in step at the end of the accelerating phase 00166 volatile uint32_t endAccPos; 00167 /// nb steps performed from the beggining of the goto or the move command 00168 volatile uint32_t relativePos; 00169 /// position in step at the start of the decelerating phase 00170 volatile uint32_t startDecPos; 00171 /// nb steps to perform for the goto or move commands 00172 volatile uint32_t stepsToTake; 00173 /// acceleration in pps^2 00174 volatile uint16_t acceleration; 00175 /// deceleration in pps^2 00176 volatile uint16_t deceleration; 00177 /// max speed in pps (speed use for goto or move command) 00178 volatile uint16_t maxSpeed; 00179 /// min speed in pps 00180 volatile uint16_t minSpeed; 00181 /// current speed in pps 00182 volatile uint16_t speed; 00183 /// command under execution 00184 volatile deviceCommand_t commandExecuted; 00185 /// FORWARD or BACKWARD direction 00186 volatile motorDir_t direction; 00187 /// Current State of the device 00188 volatile motorState_t motionState; 00189 } deviceParams_t; 00190 /** 00191 * @} 00192 */ 00193 00194 /** @defgroup Motor_Driver_Structure 00195 * @{ 00196 */ 00197 00198 /** 00199 * @brief MOTOR driver virtual table structure definition. 00200 */ 00201 typedef struct 00202 { 00203 /* ACTION ----------------------------------------------------------------* 00204 * Declare here the component's generic functions. * 00205 * Tag this group of functions with the " Generic " C-style comment. * 00206 * A component's interface has to define at least the two generic * 00207 * functions provided here below within the "Example" section, as the * 00208 * first and second functions of its Virtual Table. They have to be * 00209 * specified exactly in the given way. * 00210 * * 00211 * Example: * 00212 * Status_t (*Init) (void *handle, void *init); * 00213 * Status_t (*ReadID) (void *handle, uint8_t *id); * 00214 *------------------------------------------------------------------------*/ 00215 /* Generic */ 00216 Status_t (*Init)(void *handle, void *init); 00217 Status_t (*ReadID)(void *handle, uint8_t *id); 00218 00219 /* ACTION ----------------------------------------------------------------* 00220 * Declare here the component's interrupts related functions. * 00221 * Tag this group of functions with the " Interrupts " C-style comment. * 00222 * Do not specify any function if not required. * 00223 * * 00224 * Example: * 00225 * void (*ConfigIT) (void *handle, int a); * 00226 *------------------------------------------------------------------------*/ 00227 /* Interrupts */ 00228 /// Function pointer to AttachErrorHandler 00229 void (*AttachErrorHandler)(void *handle, void (*callback)(void *handle, uint16_t error)); 00230 /// Function pointer to AttachFlagInterrupt 00231 void (*AttachFlagInterrupt)(void *handle, void (*callback)(void *handle)); 00232 /// Function pointer to AttachBusyInterrupt 00233 void (*AttachBusyInterrupt)(void *handle, void (*callback)(void *handle)); 00234 /// Function pointer to FlagInterruptHandler 00235 void (*FlagInterruptHandler)(void *handle); 00236 00237 /* ACTION ----------------------------------------------------------------* 00238 * Declare here the component's specific functions. * 00239 * Tag this group of functions with the " Specific " C-style comment. * 00240 * Do not specify any function if not required. * 00241 * * 00242 * Example: * 00243 * Status_t (*GetValue) (void *handle, float *f); * 00244 *------------------------------------------------------------------------*/ 00245 /* Specific */ 00246 /// Function pointer to GetAcceleration 00247 uint16_t (*GetAcceleration)(void *handle); 00248 /// Function pointer to GetCurrentSpeed 00249 uint16_t (*GetCurrentSpeed)(void *handle); 00250 /// Function pointer to GetDeceleration 00251 uint16_t (*GetDeceleration)(void *handle); 00252 /// Function pointer to GetDeviceState 00253 motorState_t(*GetDeviceState)(void *handle); 00254 /// Function pointer to GetFwVersion 00255 uint8_t (*GetFwVersion)(void *handle); 00256 /// Function pointer to GetMark 00257 int32_t (*GetMark)(void *handle); 00258 /// Function pointer to GetMaxSpeed 00259 uint16_t (*GetMaxSpeed)(void *handle); 00260 /// Function pointer to GetMinSpeed 00261 uint16_t (*GetMinSpeed)(void *handle); 00262 /// Function pointer to GetPosition 00263 int32_t (*GetPosition)(void *handle); 00264 /// Function pointer to GoHome 00265 void (*GoHome)(void *handle); 00266 /// Function pointer to GoMark 00267 void (*GoMark)(void *handle); 00268 /// Function pointer to GoTo 00269 void (*GoTo)(void *handle, int32_t targetPosition); 00270 /// Function pointer to HardStop 00271 void (*HardStop)(void *handle); 00272 /// Function pointer to Move 00273 void (*Move)(void *handle, motorDir_t direction, uint32_t stepCount); 00274 /// Function pointer to ResetAllDevices 00275 //void (*ResetAllDevices)(void *handle); 00276 /// Function pointer to Run 00277 void (*Run)(void *handle, motorDir_t direction); 00278 /// Function pointer to SetAcceleration 00279 bool (*SetAcceleration)(void *handle, uint16_t newAcc); 00280 /// Function pointer to SetDeceleration 00281 bool (*SetDeceleration)(void *handle, uint16_t newDec); 00282 /// Function pointer to SetHome 00283 void (*SetHome)(void *handle); 00284 /// Function pointer to SetMark 00285 void (*SetMark)(void *handle); 00286 /// Function pointer to SetMaxSpeed 00287 bool (*SetMaxSpeed)(void *handle, uint16_t newMaxSpeed); 00288 /// Function pointer to SetMinSpeed 00289 bool (*SetMinSpeed)(void *handle, uint16_t newMinSpeed); 00290 /// Function pointer to SoftStop 00291 bool (*SoftStop)(void *handle); 00292 /// Function pointer to StepClockHandler 00293 void (*StepClockHandler)(void *handle); 00294 /// Function pointer to WaitWhileActive 00295 void (*WaitWhileActive)(void *handle); 00296 /// Function pointer to CmdDisable 00297 void (*CmdDisable)(void *handle); 00298 /// Function pointer to CmdEnable 00299 void (*CmdEnable)(void *handle); 00300 /// Function pointer to CmdGetParam 00301 uint32_t (*CmdGetParam)(void *handle, uint32_t param); 00302 /// Function pointer to CmdGetStatus 00303 uint16_t (*CmdGetStatus)(void *handle); 00304 /// Function pointer to CmdNop 00305 void (*CmdNop)(void *handle); 00306 /// Function pointer to CmdSetParam 00307 void (*CmdSetParam)(void *handle, uint32_t param, uint32_t value); 00308 /// Function pointer to ReadStatusRegister 00309 uint16_t (*ReadStatusRegister)(void *handle); 00310 /// Function pointer to ReleaseReset 00311 void (*ReleaseReset)(void *handle); 00312 /// Function pointer to Reset 00313 void (*Reset)(void *handle); 00314 /// Function pointer to SelectStepMode 00315 void (*SelectStepMode)(void *handle, motorStepMode_t stepMod); 00316 /// Function pointer to SetDirection 00317 void (*SetDirection)(void *handle, motorDir_t direction); 00318 /// Function pointer to CmdGoToDir 00319 void (*CmdGoToDir)(void *handle, motorDir_t direction, int32_t targetPosition); 00320 /// Function pointer to CheckBusyHw 00321 uint8_t (*CheckBusyHw)(void *handle); 00322 /// Function pointer to CheckStatusHw 00323 uint8_t (*CheckStatusHw)(void *handle); 00324 /// Function pointer to CmdGoUntil 00325 void (*CmdGoUntil)(void *handle, motorAction_t action, motorDir_t direction, uint32_t targetPosition); 00326 /// Function pointer to CmdHardHiZ 00327 void (*CmdHardHiZ)(void *handle); 00328 /// Function pointer to CmdReleaseSw 00329 void (*CmdReleaseSw)(void *handle, motorAction_t action, motorDir_t direction); 00330 /// Function pointer to CmdResetDevice 00331 void (*CmdResetDevice)(void *handle); 00332 /// Function pointer to CmdResetPos 00333 void (*CmdResetPos)(void *handle); 00334 /// Function pointer to CmdRun 00335 void (*CmdRun)(void *handle, motorDir_t direction, uint32_t targetPosition); 00336 /// Function pointer to CmdSoftHiZ 00337 void (*CmdSoftHiZ)(void *handle); 00338 /// Function pointer to CmdStepClock 00339 void (*CmdStepClock)(void *handle, motorDir_t direction); 00340 /// Function pointer to FetchAndClearAllStatus 00341 void (*FetchAndClearAllStatus)(void *handle); 00342 /// Function pointer to GetFetchedStatus 00343 uint16_t (*GetFetchedStatus)(void *handle); 00344 /// Function pointer to GetNbDevices 00345 uint8_t (*GetNbDevices)(void *handle); 00346 /// Function pointer to IsDeviceBusy 00347 bool (*IsDeviceBusy)(void *handle); 00348 /// Function pointer to SendQueuedCommands 00349 void (*SendQueuedCommands)(void *handle); 00350 /// Function pointer to QueueCommands 00351 void (*QueueCommands)(void *handle, uint8_t temp, uint32_t command); 00352 /// Function pointer to WaitForAllDevicesNotBusy 00353 void (*WaitForAllDevicesNotBusy)(void *handle); 00354 /// Function pointer to ErrorHandler 00355 void (*ErrorHandler)(void *handle, uint16_t error); 00356 /// Function pointer to BusyInterruptHandler 00357 void (*BusyInterruptHandler)(void *handle); 00358 /// Function pointer to CmdSoftStop 00359 void (*CmdSoftStop)(void *handle); 00360 } MOTOR_VTable_t; 00361 00362 #ifdef __cplusplus 00363 } 00364 #endif 00365 00366 #endif /* __MOTOR_H */ 00367 00368 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Fri Jul 15 2022 12:57:41 by 1.7.2