Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_IHM02A1 ConcorsoFinal HelloWorld_IHM02A1_mbedOS HelloWorld_IHM02A1-Serialinterpreter ... more

Fork of X_NUCLEO_IHM02A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM02A1 Motor Control Expansion Board based on the the L6470 component.

Daisy-Chain Configuration

The two L6470 components mounted on this board are connected in daisy-chain configuration. This board can be stacked up to four times so that the eight L6470 components will be connected two-by-two in daisy-chain configuration.

Concerning the SSEL pin of the SPI communication, each expansion board must be in one of the following configuration:

  • SB_23 resistor connected only: SSEL on pin A2;
  • SB_7 resistor connected only: SSEL on pin D2;
  • SB_8 resistor connected only: SSEL on pin D10;
  • SB_9 resistor connected only: SSEL on pin D5.

Arduino Connector Compatibility Warning

X-NUCLEO-IHM02A1 is Arduino compatible with one exception: instead of using D13 pin to drive the SPI clock, it uses D3 pin, hence the default configuration for this library is with the SPI clock on D3 pin.

To be fully Arduino compatible the following patch is required:

  • to remove the SB34 resistor;
  • to solder the SB12 resistor.

Alternatively, you can route the Nucleo board’s D13 pin directly to the expansion board’s D3 pin with a wire. In case you patch your expansion board or route the pin, the SPI clock will be driven on D13 pin rather than on D3 pin, and you have also to initialize the sclk PinName variable with D13 rather than D3. This patch is known to be required, for example, on the following boards: NUCLEO-F103RB, NUCLEO-F302RB, NUCLEO-F411RE, and NUCLEO-F429ZI.

If you use D13 pin for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to the D13 pin.

Example Applications

Committer:
Davidroid
Date:
Wed Mar 01 17:52:33 2017 +0000
Revision:
21:1b7f3e002688
Parent:
19:b684efb6ba93
Fitting mbed coding style.

Who changed what in which revision?

UserRevisionLine numberNew 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 19:b684efb6ba93 71 * #include "HumiditySensor.h" *
Davidroid 19:b684efb6ba93 72 * #include "TemperatureSensor.h" *
Davidroid 0:92706998571a 73 *----------------------------------------------------------------------------*/
Davidroid 19:b684efb6ba93 74 #include "StepperMotor.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 18:ddf3d5dc8137 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 18:ddf3d5dc8137 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 21:1b7f3e002688 458 if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128) {
Davidroid 17:4b3dc908724f 459 return false;
Davidroid 21:1b7f3e002688 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 18:ddf3d5dc8137 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 21:1b7f3e002688 788 if (!L6470_DaisyChain_HalfPrepared) {
Davidroid 1:b78dab6d2c58 789 /* To avoid deleting the previous entered command. */
Davidroid 1:b78dab6d2c58 790 L6470_DaisyChain_HalfPrepared = ONE_F;
Davidroid 1:b78dab6d2c58 791 /* Resetting commands. */
Davidroid 1:b78dab6d2c58 792 L6470_ResetAppCmdPkg(L6470_AppCmdPkg);
Davidroid 1:b78dab6d2c58 793 }
Davidroid 1:b78dab6d2c58 794 prepared_action = PREPARED_GET_DIRECTION;
Davidroid 0:92706998571a 795 }
Davidroid 0:92706998571a 796
Davidroid 18:ddf3d5dc8137 797 /**
Davidroid 1:b78dab6d2c58 798 * @brief Preparing the command to set a parameter.
Davidroid 17:4b3dc908724f 799 * @param parameter A parameter's register address.
Davidroid 1:b78dab6d2c58 800 * @param value The parameter's value.
Davidroid 1:b78dab6d2c58 801 * @retval None.
Davidroid 1:b78dab6d2c58 802 * @note The command will be sent by issuing "PerformAction()".
Davidroid 17:4b3dc908724f 803 * The parameter can be one of the following:
Davidroid 17:4b3dc908724f 804 * + L6470_ABS_POS_ID
Davidroid 17:4b3dc908724f 805 * + L6470_EL_POS_ID
Davidroid 17:4b3dc908724f 806 * + L6470_MARK_ID
Davidroid 17:4b3dc908724f 807 * + L6470_SPEED_ID
Davidroid 17:4b3dc908724f 808 * + L6470_ACC_ID
Davidroid 17:4b3dc908724f 809 * + L6470_DEC_ID
Davidroid 17:4b3dc908724f 810 * + L6470_MAX_SPEED_ID
Davidroid 17:4b3dc908724f 811 * + L6470_MIN_SPEED_ID
Davidroid 17:4b3dc908724f 812 * + L6470_FS_SPD_ID
Davidroid 17:4b3dc908724f 813 * + L6470_KVAL_HOLD_ID
Davidroid 17:4b3dc908724f 814 * + L6470_KVAL_RUN_ID
Davidroid 17:4b3dc908724f 815 * + L6470_KVAL_ACC_ID
Davidroid 17:4b3dc908724f 816 * + L6470_KVAL_DEC_ID
Davidroid 17:4b3dc908724f 817 * + L6470_INT_SPEED_ID
Davidroid 17:4b3dc908724f 818 * + L6470_ST_SLP_ID
Davidroid 17:4b3dc908724f 819 * + L6470_FN_SLP_ACC_ID
Davidroid 17:4b3dc908724f 820 * + L6470_FN_SLP_DEC_ID
Davidroid 17:4b3dc908724f 821 * + L6470_K_THERM_ID
Davidroid 17:4b3dc908724f 822 * + L6470_ADC_OUT_ID
Davidroid 17:4b3dc908724f 823 * + L6470_OCD_TH_ID
Davidroid 17:4b3dc908724f 824 * + L6470_STALL_TH_ID
Davidroid 17:4b3dc908724f 825 * + L6470_STEP_MODE_ID
Davidroid 17:4b3dc908724f 826 * + L6470_ALARM_EN_ID
Davidroid 17:4b3dc908724f 827 * + L6470_CONFIG_ID
Davidroid 17:4b3dc908724f 828 * + L6470_STATUS_ID
Davidroid 17:4b3dc908724f 829 * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
Davidroid 17:4b3dc908724f 830 * Any attempt to write one of those registers when the conditions are not satisfied
Davidroid 17:4b3dc908724f 831 * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
Davidroid 17:4b3dc908724f 832 * last argument byte. Any attempt to set an inexistent register (wrong address value)
Davidroid 17:4b3dc908724f 833 * causes the command to be ignored and the WRONG_CMD flag to rise.
Davidroid 17:4b3dc908724f 834 * For example, setting some parameters requires first to disable the power bridge;
Davidroid 17:4b3dc908724f 835 * this can be done through the SoftHiZ() method.
Davidroid 17:4b3dc908724f 836 * They are the following:
Davidroid 17:4b3dc908724f 837 * + L6470_ABS_POS_ID
Davidroid 17:4b3dc908724f 838 * + L6470_EL_POS_ID
Davidroid 17:4b3dc908724f 839 * + L6470_SPEED_ID
Davidroid 17:4b3dc908724f 840 * + L6470_ACC_ID
Davidroid 17:4b3dc908724f 841 * + L6470_DEC_ID
Davidroid 17:4b3dc908724f 842 * + L6470_MAX_SPEED_ID
Davidroid 17:4b3dc908724f 843 * + L6470_MIN_SPEED_ID
Davidroid 17:4b3dc908724f 844 * + L6470_INT_SPEED_ID
Davidroid 17:4b3dc908724f 845 * + L6470_ST_SLP_ID
Davidroid 17:4b3dc908724f 846 * + L6470_FN_SLP_ACC_ID
Davidroid 17:4b3dc908724f 847 * + L6470_FN_SLP_DEC_ID
Davidroid 17:4b3dc908724f 848 * + L6470_ADC_OUT_ID
Davidroid 17:4b3dc908724f 849 * + L6470_STEP_MODE_ID
Davidroid 17:4b3dc908724f 850 * + L6470_CONFIG_ID
Davidroid 17:4b3dc908724f 851 * + L6470_STATUS_ID
Davidroid 1:b78dab6d2c58 852 */
Davidroid 0:92706998571a 853 virtual void PrepareSetParameter(unsigned int parameter, unsigned int value)
Davidroid 0:92706998571a 854 {
Davidroid 0:92706998571a 855 L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value);
Davidroid 1:b78dab6d2c58 856 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 857 }
Davidroid 0:92706998571a 858
Davidroid 1:b78dab6d2c58 859 /**
Davidroid 1:b78dab6d2c58 860 * @brief Preparing the command to set the current position to be
Davidroid 1:b78dab6d2c58 861 * the home position.
Davidroid 1:b78dab6d2c58 862 * @param None.
Davidroid 1:b78dab6d2c58 863 * @retval None.
Davidroid 1:b78dab6d2c58 864 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 865 */
Davidroid 0:92706998571a 866 virtual void PrepareSetHome(void)
Davidroid 0:92706998571a 867 {
Davidroid 0:92706998571a 868 L6470_PrepareResetPos();
Davidroid 1:b78dab6d2c58 869 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 870 }
Davidroid 0:92706998571a 871
Davidroid 1:b78dab6d2c58 872 /**
Davidroid 1:b78dab6d2c58 873 * @brief Preparing the command to set the current position to be
Davidroid 1:b78dab6d2c58 874 * the marked position.
Davidroid 1:b78dab6d2c58 875 * @param None.
Davidroid 1:b78dab6d2c58 876 * @retval None.
Davidroid 1:b78dab6d2c58 877 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 878 */
Davidroid 0:92706998571a 879 virtual void PrepareSetMark(void)
Davidroid 0:92706998571a 880 {
Davidroid 1:b78dab6d2c58 881 /*
Davidroid 1:b78dab6d2c58 882 Set "0" now as marked position. This value will be replaced by the
Davidroid 1:b78dab6d2c58 883 actual position read at the time when the prepared actions will be
Davidroid 1:b78dab6d2c58 884 performed.
Davidroid 1:b78dab6d2c58 885 */
Davidroid 1:b78dab6d2c58 886 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0);
Davidroid 1:b78dab6d2c58 887 prepared_action = PREPARED_SET_MARK;
Davidroid 0:92706998571a 888 }
Davidroid 0:92706998571a 889
Davidroid 1:b78dab6d2c58 890 /**
Davidroid 1:b78dab6d2c58 891 * @brief Preparing the command to set the given position to be
Davidroid 1:b78dab6d2c58 892 * the marked position.
Davidroid 1:b78dab6d2c58 893 * @param position The given position.
Davidroid 1:b78dab6d2c58 894 * @retval None.
Davidroid 1:b78dab6d2c58 895 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 896 */
Davidroid 1:b78dab6d2c58 897 virtual void PrepareSetMark(signed int position)
Davidroid 1:b78dab6d2c58 898 {
Davidroid 1:b78dab6d2c58 899 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 1:b78dab6d2c58 900 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 901 }
Davidroid 1:b78dab6d2c58 902
Davidroid 1:b78dab6d2c58 903 /**
Davidroid 1:b78dab6d2c58 904 * @brief Preparing the command to set the current speed in pps.
Davidroid 1:b78dab6d2c58 905 * @param speed The current speed in pps.
Davidroid 1:b78dab6d2c58 906 * @retval None.
Davidroid 1:b78dab6d2c58 907 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 908 */
Davidroid 1:b78dab6d2c58 909 virtual void PrepareSetSpeed(unsigned int speed)
Davidroid 1:b78dab6d2c58 910 {
Davidroid 1:b78dab6d2c58 911 L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed));
Davidroid 1:b78dab6d2c58 912 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 913 }
Davidroid 1:b78dab6d2c58 914
Davidroid 1:b78dab6d2c58 915 /**
Davidroid 1:b78dab6d2c58 916 * @brief Preparing the command to set the maximum speed in pps.
Davidroid 1:b78dab6d2c58 917 * @param speed The maximum speed in pps.
Davidroid 1:b78dab6d2c58 918 * @retval None.
Davidroid 1:b78dab6d2c58 919 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 920 */
Davidroid 0:92706998571a 921 virtual void PrepareSetMaxSpeed(unsigned int speed)
Davidroid 0:92706998571a 922 {
Davidroid 1:b78dab6d2c58 923 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
Davidroid 1:b78dab6d2c58 924 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 925 }
Davidroid 0:92706998571a 926
Davidroid 1:b78dab6d2c58 927 /**
Davidroid 1:b78dab6d2c58 928 * @brief Preparing the command to set the minimum speed in pps.
Davidroid 1:b78dab6d2c58 929 * @param speed The minimum speed in pps.
Davidroid 1:b78dab6d2c58 930 * @retval None.
Davidroid 1:b78dab6d2c58 931 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 932 */
Davidroid 1:b78dab6d2c58 933 virtual void PrepareSetMinSpeed(unsigned int speed)
Davidroid 1:b78dab6d2c58 934 {
Davidroid 1:b78dab6d2c58 935 L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
Davidroid 1:b78dab6d2c58 936 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 937 }
Davidroid 1:b78dab6d2c58 938
Davidroid 1:b78dab6d2c58 939 /**
Davidroid 1:b78dab6d2c58 940 * @brief Preparing the command to set the acceleration in pps^2.
Davidroid 1:b78dab6d2c58 941 * @param acceleration The acceleration in pps^2.
Davidroid 1:b78dab6d2c58 942 * @retval None.
Davidroid 1:b78dab6d2c58 943 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 944 */
Davidroid 0:92706998571a 945 virtual void PrepareSetAcceleration(unsigned int acceleration)
Davidroid 0:92706998571a 946 {
Davidroid 1:b78dab6d2c58 947 L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
Davidroid 1:b78dab6d2c58 948 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 949 }
Davidroid 0:92706998571a 950
Davidroid 1:b78dab6d2c58 951 /**
Davidroid 1:b78dab6d2c58 952 * @brief Preparing the command to set the deceleration in pps^2.
Davidroid 1:b78dab6d2c58 953 * @param deceleration The deceleration in pps^2.
Davidroid 1:b78dab6d2c58 954 * @retval None.
Davidroid 1:b78dab6d2c58 955 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 956 */
Davidroid 1:b78dab6d2c58 957 virtual void PrepareSetDeceleration(unsigned int deceleration)
Davidroid 0:92706998571a 958 {
Davidroid 1:b78dab6d2c58 959 L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
Davidroid 1:b78dab6d2c58 960 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 961 }
Davidroid 0:92706998571a 962
Davidroid 1:b78dab6d2c58 963 /**
Davidroid 1:b78dab6d2c58 964 * @brief Preparing the command to go to a specified position.
Davidroid 1:b78dab6d2c58 965 * @param position The desired position.
Davidroid 1:b78dab6d2c58 966 * @retval None.
Davidroid 1:b78dab6d2c58 967 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 968 */
Davidroid 1:b78dab6d2c58 969 virtual void PrepareGoTo(signed int position)
Davidroid 1:b78dab6d2c58 970 {
Davidroid 1:b78dab6d2c58 971 L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
Davidroid 1:b78dab6d2c58 972 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 973 }
Davidroid 1:b78dab6d2c58 974
Davidroid 1:b78dab6d2c58 975 /**
Davidroid 1:b78dab6d2c58 976 * @brief Preparing the command to go to a specified position
Davidroid 1:b78dab6d2c58 977 * imposing the desired direction.
Davidroid 1:b78dab6d2c58 978 * @param position The desired position.
Davidroid 1:b78dab6d2c58 979 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 980 * @retval None.
Davidroid 1:b78dab6d2c58 981 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 982 */
Davidroid 0:92706998571a 983 virtual void PrepareGoTo(signed int position, direction_t direction)
Davidroid 0:92706998571a 984 {
Davidroid 1:b78dab6d2c58 985 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 986 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 987 }
Davidroid 0:92706998571a 988
Davidroid 1:b78dab6d2c58 989 /**
Davidroid 1:b78dab6d2c58 990 * @brief Preparing the command to go to the home position.
Davidroid 1:b78dab6d2c58 991 * @param None.
Davidroid 1:b78dab6d2c58 992 * @retval None.
Davidroid 1:b78dab6d2c58 993 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 994 */
Davidroid 0:92706998571a 995 virtual void PrepareGoHome(void)
Davidroid 0:92706998571a 996 {
Davidroid 0:92706998571a 997 L6470_PrepareGoHome();
Davidroid 1:b78dab6d2c58 998 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 999 }
Davidroid 0:92706998571a 1000
Davidroid 1:b78dab6d2c58 1001 /**
Davidroid 1:b78dab6d2c58 1002 * @brief Preparing the command to go to the marked position.
Davidroid 1:b78dab6d2c58 1003 * @param None.
Davidroid 1:b78dab6d2c58 1004 * @retval None.
Davidroid 1:b78dab6d2c58 1005 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1006 */
Davidroid 0:92706998571a 1007 virtual void PrepareGoMark(void)
Davidroid 0:92706998571a 1008 {
Davidroid 0:92706998571a 1009 L6470_PrepareGoMark();
Davidroid 1:b78dab6d2c58 1010 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1011 }
Davidroid 0:92706998571a 1012
Davidroid 1:b78dab6d2c58 1013 /**
Davidroid 1:b78dab6d2c58 1014 * @brief Preparing the command to run at the given speed imposing the desired
Davidroid 1:b78dab6d2c58 1015 * direction until an external switch turn-on event occurs.
Davidroid 1:b78dab6d2c58 1016 * @param action The identifier of the action about the absolute position.
Davidroid 1:b78dab6d2c58 1017 * @param position The desired position.
Davidroid 1:b78dab6d2c58 1018 * @param speed The speed value in pps.
Davidroid 1:b78dab6d2c58 1019 * @retval None.
Davidroid 1:b78dab6d2c58 1020 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1021 * The identifier of the action about the absolute position can be
Davidroid 1:b78dab6d2c58 1022 * one of the following:
Davidroid 1:b78dab6d2c58 1023 * + L6470_ACT_RST_ID: the absolute position is reset;
Davidroid 1:b78dab6d2c58 1024 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
Davidroid 1:b78dab6d2c58 1025 */
Davidroid 0:92706998571a 1026 virtual void PrepareGoUntil(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed)
Davidroid 0:92706998571a 1027 {
Davidroid 1:b78dab6d2c58 1028 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 1029 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1030 }
Davidroid 0:92706998571a 1031
Davidroid 1:b78dab6d2c58 1032 /**
Davidroid 1:b78dab6d2c58 1033 * @brief Preparing the command to run towards a specified direction
Davidroid 1:b78dab6d2c58 1034 * at the maximum speed.
Davidroid 1:b78dab6d2c58 1035 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 1036 * @retval None.
Davidroid 1:b78dab6d2c58 1037 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1038 */
Davidroid 0:92706998571a 1039 virtual void PrepareRun(direction_t direction)
Davidroid 0:92706998571a 1040 {
Davidroid 0:92706998571a 1041 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 1042 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1043 }
Davidroid 0:92706998571a 1044
Davidroid 1:b78dab6d2c58 1045 /**
Davidroid 1:b78dab6d2c58 1046 * @brief Preparing the command to run towards a specified direction
Davidroid 1:b78dab6d2c58 1047 * at the given speed.
Davidroid 1:b78dab6d2c58 1048 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 1049 * @param speed The speed value in pps.
Davidroid 1:b78dab6d2c58 1050 * @retval None.
Davidroid 1:b78dab6d2c58 1051 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1052 */
Davidroid 0:92706998571a 1053 virtual void PrepareRun(direction_t direction, unsigned int speed)
Davidroid 0:92706998571a 1054 {
Davidroid 1:b78dab6d2c58 1055 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 1056 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1057 }
Davidroid 0:92706998571a 1058
Davidroid 1:b78dab6d2c58 1059 /**
Davidroid 1:b78dab6d2c58 1060 * @brief Preparing the command to move towards a specified direction
Davidroid 1:b78dab6d2c58 1061 * for a certain number of steps.
Davidroid 1:b78dab6d2c58 1062 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 1063 * @param steps The desired number of steps.
Davidroid 1:b78dab6d2c58 1064 * @retval None.
Davidroid 1:b78dab6d2c58 1065 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1066 */
Davidroid 0:92706998571a 1067 virtual void PrepareMove(direction_t direction, unsigned int steps)
Davidroid 0:92706998571a 1068 {
Davidroid 0:92706998571a 1069 L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
Davidroid 1:b78dab6d2c58 1070 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1071 }
Davidroid 0:92706998571a 1072
Davidroid 1:b78dab6d2c58 1073 /**
Davidroid 1:b78dab6d2c58 1074 * @brief Preparing the command to stop the motor.
Davidroid 1:b78dab6d2c58 1075 * @param None.
Davidroid 1:b78dab6d2c58 1076 * @retval None.
Davidroid 1:b78dab6d2c58 1077 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1078 */
Davidroid 0:92706998571a 1079 virtual void PrepareSoftStop(void)
Davidroid 0:92706998571a 1080 {
Davidroid 0:92706998571a 1081 L6470_PrepareSoftStop();
Davidroid 1:b78dab6d2c58 1082 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1083 }
Davidroid 0:92706998571a 1084
Davidroid 1:b78dab6d2c58 1085 /**
Davidroid 1:b78dab6d2c58 1086 * @brief Preparing the command to stop the motor and disabling the power bridge.
Davidroid 1:b78dab6d2c58 1087 * @param None.
Davidroid 1:b78dab6d2c58 1088 * @retval None.
Davidroid 1:b78dab6d2c58 1089 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1090 */
Davidroid 0:92706998571a 1091 virtual void PrepareHardStop(void)
Davidroid 0:92706998571a 1092 {
Davidroid 0:92706998571a 1093 L6470_PrepareHardStop();
Davidroid 1:b78dab6d2c58 1094 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1095 }
Davidroid 0:92706998571a 1096
Davidroid 1:b78dab6d2c58 1097 /**
Davidroid 1:b78dab6d2c58 1098 * @brief Preparing the command to disable the power bridge after performing
Davidroid 1:b78dab6d2c58 1099 * a deceleration to zero.
Davidroid 1:b78dab6d2c58 1100 * The used deceleration value is the one stored in the "DEC" register.
Davidroid 1:b78dab6d2c58 1101 * @param None.
Davidroid 1:b78dab6d2c58 1102 * @retval None.
Davidroid 1:b78dab6d2c58 1103 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1104 */
Davidroid 0:92706998571a 1105 virtual void PrepareSoftHiZ(void)
Davidroid 0:92706998571a 1106 {
Davidroid 0:92706998571a 1107 L6470_PrepareSoftHiZ();
Davidroid 1:b78dab6d2c58 1108 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1109 }
Davidroid 0:92706998571a 1110
Davidroid 1:b78dab6d2c58 1111 /**
Davidroid 1:b78dab6d2c58 1112 * @brief Preparing the command to disable the power bridge immediately.
Davidroid 1:b78dab6d2c58 1113 * @param None.
Davidroid 1:b78dab6d2c58 1114 * @retval None.
Davidroid 1:b78dab6d2c58 1115 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1116 */
Davidroid 0:92706998571a 1117 virtual void PrepareHardHiZ(void)
Davidroid 0:92706998571a 1118 {
Davidroid 0:92706998571a 1119 L6470_PrepareHardHiZ();
Davidroid 1:b78dab6d2c58 1120 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 1121 }
Davidroid 1:b78dab6d2c58 1122
Davidroid 1:b78dab6d2c58 1123 /**
Davidroid 18:ddf3d5dc8137 1124 * @brief Preparing the command to switch to step-clock mode.
Davidroid 18:ddf3d5dc8137 1125 * @param direction The direction of rotation.
Davidroid 18:ddf3d5dc8137 1126 * @retval None.
Davidroid 18:ddf3d5dc8137 1127 * @warning Setting the step-clock mode requires an explicit action by the user to first
Davidroid 18:ddf3d5dc8137 1128 * disable the power bridge through the SoftHiZ() method.
Davidroid 18:ddf3d5dc8137 1129 * @note The command will be sent by issuing "PerformAction()".
Davidroid 18:ddf3d5dc8137 1130 */
Davidroid 1:b78dab6d2c58 1131 virtual void PrepareStepClock(direction_t direction)
Davidroid 1:b78dab6d2c58 1132 {
Davidroid 1:b78dab6d2c58 1133 L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
Davidroid 1:b78dab6d2c58 1134 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1135 }
Davidroid 0:92706998571a 1136
Davidroid 1:b78dab6d2c58 1137 /**
Davidroid 1:b78dab6d2c58 1138 * @brief Preparing the command to do a motion at minimum speed
Davidroid 1:b78dab6d2c58 1139 * imposing a specified direction until the SW is released.
Davidroid 1:b78dab6d2c58 1140 * @param action The identifier of the action about the absolute position.
Davidroid 1:b78dab6d2c58 1141 * @param direction The direction of rotation.
Davidroid 1:b78dab6d2c58 1142 * @retval None.
Davidroid 1:b78dab6d2c58 1143 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1144 * The identifier of the action about the absolute position can be
Davidroid 1:b78dab6d2c58 1145 * one of the following:
Davidroid 1:b78dab6d2c58 1146 * + L6470_ACT_RST_ID: the absolute position is reset;
Davidroid 1:b78dab6d2c58 1147 * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
Davidroid 1:b78dab6d2c58 1148 */
Davidroid 1:b78dab6d2c58 1149 virtual void PrepareReleaseSW(eL6470_ActId_t action, direction_t direction)
Davidroid 0:92706998571a 1150 {
Davidroid 1:b78dab6d2c58 1151 L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
Davidroid 1:b78dab6d2c58 1152 prepared_action = PREPARED_NO_ACTION;
Davidroid 1:b78dab6d2c58 1153 }
Davidroid 1:b78dab6d2c58 1154
Davidroid 1:b78dab6d2c58 1155 /**
Davidroid 1:b78dab6d2c58 1156 * @brief Preparing the command to reset the device to power-up conditions.
Davidroid 1:b78dab6d2c58 1157 * @param None.
Davidroid 1:b78dab6d2c58 1158 * @retval None.
Davidroid 1:b78dab6d2c58 1159 * @note The command will be sent by issuing "PerformAction()".
Davidroid 1:b78dab6d2c58 1160 */
Davidroid 1:b78dab6d2c58 1161 virtual void PrepareResetDevice(void)
Davidroid 1:b78dab6d2c58 1162 {
Davidroid 1:b78dab6d2c58 1163 L6470_PrepareResetDevice();
Davidroid 1:b78dab6d2c58 1164 prepared_action = PREPARED_NO_ACTION;
Davidroid 0:92706998571a 1165 }
Davidroid 0:92706998571a 1166
Davidroid 1:b78dab6d2c58 1167 /**
Davidroid 1:b78dab6d2c58 1168 * @brief Performing all the actions prepared on the components
Davidroid 1:b78dab6d2c58 1169 * of the daisy-chain.
Davidroid 1:b78dab6d2c58 1170 * @param None.
Davidroid 1:b78dab6d2c58 1171 * @retval The raw data returned by the components.
Davidroid 1:b78dab6d2c58 1172 */
Davidroid 1:b78dab6d2c58 1173 uint8_t* PerformPreparedActions(void)
Davidroid 0:92706998571a 1174 {
Davidroid 1:b78dab6d2c58 1175 return L6470_PerformPreparedApplicationCommand();
Davidroid 1:b78dab6d2c58 1176 }
Davidroid 1:b78dab6d2c58 1177
Davidroid 1:b78dab6d2c58 1178 /**
Davidroid 1:b78dab6d2c58 1179 * @brief Getting the prepared action.
Davidroid 1:b78dab6d2c58 1180 * @param None
Davidroid 1:b78dab6d2c58 1181 * @retval The prepared action.
Davidroid 1:b78dab6d2c58 1182 */
Davidroid 1:b78dab6d2c58 1183 prepared_action_t GetPreparedAction(void)
Davidroid 1:b78dab6d2c58 1184 {
Davidroid 1:b78dab6d2c58 1185 return prepared_action;
Davidroid 0:92706998571a 1186 }
Davidroid 0:92706998571a 1187
Davidroid 1:b78dab6d2c58 1188 /**
Davidroid 1:b78dab6d2c58 1189 * @brief Converting the raw data received by the component according to
Davidroid 1:b78dab6d2c58 1190 * the action performed on it.
Davidroid 1:b78dab6d2c58 1191 * @param raw_data The received raw data.
Davidroid 1:b78dab6d2c58 1192 * @retval The result of the action performed.
Davidroid 1:b78dab6d2c58 1193 */
Davidroid 1:b78dab6d2c58 1194 int32_t GetResult(uint8_t *raw_data)
Davidroid 0:92706998571a 1195 {
Davidroid 21:1b7f3e002688 1196 switch (prepared_action) {
Davidroid 1:b78dab6d2c58 1197 case PREPARED_GET_POSITION:
Davidroid 1:b78dab6d2c58 1198 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte));
Davidroid 1:b78dab6d2c58 1199
Davidroid 1:b78dab6d2c58 1200 case PREPARED_GET_MARK:
Davidroid 1:b78dab6d2c58 1201 return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte));
Davidroid 0:92706998571a 1202
Davidroid 1:b78dab6d2c58 1203 case PREPARED_GET_SPEED:
Davidroid 1:b78dab6d2c58 1204 return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1205
Davidroid 1:b78dab6d2c58 1206 case PREPARED_GET_MAX_SPEED:
Davidroid 1:b78dab6d2c58 1207 return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1208
Davidroid 1:b78dab6d2c58 1209 case PREPARED_GET_MIN_SPEED:
Davidroid 1:b78dab6d2c58 1210 return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1211
Davidroid 1:b78dab6d2c58 1212 case PREPARED_GET_ACCELERATION:
Davidroid 1:b78dab6d2c58 1213 return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1214
Davidroid 1:b78dab6d2c58 1215 case PREPARED_GET_DECELERATION:
Davidroid 1:b78dab6d2c58 1216 return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte)));
Davidroid 1:b78dab6d2c58 1217
Davidroid 1:b78dab6d2c58 1218 case PREPARED_GET_DIRECTION:
Davidroid 1:b78dab6d2c58 1219 return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
Davidroid 1:b78dab6d2c58 1220
Davidroid 1:b78dab6d2c58 1221 default:
Davidroid 1:b78dab6d2c58 1222 case PREPARED_NO_ACTION:
Davidroid 1:b78dab6d2c58 1223 return 0;
Davidroid 1:b78dab6d2c58 1224 }
Davidroid 0:92706998571a 1225 }
Davidroid 0:92706998571a 1226
Davidroid 0:92706998571a 1227
Davidroid 0:92706998571a 1228 /*** Public Interrupt Related Methods ***/
Davidroid 0:92706998571a 1229
Davidroid 0:92706998571a 1230 /* ACTION 6 --------------------------------------------------------------*
Davidroid 0:92706998571a 1231 * Implement here interrupt related methods, if any. *
Davidroid 0:92706998571a 1232 * Note that interrupt handling is platform dependent, e.g.: *
Davidroid 0:92706998571a 1233 * + mbed: *
Davidroid 14:e614697ebf34 1234 * InterruptIn feature_irq(pin); //Interrupt object. *
Davidroid 14:e614697ebf34 1235 * feature_irq.fall(callback); //Attach a callback. *
Davidroid 14:e614697ebf34 1236 * feature_irq.mode(PullNone); //Set interrupt mode. *
Davidroid 14:e614697ebf34 1237 * feature_irq.enable_irq(); //Enable interrupt. *
Davidroid 14:e614697ebf34 1238 * feature_irq.disable_irq(); //Disable interrupt. *
Davidroid 0:92706998571a 1239 * + Arduino: *
Davidroid 0:92706998571a 1240 * attachInterrupt(pin, callback, RISING); //Attach a callback. *
Davidroid 0:92706998571a 1241 * detachInterrupt(pin); //Detach a callback. *
Davidroid 0:92706998571a 1242 * *
Davidroid 0:92706998571a 1243 * Example (mbed): *
Davidroid 0:92706998571a 1244 * void AttachFeatureIRQ(void (*fptr) (void)) *
Davidroid 0:92706998571a 1245 * { *
Davidroid 14:e614697ebf34 1246 * feature_irq.fall(fptr); *
Davidroid 0:92706998571a 1247 * } *
Davidroid 0:92706998571a 1248 * *
Davidroid 0:92706998571a 1249 * void EnableFeatureIRQ(void) *
Davidroid 0:92706998571a 1250 * { *
Davidroid 0:92706998571a 1251 * feature_irq.enable_irq(); *
Davidroid 0:92706998571a 1252 * } *
Davidroid 0:92706998571a 1253 * *
Davidroid 0:92706998571a 1254 * void DisableFeatureIRQ(void) *
Davidroid 0:92706998571a 1255 * { *
Davidroid 0:92706998571a 1256 * feature_irq.disable_irq(); *
Davidroid 0:92706998571a 1257 * } *
Davidroid 0:92706998571a 1258 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1259 /**
Davidroid 1:b78dab6d2c58 1260 * @brief Attaching an interrupt handler to the FLAG interrupt.
Davidroid 1:b78dab6d2c58 1261 * @param fptr An interrupt handler.
Davidroid 0:92706998571a 1262 * @retval None.
Davidroid 0:92706998571a 1263 */
Davidroid 0:92706998571a 1264 void AttachFlagIRQ(void (*fptr)(void))
Davidroid 0:92706998571a 1265 {
Davidroid 11:1aca63b2f034 1266 flag_irq.fall(fptr);
Davidroid 0:92706998571a 1267 }
Davidroid 0:92706998571a 1268
Davidroid 0:92706998571a 1269 /**
Davidroid 1:b78dab6d2c58 1270 * @brief Enabling the FLAG interrupt handling.
Davidroid 0:92706998571a 1271 * @param None.
Davidroid 0:92706998571a 1272 * @retval None.
Davidroid 0:92706998571a 1273 */
Davidroid 0:92706998571a 1274 void EnableFlagIRQ(void)
Davidroid 0:92706998571a 1275 {
Davidroid 0:92706998571a 1276 flag_irq.enable_irq();
Davidroid 0:92706998571a 1277 }
Davidroid 0:92706998571a 1278
Davidroid 0:92706998571a 1279 /**
Davidroid 1:b78dab6d2c58 1280 * @brief Disabling the FLAG interrupt handling.
Davidroid 0:92706998571a 1281 * @param None.
Davidroid 0:92706998571a 1282 * @retval None.
Davidroid 0:92706998571a 1283 */
Davidroid 0:92706998571a 1284 void DisableFlagIRQ(void)
Davidroid 0:92706998571a 1285 {
Davidroid 0:92706998571a 1286 flag_irq.disable_irq();
Davidroid 0:92706998571a 1287 }
Davidroid 0:92706998571a 1288
Davidroid 1:b78dab6d2c58 1289 /**
Davidroid 1:b78dab6d2c58 1290 * @brief Attaching an interrupt handler to the BUSY interrupt.
Davidroid 1:b78dab6d2c58 1291 * @param fptr An interrupt handler.
Davidroid 1:b78dab6d2c58 1292 * @retval None.
Davidroid 1:b78dab6d2c58 1293 */
Davidroid 1:b78dab6d2c58 1294 void AttachBusyIRQ(void (*fptr)(void))
Davidroid 1:b78dab6d2c58 1295 {
Davidroid 11:1aca63b2f034 1296 busy_irq.fall(fptr);
Davidroid 1:b78dab6d2c58 1297 }
Davidroid 1:b78dab6d2c58 1298
Davidroid 1:b78dab6d2c58 1299 /**
Davidroid 1:b78dab6d2c58 1300 * @brief Enabling the BUSY interrupt handling.
Davidroid 1:b78dab6d2c58 1301 * @param None.
Davidroid 1:b78dab6d2c58 1302 * @retval None.
Davidroid 1:b78dab6d2c58 1303 */
Davidroid 1:b78dab6d2c58 1304 void EnableBusyIRQ(void)
Davidroid 1:b78dab6d2c58 1305 {
Davidroid 1:b78dab6d2c58 1306 busy_irq.enable_irq();
Davidroid 1:b78dab6d2c58 1307 }
Davidroid 1:b78dab6d2c58 1308
Davidroid 1:b78dab6d2c58 1309 /**
Davidroid 1:b78dab6d2c58 1310 * @brief Disabling the BUSY interrupt handling.
Davidroid 1:b78dab6d2c58 1311 * @param None.
Davidroid 1:b78dab6d2c58 1312 * @retval None.
Davidroid 1:b78dab6d2c58 1313 */
Davidroid 1:b78dab6d2c58 1314 void DisableBusyIRQ(void)
Davidroid 1:b78dab6d2c58 1315 {
Davidroid 1:b78dab6d2c58 1316 busy_irq.disable_irq();
Davidroid 1:b78dab6d2c58 1317 }
Davidroid 1:b78dab6d2c58 1318
Davidroid 0:92706998571a 1319
Davidroid 0:92706998571a 1320 protected:
Davidroid 0:92706998571a 1321
Davidroid 0:92706998571a 1322 /*** Protected Component Related Methods ***/
Davidroid 0:92706998571a 1323
Davidroid 0:92706998571a 1324 /* ACTION 7 --------------------------------------------------------------*
Davidroid 0:92706998571a 1325 * Declare here the component's specific methods. *
Davidroid 0:92706998571a 1326 * They should be: *
Davidroid 0:92706998571a 1327 * + Methods with the same name of the C component's virtual table's *
Davidroid 0:92706998571a 1328 * functions (1); *
Davidroid 0:92706998571a 1329 * + Methods with the same name of the C component's extended virtual *
Davidroid 0:92706998571a 1330 * table's functions, if any (2); *
Davidroid 0:92706998571a 1331 * + Helper methods, if any, like functions declared in the component's *
Davidroid 0:92706998571a 1332 * source files but not pointed by the component's virtual table (3). *
Davidroid 0:92706998571a 1333 * *
Davidroid 0:92706998571a 1334 * Example: *
Davidroid 14:e614697ebf34 1335 * Status_t COMPONENT_GetValue(float *f); //(1) *
Davidroid 14:e614697ebf34 1336 * Status_t COMPONENT_EnableFeature(void); //(2) *
Davidroid 14:e614697ebf34 1337 * Status_t COMPONENT_ComputeAverage(void); //(3) *
Davidroid 0:92706998571a 1338 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1339 int32_t L6470_AbsPos_2_Position(uint32_t AbsPos);
Davidroid 0:92706998571a 1340 uint32_t L6470_Position_2_AbsPos(int32_t Position);
Davidroid 0:92706998571a 1341 float L6470_Speed_2_Step_s(uint32_t Speed);
Davidroid 0:92706998571a 1342 uint32_t L6470_Step_s_2_Speed(float Step_s);
Davidroid 0:92706998571a 1343 float L6470_Acc_2_Step_s2(uint16_t Acc);
Davidroid 0:92706998571a 1344 uint16_t L6470_Step_s2_2_Acc(float Step_s2);
Davidroid 0:92706998571a 1345 float L6470_Dec_2_Step_s2(uint16_t Dec);
Davidroid 0:92706998571a 1346 uint16_t L6470_Step_s2_2_Dec(float Step_s2);
Davidroid 0:92706998571a 1347 float L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed);
Davidroid 0:92706998571a 1348 uint16_t L6470_Step_s_2_MaxSpeed(float Step_s);
Davidroid 0:92706998571a 1349 float L6470_MinSpeed_2_Step_s(uint16_t MinSpeed);
Davidroid 0:92706998571a 1350 uint16_t L6470_Step_s_2_MinSpeed(float Step_s);
Davidroid 0:92706998571a 1351 float L6470_FsSpd_2_Step_s(uint16_t FsSpd);
Davidroid 0:92706998571a 1352 uint16_t L6470_Step_s_2_FsSpd(float Step_s);
Davidroid 0:92706998571a 1353 float L6470_IntSpeed_2_Step_s(uint16_t IntSpeed);
Davidroid 0:92706998571a 1354 uint16_t L6470_Step_s_2_IntSpeed(float Step_s);
Davidroid 0:92706998571a 1355 float L6470_StSlp_2_s_Step(uint8_t StSlp);
Davidroid 0:92706998571a 1356 uint8_t L6470_s_Step_2_StSlp(float s_Step);
Davidroid 0:92706998571a 1357 float L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc);
Davidroid 0:92706998571a 1358 uint8_t L6470_s_Step_2_FnSlpAcc(float s_Step);
Davidroid 0:92706998571a 1359 float L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec);
Davidroid 0:92706998571a 1360 uint8_t L6470_s_Step_2_FnSlpDec(float s_Step);
Davidroid 0:92706998571a 1361 float L6470_OcdTh_2_mA(uint8_t OcdTh);
Davidroid 0:92706998571a 1362 uint8_t L6470_mA_2_OcdTh(float mA);
Davidroid 0:92706998571a 1363 float L6470_StallTh_2_mA(uint8_t StallTh);
Davidroid 0:92706998571a 1364 uint8_t L6470_mA_2_StallTh(float mA);
Davidroid 14:e614697ebf34 1365 Status_t L6470_Config(void *init);
Davidroid 0:92706998571a 1366 void L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
Davidroid 0:92706998571a 1367 uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId);
Davidroid 0:92706998571a 1368 void L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1369 void L6470_StepClock(eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1370 void L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
Davidroid 0:92706998571a 1371 void L6470_GoTo(uint32_t AbsPos);
Davidroid 0:92706998571a 1372 void L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
Davidroid 0:92706998571a 1373 void L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1374 void L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1375 void L6470_GoHome(void);
Davidroid 0:92706998571a 1376 void L6470_GoMark(void);
Davidroid 0:92706998571a 1377 void L6470_ResetPos(void);
Davidroid 0:92706998571a 1378 void L6470_ResetDevice(void);
Davidroid 0:92706998571a 1379 void L6470_SoftStop(void);
Davidroid 0:92706998571a 1380 void L6470_HardStop(void);
Davidroid 0:92706998571a 1381 void L6470_SoftHiZ(void);
Davidroid 0:92706998571a 1382 void L6470_HardHiZ(void);
Davidroid 0:92706998571a 1383 uint16_t L6470_GetStatus(void);
Davidroid 0:92706998571a 1384 void L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
Davidroid 0:92706998571a 1385 void L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId);
Davidroid 0:92706998571a 1386 void L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1387 void L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1388 void L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
Davidroid 0:92706998571a 1389 void L6470_PrepareGoTo(uint32_t AbsPos);
Davidroid 0:92706998571a 1390 void L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
Davidroid 0:92706998571a 1391 void L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 1392 void L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 1393 void L6470_PrepareGoHome(void);
Davidroid 0:92706998571a 1394 void L6470_PrepareGoMark(void);
Davidroid 0:92706998571a 1395 void L6470_PrepareResetPos(void);
Davidroid 0:92706998571a 1396 void L6470_PrepareResetDevice(void);
Davidroid 0:92706998571a 1397 void L6470_PrepareSoftStop(void);
Davidroid 0:92706998571a 1398 void L6470_PrepareHardStop(void);
Davidroid 0:92706998571a 1399 void L6470_PrepareSoftHiZ(void);
Davidroid 0:92706998571a 1400 void L6470_PrepareHardHiZ(void);
Davidroid 0:92706998571a 1401 void L6470_PrepareGetStatus(void);
Davidroid 0:92706998571a 1402 uint8_t* L6470_PerformPreparedApplicationCommand(void);
Davidroid 0:92706998571a 1403 void L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 1404 uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
Davidroid 0:92706998571a 1405 uint8_t L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId);
Davidroid 0:92706998571a 1406 uint8_t* L6470_GetRegisterName(uint8_t id);
Davidroid 0:92706998571a 1407 void L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg);
Davidroid 0:92706998571a 1408 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 1409 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 1410 void L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 1411
Davidroid 1:b78dab6d2c58 1412 /**
Davidroid 1:b78dab6d2c58 1413 * @brief Rounding a floating point number to the nearest unsigned integer number.
Davidroid 1:b78dab6d2c58 1414 * @param f The floating point number.
Davidroid 1:b78dab6d2c58 1415 * @retval The nearest unsigned integer number.
Davidroid 1:b78dab6d2c58 1416 */
Davidroid 1:b78dab6d2c58 1417 int round(float f)
Davidroid 1:b78dab6d2c58 1418 {
Davidroid 21:1b7f3e002688 1419 if (f >= 0) {
Davidroid 1:b78dab6d2c58 1420 return (int) f + (f - (int) f < 0.5f ? 0 : 1);
Davidroid 21:1b7f3e002688 1421 } else {
Davidroid 1:b78dab6d2c58 1422 return (int) f - (f - (int) f < -0.5f ? 1 : 0);
Davidroid 21:1b7f3e002688 1423 }
Davidroid 1:b78dab6d2c58 1424 }
Davidroid 1:b78dab6d2c58 1425
Davidroid 0:92706998571a 1426
Davidroid 0:92706998571a 1427 /*** Component's I/O Methods ***/
Davidroid 0:92706998571a 1428
Davidroid 0:92706998571a 1429 /**
Davidroid 0:92706998571a 1430 * @brief Utility function to read data from L6470.
Davidroid 0:92706998571a 1431 * @param[out] pBuffer pointer to the buffer to read data into.
Davidroid 0:92706998571a 1432 * @param[in] NumBytesToRead number of bytes to read.
Davidroid 0:92706998571a 1433 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
Davidroid 0:92706998571a 1434 */
Davidroid 14:e614697ebf34 1435 Status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
Davidroid 0:92706998571a 1436 {
Davidroid 21:1b7f3e002688 1437 if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) {
Davidroid 0:92706998571a 1438 return COMPONENT_ERROR;
Davidroid 21:1b7f3e002688 1439 }
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 21:1b7f3e002688 1451 if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) {
Davidroid 0:92706998571a 1452 return COMPONENT_ERROR;
Davidroid 21:1b7f3e002688 1453 }
Davidroid 0:92706998571a 1454 return COMPONENT_OK;
Davidroid 0:92706998571a 1455 }
Davidroid 0:92706998571a 1456
Davidroid 0:92706998571a 1457 /**
Davidroid 0:92706998571a 1458 * @brief Utility function to read and write data from/to L6470 at the same time.
Davidroid 0:92706998571a 1459 * @param[out] pBufferToRead pointer to the buffer to read data into.
Davidroid 0:92706998571a 1460 * @param[in] pBufferToWrite pointer to the buffer of data to send.
Davidroid 0:92706998571a 1461 * @param[in] NumBytes number of bytes to read and write.
Davidroid 0:92706998571a 1462 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
Davidroid 0:92706998571a 1463 */
Davidroid 14:e614697ebf34 1464 Status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
Davidroid 0:92706998571a 1465 {
Davidroid 21:1b7f3e002688 1466 if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) {
Davidroid 0:92706998571a 1467 return COMPONENT_ERROR;
Davidroid 21:1b7f3e002688 1468 }
Davidroid 0:92706998571a 1469 return COMPONENT_OK;
Davidroid 0:92706998571a 1470 }
Davidroid 0:92706998571a 1471
Davidroid 0:92706998571a 1472 /* ACTION 8 --------------------------------------------------------------*
Davidroid 0:92706998571a 1473 * Implement here other I/O methods beyond those already implemented *
Davidroid 0:92706998571a 1474 * above, which are declared extern within the component's header file. *
Davidroid 0:92706998571a 1475 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1476 /*
Davidroid 0:92706998571a 1477 * Puts the device in standby mode.
Davidroid 0:92706998571a 1478 */
Davidroid 0:92706998571a 1479 void L6470_ENABLE(void)
Davidroid 0:92706998571a 1480 {
Davidroid 0:92706998571a 1481 standby_reset = 1;
Davidroid 0:92706998571a 1482 }
Davidroid 0:92706998571a 1483
Davidroid 0:92706998571a 1484 /*
Davidroid 0:92706998571a 1485 * Puts the device in reset mode.
Davidroid 0:92706998571a 1486 */
Davidroid 0:92706998571a 1487 void L6470_DISABLE(void)
Davidroid 0:92706998571a 1488 {
Davidroid 0:92706998571a 1489 standby_reset = 0;
Davidroid 0:92706998571a 1490 }
Davidroid 0:92706998571a 1491
Davidroid 0:92706998571a 1492 /*
Davidroid 0:92706998571a 1493 * Write and read bytes to/from the component through the SPI at the same time.
Davidroid 0:92706998571a 1494 */
Davidroid 0:92706998571a 1495 void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
Davidroid 0:92706998571a 1496 {
Davidroid 0:92706998571a 1497 ReadWrite(pRxData, pTxData, Size);
Davidroid 0:92706998571a 1498 }
Davidroid 0:92706998571a 1499
Davidroid 0:92706998571a 1500
Davidroid 0:92706998571a 1501 /*** Component's Instance Variables ***/
Davidroid 0:92706998571a 1502
Davidroid 0:92706998571a 1503 /* ACTION 9 --------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1504 * Declare here interrupt related variables, if needed. *
Davidroid 1:b78dab6d2c58 1505 * Note that interrupt handling is platform dependent, see *
Davidroid 1:b78dab6d2c58 1506 * "Interrupt Related Methods" above. *
Davidroid 1:b78dab6d2c58 1507 * *
Davidroid 1:b78dab6d2c58 1508 * Example: *
Davidroid 1:b78dab6d2c58 1509 * + mbed: *
Davidroid 1:b78dab6d2c58 1510 * InterruptIn feature_irq; *
Davidroid 0:92706998571a 1511 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1512 /* Flag Interrupt. */
Davidroid 0:92706998571a 1513 InterruptIn flag_irq;
Davidroid 0:92706998571a 1514
Davidroid 1:b78dab6d2c58 1515 /* Busy Interrupt. */
Davidroid 1:b78dab6d2c58 1516 InterruptIn busy_irq;
Davidroid 1:b78dab6d2c58 1517
Davidroid 1:b78dab6d2c58 1518 /* ACTION 10 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1519 * Declare here other pin related variables, if needed. *
Davidroid 1:b78dab6d2c58 1520 * *
Davidroid 1:b78dab6d2c58 1521 * Example: *
Davidroid 1:b78dab6d2c58 1522 * + mbed: *
Davidroid 1:b78dab6d2c58 1523 * DigitalOut standby_reset; *
Davidroid 1:b78dab6d2c58 1524 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1525 /* Standby/reset pin. */
Davidroid 0:92706998571a 1526 DigitalOut standby_reset;
Davidroid 0:92706998571a 1527
Davidroid 1:b78dab6d2c58 1528 /* ACTION 11 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1529 * Declare here communication related variables, if needed. *
Davidroid 1:b78dab6d2c58 1530 * *
Davidroid 1:b78dab6d2c58 1531 * Example: *
Davidroid 1:b78dab6d2c58 1532 * + mbed: *
Davidroid 1:b78dab6d2c58 1533 * DigitalOut ssel; *
Davidroid 1:b78dab6d2c58 1534 * DevSPI &dev_spi; *
Davidroid 1:b78dab6d2c58 1535 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1536 /* Configuration. */
Davidroid 0:92706998571a 1537 DigitalOut ssel;
Davidroid 0:92706998571a 1538
Davidroid 0:92706998571a 1539 /* IO Device. */
Davidroid 0:92706998571a 1540 DevSPI &dev_spi;
Davidroid 0:92706998571a 1541
Davidroid 1:b78dab6d2c58 1542 /* ACTION 12 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1543 * Declare here identity related variables, if needed. *
Davidroid 1:b78dab6d2c58 1544 * Note that there should be only a unique identifier for each component, *
Davidroid 1:b78dab6d2c58 1545 * which should be the "who_am_i" parameter. *
Davidroid 1:b78dab6d2c58 1546 *------------------------------------------------------------------------*/
Davidroid 1:b78dab6d2c58 1547 /* Identity */
Davidroid 1:b78dab6d2c58 1548 uint8_t who_am_i;
Davidroid 1:b78dab6d2c58 1549
Davidroid 1:b78dab6d2c58 1550 /* ACTION 13 -------------------------------------------------------------*
Davidroid 1:b78dab6d2c58 1551 * Declare here the component's static and non-static data, one variable *
Davidroid 1:b78dab6d2c58 1552 * per line. *
Davidroid 0:92706998571a 1553 * *
Davidroid 0:92706998571a 1554 * Example: *
Davidroid 1:b78dab6d2c58 1555 * float measure; *
Davidroid 1:b78dab6d2c58 1556 * int instance_id; *
Davidroid 1:b78dab6d2c58 1557 * static int number_of_instances; *
Davidroid 0:92706998571a 1558 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 1559 /* Data. */
Davidroid 0:92706998571a 1560 uint8_t L6470_Id;
Davidroid 0:92706998571a 1561 const sL6470_Register_t *L6470_Register;
Davidroid 0:92706998571a 1562 const sL6470_ApplicationCommand_t *L6470_ApplicationCommand;
Davidroid 0:92706998571a 1563 const sL6470_Direction_t *L6470_Direction;
Davidroid 0:92706998571a 1564 const sL6470_ACT_t *L6470_ACT;
Davidroid 0:92706998571a 1565 sL6470_StatusRegister_t L6470_StatusRegister;
Davidroid 0:92706998571a 1566 sL6470_StatusRegister_t *pL6470_StatusRegister;
Davidroid 0:92706998571a 1567 StepperMotorRegister_t StepperMotorRegister;
Davidroid 1:b78dab6d2c58 1568 prepared_action_t prepared_action;
Davidroid 0:92706998571a 1569
Davidroid 0:92706998571a 1570 /* Static data. */
Davidroid 0:92706998571a 1571 static uint8_t number_of_devices;
Davidroid 0:92706998571a 1572 static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE];
Davidroid 0:92706998571a 1573 static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE];
Davidroid 0:92706998571a 1574 static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE];
Davidroid 0:92706998571a 1575 static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE];
Davidroid 0:92706998571a 1576 static eFlagStatus_t L6470_DaisyChain_HalfPrepared;
Davidroid 0:92706998571a 1577 static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 1578 static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 1579 static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 1580 };
Davidroid 0:92706998571a 1581
Davidroid 14:e614697ebf34 1582 #endif /* __L6470_CLASS_H */
Davidroid 0:92706998571a 1583
Davidroid 14:e614697ebf34 1584 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/