motor control
Fork of X_NUCLEO_IHM01A1 by
Embed:
(wiki syntax)
Show/hide line numbers
l6474_class.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file l6474_class.h 00004 * @author Davide Aliprandi, STMicroelectronics 00005 * @version V1.0.0 00006 * @date October 14th, 2015 00007 * @brief This file contains the class of an L6474 Motor Control component. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Generated with STM32CubeTOO -----------------------------------------------*/ 00040 00041 00042 /* Revision ------------------------------------------------------------------*/ 00043 /* 00044 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev 00045 Branch/Trunk/Tag: trunk 00046 Based on: X-CUBE-SPN1/trunk/Drivers/BSP/Components/l6474/l6474.h 00047 Revision: 0 00048 */ 00049 00050 00051 /* Define to prevent recursive inclusion -------------------------------------*/ 00052 00053 #ifndef __L6474_CLASS_H 00054 #define __L6474_CLASS_H 00055 00056 00057 /* Includes ------------------------------------------------------------------*/ 00058 00059 /* ACTION 1 ------------------------------------------------------------------* 00060 * Include here platform specific header files. * 00061 *----------------------------------------------------------------------------*/ 00062 #include "mbed.h" 00063 #include "DevSPI.h" 00064 /* ACTION 2 ------------------------------------------------------------------* 00065 * Include here component specific header files. * 00066 *----------------------------------------------------------------------------*/ 00067 #include "l6474.h" 00068 /* ACTION 3 ------------------------------------------------------------------* 00069 * Include here interface specific header files. * 00070 * * 00071 * Example: * 00072 * #include "../Interfaces/Humidity_class.h" * 00073 * #include "../Interfaces/Temperature_class.h" * 00074 *----------------------------------------------------------------------------*/ 00075 #include "../Interfaces/StepperMotor_class.h" 00076 00077 00078 /* Classes -------------------------------------------------------------------*/ 00079 00080 /** 00081 * @brief Class representing an L6474 component. 00082 */ 00083 class L6474 : public StepperMotor 00084 { 00085 public: 00086 00087 /*** Constructor and Destructor Methods ***/ 00088 00089 /** 00090 * @brief Constructor. 00091 * @param flag_irq pin name of the FLAG pin of the component. 00092 * @param standby_reset pin name of the STBY\RST pin of the component. 00093 * @param direction pin name of the DIR pin of the component. 00094 * @param pwm pin name of the PWM pin of the component. 00095 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication. 00096 * @param spi SPI device to be used for communication. 00097 */ 00098 L6474(PinName flag_irq, PinName standby_reset, PinName direction, PinName pwm, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), standby_reset(standby_reset), direction(direction), pwm(pwm), ssel(ssel), dev_spi(spi) 00099 { 00100 /* Checking stackability. */ 00101 if (!(number_of_devices < MAX_NUMBER_OF_DEVICES)) 00102 error("Instantiation of the L6474 component failed: it can be stacked up to %d times.\r\n", MAX_NUMBER_OF_DEVICES); 00103 00104 /* ACTION 4 ----------------------------------------------------------* 00105 * Initialize here the component's member variables, one variable per * 00106 * line. * 00107 * * 00108 * Example: * 00109 * measure = 0; * 00110 * instance_id = number_of_instances++; * 00111 *--------------------------------------------------------------------*/ 00112 error_handler_callback = 0; 00113 device_instance = number_of_devices++; 00114 memset(spi_tx_bursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t)); 00115 memset(spi_rx_bursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t)); 00116 } 00117 00118 /** 00119 * @brief Destructor. 00120 */ 00121 virtual ~L6474(void) {} 00122 00123 00124 /*** Public Component Related Methods ***/ 00125 00126 /* ACTION 5 --------------------------------------------------------------* 00127 * Implement here the component's public methods, as wrappers of the C * 00128 * component's functions. * 00129 * They should be: * 00130 * + Methods with the same name of the C component's virtual table's * 00131 * functions (1); * 00132 * + Methods with the same name of the C component's extended virtual * 00133 * table's functions, if any (2). * 00134 * * 00135 * Example: * 00136 * virtual int GetValue(float *pData) //(1) * 00137 * { * 00138 * return COMPONENT_GetValue(float *pfData); * 00139 * } * 00140 * * 00141 * virtual int EnableFeature(void) //(2) * 00142 * { * 00143 * return COMPONENT_EnableFeature(); * 00144 * } * 00145 *------------------------------------------------------------------------*/ 00146 /** 00147 * @brief Initializing the component in 1/16 Microstepping mode. 00148 * @param init Pointer to device specific initalization structure. 00149 * @retval "0" in case of success, an error code otherwise. 00150 */ 00151 virtual int Init(void *init = NULL) 00152 { 00153 return (int) L6474_Init((void *) init); 00154 } 00155 00156 /** 00157 * @brief Getting the ID of the component. 00158 * @param id Pointer to an allocated variable to store the ID into. 00159 * @retval "0" in case of success, an error code otherwise. 00160 */ 00161 virtual int ReadID(uint8_t *id = NULL) 00162 { 00163 return (int) L6474_ReadID((uint8_t *) id); 00164 } 00165 00166 /** 00167 * @brief Getting the value of the Status Register. 00168 * @param None. 00169 * @retval None. 00170 * @note The Status Register's flags are cleared, contrary to ReadStatusRegister(). 00171 */ 00172 virtual unsigned int GetStatus(void) 00173 { 00174 return (unsigned int) L6474_CmdGetStatus(); 00175 } 00176 00177 /** 00178 * @brief Getting a parameter. 00179 * @param parameter A parameter's register adress. 00180 * @retval The parameter's value. 00181 * @note The Status Register's flags are cleared, contrary to ReadStatusRegister(). 00182 * parameter can be one of the following: 00183 * + L6474_ABS_POS 00184 * + L6474_EL_POS 00185 * + L6474_MARK 00186 * + L6474_RESERVED_REG01 00187 * + L6474_RESERVED_REG02 00188 * + L6474_RESERVED_REG03 00189 * + L6474_RESERVED_REG04 00190 * + L6474_RESERVED_REG05 00191 * + L6474_RESERVED_REG06 00192 * + L6474_TVAL : value in mA 00193 * + L6474_RESERVED_REG07 00194 * + L6474_RESERVED_REG08 00195 * + L6474_RESERVED_REG09 00196 * + L6474_RESERVED_REG10 00197 * + L6474_T_FAST 00198 * + L6474_TON_MIN : value in us 00199 * + L6474_TOFF_MIN : value in us 00200 * + L6474_RESERVED_REG11 00201 * + L6474_ADC_OUT 00202 * + L6474_OCD_TH 00203 * + L6474_RESERVED_REG12 00204 * + L6474_STEP_MODE 00205 * + L6474_ALARM_EN 00206 * + L6474_CONFIG 00207 * + L6474_STATUS 00208 * + L6474_RESERVED_REG13 00209 * + L6474_RESERVED_REG14 00210 * + L6474_INEXISTENT_REG 00211 */ 00212 virtual float GetParameter(unsigned int parameter) 00213 { 00214 unsigned int register_value = (unsigned int) L6474_CmdGetParam((L6474_Registers_t) parameter); 00215 float value; 00216 00217 switch ((L6474_Registers_t) parameter) 00218 { 00219 case L6474_TVAL: 00220 value = L6474_Par_to_Tval_Current((float) register_value); 00221 break; 00222 case L6474_TON_MIN: 00223 case L6474_TOFF_MIN: 00224 value = L6474_Par_to_Tmin_Time((float) register_value); 00225 break; 00226 default: 00227 value = (float) register_value; 00228 break; 00229 } 00230 00231 return value; 00232 } 00233 00234 /** 00235 * @brief Getting the position. 00236 * @param None. 00237 * @retval The position. 00238 */ 00239 virtual signed int GetPosition(void) 00240 { 00241 return (signed int) L6474_GetPosition(); 00242 } 00243 00244 /** 00245 * @brief Getting the marked position. 00246 * @param None. 00247 * @retval The marked position. 00248 */ 00249 virtual signed int GetMark(void) 00250 { 00251 return (signed int) L6474_GetMark(); 00252 } 00253 00254 /** 00255 * @brief Getting the current speed in pps. 00256 * @param None. 00257 * @retval The current speed in pps. 00258 */ 00259 virtual unsigned int GetSpeed(void) 00260 { 00261 return (unsigned int) L6474_GetCurrentSpeed(); 00262 } 00263 00264 /** 00265 * @brief Getting the maximum speed in pps. 00266 * @param None. 00267 * @retval The maximum speed in pps. 00268 */ 00269 virtual unsigned int GetMaxSpeed(void) 00270 { 00271 return (unsigned int) L6474_GetMaxSpeed(); 00272 } 00273 00274 /** 00275 * @brief Getting the minimum speed in pps. 00276 * @param None. 00277 * @retval The minimum speed in pps. 00278 */ 00279 virtual unsigned int GetMinSpeed(void) 00280 { 00281 return (unsigned int) L6474_GetMinSpeed(); 00282 } 00283 00284 /** 00285 * @brief Getting the acceleration in pps^2. 00286 * @param None. 00287 * @retval The acceleration in pps^2. 00288 */ 00289 virtual unsigned int GetAcceleration(void) 00290 { 00291 return (unsigned int) L6474_GetAcceleration(); 00292 } 00293 00294 /** 00295 * @brief Getting the deceleration in pps^2. 00296 * @param None. 00297 * @retval The deceleration in pps^2. 00298 */ 00299 virtual unsigned int GetDeceleration(void) 00300 { 00301 return (unsigned int) L6474_GetDeceleration(); 00302 } 00303 00304 /** 00305 * @brief Getting the direction of rotation. 00306 * @param None. 00307 * @retval The direction of rotation. 00308 */ 00309 virtual direction_t GetDirection(void) 00310 { 00311 return (direction_t) (L6474_GetDirection() == FORWARD ? StepperMotor::FWD : StepperMotor::BWD); 00312 } 00313 00314 /** 00315 * @brief Setting a parameter. 00316 * @param parameter A parameter's register adress. 00317 * @param value The parameter's value. 00318 * @retval None. 00319 * @note parameter can be one of the following: 00320 * + L6474_ABS_POS 00321 * + L6474_EL_POS 00322 * + L6474_MARK 00323 * + L6474_RESERVED_REG01 00324 * + L6474_RESERVED_REG02 00325 * + L6474_RESERVED_REG03 00326 * + L6474_RESERVED_REG04 00327 * + L6474_RESERVED_REG05 00328 * + L6474_RESERVED_REG06 00329 * + L6474_TVAL : value in mA 00330 * + L6474_RESERVED_REG07 00331 * + L6474_RESERVED_REG08 00332 * + L6474_RESERVED_REG09 00333 * + L6474_RESERVED_REG10 00334 * + L6474_T_FAST 00335 * + L6474_TON_MIN : value in us 00336 * + L6474_TOFF_MIN : value in us 00337 * + L6474_RESERVED_REG11 00338 * + L6474_ADC_OUT 00339 * + L6474_OCD_TH 00340 * + L6474_RESERVED_REG12 00341 * + L6474_STEP_MODE 00342 * + L6474_ALARM_EN 00343 * + L6474_CONFIG 00344 * + L6474_STATUS 00345 * + L6474_RESERVED_REG13 00346 * + L6474_RESERVED_REG14 00347 * + L6474_INEXISTENT_REG 00348 */ 00349 virtual void SetParameter(unsigned int parameter, float value) 00350 { 00351 float register_value; 00352 00353 switch ((L6474_Registers_t) parameter) 00354 { 00355 case L6474_TVAL: 00356 register_value = L6474_Tval_Current_to_Par(value); 00357 break; 00358 case L6474_TON_MIN: 00359 case L6474_TOFF_MIN: 00360 register_value = L6474_Tmin_Time_to_Par(value); 00361 break; 00362 default: 00363 register_value = value; 00364 break; 00365 } 00366 00367 L6474_CmdSetParam((L6474_Registers_t) parameter, (unsigned int) register_value); 00368 } 00369 00370 /** 00371 * @brief Setting the current position to be the home position. 00372 * @param None. 00373 * @retval None. 00374 */ 00375 virtual void SetHome(void) 00376 { 00377 L6474_SetHome(); 00378 } 00379 00380 /** 00381 * @brief Setting the current position to be the marked position. 00382 * @param None. 00383 * @retval None. 00384 */ 00385 virtual void SetMark(void) 00386 { 00387 L6474_SetMark(); 00388 } 00389 00390 /** 00391 * @brief Setting the maximum speed in pps. 00392 * @param speed The maximum speed in pps. 00393 * @retval None. 00394 */ 00395 virtual void SetMaxSpeed(unsigned int speed) 00396 { 00397 L6474_SetMaxSpeed((unsigned int) speed); 00398 } 00399 00400 /** 00401 * @brief Setting the minimum speed in pps. 00402 * @param speed The minimum speed in pps. 00403 * @retval None. 00404 */ 00405 virtual void SetMinSpeed(unsigned int speed) 00406 { 00407 L6474_SetMinSpeed((unsigned int) speed); 00408 } 00409 00410 /** 00411 * @brief Setting the acceleration in pps^2. 00412 * @param acceleration The acceleration in pps^2. 00413 * @retval None. 00414 */ 00415 virtual void SetAcceleration(unsigned int acceleration) 00416 { 00417 L6474_SetAcceleration((unsigned int) acceleration); 00418 } 00419 00420 /** 00421 * @brief Setting the deceleration in pps^2. 00422 * @param deceleration The deceleration in pps^2. 00423 * @retval None. 00424 */ 00425 virtual void SetDeceleration(unsigned int deceleration) 00426 { 00427 L6474_SetDeceleration((unsigned int) deceleration); 00428 } 00429 00430 /** 00431 * @brief Going to a specified position. 00432 * @param position The desired position. 00433 * @retval None. 00434 */ 00435 virtual void GoTo(signed int position) 00436 { 00437 L6474_GoTo((signed int) position); 00438 } 00439 00440 /** 00441 * @brief Going to the home position. 00442 * @param None. 00443 * @retval None. 00444 */ 00445 virtual void GoHome(void) 00446 { 00447 L6474_GoHome(); 00448 } 00449 00450 /** 00451 * @brief Going to the marked position. 00452 * @param None. 00453 * @retval None. 00454 */ 00455 virtual void GoMark(void) 00456 { 00457 L6474_GoMark(); 00458 } 00459 00460 /** 00461 * @brief Running the motor towards a specified direction. 00462 * @param direction The direction of rotation. 00463 * @retval None. 00464 */ 00465 virtual void Run(direction_t direction) 00466 { 00467 L6474_Run((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD)); 00468 } 00469 00470 /** 00471 * @brief Moving the motor towards a specified direction for a certain number of steps. 00472 * @param direction The direction of rotation. 00473 * @param steps The desired number of steps. 00474 * @retval None. 00475 */ 00476 virtual void Move(direction_t direction, unsigned int steps) 00477 { 00478 L6474_Move((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD), (unsigned int) steps); 00479 } 00480 00481 /** 00482 * @brief Stopping the motor through an immediate deceleration up to zero speed. 00483 * @param None. 00484 * @retval None. 00485 */ 00486 virtual void SoftStop(void) 00487 { 00488 L6474_SoftStop(); 00489 } 00490 00491 /** 00492 * @brief Stopping the motor through an immediate infinite deceleration. 00493 * @param None. 00494 * @retval None. 00495 */ 00496 virtual void HardStop(void) 00497 { 00498 L6474_HardStop(); 00499 } 00500 00501 /** 00502 * @brief Disabling the power bridge after performing a deceleration to zero. 00503 * @param None. 00504 * @retval None. 00505 */ 00506 virtual void SoftHiZ(void) 00507 { 00508 L6474_SoftStop(); 00509 L6474_CmdDisable(); 00510 } 00511 00512 /** 00513 * @brief Disabling the power bridge immediately. 00514 * @param None. 00515 * @retval None. 00516 */ 00517 virtual void HardHiZ(void) 00518 { 00519 L6474_HardStop(); 00520 L6474_CmdDisable(); 00521 } 00522 00523 /** 00524 * @brief Waiting while the motor is active. 00525 * @param None. 00526 * @retval None. 00527 */ 00528 virtual void WaitWhileActive(void) 00529 { 00530 L6474_WaitWhileActive(); 00531 } 00532 00533 /** 00534 * @brief Getting the device state. 00535 * @param None. 00536 * @retval The device state. 00537 * @note The device state can be one of the following: 00538 * + ACCELERATING 00539 * + DECELERATING 00540 * + STEADY 00541 * + INACTIVE 00542 */ 00543 virtual motorState_t GetDeviceState(void) 00544 { 00545 return (motorState_t) L6474_GetDeviceState(); 00546 } 00547 00548 /** 00549 * @brief Reading the Status Register. 00550 * @param None. 00551 * @retval None. 00552 * @note The Status Register's flags are not cleared, contrary to GetStatus(). 00553 */ 00554 virtual uint16_t ReadStatusRegister(void) 00555 { 00556 return (uint16_t) L6474_ReadStatusRegister(); 00557 } 00558 00559 /** 00560 * @brief Setting the Step Mode. 00561 * @param step_mode The Step Mode. 00562 * @retval None. 00563 * @note step_mode can be one of the following: 00564 * + STEP_MODE_FULL 00565 * + STEP_MODE_HALF 00566 * + STEP_MODE_1_4 00567 * + STEP_MODE_1_8 00568 * + STEP_MODE_1_16 00569 * + STEP_MODE_1_32 00570 * + STEP_MODE_1_64 00571 * + STEP_MODE_1_128 00572 */ 00573 virtual void SetStepMode(motorStepMode_t step_mode) 00574 { 00575 L6474_SelectStepMode((motorStepMode_t) step_mode); 00576 } 00577 00578 /** 00579 * @brief Attaching an error handler. 00580 * @param fptr An error handler. 00581 * @retval None. 00582 */ 00583 virtual void AttachErrorHandler(void (*fptr)(uint16_t error)) 00584 { 00585 L6474_AttachErrorHandler((void (*)(uint16_t error)) fptr); 00586 } 00587 00588 /** 00589 * @brief Enabling the device. 00590 * @param None. 00591 * @retval None. 00592 */ 00593 virtual void Enable(void) 00594 { 00595 L6474_CmdEnable(); 00596 } 00597 00598 /** 00599 * @brief Disabling the device. 00600 * @param None. 00601 * @retval None. 00602 */ 00603 virtual void Disable(void) 00604 { 00605 L6474_CmdDisable(); 00606 } 00607 00608 /** 00609 * @brief Getting the version of the firmware. 00610 * @param None. 00611 * @retval The version of the firmware. 00612 */ 00613 virtual uint8_t GetFwVersion(void) 00614 { 00615 return (uint8_t) L6474_GetFwVersion(); 00616 } 00617 00618 00619 /*** Public Interrupt Related Methods ***/ 00620 00621 /* ACTION 6 --------------------------------------------------------------* 00622 * Implement here interrupt related methods, if any. * 00623 * Note that interrupt handling is platform dependent, e.g.: * 00624 * + mbed: * 00625 * InterruptIn feature_irq(pin); //Interrupt object. * 00626 * feature_irq.rise(callback); //Attach a callback. * 00627 * feature_irq.mode(PullNone); //Set interrupt mode. * 00628 * feature_irq.enable_irq(); //Enable interrupt. * 00629 * feature_irq.disable_irq(); //Disable interrupt. * 00630 * + Arduino: * 00631 * attachInterrupt(pin, callback, RISING); //Attach a callback. * 00632 * detachInterrupt(pin); //Detach a callback. * 00633 * * 00634 * Example (mbed): * 00635 * void AttachFeatureIRQ(void (*fptr) (void)) * 00636 * { * 00637 * feature_irq.rise(fptr); * 00638 * } * 00639 * * 00640 * void EnableFeatureIRQ(void) * 00641 * { * 00642 * feature_irq.enable_irq(); * 00643 * } * 00644 * * 00645 * void DisableFeatureIRQ(void) * 00646 * { * 00647 * feature_irq.disable_irq(); * 00648 * } * 00649 *------------------------------------------------------------------------*/ 00650 /** 00651 * @brief Attaching an interrupt handler to the FLAG interrupt. 00652 * @param fptr An interrupt handler. 00653 * @retval None. 00654 */ 00655 void AttachFlagIRQ(void (*fptr)(void)) 00656 { 00657 flag_irq.fall(fptr); 00658 } 00659 00660 /** 00661 * @brief Enabling the FLAG interrupt handling. 00662 * @param None. 00663 * @retval None. 00664 */ 00665 void EnableFlagIRQ(void) 00666 { 00667 flag_irq.enable_irq(); 00668 } 00669 00670 /** 00671 * @brief Disabling the FLAG interrupt handling. 00672 * @param None. 00673 * @retval None. 00674 */ 00675 void DisableFlagIRQ(void) 00676 { 00677 flag_irq.disable_irq(); 00678 } 00679 00680 00681 protected: 00682 00683 /*** Protected Component Related Methods ***/ 00684 00685 /* ACTION 7 --------------------------------------------------------------* 00686 * Declare here the component's specific methods. * 00687 * They should be: * 00688 * + Methods with the same name of the C component's virtual table's * 00689 * functions (1); * 00690 * + Methods with the same name of the C component's extended virtual * 00691 * table's functions, if any (2); * 00692 * + Helper methods, if any, like functions declared in the component's * 00693 * source files but not pointed by the component's virtual table (3). * 00694 * * 00695 * Example: * 00696 * Status_t COMPONENT_GetValue(float *f); //(1) * 00697 * Status_t COMPONENT_EnableFeature(void); //(2) * 00698 * Status_t COMPONENT_ComputeAverage(void); //(3) * 00699 *------------------------------------------------------------------------*/ 00700 void L6474_AttachErrorHandler(void (*callback)(uint16_t error)); 00701 Status_t L6474_Init(void *init); 00702 Status_t L6474_ReadID(uint8_t *id); 00703 uint16_t L6474_GetAcceleration(void); 00704 uint16_t L6474_GetCurrentSpeed(void); 00705 uint16_t L6474_GetDeceleration(void); 00706 motorState_t L6474_GetDeviceState(void); 00707 uint8_t L6474_GetFwVersion(void); 00708 int32_t L6474_GetMark(void); 00709 uint16_t L6474_GetMaxSpeed(void); 00710 uint16_t L6474_GetMinSpeed(void); 00711 int32_t L6474_GetPosition(void); 00712 void L6474_GoHome(void); 00713 void L6474_GoMark(void); 00714 void L6474_GoTo(int32_t targetPosition); 00715 void L6474_HardStop(void); 00716 void L6474_Move(motorDir_t direction, uint32_t stepCount); 00717 void L6474_Run(motorDir_t direction); 00718 bool L6474_SetAcceleration(uint16_t newAcc); 00719 bool L6474_SetDeceleration(uint16_t newDec); 00720 void L6474_SetHome(void); 00721 void L6474_SetMark(void); 00722 bool L6474_SetMaxSpeed(uint16_t newMaxSpeed); 00723 bool L6474_SetMinSpeed(uint16_t newMinSpeed); 00724 bool L6474_SoftStop(void); 00725 void L6474_WaitWhileActive(void); 00726 void L6474_CmdDisable(void); 00727 void L6474_CmdEnable(void); 00728 uint32_t L6474_CmdGetParam(L6474_Registers_t parameter); 00729 uint16_t L6474_CmdGetStatus(void); 00730 void L6474_CmdNop(void); 00731 void L6474_CmdSetParam(L6474_Registers_t parameter, uint32_t value); 00732 uint16_t L6474_ReadStatusRegister(void); 00733 void L6474_SelectStepMode(motorStepMode_t stepMod); 00734 motorDir_t L6474_GetDirection(void); 00735 void L6474_SetDirection(motorDir_t direction); 00736 void L6474_ApplySpeed(uint16_t newSpeed); 00737 void L6474_ComputeSpeedProfile(uint32_t nbSteps); 00738 int32_t L6474_ConvertPosition(uint32_t abs_position_reg); 00739 void L6474_ErrorHandler(uint16_t error); 00740 void L6474_SendCommand(uint8_t param); 00741 void L6474_SetRegisterToPredefinedValues(void); 00742 void L6474_SetRegisterToInitializationValues(L6474_Init_t *init); 00743 void L6474_WriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte); 00744 void L6474_SetDeviceParamsToPredefinedValues(void); 00745 void L6474_StartMovement(void); 00746 void L6474_StepClockHandler(void); 00747 float L6474_Tval_Current_to_Par(float current_mA); 00748 float L6474_Par_to_Tval_Current(float Tval); 00749 float L6474_Tmin_Time_to_Par(float ton_min_us); 00750 float L6474_Par_to_Tmin_Time(float Tmin); 00751 00752 00753 /*** Component's I/O Methods ***/ 00754 00755 /** 00756 * @brief Utility function to read data from L6474. 00757 * @param[out] pBuffer pointer to the buffer to read data into. 00758 * @param[in] NumBytesToRead number of bytes to read. 00759 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. 00760 */ 00761 Status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead) 00762 { 00763 if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) 00764 return COMPONENT_ERROR; 00765 return COMPONENT_OK; 00766 } 00767 00768 /** 00769 * @brief Utility function to write data to L6474. 00770 * @param[in] pBuffer pointer to the buffer of data to send. 00771 * @param[in] NumBytesToWrite number of bytes to write. 00772 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. 00773 */ 00774 Status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite) 00775 { 00776 if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) 00777 return COMPONENT_ERROR; 00778 return COMPONENT_OK; 00779 } 00780 00781 /** 00782 * @brief Utility function to read and write data from/to L6474 at the same time. 00783 * @param[out] pBufferToRead pointer to the buffer to read data into. 00784 * @param[in] pBufferToWrite pointer to the buffer of data to send. 00785 * @param[in] NumBytes number of bytes to read and write. 00786 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. 00787 */ 00788 Status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes) 00789 { 00790 if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) 00791 return COMPONENT_ERROR; 00792 return COMPONENT_OK; 00793 } 00794 00795 /* ACTION 8 --------------------------------------------------------------* 00796 * Implement here other I/O methods beyond those already implemented * 00797 * above, which are declared extern within the component's header file. * 00798 *------------------------------------------------------------------------*/ 00799 /** 00800 * @brief Making the CPU wait. 00801 * @param None. 00802 * @retval None. 00803 */ 00804 void L6474_Delay(uint32_t delay) 00805 { 00806 wait_ms(delay); 00807 } 00808 00809 /** 00810 * @brief Enabling interrupts. 00811 * @param None. 00812 * @retval None. 00813 */ 00814 void L6474_EnableIrq(void) 00815 { 00816 __enable_irq(); 00817 } 00818 00819 /** 00820 * @brief Disabling interrupts. 00821 * @param None. 00822 * @retval None. 00823 */ 00824 void L6474_DisableIrq(void) 00825 { 00826 __disable_irq(); 00827 } 00828 00829 /** 00830 * @brief Initialising the PWM. 00831 * @param None. 00832 * @retval None. 00833 */ 00834 void L6474_PwmInit(void) {} 00835 00836 /** 00837 * @brief Setting the frequency of PWM. 00838 * The frequency controls directly the speed of the device. 00839 * @param frequency the frequency of PWM. 00840 * @retval None. 00841 */ 00842 void L6474_PwmSetFreq(uint16_t frequency) 00843 { 00844 /* Computing the period of PWM. */ 00845 double period = 1.0f / frequency; 00846 00847 /* Setting the period and the duty-cycle of PWM. */ 00848 pwm.period(period); 00849 pwm.write(0.5f); 00850 00851 /* Setting a callback with the same period of PWM's, to update the state machine. */ 00852 ticker.attach(this, &L6474::L6474_StepClockHandler, period); 00853 } 00854 00855 /** 00856 * @brief Stopping the PWM. 00857 * @param None. 00858 * @retval None. 00859 */ 00860 void L6474_PwmStop(void) 00861 { 00862 pwm.write(0.0f); 00863 ticker.detach(); 00864 } 00865 00866 /** 00867 * @brief Putting the device in standby mode. 00868 * @param None. 00869 * @retval None. 00870 */ 00871 void L6474_ReleaseReset(void) 00872 { 00873 standby_reset = 1; 00874 } 00875 00876 /** 00877 * @brief Putting the device in reset mode. 00878 * @param None. 00879 * @retval None. 00880 */ 00881 void L6474_Reset(void) 00882 { 00883 standby_reset = 0; 00884 } 00885 00886 /** 00887 * @brief Setting the direction of rotation. 00888 * @param gpioState direction of rotation: "1" for forward, "0" for backward. 00889 * @retval None. 00890 */ 00891 void L6474_SetDirectionGpio(uint8_t gpioState) 00892 { 00893 direction = gpioState; 00894 } 00895 00896 /** 00897 * @brief Writing and reading bytes to/from the component through the SPI at the same time. 00898 * @param[in] pByteToTransmit pointer to the buffer of data to send. 00899 * @param[out] pReceivedByte pointer to the buffer to read data into. 00900 * @retval "0" in case of success, "1" otherwise. 00901 */ 00902 uint8_t L6474_SpiWriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte) 00903 { 00904 return (uint8_t) (ReadWrite(pReceivedByte, pByteToTransmit, number_of_devices) == COMPONENT_OK ? 0 : 1); 00905 } 00906 00907 00908 /*** Component's Instance Variables ***/ 00909 00910 /* ACTION 9 --------------------------------------------------------------* 00911 * Declare here interrupt related variables, if needed. * 00912 * Note that interrupt handling is platform dependent, see * 00913 * "Interrupt Related Methods" above. * 00914 * * 00915 * Example: * 00916 * + mbed: * 00917 * InterruptIn feature_irq; * 00918 *------------------------------------------------------------------------*/ 00919 /* Flag Interrupt. */ 00920 InterruptIn flag_irq; 00921 00922 /* ACTION 10 -------------------------------------------------------------* 00923 * Declare here other pin related variables, if needed. * 00924 * * 00925 * Example: * 00926 * + mbed: * 00927 * DigitalOut standby_reset; * 00928 *------------------------------------------------------------------------*/ 00929 /* Standby/reset pin. */ 00930 DigitalOut standby_reset; 00931 00932 /* Direction of rotation pin. */ 00933 DigitalOut direction; 00934 00935 /* Pulse Width Modulation pin. */ 00936 PwmOut pwm; 00937 00938 /* Timer to trigger the PWM callback at each PWM pulse. */ 00939 Ticker ticker; 00940 00941 /* ACTION 11 -------------------------------------------------------------* 00942 * Declare here communication related variables, if needed. * 00943 * * 00944 * Example: * 00945 * + mbed: * 00946 * DigitalOut ssel; * 00947 * DevSPI &dev_spi; * 00948 *------------------------------------------------------------------------*/ 00949 /* Configuration. */ 00950 DigitalOut ssel; 00951 00952 /* IO Device. */ 00953 DevSPI &dev_spi; 00954 00955 /* ACTION 12 -------------------------------------------------------------* 00956 * Declare here identity related variables, if needed. * 00957 * Note that there should be only a unique identifier for each component, * 00958 * which should be the "who_am_i" parameter. * 00959 *------------------------------------------------------------------------*/ 00960 /* Identity */ 00961 uint8_t who_am_i; 00962 00963 /* ACTION 13 -------------------------------------------------------------* 00964 * Declare here the component's static and non-static data, one variable * 00965 * per line. * 00966 * * 00967 * Example: * 00968 * float measure; * 00969 * int instance_id; * 00970 * static int number_of_instances; * 00971 *------------------------------------------------------------------------*/ 00972 /* Data. */ 00973 void (*error_handler_callback)(uint16_t error); 00974 deviceParams_t device_prm; 00975 uint8_t device_instance; 00976 00977 /* Static data. */ 00978 static uint8_t number_of_devices; 00979 static uint8_t spi_tx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES]; 00980 static uint8_t spi_rx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES]; 00981 00982 00983 public: 00984 00985 /* Static data. */ 00986 static bool spi_preemtion_by_isr; 00987 static bool isr_flag; 00988 }; 00989 00990 #endif // __L6474_CLASS_H 00991 00992 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Sun Jul 17 2022 22:38:37 by 1.7.2