Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: HelloWorld_IHM02A1 ConcorsoFinal HelloWorld_IHM02A1_mbedOS HelloWorld_IHM02A1-Serialinterpreter ... more
Fork of X_NUCLEO_IHM02A1 by
L6470.h
00001 /** 00002 ****************************************************************************** 00003 * @file L6470.h 00004 * @author Davide Aliprandi, STMicroelectronics 00005 * @version V1.0.0 00006 * @date November 12th, 2015 00007 * @brief This file contains the class of an L6470 Motor Control component. 00008 ****************************************************************************** 00009 * 00010 * COPYRIGHT(c) 2014 STMicroelectronics 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 00038 /* Generated with STM32CubeTOO -----------------------------------------------*/ 00039 00040 00041 /* Revision ------------------------------------------------------------------*/ 00042 /* 00043 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev 00044 Branch/Trunk/Tag: trunk 00045 Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.h 00046 Revision: 0 00047 */ 00048 00049 00050 /* Define to prevent recursive inclusion -------------------------------------*/ 00051 00052 #ifndef __L6470_CLASS_H 00053 #define __L6470_CLASS_H 00054 00055 00056 /* Includes ------------------------------------------------------------------*/ 00057 00058 /* ACTION 1 ------------------------------------------------------------------* 00059 * Include here platform specific header files. * 00060 *----------------------------------------------------------------------------*/ 00061 #include "mbed.h" 00062 #include "DevSPI.h" 00063 /* ACTION 2 ------------------------------------------------------------------* 00064 * Include here component specific header files. * 00065 *----------------------------------------------------------------------------*/ 00066 #include "L6470_def.h" 00067 /* ACTION 3 ------------------------------------------------------------------* 00068 * Include here interface specific header files. * 00069 * * 00070 * Example: * 00071 * #include "HumiditySensor.h" * 00072 * #include "TemperatureSensor.h" * 00073 *----------------------------------------------------------------------------*/ 00074 #include "StepperMotor.h" 00075 00076 00077 /* Classes -------------------------------------------------------------------*/ 00078 00079 /** 00080 * @brief Class representing a L6470 component. 00081 */ 00082 class L6470 : public StepperMotor 00083 { 00084 public: 00085 00086 /*** Public Component Related Types ***/ 00087 00088 /** 00089 * @brief Prepared Actions. 00090 */ 00091 typedef enum 00092 { 00093 PREPARED_NO_ACTION = 0, 00094 PREPARED_GET_POSITION, 00095 PREPARED_GET_MARK, 00096 PREPARED_GET_SPEED, 00097 PREPARED_GET_MAX_SPEED, 00098 PREPARED_GET_MIN_SPEED, 00099 PREPARED_GET_ACCELERATION, 00100 PREPARED_GET_DECELERATION, 00101 PREPARED_GET_DIRECTION, 00102 PREPARED_SET_MARK 00103 } prepared_action_t; 00104 00105 00106 /*** Constructor and Destructor Methods ***/ 00107 00108 /** 00109 * @brief Constructor. 00110 * @param flag_irq pin name of the FLAG pin of the component. 00111 * @param busy_irq pin name of the BUSY pin of the component. 00112 * @param standby_reset pin name of the STBY\RST pin of the component. 00113 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication. 00114 * @param spi SPI device to be used for communication. 00115 */ 00116 L6470(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), busy_irq(busy_irq), standby_reset(standby_reset), ssel(ssel), dev_spi(spi) 00117 { 00118 /* ACTION 4 ----------------------------------------------------------* 00119 * Initialize here the component's member variables, one variable per * 00120 * line. * 00121 * * 00122 * Example: * 00123 * measure = 0; * 00124 * instance_id = number_of_instances++; * 00125 *--------------------------------------------------------------------*/ 00126 L6470_Register = &_L6470_Register[0]; 00127 L6470_ApplicationCommand = &_L6470_ApplicationCommand[0]; 00128 L6470_Direction = &_L6470_Direction[0]; 00129 L6470_ACT = &_L6470_ACT[0]; 00130 pL6470_StatusRegister = &L6470_StatusRegister; 00131 prepared_action = PREPARED_NO_ACTION; 00132 L6470_Id = number_of_devices++; 00133 L6470_DaisyChain_HalfPrepared = ZERO_F; 00134 memset(L6470_AppCmdPkg, 0, L6470DAISYCHAINSIZE * sizeof(sL6470_AppCmdPkg_t)); 00135 memset(L6470_DaisyChainSpiTxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t)); 00136 memset(L6470_DaisyChainSpiRxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t)); 00137 } 00138 00139 /** 00140 * @brief Destructor. 00141 */ 00142 virtual ~L6470(void) {} 00143 00144 00145 /*** Public Component Related Methods ***/ 00146 00147 /* ACTION 5 --------------------------------------------------------------* 00148 * Implement here the component's public methods, as wrappers of the C * 00149 * component's functions. * 00150 * They should be: * 00151 * + Methods with the same name of the C component's virtual table's * 00152 * functions (1); * 00153 * + Methods with the same name of the C component's extended virtual * 00154 * table's functions, if any (2). * 00155 * * 00156 * Example: * 00157 * virtual int get_value(float *p_data) //(1) * 00158 * { * 00159 * return COMPONENT_get_value(float *pf_data); * 00160 * } * 00161 * * 00162 * virtual int enable_feature(void) //(2) * 00163 * { * 00164 * return COMPONENT_enable_feature(); * 00165 * } * 00166 *------------------------------------------------------------------------*/ 00167 /** 00168 * @brief Initializing the component. 00169 * @param init Pointer to device specific initalization structure. 00170 * @retval "0" in case of success, an error code otherwise. 00171 */ 00172 virtual int init(void *init) 00173 { 00174 return (int) L6470_Config((void *) init); 00175 } 00176 00177 /** 00178 * @brief Getting the ID of the component. 00179 * @param id Pointer to an allocated variable to store the ID into. 00180 * @retval "0" in case of success, an error code otherwise. 00181 */ 00182 virtual int read_id(uint8_t *id) 00183 { 00184 return (int) 0; 00185 } 00186 00187 /** 00188 * @brief Getting the status. 00189 * @param None. 00190 * @retval The status. 00191 */ 00192 virtual unsigned int get_status(void) 00193 { 00194 return (unsigned int) L6470_GetStatus(); 00195 } 00196 00197 /** 00198 * @brief Getting a parameter. 00199 * @param parameter A parameter's register address. 00200 * @retval The parameter's value. 00201 * @note The parameter can be one of the following: 00202 * + L6470_ABS_POS_ID 00203 * + L6470_EL_POS_ID 00204 * + L6470_MARK_ID 00205 * + L6470_SPEED_ID 00206 * + L6470_ACC_ID 00207 * + L6470_DEC_ID 00208 * + L6470_MAX_SPEED_ID 00209 * + L6470_MIN_SPEED_ID 00210 * + L6470_FS_SPD_ID 00211 * + L6470_KVAL_HOLD_ID 00212 * + L6470_KVAL_RUN_ID 00213 * + L6470_KVAL_ACC_ID 00214 * + L6470_KVAL_DEC_ID 00215 * + L6470_INT_SPEED_ID 00216 * + L6470_ST_SLP_ID 00217 * + L6470_FN_SLP_ACC_ID 00218 * + L6470_FN_SLP_DEC_ID 00219 * + L6470_K_THERM_ID 00220 * + L6470_ADC_OUT_ID 00221 * + L6470_OCD_TH_ID 00222 * + L6470_STALL_TH_ID 00223 * + L6470_STEP_MODE_ID 00224 * + L6470_ALARM_EN_ID 00225 * + L6470_CONFIG_ID 00226 * + L6470_STATUS_ID 00227 */ 00228 virtual unsigned int get_parameter(unsigned int parameter) 00229 { 00230 return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter); 00231 } 00232 00233 /** 00234 * @brief Getting the position. 00235 * @param None. 00236 * @retval The position. 00237 */ 00238 virtual signed int get_position(void) 00239 { 00240 return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID)); 00241 } 00242 00243 /** 00244 * @brief Getting the marked position. 00245 * @param None. 00246 * @retval The marked position. 00247 */ 00248 virtual signed int get_mark(void) 00249 { 00250 return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID)); 00251 } 00252 00253 /** 00254 * @brief Getting the current speed in pps. 00255 * @param None. 00256 * @retval The current speed in pps. 00257 */ 00258 virtual unsigned int get_speed(void) 00259 { 00260 return round(L6470_Speed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID))); 00261 } 00262 00263 /** 00264 * @brief Getting the maximum speed in pps. 00265 * @param None. 00266 * @retval The maximum speed in pps. 00267 */ 00268 virtual unsigned int get_max_speed(void) 00269 { 00270 return round(L6470_MaxSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID))); 00271 } 00272 00273 /** 00274 * @brief Getting the minimum speed in pps. 00275 * @param None. 00276 * @retval The minimum speed in pps. 00277 */ 00278 virtual unsigned int get_min_speed(void) 00279 { 00280 return round(L6470_MinSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID))); 00281 } 00282 00283 /** 00284 * @brief Getting the acceleration in pps^2. 00285 * @param None. 00286 * @retval The acceleration in pps^2. 00287 */ 00288 virtual unsigned int get_acceleration(void) 00289 { 00290 return round(L6470_Acc_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID))); 00291 } 00292 00293 /** 00294 * @brief Getting the deceleration in pps^2. 00295 * @param None. 00296 * @retval The deceleration in pps^2. 00297 */ 00298 virtual unsigned int get_deceleration(void) 00299 { 00300 return round(L6470_Dec_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID))); 00301 } 00302 00303 /** 00304 * @brief Getting the direction of rotation. 00305 * @param None. 00306 * @retval The direction of rotation. 00307 */ 00308 virtual direction_t get_direction(void) 00309 { 00310 return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD); 00311 } 00312 00313 /** 00314 * @brief Setting a parameter. 00315 * @param parameter A parameter's register address. 00316 * @param value The parameter's value. 00317 * @retval None. 00318 * @note The parameter can be one of the following: 00319 * + L6470_ABS_POS_ID 00320 * + L6470_EL_POS_ID 00321 * + L6470_MARK_ID 00322 * + L6470_SPEED_ID 00323 * + L6470_ACC_ID 00324 * + L6470_DEC_ID 00325 * + L6470_MAX_SPEED_ID 00326 * + L6470_MIN_SPEED_ID 00327 * + L6470_FS_SPD_ID 00328 * + L6470_KVAL_HOLD_ID 00329 * + L6470_KVAL_RUN_ID 00330 * + L6470_KVAL_ACC_ID 00331 * + L6470_KVAL_DEC_ID 00332 * + L6470_INT_SPEED_ID 00333 * + L6470_ST_SLP_ID 00334 * + L6470_FN_SLP_ACC_ID 00335 * + L6470_FN_SLP_DEC_ID 00336 * + L6470_K_THERM_ID 00337 * + L6470_ADC_OUT_ID 00338 * + L6470_OCD_TH_ID 00339 * + L6470_STALL_TH_ID 00340 * + L6470_STEP_MODE_ID 00341 * + L6470_ALARM_EN_ID 00342 * + L6470_CONFIG_ID 00343 * + L6470_STATUS_ID 00344 * @warning Some registers can only be written in particular conditions (see L6470's datasheet). 00345 * Any attempt to write one of those registers when the conditions are not satisfied 00346 * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the 00347 * last argument byte. Any attempt to set an inexistent register (wrong address value) 00348 * causes the command to be ignored and the WRONG_CMD flag to rise. 00349 * For example, setting some parameters requires first to disable the power bridge; 00350 * this can be done through the soft_hiz() method. 00351 * They are the following: 00352 * + L6470_ABS_POS_ID 00353 * + L6470_EL_POS_ID 00354 * + L6470_SPEED_ID 00355 * + L6470_ACC_ID 00356 * + L6470_DEC_ID 00357 * + L6470_MAX_SPEED_ID 00358 * + L6470_MIN_SPEED_ID 00359 * + L6470_INT_SPEED_ID 00360 * + L6470_ST_SLP_ID 00361 * + L6470_FN_SLP_ACC_ID 00362 * + L6470_FN_SLP_DEC_ID 00363 * + L6470_ADC_OUT_ID 00364 * + L6470_STEP_MODE_ID 00365 * + L6470_CONFIG_ID 00366 * + L6470_STATUS_ID 00367 */ 00368 virtual void set_parameter(unsigned int parameter, unsigned int value) 00369 { 00370 L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value); 00371 } 00372 00373 /** 00374 * @brief Setting the current position to be the home position. 00375 * @param None. 00376 * @retval None. 00377 */ 00378 virtual void set_home(void) 00379 { 00380 L6470_ResetPos(); 00381 } 00382 00383 /** 00384 * @brief Setting the current position to be the marked position. 00385 * @param None. 00386 * @retval None. 00387 */ 00388 virtual void set_mark(void) 00389 { 00390 L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID)); 00391 } 00392 00393 /** 00394 * @brief Setting the current position to be the marked position. 00395 * @param position The given position. 00396 * @retval None. 00397 */ 00398 virtual void set_mark(signed int position) 00399 { 00400 L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position)); 00401 } 00402 00403 /** 00404 * @brief Setting the maximum speed in pps. 00405 * @param speed The maximum speed in pps. 00406 * @retval "true" in case of success, "false" otherwise. 00407 */ 00408 virtual bool set_max_speed(unsigned int speed) 00409 { 00410 L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed)); 00411 return true; 00412 } 00413 00414 /** 00415 * @brief Setting the minimum speed in pps. 00416 * @param speed The minimum speed in pps. 00417 * @retval "true" in case of success, "false" otherwise. 00418 */ 00419 virtual bool set_min_speed(unsigned int speed) 00420 { 00421 L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed)); 00422 return true; 00423 } 00424 00425 /** 00426 * @brief Setting the acceleration in pps^2. 00427 * @param acceleration The acceleration in pps^2. 00428 * @retval "true" in case of success, "false" otherwise. 00429 */ 00430 virtual bool set_acceleration(unsigned int acceleration) 00431 { 00432 L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration)); 00433 return true; 00434 } 00435 00436 /** 00437 * @brief Setting the deceleration in pps^2. 00438 * @param deceleration The deceleration in pps^2. 00439 * @retval "true" in case of success, "false" otherwise. 00440 */ 00441 virtual bool set_deceleration(unsigned int deceleration) 00442 { 00443 L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration)); 00444 return true; 00445 } 00446 00447 /** 00448 * @brief Setting the Step Mode. 00449 * @param step_mode The Step Mode. 00450 * @retval "true" in case of success, "false" otherwise. 00451 * @warning Setting the step mode implies first disabling the power bridge through 00452 * the soft_hiz() method. 00453 * @warning Every time step mode is changed, the values of the home 00454 * and mark positions lose meaning and are reset. 00455 */ 00456 virtual bool set_step_mode(step_mode_t step_mode) 00457 { 00458 if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128) { 00459 return false; 00460 } 00461 soft_hiz(); 00462 L6470_SetParam((eL6470_RegId_t) L6470_STEP_MODE_ID, (eMotorStepMode_t) step_mode); 00463 return true; 00464 } 00465 00466 /** 00467 * @brief Going to a specified position through the shortest path. 00468 * @param position The desired position. 00469 * @retval None. 00470 */ 00471 virtual void go_to(signed int position) 00472 { 00473 L6470_GoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position)); 00474 } 00475 00476 /** 00477 * @brief Going to a specified position imposing the desired direction. 00478 * @param position The desired position. 00479 * @param direction The direction of rotation. 00480 * @retval None. 00481 */ 00482 virtual void go_to(signed int position, direction_t direction) 00483 { 00484 L6470_GoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (uint32_t) L6470_Position_2_AbsPos((int32_t) position)); 00485 } 00486 00487 /** 00488 * @brief Going to the home position. 00489 * @param None. 00490 * @retval None. 00491 */ 00492 virtual void go_home(void) 00493 { 00494 L6470_GoHome(); 00495 } 00496 00497 /** 00498 * @brief Going to the marked position. 00499 * @param None. 00500 * @retval None. 00501 */ 00502 virtual void go_mark(void) 00503 { 00504 L6470_GoMark(); 00505 } 00506 00507 /** 00508 * @brief Running at the given speed imposing the desired direction until 00509 * an external switch turn-on event occurs. 00510 * @param action The identifier of the action about the absolute position. 00511 * @param position The desired position. 00512 * @param speed The speed value in pps. 00513 * @retval None. 00514 * @note The identifier of the action about the absolute position can be 00515 * one of the following: 00516 * + L6470_ACT_RST_ID: the absolute position is reset; 00517 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. 00518 */ 00519 virtual void go_until(eL6470_ActId_t action, direction_t direction, unsigned int speed) 00520 { 00521 L6470_GoUntil((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed)); 00522 } 00523 00524 /** 00525 * @brief Running towards a specified direction. 00526 * @param direction The direction of rotation. 00527 * @retval None. 00528 */ 00529 virtual void run(direction_t direction) 00530 { 00531 L6470_Run((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID)); 00532 } 00533 00534 /** 00535 * @brief Running towards a specified direction at the given speed. 00536 * @param direction The direction of rotation. 00537 * @param speed The speed value in pps. 00538 * @retval None. 00539 */ 00540 virtual void run(direction_t direction, unsigned int speed) 00541 { 00542 L6470_Run((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed)); 00543 } 00544 00545 /** 00546 * @brief Moving towards a specified direction for a certain number of steps. 00547 * @param direction The direction of rotation. 00548 * @param steps The desired number of steps. 00549 * @retval None. 00550 */ 00551 virtual void move(direction_t direction, unsigned int steps) 00552 { 00553 L6470_Move((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps); 00554 } 00555 00556 /** 00557 * @brief Stopping the motor through an immediate deceleration up to zero speed. 00558 * The used deceleration value is the one stored in the "DEC" register. 00559 * @param None. 00560 * @retval None. 00561 */ 00562 virtual void soft_stop(void) 00563 { 00564 L6470_SoftStop(); 00565 } 00566 00567 /** 00568 * @brief Stopping the motor through an immediate infinite deceleration. 00569 * @param None. 00570 * @retval None. 00571 */ 00572 virtual void hard_stop(void) 00573 { 00574 L6470_HardStop(); 00575 } 00576 00577 /** 00578 * @brief Disabling the power bridge after performing a deceleration to zero. 00579 * The used deceleration value is the one stored in the "DEC" register. 00580 * @param None. 00581 * @retval None. 00582 */ 00583 virtual void soft_hiz(void) 00584 { 00585 L6470_SoftHiZ(); 00586 } 00587 00588 /** 00589 * @brief Disabling the power bridge immediately. 00590 * @param None. 00591 * @retval None. 00592 */ 00593 virtual void hard_hiz(void) 00594 { 00595 L6470_HardHiZ(); 00596 } 00597 00598 /** 00599 * @brief Waiting while the motor is active. 00600 * @param None. 00601 * @retval None. 00602 */ 00603 virtual void wait_while_active(void) 00604 { 00605 while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0); 00606 } 00607 00608 /** 00609 * @brief Switching to step-clock mode. 00610 * @param direction The direction of rotation. 00611 * @retval None. 00612 * @warning Setting the step-clock mode implies first disabling the power bridge through 00613 * the soft_hiz() method. 00614 */ 00615 virtual void step_clock(direction_t direction) 00616 { 00617 soft_hiz(); 00618 L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); 00619 } 00620 00621 /** 00622 * @brief Doing a motion at minimum speed imposing a specified direction 00623 * until the SW is released. 00624 * @param action The identifier of the action about the absolute position. 00625 * @param direction The direction of rotation. 00626 * @note The identifier of the action about the absolute position can be 00627 * one of the following: 00628 * + L6470_ACT_RST_ID: the absolute position is reset; 00629 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. 00630 */ 00631 virtual void release_sw(eL6470_ActId_t action, direction_t direction) 00632 { 00633 L6470_ReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); 00634 } 00635 00636 /** 00637 * @brief Resetting the device to power-up conditions. 00638 * @param None. 00639 * @retval None. 00640 */ 00641 virtual void reset_device(void) 00642 { 00643 L6470_ResetDevice(); 00644 } 00645 00646 /** 00647 * @brief Preparing the command to get the status. 00648 * @param None. 00649 * @retval None. 00650 * @note The command will be sent by issuing "perform_action()". 00651 */ 00652 virtual void prepare_get_status(void) 00653 { 00654 L6470_PrepareGetStatus(); 00655 prepared_action = PREPARED_NO_ACTION; 00656 } 00657 00658 /** 00659 * @brief Preparing the command to get a parameter. 00660 * @param parameter A parameter's register address. 00661 * @retval None. 00662 * @note The command will be sent by issuing "perform_action()". 00663 * The parameter can be one of the following: 00664 * + L6470_ABS_POS_ID 00665 * + L6470_EL_POS_ID 00666 * + L6470_MARK_ID 00667 * + L6470_SPEED_ID 00668 * + L6470_ACC_ID 00669 * + L6470_DEC_ID 00670 * + L6470_MAX_SPEED_ID 00671 * + L6470_MIN_SPEED_ID 00672 * + L6470_FS_SPD_ID 00673 * + L6470_KVAL_HOLD_ID 00674 * + L6470_KVAL_RUN_ID 00675 * + L6470_KVAL_ACC_ID 00676 * + L6470_KVAL_DEC_ID 00677 * + L6470_INT_SPEED_ID 00678 * + L6470_ST_SLP_ID 00679 * + L6470_FN_SLP_ACC_ID 00680 * + L6470_FN_SLP_DEC_ID 00681 * + L6470_K_THERM_ID 00682 * + L6470_ADC_OUT_ID 00683 * + L6470_OCD_TH_ID 00684 * + L6470_STALL_TH_ID 00685 * + L6470_STEP_MODE_ID 00686 * + L6470_ALARM_EN_ID 00687 * + L6470_CONFIG_ID 00688 * + L6470_STATUS_ID 00689 */ 00690 virtual void prepare_get_parameter(unsigned int parameter) 00691 { 00692 L6470_PrepareGetParam((eL6470_RegId_t) parameter); 00693 prepared_action = PREPARED_NO_ACTION; 00694 } 00695 00696 /** 00697 * @brief Preparing the command to get the position. 00698 * @param None. 00699 * @retval None. 00700 * @note The command will be sent by issuing "perform_action()". 00701 */ 00702 virtual void prepare_get_position(void) 00703 { 00704 L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID); 00705 prepared_action = PREPARED_GET_POSITION; 00706 } 00707 00708 /** 00709 * @brief Preparing the command to get the marked position. 00710 * @param None. 00711 * @retval None. 00712 * @note The command will be sent by issuing "perform_action()". 00713 */ 00714 virtual void prepare_get_mark(void) 00715 { 00716 L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID); 00717 prepared_action = PREPARED_GET_MARK; 00718 } 00719 00720 /** 00721 * @brief Preparing the command to get the current speed in pps. 00722 * @param None. 00723 * @retval None. 00724 * @note The command will be sent by issuing "perform_action()". 00725 */ 00726 virtual void prepare_get_speed(void) 00727 { 00728 L6470_PrepareGetParam((eL6470_RegId_t) L6470_SPEED_ID); 00729 prepared_action = PREPARED_GET_SPEED; 00730 } 00731 00732 /** 00733 * @brief Preparing the command to get the maximum speed in pps. 00734 * @param None. 00735 * @retval None. 00736 * @note The command will be sent by issuing "perform_action()". 00737 */ 00738 virtual void prepare_get_max_speed(void) 00739 { 00740 L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID); 00741 prepared_action = PREPARED_GET_MAX_SPEED; 00742 } 00743 00744 /** 00745 * @brief Preparing the command to get the minimum speed in pps. 00746 * @param None. 00747 * @retval None. 00748 * @note The command will be sent by issuing "perform_action()". 00749 */ 00750 virtual void prepare_get_min_speed(void) 00751 { 00752 L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID); 00753 prepared_action = PREPARED_GET_MIN_SPEED; 00754 } 00755 00756 /** 00757 * @brief Preparing the command to get the acceleration in pps^2. 00758 * @param None. 00759 * @retval None. 00760 * @note The command will be sent by issuing "perform_action()". 00761 */ 00762 virtual void prepare_get_acceleration(void) 00763 { 00764 L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID); 00765 prepared_action = PREPARED_GET_ACCELERATION; 00766 } 00767 00768 /** 00769 * @brief Preparing the command to get the deceleration in pps^2. 00770 * @param None. 00771 * @retval None. 00772 * @note The command will be sent by issuing "perform_action()". 00773 */ 00774 virtual void prepare_get_deceleration(void) 00775 { 00776 L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID); 00777 prepared_action = PREPARED_GET_DECELERATION; 00778 } 00779 00780 /** 00781 * @brief Preparing the command to get the direction of rotation. 00782 * @param None. 00783 * @retval None. 00784 * @note The command will be sent by issuing "perform_action()". 00785 */ 00786 virtual void prepare_get_direction(void) 00787 { 00788 if (!L6470_DaisyChain_HalfPrepared) { 00789 /* To avoid deleting the previous entered command. */ 00790 L6470_DaisyChain_HalfPrepared = ONE_F; 00791 /* Resetting commands. */ 00792 L6470_ResetAppCmdPkg(L6470_AppCmdPkg); 00793 } 00794 prepared_action = PREPARED_GET_DIRECTION; 00795 } 00796 00797 /** 00798 * @brief Preparing the command to set a parameter. 00799 * @param parameter A parameter's register address. 00800 * @param value The parameter's value. 00801 * @retval None. 00802 * @note The command will be sent by issuing "perform_action()". 00803 * The parameter can be one of the following: 00804 * + L6470_ABS_POS_ID 00805 * + L6470_EL_POS_ID 00806 * + L6470_MARK_ID 00807 * + L6470_SPEED_ID 00808 * + L6470_ACC_ID 00809 * + L6470_DEC_ID 00810 * + L6470_MAX_SPEED_ID 00811 * + L6470_MIN_SPEED_ID 00812 * + L6470_FS_SPD_ID 00813 * + L6470_KVAL_HOLD_ID 00814 * + L6470_KVAL_RUN_ID 00815 * + L6470_KVAL_ACC_ID 00816 * + L6470_KVAL_DEC_ID 00817 * + L6470_INT_SPEED_ID 00818 * + L6470_ST_SLP_ID 00819 * + L6470_FN_SLP_ACC_ID 00820 * + L6470_FN_SLP_DEC_ID 00821 * + L6470_K_THERM_ID 00822 * + L6470_ADC_OUT_ID 00823 * + L6470_OCD_TH_ID 00824 * + L6470_STALL_TH_ID 00825 * + L6470_STEP_MODE_ID 00826 * + L6470_ALARM_EN_ID 00827 * + L6470_CONFIG_ID 00828 * + L6470_STATUS_ID 00829 * @warning Some registers can only be written in particular conditions (see L6470's datasheet). 00830 * Any attempt to write one of those registers when the conditions are not satisfied 00831 * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the 00832 * last argument byte. Any attempt to set an inexistent register (wrong address value) 00833 * causes the command to be ignored and the WRONG_CMD flag to rise. 00834 * For example, setting some parameters requires first to disable the power bridge; 00835 * this can be done through the soft_hiz() method. 00836 * They are the following: 00837 * + L6470_ABS_POS_ID 00838 * + L6470_EL_POS_ID 00839 * + L6470_SPEED_ID 00840 * + L6470_ACC_ID 00841 * + L6470_DEC_ID 00842 * + L6470_MAX_SPEED_ID 00843 * + L6470_MIN_SPEED_ID 00844 * + L6470_INT_SPEED_ID 00845 * + L6470_ST_SLP_ID 00846 * + L6470_FN_SLP_ACC_ID 00847 * + L6470_FN_SLP_DEC_ID 00848 * + L6470_ADC_OUT_ID 00849 * + L6470_STEP_MODE_ID 00850 * + L6470_CONFIG_ID 00851 * + L6470_STATUS_ID 00852 */ 00853 virtual void prepare_set_parameter(unsigned int parameter, unsigned int value) 00854 { 00855 L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value); 00856 prepared_action = PREPARED_NO_ACTION; 00857 } 00858 00859 /** 00860 * @brief Preparing the command to set the current position to be 00861 * the home position. 00862 * @param None. 00863 * @retval None. 00864 * @note The command will be sent by issuing "perform_action()". 00865 */ 00866 virtual void prepare_set_home(void) 00867 { 00868 L6470_PrepareResetPos(); 00869 prepared_action = PREPARED_NO_ACTION; 00870 } 00871 00872 /** 00873 * @brief Preparing the command to set the current position to be 00874 * the marked position. 00875 * @param None. 00876 * @retval None. 00877 * @note The command will be sent by issuing "perform_action()". 00878 */ 00879 virtual void prepare_set_mark(void) 00880 { 00881 /* 00882 Set "0" now as marked position. This value will be replaced by the 00883 actual position read at the time when the prepared actions will be 00884 performed. 00885 */ 00886 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0); 00887 prepared_action = PREPARED_SET_MARK; 00888 } 00889 00890 /** 00891 * @brief Preparing the command to set the given position to be 00892 * the marked position. 00893 * @param position The given position. 00894 * @retval None. 00895 * @note The command will be sent by issuing "perform_action()". 00896 */ 00897 virtual void prepare_set_mark(signed int position) 00898 { 00899 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position)); 00900 prepared_action = PREPARED_NO_ACTION; 00901 } 00902 00903 /** 00904 * @brief Preparing the command to set the current speed in pps. 00905 * @param speed The current speed in pps. 00906 * @retval None. 00907 * @note The command will be sent by issuing "perform_action()". 00908 */ 00909 virtual void prepare_set_speed(unsigned int speed) 00910 { 00911 L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed)); 00912 prepared_action = PREPARED_NO_ACTION; 00913 } 00914 00915 /** 00916 * @brief Preparing the command to set the maximum speed in pps. 00917 * @param speed The maximum speed in pps. 00918 * @retval None. 00919 * @note The command will be sent by issuing "perform_action()". 00920 */ 00921 virtual void prepare_set_max_speed(unsigned int speed) 00922 { 00923 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed)); 00924 prepared_action = PREPARED_NO_ACTION; 00925 } 00926 00927 /** 00928 * @brief Preparing the command to set the minimum speed in pps. 00929 * @param speed The minimum speed in pps. 00930 * @retval None. 00931 * @note The command will be sent by issuing "perform_action()". 00932 */ 00933 virtual void prepare_set_min_speed(unsigned int speed) 00934 { 00935 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed)); 00936 prepared_action = PREPARED_NO_ACTION; 00937 } 00938 00939 /** 00940 * @brief Preparing the command to set the acceleration in pps^2. 00941 * @param acceleration The acceleration in pps^2. 00942 * @retval None. 00943 * @note The command will be sent by issuing "perform_action()". 00944 */ 00945 virtual void prepare_set_acceleration(unsigned int acceleration) 00946 { 00947 L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration)); 00948 prepared_action = PREPARED_NO_ACTION; 00949 } 00950 00951 /** 00952 * @brief Preparing the command to set the deceleration in pps^2. 00953 * @param deceleration The deceleration in pps^2. 00954 * @retval None. 00955 * @note The command will be sent by issuing "perform_action()". 00956 */ 00957 virtual void prepare_set_deceleration(unsigned int deceleration) 00958 { 00959 L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration)); 00960 prepared_action = PREPARED_NO_ACTION; 00961 } 00962 00963 /** 00964 * @brief Preparing the command to go to a specified position. 00965 * @param position The desired position. 00966 * @retval None. 00967 * @note The command will be sent by issuing "perform_action()". 00968 */ 00969 virtual void prepare_go_to(signed int position) 00970 { 00971 L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position)); 00972 prepared_action = PREPARED_NO_ACTION; 00973 } 00974 00975 /** 00976 * @brief Preparing the command to go to a specified position 00977 * imposing the desired direction. 00978 * @param position The desired position. 00979 * @param direction The direction of rotation. 00980 * @retval None. 00981 * @note The command will be sent by issuing "perform_action()". 00982 */ 00983 virtual void prepare_go_to(signed int position, direction_t direction) 00984 { 00985 L6470_PrepareGoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (uint32_t) L6470_Position_2_AbsPos((int32_t) position)); 00986 prepared_action = PREPARED_NO_ACTION; 00987 } 00988 00989 /** 00990 * @brief Preparing the command to go to the home position. 00991 * @param None. 00992 * @retval None. 00993 * @note The command will be sent by issuing "perform_action()". 00994 */ 00995 virtual void prepare_go_home(void) 00996 { 00997 L6470_PrepareGoHome(); 00998 prepared_action = PREPARED_NO_ACTION; 00999 } 01000 01001 /** 01002 * @brief Preparing the command to go to the marked position. 01003 * @param None. 01004 * @retval None. 01005 * @note The command will be sent by issuing "perform_action()". 01006 */ 01007 virtual void prepare_go_mark(void) 01008 { 01009 L6470_PrepareGoMark(); 01010 prepared_action = PREPARED_NO_ACTION; 01011 } 01012 01013 /** 01014 * @brief Preparing the command to run at the given speed imposing the desired 01015 * direction until an external switch turn-on event occurs. 01016 * @param action The identifier of the action about the absolute position. 01017 * @param position The desired position. 01018 * @param speed The speed value in pps. 01019 * @retval None. 01020 * @note The command will be sent by issuing "perform_action()". 01021 * The identifier of the action about the absolute position can be 01022 * one of the following: 01023 * + L6470_ACT_RST_ID: the absolute position is reset; 01024 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. 01025 */ 01026 virtual void prepare_go_until(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed) 01027 { 01028 L6470_PrepareGoUntil((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed)); 01029 prepared_action = PREPARED_NO_ACTION; 01030 } 01031 01032 /** 01033 * @brief Preparing the command to run towards a specified direction 01034 * at the maximum speed. 01035 * @param direction The direction of rotation. 01036 * @retval None. 01037 * @note The command will be sent by issuing "perform_action()". 01038 */ 01039 virtual void prepare_run(direction_t direction) 01040 { 01041 L6470_PrepareRun((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID)); 01042 prepared_action = PREPARED_NO_ACTION; 01043 } 01044 01045 /** 01046 * @brief Preparing the command to run towards a specified direction 01047 * at the given speed. 01048 * @param direction The direction of rotation. 01049 * @param speed The speed value in pps. 01050 * @retval None. 01051 * @note The command will be sent by issuing "perform_action()". 01052 */ 01053 virtual void prepare_run(direction_t direction, unsigned int speed) 01054 { 01055 L6470_PrepareRun((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) L6470_Step_s_2_Speed((float) speed)); 01056 prepared_action = PREPARED_NO_ACTION; 01057 } 01058 01059 /** 01060 * @brief Preparing the command to move towards a specified direction 01061 * for a certain number of steps. 01062 * @param direction The direction of rotation. 01063 * @param steps The desired number of steps. 01064 * @retval None. 01065 * @note The command will be sent by issuing "perform_action()". 01066 */ 01067 virtual void prepare_move(direction_t direction, unsigned int steps) 01068 { 01069 L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps); 01070 prepared_action = PREPARED_NO_ACTION; 01071 } 01072 01073 /** 01074 * @brief Preparing the command to stop the motor. 01075 * @param None. 01076 * @retval None. 01077 * @note The command will be sent by issuing "perform_action()". 01078 */ 01079 virtual void prepare_soft_stop(void) 01080 { 01081 L6470_PrepareSoftStop(); 01082 prepared_action = PREPARED_NO_ACTION; 01083 } 01084 01085 /** 01086 * @brief Preparing the command to stop the motor and disabling the power bridge. 01087 * @param None. 01088 * @retval None. 01089 * @note The command will be sent by issuing "perform_action()". 01090 */ 01091 virtual void prepare_hard_stop(void) 01092 { 01093 L6470_PrepareHardStop(); 01094 prepared_action = PREPARED_NO_ACTION; 01095 } 01096 01097 /** 01098 * @brief Preparing the command to disable the power bridge after performing 01099 * a deceleration to zero. 01100 * The used deceleration value is the one stored in the "DEC" register. 01101 * @param None. 01102 * @retval None. 01103 * @note The command will be sent by issuing "perform_action()". 01104 */ 01105 virtual void prepare_soft_hiz(void) 01106 { 01107 L6470_PrepareSoftHiZ(); 01108 prepared_action = PREPARED_NO_ACTION; 01109 } 01110 01111 /** 01112 * @brief Preparing the command to disable the power bridge immediately. 01113 * @param None. 01114 * @retval None. 01115 * @note The command will be sent by issuing "perform_action()". 01116 */ 01117 virtual void prepare_hard_hiz(void) 01118 { 01119 L6470_PrepareHardHiZ(); 01120 prepared_action = PREPARED_NO_ACTION; 01121 } 01122 01123 /** 01124 * @brief Preparing the command to switch to step-clock mode. 01125 * @param direction The direction of rotation. 01126 * @retval None. 01127 * @warning Setting the step-clock mode requires an explicit action by the user to first 01128 * disable the power bridge through the soft_hiz() method. 01129 * @note The command will be sent by issuing "perform_action()". 01130 */ 01131 virtual void prepare_step_clock(direction_t direction) 01132 { 01133 L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); 01134 prepared_action = PREPARED_NO_ACTION; 01135 } 01136 01137 /** 01138 * @brief Preparing the command to do a motion at minimum speed 01139 * imposing a specified direction until the SW is released. 01140 * @param action The identifier of the action about the absolute position. 01141 * @param direction The direction of rotation. 01142 * @retval None. 01143 * @note The command will be sent by issuing "perform_action()". 01144 * The identifier of the action about the absolute position can be 01145 * one of the following: 01146 * + L6470_ACT_RST_ID: the absolute position is reset; 01147 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. 01148 */ 01149 virtual void prepare_release_sw(eL6470_ActId_t action, direction_t direction) 01150 { 01151 L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); 01152 prepared_action = PREPARED_NO_ACTION; 01153 } 01154 01155 /** 01156 * @brief Preparing the command to reset the device to power-up conditions. 01157 * @param None. 01158 * @retval None. 01159 * @note The command will be sent by issuing "perform_action()". 01160 */ 01161 virtual void prepare_reset_device(void) 01162 { 01163 L6470_PrepareResetDevice(); 01164 prepared_action = PREPARED_NO_ACTION; 01165 } 01166 01167 /** 01168 * @brief Performing all the actions prepared on the components 01169 * of the daisy-chain. 01170 * @param None. 01171 * @retval The raw data returned by the components. 01172 */ 01173 uint8_t* perform_prepared_actions(void) 01174 { 01175 return L6470_PerformPreparedApplicationCommand(); 01176 } 01177 01178 /** 01179 * @brief Getting the prepared action. 01180 * @param None 01181 * @retval The prepared action. 01182 */ 01183 prepared_action_t get_prepared_action(void) 01184 { 01185 return prepared_action; 01186 } 01187 01188 /** 01189 * @brief Converting the raw data received by the component according to 01190 * the action performed on it. 01191 * @param raw_data The received raw data. 01192 * @retval The result of the action performed. 01193 */ 01194 int32_t get_result(uint8_t *raw_data) 01195 { 01196 switch (prepared_action) { 01197 case PREPARED_GET_POSITION: 01198 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte)); 01199 01200 case PREPARED_GET_MARK: 01201 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte)); 01202 01203 case PREPARED_GET_SPEED: 01204 return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte))); 01205 01206 case PREPARED_GET_MAX_SPEED: 01207 return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte))); 01208 01209 case PREPARED_GET_MIN_SPEED: 01210 return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte))); 01211 01212 case PREPARED_GET_ACCELERATION: 01213 return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte))); 01214 01215 case PREPARED_GET_DECELERATION: 01216 return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte))); 01217 01218 case PREPARED_GET_DIRECTION: 01219 return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD); 01220 01221 default: 01222 case PREPARED_NO_ACTION: 01223 return 0; 01224 } 01225 } 01226 01227 01228 /*** Public Interrupt Related Methods ***/ 01229 01230 /* ACTION 6 --------------------------------------------------------------* 01231 * Implement here interrupt related methods, if any. * 01232 * Note that interrupt handling is platform dependent, e.g.: * 01233 * + mbed: * 01234 * InterruptIn feature_irq(pin); //Interrupt object. * 01235 * feature_irq.rise(callback); //Attach a callback. * 01236 * feature_irq.mode(PullNone); //Set interrupt mode. * 01237 * feature_irq.enable_irq(); //Enable interrupt. * 01238 * feature_irq.disable_irq(); //Disable interrupt. * 01239 * + Arduino: * 01240 * attachInterrupt(pin, callback, RISING); //Attach a callback. * 01241 * detachInterrupt(pin); //Detach a callback. * 01242 * * 01243 * Example (mbed): * 01244 * void attach_feature_irq(void (*fptr) (void)) * 01245 * { * 01246 * feature_irq.rise(fptr); * 01247 * } * 01248 * * 01249 * void enable_feature_irq(void) * 01250 * { * 01251 * feature_irq.enable_irq(); * 01252 * } * 01253 * * 01254 * void disable_feature_irq(void) * 01255 * { * 01256 * feature_irq.disable_irq(); * 01257 * } * 01258 *------------------------------------------------------------------------*/ 01259 /** 01260 * @brief Attaching an interrupt handler to the FLAG interrupt. 01261 * @param fptr An interrupt handler. 01262 * @retval None. 01263 */ 01264 void attach_flag_irq(void (*fptr)(void)) 01265 { 01266 flag_irq.fall(fptr); 01267 } 01268 01269 /** 01270 * @brief Enabling the FLAG interrupt handling. 01271 * @param None. 01272 * @retval None. 01273 */ 01274 void enable_flag_irq(void) 01275 { 01276 flag_irq.enable_irq(); 01277 } 01278 01279 /** 01280 * @brief Disabling the FLAG interrupt handling. 01281 * @param None. 01282 * @retval None. 01283 */ 01284 void disable_flag_irq(void) 01285 { 01286 flag_irq.disable_irq(); 01287 } 01288 01289 /** 01290 * @brief Attaching an interrupt handler to the BUSY interrupt. 01291 * @param fptr An interrupt handler. 01292 * @retval None. 01293 */ 01294 void attach_busy_irq(void (*fptr)(void)) 01295 { 01296 busy_irq.fall(fptr); 01297 } 01298 01299 /** 01300 * @brief Enabling the BUSY interrupt handling. 01301 * @param None. 01302 * @retval None. 01303 */ 01304 void enable_busy_irq(void) 01305 { 01306 busy_irq.enable_irq(); 01307 } 01308 01309 /** 01310 * @brief Disabling the BUSY interrupt handling. 01311 * @param None. 01312 * @retval None. 01313 */ 01314 void disable_busy_irq(void) 01315 { 01316 busy_irq.disable_irq(); 01317 } 01318 01319 01320 protected: 01321 01322 /*** Protected Component Related Methods ***/ 01323 01324 /* ACTION 7 --------------------------------------------------------------* 01325 * Declare here the component's specific methods. * 01326 * They should be: * 01327 * + Methods with the same name of the C component's virtual table's * 01328 * functions (1); * 01329 * + Methods with the same name of the C component's extended virtual * 01330 * table's functions, if any (2); * 01331 * + Helper methods, if any, like functions declared in the component's * 01332 * source files but not pointed by the component's virtual table (3). * 01333 * * 01334 * Example: * 01335 * status_t COMPONENT_get_value(float *f); //(1) * 01336 * status_t COMPONENT_enable_feature(void); //(2) * 01337 * status_t COMPONENT_compute_average(void); //(3) * 01338 *------------------------------------------------------------------------*/ 01339 int32_t L6470_AbsPos_2_Position(uint32_t AbsPos); 01340 uint32_t L6470_Position_2_AbsPos(int32_t Position); 01341 float L6470_Speed_2_Step_s(uint32_t Speed); 01342 uint32_t L6470_Step_s_2_Speed(float Step_s); 01343 float L6470_Acc_2_Step_s2(uint16_t Acc); 01344 uint16_t L6470_Step_s2_2_Acc(float Step_s2); 01345 float L6470_Dec_2_Step_s2(uint16_t Dec); 01346 uint16_t L6470_Step_s2_2_Dec(float Step_s2); 01347 float L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed); 01348 uint16_t L6470_Step_s_2_MaxSpeed(float Step_s); 01349 float L6470_MinSpeed_2_Step_s(uint16_t MinSpeed); 01350 uint16_t L6470_Step_s_2_MinSpeed(float Step_s); 01351 float L6470_FsSpd_2_Step_s(uint16_t FsSpd); 01352 uint16_t L6470_Step_s_2_FsSpd(float Step_s); 01353 float L6470_IntSpeed_2_Step_s(uint16_t IntSpeed); 01354 uint16_t L6470_Step_s_2_IntSpeed(float Step_s); 01355 float L6470_StSlp_2_s_Step(uint8_t StSlp); 01356 uint8_t L6470_s_Step_2_StSlp(float s_Step); 01357 float L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc); 01358 uint8_t L6470_s_Step_2_FnSlpAcc(float s_Step); 01359 float L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec); 01360 uint8_t L6470_s_Step_2_FnSlpDec(float s_Step); 01361 float L6470_OcdTh_2_mA(uint8_t OcdTh); 01362 uint8_t L6470_mA_2_OcdTh(float mA); 01363 float L6470_StallTh_2_mA(uint8_t StallTh); 01364 uint8_t L6470_mA_2_StallTh(float mA); 01365 status_t L6470_Config(void *init); 01366 void L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value); 01367 uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId); 01368 void L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed); 01369 void L6470_StepClock(eL6470_DirId_t L6470_DirId); 01370 void L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step); 01371 void L6470_GoTo(uint32_t AbsPos); 01372 void L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos); 01373 void L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed); 01374 void L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId); 01375 void L6470_GoHome(void); 01376 void L6470_GoMark(void); 01377 void L6470_ResetPos(void); 01378 void L6470_ResetDevice(void); 01379 void L6470_SoftStop(void); 01380 void L6470_HardStop(void); 01381 void L6470_SoftHiZ(void); 01382 void L6470_HardHiZ(void); 01383 uint16_t L6470_GetStatus(void); 01384 void L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value); 01385 void L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId); 01386 void L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed); 01387 void L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId); 01388 void L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step); 01389 void L6470_PrepareGoTo(uint32_t AbsPos); 01390 void L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos); 01391 void L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed); 01392 void L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId); 01393 void L6470_PrepareGoHome(void); 01394 void L6470_PrepareGoMark(void); 01395 void L6470_PrepareResetPos(void); 01396 void L6470_PrepareResetDevice(void); 01397 void L6470_PrepareSoftStop(void); 01398 void L6470_PrepareHardStop(void); 01399 void L6470_PrepareSoftHiZ(void); 01400 void L6470_PrepareHardHiZ(void); 01401 void L6470_PrepareGetStatus(void); 01402 uint8_t* L6470_PerformPreparedApplicationCommand(void); 01403 void L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct); 01404 uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte); 01405 uint8_t L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId); 01406 uint8_t* L6470_GetRegisterName(uint8_t id); 01407 void L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg); 01408 void L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3); 01409 void L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3); 01410 void L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct); 01411 01412 /** 01413 * @brief Rounding a floating point number to the nearest unsigned integer number. 01414 * @param f The floating point number. 01415 * @retval The nearest unsigned integer number. 01416 */ 01417 int round(float f) 01418 { 01419 if (f >= 0) { 01420 return (int) f + (f - (int) f < 0.5f ? 0 : 1); 01421 } else { 01422 return (int) f - (f - (int) f < -0.5f ? 1 : 0); 01423 } 01424 } 01425 01426 01427 /*** Component's I/O Methods ***/ 01428 01429 /** 01430 * @brief Utility function to read data from L6470. 01431 * @param[out] pBuffer pointer to the buffer to read data into. 01432 * @param[in] NumBytesToRead number of bytes to read. 01433 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. 01434 */ 01435 status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead) 01436 { 01437 if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) { 01438 return COMPONENT_ERROR; 01439 } 01440 return COMPONENT_OK; 01441 } 01442 01443 /** 01444 * @brief Utility function to write data to L6470. 01445 * @param[in] pBuffer pointer to the buffer of data to send. 01446 * @param[in] NumBytesToWrite number of bytes to write. 01447 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. 01448 */ 01449 status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite) 01450 { 01451 if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) { 01452 return COMPONENT_ERROR; 01453 } 01454 return COMPONENT_OK; 01455 } 01456 01457 /** 01458 * @brief Utility function to read and write data from/to L6470 at the same time. 01459 * @param[out] pBufferToRead pointer to the buffer to read data into. 01460 * @param[in] pBufferToWrite pointer to the buffer of data to send. 01461 * @param[in] NumBytes number of bytes to read and write. 01462 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. 01463 */ 01464 status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes) 01465 { 01466 if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) { 01467 return COMPONENT_ERROR; 01468 } 01469 return COMPONENT_OK; 01470 } 01471 01472 /* ACTION 8 --------------------------------------------------------------* 01473 * Implement here other I/O methods beyond those already implemented * 01474 * above, which are declared extern within the component's header file. * 01475 *------------------------------------------------------------------------*/ 01476 /* 01477 * Puts the device in standby mode. 01478 */ 01479 void L6470_ENABLE(void) 01480 { 01481 standby_reset = 1; 01482 } 01483 01484 /* 01485 * Puts the device in reset mode. 01486 */ 01487 void L6470_DISABLE(void) 01488 { 01489 standby_reset = 0; 01490 } 01491 01492 /* 01493 * Write and read bytes to/from the component through the SPI at the same time. 01494 */ 01495 void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout) 01496 { 01497 ReadWrite(pRxData, pTxData, Size); 01498 } 01499 01500 01501 /*** Component's Instance Variables ***/ 01502 01503 /* ACTION 9 --------------------------------------------------------------* 01504 * Declare here interrupt related variables, if needed. * 01505 * Note that interrupt handling is platform dependent, see * 01506 * "Interrupt Related Methods" above. * 01507 * * 01508 * Example: * 01509 * + mbed: * 01510 * InterruptIn feature_irq; * 01511 *------------------------------------------------------------------------*/ 01512 /* Flag Interrupt. */ 01513 InterruptIn flag_irq; 01514 01515 /* Busy Interrupt. */ 01516 InterruptIn busy_irq; 01517 01518 /* ACTION 10 -------------------------------------------------------------* 01519 * Declare here other pin related variables, if needed. * 01520 * * 01521 * Example: * 01522 * + mbed: * 01523 * DigitalOut standby_reset; * 01524 *------------------------------------------------------------------------*/ 01525 /* Standby/reset pin. */ 01526 DigitalOut standby_reset; 01527 01528 /* ACTION 11 -------------------------------------------------------------* 01529 * Declare here communication related variables, if needed. * 01530 * * 01531 * Example: * 01532 * + mbed: * 01533 * DigitalOut ssel; * 01534 * DevSPI &dev_spi; * 01535 *------------------------------------------------------------------------*/ 01536 /* Configuration. */ 01537 DigitalOut ssel; 01538 01539 /* IO Device. */ 01540 DevSPI &dev_spi; 01541 01542 /* ACTION 12 -------------------------------------------------------------* 01543 * Declare here identity related variables, if needed. * 01544 * Note that there should be only a unique identifier for each component, * 01545 * which should be the "who_am_i" parameter. * 01546 *------------------------------------------------------------------------*/ 01547 /* Identity */ 01548 uint8_t who_am_i; 01549 01550 /* ACTION 13 -------------------------------------------------------------* 01551 * Declare here the component's static and non-static data, one variable * 01552 * per line. * 01553 * * 01554 * Example: * 01555 * float measure; * 01556 * int instance_id; * 01557 * static int number_of_instances; * 01558 *------------------------------------------------------------------------*/ 01559 /* Data. */ 01560 uint8_t L6470_Id; 01561 const sL6470_Register_t *L6470_Register; 01562 const sL6470_ApplicationCommand_t *L6470_ApplicationCommand; 01563 const sL6470_Direction_t *L6470_Direction; 01564 const sL6470_ACT_t *L6470_ACT; 01565 sL6470_StatusRegister_t L6470_StatusRegister; 01566 sL6470_StatusRegister_t *pL6470_StatusRegister; 01567 StepperMotorRegister_t StepperMotorRegister; 01568 prepared_action_t prepared_action; 01569 01570 /* Static data. */ 01571 static uint8_t number_of_devices; 01572 static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE]; 01573 static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE]; 01574 static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE]; 01575 static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE]; 01576 static eFlagStatus_t L6470_DaisyChain_HalfPrepared; 01577 static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; 01578 static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; 01579 static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; 01580 }; 01581 01582 #endif /* __L6470_CLASS_H */ 01583 01584 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 22:48:07 by 1.7.2