You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

motor.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /**
  2. ******************************************************************************
  3. * @file motor.h
  4. * @author IPC Rennes
  5. * @version V1.7.0
  6. * @date March 16th, 2018
  7. * @brief This file contains all the functions prototypes for motor drivers.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __MOTOR_H
  39. #define __MOTOR_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include <stdint.h>
  45. /** @addtogroup BSP
  46. * @{
  47. */
  48. /** @addtogroup Components
  49. * @{
  50. */
  51. /** @defgroup Motor Motor
  52. * @{
  53. */
  54. /** @defgroup Motor_Exported_Constants Motor Exported Constants
  55. * @{
  56. */
  57. /// boolean for false condition
  58. #ifndef FALSE
  59. #define FALSE (0)
  60. #endif
  61. /// boolean for true condition
  62. #ifndef TRUE
  63. #define TRUE (1)
  64. #endif
  65. /**
  66. * @}
  67. */
  68. /** @defgroup Motor_Exported_Types Motor Exported Types
  69. * @{
  70. */
  71. /** @defgroup Motor_Boolean_Type Motor Boolean Type
  72. * @{
  73. */
  74. ///bool Type
  75. typedef uint8_t bool;
  76. /**
  77. * @}
  78. */
  79. /** @defgroup Device_Direction_Options Device Direction Options
  80. * @{
  81. */
  82. /// Direction options
  83. typedef enum {
  84. BACKWARD = 0,
  85. FORWARD = 1,
  86. UNKNOW_DIR = ((uint8_t)0xFF)
  87. } motorDir_t;
  88. /**
  89. * @}
  90. */
  91. /** @defgroup Device_Action_Options Device Action Options
  92. * @{
  93. */
  94. /// Action options
  95. typedef enum {
  96. ACTION_RESET = ((uint8_t)0x00),
  97. ACTION_COPY = ((uint8_t)0x08)
  98. } motorAction_t;
  99. /**
  100. * @}
  101. */
  102. /** @defgroup Device_States Device States
  103. * @{
  104. */
  105. /// Device states
  106. typedef enum {
  107. ACCELERATING = 0,
  108. DECELERATINGTOSTOP = 1,
  109. DECELERATING = 2,
  110. STEADY = 3,
  111. INDEX_ACCEL = 4,
  112. INDEX_RUN = 5,
  113. INDEX_DECEL = 6,
  114. INDEX_DWELL = 7,
  115. INACTIVE = 8,
  116. STANDBY = 9,
  117. STANDBYTOINACTIVE = 10
  118. } motorState_t;
  119. /**
  120. * @}
  121. */
  122. /** @defgroup Device_Step_mode Device Step mode
  123. * @{
  124. */
  125. /// Stepping options
  126. typedef enum {
  127. STEP_MODE_FULL = ((uint8_t)0x00),
  128. STEP_MODE_HALF = ((uint8_t)0x01),
  129. STEP_MODE_1_4 = ((uint8_t)0x02),
  130. STEP_MODE_1_8 = ((uint8_t)0x03),
  131. STEP_MODE_1_16 = ((uint8_t)0x04),
  132. STEP_MODE_1_32 = ((uint8_t)0x05),
  133. STEP_MODE_1_64 = ((uint8_t)0x06),
  134. STEP_MODE_1_128 = ((uint8_t)0x07),
  135. STEP_MODE_1_256 = ((uint8_t)0x08),
  136. STEP_MODE_UNKNOW = ((uint8_t)0xFE),
  137. STEP_MODE_WAVE = ((uint8_t)0xFF)
  138. } motorStepMode_t;
  139. /**
  140. * @}
  141. */
  142. /** @defgroup Decay_mode Decay mode
  143. * @{
  144. */
  145. /// Decay Mode
  146. typedef enum {
  147. SLOW_DECAY = 0,
  148. FAST_DECAY = 1,
  149. UNKNOW_DECAY = ((uint8_t)0xFF)
  150. } motorDecayMode_t;
  151. /**
  152. * @}
  153. */
  154. /** @defgroup Stop_mode Stop mode
  155. * @{
  156. */
  157. /// Stop mode
  158. typedef enum
  159. {
  160. HOLD_MODE = 0,
  161. HIZ_MODE = 1,
  162. STANDBY_MODE = 2,
  163. UNKNOW_STOP_MODE = ((uint8_t)0xFF)
  164. } motorStopMode_t;
  165. /**
  166. * @}
  167. */
  168. /** @defgroup Torque_mode Torque mode
  169. * @{
  170. */
  171. /// Torque mode
  172. typedef enum
  173. {
  174. ACC_TORQUE = 0,
  175. DEC_TORQUE = 1,
  176. RUN_TORQUE = 2,
  177. HOLD_TORQUE = 3,
  178. CURRENT_TORQUE = 4,
  179. UNKNOW_TORQUE = ((uint8_t)0xFF)
  180. } motorTorqueMode_t;
  181. /**
  182. * @}
  183. */
  184. /** @defgroup Dual_Full_Bridge_Configuration Dual Full Bridge Configuration
  185. * @{
  186. */
  187. ///Dual full bridge configurations for brush DC motors
  188. typedef enum {
  189. PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 0,
  190. PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 1,
  191. PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 2,
  192. PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 3,
  193. PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 4,
  194. PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 5,
  195. PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 6,
  196. PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 7,
  197. PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 8,
  198. PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR = 9,
  199. PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A = 10,
  200. PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR = 11,
  201. PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR = 12,
  202. PARALLELING_END_ENUM = 13
  203. } dualFullBridgeConfig_t;
  204. /**
  205. * @}
  206. */
  207. /** @defgroup Motor_Driver_Structure Motor Driver Structure
  208. * @{
  209. */
  210. /// Motor driver structure definition
  211. typedef struct
  212. {
  213. /// Function pointer to Init
  214. void (*Init)(void*);
  215. /// Function pointer to ReadID
  216. uint16_t (*ReadID)(void);
  217. /// Function pointer to AttachErrorHandler
  218. void(*AttachErrorHandler)(void (*callback)(uint16_t));
  219. /// Function pointer to AttachFlagInterrupt
  220. void (*AttachFlagInterrupt)(void (*callback)(void));
  221. /// Function pointer to AttachBusyInterrupt
  222. void (*AttachBusyInterrupt)(void (*callback)(void));
  223. /// Function pointer to FlagInterruptHandler
  224. void (*FlagInterruptHandler)(void);
  225. /// Function pointer to GetAcceleration
  226. uint16_t (*GetAcceleration)(uint8_t);
  227. /// Function pointer to GetCurrentSpeed
  228. uint16_t (*GetCurrentSpeed)(uint8_t);
  229. /// Function pointer to GetDeceleration
  230. uint16_t (*GetDeceleration)(uint8_t);
  231. /// Function pointer to GetDeviceState
  232. motorState_t(*GetDeviceState)(uint8_t);
  233. /// Function pointer to GetFwVersion
  234. uint32_t (*GetFwVersion)(void);
  235. /// Function pointer to GetMark
  236. int32_t (*GetMark)(uint8_t);
  237. /// Function pointer to GetMaxSpeed
  238. uint16_t (*GetMaxSpeed)(uint8_t);
  239. /// Function pointer to GetMinSpeed
  240. uint16_t (*GetMinSpeed)(uint8_t);
  241. /// Function pointer to GetPosition
  242. int32_t (*GetPosition)(uint8_t);
  243. /// Function pointer to GoHome
  244. void (*GoHome)(uint8_t);
  245. /// Function pointer to GoMark
  246. void (*GoMark)(uint8_t);
  247. /// Function pointer to GoTo
  248. void (*GoTo)(uint8_t, int32_t);
  249. /// Function pointer to HardStop
  250. void (*HardStop)(uint8_t);
  251. /// Function pointer to Move
  252. void (*Move)(uint8_t, motorDir_t, uint32_t );
  253. /// Function pointer to ResetAllDevices
  254. void (*ResetAllDevices)(void);
  255. /// Function pointer to Run
  256. void (*Run)(uint8_t, motorDir_t);
  257. /// Function pointer to SetAcceleration
  258. bool(*SetAcceleration)(uint8_t ,uint16_t );
  259. /// Function pointer to SetDeceleration
  260. bool(*SetDeceleration)(uint8_t , uint16_t );
  261. /// Function pointer to SetHome
  262. void (*SetHome)(uint8_t, int32_t);
  263. /// Function pointer to SetMark
  264. void (*SetMark)(uint8_t, int32_t);
  265. /// Function pointer to SetMaxSpeed
  266. bool (*SetMaxSpeed)(uint8_t, uint16_t );
  267. /// Function pointer to SetMinSpeed
  268. bool (*SetMinSpeed)(uint8_t, uint16_t );
  269. /// Function pointer to SoftStop
  270. bool (*SoftStop)(uint8_t);
  271. /// Function pointer to StepClockHandler
  272. void (*StepClockHandler)(uint8_t deviceId);
  273. /// Function pointer to WaitWhileActive
  274. void (*WaitWhileActive)(uint8_t);
  275. /// Function pointer to CmdDisable
  276. void (*CmdDisable)(uint8_t);
  277. /// Function pointer to CmdEnable
  278. void (*CmdEnable)(uint8_t);
  279. /// Function pointer to CmdGetParam
  280. uint32_t (*CmdGetParam)(uint8_t, uint32_t);
  281. /// Function pointer to CmdGetStatus
  282. uint16_t (*CmdGetStatus)(uint8_t);
  283. /// Function pointer to CmdNop
  284. void (*CmdNop)(uint8_t);
  285. /// Function pointer to CmdSetParam
  286. void (*CmdSetParam)(uint8_t, uint32_t, uint32_t);
  287. /// Function pointer to ReadStatusRegister
  288. uint16_t (*ReadStatusRegister)(uint8_t);
  289. /// Function pointer to ReleaseReset
  290. void (*ReleaseReset)(uint8_t);
  291. /// Function pointer to Reset
  292. void (*Reset)(uint8_t);
  293. /// Function pointer to SelectStepMode
  294. bool (*SelectStepMode)(uint8_t deviceId, motorStepMode_t);
  295. /// Function pointer to SetDirection
  296. void (*SetDirection)(uint8_t, motorDir_t);
  297. /// Function pointer to CmdGoToDir
  298. void (*CmdGoToDir)(uint8_t, motorDir_t, int32_t);
  299. /// Function pointer to CheckBusyHw
  300. uint8_t (*CheckBusyHw)(void);
  301. /// Function pointer to CheckStatusHw
  302. uint8_t (*CheckStatusHw)(void);
  303. /// Function pointer to CmdGoUntil
  304. void (*CmdGoUntil)(uint8_t, motorAction_t, motorDir_t, uint32_t);
  305. /// Function pointer to CmdHardHiZ
  306. void (*CmdHardHiZ)(uint8_t);
  307. /// Function pointer to CmdReleaseSw
  308. void (*CmdReleaseSw)(uint8_t, motorAction_t, motorDir_t);
  309. /// Function pointer to CmdResetDevice
  310. void (*CmdResetDevice)(uint8_t);
  311. /// Function pointer to CmdResetPos
  312. void (*CmdResetPos)(uint8_t);
  313. /// Function pointer to CmdRun
  314. void (*CmdRun)(uint8_t, motorDir_t, uint32_t);
  315. /// Function pointer to CmdSoftHiZ
  316. void (*CmdSoftHiZ)(uint8_t);
  317. /// Function pointer to CmdStepClock
  318. void (*CmdStepClock)(uint8_t, motorDir_t);
  319. /// Function pointer to FetchAndClearAllStatus
  320. void (*FetchAndClearAllStatus)(void);
  321. /// Function pointer to GetFetchedStatus
  322. uint16_t (*GetFetchedStatus)(uint8_t);
  323. /// Function pointer to GetNbDevices
  324. uint8_t (*GetNbDevices)(void);
  325. /// Function pointer to IsDeviceBusy
  326. bool (*IsDeviceBusy)(uint8_t);
  327. /// Function pointer to SendQueuedCommands
  328. void (*SendQueuedCommands)(void);
  329. /// Function pointer to QueueCommands
  330. void (*QueueCommands)(uint8_t, uint8_t, int32_t);
  331. /// Function pointer to WaitForAllDevicesNotBusy
  332. void (*WaitForAllDevicesNotBusy)(void);
  333. /// Function pointer to ErrorHandler
  334. void (*ErrorHandler)(uint16_t);
  335. /// Function pointer to BusyInterruptHandler
  336. void (*BusyInterruptHandler)(void);
  337. /// Function pointer to CmdSoftStop
  338. void (*CmdSoftStop)(uint8_t);
  339. /// Function pointer to StartStepClock
  340. void (*StartStepClock)(uint16_t);
  341. /// Function pointer to StopStepClock
  342. void (*StopStepClock)(void);
  343. /// Function pointer to SetDualFullBridgeConfig
  344. void (*SetDualFullBridgeConfig)(uint8_t);
  345. /// Function pointer to GetBridgeInputPwmFreq
  346. uint32_t (*GetBridgeInputPwmFreq)(uint8_t);
  347. /// Function pointer to SetBridgeInputPwmFreq
  348. void (*SetBridgeInputPwmFreq)(uint8_t, uint32_t);
  349. /// Function pointer to SetStopMode
  350. void (*SetStopMode)(uint8_t, motorStopMode_t);
  351. /// Function pointer to GetStopMode
  352. motorStopMode_t (*GetStopMode)(uint8_t);
  353. /// Function pointer to SetDecayMode
  354. void (*SetDecayMode)(uint8_t, motorDecayMode_t);
  355. /// Function pointer to GetDecayMode
  356. motorDecayMode_t (*GetDecayMode)(uint8_t);
  357. /// Function pointer to GetStepMode
  358. motorStepMode_t (*GetStepMode)(uint8_t);
  359. /// Function pointer to GetDirection
  360. motorDir_t (*GetDirection)(uint8_t);
  361. /// Function pointer to ExitDeviceFromReset
  362. void (*ExitDeviceFromReset)(uint8_t);
  363. /// Function pointer to SetTorque
  364. void (*SetTorque)(uint8_t, motorTorqueMode_t, uint8_t);
  365. /// Function pointer to GetTorque
  366. uint8_t (*GetTorque)(uint8_t, motorTorqueMode_t);
  367. /// Function pointer to SetVRefFreq
  368. void (*SetRefFreq)(uint8_t, uint32_t);
  369. /// Function pointer to GetVRefFreq
  370. uint32_t (*GetRefFreq)(uint8_t);
  371. /// Function pointer to SetVRefDc
  372. void (*SetRefDc)(uint8_t, uint8_t);
  373. /// Function pointer to GetVRefDc
  374. uint8_t (*GetRefDc)(uint8_t);
  375. /// Function pointer to SetNbDevices
  376. bool (*SetNbDevices)(uint8_t);
  377. /// Function pointer to SetAnalogValue
  378. bool (*SetAnalogValue)(uint8_t, uint32_t, float);
  379. /// Function pointer to GetAnalogValue
  380. float (*GetAnalogValue)(uint8_t, uint32_t);
  381. /// Function pointer to SetTorqueBoostEnable
  382. void (*SetTorqueBoostEnable) (uint8_t, bool);
  383. /// Function pointer to GetTorqueBoostEnable
  384. bool (*GetTorqueBoostEnable) (uint8_t);
  385. /// Function pointer to SetTorqueBoostThreshold
  386. void (*SetTorqueBoostThreshold) (uint8_t, uint16_t);
  387. /// Function pointer to GetTorqueBoostThreshold
  388. uint16_t (*GetTorqueBoostThreshold) (uint8_t);
  389. /// Function pointer to GetDualFullBridgeConfig
  390. uint8_t (*GetDualFullBridgeConfig) (void);
  391. }motorDrv_t;
  392. /**
  393. * @}
  394. */
  395. /**
  396. * @}
  397. */
  398. /**
  399. * @}
  400. */
  401. /**
  402. * @}
  403. */
  404. /**
  405. * @}
  406. */
  407. #ifdef __cplusplus
  408. }
  409. #endif
  410. #endif /* __MOTOR_H */
  411. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/