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@0:92706998571a, 2015-11-20 (annotated)
- Committer:
- Davidroid
- Date:
- Fri Nov 20 18:07:45 2015 +0000
- Revision:
- 0:92706998571a
- Child:
- 1:b78dab6d2c58
Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the the L6470 component.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Davidroid | 0:92706998571a | 1 | /** |
Davidroid | 0:92706998571a | 2 | ****************************************************************************** |
Davidroid | 0:92706998571a | 3 | * @file L6470.c |
Davidroid | 0:92706998571a | 4 | * @date 01/10/2014 12:00:00 |
Davidroid | 0:92706998571a | 5 | * @brief This file provides set of firmware functions to manage the |
Davidroid | 0:92706998571a | 6 | * L6470. |
Davidroid | 0:92706998571a | 7 | ****************************************************************************** |
Davidroid | 0:92706998571a | 8 | * |
Davidroid | 0:92706998571a | 9 | * COPYRIGHT(c) 2014 STMicroelectronics |
Davidroid | 0:92706998571a | 10 | * |
Davidroid | 0:92706998571a | 11 | * Redistribution and use in source and binary forms, with or without modification, |
Davidroid | 0:92706998571a | 12 | * are permitted provided that the following conditions are met: |
Davidroid | 0:92706998571a | 13 | * 1. Redistributions of source code must retain the above copyright notice, |
Davidroid | 0:92706998571a | 14 | * this list of conditions and the following disclaimer. |
Davidroid | 0:92706998571a | 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Davidroid | 0:92706998571a | 16 | * this list of conditions and the following disclaimer in the documentation |
Davidroid | 0:92706998571a | 17 | * and/or other materials provided with the distribution. |
Davidroid | 0:92706998571a | 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Davidroid | 0:92706998571a | 19 | * may be used to endorse or promote products derived from this software |
Davidroid | 0:92706998571a | 20 | * without specific prior written permission. |
Davidroid | 0:92706998571a | 21 | * |
Davidroid | 0:92706998571a | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Davidroid | 0:92706998571a | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Davidroid | 0:92706998571a | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Davidroid | 0:92706998571a | 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Davidroid | 0:92706998571a | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Davidroid | 0:92706998571a | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Davidroid | 0:92706998571a | 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Davidroid | 0:92706998571a | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Davidroid | 0:92706998571a | 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Davidroid | 0:92706998571a | 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Davidroid | 0:92706998571a | 32 | * |
Davidroid | 0:92706998571a | 33 | ****************************************************************************** |
Davidroid | 0:92706998571a | 34 | */ |
Davidroid | 0:92706998571a | 35 | |
Davidroid | 0:92706998571a | 36 | |
Davidroid | 0:92706998571a | 37 | /* Generated with Stm32CubeTOO -----------------------------------------------*/ |
Davidroid | 0:92706998571a | 38 | |
Davidroid | 0:92706998571a | 39 | |
Davidroid | 0:92706998571a | 40 | /* Revision ------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 41 | /* |
Davidroid | 0:92706998571a | 42 | Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev |
Davidroid | 0:92706998571a | 43 | Branch/Trunk/Tag: trunk |
Davidroid | 0:92706998571a | 44 | Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.h |
Davidroid | 0:92706998571a | 45 | Revision: 0 |
Davidroid | 0:92706998571a | 46 | */ |
Davidroid | 0:92706998571a | 47 | |
Davidroid | 0:92706998571a | 48 | |
Davidroid | 0:92706998571a | 49 | /* Define to prevent recursive inclusion -------------------------------------*/ |
Davidroid | 0:92706998571a | 50 | |
Davidroid | 0:92706998571a | 51 | #ifndef __L6470_CLASS_H |
Davidroid | 0:92706998571a | 52 | #define __L6470_CLASS_H |
Davidroid | 0:92706998571a | 53 | |
Davidroid | 0:92706998571a | 54 | |
Davidroid | 0:92706998571a | 55 | /* Includes ------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 56 | |
Davidroid | 0:92706998571a | 57 | /* ACTION 1 ------------------------------------------------------------------* |
Davidroid | 0:92706998571a | 58 | * Include here platform specific header files. * |
Davidroid | 0:92706998571a | 59 | *----------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 60 | #include "mbed.h" |
Davidroid | 0:92706998571a | 61 | #include "DevSPI.h" |
Davidroid | 0:92706998571a | 62 | /* ACTION 2 ------------------------------------------------------------------* |
Davidroid | 0:92706998571a | 63 | * Include here component specific header files. * |
Davidroid | 0:92706998571a | 64 | *----------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 65 | #include "l6470.h" |
Davidroid | 0:92706998571a | 66 | /* ACTION 3 ------------------------------------------------------------------* |
Davidroid | 0:92706998571a | 67 | * Include here interface specific header files. * |
Davidroid | 0:92706998571a | 68 | * * |
Davidroid | 0:92706998571a | 69 | * Example: * |
Davidroid | 0:92706998571a | 70 | * #include "../Interfaces/Humidity_class.h" * |
Davidroid | 0:92706998571a | 71 | * #include "../Interfaces/Temperature_class.h" * |
Davidroid | 0:92706998571a | 72 | *----------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 73 | #include "../Interfaces/StepperMotor_class.h" |
Davidroid | 0:92706998571a | 74 | |
Davidroid | 0:92706998571a | 75 | |
Davidroid | 0:92706998571a | 76 | /* Classes -------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 77 | |
Davidroid | 0:92706998571a | 78 | /** Class representing a L6470 component. |
Davidroid | 0:92706998571a | 79 | */ |
Davidroid | 0:92706998571a | 80 | class L6470 : public StepperMotor |
Davidroid | 0:92706998571a | 81 | { |
Davidroid | 0:92706998571a | 82 | public: |
Davidroid | 0:92706998571a | 83 | |
Davidroid | 0:92706998571a | 84 | /*** Constructor and Destructor Methods ***/ |
Davidroid | 0:92706998571a | 85 | |
Davidroid | 0:92706998571a | 86 | /** |
Davidroid | 0:92706998571a | 87 | * @brief Constructor. |
Davidroid | 0:92706998571a | 88 | * @param flag_irq pin name of the FLAG pin of the component. |
Davidroid | 0:92706998571a | 89 | * @param standby_reset pin name of the STBY\RST pin of the component. |
Davidroid | 0:92706998571a | 90 | * @param ssel pin name of the SSEL pin of the SPI device to be used for communication. |
Davidroid | 0:92706998571a | 91 | * @param spi SPI device to be used for communication. |
Davidroid | 0:92706998571a | 92 | */ |
Davidroid | 0:92706998571a | 93 | L6470(PinName flag_irq, PinName standby_reset, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), standby_reset(standby_reset), ssel(ssel), dev_spi(spi) |
Davidroid | 0:92706998571a | 94 | { |
Davidroid | 0:92706998571a | 95 | /* ACTION 4 ----------------------------------------------------------* |
Davidroid | 0:92706998571a | 96 | * Initialize here the component's member variables, one variable per * |
Davidroid | 0:92706998571a | 97 | * line. * |
Davidroid | 0:92706998571a | 98 | * * |
Davidroid | 0:92706998571a | 99 | * Example: * |
Davidroid | 0:92706998571a | 100 | * T0_out = 0; * |
Davidroid | 0:92706998571a | 101 | * T1_out = 0; * |
Davidroid | 0:92706998571a | 102 | * T0_degC = 0; * |
Davidroid | 0:92706998571a | 103 | * T1_degC = 0; * |
Davidroid | 0:92706998571a | 104 | *--------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 105 | L6470_Register = &_L6470_Register[0]; |
Davidroid | 0:92706998571a | 106 | L6470_ApplicationCommand = &_L6470_ApplicationCommand[0]; |
Davidroid | 0:92706998571a | 107 | L6470_Direction = &_L6470_Direction[0]; |
Davidroid | 0:92706998571a | 108 | L6470_ACT = &_L6470_ACT[0]; |
Davidroid | 0:92706998571a | 109 | pL6470_StatusRegister = &L6470_StatusRegister; |
Davidroid | 0:92706998571a | 110 | L6470_Id = number_of_devices++; |
Davidroid | 0:92706998571a | 111 | L6470_DaisyChain_HalfPrepared = ZERO_F; |
Davidroid | 0:92706998571a | 112 | memset(L6470_AppCmdPkg, 0, L6470DAISYCHAINSIZE * sizeof(sL6470_AppCmdPkg_t)); |
Davidroid | 0:92706998571a | 113 | memset(L6470_DaisyChainSpiTxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t)); |
Davidroid | 0:92706998571a | 114 | memset(L6470_DaisyChainSpiRxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t)); |
Davidroid | 0:92706998571a | 115 | } |
Davidroid | 0:92706998571a | 116 | |
Davidroid | 0:92706998571a | 117 | /** |
Davidroid | 0:92706998571a | 118 | * @brief Destructor. |
Davidroid | 0:92706998571a | 119 | */ |
Davidroid | 0:92706998571a | 120 | virtual ~L6470(void) {} |
Davidroid | 0:92706998571a | 121 | |
Davidroid | 0:92706998571a | 122 | |
Davidroid | 0:92706998571a | 123 | /*** Public Component Related Methods ***/ |
Davidroid | 0:92706998571a | 124 | |
Davidroid | 0:92706998571a | 125 | /* ACTION 5 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 126 | * Implement here the component's public methods, as wrappers of the C * |
Davidroid | 0:92706998571a | 127 | * component's functions. * |
Davidroid | 0:92706998571a | 128 | * They should be: * |
Davidroid | 0:92706998571a | 129 | * + Methods with the same name of the C component's virtual table's * |
Davidroid | 0:92706998571a | 130 | * functions (1); * |
Davidroid | 0:92706998571a | 131 | * + Methods with the same name of the C component's extended virtual * |
Davidroid | 0:92706998571a | 132 | * table's functions, if any (2). * |
Davidroid | 0:92706998571a | 133 | * * |
Davidroid | 0:92706998571a | 134 | * Example: * |
Davidroid | 0:92706998571a | 135 | * virtual int GetValue(float *pData) //(1) * |
Davidroid | 0:92706998571a | 136 | * { * |
Davidroid | 0:92706998571a | 137 | * return COMPONENT_GetValue(float *pfData); * |
Davidroid | 0:92706998571a | 138 | * } * |
Davidroid | 0:92706998571a | 139 | * * |
Davidroid | 0:92706998571a | 140 | * virtual int EnableFeature(void) //(2) * |
Davidroid | 0:92706998571a | 141 | * { * |
Davidroid | 0:92706998571a | 142 | * return COMPONENT_EnableFeature(); * |
Davidroid | 0:92706998571a | 143 | * } * |
Davidroid | 0:92706998571a | 144 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 145 | virtual int Init(void *init) |
Davidroid | 0:92706998571a | 146 | { |
Davidroid | 0:92706998571a | 147 | return (int) L6470_Config((MICROSTEPPING_MOTOR_InitTypeDef *) init); |
Davidroid | 0:92706998571a | 148 | } |
Davidroid | 0:92706998571a | 149 | |
Davidroid | 0:92706998571a | 150 | virtual int ReadID(uint8_t *id) |
Davidroid | 0:92706998571a | 151 | { |
Davidroid | 0:92706998571a | 152 | return (int) 0; |
Davidroid | 0:92706998571a | 153 | } |
Davidroid | 0:92706998571a | 154 | |
Davidroid | 0:92706998571a | 155 | virtual unsigned int GetStatus(void) |
Davidroid | 0:92706998571a | 156 | { |
Davidroid | 0:92706998571a | 157 | return (unsigned int) L6470_GetStatus(); |
Davidroid | 0:92706998571a | 158 | } |
Davidroid | 0:92706998571a | 159 | |
Davidroid | 0:92706998571a | 160 | virtual unsigned int GetParameter(unsigned int parameter) |
Davidroid | 0:92706998571a | 161 | { |
Davidroid | 0:92706998571a | 162 | return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter); |
Davidroid | 0:92706998571a | 163 | } |
Davidroid | 0:92706998571a | 164 | |
Davidroid | 0:92706998571a | 165 | virtual signed int GetPosition(void) |
Davidroid | 0:92706998571a | 166 | { |
Davidroid | 0:92706998571a | 167 | return (signed int) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID); |
Davidroid | 0:92706998571a | 168 | } |
Davidroid | 0:92706998571a | 169 | |
Davidroid | 0:92706998571a | 170 | virtual signed int GetMark(void) |
Davidroid | 0:92706998571a | 171 | { |
Davidroid | 0:92706998571a | 172 | return (signed int) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID); |
Davidroid | 0:92706998571a | 173 | } |
Davidroid | 0:92706998571a | 174 | |
Davidroid | 0:92706998571a | 175 | virtual unsigned int GetSpeed(void) |
Davidroid | 0:92706998571a | 176 | { |
Davidroid | 0:92706998571a | 177 | return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID); |
Davidroid | 0:92706998571a | 178 | } |
Davidroid | 0:92706998571a | 179 | |
Davidroid | 0:92706998571a | 180 | virtual unsigned int GetMaxSpeed(void) |
Davidroid | 0:92706998571a | 181 | { |
Davidroid | 0:92706998571a | 182 | return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID); |
Davidroid | 0:92706998571a | 183 | } |
Davidroid | 0:92706998571a | 184 | |
Davidroid | 0:92706998571a | 185 | virtual unsigned int GetMinSpeed(void) |
Davidroid | 0:92706998571a | 186 | { |
Davidroid | 0:92706998571a | 187 | return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID); |
Davidroid | 0:92706998571a | 188 | } |
Davidroid | 0:92706998571a | 189 | |
Davidroid | 0:92706998571a | 190 | virtual unsigned int GetAcceleration(void) |
Davidroid | 0:92706998571a | 191 | { |
Davidroid | 0:92706998571a | 192 | return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID); |
Davidroid | 0:92706998571a | 193 | } |
Davidroid | 0:92706998571a | 194 | |
Davidroid | 0:92706998571a | 195 | virtual unsigned int GetDeceleration(void) |
Davidroid | 0:92706998571a | 196 | { |
Davidroid | 0:92706998571a | 197 | return (unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID); |
Davidroid | 0:92706998571a | 198 | } |
Davidroid | 0:92706998571a | 199 | |
Davidroid | 0:92706998571a | 200 | virtual direction_t GetDirection(void) |
Davidroid | 0:92706998571a | 201 | { |
Davidroid | 0:92706998571a | 202 | return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD); |
Davidroid | 0:92706998571a | 203 | } |
Davidroid | 0:92706998571a | 204 | |
Davidroid | 0:92706998571a | 205 | virtual void SetParameter(unsigned int parameter, unsigned int value) |
Davidroid | 0:92706998571a | 206 | { |
Davidroid | 0:92706998571a | 207 | L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value); |
Davidroid | 0:92706998571a | 208 | } |
Davidroid | 0:92706998571a | 209 | |
Davidroid | 0:92706998571a | 210 | virtual void SetHome(void) |
Davidroid | 0:92706998571a | 211 | { |
Davidroid | 0:92706998571a | 212 | L6470_ResetPos(); |
Davidroid | 0:92706998571a | 213 | //L6470_SetParam((eL6470_RegId_t) L6470_ABS_POS_ID, (uint32_t) 0); |
Davidroid | 0:92706998571a | 214 | } |
Davidroid | 0:92706998571a | 215 | |
Davidroid | 0:92706998571a | 216 | virtual void SetMark(void) |
Davidroid | 0:92706998571a | 217 | { |
Davidroid | 0:92706998571a | 218 | L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID)); |
Davidroid | 0:92706998571a | 219 | //L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) 0); |
Davidroid | 0:92706998571a | 220 | } |
Davidroid | 0:92706998571a | 221 | |
Davidroid | 0:92706998571a | 222 | virtual void SetMaxSpeed(unsigned int speed) |
Davidroid | 0:92706998571a | 223 | { |
Davidroid | 0:92706998571a | 224 | L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) speed); |
Davidroid | 0:92706998571a | 225 | } |
Davidroid | 0:92706998571a | 226 | |
Davidroid | 0:92706998571a | 227 | virtual void SetMinSpeed(unsigned int speed) |
Davidroid | 0:92706998571a | 228 | { |
Davidroid | 0:92706998571a | 229 | L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) speed); |
Davidroid | 0:92706998571a | 230 | } |
Davidroid | 0:92706998571a | 231 | |
Davidroid | 0:92706998571a | 232 | virtual void SetAcceleration(unsigned int acceleration) |
Davidroid | 0:92706998571a | 233 | { |
Davidroid | 0:92706998571a | 234 | L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) acceleration); |
Davidroid | 0:92706998571a | 235 | } |
Davidroid | 0:92706998571a | 236 | |
Davidroid | 0:92706998571a | 237 | virtual void SetDeceleration(unsigned int deceleration) |
Davidroid | 0:92706998571a | 238 | { |
Davidroid | 0:92706998571a | 239 | L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) deceleration); |
Davidroid | 0:92706998571a | 240 | } |
Davidroid | 0:92706998571a | 241 | |
Davidroid | 0:92706998571a | 242 | virtual void GoTo(signed int position) |
Davidroid | 0:92706998571a | 243 | { |
Davidroid | 0:92706998571a | 244 | L6470_GoTo((uint32_t) position); |
Davidroid | 0:92706998571a | 245 | } |
Davidroid | 0:92706998571a | 246 | |
Davidroid | 0:92706998571a | 247 | virtual void GoTo(signed int position, direction_t direction) |
Davidroid | 0:92706998571a | 248 | { |
Davidroid | 0:92706998571a | 249 | L6470_GoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (signed int) position); |
Davidroid | 0:92706998571a | 250 | } |
Davidroid | 0:92706998571a | 251 | |
Davidroid | 0:92706998571a | 252 | virtual void GoHome(void) |
Davidroid | 0:92706998571a | 253 | { |
Davidroid | 0:92706998571a | 254 | L6470_GoHome(); |
Davidroid | 0:92706998571a | 255 | } |
Davidroid | 0:92706998571a | 256 | |
Davidroid | 0:92706998571a | 257 | virtual void GoMark(void) |
Davidroid | 0:92706998571a | 258 | { |
Davidroid | 0:92706998571a | 259 | L6470_GoMark(); |
Davidroid | 0:92706998571a | 260 | } |
Davidroid | 0:92706998571a | 261 | |
Davidroid | 0:92706998571a | 262 | virtual void GoUntil(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 263 | { |
Davidroid | 0:92706998571a | 264 | L6470_GoUntil((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) speed); |
Davidroid | 0:92706998571a | 265 | } |
Davidroid | 0:92706998571a | 266 | |
Davidroid | 0:92706998571a | 267 | virtual void Run(direction_t direction) |
Davidroid | 0:92706998571a | 268 | { |
Davidroid | 0:92706998571a | 269 | 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 | 270 | } |
Davidroid | 0:92706998571a | 271 | |
Davidroid | 0:92706998571a | 272 | virtual void Run(direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 273 | { |
Davidroid | 0:92706998571a | 274 | L6470_Run((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) speed); |
Davidroid | 0:92706998571a | 275 | } |
Davidroid | 0:92706998571a | 276 | |
Davidroid | 0:92706998571a | 277 | virtual void Move(direction_t direction, unsigned int steps) |
Davidroid | 0:92706998571a | 278 | { |
Davidroid | 0:92706998571a | 279 | L6470_Move((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps); |
Davidroid | 0:92706998571a | 280 | } |
Davidroid | 0:92706998571a | 281 | |
Davidroid | 0:92706998571a | 282 | virtual void SoftStop(void) |
Davidroid | 0:92706998571a | 283 | { |
Davidroid | 0:92706998571a | 284 | L6470_SoftStop(); |
Davidroid | 0:92706998571a | 285 | } |
Davidroid | 0:92706998571a | 286 | |
Davidroid | 0:92706998571a | 287 | virtual void HardStop(void) |
Davidroid | 0:92706998571a | 288 | { |
Davidroid | 0:92706998571a | 289 | L6470_HardStop(); |
Davidroid | 0:92706998571a | 290 | } |
Davidroid | 0:92706998571a | 291 | |
Davidroid | 0:92706998571a | 292 | virtual void WaitWhileActive(void) |
Davidroid | 0:92706998571a | 293 | { |
Davidroid | 0:92706998571a | 294 | while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0); |
Davidroid | 0:92706998571a | 295 | } |
Davidroid | 0:92706998571a | 296 | |
Davidroid | 0:92706998571a | 297 | virtual void SoftHiZ(void) |
Davidroid | 0:92706998571a | 298 | { |
Davidroid | 0:92706998571a | 299 | L6470_SoftHiZ(); |
Davidroid | 0:92706998571a | 300 | } |
Davidroid | 0:92706998571a | 301 | |
Davidroid | 0:92706998571a | 302 | virtual void HardHiZ(void) |
Davidroid | 0:92706998571a | 303 | { |
Davidroid | 0:92706998571a | 304 | L6470_HardHiZ(); |
Davidroid | 0:92706998571a | 305 | } |
Davidroid | 0:92706998571a | 306 | |
Davidroid | 0:92706998571a | 307 | virtual void StepClock(direction_t direction) |
Davidroid | 0:92706998571a | 308 | { |
Davidroid | 0:92706998571a | 309 | L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 0:92706998571a | 310 | } |
Davidroid | 0:92706998571a | 311 | |
Davidroid | 0:92706998571a | 312 | virtual void ReleaseSW(eL6470_ActId_t L6470_ActId, direction_t direction) |
Davidroid | 0:92706998571a | 313 | { |
Davidroid | 0:92706998571a | 314 | L6470_ReleaseSW((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 0:92706998571a | 315 | } |
Davidroid | 0:92706998571a | 316 | |
Davidroid | 0:92706998571a | 317 | virtual void ResetDevice(void) |
Davidroid | 0:92706998571a | 318 | { |
Davidroid | 0:92706998571a | 319 | L6470_ResetDevice(); |
Davidroid | 0:92706998571a | 320 | } |
Davidroid | 0:92706998571a | 321 | |
Davidroid | 0:92706998571a | 322 | virtual void PrepareGetStatus(void) |
Davidroid | 0:92706998571a | 323 | { |
Davidroid | 0:92706998571a | 324 | L6470_PrepareGetStatus(); |
Davidroid | 0:92706998571a | 325 | } |
Davidroid | 0:92706998571a | 326 | |
Davidroid | 0:92706998571a | 327 | virtual void PrepareGetParameter(unsigned int parameter) |
Davidroid | 0:92706998571a | 328 | { |
Davidroid | 0:92706998571a | 329 | L6470_PrepareGetParam((eL6470_RegId_t) parameter); |
Davidroid | 0:92706998571a | 330 | } |
Davidroid | 0:92706998571a | 331 | |
Davidroid | 0:92706998571a | 332 | virtual void PrepareGetPosition(void) |
Davidroid | 0:92706998571a | 333 | { |
Davidroid | 0:92706998571a | 334 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID); |
Davidroid | 0:92706998571a | 335 | } |
Davidroid | 0:92706998571a | 336 | |
Davidroid | 0:92706998571a | 337 | virtual void PrepareGetMark(void) |
Davidroid | 0:92706998571a | 338 | { |
Davidroid | 0:92706998571a | 339 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID); |
Davidroid | 0:92706998571a | 340 | } |
Davidroid | 0:92706998571a | 341 | |
Davidroid | 0:92706998571a | 342 | virtual void PrepareGetSpeed(void) |
Davidroid | 0:92706998571a | 343 | { |
Davidroid | 0:92706998571a | 344 | L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID); |
Davidroid | 0:92706998571a | 345 | } |
Davidroid | 0:92706998571a | 346 | |
Davidroid | 0:92706998571a | 347 | virtual void PrepareGetMaxSpeed(void) |
Davidroid | 0:92706998571a | 348 | { |
Davidroid | 0:92706998571a | 349 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID); |
Davidroid | 0:92706998571a | 350 | } |
Davidroid | 0:92706998571a | 351 | |
Davidroid | 0:92706998571a | 352 | virtual void PrepareGetMinSpeed(void) |
Davidroid | 0:92706998571a | 353 | { |
Davidroid | 0:92706998571a | 354 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID); |
Davidroid | 0:92706998571a | 355 | } |
Davidroid | 0:92706998571a | 356 | |
Davidroid | 0:92706998571a | 357 | virtual void PrepareGetAcceleration(void) |
Davidroid | 0:92706998571a | 358 | { |
Davidroid | 0:92706998571a | 359 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID); |
Davidroid | 0:92706998571a | 360 | } |
Davidroid | 0:92706998571a | 361 | |
Davidroid | 0:92706998571a | 362 | virtual void PrepareGetDeceleration(void) |
Davidroid | 0:92706998571a | 363 | { |
Davidroid | 0:92706998571a | 364 | L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID); |
Davidroid | 0:92706998571a | 365 | } |
Davidroid | 0:92706998571a | 366 | |
Davidroid | 0:92706998571a | 367 | virtual direction_t PrepareGetDirection(void) |
Davidroid | 0:92706998571a | 368 | { |
Davidroid | 0:92706998571a | 369 | return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD); |
Davidroid | 0:92706998571a | 370 | } |
Davidroid | 0:92706998571a | 371 | |
Davidroid | 0:92706998571a | 372 | virtual void PrepareSetParameter(unsigned int parameter, unsigned int value) |
Davidroid | 0:92706998571a | 373 | { |
Davidroid | 0:92706998571a | 374 | L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value); |
Davidroid | 0:92706998571a | 375 | } |
Davidroid | 0:92706998571a | 376 | |
Davidroid | 0:92706998571a | 377 | virtual void PrepareSetHome(void) |
Davidroid | 0:92706998571a | 378 | { |
Davidroid | 0:92706998571a | 379 | L6470_PrepareResetPos(); |
Davidroid | 0:92706998571a | 380 | //L6470_SetParam((eL6470_RegId_t) L6470_ABS_POS_ID, (uint32_t) 0); |
Davidroid | 0:92706998571a | 381 | } |
Davidroid | 0:92706998571a | 382 | |
Davidroid | 0:92706998571a | 383 | virtual void PrepareSetMark(void) |
Davidroid | 0:92706998571a | 384 | { |
Davidroid | 0:92706998571a | 385 | uint32_t mark = L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID); |
Davidroid | 0:92706998571a | 386 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, mark); |
Davidroid | 0:92706998571a | 387 | } |
Davidroid | 0:92706998571a | 388 | |
Davidroid | 0:92706998571a | 389 | virtual void PrepareSetMaxSpeed(unsigned int speed) |
Davidroid | 0:92706998571a | 390 | { |
Davidroid | 0:92706998571a | 391 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) speed); |
Davidroid | 0:92706998571a | 392 | } |
Davidroid | 0:92706998571a | 393 | |
Davidroid | 0:92706998571a | 394 | virtual void PrepareSetMinSpeed(unsigned int speed) |
Davidroid | 0:92706998571a | 395 | { |
Davidroid | 0:92706998571a | 396 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) speed); |
Davidroid | 0:92706998571a | 397 | } |
Davidroid | 0:92706998571a | 398 | |
Davidroid | 0:92706998571a | 399 | virtual void PrepareSetAcceleration(unsigned int acceleration) |
Davidroid | 0:92706998571a | 400 | { |
Davidroid | 0:92706998571a | 401 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) acceleration); |
Davidroid | 0:92706998571a | 402 | } |
Davidroid | 0:92706998571a | 403 | |
Davidroid | 0:92706998571a | 404 | virtual void PrepareSetDeceleration(unsigned int deceleration) |
Davidroid | 0:92706998571a | 405 | { |
Davidroid | 0:92706998571a | 406 | L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) deceleration); |
Davidroid | 0:92706998571a | 407 | } |
Davidroid | 0:92706998571a | 408 | |
Davidroid | 0:92706998571a | 409 | virtual void PrepareGoTo(signed int position) |
Davidroid | 0:92706998571a | 410 | { |
Davidroid | 0:92706998571a | 411 | L6470_PrepareGoTo((uint32_t) position); |
Davidroid | 0:92706998571a | 412 | } |
Davidroid | 0:92706998571a | 413 | |
Davidroid | 0:92706998571a | 414 | virtual void PrepareGoTo(signed int position, direction_t direction) |
Davidroid | 0:92706998571a | 415 | { |
Davidroid | 0:92706998571a | 416 | L6470_PrepareGoToDir((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (signed int) position); |
Davidroid | 0:92706998571a | 417 | } |
Davidroid | 0:92706998571a | 418 | |
Davidroid | 0:92706998571a | 419 | virtual void PrepareGoHome(void) |
Davidroid | 0:92706998571a | 420 | { |
Davidroid | 0:92706998571a | 421 | L6470_PrepareGoHome(); |
Davidroid | 0:92706998571a | 422 | } |
Davidroid | 0:92706998571a | 423 | |
Davidroid | 0:92706998571a | 424 | virtual void PrepareGoMark(void) |
Davidroid | 0:92706998571a | 425 | { |
Davidroid | 0:92706998571a | 426 | L6470_PrepareGoMark(); |
Davidroid | 0:92706998571a | 427 | } |
Davidroid | 0:92706998571a | 428 | |
Davidroid | 0:92706998571a | 429 | virtual void PrepareGoUntil(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 430 | { |
Davidroid | 0:92706998571a | 431 | L6470_PrepareGoUntil((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) speed); |
Davidroid | 0:92706998571a | 432 | } |
Davidroid | 0:92706998571a | 433 | |
Davidroid | 0:92706998571a | 434 | virtual void PrepareRun(direction_t direction) |
Davidroid | 0:92706998571a | 435 | { |
Davidroid | 0:92706998571a | 436 | 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 | 0:92706998571a | 437 | } |
Davidroid | 0:92706998571a | 438 | |
Davidroid | 0:92706998571a | 439 | virtual void PrepareRun(direction_t direction, unsigned int speed) |
Davidroid | 0:92706998571a | 440 | { |
Davidroid | 0:92706998571a | 441 | L6470_PrepareRun((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) speed); |
Davidroid | 0:92706998571a | 442 | } |
Davidroid | 0:92706998571a | 443 | |
Davidroid | 0:92706998571a | 444 | virtual void PrepareMove(direction_t direction, unsigned int steps) |
Davidroid | 0:92706998571a | 445 | { |
Davidroid | 0:92706998571a | 446 | L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps); |
Davidroid | 0:92706998571a | 447 | } |
Davidroid | 0:92706998571a | 448 | |
Davidroid | 0:92706998571a | 449 | virtual void PrepareSoftStop(void) |
Davidroid | 0:92706998571a | 450 | { |
Davidroid | 0:92706998571a | 451 | L6470_PrepareSoftStop(); |
Davidroid | 0:92706998571a | 452 | } |
Davidroid | 0:92706998571a | 453 | |
Davidroid | 0:92706998571a | 454 | virtual void PrepareHardStop(void) |
Davidroid | 0:92706998571a | 455 | { |
Davidroid | 0:92706998571a | 456 | L6470_PrepareHardStop(); |
Davidroid | 0:92706998571a | 457 | } |
Davidroid | 0:92706998571a | 458 | |
Davidroid | 0:92706998571a | 459 | virtual void PrepareSoftHiZ(void) |
Davidroid | 0:92706998571a | 460 | { |
Davidroid | 0:92706998571a | 461 | L6470_PrepareSoftHiZ(); |
Davidroid | 0:92706998571a | 462 | } |
Davidroid | 0:92706998571a | 463 | |
Davidroid | 0:92706998571a | 464 | virtual void PrepareHardHiZ(void) |
Davidroid | 0:92706998571a | 465 | { |
Davidroid | 0:92706998571a | 466 | L6470_PrepareHardHiZ(); |
Davidroid | 0:92706998571a | 467 | } |
Davidroid | 0:92706998571a | 468 | |
Davidroid | 0:92706998571a | 469 | virtual void PrepareStepClock(direction_t direction) |
Davidroid | 0:92706998571a | 470 | { |
Davidroid | 0:92706998571a | 471 | L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 0:92706998571a | 472 | } |
Davidroid | 0:92706998571a | 473 | |
Davidroid | 0:92706998571a | 474 | virtual void PrepareReleaseSW(eL6470_ActId_t L6470_ActId, direction_t direction) |
Davidroid | 0:92706998571a | 475 | { |
Davidroid | 0:92706998571a | 476 | L6470_ReleaseSW((eL6470_ActId_t) L6470_ActId, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID)); |
Davidroid | 0:92706998571a | 477 | } |
Davidroid | 0:92706998571a | 478 | |
Davidroid | 0:92706998571a | 479 | virtual void PrepareResetDevice(void) |
Davidroid | 0:92706998571a | 480 | { |
Davidroid | 0:92706998571a | 481 | L6470_ResetDevice(); |
Davidroid | 0:92706998571a | 482 | } |
Davidroid | 0:92706998571a | 483 | |
Davidroid | 0:92706998571a | 484 | virtual uint8_t* PerformAction(void) |
Davidroid | 0:92706998571a | 485 | { |
Davidroid | 0:92706998571a | 486 | return (uint8_t*) L6470_PerformPreparedApplicationCommand(); |
Davidroid | 0:92706998571a | 487 | } |
Davidroid | 0:92706998571a | 488 | |
Davidroid | 0:92706998571a | 489 | |
Davidroid | 0:92706998571a | 490 | /*** Public Interrupt Related Methods ***/ |
Davidroid | 0:92706998571a | 491 | |
Davidroid | 0:92706998571a | 492 | /* ACTION 6 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 493 | * Implement here interrupt related methods, if any. * |
Davidroid | 0:92706998571a | 494 | * Note that interrupt handling is platform dependent, e.g.: * |
Davidroid | 0:92706998571a | 495 | * + mbed: * |
Davidroid | 0:92706998571a | 496 | * InterruptIn feature_irq(pin); //Interrupt object. * |
Davidroid | 0:92706998571a | 497 | * feature_irq.rise(callback); //Attach a callback. * |
Davidroid | 0:92706998571a | 498 | * feature_irq.mode(PullNone); //Set interrupt mode. * |
Davidroid | 0:92706998571a | 499 | * feature_irq.enable_irq(); //Enable interrupt. * |
Davidroid | 0:92706998571a | 500 | * feature_irq.disable_irq(); //Disable interrupt. * |
Davidroid | 0:92706998571a | 501 | * + Arduino: * |
Davidroid | 0:92706998571a | 502 | * attachInterrupt(pin, callback, RISING); //Attach a callback. * |
Davidroid | 0:92706998571a | 503 | * detachInterrupt(pin); //Detach a callback. * |
Davidroid | 0:92706998571a | 504 | * * |
Davidroid | 0:92706998571a | 505 | * Example (mbed): * |
Davidroid | 0:92706998571a | 506 | * void AttachFeatureIRQ(void (*fptr) (void)) * |
Davidroid | 0:92706998571a | 507 | * { * |
Davidroid | 0:92706998571a | 508 | * feature_irq.rise(fptr); * |
Davidroid | 0:92706998571a | 509 | * } * |
Davidroid | 0:92706998571a | 510 | * * |
Davidroid | 0:92706998571a | 511 | * void EnableFeatureIRQ(void) * |
Davidroid | 0:92706998571a | 512 | * { * |
Davidroid | 0:92706998571a | 513 | * feature_irq.enable_irq(); * |
Davidroid | 0:92706998571a | 514 | * } * |
Davidroid | 0:92706998571a | 515 | * * |
Davidroid | 0:92706998571a | 516 | * void DisableFeatureIRQ(void) * |
Davidroid | 0:92706998571a | 517 | * { * |
Davidroid | 0:92706998571a | 518 | * feature_irq.disable_irq(); * |
Davidroid | 0:92706998571a | 519 | * } * |
Davidroid | 0:92706998571a | 520 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 521 | /** |
Davidroid | 0:92706998571a | 522 | * @brief Attaching a FLAG interrupt handler. |
Davidroid | 0:92706998571a | 523 | * @param fptr an interrupt handler. |
Davidroid | 0:92706998571a | 524 | * @retval None. |
Davidroid | 0:92706998571a | 525 | */ |
Davidroid | 0:92706998571a | 526 | void AttachFlagIRQ(void (*fptr)(void)) |
Davidroid | 0:92706998571a | 527 | { |
Davidroid | 0:92706998571a | 528 | flag_irq.rise(fptr); |
Davidroid | 0:92706998571a | 529 | } |
Davidroid | 0:92706998571a | 530 | |
Davidroid | 0:92706998571a | 531 | /** |
Davidroid | 0:92706998571a | 532 | * @brief Enabling FLAG interrupt handling. |
Davidroid | 0:92706998571a | 533 | * @param None. |
Davidroid | 0:92706998571a | 534 | * @retval None. |
Davidroid | 0:92706998571a | 535 | */ |
Davidroid | 0:92706998571a | 536 | void EnableFlagIRQ(void) |
Davidroid | 0:92706998571a | 537 | { |
Davidroid | 0:92706998571a | 538 | flag_irq.enable_irq(); |
Davidroid | 0:92706998571a | 539 | } |
Davidroid | 0:92706998571a | 540 | |
Davidroid | 0:92706998571a | 541 | /** |
Davidroid | 0:92706998571a | 542 | * @brief Disabling FLAG interrupt handling. |
Davidroid | 0:92706998571a | 543 | * @param None. |
Davidroid | 0:92706998571a | 544 | * @retval None. |
Davidroid | 0:92706998571a | 545 | */ |
Davidroid | 0:92706998571a | 546 | void DisableFlagIRQ(void) |
Davidroid | 0:92706998571a | 547 | { |
Davidroid | 0:92706998571a | 548 | flag_irq.disable_irq(); |
Davidroid | 0:92706998571a | 549 | } |
Davidroid | 0:92706998571a | 550 | |
Davidroid | 0:92706998571a | 551 | |
Davidroid | 0:92706998571a | 552 | protected: |
Davidroid | 0:92706998571a | 553 | |
Davidroid | 0:92706998571a | 554 | /*** Protected Component Related Methods ***/ |
Davidroid | 0:92706998571a | 555 | |
Davidroid | 0:92706998571a | 556 | /* ACTION 7 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 557 | * Declare here the component's specific methods. * |
Davidroid | 0:92706998571a | 558 | * They should be: * |
Davidroid | 0:92706998571a | 559 | * + Methods with the same name of the C component's virtual table's * |
Davidroid | 0:92706998571a | 560 | * functions (1); * |
Davidroid | 0:92706998571a | 561 | * + Methods with the same name of the C component's extended virtual * |
Davidroid | 0:92706998571a | 562 | * table's functions, if any (2); * |
Davidroid | 0:92706998571a | 563 | * + Helper methods, if any, like functions declared in the component's * |
Davidroid | 0:92706998571a | 564 | * source files but not pointed by the component's virtual table (3). * |
Davidroid | 0:92706998571a | 565 | * * |
Davidroid | 0:92706998571a | 566 | * Example: * |
Davidroid | 0:92706998571a | 567 | * DrvStatusTypeDef COMPONENT_GetValue(float* pfData); //(1) * |
Davidroid | 0:92706998571a | 568 | * DrvStatusTypeDef COMPONENT_EnableFeature(void); //(2) * |
Davidroid | 0:92706998571a | 569 | * DrvStatusTypeDef COMPONENT_ComputeAverage(void); //(3) * |
Davidroid | 0:92706998571a | 570 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 571 | int32_t L6470_AbsPos_2_Position(uint32_t AbsPos); |
Davidroid | 0:92706998571a | 572 | uint32_t L6470_Position_2_AbsPos(int32_t Position); |
Davidroid | 0:92706998571a | 573 | float L6470_Speed_2_Step_s(uint32_t Speed); |
Davidroid | 0:92706998571a | 574 | uint32_t L6470_Step_s_2_Speed(float Step_s); |
Davidroid | 0:92706998571a | 575 | float L6470_Acc_2_Step_s2(uint16_t Acc); |
Davidroid | 0:92706998571a | 576 | uint16_t L6470_Step_s2_2_Acc(float Step_s2); |
Davidroid | 0:92706998571a | 577 | float L6470_Dec_2_Step_s2(uint16_t Dec); |
Davidroid | 0:92706998571a | 578 | uint16_t L6470_Step_s2_2_Dec(float Step_s2); |
Davidroid | 0:92706998571a | 579 | float L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed); |
Davidroid | 0:92706998571a | 580 | uint16_t L6470_Step_s_2_MaxSpeed(float Step_s); |
Davidroid | 0:92706998571a | 581 | float L6470_MinSpeed_2_Step_s(uint16_t MinSpeed); |
Davidroid | 0:92706998571a | 582 | uint16_t L6470_Step_s_2_MinSpeed(float Step_s); |
Davidroid | 0:92706998571a | 583 | float L6470_FsSpd_2_Step_s(uint16_t FsSpd); |
Davidroid | 0:92706998571a | 584 | uint16_t L6470_Step_s_2_FsSpd(float Step_s); |
Davidroid | 0:92706998571a | 585 | float L6470_IntSpeed_2_Step_s(uint16_t IntSpeed); |
Davidroid | 0:92706998571a | 586 | uint16_t L6470_Step_s_2_IntSpeed(float Step_s); |
Davidroid | 0:92706998571a | 587 | float L6470_StSlp_2_s_Step(uint8_t StSlp); |
Davidroid | 0:92706998571a | 588 | uint8_t L6470_s_Step_2_StSlp(float s_Step); |
Davidroid | 0:92706998571a | 589 | float L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc); |
Davidroid | 0:92706998571a | 590 | uint8_t L6470_s_Step_2_FnSlpAcc(float s_Step); |
Davidroid | 0:92706998571a | 591 | float L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec); |
Davidroid | 0:92706998571a | 592 | uint8_t L6470_s_Step_2_FnSlpDec(float s_Step); |
Davidroid | 0:92706998571a | 593 | float L6470_OcdTh_2_mA(uint8_t OcdTh); |
Davidroid | 0:92706998571a | 594 | uint8_t L6470_mA_2_OcdTh(float mA); |
Davidroid | 0:92706998571a | 595 | float L6470_StallTh_2_mA(uint8_t StallTh); |
Davidroid | 0:92706998571a | 596 | uint8_t L6470_mA_2_StallTh(float mA); |
Davidroid | 0:92706998571a | 597 | DrvStatusTypeDef L6470_Config(MICROSTEPPING_MOTOR_InitTypeDef *MotorParameterData); |
Davidroid | 0:92706998571a | 598 | void L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value); |
Davidroid | 0:92706998571a | 599 | uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId); |
Davidroid | 0:92706998571a | 600 | void L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 601 | void L6470_StepClock(eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 602 | void L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step); |
Davidroid | 0:92706998571a | 603 | void L6470_GoTo(uint32_t AbsPos); |
Davidroid | 0:92706998571a | 604 | void L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos); |
Davidroid | 0:92706998571a | 605 | void L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 606 | void L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 607 | void L6470_GoHome(void); |
Davidroid | 0:92706998571a | 608 | void L6470_GoMark(void); |
Davidroid | 0:92706998571a | 609 | void L6470_ResetPos(void); |
Davidroid | 0:92706998571a | 610 | void L6470_ResetDevice(void); |
Davidroid | 0:92706998571a | 611 | void L6470_SoftStop(void); |
Davidroid | 0:92706998571a | 612 | void L6470_HardStop(void); |
Davidroid | 0:92706998571a | 613 | void L6470_SoftHiZ(void); |
Davidroid | 0:92706998571a | 614 | void L6470_HardHiZ(void); |
Davidroid | 0:92706998571a | 615 | uint16_t L6470_GetStatus(void); |
Davidroid | 0:92706998571a | 616 | void L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value); |
Davidroid | 0:92706998571a | 617 | void L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId); |
Davidroid | 0:92706998571a | 618 | void L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 619 | void L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 620 | void L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step); |
Davidroid | 0:92706998571a | 621 | void L6470_PrepareGoTo(uint32_t AbsPos); |
Davidroid | 0:92706998571a | 622 | void L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos); |
Davidroid | 0:92706998571a | 623 | void L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed); |
Davidroid | 0:92706998571a | 624 | void L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId); |
Davidroid | 0:92706998571a | 625 | void L6470_PrepareGoHome(void); |
Davidroid | 0:92706998571a | 626 | void L6470_PrepareGoMark(void); |
Davidroid | 0:92706998571a | 627 | void L6470_PrepareResetPos(void); |
Davidroid | 0:92706998571a | 628 | void L6470_PrepareResetDevice(void); |
Davidroid | 0:92706998571a | 629 | void L6470_PrepareSoftStop(void); |
Davidroid | 0:92706998571a | 630 | void L6470_PrepareHardStop(void); |
Davidroid | 0:92706998571a | 631 | void L6470_PrepareSoftHiZ(void); |
Davidroid | 0:92706998571a | 632 | void L6470_PrepareHardHiZ(void); |
Davidroid | 0:92706998571a | 633 | void L6470_PrepareGetStatus(void); |
Davidroid | 0:92706998571a | 634 | uint8_t* L6470_PerformPreparedApplicationCommand(void); |
Davidroid | 0:92706998571a | 635 | void L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct); |
Davidroid | 0:92706998571a | 636 | uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte); |
Davidroid | 0:92706998571a | 637 | uint8_t L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId); |
Davidroid | 0:92706998571a | 638 | uint8_t* L6470_GetRegisterName(uint8_t id); |
Davidroid | 0:92706998571a | 639 | void L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg); |
Davidroid | 0:92706998571a | 640 | 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 | 641 | 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 | 642 | void L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct); |
Davidroid | 0:92706998571a | 643 | |
Davidroid | 0:92706998571a | 644 | |
Davidroid | 0:92706998571a | 645 | /*** Component's I/O Methods ***/ |
Davidroid | 0:92706998571a | 646 | |
Davidroid | 0:92706998571a | 647 | /** |
Davidroid | 0:92706998571a | 648 | * @brief Utility function to read data from L6470. |
Davidroid | 0:92706998571a | 649 | * @param[out] pBuffer pointer to the buffer to read data into. |
Davidroid | 0:92706998571a | 650 | * @param[in] NumBytesToRead number of bytes to read. |
Davidroid | 0:92706998571a | 651 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
Davidroid | 0:92706998571a | 652 | */ |
Davidroid | 0:92706998571a | 653 | DrvStatusTypeDef Read(uint8_t* pBuffer, uint16_t NumBytesToRead) |
Davidroid | 0:92706998571a | 654 | { |
Davidroid | 0:92706998571a | 655 | if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) |
Davidroid | 0:92706998571a | 656 | return COMPONENT_ERROR; |
Davidroid | 0:92706998571a | 657 | return COMPONENT_OK; |
Davidroid | 0:92706998571a | 658 | } |
Davidroid | 0:92706998571a | 659 | |
Davidroid | 0:92706998571a | 660 | /** |
Davidroid | 0:92706998571a | 661 | * @brief Utility function to write data to L6470. |
Davidroid | 0:92706998571a | 662 | * @param[in] pBuffer pointer to the buffer of data to send. |
Davidroid | 0:92706998571a | 663 | * @param[in] NumBytesToWrite number of bytes to write. |
Davidroid | 0:92706998571a | 664 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
Davidroid | 0:92706998571a | 665 | */ |
Davidroid | 0:92706998571a | 666 | DrvStatusTypeDef Write(uint8_t* pBuffer, uint16_t NumBytesToWrite) |
Davidroid | 0:92706998571a | 667 | { |
Davidroid | 0:92706998571a | 668 | if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) |
Davidroid | 0:92706998571a | 669 | return COMPONENT_ERROR; |
Davidroid | 0:92706998571a | 670 | return COMPONENT_OK; |
Davidroid | 0:92706998571a | 671 | } |
Davidroid | 0:92706998571a | 672 | |
Davidroid | 0:92706998571a | 673 | /** |
Davidroid | 0:92706998571a | 674 | * @brief Utility function to read and write data from/to L6470 at the same time. |
Davidroid | 0:92706998571a | 675 | * @param[out] pBufferToRead pointer to the buffer to read data into. |
Davidroid | 0:92706998571a | 676 | * @param[in] pBufferToWrite pointer to the buffer of data to send. |
Davidroid | 0:92706998571a | 677 | * @param[in] NumBytes number of bytes to read and write. |
Davidroid | 0:92706998571a | 678 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
Davidroid | 0:92706998571a | 679 | */ |
Davidroid | 0:92706998571a | 680 | DrvStatusTypeDef ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes) |
Davidroid | 0:92706998571a | 681 | { |
Davidroid | 0:92706998571a | 682 | if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) |
Davidroid | 0:92706998571a | 683 | return COMPONENT_ERROR; |
Davidroid | 0:92706998571a | 684 | return COMPONENT_OK; |
Davidroid | 0:92706998571a | 685 | } |
Davidroid | 0:92706998571a | 686 | |
Davidroid | 0:92706998571a | 687 | /* ACTION 8 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 688 | * Implement here other I/O methods beyond those already implemented * |
Davidroid | 0:92706998571a | 689 | * above, which are declared extern within the component's header file. * |
Davidroid | 0:92706998571a | 690 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 691 | /* |
Davidroid | 0:92706998571a | 692 | * Puts the device in standby mode. |
Davidroid | 0:92706998571a | 693 | */ |
Davidroid | 0:92706998571a | 694 | void L6470_ENABLE(void) |
Davidroid | 0:92706998571a | 695 | { |
Davidroid | 0:92706998571a | 696 | /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ |
Davidroid | 0:92706998571a | 697 | standby_reset = 1; |
Davidroid | 0:92706998571a | 698 | } |
Davidroid | 0:92706998571a | 699 | |
Davidroid | 0:92706998571a | 700 | /* |
Davidroid | 0:92706998571a | 701 | * Puts the device in reset mode. |
Davidroid | 0:92706998571a | 702 | */ |
Davidroid | 0:92706998571a | 703 | void L6470_DISABLE(void) |
Davidroid | 0:92706998571a | 704 | { |
Davidroid | 0:92706998571a | 705 | /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ |
Davidroid | 0:92706998571a | 706 | standby_reset = 0; |
Davidroid | 0:92706998571a | 707 | } |
Davidroid | 0:92706998571a | 708 | |
Davidroid | 0:92706998571a | 709 | /* |
Davidroid | 0:92706998571a | 710 | * Write and read bytes to/from the component through the SPI at the same time. |
Davidroid | 0:92706998571a | 711 | */ |
Davidroid | 0:92706998571a | 712 | void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout) |
Davidroid | 0:92706998571a | 713 | { |
Davidroid | 0:92706998571a | 714 | /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */ |
Davidroid | 0:92706998571a | 715 | ReadWrite(pRxData, pTxData, Size); |
Davidroid | 0:92706998571a | 716 | } |
Davidroid | 0:92706998571a | 717 | |
Davidroid | 0:92706998571a | 718 | |
Davidroid | 0:92706998571a | 719 | /*** Component's Instance Variables ***/ |
Davidroid | 0:92706998571a | 720 | |
Davidroid | 0:92706998571a | 721 | /* Identity */ |
Davidroid | 0:92706998571a | 722 | uint8_t who_am_i; |
Davidroid | 0:92706998571a | 723 | |
Davidroid | 0:92706998571a | 724 | /* ACTION 9 --------------------------------------------------------------* |
Davidroid | 0:92706998571a | 725 | * There should be only a unique identifier for each component, which * |
Davidroid | 0:92706998571a | 726 | * should be the "who_am_i" parameter, hence this parameter is optional. * |
Davidroid | 0:92706998571a | 727 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 728 | /* Type. */ |
Davidroid | 0:92706998571a | 729 | uint8_t type; |
Davidroid | 0:92706998571a | 730 | |
Davidroid | 0:92706998571a | 731 | /* Flag Interrupt. */ |
Davidroid | 0:92706998571a | 732 | InterruptIn flag_irq; |
Davidroid | 0:92706998571a | 733 | |
Davidroid | 0:92706998571a | 734 | /* Standby/reset pin. */ |
Davidroid | 0:92706998571a | 735 | DigitalOut standby_reset; |
Davidroid | 0:92706998571a | 736 | |
Davidroid | 0:92706998571a | 737 | /* Configuration. */ |
Davidroid | 0:92706998571a | 738 | DigitalOut ssel; |
Davidroid | 0:92706998571a | 739 | |
Davidroid | 0:92706998571a | 740 | /* IO Device. */ |
Davidroid | 0:92706998571a | 741 | DevSPI &dev_spi; |
Davidroid | 0:92706998571a | 742 | |
Davidroid | 0:92706998571a | 743 | /* Interrupts. */ |
Davidroid | 0:92706998571a | 744 | /* ACTION 10 -------------------------------------------------------------* |
Davidroid | 0:92706998571a | 745 | * Put here interrupt related objects, if needed. * |
Davidroid | 0:92706998571a | 746 | * Note that interrupt handling is platform dependent, see * |
Davidroid | 0:92706998571a | 747 | * "Interrupt Related Methods" above. * |
Davidroid | 0:92706998571a | 748 | * * |
Davidroid | 0:92706998571a | 749 | * Example: * |
Davidroid | 0:92706998571a | 750 | * + mbed: * |
Davidroid | 0:92706998571a | 751 | * InterruptIn feature_int; * |
Davidroid | 0:92706998571a | 752 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 753 | |
Davidroid | 0:92706998571a | 754 | /* Data. */ |
Davidroid | 0:92706998571a | 755 | /* ACTION 11 -------------------------------------------------------------* |
Davidroid | 0:92706998571a | 756 | * Declare here the component's data, one variable per line. * |
Davidroid | 0:92706998571a | 757 | * * |
Davidroid | 0:92706998571a | 758 | * Example: * |
Davidroid | 0:92706998571a | 759 | * int T0_out; * |
Davidroid | 0:92706998571a | 760 | * int T1_out; * |
Davidroid | 0:92706998571a | 761 | * float T0_degC; * |
Davidroid | 0:92706998571a | 762 | * float T1_degC; * |
Davidroid | 0:92706998571a | 763 | *------------------------------------------------------------------------*/ |
Davidroid | 0:92706998571a | 764 | uint8_t L6470_Id; |
Davidroid | 0:92706998571a | 765 | const sL6470_Register_t *L6470_Register; |
Davidroid | 0:92706998571a | 766 | const sL6470_ApplicationCommand_t *L6470_ApplicationCommand; |
Davidroid | 0:92706998571a | 767 | const sL6470_Direction_t *L6470_Direction; |
Davidroid | 0:92706998571a | 768 | const sL6470_ACT_t *L6470_ACT; |
Davidroid | 0:92706998571a | 769 | sL6470_StatusRegister_t L6470_StatusRegister; |
Davidroid | 0:92706998571a | 770 | sL6470_StatusRegister_t *pL6470_StatusRegister; |
Davidroid | 0:92706998571a | 771 | StepperMotorRegister_t StepperMotorRegister; |
Davidroid | 0:92706998571a | 772 | |
Davidroid | 0:92706998571a | 773 | /* Static data. */ |
Davidroid | 0:92706998571a | 774 | static uint8_t number_of_devices; |
Davidroid | 0:92706998571a | 775 | static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE]; |
Davidroid | 0:92706998571a | 776 | static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE]; |
Davidroid | 0:92706998571a | 777 | static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE]; |
Davidroid | 0:92706998571a | 778 | static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE]; |
Davidroid | 0:92706998571a | 779 | static eFlagStatus_t L6470_DaisyChain_HalfPrepared; |
Davidroid | 0:92706998571a | 780 | static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; |
Davidroid | 0:92706998571a | 781 | static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; |
Davidroid | 0:92706998571a | 782 | static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; |
Davidroid | 0:92706998571a | 783 | }; |
Davidroid | 0:92706998571a | 784 | |
Davidroid | 0:92706998571a | 785 | #endif // __L6470_CLASS_H |
Davidroid | 0:92706998571a | 786 | |
Davidroid | 0:92706998571a | 787 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |