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.

x_nucleo_ihmxx.c 63KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943
  1. /**
  2. ******************************************************************************
  3. * @file x_nucleo_ihmxx.c
  4. * @author IPC Rennes
  5. * @version V1.7.0
  6. * @date March 16th, 2018
  7. * @brief This file provides common functions for motor control
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2018 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. /* Includes ------------------------------------------------------------------*/
  38. #include "x_nucleo_ihmxx.h"
  39. /** @addtogroup BSP
  40. * @{
  41. */
  42. /** @defgroup MOTOR_CONTROL MOTOR CONTROL
  43. * @{
  44. */
  45. /** @defgroup MOTOR_CONTROL_Private_Types_Definitions MOTOR CONTROL Private Types Definitions
  46. * @{
  47. */
  48. /**
  49. * @}
  50. */
  51. /** @defgroup MOTOR_CONTROL_Private_Defines MOTOR CONTROL Private Defines
  52. * @{
  53. */
  54. /**
  55. * @}
  56. */
  57. /** @defgroup MOTOR_CONTROL_Private_Constants MOTOR CONTROL Private Constants
  58. * @{
  59. */
  60. /**
  61. * @}
  62. */
  63. /** @defgroup MOTOR_CONTROL_Private_Macros MOTOR CONTROL Private Macros
  64. * @{
  65. */
  66. /// Error when trying to call undefined functions via motorDrvHandle
  67. #define MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(errorNb) (BSP_MotorControl_ErrorHandler(MOTOR_CONTROL_ERROR_TAG|(errorNb)))
  68. /**
  69. * @}
  70. */
  71. /** @defgroup MOTOR_CONTROL_Private_Variables MOTOR CONTROL Private Variables
  72. * @{
  73. */
  74. static motorDrv_t *motorDrvHandle = 0;
  75. static uint16_t MotorControlBoardId;
  76. /**
  77. * @}
  78. */
  79. /** @defgroup MOTOR_CONTROL_Weak_Private_Functions MOTOR CONTROL Weak Private Functions
  80. * @{
  81. */
  82. /// Get motor handle for L6474
  83. __weak motorDrv_t* L6474_GetMotorHandle(void){return ((motorDrv_t* )0);}
  84. /// Get motor handle for L647x
  85. __weak motorDrv_t* l647x_GetMotorHandle(void){return ((motorDrv_t* )0);}
  86. /// Get motor handle for L648x
  87. __weak motorDrv_t* l648x_GetMotorHandle(void){return ((motorDrv_t* )0);}
  88. /// Get motor handle for Powerstep
  89. __weak motorDrv_t* Powerstep01_GetMotorHandle(void){return ((motorDrv_t* )0);}
  90. /// Get motor handle for L6206
  91. __weak motorDrv_t* L6206_GetMotorHandle(void){return ((motorDrv_t* )0);}
  92. /// Get motor handle for L6208
  93. __weak motorDrv_t* L6208_GetMotorHandle(void){return ((motorDrv_t* )0);}
  94. /// Get motor handle for STSPIN220
  95. __weak motorDrv_t* Stspin220_GetMotorHandle(void){return ((motorDrv_t* )0);}
  96. /// Get motor handle for STSPIN240
  97. __weak motorDrv_t* Stspin240_250_GetMotorHandle(void){return ((motorDrv_t* )0);}
  98. /**
  99. * @}
  100. */
  101. /** @defgroup MOTOR_CONTROL_Private_Functions MOTOR CONTROL Private Functions
  102. * @{
  103. */
  104. /******************************************************//**
  105. * @brief Attaches a user callback to the error Handler.
  106. * The call back will be then called each time the library
  107. * detects an error
  108. * @param[in] callback Name of the callback to attach
  109. * to the error Hanlder
  110. * @retval None
  111. **********************************************************/
  112. void BSP_MotorControl_AttachErrorHandler(void (*callback)(uint16_t))
  113. {
  114. if ((motorDrvHandle != 0)&&(motorDrvHandle->AttachErrorHandler != 0))
  115. {
  116. motorDrvHandle->AttachErrorHandler(callback);
  117. }
  118. else
  119. {
  120. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(2);
  121. }
  122. }
  123. /******************************************************//**
  124. * @brief Attaches a user callback to the Flag interrupt Handler.
  125. * The call back will be then called each time the library
  126. * detects a FLAG signal falling edge.
  127. * @param[in] callback Name of the callback to attach
  128. * to the Flag interrupt Hanlder
  129. * @retval None
  130. **********************************************************/
  131. void BSP_MotorControl_AttachFlagInterrupt(void (*callback)(void))
  132. {
  133. if ((motorDrvHandle != 0)&&(motorDrvHandle->AttachFlagInterrupt != 0))
  134. {
  135. motorDrvHandle->AttachFlagInterrupt(callback);
  136. }
  137. else
  138. {
  139. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(3);
  140. }
  141. }
  142. /******************************************************//**
  143. * @brief Attaches a user callback to the Busy interrupt Handler.
  144. * The call back will be then called each time the library
  145. * detects a BUSY signal falling edge.
  146. * @param[in] callback Name of the callback to attach
  147. * to the Busy interrupt Hanlder
  148. * @retval None
  149. **********************************************************/
  150. void BSP_MotorControl_AttachBusyInterrupt(void (*callback)(void))
  151. {
  152. if ((motorDrvHandle != 0)&&(motorDrvHandle->AttachBusyInterrupt != 0))
  153. {
  154. motorDrvHandle->AttachBusyInterrupt(callback);
  155. }
  156. else
  157. {
  158. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(4);
  159. }
  160. }
  161. /******************************************************//**
  162. * @brief Motor control error handler
  163. * @param[in] error number of the error
  164. * @retval None
  165. **********************************************************/
  166. void BSP_MotorControl_ErrorHandler(uint16_t error)
  167. {
  168. if ((motorDrvHandle != 0)&&(motorDrvHandle->ErrorHandler != 0))
  169. {
  170. motorDrvHandle->ErrorHandler(error);
  171. }
  172. else
  173. {
  174. while(1)
  175. {
  176. /* Infinite loop as Error handler must be defined*/
  177. }
  178. }
  179. }
  180. /******************************************************//**
  181. * @brief Initialises the motor driver. This function has to be called one time
  182. * for each device. The number of devices is incremented in the driver up to
  183. * the maximum allowed. Calling this function a number of times greater than the
  184. * maximum number triggers an error in the driver.
  185. * @param[in] id Component Id (L6474, Powerstep01,...)
  186. * @param[in] initDeviceParameters Initialization structure for one device
  187. * @retval None
  188. **********************************************************/
  189. void BSP_MotorControl_Init(uint16_t id, void* initDeviceParameters)
  190. {
  191. if ((motorDrvHandle != 0)&&(motorDrvHandle->Init != 0))
  192. {
  193. motorDrvHandle->Init(initDeviceParameters);
  194. }
  195. else
  196. {
  197. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(0);
  198. }
  199. }
  200. /******************************************************//**
  201. * @brief Handlers of the flag interrupt which calls the user callback (if defined)
  202. * @retval None
  203. **********************************************************/
  204. void BSP_MotorControl_FlagInterruptHandler(void)
  205. {
  206. if ((motorDrvHandle != 0)&&(motorDrvHandle->FlagInterruptHandler != 0))
  207. {
  208. motorDrvHandle->FlagInterruptHandler();
  209. }
  210. else
  211. {
  212. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(5);
  213. }
  214. }
  215. /******************************************************//**
  216. * @brief Returns the acceleration of the specified device
  217. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  218. * For L6208: dummy parameter for compatibility with motor.h
  219. * @retval Acceleration in pps^2
  220. **********************************************************/
  221. uint16_t BSP_MotorControl_GetAcceleration(uint8_t deviceId)
  222. {
  223. uint16_t acceleration = 0;
  224. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetAcceleration != 0))
  225. {
  226. acceleration = motorDrvHandle->GetAcceleration(deviceId);
  227. }
  228. else
  229. {
  230. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(6);
  231. }
  232. return(acceleration);
  233. }
  234. /******************************************************//**
  235. * @brief Get board Id the motor driver
  236. * @retval Motor control board Id
  237. **********************************************************/
  238. uint16_t BSP_MotorControl_GetBoardId(void)
  239. {
  240. return (MotorControlBoardId);
  241. }
  242. /******************************************************//**
  243. * @brief Returns the current speed of the specified device
  244. * @param[in] deviceId from 0 to (MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  245. * For L6208: dummy parameter for compatibility with motor.h
  246. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  247. * @retval Speed in pps for stepper motor
  248. * in % for Brush DC motor (0-100)
  249. **********************************************************/
  250. uint16_t BSP_MotorControl_GetCurrentSpeed(uint8_t deviceId)
  251. {
  252. uint16_t currentSpeed = 0;
  253. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetCurrentSpeed != 0))
  254. {
  255. currentSpeed = motorDrvHandle->GetCurrentSpeed(deviceId);
  256. }
  257. else
  258. {
  259. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(7);
  260. }
  261. return(currentSpeed);
  262. }
  263. /******************************************************//**
  264. * @brief Returns the deceleration of the specified device
  265. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  266. * For L6208: dummy parameter for compatibility with motor.h
  267. * @retval Deceleration in pps^2
  268. **********************************************************/
  269. uint16_t BSP_MotorControl_GetDeceleration(uint8_t deviceId)
  270. {
  271. uint16_t deceleration = 0;
  272. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetDeceleration != 0))
  273. {
  274. deceleration = motorDrvHandle->GetDeceleration(deviceId);
  275. }
  276. else
  277. {
  278. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(8);
  279. }
  280. return(deceleration);
  281. }
  282. /******************************************************//**
  283. * @brief Returns the device state
  284. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  285. * For L6208: dummy parameter for compatibility with motor.h
  286. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  287. * @retval State ACCELERATING, DECELERATING, STEADY or INACTIVE for stepper motor,
  288. STEADY or INACTIVE for Brush DC motor
  289. **********************************************************/
  290. motorState_t BSP_MotorControl_GetDeviceState(uint8_t deviceId)
  291. {
  292. motorState_t state = INACTIVE;
  293. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetDeviceState != 0))
  294. {
  295. state = motorDrvHandle->GetDeviceState(deviceId);
  296. }
  297. else
  298. {
  299. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(9);
  300. }
  301. return(state);
  302. }
  303. /******************************************************//**
  304. * @brief Returns the FW version of the library
  305. * @retval BSP_MotorControl_FW_VERSION
  306. * @note the format is (MAJOR_VERSION<<16)|(MINOR_VERSION<<8)|(PATCH_VERSION)
  307. * with major, minor and patch versions coded on 8 bits.
  308. **********************************************************/
  309. uint32_t BSP_MotorControl_GetFwVersion(void)
  310. {
  311. uint32_t version = 0;
  312. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetFwVersion != 0))
  313. {
  314. version = motorDrvHandle->GetFwVersion();
  315. }
  316. else
  317. {
  318. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(10);
  319. }
  320. return(version);
  321. }
  322. /******************************************************//**
  323. * @brief Returns the mark position of the specified device
  324. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  325. * For L6208: dummy parameter for compatibility with motor.h
  326. * @retval Mark register value converted in a 32b signed integer
  327. **********************************************************/
  328. int32_t BSP_MotorControl_GetMark(uint8_t deviceId)
  329. {
  330. int32_t mark = 0;
  331. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetMark != 0))
  332. {
  333. mark = motorDrvHandle->GetMark(deviceId);
  334. }
  335. else
  336. {
  337. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(11);
  338. }
  339. return(mark);
  340. }
  341. /******************************************************//**
  342. * @brief Returns the max speed of the specified device
  343. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  344. * For L6208: dummy parameter for compatibility with motor.h
  345. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  346. * @retval maxSpeed in pps for stepper motor
  347. * in % for Brush DC motor (0-100)
  348. **********************************************************/
  349. uint16_t BSP_MotorControl_GetMaxSpeed(uint8_t deviceId)
  350. {
  351. uint16_t maxSpeed = 0;
  352. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetMaxSpeed != 0))
  353. {
  354. maxSpeed = motorDrvHandle->GetMaxSpeed(deviceId);
  355. }
  356. else
  357. {
  358. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(12);
  359. }
  360. return(maxSpeed);
  361. }
  362. /******************************************************//**
  363. * @brief Returns the min speed of the specified device
  364. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  365. * For L6208: dummy parameter for compatibility with motor.h
  366. * @retval minSpeed in pps
  367. **********************************************************/
  368. uint16_t BSP_MotorControl_GetMinSpeed(uint8_t deviceId)
  369. {
  370. uint16_t minSpeed = 0;
  371. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetMinSpeed != 0))
  372. {
  373. minSpeed = motorDrvHandle->GetMinSpeed(deviceId);
  374. }
  375. else
  376. {
  377. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(13);
  378. }
  379. return(minSpeed);
  380. }
  381. /******************************************************//**
  382. * @brief Returns the ABS_POSITION of the specified device
  383. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  384. * For L6208: dummy parameter for compatibility with motor.h
  385. * @retval ABS_POSITION register value converted in a 32b signed integer
  386. **********************************************************/
  387. int32_t BSP_MotorControl_GetPosition(uint8_t deviceId)
  388. {
  389. int32_t pos = 0;
  390. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetPosition != 0))
  391. {
  392. pos = motorDrvHandle->GetPosition(deviceId);
  393. }
  394. else
  395. {
  396. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(14);
  397. }
  398. return(pos);
  399. }
  400. /******************************************************//**
  401. * @brief Requests the motor to move to the home position (ABS_POSITION = 0)
  402. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  403. * For L6208: dummy parameter for compatibility with motor.h
  404. * @retval None
  405. **********************************************************/
  406. void BSP_MotorControl_GoHome(uint8_t deviceId)
  407. {
  408. if ((motorDrvHandle != 0)&&(motorDrvHandle->GoHome != 0))
  409. {
  410. motorDrvHandle->GoHome(deviceId);
  411. }
  412. else
  413. {
  414. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(15);
  415. }
  416. }
  417. /******************************************************//**
  418. * @brief Requests the motor to move to the mark position
  419. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  420. * For L6208: dummy parameter for compatibility with motor.h
  421. * @retval None
  422. **********************************************************/
  423. void BSP_MotorControl_GoMark(uint8_t deviceId)
  424. {
  425. if ((motorDrvHandle != 0)&&(motorDrvHandle->GoMark != 0))
  426. {
  427. motorDrvHandle->GoMark(deviceId);
  428. }
  429. else
  430. {
  431. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(16);
  432. }
  433. }
  434. /******************************************************//**
  435. * @brief Requests the motor to move to the specified position
  436. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  437. * For L6208: dummy parameter for compatibility with motor.h
  438. * @param[in] targetPosition absolute position in steps
  439. * @retval None
  440. **********************************************************/
  441. void BSP_MotorControl_GoTo(uint8_t deviceId, int32_t targetPosition)
  442. {
  443. if ((motorDrvHandle != 0)&&(motorDrvHandle->GoTo != 0))
  444. {
  445. motorDrvHandle->GoTo(deviceId, targetPosition);
  446. }
  447. else
  448. {
  449. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(17);
  450. }
  451. }
  452. /******************************************************//**
  453. * @brief Immediatly stops the motor.
  454. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  455. * For L6208: dummy parameter for compatibility with motor.h
  456. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  457. * @retval None
  458. **********************************************************/
  459. void BSP_MotorControl_HardStop(uint8_t deviceId)
  460. {
  461. if ((motorDrvHandle != 0)&&(motorDrvHandle->HardStop != 0))
  462. {
  463. motorDrvHandle->HardStop(deviceId);
  464. }
  465. else
  466. {
  467. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(18);
  468. }
  469. }
  470. /******************************************************//**
  471. * @brief Moves the motor of the specified number of steps
  472. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  473. * For L6208: dummy parameter for compatibility with motor.h
  474. * @param[in] direction FORWARD or BACKWARD
  475. * @param[in] stepCount Number of steps to perform
  476. * @retval None
  477. **********************************************************/
  478. void BSP_MotorControl_Move(uint8_t deviceId, motorDir_t direction, uint32_t stepCount)
  479. {
  480. if ((motorDrvHandle != 0)&&(motorDrvHandle->Move != 0))
  481. {
  482. motorDrvHandle->Move(deviceId, direction, stepCount);
  483. }
  484. else
  485. {
  486. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(19);
  487. }
  488. }
  489. /******************************************************//**
  490. * @brief Resets all motor driver devices
  491. * @retval None
  492. **********************************************************/
  493. void BSP_MotorControl_ResetAllDevices(void)
  494. {
  495. if ((motorDrvHandle != 0)&&(motorDrvHandle->ResetAllDevices != 0))
  496. {
  497. motorDrvHandle->ResetAllDevices();
  498. }
  499. else
  500. {
  501. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(20);
  502. }
  503. }
  504. /******************************************************//**
  505. * @brief Runs the motor. It will accelerate from the min
  506. * speed up to the max speed by using the device acceleration.
  507. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  508. * For L6208: dummy parameter for compatibility with motor.h
  509. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  510. * @param[in] direction FORWARD or BACKWARD
  511. * @retval None
  512. * @note For unidirectionnal brush DC motor, direction parameter
  513. * has no effect
  514. **********************************************************/
  515. void BSP_MotorControl_Run(uint8_t deviceId, motorDir_t direction)
  516. {
  517. if ((motorDrvHandle != 0)&&(motorDrvHandle->Run != 0))
  518. {
  519. motorDrvHandle->Run(deviceId, direction);
  520. }
  521. else
  522. {
  523. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(21);
  524. }
  525. }
  526. /******************************************************//**
  527. * @brief Changes the acceleration of the specified device
  528. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  529. * For L6208: dummy parameter for compatibility with motor.h
  530. * @param[in] newAcc New acceleration to apply in pps^2
  531. * @retval true if the command is successfully executed, else false
  532. * @note The command is not performed is the device is executing
  533. * a MOVE or GOTO command (but it can be used during a RUN command)
  534. **********************************************************/
  535. bool BSP_MotorControl_SetAcceleration(uint8_t deviceId,uint16_t newAcc)
  536. {
  537. bool status = FALSE;
  538. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetAcceleration != 0))
  539. {
  540. status = motorDrvHandle->SetAcceleration(deviceId, newAcc);
  541. }
  542. else
  543. {
  544. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(22);
  545. }
  546. return (status);
  547. }
  548. /******************************************************//**
  549. * @brief Changes the deceleration of the specified device
  550. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  551. * For L6208: dummy parameter for compatibility with motor.h
  552. * @param[in] newDec New deceleration to apply in pps^2
  553. * @retval true if the command is successfully executed, else false
  554. * @note The command is not performed is the device is executing
  555. * a MOVE or GOTO command (but it can be used during a RUN command)
  556. **********************************************************/
  557. bool BSP_MotorControl_SetDeceleration(uint8_t deviceId, uint16_t newDec)
  558. {
  559. bool status = FALSE;
  560. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetDeceleration != 0))
  561. {
  562. status = motorDrvHandle->SetDeceleration(deviceId, newDec);
  563. }
  564. else
  565. {
  566. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(23);
  567. }
  568. return (status);
  569. }
  570. /******************************************************//**
  571. * @brief Set current position to be the Home position (ABS pos set to 0)
  572. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  573. * @param[in] homePosition new absolute home position
  574. * For L6208: dummy parameter for compatibility with motor.h
  575. * @retval None
  576. **********************************************************/
  577. void BSP_MotorControl_SetHome(uint8_t deviceId, int32_t homePosition)
  578. {
  579. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetHome != 0))
  580. {
  581. motorDrvHandle->SetHome(deviceId, homePosition);
  582. }
  583. else
  584. {
  585. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(24);
  586. }
  587. }
  588. /******************************************************//**
  589. * @brief Sets current position to be the Mark position
  590. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  591. * @param[in] markPosition new absolute mark position
  592. * For L6208: dummy parameter for compatibility with motor.h
  593. * @retval None
  594. **********************************************************/
  595. void BSP_MotorControl_SetMark(uint8_t deviceId, int32_t markPosition)
  596. {
  597. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetMark != 0))
  598. {
  599. motorDrvHandle->SetMark(deviceId, markPosition);
  600. }
  601. else
  602. {
  603. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(25);
  604. }
  605. }
  606. /******************************************************//**
  607. * @brief Changes the max speed of the specified device
  608. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  609. * For L6208: dummy parameter for compatibility with motor.h
  610. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  611. * @param[in] newMaxSpeed New max speed to apply in pps for stepper motor,
  612. in % for Brush DC motor (0-100)
  613. * @retval true if the command is successfully executed, else false
  614. * @note For a stepper motor, the command is not performed if the device
  615. * is executing a MOVE or GOTO command (but it can be used during a RUN command).
  616. **********************************************************/
  617. bool BSP_MotorControl_SetMaxSpeed(uint8_t deviceId, uint16_t newMaxSpeed)
  618. {
  619. bool status = FALSE;
  620. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetMaxSpeed != 0))
  621. {
  622. status = motorDrvHandle->SetMaxSpeed(deviceId, newMaxSpeed);
  623. }
  624. else
  625. {
  626. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(26);
  627. }
  628. return (status);
  629. }
  630. /******************************************************//**
  631. * @brief Changes the min speed of the specified device
  632. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  633. * For L6208: dummy parameter for compatibility with motor.h
  634. * @param[in] newMinSpeed New min speed to apply in pps
  635. * @retval true if the command is successfully executed, else false
  636. * @note The command is not performed is the device is executing
  637. * a MOVE or GOTO command (but it can be used during a RUN command).
  638. **********************************************************/
  639. bool BSP_MotorControl_SetMinSpeed(uint8_t deviceId, uint16_t newMinSpeed)
  640. {
  641. bool status = FALSE;
  642. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetMinSpeed != 0))
  643. {
  644. status = motorDrvHandle->SetMinSpeed(deviceId, newMinSpeed);
  645. }
  646. else
  647. {
  648. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(27);
  649. }
  650. return (status);
  651. }
  652. /******************************************************//**
  653. * @brief Stops the motor by using the device deceleration
  654. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  655. * For L6208: dummy parameter for compatibility with motor.h
  656. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  657. * @retval true if the command is successfully executed, else false
  658. * @note The command is not performed is the device is in INACTIVE state.
  659. **********************************************************/
  660. bool BSP_MotorControl_SoftStop(uint8_t deviceId)
  661. {
  662. bool status = FALSE;
  663. if ((motorDrvHandle != 0)&&(motorDrvHandle->SoftStop != 0))
  664. {
  665. status = motorDrvHandle->SoftStop(deviceId);
  666. }
  667. else
  668. {
  669. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(28);
  670. }
  671. return (status);
  672. }
  673. /******************************************************//**
  674. * @brief Handles the device state machine at each step
  675. * or at each tick
  676. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  677. * For L6208: dummy parameter for compatibility with motor.h
  678. * @retval None
  679. * @note Must only be called by the timer ISR
  680. **********************************************************/
  681. void BSP_MotorControl_StepClockHandler(uint8_t deviceId)
  682. {
  683. if ((motorDrvHandle != 0)&&(motorDrvHandle->StepClockHandler != 0))
  684. {
  685. motorDrvHandle->StepClockHandler(deviceId);
  686. }
  687. else
  688. {
  689. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(29);
  690. }
  691. }
  692. /******************************************************//**
  693. * @brief Locks until the device state becomes Inactive
  694. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  695. * For L6208: dummy parameter for compatibility with motor.h
  696. * @retval None
  697. **********************************************************/
  698. void BSP_MotorControl_WaitWhileActive(uint8_t deviceId)
  699. {
  700. if ((motorDrvHandle != 0)&&(motorDrvHandle->WaitWhileActive != 0))
  701. {
  702. motorDrvHandle->WaitWhileActive(deviceId);
  703. }
  704. else
  705. {
  706. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(30);
  707. }
  708. }
  709. /**
  710. * @}
  711. */
  712. /** @defgroup BSP_MotorControl_Control_Functions BSP MotorControl Control Functions
  713. * @{
  714. */
  715. /******************************************************//**
  716. * @brief Issue the Disable command to the motor driver of the specified device
  717. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  718. * For L6208: dummy parameter for compatibility with motor.h
  719. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  720. * @retval None
  721. * @note For brush DC motor, when input of different brigdes are parallelized
  722. * together, the disabling of one bridge leads to the disabling
  723. * of the second one
  724. **********************************************************/
  725. void BSP_MotorControl_CmdDisable(uint8_t deviceId)
  726. {
  727. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdDisable != 0))
  728. {
  729. motorDrvHandle->CmdDisable(deviceId);
  730. }
  731. else
  732. {
  733. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(31);
  734. }
  735. }
  736. /******************************************************//**
  737. * @brief Issues the Enable command to the motor driver of the specified device
  738. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1) for stepper motor
  739. * For L6208: dummy parameter for compatibility with motor.h
  740. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  741. * @retval None
  742. * @note For brush DC motor, when input of different brigdes are parallelized
  743. * together, the enabling of one bridge leads to the enabling
  744. * of the second one
  745. **********************************************************/
  746. void BSP_MotorControl_CmdEnable(uint8_t deviceId)
  747. {
  748. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdEnable != 0))
  749. {
  750. motorDrvHandle->CmdEnable(deviceId);
  751. }
  752. else
  753. {
  754. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(32);
  755. }
  756. }
  757. /******************************************************//**
  758. * @brief Issues the GetParam command to the motor driver of the specified device
  759. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  760. * @param[in] param Register adress (BSP_MotorControl_ABS_POS, BSP_MotorControl_MARK,...)
  761. * @retval Register value
  762. **********************************************************/
  763. uint32_t BSP_MotorControl_CmdGetParam(uint8_t deviceId,
  764. uint32_t param)
  765. {
  766. uint32_t value = 0;
  767. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGetParam != 0))
  768. {
  769. value = motorDrvHandle->CmdGetParam(deviceId, param);
  770. }
  771. else
  772. {
  773. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(33);
  774. }
  775. return (value);
  776. }
  777. /******************************************************//**
  778. * @brief Issues the GetStatus command to the motor driver of the specified
  779. * device for stepper motor,
  780. * Get bridge status for Brush DC motor
  781. * @param[in] deviceId from 0 to MAX_NUMBER_OF_DEVICES - 1 for stepper motor,
  782. bridgeId from 0 for bridge A, 1 for bridge B for brush DC motor
  783. * @retval Status Register value for stepper motor,
  784. * Bridge state for brush DC motor
  785. * @note For stepper motor, once the GetStatus command is performed,
  786. * the flags of the status register are reset.
  787. * This is not the case when the status register is read with the
  788. * GetParam command (via the functions ReadStatusRegister or CmdGetParam).
  789. **********************************************************/
  790. uint16_t BSP_MotorControl_CmdGetStatus(uint8_t deviceId)
  791. {
  792. uint16_t status = 0;
  793. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGetStatus != 0))
  794. {
  795. status = motorDrvHandle->CmdGetStatus(deviceId);
  796. }
  797. else
  798. {
  799. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(34);
  800. }
  801. return (status);
  802. }
  803. /******************************************************//**
  804. * @brief Issues the Nop command to the motor driver of the specified device
  805. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  806. * @retval None
  807. **********************************************************/
  808. void BSP_MotorControl_CmdNop(uint8_t deviceId)
  809. {
  810. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdNop != 0))
  811. {
  812. motorDrvHandle->CmdNop(deviceId);
  813. }
  814. else
  815. {
  816. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(35);
  817. }
  818. }
  819. /******************************************************//**
  820. * @brief Issues the SetParam command to the motor driver of the specified device
  821. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  822. * @param[in] param Register adress (BSP_MotorControl_ABS_POS, BSP_MotorControl_MARK,...)
  823. * @param[in] value Value to set in the register
  824. * @retval None
  825. **********************************************************/
  826. void BSP_MotorControl_CmdSetParam(uint8_t deviceId,
  827. uint32_t param,
  828. uint32_t value)
  829. {
  830. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdSetParam != 0))
  831. {
  832. motorDrvHandle->CmdSetParam(deviceId, param, value);
  833. }
  834. else
  835. {
  836. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(36);
  837. }
  838. }
  839. /******************************************************//**
  840. * @brief Reads the Status Register value
  841. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  842. * @retval Status register valued
  843. * @note The status register flags are not cleared
  844. * at the difference with CmdGetStatus()
  845. **********************************************************/
  846. uint16_t BSP_MotorControl_ReadStatusRegister(uint8_t deviceId)
  847. {
  848. uint16_t status = 0;
  849. if ((motorDrvHandle != 0)&&(motorDrvHandle->ReadStatusRegister != 0))
  850. {
  851. status = motorDrvHandle->ReadStatusRegister(deviceId);
  852. }
  853. else
  854. {
  855. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(37);
  856. }
  857. return (status);
  858. }
  859. /******************************************************//**
  860. * @brief Releases the motor driver (pin set to High) of all devices
  861. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  862. * @retval None
  863. **********************************************************/
  864. void BSP_MotorControl_ReleaseReset(uint8_t deviceId)
  865. {
  866. if ((motorDrvHandle != 0)&&(motorDrvHandle->ReleaseReset != 0))
  867. {
  868. motorDrvHandle->ReleaseReset(deviceId);
  869. }
  870. else
  871. {
  872. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(38);
  873. }
  874. }
  875. /******************************************************//**
  876. * @brief Resets the motor driver (reset pin set to low) of all devices
  877. * @retval None
  878. **********************************************************/
  879. void BSP_MotorControl_Reset(uint8_t deviceId)
  880. {
  881. if ((motorDrvHandle != 0)&&(motorDrvHandle->Reset != 0))
  882. {
  883. motorDrvHandle->Reset(deviceId);
  884. }
  885. else
  886. {
  887. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(39);
  888. }
  889. }
  890. /******************************************************//**
  891. * @brief Set the stepping mode
  892. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  893. * For L6208: dummy parameter for compatibility with motor.h
  894. * @param[in] stepMode from full step to 1/16 microstep as specified in
  895. * enum BSP_MotorControl_STEP_SEL_t
  896. * @retval true if the command is successfully executed, else false
  897. **********************************************************/
  898. bool BSP_MotorControl_SelectStepMode(uint8_t deviceId, motorStepMode_t stepMode)
  899. {
  900. bool value = 0;
  901. if ((motorDrvHandle != 0)&&(motorDrvHandle->SelectStepMode != 0))
  902. {
  903. value = motorDrvHandle->SelectStepMode(deviceId, stepMode);
  904. }
  905. else
  906. {
  907. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(40);
  908. }
  909. return (value);
  910. }
  911. /******************************************************//**
  912. * @brief Specifies the direction
  913. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  914. * For L6208: dummy parameter for compatibility with motor.h
  915. * @param[in] dir FORWARD or BACKWARD
  916. * @note The direction change is only applied if the device
  917. * is in INACTIVE state
  918. * For L6208: In velocity mode a direction change forces the device to stop and
  919. * then run in the new direction. In position mode, if the device is
  920. * running, a direction change will generate an error.
  921. * @retval None
  922. **********************************************************/
  923. void BSP_MotorControl_SetDirection(uint8_t deviceId, motorDir_t dir)
  924. {
  925. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetDirection != 0))
  926. {
  927. motorDrvHandle->SetDirection(deviceId, dir);
  928. }
  929. else
  930. {
  931. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(41);
  932. }
  933. }
  934. /******************************************************//**
  935. * @brief Issues Go To Dir command
  936. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  937. * For L6208: dummy parameter for compatibility with motor.h
  938. * @param[in] dir movement direction
  939. * @param[in] abs_pos absolute position where requested to move
  940. * @retval None
  941. **********************************************************/
  942. void BSP_MotorControl_CmdGoToDir(uint8_t deviceId, motorDir_t dir, int32_t abs_pos)
  943. {
  944. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGoToDir != 0))
  945. {
  946. motorDrvHandle->CmdGoToDir(deviceId, dir, abs_pos);
  947. }
  948. else
  949. {
  950. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(42);
  951. }
  952. }
  953. /******************************************************//**
  954. * @brief Checks if at least one device is busy by checking
  955. * busy pin position.
  956. * The busy pin is shared between all devices.
  957. * @retval One if at least one device is busy, otherwise zero
  958. **********************************************************/
  959. uint8_t BSP_MotorControl_CheckBusyHw(void)
  960. {
  961. uint8_t value = 0;
  962. if ((motorDrvHandle != 0)&&(motorDrvHandle->CheckBusyHw != 0))
  963. {
  964. value = motorDrvHandle->CheckBusyHw();
  965. }
  966. else
  967. {
  968. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(43);
  969. }
  970. return (value);
  971. }
  972. /******************************************************//**
  973. * @brief Checks if at least one device has an alarm flag set
  974. * by reading flag pin position.
  975. * The flag pin is shared between all devices.
  976. * @retval One if at least one device has an alarm flag set ,
  977. * otherwise zero
  978. **********************************************************/
  979. uint8_t BSP_MotorControl_CheckStatusHw(void)
  980. {
  981. uint8_t value = 0;
  982. if ((motorDrvHandle != 0)&&(motorDrvHandle->CheckStatusHw != 0))
  983. {
  984. value = motorDrvHandle->CheckStatusHw();
  985. }
  986. else
  987. {
  988. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(44);
  989. }
  990. return (value);
  991. }
  992. /******************************************************//**
  993. * @brief Issues Go Until command
  994. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  995. * @param[in] action ACTION_RESET or ACTION_COPY
  996. * @param[in] dir movement direction
  997. * @param[in] speed in 2^-28 step/tick
  998. * @retval None
  999. **********************************************************/
  1000. void BSP_MotorControl_CmdGoUntil(uint8_t deviceId, motorAction_t action, motorDir_t dir, uint32_t speed)
  1001. {
  1002. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdGoUntil != 0))
  1003. {
  1004. motorDrvHandle->CmdGoUntil(deviceId, action, dir, speed);
  1005. }
  1006. else
  1007. {
  1008. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(45);
  1009. }
  1010. }
  1011. /******************************************************//**
  1012. * @brief Immediately stops the motor and disable the power bridge.
  1013. * @param[in] deviceId from 0 to MAX_NUMBER_OF_DEVICES-1 for stepper motor
  1014. * motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS for Brush DC motor
  1015. * @retval None
  1016. * @note if two Brush DC motors use the same power bridge, the
  1017. * power bridge will be disable only if the two motors are
  1018. * stopped
  1019. **********************************************************/
  1020. void BSP_MotorControl_CmdHardHiZ(uint8_t deviceId)
  1021. {
  1022. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdHardHiZ != 0))
  1023. {
  1024. motorDrvHandle->CmdHardHiZ(deviceId);
  1025. }
  1026. else
  1027. {
  1028. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(46);
  1029. }
  1030. }
  1031. /******************************************************//**
  1032. * @brief Issues Release SW command
  1033. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1034. * @param[in] action
  1035. * @param[in] dir movement direction
  1036. * @retval None
  1037. **********************************************************/
  1038. void BSP_MotorControl_CmdReleaseSw(uint8_t deviceId, motorAction_t action, motorDir_t dir)
  1039. {
  1040. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdReleaseSw != 0))
  1041. {
  1042. motorDrvHandle->CmdReleaseSw(deviceId, action, dir);
  1043. }
  1044. else
  1045. {
  1046. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(47);
  1047. }
  1048. }
  1049. /******************************************************//**
  1050. * @brief Issues Reset Device command
  1051. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1052. * @retval None
  1053. **********************************************************/
  1054. void BSP_MotorControl_CmdResetDevice(uint8_t deviceId)
  1055. {
  1056. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdResetDevice != 0))
  1057. {
  1058. motorDrvHandle->CmdResetDevice(deviceId);
  1059. }
  1060. else
  1061. {
  1062. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(48);
  1063. }
  1064. }
  1065. /******************************************************//**
  1066. * @brief Issues Reset Pos command
  1067. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1068. * @retval None
  1069. **********************************************************/
  1070. void BSP_MotorControl_CmdResetPos(uint8_t deviceId)
  1071. {
  1072. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdResetPos != 0))
  1073. {
  1074. motorDrvHandle->CmdResetPos(deviceId);
  1075. }
  1076. else
  1077. {
  1078. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(49);
  1079. }
  1080. }
  1081. /******************************************************//**
  1082. * @brief Issues Run command
  1083. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1084. * @param[in] dir Movement direction (FORWARD, BACKWARD)
  1085. * @param[in] speed in 2^-28 step/tick
  1086. * @retval None
  1087. **********************************************************/
  1088. void BSP_MotorControl_CmdRun(uint8_t deviceId, motorDir_t dir, uint32_t speed)
  1089. {
  1090. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdRun != 0))
  1091. {
  1092. motorDrvHandle->CmdRun(deviceId, dir, speed);
  1093. }
  1094. else
  1095. {
  1096. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(50);
  1097. }
  1098. }
  1099. /******************************************************//**
  1100. * @brief Issues Soft HiZ command
  1101. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1102. * @retval None
  1103. **********************************************************/
  1104. void BSP_MotorControl_CmdSoftHiZ(uint8_t deviceId)
  1105. {
  1106. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdSoftHiZ != 0))
  1107. {
  1108. motorDrvHandle->CmdSoftHiZ(deviceId);
  1109. }
  1110. else
  1111. {
  1112. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(51);
  1113. }
  1114. }
  1115. /******************************************************//**
  1116. * @brief Issues Step Clock command
  1117. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1118. * @param[in] dir Movement direction (FORWARD, BACKWARD)
  1119. * @retval None
  1120. **********************************************************/
  1121. void BSP_MotorControl_CmdStepClock(uint8_t deviceId, motorDir_t dir)
  1122. {
  1123. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdStepClock != 0))
  1124. {
  1125. motorDrvHandle->CmdStepClock(deviceId, dir);
  1126. }
  1127. else
  1128. {
  1129. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(52);
  1130. }
  1131. }
  1132. /******************************************************//**
  1133. * @brief Fetch and clear status flags of all devices
  1134. * by issuing a GET_STATUS command simultaneously
  1135. * to all devices.
  1136. * Then, the fetched status of each device can be retrieved
  1137. * by using the BSP_MotorControl_GetFetchedStatus function
  1138. * provided there is no other calls to functions which
  1139. * use the SPI in between.
  1140. * @retval None
  1141. **********************************************************/
  1142. void BSP_MotorControl_FetchAndClearAllStatus(void)
  1143. {
  1144. if ((motorDrvHandle != 0)&&(motorDrvHandle->FetchAndClearAllStatus != 0))
  1145. {
  1146. motorDrvHandle->FetchAndClearAllStatus();
  1147. }
  1148. else
  1149. {
  1150. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(53);
  1151. }
  1152. }
  1153. /******************************************************//**
  1154. * @brief Get the value of the STATUS register which was
  1155. * fetched by using BSP_MotorControl_FetchAndClearAllStatus.
  1156. * The fetched values are available as long as there is
  1157. * no other calls to functions which use the SPI.
  1158. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1159. * @retval Last fetched value of the STATUS register
  1160. **********************************************************/
  1161. uint16_t BSP_MotorControl_GetFetchedStatus(uint8_t deviceId)
  1162. {
  1163. uint16_t value = 0;
  1164. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetFetchedStatus != 0))
  1165. {
  1166. value = motorDrvHandle->GetFetchedStatus(deviceId);
  1167. }
  1168. else
  1169. {
  1170. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(54);
  1171. }
  1172. return (value);
  1173. }
  1174. /******************************************************//**
  1175. * @brief Return the number of devices in the daisy chain
  1176. * @retval number of devices from 1 to MAX_NUMBER_OF_DEVICES
  1177. **********************************************************/
  1178. uint8_t BSP_MotorControl_GetNbDevices(void)
  1179. {
  1180. uint8_t value = 0;
  1181. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetNbDevices != 0))
  1182. {
  1183. value = motorDrvHandle->GetNbDevices();
  1184. }
  1185. else
  1186. {
  1187. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(55);
  1188. }
  1189. return (value);
  1190. }
  1191. /******************************************************//**
  1192. * @brief Checks if the specified device is busy
  1193. * by reading the Busy bit of its status Register
  1194. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1195. * @retval true if device is busy, else false
  1196. **********************************************************/
  1197. bool BSP_MotorControl_IsDeviceBusy(uint8_t deviceId)
  1198. {
  1199. bool value = 0;
  1200. if ((motorDrvHandle != 0)&&(motorDrvHandle->IsDeviceBusy != 0))
  1201. {
  1202. value = motorDrvHandle->IsDeviceBusy(deviceId);
  1203. }
  1204. else
  1205. {
  1206. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(56);
  1207. }
  1208. return (value);
  1209. }
  1210. /******************************************************//**
  1211. * @brief Sends commands stored in the queue by previously
  1212. * BSP_MotorControl_QueueCommands
  1213. * @retval None
  1214. *********************************************************/
  1215. void BSP_MotorControl_SendQueuedCommands(void)
  1216. {
  1217. if ((motorDrvHandle != 0)&&(motorDrvHandle->SendQueuedCommands != 0))
  1218. {
  1219. motorDrvHandle->SendQueuedCommands();
  1220. }
  1221. else
  1222. {
  1223. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(57);
  1224. }
  1225. }
  1226. /******************************************************//**
  1227. * @brief Put commands in queue before synchronous sending
  1228. * done by calling BSP_MotorControl_SendQueuedCommands.
  1229. * Any call to functions that use the SPI between the calls of
  1230. * BSP_MotorControl_QueueCommands and BSP_MotorControl_SendQueuedCommands
  1231. * will corrupt the queue.
  1232. * A command for each device of the daisy chain must be
  1233. * specified before calling BSP_MotorControl_SendQueuedCommands.
  1234. * @param[in] deviceId deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1235. * @param[in] command Command to queue (all BSP_MotorControl commmands
  1236. * except SET_PARAM, GET_PARAM, GET_STATUS)
  1237. * @param[in] value argument of the command to queue
  1238. * @retval None
  1239. *********************************************************/
  1240. void BSP_MotorControl_QueueCommands(uint8_t deviceId, uint8_t command, int32_t value)
  1241. {
  1242. if ((motorDrvHandle != 0)&&(motorDrvHandle->QueueCommands != 0))
  1243. {
  1244. motorDrvHandle->QueueCommands(deviceId, command, value);
  1245. }
  1246. else
  1247. {
  1248. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(58);
  1249. }
  1250. }
  1251. /******************************************************//**
  1252. * @brief Locks until all devices become not busy
  1253. * @retval None
  1254. **********************************************************/
  1255. void BSP_MotorControl_WaitForAllDevicesNotBusy(void)
  1256. {
  1257. if ((motorDrvHandle != 0)&&(motorDrvHandle->WaitForAllDevicesNotBusy != 0))
  1258. {
  1259. motorDrvHandle->WaitForAllDevicesNotBusy();
  1260. }
  1261. else
  1262. {
  1263. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(59);
  1264. }
  1265. }
  1266. /******************************************************//**
  1267. * @brief Handler of the busy interrupt which calls the user callback (if defined)
  1268. * @retval None
  1269. **********************************************************/
  1270. void BSP_MotorControl_BusyInterruptHandler(void)
  1271. {
  1272. if ((motorDrvHandle != 0)&&(motorDrvHandle->BusyInterruptHandler != 0))
  1273. {
  1274. motorDrvHandle->BusyInterruptHandler();
  1275. }
  1276. else
  1277. {
  1278. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(61);
  1279. }
  1280. }
  1281. /******************************************************//**
  1282. * @brief Issues Soft Stop command
  1283. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1284. * @retval None
  1285. **********************************************************/
  1286. void BSP_MotorControl_CmdSoftStop(uint8_t deviceId)
  1287. {
  1288. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdSoftStop != 0))
  1289. {
  1290. motorDrvHandle->CmdSoftStop(deviceId);
  1291. }
  1292. else
  1293. {
  1294. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(62);
  1295. }
  1296. }
  1297. /******************************************************//**
  1298. * @brief Start the step clock by using the given frequency
  1299. * @param[in] newFreq in Hz of the step clock
  1300. * @retval None
  1301. * @note The frequency is directly the current speed of the device
  1302. **********************************************************/
  1303. void BSP_MotorControl_StartStepClock(uint16_t newFreq)
  1304. {
  1305. if ((motorDrvHandle != 0)&&(motorDrvHandle->StartStepClock != 0))
  1306. {
  1307. motorDrvHandle->StartStepClock(newFreq);
  1308. }
  1309. else
  1310. {
  1311. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(63);
  1312. }
  1313. }
  1314. /******************************************************//**
  1315. * @brief Stops the PWM uses for the step clock
  1316. * @retval None
  1317. **********************************************************/
  1318. void BSP_MotorControl_StopStepClock(void)
  1319. {
  1320. if ((motorDrvHandle != 0)&&(motorDrvHandle->StopStepClock != 0))
  1321. {
  1322. motorDrvHandle->StopStepClock();
  1323. }
  1324. else
  1325. {
  1326. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(64);
  1327. }
  1328. }
  1329. /******************************************************//**
  1330. * @brief Set the dual full bridge configuration
  1331. * @param[in] config bridge configuration to apply
  1332. * for L6206, see dualFullBridgeConfig_t enum
  1333. * for Stspin240, 0 for a mono brush DC configuration, 1 for a dual brush DC configuration
  1334. * for Stspin250, 0 only as no dual brush DC configuration is supported
  1335. * @retval None
  1336. **********************************************************/
  1337. void BSP_MotorControl_SetDualFullBridgeConfig(uint8_t config)
  1338. {
  1339. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetDualFullBridgeConfig != 0))
  1340. {
  1341. motorDrvHandle->SetDualFullBridgeConfig(config);
  1342. }
  1343. else
  1344. {
  1345. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(65);
  1346. }
  1347. }
  1348. /******************************************************//**
  1349. * @brief Get the PWM frequency of the bridge input
  1350. * @param[in] bridgeId from 0 for bridge A to 1 for bridge B for brush DC motor
  1351. * bridgeId must be 0 for L6208 (both bridges are set with the same frequency)
  1352. * @retval Freq in Hz
  1353. **********************************************************/
  1354. uint32_t BSP_MotorControl_GetBridgeInputPwmFreq(uint8_t bridgeId)
  1355. {
  1356. uint32_t pwmFreq = 0;
  1357. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetBridgeInputPwmFreq != 0))
  1358. {
  1359. pwmFreq = motorDrvHandle->GetBridgeInputPwmFreq(bridgeId);
  1360. }
  1361. else
  1362. {
  1363. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(66);
  1364. }
  1365. return (pwmFreq);
  1366. }
  1367. /******************************************************//**
  1368. * @brief Changes the PWM frequency of the bridge input
  1369. * @param[in] bridgeId from 0 for bridge A to 1 for bridge B for brush DC motor
  1370. * bridgeId must be 0 for L6208 (both bridges are set with the same frequency)
  1371. * @param[in] newFreq in Hz up to 100000Hz
  1372. * @retval None
  1373. **********************************************************/
  1374. void BSP_MotorControl_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq)
  1375. {
  1376. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetBridgeInputPwmFreq != 0))
  1377. {
  1378. motorDrvHandle->SetBridgeInputPwmFreq(bridgeId, newFreq);
  1379. }
  1380. else
  1381. {
  1382. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(67);
  1383. }
  1384. }
  1385. /******************************************************//**
  1386. * @brief Select the mode to stop the motor. When the motor
  1387. * is stopped, if autoHiZ is TRUE, the power bridges are disabled
  1388. * if autoHiZ is FALSE, the power bridges are kept enabled.
  1389. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1390. * deviceId dummy parameter for compatibility with motor.h
  1391. * @param[in] stopMode selected stop mode
  1392. * @retval None
  1393. **********************************************************/
  1394. void BSP_MotorControl_SetStopMode(uint8_t deviceId, motorStopMode_t stopMode)
  1395. {
  1396. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetStopMode != 0))
  1397. {
  1398. motorDrvHandle->SetStopMode(deviceId, stopMode);
  1399. }
  1400. else
  1401. {
  1402. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(68);
  1403. }
  1404. }
  1405. /******************************************************//**
  1406. * @brief Get the selected stop mode
  1407. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1408. * For L6208: dummy parameter for compatibility with motor.h
  1409. * @retval the selected stop mode
  1410. **********************************************************/
  1411. motorStopMode_t BSP_MotorControl_GetStopMode(uint8_t deviceId)
  1412. {
  1413. motorStopMode_t stopMode = UNKNOW_STOP_MODE;
  1414. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetStopMode != 0))
  1415. {
  1416. stopMode = motorDrvHandle->GetStopMode(deviceId);
  1417. }
  1418. else
  1419. {
  1420. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(69);
  1421. }
  1422. return (stopMode);
  1423. }
  1424. /******************************************************//**
  1425. * @brief Select the motor decay mode
  1426. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1427. * For L6208: dummy parameter for compatibility with motor.h
  1428. * @param[in] decayMode (SLOW_DECAY or FAST_DECAY)
  1429. * @retval None
  1430. **********************************************************/
  1431. void BSP_MotorControl_SetDecayMode(uint8_t deviceId, motorDecayMode_t decayMode)
  1432. {
  1433. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetDecayMode != 0))
  1434. {
  1435. motorDrvHandle->SetDecayMode(deviceId, decayMode);
  1436. }
  1437. else
  1438. {
  1439. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(70);
  1440. }
  1441. }
  1442. /******************************************************//**
  1443. * @brief Get the motor decay mode
  1444. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1445. * For L6208: dummy parameter for compatibility with motor.h
  1446. * @retval decay mode
  1447. **********************************************************/
  1448. motorDecayMode_t BSP_MotorControl_GetDecayMode(uint8_t deviceId)
  1449. {
  1450. motorDecayMode_t decayMode = UNKNOW_DECAY;
  1451. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetDecayMode != 0))
  1452. {
  1453. decayMode = motorDrvHandle->GetDecayMode(deviceId);
  1454. }
  1455. else
  1456. {
  1457. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(71);
  1458. }
  1459. return (decayMode);
  1460. }
  1461. /******************************************************//**
  1462. * @brief Get the motor step mode
  1463. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1464. * For L6208: dummy parameter for compatibility with motor.h
  1465. * @retval step mode
  1466. **********************************************************/
  1467. motorStepMode_t BSP_MotorControl_GetStepMode(uint8_t deviceId)
  1468. {
  1469. motorStepMode_t stepMode = STEP_MODE_UNKNOW;
  1470. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetStepMode != 0))
  1471. {
  1472. stepMode = motorDrvHandle->GetStepMode(deviceId);
  1473. }
  1474. else
  1475. {
  1476. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(72);
  1477. }
  1478. return (stepMode);
  1479. }
  1480. /******************************************************//**
  1481. * @brief Get the motor direction
  1482. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1483. * For L6208: dummy parameter for compatibility with motor.h
  1484. * @retval direction
  1485. **********************************************************/
  1486. motorDir_t BSP_MotorControl_GetDirection(uint8_t deviceId)
  1487. {
  1488. motorDir_t dir = UNKNOW_DIR;
  1489. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetDirection != 0))
  1490. {
  1491. dir = motorDrvHandle->GetDirection(deviceId);
  1492. }
  1493. else
  1494. {
  1495. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(73);
  1496. }
  1497. return (dir);
  1498. }
  1499. /******************************************************//**
  1500. * @brief Exit specified device from reset
  1501. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES-1 )
  1502. * @retval None
  1503. **********************************************************/
  1504. void BSP_MotorControl_ExitDeviceFromReset(uint8_t deviceId)
  1505. {
  1506. if ((motorDrvHandle != 0)&&(motorDrvHandle->ExitDeviceFromReset != 0))
  1507. {
  1508. motorDrvHandle->ExitDeviceFromReset(deviceId);
  1509. }
  1510. else
  1511. {
  1512. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(74);
  1513. }
  1514. }
  1515. /******************************************************//**
  1516. * @brief Get the motor torque
  1517. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1518. * @param[in] torqueMode Torque mode as specified in enum motorTorqueMode_t
  1519. * @retval torque value in % (from 0 to 100)
  1520. **********************************************************/
  1521. uint8_t BSP_MotorControl_GetTorque(uint8_t deviceId, motorTorqueMode_t torqueMode)
  1522. {
  1523. uint8_t torqueValue = 0;
  1524. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetTorque != 0))
  1525. {
  1526. torqueValue = motorDrvHandle->GetTorque(deviceId, torqueMode);
  1527. }
  1528. else
  1529. {
  1530. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(76);
  1531. }
  1532. return (torqueValue);
  1533. }
  1534. /******************************************************//**
  1535. * @brief Set the motor torque
  1536. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1537. * @param[in] torqueMode Torque mode as specified in enum motorTorqueMode_t
  1538. * @param[in] torqueValue in % (from 0 to 100)
  1539. * @retval None
  1540. **********************************************************/
  1541. void BSP_MotorControl_SetTorque(uint8_t deviceId, motorTorqueMode_t torqueMode, uint8_t torqueValue)
  1542. {
  1543. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetTorque != 0))
  1544. {
  1545. motorDrvHandle->SetTorque(deviceId, torqueMode, torqueValue);
  1546. }
  1547. else
  1548. {
  1549. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(75);
  1550. }
  1551. }
  1552. /******************************************************//**
  1553. * @brief Set the PWM frequency of Ref
  1554. * @param[in] refId Id of the targeted Ref
  1555. * @param[in] newFreq frequency in Hz
  1556. * @retval None
  1557. **********************************************************/
  1558. void BSP_MotorControl_SetRefFreq(uint8_t refId, uint32_t newFreq)
  1559. {
  1560. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetRefFreq != 0))
  1561. {
  1562. motorDrvHandle->SetRefFreq(refId, newFreq);
  1563. }
  1564. else
  1565. {
  1566. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(77);
  1567. }
  1568. }
  1569. /******************************************************//**
  1570. * @brief Return the PWM frequency of Ref
  1571. * @param[in] refId Id of the targeted Ref
  1572. * @retval frequency in Hz
  1573. **********************************************************/
  1574. uint32_t BSP_MotorControl_GetRefFreq(uint8_t refId)
  1575. {
  1576. uint32_t value = 0;
  1577. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetRefFreq != 0))
  1578. {
  1579. value = motorDrvHandle->GetRefFreq(refId);
  1580. }
  1581. else
  1582. {
  1583. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(78);
  1584. }
  1585. return (value);
  1586. }
  1587. /******************************************************//**
  1588. * @brief Set the PWM duty cycle of Ref
  1589. * @param[in] refId Id of the targeted Ref
  1590. * @param[in] newDc duty cycle in % (from 0 to 100)
  1591. * @retval None
  1592. **********************************************************/
  1593. void BSP_MotorControl_SetRefDc(uint8_t refId, uint8_t newDc)
  1594. {
  1595. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetRefDc != 0))
  1596. {
  1597. motorDrvHandle->SetRefDc(refId, newDc);
  1598. }
  1599. else
  1600. {
  1601. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(79);
  1602. }
  1603. }
  1604. /******************************************************//**
  1605. * @brief Return the PWM duty cycle of Ref
  1606. * @param[in] refId Id of the targeted Ref
  1607. * @retval duty cycle in % (from 0 to 100)
  1608. **********************************************************/
  1609. uint8_t BSP_MotorControl_GetRefDc(uint8_t refId)
  1610. {
  1611. uint8_t value = 0;
  1612. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetRefDc != 0))
  1613. {
  1614. value = motorDrvHandle->GetRefDc(refId);
  1615. }
  1616. else
  1617. {
  1618. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(80);
  1619. }
  1620. return (value);
  1621. }
  1622. /******************************************************//**
  1623. * @brief Set the number of devices in the daisy chain
  1624. * @param[in] id Component Id (L6474, Powerstep01,...)
  1625. * @param[in] nbDevices the number of devices to be used
  1626. * from 1 to MAX_NUMBER_OF_DEVICES
  1627. * @retval TRUE if successfull, FALSE if failure, attempt
  1628. * to set a number of devices greater than MAX_NUMBER_OF_DEVICES
  1629. **********************************************************/
  1630. bool BSP_MotorControl_SetNbDevices(uint16_t id, uint8_t nbDevices)
  1631. {
  1632. MotorControlBoardId = id;
  1633. bool status = FALSE;
  1634. if (id == BSP_MOTOR_CONTROL_BOARD_ID_L6474)
  1635. {
  1636. motorDrvHandle = L6474_GetMotorHandle();
  1637. }
  1638. else if (id == BSP_MOTOR_CONTROL_BOARD_ID_POWERSTEP01)
  1639. {
  1640. motorDrvHandle = Powerstep01_GetMotorHandle();
  1641. }
  1642. else if (id == BSP_MOTOR_CONTROL_BOARD_ID_L6206)
  1643. {
  1644. motorDrvHandle = L6206_GetMotorHandle();
  1645. }
  1646. else if (id == BSP_MOTOR_CONTROL_BOARD_ID_L6208)
  1647. {
  1648. motorDrvHandle = L6208_GetMotorHandle();
  1649. }
  1650. else if (id == BSP_MOTOR_CONTROL_BOARD_ID_STSPIN220)
  1651. {
  1652. motorDrvHandle = Stspin220_GetMotorHandle();
  1653. }
  1654. else if ( (id == BSP_MOTOR_CONTROL_BOARD_ID_L6470) ||
  1655. (id == BSP_MOTOR_CONTROL_BOARD_ID_L6472) )
  1656. {
  1657. motorDrvHandle = l647x_GetMotorHandle();
  1658. }
  1659. else if ( (id == BSP_MOTOR_CONTROL_BOARD_ID_L6480) ||
  1660. (id == BSP_MOTOR_CONTROL_BOARD_ID_L6482) )
  1661. {
  1662. motorDrvHandle = l648x_GetMotorHandle();
  1663. }
  1664. else if ((id == BSP_MOTOR_CONTROL_BOARD_ID_STSPIN240)||
  1665. (id == BSP_MOTOR_CONTROL_BOARD_ID_STSPIN250))
  1666. {
  1667. motorDrvHandle = Stspin240_250_GetMotorHandle();
  1668. }
  1669. else
  1670. {
  1671. motorDrvHandle = 0;
  1672. }
  1673. if ((motorDrvHandle != 0)&&
  1674. (motorDrvHandle->SetNbDevices != 0)&&
  1675. (nbDevices !=0))
  1676. {
  1677. status = motorDrvHandle->SetNbDevices(nbDevices);
  1678. }
  1679. return (status);
  1680. }
  1681. /******************************************************//**
  1682. * @brief Set the parameter param in the motor driver of the specified device
  1683. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1684. * @param[in] param Register adress (BSP_MotorControl_ABS_POS, BSP_MotorControl_MARK,...)
  1685. * @param[in] value Floating point value to convert and set into the register
  1686. * @retval None
  1687. **********************************************************/
  1688. bool BSP_MotorControl_SetAnalogValue(uint8_t deviceId, uint32_t param, float value)
  1689. {
  1690. bool status = FALSE;
  1691. if ((motorDrvHandle != 0)&&(motorDrvHandle->CmdSetParam != 0))
  1692. {
  1693. status = motorDrvHandle->SetAnalogValue(deviceId, param, value);
  1694. }
  1695. else
  1696. {
  1697. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(82);
  1698. }
  1699. return (status);
  1700. }
  1701. /******************************************************//**
  1702. * @brief Get the parameter param in the motor driver of the specified device
  1703. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1704. * @param[in] param Register adress (BSP_MotorControl_ABS_POS, BSP_MotorControl_MARK,...)
  1705. * @retval Floating point value corresponding to the register value
  1706. **********************************************************/
  1707. float BSP_MotorControl_GetAnalogValue(uint8_t deviceId, uint32_t param)
  1708. {
  1709. float value = 0;
  1710. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetAnalogValue != 0))
  1711. {
  1712. value = motorDrvHandle->GetAnalogValue(deviceId, param);
  1713. }
  1714. else
  1715. {
  1716. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(83);
  1717. }
  1718. return (value);
  1719. }
  1720. /******************************************************//**
  1721. * @brief Enable or disable the torque boost
  1722. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1723. * @param[in] enable true to enable torque boost, false to disable
  1724. * @retval None
  1725. **********************************************************/
  1726. void BSP_MotorControl_SetTorqueBoostEnable(uint8_t deviceId, bool enable)
  1727. {
  1728. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetTorqueBoostEnable != 0))
  1729. {
  1730. motorDrvHandle->SetTorqueBoostEnable(deviceId, enable);
  1731. }
  1732. else
  1733. {
  1734. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(84);
  1735. }
  1736. }
  1737. /******************************************************//**
  1738. * @brief Get the torque boost feature status
  1739. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1740. * @retval TRUE if enabled, FALSE if disabled
  1741. **********************************************************/
  1742. bool BSP_MotorControl_GetTorqueBoostEnable(uint8_t deviceId)
  1743. {
  1744. bool status = FALSE;
  1745. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetTorqueBoostEnable != 0))
  1746. {
  1747. status = motorDrvHandle->GetTorqueBoostEnable(deviceId);
  1748. }
  1749. else
  1750. {
  1751. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(85);
  1752. }
  1753. return status;
  1754. }
  1755. /******************************************************//**
  1756. * @brief Set the torque boost threshold
  1757. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1758. * @param[in] speedThreshold speed threshold above which the step mode is
  1759. * changed to full step
  1760. * @retval None
  1761. **********************************************************/
  1762. void BSP_MotorControl_SetTorqueBoostThreshold(uint8_t deviceId, uint16_t speedThreshold)
  1763. {
  1764. if ((motorDrvHandle != 0)&&(motorDrvHandle->SetTorqueBoostThreshold != 0))
  1765. {
  1766. motorDrvHandle->SetTorqueBoostThreshold(deviceId, speedThreshold);
  1767. }
  1768. else
  1769. {
  1770. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(86);
  1771. }
  1772. }
  1773. /******************************************************//**
  1774. * @brief Get the torque boost threshold
  1775. * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES - 1)
  1776. * @retval the torque boost threshold above which the step mode is
  1777. * changed to full step
  1778. **********************************************************/
  1779. uint16_t BSP_MotorControl_GetTorqueBoostThreshold(uint8_t deviceId)
  1780. {
  1781. uint16_t value = 0;
  1782. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetTorqueBoostThreshold != 0))
  1783. {
  1784. value = motorDrvHandle->GetTorqueBoostThreshold(deviceId);
  1785. }
  1786. else
  1787. {
  1788. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(87);
  1789. }
  1790. return value;
  1791. }
  1792. /******************************************************//**
  1793. * @brief Get the dual full bridge configuration
  1794. * return config bridge configuration to apply
  1795. * for L6206, see dualFullBridgeConfig_t enum
  1796. * for Stspin240, 0 for a mono brush DC configuration, 1 for a dual brush DC configuration
  1797. * for Stspin250, 0 only as no dual brush DC configuration is supported
  1798. **********************************************************/
  1799. uint8_t BSP_MotorControl_GetDualFullBridgeConfig(void)
  1800. {
  1801. uint8_t value = 0;
  1802. if ((motorDrvHandle != 0)&&(motorDrvHandle->GetDualFullBridgeConfig != 0))
  1803. {
  1804. value = motorDrvHandle->GetDualFullBridgeConfig();
  1805. }
  1806. else
  1807. {
  1808. MOTOR_CONTROL_ERROR_UNDEFINED_FUNCTION(88);
  1809. }
  1810. return value;
  1811. }
  1812. /**
  1813. * @}
  1814. */
  1815. /**
  1816. * @}
  1817. */
  1818. /**
  1819. * @}
  1820. */
  1821. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/