Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.
Fork of X_NUCLEO_IHM02A1 by
Components/l6470/l6470_class.h@17:4b3dc908724f, 2016-04-07 (annotated)
- Committer:
- Davidroid
- Date:
- Thu Apr 07 16:55:51 2016 +0000
- Revision:
- 17:4b3dc908724f
- Parent:
- 15:31785d1acd4b
- Child:
- 18:ddf3d5dc8137
+ StepperMotor interface updated: step-modes added, getter/setter methods for parameters removed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Davidroid | 0:92706998571a | 1 | /** |
Davidroid | 4:381d76f5b0b4 | 2 | ****************************************************************************** |
Davidroid | 4:381d76f5b0b4 | 3 | * @file l6470_class.h |
Davidroid | 12:a942d51c488b | 4 | * @author Davide Aliprandi, STMicroelectronics |
Davidroid | 4:381d76f5b0b4 | 5 | * @version V1.0.0 |
Davidroid | 4:381d76f5b0b4 | 6 | * @date November 12th, 2015 |
Davidroid | 4:381d76f5b0b4 | 7 | * @brief This file contains the class of an L6470 Motor Control component. |
Davidroid | 4:381d76f5b0b4 | 8 | ****************************************************************************** |
Davidroid | 4:381d76f5b0b4 | 9 | * |
Davidroid | 4:381d76f5b0b4 | 10 | * COPYRIGHT(c) 2014 STMicroelectronics |
Davidroid | 4:381d76f5b0b4 | 11 | * |
Davidroid | 4:381d76f5b0b4 | 12 | * Redistribution and use in source and binary forms, with or without modification, |
Davidroid | 4:381d76f5b0b4 | 13 | * are permitted provided that the following conditions are met: |
Davidroid | 4:381d76f5b0b4 | 14 | * 1. Redistributions of source code must retain the above copyright notice, |
Davidroid | 4:381d76f5b0b4 | 15 | * this list of conditions and the following disclaimer. |
Davidroid | 4:381d76f5b0b4 | 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Davidroid | 4:381d76f5b0b4 | 17 | * this list of conditions and the following disclaimer in the documentation |
Davidroid | 4:381d76f5b0b4 | 18 | * and/or other materials provided with the distribution. |
Davidroid | 4:381d76f5b0b4 | 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Davidroid | 4:381d76f5b0b4 | 20 | * may be used to endorse or promote products derived from this software |
Davidroid | 4:381d76f5b0b4 | 21 | * without specific prior written permission. |
Davidroid | 4:381d76f5b0b4 | 22 | * |
Davidroid | 4:381d76f5b0b4 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Davidroid | 4:381d76f5b0b4 | 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Davidroid | 4:381d76f5b0b4 | 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Davidroid | 4:381d76f5b0b4 | 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Davidroid | 4:381d76f5b0b4 | 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Davidroid | 4:381d76f5b0b4 | 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Davidroid | 4:381d76f5b0b4 | 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Davidroid | 4:381d76f5b0b4 | 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Davidroid | 4:381d76f5b0b4 | 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Davidroid | 4:381d76f5b0b4 | 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Davidroid | 4:381d76f5b0b4 | 33 | * |
Davidroid | 4:381d76f5b0b4 | 34 | ****************************************************************************** |
Davidroid | 4:381d76f5b0b4 | 35 | */ |
Davidroid | 0:92706998571a | 36 | |
Davidroid | 0:92706998571a | 37 | |
Davidroid | 15:31785d1acd4b | 38 | /* Generated with STM32CubeTOO -----------------------------------------------*/ |
Davidroid | 0:92706998571a | 39 | |
Davidroid | 0:92706998571a | 40 | |
Davidroid | 0:92706998571a | 41 | /* Revision ------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 42 | /* |
Davidroid | 0:92706998571a | 43 | Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev |
Davidroid | 0:92706998571a | 44 | Branch/Trunk/Tag: trunk |
Davidroid | 0:92706998571a | 45 | Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.h |
Davidroid | 0:92706998571a | 46 | Revision: 0 |
Davidroid | 0:92706998571a | 47 | */ |
Davidroid | 0:92706998571a | 48 | |
Davidroid | 0:92706998571a | 49 | |
Davidroid | 0:92706998571a | 50 | /* Define to prevent recursive inclusion -------------------------------------*/ |
Davidroid | 0:92706998571a | 51 | |
Davidroid | 0:92706998571a | 52 | #ifndef __L6470_CLASS_H |
Davidroid | 0:92706998571a | 53 | #define __L6470_CLASS_H |
Davidroid | 0:92706998571a | 54 | |
Davidroid | 0:92706998571a | 55 | |
Davidroid | 0:92706998571a | 56 | /* Includes ------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 57 | |
Davidroid | 0:92706998571a | 58 | /* ACTION 1 ------------------------------------------------------------------* |
Davidroid | 0:92706998571a | 59 | * Include here platform specific header files. * |
Davidroid | 14:e614697ebf34 | 60 | *----------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 61 | #include "mbed.h" |
Davidroid | 0:92706998571a | 62 | #include "DevSPI.h" |
Davidroid | 0:92706998571a | 63 | /* ACTION 2 ------------------------------------------------------------------* |
Davidroid | 0:92706998571a | 64 | * Include here component specific header files. * |
Davidroid | 14:e614697ebf34 | 65 | *----------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 66 | #include "l6470.h" |
Davidroid | 0:92706998571a | 67 | /* ACTION 3 ------------------------------------------------------------------* |
Davidroid | 0:92706998571a | 68 | * Include here interface specific header files. * |
Davidroid | 0:92706998571a | 69 | * * |
Davidroid | 0:92706998571a | 70 | * Example: * |
Davidroid | 0:92706998571a | 71 | * #include "../Interfaces/Humidity_class.h" * |
Davidroid | 0:92706998571a | 72 | * #include "../Interfaces/Temperature_class.h" * |
Davidroid | 0:92706998571a | 73 | *----------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 74 | #include "../Interfaces/StepperMotor_class.h" |
Davidroid | 0:92706998571a | 75 | |
Davidroid | 0:92706998571a | 76 | |
Davidroid | 0:92706998571a | 77 | /* Classes -------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 78 | |
Davidroid | 14:e614697ebf34 | 79 | /** |
Davidroid | 14:e614697ebf34 | 80 | * @brief Class representing a L6470 component. |
Davidroid | 0:92706998571a | 81 | */ |
Davidroid | 0:92706998571a | 82 | class L6470 : public StepperMotor |
Davidroid | 0:92706998571a | 83 | { |
Davidroid | 0:92706998571a | 84 | public: |
Davidroid | 0:92706998571a | 85 | |
Davidroid | 1:b78dab6d2c58 | 86 | /*** Public Component Related Types ***/ |
Davidroid | 1:b78dab6d2c58 | 87 | |
Davidroid | 1:b78dab6d2c58 | 88 | /** |
Davidroid | 1:b78dab6d2c58 | 89 | * @brief Prepared Actions. |
Davidroid | 1:b78dab6d2c58 | 90 | */ |
Davidroid | 1:b78dab6d2c58 | 91 | typedef enum |
Davidroid | 1:b78dab6d2c58 | 92 | { |
Davidroid | 1:b78dab6d2c58 | 93 | PREPARED_NO_ACTION = 0, |
Davidroid | 1:b78dab6d2c58 | 94 | PREPARED_GET_POSITION, |
Davidroid | 1:b78dab6d2c58 | 95 | PREPARED_GET_MARK, |
Davidroid | 1:b78dab6d2c58 | 96 | PREPARED_GET_SPEED, |
Davidroid | 1:b78dab6d2c58 | 97 | PREPARED_GET_MAX_SPEED, |
Davidroid | 1:b78dab6d2c58 | 98 | PREPARED_GET_MIN_SPEED, |
Davidroid | 1:b78dab6d2c58 | 99 | PREPARED_GET_ACCELERATION, |
Davidroid | 1:b78dab6d2c58 | 100 | PREPARED_GET_DECELERATION, |
Davidroid | 1:b78dab6d2c58 | 101 | PREPARED_GET_DIRECTION, |
Davidroid | 1:b78dab6d2c58 | 102 | PREPARED_SET_MARK |
Davidroid | 1:b78dab6d2c58 | 103 | } prepared_action_t; |
Davidroid | 1:b78dab6d2c58 | 104 | |
Davidroid | 1:b78dab6d2c58 | 105 | |
Davidroid | 0:92706998571a | 106 | /*** Constructor and Destructor Methods ***/ |
Davidroid | 0:92706998571a | 107 | |
Davidroid | 0:92706998571a | 108 | /** |
Davidroid | 0:92706998571a | 109 | * @brief Constructor. |
Davidroid | 0:92706998571a | 110 | * @param flag_irq pin name of the FLAG pin of the component. |
Davidroid | 1:b78dab6d2c58 | 111 | * @param busy_irq pin name of the BUSY pin of the component. |
Davidroid | 0:92706998571a | 112 | * @param standby_reset pin name of the STBY\RST pin of the component. |
Davidroid | 0:92706998571a | 113 | * @param ssel pin name of the SSEL pin of the SPI device to be used for communication. |
Davidroid | 0:92706998571a | 114 | * @param spi SPI device to be used for communication. |
Davidroid | 0:92706998571a | 115 | */ |
Davidroid | 1:b78dab6d2c58 | 116 | 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) |
Davidroid | 0:92706998571a | 117 | { |
Davidroid | 0:92706998571a | 118 | /* ACTION 4 ----------------------------------------------------------* |
Davidroid | 0:92706998571a | 119 | * Initialize here the component's member variables, one variable per * |
Davidroid | 0:92706998571a | 120 | * line. * |
Davidroid | 0:92706998571a | 121 | * * |
Davidroid | 0:92706998571a | 122 | * Example: * |
Davidroid | 7:3bb27256c3ed | 123 | * measure = 0; * |
Davidroid | 7:3bb27256c3ed | 124 | * instance_id = number_of_instances++; * |
Davidroid | 0:92706998571a | 125 | *--------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 126 | L6470_Register = &_L6470_Register[0]; |
Davidroid | 0:92706998571a | 127 | L6470_ApplicationCommand = &_L6470_ApplicationCommand[0]; |
Davidroid | 0:92706998571a | 128 | L6470_Direction = &_L6470_Direction[0]; |
Davidroid | 0:92706998571a | 129 | L6470_ACT = &_L6470_ACT[0]; |
Davidroid | 0:92706998571a | 130 | pL6470_StatusRegister = &L6470_StatusRegister; |
Davidroid | 1:b78dab6d2c58 | 131 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 132 | L6470_Id = number_of_devices++; |
Davidroid | 0:92706998571a | 133 | L6470_DaisyChain_HalfPrepared = ZERO_F; |
Davidroid | 0:92706998571a | 134 | memset(L6470_AppCmdPkg, 0, L6470DAISYCHAINSIZE * sizeof(sL6470_AppCmdPkg_t)); |
Davidroid | 0:92706998571a | 135 | memset(L6470_DaisyChainSpiTxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t)); |
Davidroid | 0:92706998571a | 136 | memset(L6470_DaisyChainSpiRxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t)); |
Davidroid | 0:92706998571a | 137 | } |
Davidroid | 0:92706998571a | 138 | |
Davidroid | 0:92706998571a | 139 | /** |
Davidroid | 0:92706998571a | 140 | * @brief Destructor. |
Davidroid | 0:92706998571a | 141 | */ |
Davidroid | 0:92706998571a | 142 | virtual ~L6470(void) {} |
Davidroid | 0:92706998571a | 143 | |
Davidroid | 0:92706998571a | 144 | |
Davidroid | 0:92706998571a | 145 | /*** Public Component Related Methods ***/ |
Davidroid | 0:92706998571a | 146 | |
Davidroid | 0:92706998571a | 147 | /* ACTION 5 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 148 | * Implement here the component's public methods, as wrappers of the C * |
Davidroid | 0:92706998571a | 149 | * component's functions. * |
Davidroid | 0:92706998571a | 150 | * They should be: * |
Davidroid | 0:92706998571a | 151 | * + Methods with the same name of the C component's virtual table's * |
Davidroid | 0:92706998571a | 152 | * functions (1); * |
Davidroid | 0:92706998571a | 153 | * + Methods with the same name of the C component's extended virtual * |
Davidroid | 0:92706998571a | 154 | * table's functions, if any (2). * |
Davidroid | 0:92706998571a | 155 | * * |
Davidroid | 0:92706998571a | 156 | * Example: * |
Davidroid | 14:e614697ebf34 | 157 | * virtual int GetValue(float *f) //(1) * |
Davidroid | 0:92706998571a | 158 | * { * |
Davidroid | 14:e614697ebf34 | 159 | * return COMPONENT_GetValue(float *f); * |
Davidroid | 0:92706998571a | 160 | * } * |
Davidroid | 0:92706998571a | 161 | * * |
Davidroid | 0:92706998571a | 162 | * virtual int EnableFeature(void) //(2) * |
Davidroid | 0:92706998571a | 163 | * { * |
Davidroid | 0:92706998571a | 164 | * return COMPONENT_EnableFeature(); * |
Davidroid | 0:92706998571a | 165 | * } * |
Davidroid | 0:92706998571a | 166 | *------------------------------------------------------------------------*/ |
Davidroid | 1:b78dab6d2c58 | 167 | /** |
Davidroid | 1:b78dab6d2c58 | 168 | * @brief Initializing the component. |
Davidroid | 1:b78dab6d2c58 | 169 | * @param init Pointer to device specific initalization structure. |
Davidroid | 1:b78dab6d2c58 | 170 | * @retval "0" in case of success, an error code otherwise. |
Davidroid | 1:b78dab6d2c58 | 171 | */ |
Davidroid | 0:92706998571a | 172 | virtual int Init(void *init) |
Davidroid | 0:92706998571a | 173 | { |
Davidroid | 13:25a579b9b7c3 | 174 | return (int) L6470_Config((void *) init); |
Davidroid | 0:92706998571a | 175 | } |
Davidroid | 0:92706998571a | 176 | |
Davidroid | 1:b78dab6d2c58 | 177 | /** |
Davidroid | 1:b78dab6d2c58 | 178 | * @brief Getting the ID of the component. |
Davidroid | 1:b78dab6d2c58 | 179 | * @param id Pointer to an allocated variable to store the ID into. |
Davidroid | 1:b78dab6d2c58 | 180 | * @retval "0" in case of success, an error code otherwise. |
Davidroid | 1:b78dab6d2c58 | 181 | */ |
Davidroid | 0:92706998571a | 182 | virtual int ReadID(uint8_t *id) |
Davidroid | 0:92706998571a | 183 | { |
Davidroid | 0:92706998571a | 184 | return (int) 0; |
Davidroid | 0:92706998571a | 185 | } |
Davidroid | 0:92706998571a | 186 | |
Davidroid | 1:b78dab6d2c58 | 187 | /** |
Davidroid | 1:b78dab6d2c58 | 188 | * @brief Getting the status. |
Davidroid | 1:b78dab6d2c58 | 189 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 190 | * @retval The status. |
Davidroid | 1:b78dab6d2c58 | 191 | */ |
Davidroid | 0:92706998571a | 192 | virtual unsigned int GetStatus(void) |
Davidroid | 0:92706998571a | 193 | { |
Davidroid | 0:92706998571a | 194 | return (unsigned int) L6470_GetStatus(); |
Davidroid | 0:92706998571a | 195 | } |
Davidroid | 1:b78dab6d2c58 | 196 | |
Davidroid | 17:4b3dc908724f | 197 | /** |
Davidroid | 1:b78dab6d2c58 | 198 | * @brief Getting a parameter. |
Davidroid | 17:4b3dc908724f | 199 | * @param parameter A parameter's register address. |
Davidroid | 1:b78dab6d2c58 | 200 | * @retval The parameter's value. |
Davidroid | 17:4b3dc908724f | 201 | * @note The parameter can be one of the following: |
Davidroid | 17:4b3dc908724f | 202 | * + L6470_ABS_POS_ID |
Davidroid | 17:4b3dc908724f | 203 | * + L6470_EL_POS_ID |
Davidroid | 17:4b3dc908724f | 204 | * + L6470_MARK_ID |
Davidroid | 17:4b3dc908724f | 205 | * + L6470_SPEED_ID |
Davidroid | 17:4b3dc908724f | 206 | * + L6470_ACC_ID |
Davidroid | 17:4b3dc908724f | 207 | * + L6470_DEC_ID |
Davidroid | 17:4b3dc908724f | 208 | * + L6470_MAX_SPEED_ID |
Davidroid | 17:4b3dc908724f | 209 | * + L6470_MIN_SPEED_ID |
Davidroid | 17:4b3dc908724f | 210 | * + L6470_FS_SPD_ID |
Davidroid | 17:4b3dc908724f | 211 | * + L6470_KVAL_HOLD_ID |
Davidroid | 17:4b3dc908724f | 212 | * + L6470_KVAL_RUN_ID |
Davidroid | 17:4b3dc908724f | 213 | * + L6470_KVAL_ACC_ID |
Davidroid | 17:4b3dc908724f | 214 | * + L6470_KVAL_DEC_ID |
Davidroid | 17:4b3dc908724f | 215 | * + L6470_INT_SPEED_ID |
Davidroid | 17:4b3dc908724f | 216 | * + L6470_ST_SLP_ID |
Davidroid | 17:4b3dc908724f | 217 | * + L6470_FN_SLP_ACC_ID |
Davidroid | 17:4b3dc908724f | 218 | * + L6470_FN_SLP_DEC_ID |
Davidroid | 17:4b3dc908724f | 219 | * + L6470_K_THERM_ID |
Davidroid | 17:4b3dc908724f | 220 | * + L6470_ADC_OUT_ID |
Davidroid | 17:4b3dc908724f | 221 | * + L6470_OCD_TH_ID |
Davidroid | 17:4b3dc908724f | 222 | * + L6470_STALL_TH_ID |
Davidroid | 17:4b3dc908724f | 223 | * + L6470_STEP_MODE_ID |
Davidroid | 17:4b3dc908724f | 224 | * + L6470_ALARM_EN_ID |
Davidroid | 17:4b3dc908724f | 225 | * + L6470_CONFIG_ID |
Davidroid | 17:4b3dc908724f | 226 | * + L6470_STATUS_ID |
Davidroid | 1:b78dab6d2c58 | 227 | */ |
Davidroid | 17:4b3dc908724f | 228 | virtual unsigned int GetParameter(unsigned int parameter) |
Davidroid | 0:92706998571a | 229 | { |
Davidroid | 17:4b3dc908724f | 230 | return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter); |
Davidroid | 0:92706998571a | 231 | } |
Davidroid | 0:92706998571a | 232 | |
Davidroid | 1:b78dab6d2c58 | 233 | /** |
Davidroid | 1:b78dab6d2c58 | 234 | * @brief Getting the position. |
Davidroid | 1:b78dab6d2c58 | 235 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 236 | * @retval The position. |
Davidroid | 1:b78dab6d2c58 | 237 | */ |
Davidroid | 0:92706998571a | 238 | virtual signed int GetPosition(void) |
Davidroid | 0:92706998571a | 239 | { |
Davidroid | 1:b78dab6d2c58 | 240 | return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID)); |
Davidroid | 0:92706998571a | 241 | } |
Davidroid | 0:92706998571a | 242 | |
Davidroid | 1:b78dab6d2c58 | 243 | /** |
Davidroid | 1:b78dab6d2c58 | 244 | * @brief Getting the marked position. |
Davidroid | 1:b78dab6d2c58 | 245 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 246 | * @retval The marked position. |
Davidroid | 1:b78dab6d2c58 | 247 | */ |
Davidroid | 0:92706998571a | 248 | virtual signed int GetMark(void) |
Davidroid | 0:92706998571a | 249 | { |
Davidroid | 1:b78dab6d2c58 | 250 | return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID)); |
Davidroid | 0:92706998571a | 251 | } |
Davidroid | 0:92706998571a | 252 | |
Davidroid | 1:b78dab6d2c58 | 253 | /** |
Davidroid | 1:b78dab6d2c58 | 254 | * @brief Getting the current speed in pps. |
Davidroid | 1:b78dab6d2c58 | 255 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 256 | * @retval The current speed in pps. |
Davidroid | 1:b78dab6d2c58 | 257 | */ |
Davidroid | 0:92706998571a | 258 | virtual unsigned int GetSpeed(void) |
Davidroid | 0:92706998571a | 259 | { |
Davidroid | 1:b78dab6d2c58 | 260 | return round(L6470_Speed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID))); |
Davidroid | 0:92706998571a | 261 | } |
Davidroid | 0:92706998571a | 262 | |
Davidroid | 1:b78dab6d2c58 | 263 | /** |
Davidroid | 1:b78dab6d2c58 | 264 | * @brief Getting the maximum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 265 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 266 | * @retval The maximum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 267 | */ |
Davidroid | 0:92706998571a | 268 | virtual unsigned int GetMaxSpeed(void) |
Davidroid | 0:92706998571a | 269 | { |
Davidroid | 1:b78dab6d2c58 | 270 | return round(L6470_MaxSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID))); |
Davidroid | 0:92706998571a | 271 | } |
Davidroid | 0:92706998571a | 272 | |
Davidroid | 1:b78dab6d2c58 | 273 | /** |
Davidroid | 1:b78dab6d2c58 | 274 | * @brief Getting the minimum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 275 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 276 | * @retval The minimum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 277 | */ |
Davidroid | 0:92706998571a | 278 | virtual unsigned int GetMinSpeed(void) |
Davidroid | 0:92706998571a | 279 | { |
Davidroid | 1:b78dab6d2c58 | 280 | return round(L6470_MinSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID))); |
Davidroid | 0:92706998571a | 281 | } |
Davidroid | 0:92706998571a | 282 | |
Davidroid | 1:b78dab6d2c58 | 283 | /** |
Davidroid | 1:b78dab6d2c58 | 284 | * @brief Getting the acceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 285 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 286 | * @retval The acceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 287 | */ |
Davidroid | 0:92706998571a | 288 | virtual unsigned int GetAcceleration(void) |
Davidroid | 0:92706998571a | 289 | { |
Davidroid | 1:b78dab6d2c58 | 290 | return round(L6470_Acc_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID))); |
Davidroid | 0:92706998571a | 291 | } |
Davidroid | 0:92706998571a | 292 | |
Davidroid | 1:b78dab6d2c58 | 293 | /** |
Davidroid | 1:b78dab6d2c58 | 294 | * @brief Getting the deceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 295 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 296 | * @retval The deceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 297 | */ |
Davidroid | 0:92706998571a | 298 | virtual unsigned int GetDeceleration(void) |
Davidroid | 0:92706998571a | 299 | { |
Davidroid | 1:b78dab6d2c58 | 300 | return round(L6470_Dec_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID))); |
Davidroid | 0:92706998571a | 301 | } |
Davidroid | 0:92706998571a | 302 | |
Davidroid | 1:b78dab6d2c58 | 303 | /** |
Davidroid | 1:b78dab6d2c58 | 304 | * @brief Getting the direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 305 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 306 | * @retval The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 307 | */ |
Davidroid | 0:92706998571a | 308 | virtual direction_t GetDirection(void) |
Davidroid | 0:92706998571a | 309 | { |
Davidroid | 0:92706998571a | 310 | return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD); |
Davidroid | 0:92706998571a | 311 | } |
Davidroid | 0:92706998571a | 312 | |
Davidroid | 1:b78dab6d2c58 | 313 | /** |
Davidroid | 17:4b3dc908724f | 314 | * @brief Setting a parameter. |
Davidroid | 17:4b3dc908724f | 315 | * @param parameter A parameter's register address. |
Davidroid | 17:4b3dc908724f | 316 | * @param value The parameter's value. |
Davidroid | 17:4b3dc908724f | 317 | * @retval None. |
Davidroid | 17:4b3dc908724f | 318 | * @note The parameter can be one of the following: |
Davidroid | 17:4b3dc908724f | 319 | * + L6470_ABS_POS_ID |
Davidroid | 17:4b3dc908724f | 320 | * + L6470_EL_POS_ID |
Davidroid | 17:4b3dc908724f | 321 | * + L6470_MARK_ID |
Davidroid | 17:4b3dc908724f | 322 | * + L6470_SPEED_ID |
Davidroid | 17:4b3dc908724f | 323 | * + L6470_ACC_ID |
Davidroid | 17:4b3dc908724f | 324 | * + L6470_DEC_ID |
Davidroid | 17:4b3dc908724f | 325 | * + L6470_MAX_SPEED_ID |
Davidroid | 17:4b3dc908724f | 326 | * + L6470_MIN_SPEED_ID |
Davidroid | 17:4b3dc908724f | 327 | * + L6470_FS_SPD_ID |
Davidroid | 17:4b3dc908724f | 328 | * + L6470_KVAL_HOLD_ID |
Davidroid | 17:4b3dc908724f | 329 | * + L6470_KVAL_RUN_ID |
Davidroid | 17:4b3dc908724f | 330 | * + L6470_KVAL_ACC_ID |
Davidroid | 17:4b3dc908724f | 331 | * + L6470_KVAL_DEC_ID |
Davidroid | 17:4b3dc908724f | 332 | * + L6470_INT_SPEED_ID |
Davidroid | 17:4b3dc908724f | 333 | * + L6470_ST_SLP_ID |
Davidroid | 17:4b3dc908724f | 334 | * + L6470_FN_SLP_ACC_ID |
Davidroid | 17:4b3dc908724f | 335 | * + L6470_FN_SLP_DEC_ID |
Davidroid | 17:4b3dc908724f | 336 | * + L6470_K_THERM_ID |
Davidroid | 17:4b3dc908724f | 337 | * + L6470_ADC_OUT_ID |
Davidroid | 17:4b3dc908724f | 338 | * + L6470_OCD_TH_ID |
Davidroid | 17:4b3dc908724f | 339 | * + L6470_STALL_TH_ID |
Davidroid | 17:4b3dc908724f | 340 | * + L6470_STEP_MODE_ID |
Davidroid | 17:4b3dc908724f | 341 | * + L6470_ALARM_EN_ID |
Davidroid | 17:4b3dc908724f | 342 | * + L6470_CONFIG_ID |
Davidroid | 17:4b3dc908724f | 343 | * + L6470_STATUS_ID |
Davidroid | 17:4b3dc908724f | 344 | * @warning Some registers can only be written in particular conditions (see L6470's datasheet). |
Davidroid | 17:4b3dc908724f | 345 | * Any attempt to write one of those registers when the conditions are not satisfied |
Davidroid | 17:4b3dc908724f | 346 | * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the |
Davidroid | 17:4b3dc908724f | 347 | * last argument byte. Any attempt to set an inexistent register (wrong address value) |
Davidroid | 17:4b3dc908724f | 348 | * causes the command to be ignored and the WRONG_CMD flag to rise. |
Davidroid | 17:4b3dc908724f | 349 | * For example, setting some parameters requires first to disable the power bridge; |
Davidroid | 17:4b3dc908724f | 350 | * this can be done through the SoftHiZ() method. |
Davidroid | 17:4b3dc908724f | 351 | * They are the following: |
Davidroid | 17:4b3dc908724f | 352 | * + L6470_ABS_POS_ID |
Davidroid | 17:4b3dc908724f | 353 | * + L6470_EL_POS_ID |
Davidroid | 17:4b3dc908724f | 354 | * + L6470_SPEED_ID |
Davidroid | 17:4b3dc908724f | 355 | * + L6470_ACC_ID |
Davidroid | 17:4b3dc908724f | 356 | * + L6470_DEC_ID |
Davidroid | 17:4b3dc908724f | 357 | * + L6470_MAX_SPEED_ID |
Davidroid | 17:4b3dc908724f | 358 | * + L6470_MIN_SPEED_ID |
Davidroid | 17:4b3dc908724f | 359 | * + L6470_INT_SPEED_ID |
Davidroid | 17:4b3dc908724f | 360 | * + L6470_ST_SLP_ID |
Davidroid | 17:4b3dc908724f | 361 | * + L6470_FN_SLP_ACC_ID |
Davidroid | 17:4b3dc908724f | 362 | * + L6470_FN_SLP_DEC_ID |
Davidroid | 17:4b3dc908724f | 363 | * + L6470_ADC_OUT_ID |
Davidroid | 17:4b3dc908724f | 364 | * + L6470_STEP_MODE_ID |
Davidroid | 17:4b3dc908724f | 365 | * + L6470_CONFIG_ID |
Davidroid | 17:4b3dc908724f | 366 | * + L6470_STATUS_ID |
Davidroid | 1:b78dab6d2c58 | 367 | */ |
Davidroid | 17:4b3dc908724f | 368 | virtual void SetParameter(unsigned int parameter, unsigned int value) |
Davidroid | 0:92706998571a | 369 | { |
Davidroid | 0:92706998571a | 370 | L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value); |
Davidroid | 0:92706998571a | 371 | } |
Davidroid | 0:92706998571a | 372 | |
Davidroid | 1:b78dab6d2c58 | 373 | /** |
Davidroid | 1:b78dab6d2c58 | 374 | * @brief Setting the current position to be the home position. |
Davidroid | 1:b78dab6d2c58 | 375 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 376 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 377 | */ |
Davidroid | 0:92706998571a | 378 | virtual void SetHome(void) |
Davidroid | 0:92706998571a | 379 | { |
Davidroid | 0:92706998571a | 380 | L6470_ResetPos(); |
Davidroid | 0:92706998571a | 381 | } |
Davidroid | 0:92706998571a | 382 | |
Davidroid | 1:b78dab6d2c58 | 383 | /** |
Davidroid | 1:b78dab6d2c58 | 384 | * @brief Setting the current position to be the marked position. |
Davidroid | 1:b78dab6d2c58 | 385 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 386 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 387 | */ |
Davidroid | 0:92706998571a | 388 | virtual void SetMark(void) |
Davidroid | 0:92706998571a | 389 | { |
Davidroid | 0:92706998571a | 390 | L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID)); |
Davidroid | 0:92706998571a | 391 | } |
Davidroid | 0:92706998571a | 392 | |
Davidroid | 1:b78dab6d2c58 | 393 | /** |
Davidroid | 1:b78dab6d2c58 | 394 | * @brief Setting the current position to be the marked position. |
Davidroid | 1:b78dab6d2c58 | 395 | * @param position The given position. |
Davidroid | 1:b78dab6d2c58 | 396 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 397 | */ |
Davidroid | 1:b78dab6d2c58 | 398 | virtual void SetMark(signed int position) |
Davidroid | 1:b78dab6d2c58 | 399 | { |
Davidroid | 1:b78dab6d2c58 | 400 | L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position)); |
Davidroid | 1:b78dab6d2c58 | 401 | } |
Davidroid | 1:b78dab6d2c58 | 402 | |
Davidroid | 1:b78dab6d2c58 | 403 | /** |
Davidroid | 1:b78dab6d2c58 | 404 | * @brief Setting the maximum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 405 | * @param speed The maximum speed in pps. |
Davidroid | 17:4b3dc908724f | 406 | * @retval "true" in case of success, "false" otherwise. |
Davidroid | 1:b78dab6d2c58 | 407 | */ |
Davidroid | 17:4b3dc908724f | 408 | virtual bool SetMaxSpeed(unsigned int speed) |
Davidroid | 0:92706998571a | 409 | { |
Davidroid | 1:b78dab6d2c58 | 410 | L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed)); |
Davidroid | 17:4b3dc908724f | 411 | return true; |
Davidroid | 0:92706998571a | 412 | } |
Davidroid | 0:92706998571a | 413 | |
Davidroid | 1:b78dab6d2c58 | 414 | /** |
Davidroid | 1:b78dab6d2c58 | 415 | * @brief Setting the minimum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 416 | * @param speed The minimum speed in pps. |
Davidroid | 17:4b3dc908724f | 417 | * @retval "true" in case of success, "false" otherwise. |
Davidroid | 1:b78dab6d2c58 | 418 | */ |
Davidroid | 17:4b3dc908724f | 419 | virtual bool SetMinSpeed(unsigned int speed) |
Davidroid | 0:92706998571a | 420 | { |
Davidroid | 1:b78dab6d2c58 | 421 | L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed)); |
Davidroid | 17:4b3dc908724f | 422 | return true; |
Davidroid | 0:92706998571a | 423 | } |
Davidroid | 0:92706998571a | 424 | |
Davidroid | 1:b78dab6d2c58 | 425 | /** |
Davidroid | 1:b78dab6d2c58 | 426 | * @brief Setting the acceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 427 | * @param acceleration The acceleration in pps^2. |
Davidroid | 17:4b3dc908724f | 428 | * @retval "true" in case of success, "false" otherwise. |
Davidroid | 1:b78dab6d2c58 | 429 | */ |
Davidroid | 17:4b3dc908724f | 430 | virtual bool SetAcceleration(unsigned int acceleration) |
Davidroid | 0:92706998571a | 431 | { |
Davidroid | 1:b78dab6d2c58 | 432 | L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration)); |
Davidroid | 17:4b3dc908724f | 433 | return true; |
Davidroid | 0:92706998571a | 434 | } |
Davidroid | 0:92706998571a | 435 | |
Davidroid | 1:b78dab6d2c58 | 436 | /** |
Davidroid | 1:b78dab6d2c58 | 437 | * @brief Setting the deceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 438 | * @param deceleration The deceleration in pps^2. |
Davidroid | 17:4b3dc908724f | 439 | * @retval "true" in case of success, "false" otherwise. |
Davidroid | 1:b78dab6d2c58 | 440 | */ |
Davidroid | 17:4b3dc908724f | 441 | virtual bool SetDeceleration(unsigned int deceleration) |
Davidroid | 0:92706998571a | 442 | { |
Davidroid | 1:b78dab6d2c58 | 443 | L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration)); |
Davidroid | 17:4b3dc908724f | 444 | return true; |
Davidroid | 17:4b3dc908724f | 445 | } |
Davidroid | 17:4b3dc908724f | 446 | |
Davidroid | 17:4b3dc908724f | 447 | /** |
Davidroid | 17:4b3dc908724f | 448 | * @brief Setting the Step Mode. |
Davidroid | 17:4b3dc908724f | 449 | * @param step_mode The Step Mode. |
Davidroid | 17:4b3dc908724f | 450 | * @retval "true" in case of success, "false" otherwise. |
Davidroid | 17:4b3dc908724f | 451 | * @warning Setting the step mode implies first disabling the power bridge through |
Davidroid | 17:4b3dc908724f | 452 | * the SoftHiZ() method. |
Davidroid | 17:4b3dc908724f | 453 | * @warning Every time step mode is changed, the values of the home |
Davidroid | 17:4b3dc908724f | 454 | * and mark positions lose meaning and are reset. |
Davidroid | 17:4b3dc908724f | 455 | */ |
Davidroid | 17:4b3dc908724f | 456 | virtual bool SetStepMode(step_mode_t step_mode) |
Davidroid | 17:4b3dc908724f | 457 | { |
Davidroid | 17:4b3dc908724f | 458 | if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128) |
Davidroid | 17:4b3dc908724f | 459 | return false; |
Davidroid | 17:4b3dc908724f | 460 | |
Davidroid | 17:4b3dc908724f | 461 | SoftHiZ(); |
Davidroid | 17:4b3dc908724f | 462 | L6470_SetParam((eL6470_RegId_t) L6470_STEP_MODE_ID, (eMotorStepMode_t) step_mode); |
Davidroid | 17:4b3dc908724f | 463 | return true; |
Davidroid | 0:92706998571a | 464 | } |
Davidroid | 0:92706998571a | 465 | |
Davidroid | 1:b78dab6d2c58 | 466 | /** |
Davidroid | 1:b78dab6d2c58 | 467 | * @brief Going to a specified position through the shortest path. |
Davidroid | 1:b78dab6d2c58 | 468 | * @param position The desired position. |
Davidroid | 1:b78dab6d2c58 | 469 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 470 | */ |
Davidroid | 0:92706998571a | 471 | virtual void GoTo(signed int position) |
Davidroid | 0:92706998571a | 472 | { |
Davidroid | 1:b78dab6d2c58 | 473 | L6470_GoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position)); |
Davidroid | 0:92706998571a | 474 | } |
Davidroid | 0:92706998571a | 475 | |
Davidroid | 1:b78dab6d2c58 | 476 | /** |
Davidroid | 1:b78dab6d2c58 | 477 | * @brief Going to a specified position imposing the desired direction. |
Davidroid | 1:b78dab6d2c58 | 478 | * @param position The desired position. |
Davidroid | 1:b78dab6d2c58 | 479 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 480 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 481 | */ |
Davidroid | 0:92706998571a | 482 | virtual void GoTo(signed int position, direction_t direction) |
Davidroid | 0:92706998571a | 483 | { |
Davidroid | 1:b78dab6d2c58 | 484 | 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)); |
Davidroid | 0:92706998571a | 485 | } |
Davidroid | 0:92706998571a | 486 | |
Davidroid | 1:b78dab6d2c58 | 487 | /** |
Davidroid | 1:b78dab6d2c58 | 488 | * @brief Going to the home position. |
Davidroid | 1:b78dab6d2c58 | 489 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 490 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 491 | */ |
Davidroid | 0:92706998571a | 492 | virtual void GoHome(void) |
Davidroid | 0:92706998571a | 493 | { |
Davidroid | 0:92706998571a | 494 | L6470_GoHome(); |
Davidroid | 0:92706998571a | 495 | } |
Davidroid | 0:92706998571a | 496 | |
Davidroid | 1:b78dab6d2c58 | 497 | /** |
Davidroid | 1:b78dab6d2c58 | 498 | * @brief Going to the marked position. |
Davidroid | 1:b78dab6d2c58 | 499 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 500 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 501 | */ |
Davidroid | 0:92706998571a | 502 | virtual void GoMark(void) |
Davidroid | 0:92706998571a | 503 | { |
Davidroid | 0:92706998571a | 504 | L6470_GoMark(); |
Davidroid | 0:92706998571a | 505 | } |
Davidroid | 0:92706998571a | 506 | |
Davidroid | 1:b78dab6d2c58 | 507 | /** |
Davidroid | 1:b78dab6d2c58 | 508 | * @brief Running at the given speed imposing the desired direction until |
Davidroid | 1:b78dab6d2c58 | 509 | * an external switch turn-on event occurs. |
Davidroid | 1:b78dab6d2c58 | 510 | * @param action The identifier of the action about the absolute position. |
Davidroid | 1:b78dab6d2c58 | 511 | * @param position The desired position. |
Davidroid | 1:b78dab6d2c58 | 512 | * @param speed The speed value in pps. |
Davidroid | 1:b78dab6d2c58 | 513 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 514 | * @note The identifier of the action about the absolute position can be |
Davidroid | 1:b78dab6d2c58 | 515 | * one of the following: |
Davidroid | 1:b78dab6d2c58 | 516 | * + L6470_ACT_RST_ID: the absolute position is reset; |
Davidroid | 1:b78dab6d2c58 | 517 | * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. |
Davidroid | 1:b78dab6d2c58 | 518 | */ |
Davidroid | 1:b78dab6d2c58 | 519 | virtual void GoUntil(eL6470_ActId_t action, direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 520 | { |
Davidroid | 1:b78dab6d2c58 | 521 | 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)); |
Davidroid | 0:92706998571a | 522 | } |
Davidroid | 0:92706998571a | 523 | |
Davidroid | 1:b78dab6d2c58 | 524 | /** |
Davidroid | 1:b78dab6d2c58 | 525 | * @brief Running towards a specified direction. |
Davidroid | 1:b78dab6d2c58 | 526 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 527 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 528 | */ |
Davidroid | 0:92706998571a | 529 | virtual void Run(direction_t direction) |
Davidroid | 0:92706998571a | 530 | { |
Davidroid | 0:92706998571a | 531 | 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)); |
Davidroid | 0:92706998571a | 532 | } |
Davidroid | 0:92706998571a | 533 | |
Davidroid | 1:b78dab6d2c58 | 534 | /** |
Davidroid | 1:b78dab6d2c58 | 535 | * @brief Running towards a specified direction at the given speed. |
Davidroid | 1:b78dab6d2c58 | 536 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 537 | * @param speed The speed value in pps. |
Davidroid | 1:b78dab6d2c58 | 538 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 539 | */ |
Davidroid | 0:92706998571a | 540 | virtual void Run(direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 541 | { |
Davidroid | 1:b78dab6d2c58 | 542 | 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)); |
Davidroid | 0:92706998571a | 543 | } |
Davidroid | 0:92706998571a | 544 | |
Davidroid | 1:b78dab6d2c58 | 545 | /** |
Davidroid | 1:b78dab6d2c58 | 546 | * @brief Moving towards a specified direction for a certain number of steps. |
Davidroid | 1:b78dab6d2c58 | 547 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 548 | * @param steps The desired number of steps. |
Davidroid | 1:b78dab6d2c58 | 549 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 550 | */ |
Davidroid | 0:92706998571a | 551 | virtual void Move(direction_t direction, unsigned int steps) |
Davidroid | 0:92706998571a | 552 | { |
Davidroid | 0:92706998571a | 553 | L6470_Move((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps); |
Davidroid | 0:92706998571a | 554 | } |
Davidroid | 0:92706998571a | 555 | |
Davidroid | 1:b78dab6d2c58 | 556 | /** |
Davidroid | 1:b78dab6d2c58 | 557 | * @brief Stopping the motor through an immediate deceleration up to zero speed. |
Davidroid | 1:b78dab6d2c58 | 558 | * The used deceleration value is the one stored in the "DEC" register. |
Davidroid | 1:b78dab6d2c58 | 559 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 560 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 561 | */ |
Davidroid | 0:92706998571a | 562 | virtual void SoftStop(void) |
Davidroid | 0:92706998571a | 563 | { |
Davidroid | 0:92706998571a | 564 | L6470_SoftStop(); |
Davidroid | 0:92706998571a | 565 | } |
Davidroid | 0:92706998571a | 566 | |
Davidroid | 1:b78dab6d2c58 | 567 | /** |
Davidroid | 1:b78dab6d2c58 | 568 | * @brief Stopping the motor through an immediate infinite deceleration. |
Davidroid | 1:b78dab6d2c58 | 569 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 570 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 571 | */ |
Davidroid | 0:92706998571a | 572 | virtual void HardStop(void) |
Davidroid | 0:92706998571a | 573 | { |
Davidroid | 0:92706998571a | 574 | L6470_HardStop(); |
Davidroid | 0:92706998571a | 575 | } |
Davidroid | 0:92706998571a | 576 | |
Davidroid | 1:b78dab6d2c58 | 577 | /** |
Davidroid | 1:b78dab6d2c58 | 578 | * @brief Disabling the power bridge after performing a deceleration to zero. |
Davidroid | 1:b78dab6d2c58 | 579 | * The used deceleration value is the one stored in the "DEC" register. |
Davidroid | 1:b78dab6d2c58 | 580 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 581 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 582 | */ |
Davidroid | 1:b78dab6d2c58 | 583 | virtual void SoftHiZ(void) |
Davidroid | 1:b78dab6d2c58 | 584 | { |
Davidroid | 1:b78dab6d2c58 | 585 | L6470_SoftHiZ(); |
Davidroid | 1:b78dab6d2c58 | 586 | } |
Davidroid | 1:b78dab6d2c58 | 587 | |
Davidroid | 1:b78dab6d2c58 | 588 | /** |
Davidroid | 1:b78dab6d2c58 | 589 | * @brief Disabling the power bridge immediately. |
Davidroid | 1:b78dab6d2c58 | 590 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 591 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 592 | */ |
Davidroid | 1:b78dab6d2c58 | 593 | virtual void HardHiZ(void) |
Davidroid | 1:b78dab6d2c58 | 594 | { |
Davidroid | 1:b78dab6d2c58 | 595 | L6470_HardHiZ(); |
Davidroid | 1:b78dab6d2c58 | 596 | } |
Davidroid | 1:b78dab6d2c58 | 597 | |
Davidroid | 1:b78dab6d2c58 | 598 | /** |
Davidroid | 1:b78dab6d2c58 | 599 | * @brief Waiting while the motor is active. |
Davidroid | 1:b78dab6d2c58 | 600 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 601 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 602 | */ |
Davidroid | 0:92706998571a | 603 | virtual void WaitWhileActive(void) |
Davidroid | 0:92706998571a | 604 | { |
Davidroid | 0:92706998571a | 605 | while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0); |
Davidroid | 0:92706998571a | 606 | } |
Davidroid | 0:92706998571a | 607 | |
Davidroid | 1:b78dab6d2c58 | 608 | /** |
Davidroid | 17:4b3dc908724f | 609 | * @brief Switching to step-clock mode. |
Davidroid | 17:4b3dc908724f | 610 | * @param direction The direction of rotation. |
Davidroid | 17:4b3dc908724f | 611 | * @retval None. |
Davidroid | 17:4b3dc908724f | 612 | * @warning Setting the step-clock mode implies first disabling the power bridge through |
Davidroid | 17:4b3dc908724f | 613 | * the SoftHiZ() method. |
Davidroid | 17:4b3dc908724f | 614 | */ |
Davidroid | 0:92706998571a | 615 | virtual void StepClock(direction_t direction) |
Davidroid | 0:92706998571a | 616 | { |
Davidroid | 17:4b3dc908724f | 617 | SoftHiZ(); |
Davidroid | 0:92706998571a | 618 | L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 0:92706998571a | 619 | } |
Davidroid | 0:92706998571a | 620 | |
Davidroid | 1:b78dab6d2c58 | 621 | /** |
Davidroid | 1:b78dab6d2c58 | 622 | * @brief Doing a motion at minimum speed imposing a specified direction |
Davidroid | 1:b78dab6d2c58 | 623 | * until the SW is released. |
Davidroid | 1:b78dab6d2c58 | 624 | * @param action The identifier of the action about the absolute position. |
Davidroid | 1:b78dab6d2c58 | 625 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 626 | * @note The identifier of the action about the absolute position can be |
Davidroid | 1:b78dab6d2c58 | 627 | * one of the following: |
Davidroid | 1:b78dab6d2c58 | 628 | * + L6470_ACT_RST_ID: the absolute position is reset; |
Davidroid | 1:b78dab6d2c58 | 629 | * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. |
Davidroid | 1:b78dab6d2c58 | 630 | */ |
Davidroid | 1:b78dab6d2c58 | 631 | virtual void ReleaseSW(eL6470_ActId_t action, direction_t direction) |
Davidroid | 0:92706998571a | 632 | { |
Davidroid | 1:b78dab6d2c58 | 633 | L6470_ReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 0:92706998571a | 634 | } |
Davidroid | 0:92706998571a | 635 | |
Davidroid | 1:b78dab6d2c58 | 636 | /** |
Davidroid | 1:b78dab6d2c58 | 637 | * @brief Resetting the device to power-up conditions. |
Davidroid | 1:b78dab6d2c58 | 638 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 639 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 640 | */ |
Davidroid | 0:92706998571a | 641 | virtual void ResetDevice(void) |
Davidroid | 0:92706998571a | 642 | { |
Davidroid | 0:92706998571a | 643 | L6470_ResetDevice(); |
Davidroid | 0:92706998571a | 644 | } |
Davidroid | 0:92706998571a | 645 | |
Davidroid | 1:b78dab6d2c58 | 646 | /** |
Davidroid | 1:b78dab6d2c58 | 647 | * @brief Preparing the command to get the status. |
Davidroid | 1:b78dab6d2c58 | 648 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 649 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 650 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 651 | */ |
Davidroid | 0:92706998571a | 652 | virtual void PrepareGetStatus(void) |
Davidroid | 0:92706998571a | 653 | { |
Davidroid | 0:92706998571a | 654 | L6470_PrepareGetStatus(); |
Davidroid | 1:b78dab6d2c58 | 655 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 656 | } |
Davidroid | 0:92706998571a | 657 | |
Davidroid | 17:4b3dc908724f | 658 | /** |
Davidroid | 1:b78dab6d2c58 | 659 | * @brief Preparing the command to get a parameter. |
Davidroid | 17:4b3dc908724f | 660 | * @param parameter A parameter's register address. |
Davidroid | 1:b78dab6d2c58 | 661 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 662 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 17:4b3dc908724f | 663 | * The parameter can be one of the following: |
Davidroid | 17:4b3dc908724f | 664 | * + L6470_ABS_POS_ID |
Davidroid | 17:4b3dc908724f | 665 | * + L6470_EL_POS_ID |
Davidroid | 17:4b3dc908724f | 666 | * + L6470_MARK_ID |
Davidroid | 17:4b3dc908724f | 667 | * + L6470_SPEED_ID |
Davidroid | 17:4b3dc908724f | 668 | * + L6470_ACC_ID |
Davidroid | 17:4b3dc908724f | 669 | * + L6470_DEC_ID |
Davidroid | 17:4b3dc908724f | 670 | * + L6470_MAX_SPEED_ID |
Davidroid | 17:4b3dc908724f | 671 | * + L6470_MIN_SPEED_ID |
Davidroid | 17:4b3dc908724f | 672 | * + L6470_FS_SPD_ID |
Davidroid | 17:4b3dc908724f | 673 | * + L6470_KVAL_HOLD_ID |
Davidroid | 17:4b3dc908724f | 674 | * + L6470_KVAL_RUN_ID |
Davidroid | 17:4b3dc908724f | 675 | * + L6470_KVAL_ACC_ID |
Davidroid | 17:4b3dc908724f | 676 | * + L6470_KVAL_DEC_ID |
Davidroid | 17:4b3dc908724f | 677 | * + L6470_INT_SPEED_ID |
Davidroid | 17:4b3dc908724f | 678 | * + L6470_ST_SLP_ID |
Davidroid | 17:4b3dc908724f | 679 | * + L6470_FN_SLP_ACC_ID |
Davidroid | 17:4b3dc908724f | 680 | * + L6470_FN_SLP_DEC_ID |
Davidroid | 17:4b3dc908724f | 681 | * + L6470_K_THERM_ID |
Davidroid | 17:4b3dc908724f | 682 | * + L6470_ADC_OUT_ID |
Davidroid | 17:4b3dc908724f | 683 | * + L6470_OCD_TH_ID |
Davidroid | 17:4b3dc908724f | 684 | * + L6470_STALL_TH_ID |
Davidroid | 17:4b3dc908724f | 685 | * + L6470_STEP_MODE_ID |
Davidroid | 17:4b3dc908724f | 686 | * + L6470_ALARM_EN_ID |
Davidroid | 17:4b3dc908724f | 687 | * + L6470_CONFIG_ID |
Davidroid | 17:4b3dc908724f | 688 | * + L6470_STATUS_ID |
Davidroid | 1:b78dab6d2c58 | 689 | */ |
Davidroid | 0:92706998571a | 690 | virtual void PrepareGetParameter(unsigned int parameter) |
Davidroid | 0:92706998571a | 691 | { |
Davidroid | 0:92706998571a | 692 | L6470_PrepareGetParam((eL6470_RegId_t) parameter); |
Davidroid | 1:b78dab6d2c58 | 693 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 694 | } |
Davidroid | 0:92706998571a | 695 | |
Davidroid | 1:b78dab6d2c58 | 696 | /** |
Davidroid | 1:b78dab6d2c58 | 697 | * @brief Preparing the command to get the position. |
Davidroid | 1:b78dab6d2c58 | 698 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 699 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 700 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 701 | */ |
Davidroid | 0:92706998571a | 702 | virtual void PrepareGetPosition(void) |
Davidroid | 0:92706998571a | 703 | { |
Davidroid | 0:92706998571a | 704 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID); |
Davidroid | 1:b78dab6d2c58 | 705 | prepared_action = PREPARED_GET_POSITION; |
Davidroid | 0:92706998571a | 706 | } |
Davidroid | 0:92706998571a | 707 | |
Davidroid | 1:b78dab6d2c58 | 708 | /** |
Davidroid | 1:b78dab6d2c58 | 709 | * @brief Preparing the command to get the marked position. |
Davidroid | 1:b78dab6d2c58 | 710 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 711 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 712 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 713 | */ |
Davidroid | 0:92706998571a | 714 | virtual void PrepareGetMark(void) |
Davidroid | 0:92706998571a | 715 | { |
Davidroid | 0:92706998571a | 716 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID); |
Davidroid | 1:b78dab6d2c58 | 717 | prepared_action = PREPARED_GET_MARK; |
Davidroid | 0:92706998571a | 718 | } |
Davidroid | 0:92706998571a | 719 | |
Davidroid | 1:b78dab6d2c58 | 720 | /** |
Davidroid | 1:b78dab6d2c58 | 721 | * @brief Preparing the command to get the current speed in pps. |
Davidroid | 1:b78dab6d2c58 | 722 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 723 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 724 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 725 | */ |
Davidroid | 0:92706998571a | 726 | virtual void PrepareGetSpeed(void) |
Davidroid | 0:92706998571a | 727 | { |
Davidroid | 1:b78dab6d2c58 | 728 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_SPEED_ID); |
Davidroid | 1:b78dab6d2c58 | 729 | prepared_action = PREPARED_GET_SPEED; |
Davidroid | 0:92706998571a | 730 | } |
Davidroid | 0:92706998571a | 731 | |
Davidroid | 1:b78dab6d2c58 | 732 | /** |
Davidroid | 1:b78dab6d2c58 | 733 | * @brief Preparing the command to get the maximum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 734 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 735 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 736 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 737 | */ |
Davidroid | 0:92706998571a | 738 | virtual void PrepareGetMaxSpeed(void) |
Davidroid | 0:92706998571a | 739 | { |
Davidroid | 0:92706998571a | 740 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID); |
Davidroid | 1:b78dab6d2c58 | 741 | prepared_action = PREPARED_GET_MAX_SPEED; |
Davidroid | 0:92706998571a | 742 | } |
Davidroid | 0:92706998571a | 743 | |
Davidroid | 1:b78dab6d2c58 | 744 | /** |
Davidroid | 1:b78dab6d2c58 | 745 | * @brief Preparing the command to get the minimum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 746 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 747 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 748 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 749 | */ |
Davidroid | 0:92706998571a | 750 | virtual void PrepareGetMinSpeed(void) |
Davidroid | 0:92706998571a | 751 | { |
Davidroid | 0:92706998571a | 752 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID); |
Davidroid | 1:b78dab6d2c58 | 753 | prepared_action = PREPARED_GET_MIN_SPEED; |
Davidroid | 0:92706998571a | 754 | } |
Davidroid | 0:92706998571a | 755 | |
Davidroid | 1:b78dab6d2c58 | 756 | /** |
Davidroid | 1:b78dab6d2c58 | 757 | * @brief Preparing the command to get the acceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 758 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 759 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 760 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 761 | */ |
Davidroid | 0:92706998571a | 762 | virtual void PrepareGetAcceleration(void) |
Davidroid | 0:92706998571a | 763 | { |
Davidroid | 0:92706998571a | 764 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID); |
Davidroid | 1:b78dab6d2c58 | 765 | prepared_action = PREPARED_GET_ACCELERATION; |
Davidroid | 0:92706998571a | 766 | } |
Davidroid | 0:92706998571a | 767 | |
Davidroid | 1:b78dab6d2c58 | 768 | /** |
Davidroid | 1:b78dab6d2c58 | 769 | * @brief Preparing the command to get the deceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 770 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 771 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 772 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 773 | */ |
Davidroid | 0:92706998571a | 774 | virtual void PrepareGetDeceleration(void) |
Davidroid | 0:92706998571a | 775 | { |
Davidroid | 0:92706998571a | 776 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID); |
Davidroid | 1:b78dab6d2c58 | 777 | prepared_action = PREPARED_GET_DECELERATION; |
Davidroid | 0:92706998571a | 778 | } |
Davidroid | 0:92706998571a | 779 | |
Davidroid | 1:b78dab6d2c58 | 780 | /** |
Davidroid | 1:b78dab6d2c58 | 781 | * @brief Preparing the command to get the direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 782 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 783 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 784 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 785 | */ |
Davidroid | 1:b78dab6d2c58 | 786 | virtual void PrepareGetDirection(void) |
Davidroid | 0:92706998571a | 787 | { |
Davidroid | 1:b78dab6d2c58 | 788 | if (!L6470_DaisyChain_HalfPrepared) |
Davidroid | 1:b78dab6d2c58 | 789 | { |
Davidroid | 1:b78dab6d2c58 | 790 | /* To avoid deleting the previous entered command. */ |
Davidroid | 1:b78dab6d2c58 | 791 | L6470_DaisyChain_HalfPrepared = ONE_F; |
Davidroid | 1:b78dab6d2c58 | 792 | /* Resetting commands. */ |
Davidroid | 1:b78dab6d2c58 | 793 | L6470_ResetAppCmdPkg(L6470_AppCmdPkg); |
Davidroid | 1:b78dab6d2c58 | 794 | } |
Davidroid | 1:b78dab6d2c58 | 795 | prepared_action = PREPARED_GET_DIRECTION; |
Davidroid | 0:92706998571a | 796 | } |
Davidroid | 0:92706998571a | 797 | |
Davidroid | 1:b78dab6d2c58 | 798 | /** |
Davidroid | 1:b78dab6d2c58 | 799 | * @brief Preparing the command to set a parameter. |
Davidroid | 17:4b3dc908724f | 800 | * @param parameter A parameter's register address. |
Davidroid | 1:b78dab6d2c58 | 801 | * @param value The parameter's value. |
Davidroid | 1:b78dab6d2c58 | 802 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 803 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 17:4b3dc908724f | 804 | * The parameter can be one of the following: |
Davidroid | 17:4b3dc908724f | 805 | * + L6470_ABS_POS_ID |
Davidroid | 17:4b3dc908724f | 806 | * + L6470_EL_POS_ID |
Davidroid | 17:4b3dc908724f | 807 | * + L6470_MARK_ID |
Davidroid | 17:4b3dc908724f | 808 | * + L6470_SPEED_ID |
Davidroid | 17:4b3dc908724f | 809 | * + L6470_ACC_ID |
Davidroid | 17:4b3dc908724f | 810 | * + L6470_DEC_ID |
Davidroid | 17:4b3dc908724f | 811 | * + L6470_MAX_SPEED_ID |
Davidroid | 17:4b3dc908724f | 812 | * + L6470_MIN_SPEED_ID |
Davidroid | 17:4b3dc908724f | 813 | * + L6470_FS_SPD_ID |
Davidroid | 17:4b3dc908724f | 814 | * + L6470_KVAL_HOLD_ID |
Davidroid | 17:4b3dc908724f | 815 | * + L6470_KVAL_RUN_ID |
Davidroid | 17:4b3dc908724f | 816 | * + L6470_KVAL_ACC_ID |
Davidroid | 17:4b3dc908724f | 817 | * + L6470_KVAL_DEC_ID |
Davidroid | 17:4b3dc908724f | 818 | * + L6470_INT_SPEED_ID |
Davidroid | 17:4b3dc908724f | 819 | * + L6470_ST_SLP_ID |
Davidroid | 17:4b3dc908724f | 820 | * + L6470_FN_SLP_ACC_ID |
Davidroid | 17:4b3dc908724f | 821 | * + L6470_FN_SLP_DEC_ID |
Davidroid | 17:4b3dc908724f | 822 | * + L6470_K_THERM_ID |
Davidroid | 17:4b3dc908724f | 823 | * + L6470_ADC_OUT_ID |
Davidroid | 17:4b3dc908724f | 824 | * + L6470_OCD_TH_ID |
Davidroid | 17:4b3dc908724f | 825 | * + L6470_STALL_TH_ID |
Davidroid | 17:4b3dc908724f | 826 | * + L6470_STEP_MODE_ID |
Davidroid | 17:4b3dc908724f | 827 | * + L6470_ALARM_EN_ID |
Davidroid | 17:4b3dc908724f | 828 | * + L6470_CONFIG_ID |
Davidroid | 17:4b3dc908724f | 829 | * + L6470_STATUS_ID |
Davidroid | 17:4b3dc908724f | 830 | * @warning Some registers can only be written in particular conditions (see L6470's datasheet). |
Davidroid | 17:4b3dc908724f | 831 | * Any attempt to write one of those registers when the conditions are not satisfied |
Davidroid | 17:4b3dc908724f | 832 | * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the |
Davidroid | 17:4b3dc908724f | 833 | * last argument byte. Any attempt to set an inexistent register (wrong address value) |
Davidroid | 17:4b3dc908724f | 834 | * causes the command to be ignored and the WRONG_CMD flag to rise. |
Davidroid | 17:4b3dc908724f | 835 | * For example, setting some parameters requires first to disable the power bridge; |
Davidroid | 17:4b3dc908724f | 836 | * this can be done through the SoftHiZ() method. |
Davidroid | 17:4b3dc908724f | 837 | * They are the following: |
Davidroid | 17:4b3dc908724f | 838 | * + L6470_ABS_POS_ID |
Davidroid | 17:4b3dc908724f | 839 | * + L6470_EL_POS_ID |
Davidroid | 17:4b3dc908724f | 840 | * + L6470_SPEED_ID |
Davidroid | 17:4b3dc908724f | 841 | * + L6470_ACC_ID |
Davidroid | 17:4b3dc908724f | 842 | * + L6470_DEC_ID |
Davidroid | 17:4b3dc908724f | 843 | * + L6470_MAX_SPEED_ID |
Davidroid | 17:4b3dc908724f | 844 | * + L6470_MIN_SPEED_ID |
Davidroid | 17:4b3dc908724f | 845 | * + L6470_INT_SPEED_ID |
Davidroid | 17:4b3dc908724f | 846 | * + L6470_ST_SLP_ID |
Davidroid | 17:4b3dc908724f | 847 | * + L6470_FN_SLP_ACC_ID |
Davidroid | 17:4b3dc908724f | 848 | * + L6470_FN_SLP_DEC_ID |
Davidroid | 17:4b3dc908724f | 849 | * + L6470_ADC_OUT_ID |
Davidroid | 17:4b3dc908724f | 850 | * + L6470_STEP_MODE_ID |
Davidroid | 17:4b3dc908724f | 851 | * + L6470_CONFIG_ID |
Davidroid | 17:4b3dc908724f | 852 | * + L6470_STATUS_ID |
Davidroid | 1:b78dab6d2c58 | 853 | */ |
Davidroid | 0:92706998571a | 854 | virtual void PrepareSetParameter(unsigned int parameter, unsigned int value) |
Davidroid | 0:92706998571a | 855 | { |
Davidroid | 0:92706998571a | 856 | L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value); |
Davidroid | 1:b78dab6d2c58 | 857 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 858 | } |
Davidroid | 0:92706998571a | 859 | |
Davidroid | 1:b78dab6d2c58 | 860 | /** |
Davidroid | 1:b78dab6d2c58 | 861 | * @brief Preparing the command to set the current position to be |
Davidroid | 1:b78dab6d2c58 | 862 | * the home position. |
Davidroid | 1:b78dab6d2c58 | 863 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 864 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 865 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 866 | */ |
Davidroid | 0:92706998571a | 867 | virtual void PrepareSetHome(void) |
Davidroid | 0:92706998571a | 868 | { |
Davidroid | 0:92706998571a | 869 | L6470_PrepareResetPos(); |
Davidroid | 1:b78dab6d2c58 | 870 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 871 | } |
Davidroid | 0:92706998571a | 872 | |
Davidroid | 1:b78dab6d2c58 | 873 | /** |
Davidroid | 1:b78dab6d2c58 | 874 | * @brief Preparing the command to set the current position to be |
Davidroid | 1:b78dab6d2c58 | 875 | * the marked position. |
Davidroid | 1:b78dab6d2c58 | 876 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 877 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 878 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 879 | */ |
Davidroid | 0:92706998571a | 880 | virtual void PrepareSetMark(void) |
Davidroid | 0:92706998571a | 881 | { |
Davidroid | 1:b78dab6d2c58 | 882 | /* |
Davidroid | 1:b78dab6d2c58 | 883 | Set "0" now as marked position. This value will be replaced by the |
Davidroid | 1:b78dab6d2c58 | 884 | actual position read at the time when the prepared actions will be |
Davidroid | 1:b78dab6d2c58 | 885 | performed. |
Davidroid | 1:b78dab6d2c58 | 886 | */ |
Davidroid | 1:b78dab6d2c58 | 887 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0); |
Davidroid | 1:b78dab6d2c58 | 888 | prepared_action = PREPARED_SET_MARK; |
Davidroid | 0:92706998571a | 889 | } |
Davidroid | 0:92706998571a | 890 | |
Davidroid | 1:b78dab6d2c58 | 891 | /** |
Davidroid | 1:b78dab6d2c58 | 892 | * @brief Preparing the command to set the given position to be |
Davidroid | 1:b78dab6d2c58 | 893 | * the marked position. |
Davidroid | 1:b78dab6d2c58 | 894 | * @param position The given position. |
Davidroid | 1:b78dab6d2c58 | 895 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 896 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 897 | */ |
Davidroid | 1:b78dab6d2c58 | 898 | virtual void PrepareSetMark(signed int position) |
Davidroid | 1:b78dab6d2c58 | 899 | { |
Davidroid | 1:b78dab6d2c58 | 900 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position)); |
Davidroid | 1:b78dab6d2c58 | 901 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 1:b78dab6d2c58 | 902 | } |
Davidroid | 1:b78dab6d2c58 | 903 | |
Davidroid | 1:b78dab6d2c58 | 904 | /** |
Davidroid | 1:b78dab6d2c58 | 905 | * @brief Preparing the command to set the current speed in pps. |
Davidroid | 1:b78dab6d2c58 | 906 | * @param speed The current speed in pps. |
Davidroid | 1:b78dab6d2c58 | 907 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 908 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 909 | */ |
Davidroid | 1:b78dab6d2c58 | 910 | virtual void PrepareSetSpeed(unsigned int speed) |
Davidroid | 1:b78dab6d2c58 | 911 | { |
Davidroid | 1:b78dab6d2c58 | 912 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed)); |
Davidroid | 1:b78dab6d2c58 | 913 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 1:b78dab6d2c58 | 914 | } |
Davidroid | 1:b78dab6d2c58 | 915 | |
Davidroid | 1:b78dab6d2c58 | 916 | /** |
Davidroid | 1:b78dab6d2c58 | 917 | * @brief Preparing the command to set the maximum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 918 | * @param speed The maximum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 919 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 920 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 921 | */ |
Davidroid | 0:92706998571a | 922 | virtual void PrepareSetMaxSpeed(unsigned int speed) |
Davidroid | 0:92706998571a | 923 | { |
Davidroid | 1:b78dab6d2c58 | 924 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed)); |
Davidroid | 1:b78dab6d2c58 | 925 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 926 | } |
Davidroid | 0:92706998571a | 927 | |
Davidroid | 1:b78dab6d2c58 | 928 | /** |
Davidroid | 1:b78dab6d2c58 | 929 | * @brief Preparing the command to set the minimum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 930 | * @param speed The minimum speed in pps. |
Davidroid | 1:b78dab6d2c58 | 931 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 932 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 933 | */ |
Davidroid | 1:b78dab6d2c58 | 934 | virtual void PrepareSetMinSpeed(unsigned int speed) |
Davidroid | 1:b78dab6d2c58 | 935 | { |
Davidroid | 1:b78dab6d2c58 | 936 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed)); |
Davidroid | 1:b78dab6d2c58 | 937 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 1:b78dab6d2c58 | 938 | } |
Davidroid | 1:b78dab6d2c58 | 939 | |
Davidroid | 1:b78dab6d2c58 | 940 | /** |
Davidroid | 1:b78dab6d2c58 | 941 | * @brief Preparing the command to set the acceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 942 | * @param acceleration The acceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 943 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 944 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 945 | */ |
Davidroid | 0:92706998571a | 946 | virtual void PrepareSetAcceleration(unsigned int acceleration) |
Davidroid | 0:92706998571a | 947 | { |
Davidroid | 1:b78dab6d2c58 | 948 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration)); |
Davidroid | 1:b78dab6d2c58 | 949 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 950 | } |
Davidroid | 0:92706998571a | 951 | |
Davidroid | 1:b78dab6d2c58 | 952 | /** |
Davidroid | 1:b78dab6d2c58 | 953 | * @brief Preparing the command to set the deceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 954 | * @param deceleration The deceleration in pps^2. |
Davidroid | 1:b78dab6d2c58 | 955 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 956 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 957 | */ |
Davidroid | 1:b78dab6d2c58 | 958 | virtual void PrepareSetDeceleration(unsigned int deceleration) |
Davidroid | 0:92706998571a | 959 | { |
Davidroid | 1:b78dab6d2c58 | 960 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration)); |
Davidroid | 1:b78dab6d2c58 | 961 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 962 | } |
Davidroid | 0:92706998571a | 963 | |
Davidroid | 1:b78dab6d2c58 | 964 | /** |
Davidroid | 1:b78dab6d2c58 | 965 | * @brief Preparing the command to go to a specified position. |
Davidroid | 1:b78dab6d2c58 | 966 | * @param position The desired position. |
Davidroid | 1:b78dab6d2c58 | 967 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 968 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 969 | */ |
Davidroid | 1:b78dab6d2c58 | 970 | virtual void PrepareGoTo(signed int position) |
Davidroid | 1:b78dab6d2c58 | 971 | { |
Davidroid | 1:b78dab6d2c58 | 972 | L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position)); |
Davidroid | 1:b78dab6d2c58 | 973 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 1:b78dab6d2c58 | 974 | } |
Davidroid | 1:b78dab6d2c58 | 975 | |
Davidroid | 1:b78dab6d2c58 | 976 | /** |
Davidroid | 1:b78dab6d2c58 | 977 | * @brief Preparing the command to go to a specified position |
Davidroid | 1:b78dab6d2c58 | 978 | * imposing the desired direction. |
Davidroid | 1:b78dab6d2c58 | 979 | * @param position The desired position. |
Davidroid | 1:b78dab6d2c58 | 980 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 981 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 982 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 983 | */ |
Davidroid | 0:92706998571a | 984 | virtual void PrepareGoTo(signed int position, direction_t direction) |
Davidroid | 0:92706998571a | 985 | { |
Davidroid | 1:b78dab6d2c58 | 986 | 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)); |
Davidroid | 1:b78dab6d2c58 | 987 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 988 | } |
Davidroid | 0:92706998571a | 989 | |
Davidroid | 1:b78dab6d2c58 | 990 | /** |
Davidroid | 1:b78dab6d2c58 | 991 | * @brief Preparing the command to go to the home position. |
Davidroid | 1:b78dab6d2c58 | 992 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 993 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 994 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 995 | */ |
Davidroid | 0:92706998571a | 996 | virtual void PrepareGoHome(void) |
Davidroid | 0:92706998571a | 997 | { |
Davidroid | 0:92706998571a | 998 | L6470_PrepareGoHome(); |
Davidroid | 1:b78dab6d2c58 | 999 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1000 | } |
Davidroid | 0:92706998571a | 1001 | |
Davidroid | 1:b78dab6d2c58 | 1002 | /** |
Davidroid | 1:b78dab6d2c58 | 1003 | * @brief Preparing the command to go to the marked position. |
Davidroid | 1:b78dab6d2c58 | 1004 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1005 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1006 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1007 | */ |
Davidroid | 0:92706998571a | 1008 | virtual void PrepareGoMark(void) |
Davidroid | 0:92706998571a | 1009 | { |
Davidroid | 0:92706998571a | 1010 | L6470_PrepareGoMark(); |
Davidroid | 1:b78dab6d2c58 | 1011 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1012 | } |
Davidroid | 0:92706998571a | 1013 | |
Davidroid | 1:b78dab6d2c58 | 1014 | /** |
Davidroid | 1:b78dab6d2c58 | 1015 | * @brief Preparing the command to run at the given speed imposing the desired |
Davidroid | 1:b78dab6d2c58 | 1016 | * direction until an external switch turn-on event occurs. |
Davidroid | 1:b78dab6d2c58 | 1017 | * @param action The identifier of the action about the absolute position. |
Davidroid | 1:b78dab6d2c58 | 1018 | * @param position The desired position. |
Davidroid | 1:b78dab6d2c58 | 1019 | * @param speed The speed value in pps. |
Davidroid | 1:b78dab6d2c58 | 1020 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1021 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1022 | * The identifier of the action about the absolute position can be |
Davidroid | 1:b78dab6d2c58 | 1023 | * one of the following: |
Davidroid | 1:b78dab6d2c58 | 1024 | * + L6470_ACT_RST_ID: the absolute position is reset; |
Davidroid | 1:b78dab6d2c58 | 1025 | * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. |
Davidroid | 1:b78dab6d2c58 | 1026 | */ |
Davidroid | 0:92706998571a | 1027 | virtual void PrepareGoUntil(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 1028 | { |
Davidroid | 1:b78dab6d2c58 | 1029 | 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)); |
Davidroid | 1:b78dab6d2c58 | 1030 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1031 | } |
Davidroid | 0:92706998571a | 1032 | |
Davidroid | 1:b78dab6d2c58 | 1033 | /** |
Davidroid | 1:b78dab6d2c58 | 1034 | * @brief Preparing the command to run towards a specified direction |
Davidroid | 1:b78dab6d2c58 | 1035 | * at the maximum speed. |
Davidroid | 1:b78dab6d2c58 | 1036 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 1037 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1038 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1039 | */ |
Davidroid | 0:92706998571a | 1040 | virtual void PrepareRun(direction_t direction) |
Davidroid | 0:92706998571a | 1041 | { |
Davidroid | 0:92706998571a | 1042 | 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)); |
Davidroid | 1:b78dab6d2c58 | 1043 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1044 | } |
Davidroid | 0:92706998571a | 1045 | |
Davidroid | 1:b78dab6d2c58 | 1046 | /** |
Davidroid | 1:b78dab6d2c58 | 1047 | * @brief Preparing the command to run towards a specified direction |
Davidroid | 1:b78dab6d2c58 | 1048 | * at the given speed. |
Davidroid | 1:b78dab6d2c58 | 1049 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 1050 | * @param speed The speed value in pps. |
Davidroid | 1:b78dab6d2c58 | 1051 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1052 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1053 | */ |
Davidroid | 0:92706998571a | 1054 | virtual void PrepareRun(direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 1055 | { |
Davidroid | 1:b78dab6d2c58 | 1056 | 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)); |
Davidroid | 1:b78dab6d2c58 | 1057 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1058 | } |
Davidroid | 0:92706998571a | 1059 | |
Davidroid | 1:b78dab6d2c58 | 1060 | /** |
Davidroid | 1:b78dab6d2c58 | 1061 | * @brief Preparing the command to move towards a specified direction |
Davidroid | 1:b78dab6d2c58 | 1062 | * for a certain number of steps. |
Davidroid | 1:b78dab6d2c58 | 1063 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 1064 | * @param steps The desired number of steps. |
Davidroid | 1:b78dab6d2c58 | 1065 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1066 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1067 | */ |
Davidroid | 0:92706998571a | 1068 | virtual void PrepareMove(direction_t direction, unsigned int steps) |
Davidroid | 0:92706998571a | 1069 | { |
Davidroid | 0:92706998571a | 1070 | L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps); |
Davidroid | 1:b78dab6d2c58 | 1071 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1072 | } |
Davidroid | 0:92706998571a | 1073 | |
Davidroid | 1:b78dab6d2c58 | 1074 | /** |
Davidroid | 1:b78dab6d2c58 | 1075 | * @brief Preparing the command to stop the motor. |
Davidroid | 1:b78dab6d2c58 | 1076 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1077 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1078 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1079 | */ |
Davidroid | 0:92706998571a | 1080 | virtual void PrepareSoftStop(void) |
Davidroid | 0:92706998571a | 1081 | { |
Davidroid | 0:92706998571a | 1082 | L6470_PrepareSoftStop(); |
Davidroid | 1:b78dab6d2c58 | 1083 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1084 | } |
Davidroid | 0:92706998571a | 1085 | |
Davidroid | 1:b78dab6d2c58 | 1086 | /** |
Davidroid | 1:b78dab6d2c58 | 1087 | * @brief Preparing the command to stop the motor and disabling the power bridge. |
Davidroid | 1:b78dab6d2c58 | 1088 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1089 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1090 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1091 | */ |
Davidroid | 0:92706998571a | 1092 | virtual void PrepareHardStop(void) |
Davidroid | 0:92706998571a | 1093 | { |
Davidroid | 0:92706998571a | 1094 | L6470_PrepareHardStop(); |
Davidroid | 1:b78dab6d2c58 | 1095 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1096 | } |
Davidroid | 0:92706998571a | 1097 | |
Davidroid | 1:b78dab6d2c58 | 1098 | /** |
Davidroid | 1:b78dab6d2c58 | 1099 | * @brief Preparing the command to disable the power bridge after performing |
Davidroid | 1:b78dab6d2c58 | 1100 | * a deceleration to zero. |
Davidroid | 1:b78dab6d2c58 | 1101 | * The used deceleration value is the one stored in the "DEC" register. |
Davidroid | 1:b78dab6d2c58 | 1102 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1103 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1104 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1105 | */ |
Davidroid | 0:92706998571a | 1106 | virtual void PrepareSoftHiZ(void) |
Davidroid | 0:92706998571a | 1107 | { |
Davidroid | 0:92706998571a | 1108 | L6470_PrepareSoftHiZ(); |
Davidroid | 1:b78dab6d2c58 | 1109 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1110 | } |
Davidroid | 0:92706998571a | 1111 | |
Davidroid | 1:b78dab6d2c58 | 1112 | /** |
Davidroid | 1:b78dab6d2c58 | 1113 | * @brief Preparing the command to disable the power bridge immediately. |
Davidroid | 1:b78dab6d2c58 | 1114 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1115 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1116 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1117 | */ |
Davidroid | 0:92706998571a | 1118 | virtual void PrepareHardHiZ(void) |
Davidroid | 0:92706998571a | 1119 | { |
Davidroid | 0:92706998571a | 1120 | L6470_PrepareHardHiZ(); |
Davidroid | 1:b78dab6d2c58 | 1121 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 1:b78dab6d2c58 | 1122 | } |
Davidroid | 1:b78dab6d2c58 | 1123 | |
Davidroid | 1:b78dab6d2c58 | 1124 | /** |
Davidroid | 17:4b3dc908724f | 1125 | * @brief Preparing the command to switch to step-clock mode. |
Davidroid | 17:4b3dc908724f | 1126 | * @param direction The direction of rotation. |
Davidroid | 17:4b3dc908724f | 1127 | * @retval None. |
Davidroid | 17:4b3dc908724f | 1128 | * @warning Setting the step-clock mode requires an explicit action by the user to first |
Davidroid | 17:4b3dc908724f | 1129 | * disable the power bridge through the SoftHiZ() method. |
Davidroid | 17:4b3dc908724f | 1130 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1131 | */ |
Davidroid | 1:b78dab6d2c58 | 1132 | virtual void PrepareStepClock(direction_t direction) |
Davidroid | 1:b78dab6d2c58 | 1133 | { |
Davidroid | 1:b78dab6d2c58 | 1134 | L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 1:b78dab6d2c58 | 1135 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1136 | } |
Davidroid | 0:92706998571a | 1137 | |
Davidroid | 1:b78dab6d2c58 | 1138 | /** |
Davidroid | 1:b78dab6d2c58 | 1139 | * @brief Preparing the command to do a motion at minimum speed |
Davidroid | 1:b78dab6d2c58 | 1140 | * imposing a specified direction until the SW is released. |
Davidroid | 1:b78dab6d2c58 | 1141 | * @param action The identifier of the action about the absolute position. |
Davidroid | 1:b78dab6d2c58 | 1142 | * @param direction The direction of rotation. |
Davidroid | 1:b78dab6d2c58 | 1143 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1144 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1145 | * The identifier of the action about the absolute position can be |
Davidroid | 1:b78dab6d2c58 | 1146 | * one of the following: |
Davidroid | 1:b78dab6d2c58 | 1147 | * + L6470_ACT_RST_ID: the absolute position is reset; |
Davidroid | 1:b78dab6d2c58 | 1148 | * + L6470_ACT_CPY_ID: the absolute position is set as the marked position. |
Davidroid | 1:b78dab6d2c58 | 1149 | */ |
Davidroid | 1:b78dab6d2c58 | 1150 | virtual void PrepareReleaseSW(eL6470_ActId_t action, direction_t direction) |
Davidroid | 0:92706998571a | 1151 | { |
Davidroid | 1:b78dab6d2c58 | 1152 | L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 1:b78dab6d2c58 | 1153 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 1:b78dab6d2c58 | 1154 | } |
Davidroid | 1:b78dab6d2c58 | 1155 | |
Davidroid | 1:b78dab6d2c58 | 1156 | /** |
Davidroid | 1:b78dab6d2c58 | 1157 | * @brief Preparing the command to reset the device to power-up conditions. |
Davidroid | 1:b78dab6d2c58 | 1158 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1159 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1160 | * @note The command will be sent by issuing "PerformAction()". |
Davidroid | 1:b78dab6d2c58 | 1161 | */ |
Davidroid | 1:b78dab6d2c58 | 1162 | virtual void PrepareResetDevice(void) |
Davidroid | 1:b78dab6d2c58 | 1163 | { |
Davidroid | 1:b78dab6d2c58 | 1164 | L6470_PrepareResetDevice(); |
Davidroid | 1:b78dab6d2c58 | 1165 | prepared_action = PREPARED_NO_ACTION; |
Davidroid | 0:92706998571a | 1166 | } |
Davidroid | 0:92706998571a | 1167 | |
Davidroid | 1:b78dab6d2c58 | 1168 | /** |
Davidroid | 1:b78dab6d2c58 | 1169 | * @brief Performing all the actions prepared on the components |
Davidroid | 1:b78dab6d2c58 | 1170 | * of the daisy-chain. |
Davidroid | 1:b78dab6d2c58 | 1171 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1172 | * @retval The raw data returned by the components. |
Davidroid | 1:b78dab6d2c58 | 1173 | */ |
Davidroid | 1:b78dab6d2c58 | 1174 | uint8_t* PerformPreparedActions(void) |
Davidroid | 0:92706998571a | 1175 | { |
Davidroid | 1:b78dab6d2c58 | 1176 | return L6470_PerformPreparedApplicationCommand(); |
Davidroid | 1:b78dab6d2c58 | 1177 | } |
Davidroid | 1:b78dab6d2c58 | 1178 | |
Davidroid | 1:b78dab6d2c58 | 1179 | /** |
Davidroid | 1:b78dab6d2c58 | 1180 | * @brief Getting the prepared action. |
Davidroid | 1:b78dab6d2c58 | 1181 | * @param None |
Davidroid | 1:b78dab6d2c58 | 1182 | * @retval The prepared action. |
Davidroid | 1:b78dab6d2c58 | 1183 | */ |
Davidroid | 1:b78dab6d2c58 | 1184 | prepared_action_t GetPreparedAction(void) |
Davidroid | 1:b78dab6d2c58 | 1185 | { |
Davidroid | 1:b78dab6d2c58 | 1186 | return prepared_action; |
Davidroid | 0:92706998571a | 1187 | } |
Davidroid | 0:92706998571a | 1188 | |
Davidroid | 1:b78dab6d2c58 | 1189 | /** |
Davidroid | 1:b78dab6d2c58 | 1190 | * @brief Converting the raw data received by the component according to |
Davidroid | 1:b78dab6d2c58 | 1191 | * the action performed on it. |
Davidroid | 1:b78dab6d2c58 | 1192 | * @param raw_data The received raw data. |
Davidroid | 1:b78dab6d2c58 | 1193 | * @retval The result of the action performed. |
Davidroid | 1:b78dab6d2c58 | 1194 | */ |
Davidroid | 1:b78dab6d2c58 | 1195 | int32_t GetResult(uint8_t *raw_data) |
Davidroid | 0:92706998571a | 1196 | { |
Davidroid | 1:b78dab6d2c58 | 1197 | switch (prepared_action) |
Davidroid | 1:b78dab6d2c58 | 1198 | { |
Davidroid | 1:b78dab6d2c58 | 1199 | case PREPARED_GET_POSITION: |
Davidroid | 1:b78dab6d2c58 | 1200 | return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte)); |
Davidroid | 1:b78dab6d2c58 | 1201 | |
Davidroid | 1:b78dab6d2c58 | 1202 | case PREPARED_GET_MARK: |
Davidroid | 1:b78dab6d2c58 | 1203 | return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte)); |
Davidroid | 0:92706998571a | 1204 | |
Davidroid | 1:b78dab6d2c58 | 1205 | case PREPARED_GET_SPEED: |
Davidroid | 1:b78dab6d2c58 | 1206 | return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte))); |
Davidroid | 1:b78dab6d2c58 | 1207 | |
Davidroid | 1:b78dab6d2c58 | 1208 | case PREPARED_GET_MAX_SPEED: |
Davidroid | 1:b78dab6d2c58 | 1209 | return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte))); |
Davidroid | 1:b78dab6d2c58 | 1210 | |
Davidroid | 1:b78dab6d2c58 | 1211 | case PREPARED_GET_MIN_SPEED: |
Davidroid | 1:b78dab6d2c58 | 1212 | return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte))); |
Davidroid | 1:b78dab6d2c58 | 1213 | |
Davidroid | 1:b78dab6d2c58 | 1214 | case PREPARED_GET_ACCELERATION: |
Davidroid | 1:b78dab6d2c58 | 1215 | return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte))); |
Davidroid | 1:b78dab6d2c58 | 1216 | |
Davidroid | 1:b78dab6d2c58 | 1217 | case PREPARED_GET_DECELERATION: |
Davidroid | 1:b78dab6d2c58 | 1218 | return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte))); |
Davidroid | 1:b78dab6d2c58 | 1219 | |
Davidroid | 1:b78dab6d2c58 | 1220 | case PREPARED_GET_DIRECTION: |
Davidroid | 1:b78dab6d2c58 | 1221 | return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD); |
Davidroid | 1:b78dab6d2c58 | 1222 | |
Davidroid | 1:b78dab6d2c58 | 1223 | default: |
Davidroid | 1:b78dab6d2c58 | 1224 | case PREPARED_NO_ACTION: |
Davidroid | 1:b78dab6d2c58 | 1225 | return 0; |
Davidroid | 1:b78dab6d2c58 | 1226 | } |
Davidroid | 0:92706998571a | 1227 | } |
Davidroid | 0:92706998571a | 1228 | |
Davidroid | 0:92706998571a | 1229 | |
Davidroid | 0:92706998571a | 1230 | /*** Public Interrupt Related Methods ***/ |
Davidroid | 0:92706998571a | 1231 | |
Davidroid | 0:92706998571a | 1232 | /* ACTION 6 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 1233 | * Implement here interrupt related methods, if any. * |
Davidroid | 0:92706998571a | 1234 | * Note that interrupt handling is platform dependent, e.g.: * |
Davidroid | 0:92706998571a | 1235 | * + mbed: * |
Davidroid | 14:e614697ebf34 | 1236 | * InterruptIn feature_irq(pin); //Interrupt object. * |
Davidroid | 14:e614697ebf34 | 1237 | * feature_irq.fall(callback); //Attach a callback. * |
Davidroid | 14:e614697ebf34 | 1238 | * feature_irq.mode(PullNone); //Set interrupt mode. * |
Davidroid | 14:e614697ebf34 | 1239 | * feature_irq.enable_irq(); //Enable interrupt. * |
Davidroid | 14:e614697ebf34 | 1240 | * feature_irq.disable_irq(); //Disable interrupt. * |
Davidroid | 0:92706998571a | 1241 | * + Arduino: * |
Davidroid | 0:92706998571a | 1242 | * attachInterrupt(pin, callback, RISING); //Attach a callback. * |
Davidroid | 0:92706998571a | 1243 | * detachInterrupt(pin); //Detach a callback. * |
Davidroid | 0:92706998571a | 1244 | * * |
Davidroid | 0:92706998571a | 1245 | * Example (mbed): * |
Davidroid | 0:92706998571a | 1246 | * void AttachFeatureIRQ(void (*fptr) (void)) * |
Davidroid | 0:92706998571a | 1247 | * { * |
Davidroid | 14:e614697ebf34 | 1248 | * feature_irq.fall(fptr); * |
Davidroid | 0:92706998571a | 1249 | * } * |
Davidroid | 0:92706998571a | 1250 | * * |
Davidroid | 0:92706998571a | 1251 | * void EnableFeatureIRQ(void) * |
Davidroid | 0:92706998571a | 1252 | * { * |
Davidroid | 0:92706998571a | 1253 | * feature_irq.enable_irq(); * |
Davidroid | 0:92706998571a | 1254 | * } * |
Davidroid | 0:92706998571a | 1255 | * * |
Davidroid | 0:92706998571a | 1256 | * void DisableFeatureIRQ(void) * |
Davidroid | 0:92706998571a | 1257 | * { * |
Davidroid | 0:92706998571a | 1258 | * feature_irq.disable_irq(); * |
Davidroid | 0:92706998571a | 1259 | * } * |
Davidroid | 0:92706998571a | 1260 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 1261 | /** |
Davidroid | 1:b78dab6d2c58 | 1262 | * @brief Attaching an interrupt handler to the FLAG interrupt. |
Davidroid | 1:b78dab6d2c58 | 1263 | * @param fptr An interrupt handler. |
Davidroid | 0:92706998571a | 1264 | * @retval None. |
Davidroid | 0:92706998571a | 1265 | */ |
Davidroid | 0:92706998571a | 1266 | void AttachFlagIRQ(void (*fptr)(void)) |
Davidroid | 0:92706998571a | 1267 | { |
Davidroid | 11:1aca63b2f034 | 1268 | flag_irq.fall(fptr); |
Davidroid | 0:92706998571a | 1269 | } |
Davidroid | 0:92706998571a | 1270 | |
Davidroid | 0:92706998571a | 1271 | /** |
Davidroid | 1:b78dab6d2c58 | 1272 | * @brief Enabling the FLAG interrupt handling. |
Davidroid | 0:92706998571a | 1273 | * @param None. |
Davidroid | 0:92706998571a | 1274 | * @retval None. |
Davidroid | 0:92706998571a | 1275 | */ |
Davidroid | 0:92706998571a | 1276 | void EnableFlagIRQ(void) |
Davidroid | 0:92706998571a | 1277 | { |
Davidroid | 0:92706998571a | 1278 | flag_irq.enable_irq(); |
Davidroid | 0:92706998571a | 1279 | } |
Davidroid | 0:92706998571a | 1280 | |
Davidroid | 0:92706998571a | 1281 | /** |
Davidroid | 1:b78dab6d2c58 | 1282 | * @brief Disabling the FLAG interrupt handling. |
Davidroid | 0:92706998571a | 1283 | * @param None. |
Davidroid | 0:92706998571a | 1284 | * @retval None. |
Davidroid | 0:92706998571a | 1285 | */ |
Davidroid | 0:92706998571a | 1286 | void DisableFlagIRQ(void) |
Davidroid | 0:92706998571a | 1287 | { |
Davidroid | 0:92706998571a | 1288 | flag_irq.disable_irq(); |
Davidroid | 0:92706998571a | 1289 | } |
Davidroid | 0:92706998571a | 1290 | |
Davidroid | 1:b78dab6d2c58 | 1291 | /** |
Davidroid | 1:b78dab6d2c58 | 1292 | * @brief Attaching an interrupt handler to the BUSY interrupt. |
Davidroid | 1:b78dab6d2c58 | 1293 | * @param fptr An interrupt handler. |
Davidroid | 1:b78dab6d2c58 | 1294 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1295 | */ |
Davidroid | 1:b78dab6d2c58 | 1296 | void AttachBusyIRQ(void (*fptr)(void)) |
Davidroid | 1:b78dab6d2c58 | 1297 | { |
Davidroid | 11:1aca63b2f034 | 1298 | busy_irq.fall(fptr); |
Davidroid | 1:b78dab6d2c58 | 1299 | } |
Davidroid | 1:b78dab6d2c58 | 1300 | |
Davidroid | 1:b78dab6d2c58 | 1301 | /** |
Davidroid | 1:b78dab6d2c58 | 1302 | * @brief Enabling the BUSY interrupt handling. |
Davidroid | 1:b78dab6d2c58 | 1303 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1304 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1305 | */ |
Davidroid | 1:b78dab6d2c58 | 1306 | void EnableBusyIRQ(void) |
Davidroid | 1:b78dab6d2c58 | 1307 | { |
Davidroid | 1:b78dab6d2c58 | 1308 | busy_irq.enable_irq(); |
Davidroid | 1:b78dab6d2c58 | 1309 | } |
Davidroid | 1:b78dab6d2c58 | 1310 | |
Davidroid | 1:b78dab6d2c58 | 1311 | /** |
Davidroid | 1:b78dab6d2c58 | 1312 | * @brief Disabling the BUSY interrupt handling. |
Davidroid | 1:b78dab6d2c58 | 1313 | * @param None. |
Davidroid | 1:b78dab6d2c58 | 1314 | * @retval None. |
Davidroid | 1:b78dab6d2c58 | 1315 | */ |
Davidroid | 1:b78dab6d2c58 | 1316 | void DisableBusyIRQ(void) |
Davidroid | 1:b78dab6d2c58 | 1317 | { |
Davidroid | 1:b78dab6d2c58 | 1318 | busy_irq.disable_irq(); |
Davidroid | 1:b78dab6d2c58 | 1319 | } |
Davidroid | 1:b78dab6d2c58 | 1320 | |
Davidroid | 0:92706998571a | 1321 | |
Davidroid | 0:92706998571a | 1322 | protected: |
Davidroid | 0:92706998571a | 1323 | |
Davidroid | 0:92706998571a | 1324 | /*** Protected Component Related Methods ***/ |
Davidroid | 0:92706998571a | 1325 | |
Davidroid | 0:92706998571a | 1326 | /* ACTION 7 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 1327 | * Declare here the component's specific methods. * |
Davidroid | 0:92706998571a | 1328 | * They should be: * |
Davidroid | 0:92706998571a | 1329 | * + Methods with the same name of the C component's virtual table's * |
Davidroid | 0:92706998571a | 1330 | * functions (1); * |
Davidroid | 0:92706998571a | 1331 | * + Methods with the same name of the C component's extended virtual * |
Davidroid | 0:92706998571a | 1332 | * table's functions, if any (2); * |
Davidroid | 0:92706998571a | 1333 | * + Helper methods, if any, like functions declared in the component's * |
Davidroid | 0:92706998571a | 1334 | * source files but not pointed by the component's virtual table (3). * |
Davidroid | 0:92706998571a | 1335 | * * |
Davidroid | 0:92706998571a | 1336 | * Example: * |
Davidroid | 14:e614697ebf34 | 1337 | * Status_t COMPONENT_GetValue(float *f); //(1) * |
Davidroid | 14:e614697ebf34 | 1338 | * Status_t COMPONENT_EnableFeature(void); //(2) * |
Davidroid | 14:e614697ebf34 | 1339 | * Status_t COMPONENT_ComputeAverage(void); //(3) * |
Davidroid | 0:92706998571a | 1340 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 1341 | int32_t L6470_AbsPos_2_Position(uint32_t AbsPos); |
Davidroid | 0:92706998571a | 1342 | uint32_t L6470_Position_2_AbsPos(int32_t Position); |
Davidroid | 0:92706998571a | 1343 | float L6470_Speed_2_Step_s(uint32_t Speed); |
Davidroid | 0:92706998571a | 1344 | uint32_t L6470_Step_s_2_Speed(float Step_s); |
Davidroid | 0:92706998571a | 1345 | float L6470_Acc_2_Step_s2(uint16_t Acc); |
Davidroid | 0:92706998571a | 1346 | uint16_t L6470_Step_s2_2_Acc(float Step_s2); |
Davidroid | 0:92706998571a | 1347 | float L6470_Dec_2_Step_s2(uint16_t Dec); |
Davidroid | 0:92706998571a | 1348 | uint16_t L6470_Step_s2_2_Dec(float Step_s2); |
Davidroid | 0:92706998571a | 1349 | float L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed); |
Davidroid | 0:92706998571a | 1350 | uint16_t L6470_Step_s_2_MaxSpeed(float Step_s); |
Davidroid | 0:92706998571a | 1351 | float L6470_MinSpeed_2_Step_s(uint16_t MinSpeed); |
Davidroid | 0:92706998571a | 1352 | uint16_t L6470_Step_s_2_MinSpeed(float Step_s); |
Davidroid | 0:92706998571a | 1353 | float L6470_FsSpd_2_Step_s(uint16_t FsSpd); |
Davidroid | 0:92706998571a | 1354 | uint16_t L6470_Step_s_2_FsSpd(float Step_s); |
Davidroid | 0:92706998571a | 1355 | float L6470_IntSpeed_2_Step_s(uint16_t IntSpeed); |
Davidroid | 0:92706998571a | 1356 | uint16_t L6470_Step_s_2_IntSpeed(float Step_s); |
Davidroid | 0:92706998571a | 1357 | float L6470_StSlp_2_s_Step(uint8_t StSlp); |
Davidroid | 0:92706998571a | 1358 | uint8_t L6470_s_Step_2_StSlp(float s_Step); |
Davidroid | 0:92706998571a | 1359 | float L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc); |
Davidroid | 0:92706998571a | 1360 | uint8_t L6470_s_Step_2_FnSlpAcc(float s_Step); |
Davidroid | 0:92706998571a | 1361 | float L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec); |
Davidroid | 0:92706998571a | 1362 | uint8_t L6470_s_Step_2_FnSlpDec(float s_Step); |
Davidroid | 0:92706998571a | 1363 | float L6470_OcdTh_2_mA(uint8_t OcdTh); |
Davidroid | 0:92706998571a | 1364 | uint8_t L6470_mA_2_OcdTh(float mA); |
Davidroid | 0:92706998571a | 1365 | float L6470_StallTh_2_mA(uint8_t StallTh); |
Davidroid | 0:92706998571a | 1366 | uint8_t L6470_mA_2_StallTh(float mA); |
Davidroid | 14:e614697ebf34 | 1367 | Status_t L6470_Config(void *init); |
Davidroid | 0:92706998571a | 1368 | void L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value); |
Davidroid | 0:92706998571a | 1369 | uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId); |
Davidroid | 0:92706998571a | 1370 | void L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 1371 | void L6470_StepClock(eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 1372 | void L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step); |
Davidroid | 0:92706998571a | 1373 | void L6470_GoTo(uint32_t AbsPos); |
Davidroid | 0:92706998571a | 1374 | void L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos); |
Davidroid | 0:92706998571a | 1375 | void L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 1376 | void L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 1377 | void L6470_GoHome(void); |
Davidroid | 0:92706998571a | 1378 | void L6470_GoMark(void); |
Davidroid | 0:92706998571a | 1379 | void L6470_ResetPos(void); |
Davidroid | 0:92706998571a | 1380 | void L6470_ResetDevice(void); |
Davidroid | 0:92706998571a | 1381 | void L6470_SoftStop(void); |
Davidroid | 0:92706998571a | 1382 | void L6470_HardStop(void); |
Davidroid | 0:92706998571a | 1383 | void L6470_SoftHiZ(void); |
Davidroid | 0:92706998571a | 1384 | void L6470_HardHiZ(void); |
Davidroid | 0:92706998571a | 1385 | uint16_t L6470_GetStatus(void); |
Davidroid | 0:92706998571a | 1386 | void L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value); |
Davidroid | 0:92706998571a | 1387 | void L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId); |
Davidroid | 0:92706998571a | 1388 | void L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 1389 | void L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 1390 | void L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step); |
Davidroid | 0:92706998571a | 1391 | void L6470_PrepareGoTo(uint32_t AbsPos); |
Davidroid | 0:92706998571a | 1392 | void L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos); |
Davidroid | 0:92706998571a | 1393 | void L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 1394 | void L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 1395 | void L6470_PrepareGoHome(void); |
Davidroid | 0:92706998571a | 1396 | void L6470_PrepareGoMark(void); |
Davidroid | 0:92706998571a | 1397 | void L6470_PrepareResetPos(void); |
Davidroid | 0:92706998571a | 1398 | void L6470_PrepareResetDevice(void); |
Davidroid | 0:92706998571a | 1399 | void L6470_PrepareSoftStop(void); |
Davidroid | 0:92706998571a | 1400 | void L6470_PrepareHardStop(void); |
Davidroid | 0:92706998571a | 1401 | void L6470_PrepareSoftHiZ(void); |
Davidroid | 0:92706998571a | 1402 | void L6470_PrepareHardHiZ(void); |
Davidroid | 0:92706998571a | 1403 | void L6470_PrepareGetStatus(void); |
Davidroid | 0:92706998571a | 1404 | uint8_t* L6470_PerformPreparedApplicationCommand(void); |
Davidroid | 0:92706998571a | 1405 | void L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct); |
Davidroid | 0:92706998571a | 1406 | uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte); |
Davidroid | 0:92706998571a | 1407 | uint8_t L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId); |
Davidroid | 0:92706998571a | 1408 | uint8_t* L6470_GetRegisterName(uint8_t id); |
Davidroid | 0:92706998571a | 1409 | void L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg); |
Davidroid | 0:92706998571a | 1410 | void L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3); |
Davidroid | 0:92706998571a | 1411 | void L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3); |
Davidroid | 0:92706998571a | 1412 | void L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct); |
Davidroid | 0:92706998571a | 1413 | |
Davidroid | 1:b78dab6d2c58 | 1414 | /** |
Davidroid | 1:b78dab6d2c58 | 1415 | * @brief Rounding a floating point number to the nearest unsigned integer number. |
Davidroid | 1:b78dab6d2c58 | 1416 | * @param f The floating point number. |
Davidroid | 1:b78dab6d2c58 | 1417 | * @retval The nearest unsigned integer number. |
Davidroid | 1:b78dab6d2c58 | 1418 | */ |
Davidroid | 1:b78dab6d2c58 | 1419 | int round(float f) |
Davidroid | 1:b78dab6d2c58 | 1420 | { |
Davidroid | 1:b78dab6d2c58 | 1421 | if (f >= 0) |
Davidroid | 1:b78dab6d2c58 | 1422 | return (int) f + (f - (int) f < 0.5f ? 0 : 1); |
Davidroid | 1:b78dab6d2c58 | 1423 | else |
Davidroid | 1:b78dab6d2c58 | 1424 | return (int) f - (f - (int) f < -0.5f ? 1 : 0); |
Davidroid | 1:b78dab6d2c58 | 1425 | } |
Davidroid | 1:b78dab6d2c58 | 1426 | |
Davidroid | 0:92706998571a | 1427 | |
Davidroid | 0:92706998571a | 1428 | /*** Component's I/O Methods ***/ |
Davidroid | 0:92706998571a | 1429 | |
Davidroid | 0:92706998571a | 1430 | /** |
Davidroid | 0:92706998571a | 1431 | * @brief Utility function to read data from L6470. |
Davidroid | 0:92706998571a | 1432 | * @param[out] pBuffer pointer to the buffer to read data into. |
Davidroid | 0:92706998571a | 1433 | * @param[in] NumBytesToRead number of bytes to read. |
Davidroid | 0:92706998571a | 1434 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
Davidroid | 0:92706998571a | 1435 | */ |
Davidroid | 14:e614697ebf34 | 1436 | Status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead) |
Davidroid | 0:92706998571a | 1437 | { |
Davidroid | 0:92706998571a | 1438 | if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) |
Davidroid | 0:92706998571a | 1439 | return COMPONENT_ERROR; |
Davidroid | 0:92706998571a | 1440 | return COMPONENT_OK; |
Davidroid | 0:92706998571a | 1441 | } |
Davidroid | 0:92706998571a | 1442 | |
Davidroid | 0:92706998571a | 1443 | /** |
Davidroid | 0:92706998571a | 1444 | * @brief Utility function to write data to L6470. |
Davidroid | 0:92706998571a | 1445 | * @param[in] pBuffer pointer to the buffer of data to send. |
Davidroid | 0:92706998571a | 1446 | * @param[in] NumBytesToWrite number of bytes to write. |
Davidroid | 0:92706998571a | 1447 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
Davidroid | 0:92706998571a | 1448 | */ |
Davidroid | 14:e614697ebf34 | 1449 | Status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite) |
Davidroid | 0:92706998571a | 1450 | { |
Davidroid | 0:92706998571a | 1451 | if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) |
Davidroid | 0:92706998571a | 1452 | return COMPONENT_ERROR; |
Davidroid | 0:92706998571a | 1453 | return COMPONENT_OK; |
Davidroid | 0:92706998571a | 1454 | } |
Davidroid | 0:92706998571a | 1455 | |
Davidroid | 0:92706998571a | 1456 | /** |
Davidroid | 0:92706998571a | 1457 | * @brief Utility function to read and write data from/to L6470 at the same time. |
Davidroid | 0:92706998571a | 1458 | * @param[out] pBufferToRead pointer to the buffer to read data into. |
Davidroid | 0:92706998571a | 1459 | * @param[in] pBufferToWrite pointer to the buffer of data to send. |
Davidroid | 0:92706998571a | 1460 | * @param[in] NumBytes number of bytes to read and write. |
Davidroid | 0:92706998571a | 1461 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
Davidroid | 0:92706998571a | 1462 | */ |
Davidroid | 14:e614697ebf34 | 1463 | Status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes) |
Davidroid | 0:92706998571a | 1464 | { |
Davidroid | 0:92706998571a | 1465 | if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) |
Davidroid | 0:92706998571a | 1466 | return COMPONENT_ERROR; |
Davidroid | 0:92706998571a | 1467 | return COMPONENT_OK; |
Davidroid | 0:92706998571a | 1468 | } |
Davidroid | 0:92706998571a | 1469 | |
Davidroid | 0:92706998571a | 1470 | /* ACTION 8 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 1471 | * Implement here other I/O methods beyond those already implemented * |
Davidroid | 0:92706998571a | 1472 | * above, which are declared extern within the component's header file. * |
Davidroid | 0:92706998571a | 1473 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 1474 | /* |
Davidroid | 0:92706998571a | 1475 | * Puts the device in standby mode. |
Davidroid | 0:92706998571a | 1476 | */ |
Davidroid | 0:92706998571a | 1477 | void L6470_ENABLE(void) |
Davidroid | 0:92706998571a | 1478 | { |
Davidroid | 0:92706998571a | 1479 | standby_reset = 1; |
Davidroid | 0:92706998571a | 1480 | } |
Davidroid | 0:92706998571a | 1481 | |
Davidroid | 0:92706998571a | 1482 | /* |
Davidroid | 0:92706998571a | 1483 | * Puts the device in reset mode. |
Davidroid | 0:92706998571a | 1484 | */ |
Davidroid | 0:92706998571a | 1485 | void L6470_DISABLE(void) |
Davidroid | 0:92706998571a | 1486 | { |
Davidroid | 0:92706998571a | 1487 | standby_reset = 0; |
Davidroid | 0:92706998571a | 1488 | } |
Davidroid | 0:92706998571a | 1489 | |
Davidroid | 0:92706998571a | 1490 | /* |
Davidroid | 0:92706998571a | 1491 | * Write and read bytes to/from the component through the SPI at the same time. |
Davidroid | 0:92706998571a | 1492 | */ |
Davidroid | 0:92706998571a | 1493 | void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout) |
Davidroid | 0:92706998571a | 1494 | { |
Davidroid | 0:92706998571a | 1495 | ReadWrite(pRxData, pTxData, Size); |
Davidroid | 0:92706998571a | 1496 | } |
Davidroid | 0:92706998571a | 1497 | |
Davidroid | 0:92706998571a | 1498 | |
Davidroid | 0:92706998571a | 1499 | /*** Component's Instance Variables ***/ |
Davidroid | 0:92706998571a | 1500 | |
Davidroid | 0:92706998571a | 1501 | /* ACTION 9 --------------------------------------------------------------* |
Davidroid | 1:b78dab6d2c58 | 1502 | * Declare here interrupt related variables, if needed. * |
Davidroid | 1:b78dab6d2c58 | 1503 | * Note that interrupt handling is platform dependent, see * |
Davidroid | 1:b78dab6d2c58 | 1504 | * "Interrupt Related Methods" above. * |
Davidroid | 1:b78dab6d2c58 | 1505 | * * |
Davidroid | 1:b78dab6d2c58 | 1506 | * Example: * |
Davidroid | 1:b78dab6d2c58 | 1507 | * + mbed: * |
Davidroid | 1:b78dab6d2c58 | 1508 | * InterruptIn feature_irq; * |
Davidroid | 0:92706998571a | 1509 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 1510 | /* Flag Interrupt. */ |
Davidroid | 0:92706998571a | 1511 | InterruptIn flag_irq; |
Davidroid | 0:92706998571a | 1512 | |
Davidroid | 1:b78dab6d2c58 | 1513 | /* Busy Interrupt. */ |
Davidroid | 1:b78dab6d2c58 | 1514 | InterruptIn busy_irq; |
Davidroid | 1:b78dab6d2c58 | 1515 | |
Davidroid | 1:b78dab6d2c58 | 1516 | /* ACTION 10 -------------------------------------------------------------* |
Davidroid | 1:b78dab6d2c58 | 1517 | * Declare here other pin related variables, if needed. * |
Davidroid | 1:b78dab6d2c58 | 1518 | * * |
Davidroid | 1:b78dab6d2c58 | 1519 | * Example: * |
Davidroid | 1:b78dab6d2c58 | 1520 | * + mbed: * |
Davidroid | 1:b78dab6d2c58 | 1521 | * DigitalOut standby_reset; * |
Davidroid | 1:b78dab6d2c58 | 1522 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 1523 | /* Standby/reset pin. */ |
Davidroid | 0:92706998571a | 1524 | DigitalOut standby_reset; |
Davidroid | 0:92706998571a | 1525 | |
Davidroid | 1:b78dab6d2c58 | 1526 | /* ACTION 11 -------------------------------------------------------------* |
Davidroid | 1:b78dab6d2c58 | 1527 | * Declare here communication related variables, if needed. * |
Davidroid | 1:b78dab6d2c58 | 1528 | * * |
Davidroid | 1:b78dab6d2c58 | 1529 | * Example: * |
Davidroid | 1:b78dab6d2c58 | 1530 | * + mbed: * |
Davidroid | 1:b78dab6d2c58 | 1531 | * DigitalOut ssel; * |
Davidroid | 1:b78dab6d2c58 | 1532 | * DevSPI &dev_spi; * |
Davidroid | 1:b78dab6d2c58 | 1533 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 1534 | /* Configuration. */ |
Davidroid | 0:92706998571a | 1535 | DigitalOut ssel; |
Davidroid | 0:92706998571a | 1536 | |
Davidroid | 0:92706998571a | 1537 | /* IO Device. */ |
Davidroid | 0:92706998571a | 1538 | DevSPI &dev_spi; |
Davidroid | 0:92706998571a | 1539 | |
Davidroid | 1:b78dab6d2c58 | 1540 | /* ACTION 12 -------------------------------------------------------------* |
Davidroid | 1:b78dab6d2c58 | 1541 | * Declare here identity related variables, if needed. * |
Davidroid | 1:b78dab6d2c58 | 1542 | * Note that there should be only a unique identifier for each component, * |
Davidroid | 1:b78dab6d2c58 | 1543 | * which should be the "who_am_i" parameter. * |
Davidroid | 1:b78dab6d2c58 | 1544 | *------------------------------------------------------------------------*/ |
Davidroid | 1:b78dab6d2c58 | 1545 | /* Identity */ |
Davidroid | 1:b78dab6d2c58 | 1546 | uint8_t who_am_i; |
Davidroid | 1:b78dab6d2c58 | 1547 | |
Davidroid | 1:b78dab6d2c58 | 1548 | /* ACTION 13 -------------------------------------------------------------* |
Davidroid | 1:b78dab6d2c58 | 1549 | * Declare here the component's static and non-static data, one variable * |
Davidroid | 1:b78dab6d2c58 | 1550 | * per line. * |
Davidroid | 0:92706998571a | 1551 | * * |
Davidroid | 0:92706998571a | 1552 | * Example: * |
Davidroid | 1:b78dab6d2c58 | 1553 | * float measure; * |
Davidroid | 1:b78dab6d2c58 | 1554 | * int instance_id; * |
Davidroid | 1:b78dab6d2c58 | 1555 | * static int number_of_instances; * |
Davidroid | 0:92706998571a | 1556 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 1557 | /* Data. */ |
Davidroid | 0:92706998571a | 1558 | uint8_t L6470_Id; |
Davidroid | 0:92706998571a | 1559 | const sL6470_Register_t *L6470_Register; |
Davidroid | 0:92706998571a | 1560 | const sL6470_ApplicationCommand_t *L6470_ApplicationCommand; |
Davidroid | 0:92706998571a | 1561 | const sL6470_Direction_t *L6470_Direction; |
Davidroid | 0:92706998571a | 1562 | const sL6470_ACT_t *L6470_ACT; |
Davidroid | 0:92706998571a | 1563 | sL6470_StatusRegister_t L6470_StatusRegister; |
Davidroid | 0:92706998571a | 1564 | sL6470_StatusRegister_t *pL6470_StatusRegister; |
Davidroid | 0:92706998571a | 1565 | StepperMotorRegister_t StepperMotorRegister; |
Davidroid | 1:b78dab6d2c58 | 1566 | prepared_action_t prepared_action; |
Davidroid | 0:92706998571a | 1567 | |
Davidroid | 0:92706998571a | 1568 | /* Static data. */ |
Davidroid | 0:92706998571a | 1569 | static uint8_t number_of_devices; |
Davidroid | 0:92706998571a | 1570 | static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE]; |
Davidroid | 0:92706998571a | 1571 | static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE]; |
Davidroid | 0:92706998571a | 1572 | static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE]; |
Davidroid | 0:92706998571a | 1573 | static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE]; |
Davidroid | 0:92706998571a | 1574 | static eFlagStatus_t L6470_DaisyChain_HalfPrepared; |
Davidroid | 0:92706998571a | 1575 | static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; |
Davidroid | 0:92706998571a | 1576 | static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; |
Davidroid | 0:92706998571a | 1577 | static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; |
Davidroid | 0:92706998571a | 1578 | }; |
Davidroid | 0:92706998571a | 1579 | |
Davidroid | 14:e614697ebf34 | 1580 | #endif /* __L6470_CLASS_H */ |
Davidroid | 0:92706998571a | 1581 | |
Davidroid | 14:e614697ebf34 | 1582 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |