Library to handle the X-NUCLEO-IHM01A1 Motor Control Expansion Board based on the L6474 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   Stepper_Matlab_Control SunTracker_BLE Stepper_Matlab_Control MemsMotorControl ... more

Fork of X_NUCLEO_IHM01A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM01A1 Motor Control Expansion Board based on the the L6474 component.

Daisy-Chain Configuration

This board can be stacked up to three times so that the L6474 components will be connected in daisy-chain configuration. For this purpose, some resistors must be correctly connected on the boards as depicted here below:

/media/uploads/Davidroid/daisychaintable.png

Platform compatibility

  • NUCLEO boards have been tested with the default configuration provided by the HelloWorld_IHM01A1 example.
  • LPCXpresso11U68 board has been tested with the following patch:
    • to connect with a wire from the LPCX’s D4 pin to the IHM01A1’s D9 pin;
    • to initialize the pwm PinName variable with D4 rather than D9.
  • FRDM-K64F board has been tested with the following patch:
    • to connect with a wire from the FRDM’s D4 pin to the IHM01A1’s D8 pin;
    • to initialize the standby_reset PinName variable with D4 rather than D8.

Example Applications

Committer:
davide.aliprandi@st.com
Date:
Fri Mar 10 11:07:50 2017 +0100
Revision:
33:8daea0279301
Parent:
27:990963ed581b
Aligning to ARM mbed coding style.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:2887415a46cd 1 /**
Davidroid 22:ed3a6990a6eb 2 ******************************************************************************
davide.aliprandi@st.com 33:8daea0279301 3 * @file L6474.h
davide.aliprandi@st.com 33:8daea0279301 4 * @author Davide Aliprandi, STMicroelectronics
davide.aliprandi@st.com 33:8daea0279301 5 * @version V1.0.0
davide.aliprandi@st.com 33:8daea0279301 6 * @date October 14th, 2015
davide.aliprandi@st.com 33:8daea0279301 7 * @brief This file contains the class of an L6474 Motor Control component.
Davidroid 22:ed3a6990a6eb 8 ******************************************************************************
Davidroid 22:ed3a6990a6eb 9 * @attention
Davidroid 22:ed3a6990a6eb 10 *
Davidroid 22:ed3a6990a6eb 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Davidroid 22:ed3a6990a6eb 12 *
Davidroid 22:ed3a6990a6eb 13 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 22:ed3a6990a6eb 14 * are permitted provided that the following conditions are met:
Davidroid 22:ed3a6990a6eb 15 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 22:ed3a6990a6eb 16 * this list of conditions and the following disclaimer.
Davidroid 22:ed3a6990a6eb 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 22:ed3a6990a6eb 18 * this list of conditions and the following disclaimer in the documentation
Davidroid 22:ed3a6990a6eb 19 * and/or other materials provided with the distribution.
Davidroid 22:ed3a6990a6eb 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 22:ed3a6990a6eb 21 * may be used to endorse or promote products derived from this software
Davidroid 22:ed3a6990a6eb 22 * without specific prior written permission.
Davidroid 22:ed3a6990a6eb 23 *
Davidroid 22:ed3a6990a6eb 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 22:ed3a6990a6eb 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 22:ed3a6990a6eb 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 22:ed3a6990a6eb 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 22:ed3a6990a6eb 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 22:ed3a6990a6eb 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 22:ed3a6990a6eb 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 22:ed3a6990a6eb 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 22:ed3a6990a6eb 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 22:ed3a6990a6eb 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 22:ed3a6990a6eb 34 *
Davidroid 22:ed3a6990a6eb 35 ******************************************************************************
Davidroid 22:ed3a6990a6eb 36 */
Davidroid 22:ed3a6990a6eb 37
Davidroid 0:2887415a46cd 38
davide.aliprandi@st.com 33:8daea0279301 39 /* Generated with STM32CubeTOO -----------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 40
davide.aliprandi@st.com 33:8daea0279301 41
davide.aliprandi@st.com 33:8daea0279301 42 /* Revision ------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 43 /*
davide.aliprandi@st.com 33:8daea0279301 44 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
davide.aliprandi@st.com 33:8daea0279301 45 Branch/Trunk/Tag: trunk
davide.aliprandi@st.com 33:8daea0279301 46 Based on: X-CUBE-SPN1/trunk/Drivers/BSP/Components/l6474/l6474.h
davide.aliprandi@st.com 33:8daea0279301 47 Revision: 0
davide.aliprandi@st.com 33:8daea0279301 48 */
davide.aliprandi@st.com 33:8daea0279301 49
davide.aliprandi@st.com 33:8daea0279301 50
Davidroid 0:2887415a46cd 51 /* Define to prevent recursive inclusion -------------------------------------*/
Davidroid 22:ed3a6990a6eb 52
davide.aliprandi@st.com 33:8daea0279301 53 #ifndef __L6474_CLASS_H
davide.aliprandi@st.com 33:8daea0279301 54 #define __L6474_CLASS_H
Davidroid 0:2887415a46cd 55
Davidroid 22:ed3a6990a6eb 56
Davidroid 0:2887415a46cd 57 /* Includes ------------------------------------------------------------------*/
Davidroid 22:ed3a6990a6eb 58
davide.aliprandi@st.com 33:8daea0279301 59 /* ACTION 1 ------------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 60 * Include here platform specific header files. *
davide.aliprandi@st.com 33:8daea0279301 61 *----------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 62 #include "mbed.h"
davide.aliprandi@st.com 33:8daea0279301 63 #include "DevSPI.h"
davide.aliprandi@st.com 33:8daea0279301 64 /* ACTION 2 ------------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 65 * Include here component specific header files. *
davide.aliprandi@st.com 33:8daea0279301 66 *----------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 67 #include "L6474_def.h"
davide.aliprandi@st.com 33:8daea0279301 68 /* ACTION 3 ------------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 69 * Include here interface specific header files. *
davide.aliprandi@st.com 33:8daea0279301 70 * *
davide.aliprandi@st.com 33:8daea0279301 71 * Example: *
davide.aliprandi@st.com 33:8daea0279301 72 * #include "HumiditySensor.h" *
davide.aliprandi@st.com 33:8daea0279301 73 * #include "TemperatureSensor.h" *
davide.aliprandi@st.com 33:8daea0279301 74 *----------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 75 #include "StepperMotor.h"
davide.aliprandi@st.com 33:8daea0279301 76
davide.aliprandi@st.com 33:8daea0279301 77
davide.aliprandi@st.com 33:8daea0279301 78 /* Classes -------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 79
davide.aliprandi@st.com 33:8daea0279301 80 /**
davide.aliprandi@st.com 33:8daea0279301 81 * @brief Class representing an L6474 component.
davide.aliprandi@st.com 33:8daea0279301 82 */
davide.aliprandi@st.com 33:8daea0279301 83 class L6474 : public StepperMotor
davide.aliprandi@st.com 33:8daea0279301 84 {
davide.aliprandi@st.com 33:8daea0279301 85 public:
davide.aliprandi@st.com 33:8daea0279301 86
davide.aliprandi@st.com 33:8daea0279301 87 /*** Constructor and Destructor Methods ***/
davide.aliprandi@st.com 33:8daea0279301 88
davide.aliprandi@st.com 33:8daea0279301 89 /**
davide.aliprandi@st.com 33:8daea0279301 90 * @brief Constructor.
davide.aliprandi@st.com 33:8daea0279301 91 * @param flag_irq pin name of the FLAG pin of the component.
davide.aliprandi@st.com 33:8daea0279301 92 * @param standby_reset pin name of the STBY\RST pin of the component.
davide.aliprandi@st.com 33:8daea0279301 93 * @param direction pin name of the DIR pin of the component.
davide.aliprandi@st.com 33:8daea0279301 94 * @param pwm pin name of the PWM pin of the component.
davide.aliprandi@st.com 33:8daea0279301 95 * @param ssel pin name of the SSEL pin of the SPI device to be used for communication.
davide.aliprandi@st.com 33:8daea0279301 96 * @param spi SPI device to be used for communication.
davide.aliprandi@st.com 33:8daea0279301 97 */
davide.aliprandi@st.com 33:8daea0279301 98 L6474(PinName flag_irq, PinName standby_reset, PinName direction, PinName pwm, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), standby_reset(standby_reset), direction(direction), pwm(pwm), ssel(ssel), dev_spi(spi)
davide.aliprandi@st.com 33:8daea0279301 99 {
davide.aliprandi@st.com 33:8daea0279301 100 /* Checking stackability. */
davide.aliprandi@st.com 33:8daea0279301 101 if (!(number_of_devices < MAX_NUMBER_OF_DEVICES)) {
davide.aliprandi@st.com 33:8daea0279301 102 error("Instantiation of the L6474 component failed: it can be stacked up to %d times.\r\n", MAX_NUMBER_OF_DEVICES);
davide.aliprandi@st.com 33:8daea0279301 103 }
davide.aliprandi@st.com 33:8daea0279301 104
davide.aliprandi@st.com 33:8daea0279301 105 /* ACTION 4 ----------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 106 * Initialize here the component's member variables, one variable per *
davide.aliprandi@st.com 33:8daea0279301 107 * line. *
davide.aliprandi@st.com 33:8daea0279301 108 * *
davide.aliprandi@st.com 33:8daea0279301 109 * Example: *
davide.aliprandi@st.com 33:8daea0279301 110 * measure = 0; *
davide.aliprandi@st.com 33:8daea0279301 111 * instance_id = number_of_instances++; *
davide.aliprandi@st.com 33:8daea0279301 112 *--------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 113 error_handler_callback = 0;
davide.aliprandi@st.com 33:8daea0279301 114 device_instance = number_of_devices++;
davide.aliprandi@st.com 33:8daea0279301 115 memset(spi_tx_bursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t));
davide.aliprandi@st.com 33:8daea0279301 116 memset(spi_rx_bursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t));
davide.aliprandi@st.com 33:8daea0279301 117 }
davide.aliprandi@st.com 33:8daea0279301 118
davide.aliprandi@st.com 33:8daea0279301 119 /**
davide.aliprandi@st.com 33:8daea0279301 120 * @brief Destructor.
davide.aliprandi@st.com 33:8daea0279301 121 */
davide.aliprandi@st.com 33:8daea0279301 122 virtual ~L6474(void) {}
Davidroid 24:258f0f60d30c 123
Davidroid 22:ed3a6990a6eb 124
davide.aliprandi@st.com 33:8daea0279301 125 /*** Public Component Related Methods ***/
Davidroid 0:2887415a46cd 126
davide.aliprandi@st.com 33:8daea0279301 127 /* ACTION 5 --------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 128 * Implement here the component's public methods, as wrappers of the C *
davide.aliprandi@st.com 33:8daea0279301 129 * component's functions. *
davide.aliprandi@st.com 33:8daea0279301 130 * They should be: *
davide.aliprandi@st.com 33:8daea0279301 131 * + Methods with the same name of the C component's virtual table's *
davide.aliprandi@st.com 33:8daea0279301 132 * functions (1); *
davide.aliprandi@st.com 33:8daea0279301 133 * + Methods with the same name of the C component's extended virtual *
davide.aliprandi@st.com 33:8daea0279301 134 * table's functions, if any (2). *
davide.aliprandi@st.com 33:8daea0279301 135 * *
davide.aliprandi@st.com 33:8daea0279301 136 * Example: *
davide.aliprandi@st.com 33:8daea0279301 137 * virtual int get_value(float *p_data) //(1) *
davide.aliprandi@st.com 33:8daea0279301 138 * { *
davide.aliprandi@st.com 33:8daea0279301 139 * return COMPONENT_get_value(float *pf_data); *
davide.aliprandi@st.com 33:8daea0279301 140 * } *
davide.aliprandi@st.com 33:8daea0279301 141 * *
davide.aliprandi@st.com 33:8daea0279301 142 * virtual int enable_feature(void) //(2) *
davide.aliprandi@st.com 33:8daea0279301 143 * { *
davide.aliprandi@st.com 33:8daea0279301 144 * return COMPONENT_enable_feature(); *
davide.aliprandi@st.com 33:8daea0279301 145 * } *
davide.aliprandi@st.com 33:8daea0279301 146 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 147 /**
davide.aliprandi@st.com 33:8daea0279301 148 * @brief Initializing the component in 1/16 Microstepping mode.
davide.aliprandi@st.com 33:8daea0279301 149 * @param init Pointer to device specific initalization structure.
davide.aliprandi@st.com 33:8daea0279301 150 * @retval "0" in case of success, an error code otherwise.
davide.aliprandi@st.com 33:8daea0279301 151 */
davide.aliprandi@st.com 33:8daea0279301 152 virtual int init(void *init = NULL)
davide.aliprandi@st.com 33:8daea0279301 153 {
davide.aliprandi@st.com 33:8daea0279301 154 return (int) L6474_Init((void *) init);
davide.aliprandi@st.com 33:8daea0279301 155 }
Davidroid 0:2887415a46cd 156
davide.aliprandi@st.com 33:8daea0279301 157 /**
davide.aliprandi@st.com 33:8daea0279301 158 * @brief Getting the ID of the component.
davide.aliprandi@st.com 33:8daea0279301 159 * @param id Pointer to an allocated variable to store the ID into.
davide.aliprandi@st.com 33:8daea0279301 160 * @retval "0" in case of success, an error code otherwise.
davide.aliprandi@st.com 33:8daea0279301 161 */
davide.aliprandi@st.com 33:8daea0279301 162 virtual int read_id(uint8_t *id = NULL)
davide.aliprandi@st.com 33:8daea0279301 163 {
davide.aliprandi@st.com 33:8daea0279301 164 return (int) L6474_ReadID((uint8_t *) id);
davide.aliprandi@st.com 33:8daea0279301 165 }
Davidroid 0:2887415a46cd 166
davide.aliprandi@st.com 33:8daea0279301 167 /**
davide.aliprandi@st.com 33:8daea0279301 168 * @brief Getting the value of the Status Register.
davide.aliprandi@st.com 33:8daea0279301 169 * @param None.
davide.aliprandi@st.com 33:8daea0279301 170 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 171 * @note The Status Register's flags are cleared, contrary to the
davide.aliprandi@st.com 33:8daea0279301 172 * read_status_register() method.
davide.aliprandi@st.com 33:8daea0279301 173 */
davide.aliprandi@st.com 33:8daea0279301 174 virtual unsigned int get_status(void)
davide.aliprandi@st.com 33:8daea0279301 175 {
davide.aliprandi@st.com 33:8daea0279301 176 return (unsigned int) L6474_CmdGetStatus();
davide.aliprandi@st.com 33:8daea0279301 177 }
Davidroid 0:2887415a46cd 178
davide.aliprandi@st.com 33:8daea0279301 179 /**
davide.aliprandi@st.com 33:8daea0279301 180 * @brief Getting a parameter.
davide.aliprandi@st.com 33:8daea0279301 181 * @param parameter A parameter's register address.
davide.aliprandi@st.com 33:8daea0279301 182 * @retval The parameter's value.
davide.aliprandi@st.com 33:8daea0279301 183 * @note The Status Register's flags are cleared, contrary to the
davide.aliprandi@st.com 33:8daea0279301 184 * read_status_register() method.
davide.aliprandi@st.com 33:8daea0279301 185 * The parameter can be one of the following:
davide.aliprandi@st.com 33:8daea0279301 186 * + L6474_ABS_POS
davide.aliprandi@st.com 33:8daea0279301 187 * + L6474_EL_POS
davide.aliprandi@st.com 33:8daea0279301 188 * + L6474_MARK
davide.aliprandi@st.com 33:8daea0279301 189 * + L6474_RESERVED_REG01
davide.aliprandi@st.com 33:8daea0279301 190 * + L6474_RESERVED_REG02
davide.aliprandi@st.com 33:8daea0279301 191 * + L6474_RESERVED_REG03
davide.aliprandi@st.com 33:8daea0279301 192 * + L6474_RESERVED_REG04
davide.aliprandi@st.com 33:8daea0279301 193 * + L6474_RESERVED_REG05
davide.aliprandi@st.com 33:8daea0279301 194 * + L6474_RESERVED_REG06
davide.aliprandi@st.com 33:8daea0279301 195 * + L6474_TVAL : value in mA
davide.aliprandi@st.com 33:8daea0279301 196 * + L6474_RESERVED_REG07
davide.aliprandi@st.com 33:8daea0279301 197 * + L6474_RESERVED_REG08
davide.aliprandi@st.com 33:8daea0279301 198 * + L6474_RESERVED_REG09
davide.aliprandi@st.com 33:8daea0279301 199 * + L6474_RESERVED_REG10
davide.aliprandi@st.com 33:8daea0279301 200 * + L6474_T_FAST
davide.aliprandi@st.com 33:8daea0279301 201 * + L6474_TON_MIN : value in us
davide.aliprandi@st.com 33:8daea0279301 202 * + L6474_TOFF_MIN : value in us
davide.aliprandi@st.com 33:8daea0279301 203 * + L6474_RESERVED_REG11
davide.aliprandi@st.com 33:8daea0279301 204 * + L6474_ADC_OUT
davide.aliprandi@st.com 33:8daea0279301 205 * + L6474_OCD_TH
davide.aliprandi@st.com 33:8daea0279301 206 * + L6474_RESERVED_REG12
davide.aliprandi@st.com 33:8daea0279301 207 * + L6474_STEP_MODE
davide.aliprandi@st.com 33:8daea0279301 208 * + L6474_ALARM_EN
davide.aliprandi@st.com 33:8daea0279301 209 * + L6474_CONFIG
davide.aliprandi@st.com 33:8daea0279301 210 * + L6474_STATUS
davide.aliprandi@st.com 33:8daea0279301 211 * + L6474_RESERVED_REG13
davide.aliprandi@st.com 33:8daea0279301 212 * + L6474_RESERVED_REG14
davide.aliprandi@st.com 33:8daea0279301 213 * + L6474_INEXISTENT_REG
davide.aliprandi@st.com 33:8daea0279301 214 */
davide.aliprandi@st.com 33:8daea0279301 215 virtual float get_parameter(unsigned int parameter)
davide.aliprandi@st.com 33:8daea0279301 216 {
davide.aliprandi@st.com 33:8daea0279301 217 unsigned int register_value = (unsigned int) L6474_CmdGetParam((L6474_Registers_t) parameter);
davide.aliprandi@st.com 33:8daea0279301 218 float value;
Davidroid 0:2887415a46cd 219
davide.aliprandi@st.com 33:8daea0279301 220 switch ((L6474_Registers_t) parameter) {
davide.aliprandi@st.com 33:8daea0279301 221 case L6474_TVAL:
davide.aliprandi@st.com 33:8daea0279301 222 value = L6474_Par_to_Tval_Current((float) register_value);
davide.aliprandi@st.com 33:8daea0279301 223 break;
davide.aliprandi@st.com 33:8daea0279301 224 case L6474_TON_MIN:
davide.aliprandi@st.com 33:8daea0279301 225 case L6474_TOFF_MIN:
davide.aliprandi@st.com 33:8daea0279301 226 value = L6474_Par_to_Tmin_Time((float) register_value);
davide.aliprandi@st.com 33:8daea0279301 227 break;
davide.aliprandi@st.com 33:8daea0279301 228 default:
davide.aliprandi@st.com 33:8daea0279301 229 value = (float) register_value;
davide.aliprandi@st.com 33:8daea0279301 230 break;
davide.aliprandi@st.com 33:8daea0279301 231 }
davide.aliprandi@st.com 33:8daea0279301 232
davide.aliprandi@st.com 33:8daea0279301 233 return value;
davide.aliprandi@st.com 33:8daea0279301 234 }
davide.aliprandi@st.com 33:8daea0279301 235
davide.aliprandi@st.com 33:8daea0279301 236 /**
davide.aliprandi@st.com 33:8daea0279301 237 * @brief Getting the position.
davide.aliprandi@st.com 33:8daea0279301 238 * @param None.
davide.aliprandi@st.com 33:8daea0279301 239 * @retval The position.
davide.aliprandi@st.com 33:8daea0279301 240 */
davide.aliprandi@st.com 33:8daea0279301 241 virtual signed int get_position(void)
davide.aliprandi@st.com 33:8daea0279301 242 {
davide.aliprandi@st.com 33:8daea0279301 243 return (signed int) L6474_GetPosition();
davide.aliprandi@st.com 33:8daea0279301 244 }
Davidroid 0:2887415a46cd 245
davide.aliprandi@st.com 33:8daea0279301 246 /**
davide.aliprandi@st.com 33:8daea0279301 247 * @brief Getting the marked position.
davide.aliprandi@st.com 33:8daea0279301 248 * @param None.
davide.aliprandi@st.com 33:8daea0279301 249 * @retval The marked position.
davide.aliprandi@st.com 33:8daea0279301 250 */
davide.aliprandi@st.com 33:8daea0279301 251 virtual signed int get_mark(void)
davide.aliprandi@st.com 33:8daea0279301 252 {
davide.aliprandi@st.com 33:8daea0279301 253 return (signed int) L6474_GetMark();
davide.aliprandi@st.com 33:8daea0279301 254 }
davide.aliprandi@st.com 33:8daea0279301 255
davide.aliprandi@st.com 33:8daea0279301 256 /**
davide.aliprandi@st.com 33:8daea0279301 257 * @brief Getting the current speed in pps.
davide.aliprandi@st.com 33:8daea0279301 258 * @param None.
davide.aliprandi@st.com 33:8daea0279301 259 * @retval The current speed in pps.
davide.aliprandi@st.com 33:8daea0279301 260 */
davide.aliprandi@st.com 33:8daea0279301 261 virtual unsigned int get_speed(void)
davide.aliprandi@st.com 33:8daea0279301 262 {
davide.aliprandi@st.com 33:8daea0279301 263 return (unsigned int) L6474_GetCurrentSpeed();
davide.aliprandi@st.com 33:8daea0279301 264 }
davide.aliprandi@st.com 33:8daea0279301 265
davide.aliprandi@st.com 33:8daea0279301 266 /**
davide.aliprandi@st.com 33:8daea0279301 267 * @brief Getting the maximum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 268 * @param None.
davide.aliprandi@st.com 33:8daea0279301 269 * @retval The maximum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 270 */
davide.aliprandi@st.com 33:8daea0279301 271 virtual unsigned int get_max_speed(void)
davide.aliprandi@st.com 33:8daea0279301 272 {
davide.aliprandi@st.com 33:8daea0279301 273 return (unsigned int) L6474_GetMaxSpeed();
davide.aliprandi@st.com 33:8daea0279301 274 }
Davidroid 0:2887415a46cd 275
davide.aliprandi@st.com 33:8daea0279301 276 /**
davide.aliprandi@st.com 33:8daea0279301 277 * @brief Getting the minimum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 278 * @param None.
davide.aliprandi@st.com 33:8daea0279301 279 * @retval The minimum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 280 */
davide.aliprandi@st.com 33:8daea0279301 281 virtual unsigned int get_min_speed(void)
davide.aliprandi@st.com 33:8daea0279301 282 {
davide.aliprandi@st.com 33:8daea0279301 283 return (unsigned int) L6474_GetMinSpeed();
davide.aliprandi@st.com 33:8daea0279301 284 }
Davidroid 0:2887415a46cd 285
davide.aliprandi@st.com 33:8daea0279301 286 /**
davide.aliprandi@st.com 33:8daea0279301 287 * @brief Getting the acceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 288 * @param None.
davide.aliprandi@st.com 33:8daea0279301 289 * @retval The acceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 290 */
davide.aliprandi@st.com 33:8daea0279301 291 virtual unsigned int get_acceleration(void)
davide.aliprandi@st.com 33:8daea0279301 292 {
davide.aliprandi@st.com 33:8daea0279301 293 return (unsigned int) L6474_GetAcceleration();
davide.aliprandi@st.com 33:8daea0279301 294 }
davide.aliprandi@st.com 33:8daea0279301 295
davide.aliprandi@st.com 33:8daea0279301 296 /**
davide.aliprandi@st.com 33:8daea0279301 297 * @brief Getting the deceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 298 * @param None.
davide.aliprandi@st.com 33:8daea0279301 299 * @retval The deceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 300 */
davide.aliprandi@st.com 33:8daea0279301 301 virtual unsigned int get_deceleration(void)
davide.aliprandi@st.com 33:8daea0279301 302 {
davide.aliprandi@st.com 33:8daea0279301 303 return (unsigned int) L6474_GetDeceleration();
davide.aliprandi@st.com 33:8daea0279301 304 }
Davidroid 0:2887415a46cd 305
davide.aliprandi@st.com 33:8daea0279301 306 /**
davide.aliprandi@st.com 33:8daea0279301 307 * @brief Getting the direction of rotation.
davide.aliprandi@st.com 33:8daea0279301 308 * @param None.
davide.aliprandi@st.com 33:8daea0279301 309 * @retval The direction of rotation.
davide.aliprandi@st.com 33:8daea0279301 310 */
davide.aliprandi@st.com 33:8daea0279301 311 virtual direction_t get_direction(void)
davide.aliprandi@st.com 33:8daea0279301 312 {
davide.aliprandi@st.com 33:8daea0279301 313 return (direction_t) (L6474_GetDirection() == FORWARD ? StepperMotor::FWD : StepperMotor::BWD);
davide.aliprandi@st.com 33:8daea0279301 314 }
Davidroid 0:2887415a46cd 315
davide.aliprandi@st.com 33:8daea0279301 316 /**
davide.aliprandi@st.com 33:8daea0279301 317 * @brief Setting a parameter.
davide.aliprandi@st.com 33:8daea0279301 318 * @param parameter A parameter's register address.
davide.aliprandi@st.com 33:8daea0279301 319 * @param value The parameter's value.
davide.aliprandi@st.com 33:8daea0279301 320 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 321 * @note The parameter can be one of the following:
davide.aliprandi@st.com 33:8daea0279301 322 * + L6474_ABS_POS
davide.aliprandi@st.com 33:8daea0279301 323 * + L6474_EL_POS
davide.aliprandi@st.com 33:8daea0279301 324 * + L6474_MARK
davide.aliprandi@st.com 33:8daea0279301 325 * + L6474_RESERVED_REG01
davide.aliprandi@st.com 33:8daea0279301 326 * + L6474_RESERVED_REG02
davide.aliprandi@st.com 33:8daea0279301 327 * + L6474_RESERVED_REG03
davide.aliprandi@st.com 33:8daea0279301 328 * + L6474_RESERVED_REG04
davide.aliprandi@st.com 33:8daea0279301 329 * + L6474_RESERVED_REG05
davide.aliprandi@st.com 33:8daea0279301 330 * + L6474_RESERVED_REG06
davide.aliprandi@st.com 33:8daea0279301 331 * + L6474_TVAL : value in mA
davide.aliprandi@st.com 33:8daea0279301 332 * + L6474_RESERVED_REG07
davide.aliprandi@st.com 33:8daea0279301 333 * + L6474_RESERVED_REG08
davide.aliprandi@st.com 33:8daea0279301 334 * + L6474_RESERVED_REG09
davide.aliprandi@st.com 33:8daea0279301 335 * + L6474_RESERVED_REG10
davide.aliprandi@st.com 33:8daea0279301 336 * + L6474_T_FAST
davide.aliprandi@st.com 33:8daea0279301 337 * + L6474_TON_MIN : value in us
davide.aliprandi@st.com 33:8daea0279301 338 * + L6474_TOFF_MIN : value in us
davide.aliprandi@st.com 33:8daea0279301 339 * + L6474_RESERVED_REG11
davide.aliprandi@st.com 33:8daea0279301 340 * + L6474_ADC_OUT
davide.aliprandi@st.com 33:8daea0279301 341 * + L6474_OCD_TH
davide.aliprandi@st.com 33:8daea0279301 342 * + L6474_RESERVED_REG12
davide.aliprandi@st.com 33:8daea0279301 343 * + L6474_STEP_MODE
davide.aliprandi@st.com 33:8daea0279301 344 * + L6474_ALARM_EN
davide.aliprandi@st.com 33:8daea0279301 345 * + L6474_CONFIG
davide.aliprandi@st.com 33:8daea0279301 346 * + L6474_STATUS
davide.aliprandi@st.com 33:8daea0279301 347 * + L6474_RESERVED_REG13
davide.aliprandi@st.com 33:8daea0279301 348 * + L6474_RESERVED_REG14
davide.aliprandi@st.com 33:8daea0279301 349 * + L6474_INEXISTENT_REG
davide.aliprandi@st.com 33:8daea0279301 350 * @warning Some registers can only be written in particular conditions (see L6474's datasheet).
davide.aliprandi@st.com 33:8daea0279301 351 * Any attempt to write one of those registers when the conditions are not satisfied
davide.aliprandi@st.com 33:8daea0279301 352 * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
davide.aliprandi@st.com 33:8daea0279301 353 * last argument byte. Any attempt to set an inexistent register (wrong address value)
davide.aliprandi@st.com 33:8daea0279301 354 * causes the command to be ignored and the WRONG_CMD flag to rise.
davide.aliprandi@st.com 33:8daea0279301 355 * For example, setting some parameters requires first to disable the power bridge;
davide.aliprandi@st.com 33:8daea0279301 356 * this can be done through the soft_hiz() method.
davide.aliprandi@st.com 33:8daea0279301 357 * They are the following:
davide.aliprandi@st.com 33:8daea0279301 358 * + L6474_EL_POS
davide.aliprandi@st.com 33:8daea0279301 359 * + L6474_T_FAST
davide.aliprandi@st.com 33:8daea0279301 360 * + L6474_TON_MIN : value in us
davide.aliprandi@st.com 33:8daea0279301 361 * + L6474_TOFF_MIN : value in us
davide.aliprandi@st.com 33:8daea0279301 362 * + L6474_ADC_OUT
davide.aliprandi@st.com 33:8daea0279301 363 * + L6474_STEP_MODE
davide.aliprandi@st.com 33:8daea0279301 364 * + L6474_CONFIG
davide.aliprandi@st.com 33:8daea0279301 365 * + L6474_STATUS
davide.aliprandi@st.com 33:8daea0279301 366 */
davide.aliprandi@st.com 33:8daea0279301 367 virtual void set_parameter(unsigned int parameter, float value)
davide.aliprandi@st.com 33:8daea0279301 368 {
davide.aliprandi@st.com 33:8daea0279301 369 float register_value;
Davidroid 0:2887415a46cd 370
davide.aliprandi@st.com 33:8daea0279301 371 switch ((L6474_Registers_t) parameter) {
davide.aliprandi@st.com 33:8daea0279301 372 case L6474_TVAL:
davide.aliprandi@st.com 33:8daea0279301 373 register_value = L6474_Tval_Current_to_Par(value);
davide.aliprandi@st.com 33:8daea0279301 374 break;
davide.aliprandi@st.com 33:8daea0279301 375 case L6474_TON_MIN:
davide.aliprandi@st.com 33:8daea0279301 376 case L6474_TOFF_MIN:
davide.aliprandi@st.com 33:8daea0279301 377 register_value = L6474_Tmin_Time_to_Par(value);
davide.aliprandi@st.com 33:8daea0279301 378 break;
davide.aliprandi@st.com 33:8daea0279301 379 default:
davide.aliprandi@st.com 33:8daea0279301 380 register_value = value;
davide.aliprandi@st.com 33:8daea0279301 381 break;
davide.aliprandi@st.com 33:8daea0279301 382 }
davide.aliprandi@st.com 33:8daea0279301 383
davide.aliprandi@st.com 33:8daea0279301 384 L6474_CmdSetParam((L6474_Registers_t) parameter, (unsigned int) register_value);
davide.aliprandi@st.com 33:8daea0279301 385 }
davide.aliprandi@st.com 33:8daea0279301 386
davide.aliprandi@st.com 33:8daea0279301 387 /**
davide.aliprandi@st.com 33:8daea0279301 388 * @brief Setting the current position to be the home position.
davide.aliprandi@st.com 33:8daea0279301 389 * @param None.
davide.aliprandi@st.com 33:8daea0279301 390 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 391 */
davide.aliprandi@st.com 33:8daea0279301 392 virtual void set_home(void)
davide.aliprandi@st.com 33:8daea0279301 393 {
davide.aliprandi@st.com 33:8daea0279301 394 L6474_SetHome();
davide.aliprandi@st.com 33:8daea0279301 395 }
Davidroid 0:2887415a46cd 396
davide.aliprandi@st.com 33:8daea0279301 397 /**
davide.aliprandi@st.com 33:8daea0279301 398 * @brief Setting the current position to be the marked position.
davide.aliprandi@st.com 33:8daea0279301 399 * @param None.
davide.aliprandi@st.com 33:8daea0279301 400 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 401 */
davide.aliprandi@st.com 33:8daea0279301 402 virtual void set_mark(void)
davide.aliprandi@st.com 33:8daea0279301 403 {
davide.aliprandi@st.com 33:8daea0279301 404 L6474_SetMark();
davide.aliprandi@st.com 33:8daea0279301 405 }
davide.aliprandi@st.com 33:8daea0279301 406
davide.aliprandi@st.com 33:8daea0279301 407 /**
davide.aliprandi@st.com 33:8daea0279301 408 * @brief Setting the maximum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 409 * @param speed The maximum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 410 * @retval "true" in case of success, "false" otherwise.
davide.aliprandi@st.com 33:8daea0279301 411 */
davide.aliprandi@st.com 33:8daea0279301 412 virtual bool set_max_speed(unsigned int speed)
davide.aliprandi@st.com 33:8daea0279301 413 {
davide.aliprandi@st.com 33:8daea0279301 414 L6474_SetMaxSpeed((unsigned int) speed);
davide.aliprandi@st.com 33:8daea0279301 415 return true;
davide.aliprandi@st.com 33:8daea0279301 416 }
davide.aliprandi@st.com 33:8daea0279301 417
davide.aliprandi@st.com 33:8daea0279301 418 /**
davide.aliprandi@st.com 33:8daea0279301 419 * @brief Setting the minimum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 420 * @param speed The minimum speed in pps.
davide.aliprandi@st.com 33:8daea0279301 421 * @retval "true" in case of success, "false" otherwise.
davide.aliprandi@st.com 33:8daea0279301 422 */
davide.aliprandi@st.com 33:8daea0279301 423 virtual bool set_min_speed(unsigned int speed)
davide.aliprandi@st.com 33:8daea0279301 424 {
davide.aliprandi@st.com 33:8daea0279301 425 L6474_SetMinSpeed((unsigned int) speed);
davide.aliprandi@st.com 33:8daea0279301 426 return true;
davide.aliprandi@st.com 33:8daea0279301 427 }
Davidroid 0:2887415a46cd 428
davide.aliprandi@st.com 33:8daea0279301 429 /**
davide.aliprandi@st.com 33:8daea0279301 430 * @brief Setting the acceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 431 * @param acceleration The acceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 432 * @retval "true" in case of success, "false" otherwise.
davide.aliprandi@st.com 33:8daea0279301 433 */
davide.aliprandi@st.com 33:8daea0279301 434 virtual bool set_acceleration(unsigned int acceleration)
davide.aliprandi@st.com 33:8daea0279301 435 {
davide.aliprandi@st.com 33:8daea0279301 436 L6474_SetAcceleration((unsigned int) acceleration);
davide.aliprandi@st.com 33:8daea0279301 437 return true;
davide.aliprandi@st.com 33:8daea0279301 438 }
davide.aliprandi@st.com 33:8daea0279301 439
davide.aliprandi@st.com 33:8daea0279301 440 /**
davide.aliprandi@st.com 33:8daea0279301 441 * @brief Setting the deceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 442 * @param deceleration The deceleration in pps^2.
davide.aliprandi@st.com 33:8daea0279301 443 * @retval "true" in case of success, "false" otherwise.
davide.aliprandi@st.com 33:8daea0279301 444 */
davide.aliprandi@st.com 33:8daea0279301 445 virtual bool set_deceleration(unsigned int deceleration)
davide.aliprandi@st.com 33:8daea0279301 446 {
davide.aliprandi@st.com 33:8daea0279301 447 L6474_SetDeceleration((unsigned int) deceleration);
davide.aliprandi@st.com 33:8daea0279301 448 return true;
davide.aliprandi@st.com 33:8daea0279301 449 }
davide.aliprandi@st.com 33:8daea0279301 450
davide.aliprandi@st.com 33:8daea0279301 451 /**
davide.aliprandi@st.com 33:8daea0279301 452 * @brief Going to a specified position.
davide.aliprandi@st.com 33:8daea0279301 453 * @param position The desired position.
davide.aliprandi@st.com 33:8daea0279301 454 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 455 */
davide.aliprandi@st.com 33:8daea0279301 456 virtual void go_to(signed int position)
davide.aliprandi@st.com 33:8daea0279301 457 {
davide.aliprandi@st.com 33:8daea0279301 458 L6474_GoTo((signed int) position);
davide.aliprandi@st.com 33:8daea0279301 459 }
Davidroid 0:2887415a46cd 460
davide.aliprandi@st.com 33:8daea0279301 461 /**
davide.aliprandi@st.com 33:8daea0279301 462 * @brief Going to the home position.
davide.aliprandi@st.com 33:8daea0279301 463 * @param None.
davide.aliprandi@st.com 33:8daea0279301 464 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 465 */
davide.aliprandi@st.com 33:8daea0279301 466 virtual void go_home(void)
davide.aliprandi@st.com 33:8daea0279301 467 {
davide.aliprandi@st.com 33:8daea0279301 468 L6474_GoHome();
davide.aliprandi@st.com 33:8daea0279301 469 }
davide.aliprandi@st.com 33:8daea0279301 470
davide.aliprandi@st.com 33:8daea0279301 471 /**
davide.aliprandi@st.com 33:8daea0279301 472 * @brief Going to the marked position.
davide.aliprandi@st.com 33:8daea0279301 473 * @param None.
davide.aliprandi@st.com 33:8daea0279301 474 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 475 */
davide.aliprandi@st.com 33:8daea0279301 476 virtual void go_mark(void)
davide.aliprandi@st.com 33:8daea0279301 477 {
davide.aliprandi@st.com 33:8daea0279301 478 L6474_GoMark();
davide.aliprandi@st.com 33:8daea0279301 479 }
Davidroid 0:2887415a46cd 480
davide.aliprandi@st.com 33:8daea0279301 481 /**
davide.aliprandi@st.com 33:8daea0279301 482 * @brief Running the motor towards a specified direction.
davide.aliprandi@st.com 33:8daea0279301 483 * @param direction The direction of rotation.
davide.aliprandi@st.com 33:8daea0279301 484 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 485 */
davide.aliprandi@st.com 33:8daea0279301 486 virtual void run(direction_t direction)
davide.aliprandi@st.com 33:8daea0279301 487 {
davide.aliprandi@st.com 33:8daea0279301 488 L6474_Run((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD));
davide.aliprandi@st.com 33:8daea0279301 489 }
davide.aliprandi@st.com 33:8daea0279301 490
davide.aliprandi@st.com 33:8daea0279301 491 /**
davide.aliprandi@st.com 33:8daea0279301 492 * @brief Moving the motor towards a specified direction for a certain number of steps.
davide.aliprandi@st.com 33:8daea0279301 493 * @param direction The direction of rotation.
davide.aliprandi@st.com 33:8daea0279301 494 * @param steps The desired number of steps.
davide.aliprandi@st.com 33:8daea0279301 495 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 496 */
davide.aliprandi@st.com 33:8daea0279301 497 virtual void move(direction_t direction, unsigned int steps)
davide.aliprandi@st.com 33:8daea0279301 498 {
davide.aliprandi@st.com 33:8daea0279301 499 L6474_Move((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD), (unsigned int) steps);
davide.aliprandi@st.com 33:8daea0279301 500 }
Davidroid 0:2887415a46cd 501
davide.aliprandi@st.com 33:8daea0279301 502 /**
davide.aliprandi@st.com 33:8daea0279301 503 * @brief Stopping the motor through an immediate deceleration up to zero speed.
davide.aliprandi@st.com 33:8daea0279301 504 * @param None.
davide.aliprandi@st.com 33:8daea0279301 505 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 506 */
davide.aliprandi@st.com 33:8daea0279301 507 virtual void soft_stop(void)
davide.aliprandi@st.com 33:8daea0279301 508 {
davide.aliprandi@st.com 33:8daea0279301 509 L6474_SoftStop();
davide.aliprandi@st.com 33:8daea0279301 510 }
davide.aliprandi@st.com 33:8daea0279301 511
davide.aliprandi@st.com 33:8daea0279301 512 /**
davide.aliprandi@st.com 33:8daea0279301 513 * @brief Stopping the motor through an immediate infinite deceleration.
davide.aliprandi@st.com 33:8daea0279301 514 * @param None.
davide.aliprandi@st.com 33:8daea0279301 515 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 516 */
davide.aliprandi@st.com 33:8daea0279301 517 virtual void hard_stop(void)
davide.aliprandi@st.com 33:8daea0279301 518 {
davide.aliprandi@st.com 33:8daea0279301 519 L6474_HardStop();
davide.aliprandi@st.com 33:8daea0279301 520 }
davide.aliprandi@st.com 33:8daea0279301 521
davide.aliprandi@st.com 33:8daea0279301 522 /**
davide.aliprandi@st.com 33:8daea0279301 523 * @brief Disabling the power bridge after performing a deceleration to zero.
davide.aliprandi@st.com 33:8daea0279301 524 * @param None.
davide.aliprandi@st.com 33:8daea0279301 525 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 526 */
davide.aliprandi@st.com 33:8daea0279301 527 virtual void soft_hiz(void)
davide.aliprandi@st.com 33:8daea0279301 528 {
davide.aliprandi@st.com 33:8daea0279301 529 L6474_SoftStop();
davide.aliprandi@st.com 33:8daea0279301 530 L6474_CmdDisable();
davide.aliprandi@st.com 33:8daea0279301 531 }
Davidroid 0:2887415a46cd 532
davide.aliprandi@st.com 33:8daea0279301 533 /**
davide.aliprandi@st.com 33:8daea0279301 534 * @brief Disabling the power bridge immediately.
davide.aliprandi@st.com 33:8daea0279301 535 * @param None.
davide.aliprandi@st.com 33:8daea0279301 536 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 537 */
davide.aliprandi@st.com 33:8daea0279301 538 virtual void hard_hiz(void)
davide.aliprandi@st.com 33:8daea0279301 539 {
davide.aliprandi@st.com 33:8daea0279301 540 L6474_HardStop();
davide.aliprandi@st.com 33:8daea0279301 541 L6474_CmdDisable();
davide.aliprandi@st.com 33:8daea0279301 542 }
Davidroid 0:2887415a46cd 543
davide.aliprandi@st.com 33:8daea0279301 544 /**
davide.aliprandi@st.com 33:8daea0279301 545 * @brief Waiting while the motor is active.
davide.aliprandi@st.com 33:8daea0279301 546 * @param None.
davide.aliprandi@st.com 33:8daea0279301 547 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 548 */
davide.aliprandi@st.com 33:8daea0279301 549 virtual void wait_while_active(void)
davide.aliprandi@st.com 33:8daea0279301 550 {
davide.aliprandi@st.com 33:8daea0279301 551 L6474_WaitWhileActive();
davide.aliprandi@st.com 33:8daea0279301 552 }
Davidroid 18:2d6ab2b93685 553
davide.aliprandi@st.com 33:8daea0279301 554 /**
davide.aliprandi@st.com 33:8daea0279301 555 * @brief Getting the device state.
davide.aliprandi@st.com 33:8daea0279301 556 * @param None.
davide.aliprandi@st.com 33:8daea0279301 557 * @retval The device state.
davide.aliprandi@st.com 33:8daea0279301 558 * @note The device state can be one of the following:
davide.aliprandi@st.com 33:8daea0279301 559 * + ACCELERATING
davide.aliprandi@st.com 33:8daea0279301 560 * + DECELERATING
davide.aliprandi@st.com 33:8daea0279301 561 * + STEADY
davide.aliprandi@st.com 33:8daea0279301 562 * + INACTIVE
davide.aliprandi@st.com 33:8daea0279301 563 */
davide.aliprandi@st.com 33:8daea0279301 564 virtual motorState_t get_device_state(void)
davide.aliprandi@st.com 33:8daea0279301 565 {
davide.aliprandi@st.com 33:8daea0279301 566 return (motorState_t) L6474_GetDeviceState();
davide.aliprandi@st.com 33:8daea0279301 567 }
Davidroid 18:2d6ab2b93685 568
davide.aliprandi@st.com 33:8daea0279301 569 /**
davide.aliprandi@st.com 33:8daea0279301 570 * @brief Reading the Status Register.
davide.aliprandi@st.com 33:8daea0279301 571 * @param None.
davide.aliprandi@st.com 33:8daea0279301 572 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 573 * @note The Status Register's flags are not cleared, contrary to the
davide.aliprandi@st.com 33:8daea0279301 574 * GetStatus() method.
davide.aliprandi@st.com 33:8daea0279301 575 */
davide.aliprandi@st.com 33:8daea0279301 576 virtual uint16_t read_status_register(void)
davide.aliprandi@st.com 33:8daea0279301 577 {
davide.aliprandi@st.com 33:8daea0279301 578 return (uint16_t) L6474_ReadStatusRegister();
davide.aliprandi@st.com 33:8daea0279301 579 }
Davidroid 18:2d6ab2b93685 580
davide.aliprandi@st.com 33:8daea0279301 581 /**
davide.aliprandi@st.com 33:8daea0279301 582 * @brief Setting the Step Mode.
davide.aliprandi@st.com 33:8daea0279301 583 * @param step_mode The Step Mode.
davide.aliprandi@st.com 33:8daea0279301 584 * @retval "true" in case of success, "false" otherwise.
davide.aliprandi@st.com 33:8daea0279301 585 * @warning Setting the step mode implies first disabling the power bridge through
davide.aliprandi@st.com 33:8daea0279301 586 * the soft_hiz() method.
davide.aliprandi@st.com 33:8daea0279301 587 * @warning Every time step mode is changed, the values of the home
davide.aliprandi@st.com 33:8daea0279301 588 * and mark positions lose meaning and are reset.
davide.aliprandi@st.com 33:8daea0279301 589 */
davide.aliprandi@st.com 33:8daea0279301 590 virtual bool set_step_mode(step_mode_t step_mode)
davide.aliprandi@st.com 33:8daea0279301 591 {
davide.aliprandi@st.com 33:8daea0279301 592 if ((motorStepMode_t) step_mode > STEP_MODE_1_16) {
davide.aliprandi@st.com 33:8daea0279301 593 return false;
davide.aliprandi@st.com 33:8daea0279301 594 }
Davidroid 18:2d6ab2b93685 595
davide.aliprandi@st.com 33:8daea0279301 596 soft_hiz();
davide.aliprandi@st.com 33:8daea0279301 597 L6474_SelectStepMode((motorStepMode_t) step_mode);
davide.aliprandi@st.com 33:8daea0279301 598 return true;
davide.aliprandi@st.com 33:8daea0279301 599 }
Davidroid 18:2d6ab2b93685 600
davide.aliprandi@st.com 33:8daea0279301 601 /**
davide.aliprandi@st.com 33:8daea0279301 602 * @brief Attaching an error handler.
davide.aliprandi@st.com 33:8daea0279301 603 * @param fptr An error handler.
davide.aliprandi@st.com 33:8daea0279301 604 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 605 */
davide.aliprandi@st.com 33:8daea0279301 606 virtual void attach_error_handler(void (*fptr)(uint16_t error))
davide.aliprandi@st.com 33:8daea0279301 607 {
davide.aliprandi@st.com 33:8daea0279301 608 L6474_AttachErrorHandler((void (*)(uint16_t error)) fptr);
davide.aliprandi@st.com 33:8daea0279301 609 }
Davidroid 18:2d6ab2b93685 610
davide.aliprandi@st.com 33:8daea0279301 611 /**
davide.aliprandi@st.com 33:8daea0279301 612 * @brief Enabling the device.
davide.aliprandi@st.com 33:8daea0279301 613 * @param None.
davide.aliprandi@st.com 33:8daea0279301 614 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 615 */
davide.aliprandi@st.com 33:8daea0279301 616 virtual void enable(void)
davide.aliprandi@st.com 33:8daea0279301 617 {
davide.aliprandi@st.com 33:8daea0279301 618 L6474_CmdEnable();
davide.aliprandi@st.com 33:8daea0279301 619 }
davide.aliprandi@st.com 33:8daea0279301 620
davide.aliprandi@st.com 33:8daea0279301 621 /**
davide.aliprandi@st.com 33:8daea0279301 622 * @brief Disabling the device.
davide.aliprandi@st.com 33:8daea0279301 623 * @param None.
davide.aliprandi@st.com 33:8daea0279301 624 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 625 */
davide.aliprandi@st.com 33:8daea0279301 626 virtual void disable(void)
davide.aliprandi@st.com 33:8daea0279301 627 {
davide.aliprandi@st.com 33:8daea0279301 628 L6474_CmdDisable();
davide.aliprandi@st.com 33:8daea0279301 629 }
davide.aliprandi@st.com 33:8daea0279301 630
davide.aliprandi@st.com 33:8daea0279301 631 /**
davide.aliprandi@st.com 33:8daea0279301 632 * @brief Getting the version of the firmware.
davide.aliprandi@st.com 33:8daea0279301 633 * @param None.
davide.aliprandi@st.com 33:8daea0279301 634 * @retval The version of the firmware.
davide.aliprandi@st.com 33:8daea0279301 635 */
davide.aliprandi@st.com 33:8daea0279301 636 virtual uint8_t get_fw_version(void)
davide.aliprandi@st.com 33:8daea0279301 637 {
davide.aliprandi@st.com 33:8daea0279301 638 return (uint8_t) L6474_GetFwVersion();
davide.aliprandi@st.com 33:8daea0279301 639 }
Davidroid 0:2887415a46cd 640
Davidroid 0:2887415a46cd 641
davide.aliprandi@st.com 33:8daea0279301 642 /*** Public Interrupt Related Methods ***/
Davidroid 22:ed3a6990a6eb 643
davide.aliprandi@st.com 33:8daea0279301 644 /* ACTION 6 --------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 645 * Implement here interrupt related methods, if any. *
davide.aliprandi@st.com 33:8daea0279301 646 * Note that interrupt handling is platform dependent, e.g.: *
davide.aliprandi@st.com 33:8daea0279301 647 * + mbed: *
davide.aliprandi@st.com 33:8daea0279301 648 * InterruptIn feature_irq(pin); //Interrupt object. *
davide.aliprandi@st.com 33:8daea0279301 649 * feature_irq.rise(callback); //Attach a callback. *
davide.aliprandi@st.com 33:8daea0279301 650 * feature_irq.mode(PullNone); //Set interrupt mode. *
davide.aliprandi@st.com 33:8daea0279301 651 * feature_irq.enable_irq(); //Enable interrupt. *
davide.aliprandi@st.com 33:8daea0279301 652 * feature_irq.disable_irq(); //Disable interrupt. *
davide.aliprandi@st.com 33:8daea0279301 653 * + Arduino: *
davide.aliprandi@st.com 33:8daea0279301 654 * attachInterrupt(pin, callback, RISING); //Attach a callback. *
davide.aliprandi@st.com 33:8daea0279301 655 * detachInterrupt(pin); //Detach a callback. *
davide.aliprandi@st.com 33:8daea0279301 656 * *
davide.aliprandi@st.com 33:8daea0279301 657 * Example (mbed): *
davide.aliprandi@st.com 33:8daea0279301 658 * void attach_feature_irq(void (*fptr) (void)) *
davide.aliprandi@st.com 33:8daea0279301 659 * { *
davide.aliprandi@st.com 33:8daea0279301 660 * feature_irq.rise(fptr); *
davide.aliprandi@st.com 33:8daea0279301 661 * } *
davide.aliprandi@st.com 33:8daea0279301 662 * *
davide.aliprandi@st.com 33:8daea0279301 663 * void enable_feature_irq(void) *
davide.aliprandi@st.com 33:8daea0279301 664 * { *
davide.aliprandi@st.com 33:8daea0279301 665 * feature_irq.enable_irq(); *
davide.aliprandi@st.com 33:8daea0279301 666 * } *
davide.aliprandi@st.com 33:8daea0279301 667 * *
davide.aliprandi@st.com 33:8daea0279301 668 * void disable_feature_irq(void) *
davide.aliprandi@st.com 33:8daea0279301 669 * { *
davide.aliprandi@st.com 33:8daea0279301 670 * feature_irq.disable_irq(); *
davide.aliprandi@st.com 33:8daea0279301 671 * } *
davide.aliprandi@st.com 33:8daea0279301 672 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 673 /**
davide.aliprandi@st.com 33:8daea0279301 674 * @brief Attaching an interrupt handler to the FLAG interrupt.
davide.aliprandi@st.com 33:8daea0279301 675 * @param fptr An interrupt handler.
davide.aliprandi@st.com 33:8daea0279301 676 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 677 */
davide.aliprandi@st.com 33:8daea0279301 678 void attach_flag_irq(void (*fptr)(void))
davide.aliprandi@st.com 33:8daea0279301 679 {
davide.aliprandi@st.com 33:8daea0279301 680 flag_irq.fall(fptr);
davide.aliprandi@st.com 33:8daea0279301 681 }
davide.aliprandi@st.com 33:8daea0279301 682
davide.aliprandi@st.com 33:8daea0279301 683 /**
davide.aliprandi@st.com 33:8daea0279301 684 * @brief Enabling the FLAG interrupt handling.
davide.aliprandi@st.com 33:8daea0279301 685 * @param None.
davide.aliprandi@st.com 33:8daea0279301 686 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 687 */
davide.aliprandi@st.com 33:8daea0279301 688 void enable_flag_irq(void)
davide.aliprandi@st.com 33:8daea0279301 689 {
davide.aliprandi@st.com 33:8daea0279301 690 flag_irq.enable_irq();
davide.aliprandi@st.com 33:8daea0279301 691 }
davide.aliprandi@st.com 33:8daea0279301 692
davide.aliprandi@st.com 33:8daea0279301 693 /**
davide.aliprandi@st.com 33:8daea0279301 694 * @brief Disabling the FLAG interrupt handling.
davide.aliprandi@st.com 33:8daea0279301 695 * @param None.
davide.aliprandi@st.com 33:8daea0279301 696 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 697 */
davide.aliprandi@st.com 33:8daea0279301 698 void disable_flag_irq(void)
davide.aliprandi@st.com 33:8daea0279301 699 {
davide.aliprandi@st.com 33:8daea0279301 700 flag_irq.disable_irq();
davide.aliprandi@st.com 33:8daea0279301 701 }
davide.aliprandi@st.com 33:8daea0279301 702
davide.aliprandi@st.com 33:8daea0279301 703
davide.aliprandi@st.com 33:8daea0279301 704 protected:
davide.aliprandi@st.com 33:8daea0279301 705
davide.aliprandi@st.com 33:8daea0279301 706 /*** Protected Component Related Methods ***/
Davidroid 0:2887415a46cd 707
davide.aliprandi@st.com 33:8daea0279301 708 /* ACTION 7 --------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 709 * Declare here the component's specific methods. *
davide.aliprandi@st.com 33:8daea0279301 710 * They should be: *
davide.aliprandi@st.com 33:8daea0279301 711 * + Methods with the same name of the C component's virtual table's *
davide.aliprandi@st.com 33:8daea0279301 712 * functions (1); *
davide.aliprandi@st.com 33:8daea0279301 713 * + Methods with the same name of the C component's extended virtual *
davide.aliprandi@st.com 33:8daea0279301 714 * table's functions, if any (2); *
davide.aliprandi@st.com 33:8daea0279301 715 * + Helper methods, if any, like functions declared in the component's *
davide.aliprandi@st.com 33:8daea0279301 716 * source files but not pointed by the component's virtual table (3). *
davide.aliprandi@st.com 33:8daea0279301 717 * *
davide.aliprandi@st.com 33:8daea0279301 718 * Example: *
davide.aliprandi@st.com 33:8daea0279301 719 * status_t COMPONENT_get_value(float *f); //(1) *
davide.aliprandi@st.com 33:8daea0279301 720 * status_t COMPONENT_enable_feature(void); //(2) *
davide.aliprandi@st.com 33:8daea0279301 721 * status_t COMPONENT_compute_average(void); //(3) *
davide.aliprandi@st.com 33:8daea0279301 722 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 723 void L6474_AttachErrorHandler(void (*callback)(uint16_t error));
davide.aliprandi@st.com 33:8daea0279301 724 status_t L6474_Init(void *init);
davide.aliprandi@st.com 33:8daea0279301 725 status_t L6474_ReadID(uint8_t *id);
davide.aliprandi@st.com 33:8daea0279301 726 uint16_t L6474_GetAcceleration(void);
davide.aliprandi@st.com 33:8daea0279301 727 uint16_t L6474_GetCurrentSpeed(void);
davide.aliprandi@st.com 33:8daea0279301 728 uint16_t L6474_GetDeceleration(void);
davide.aliprandi@st.com 33:8daea0279301 729 motorState_t L6474_GetDeviceState(void);
davide.aliprandi@st.com 33:8daea0279301 730 uint8_t L6474_GetFwVersion(void);
davide.aliprandi@st.com 33:8daea0279301 731 int32_t L6474_GetMark(void);
davide.aliprandi@st.com 33:8daea0279301 732 uint16_t L6474_GetMaxSpeed(void);
davide.aliprandi@st.com 33:8daea0279301 733 uint16_t L6474_GetMinSpeed(void);
davide.aliprandi@st.com 33:8daea0279301 734 int32_t L6474_GetPosition(void);
davide.aliprandi@st.com 33:8daea0279301 735 void L6474_GoHome(void);
davide.aliprandi@st.com 33:8daea0279301 736 void L6474_GoMark(void);
davide.aliprandi@st.com 33:8daea0279301 737 void L6474_GoTo(int32_t targetPosition);
davide.aliprandi@st.com 33:8daea0279301 738 void L6474_HardStop(void);
davide.aliprandi@st.com 33:8daea0279301 739 void L6474_Move(motorDir_t direction, uint32_t stepCount);
davide.aliprandi@st.com 33:8daea0279301 740 void L6474_Run(motorDir_t direction);
davide.aliprandi@st.com 33:8daea0279301 741 bool L6474_SetAcceleration(uint16_t newAcc);
davide.aliprandi@st.com 33:8daea0279301 742 bool L6474_SetDeceleration(uint16_t newDec);
davide.aliprandi@st.com 33:8daea0279301 743 void L6474_SetHome(void);
davide.aliprandi@st.com 33:8daea0279301 744 void L6474_SetMark(void);
davide.aliprandi@st.com 33:8daea0279301 745 bool L6474_SetMaxSpeed(uint16_t newMaxSpeed);
davide.aliprandi@st.com 33:8daea0279301 746 bool L6474_SetMinSpeed(uint16_t newMinSpeed);
davide.aliprandi@st.com 33:8daea0279301 747 bool L6474_SoftStop(void);
davide.aliprandi@st.com 33:8daea0279301 748 void L6474_WaitWhileActive(void);
davide.aliprandi@st.com 33:8daea0279301 749 void L6474_CmdDisable(void);
davide.aliprandi@st.com 33:8daea0279301 750 void L6474_CmdEnable(void);
davide.aliprandi@st.com 33:8daea0279301 751 uint32_t L6474_CmdGetParam(L6474_Registers_t parameter);
davide.aliprandi@st.com 33:8daea0279301 752 uint16_t L6474_CmdGetStatus(void);
davide.aliprandi@st.com 33:8daea0279301 753 void L6474_CmdNop(void);
davide.aliprandi@st.com 33:8daea0279301 754 void L6474_CmdSetParam(L6474_Registers_t parameter, uint32_t value);
davide.aliprandi@st.com 33:8daea0279301 755 uint16_t L6474_ReadStatusRegister(void);
davide.aliprandi@st.com 33:8daea0279301 756 void L6474_SelectStepMode(motorStepMode_t stepMod);
davide.aliprandi@st.com 33:8daea0279301 757 motorDir_t L6474_GetDirection(void);
davide.aliprandi@st.com 33:8daea0279301 758 void L6474_SetDirection(motorDir_t direction);
davide.aliprandi@st.com 33:8daea0279301 759 void L6474_ApplySpeed(uint16_t newSpeed);
davide.aliprandi@st.com 33:8daea0279301 760 void L6474_ComputeSpeedProfile(uint32_t nbSteps);
davide.aliprandi@st.com 33:8daea0279301 761 int32_t L6474_ConvertPosition(uint32_t abs_position_reg);
davide.aliprandi@st.com 33:8daea0279301 762 void L6474_ErrorHandler(uint16_t error);
davide.aliprandi@st.com 33:8daea0279301 763 void L6474_SendCommand(uint8_t param);
davide.aliprandi@st.com 33:8daea0279301 764 void L6474_SetRegisterToPredefinedValues(void);
davide.aliprandi@st.com 33:8daea0279301 765 void L6474_SetRegisterToInitializationValues(L6474_init_t *init);
davide.aliprandi@st.com 33:8daea0279301 766 void L6474_WriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte);
davide.aliprandi@st.com 33:8daea0279301 767 void L6474_SetDeviceParamsToPredefinedValues(void);
davide.aliprandi@st.com 33:8daea0279301 768 void L6474_StartMovement(void);
davide.aliprandi@st.com 33:8daea0279301 769 void L6474_StepClockHandler(void);
davide.aliprandi@st.com 33:8daea0279301 770 float L6474_Tval_Current_to_Par(float current_mA);
davide.aliprandi@st.com 33:8daea0279301 771 float L6474_Par_to_Tval_Current(float Tval);
davide.aliprandi@st.com 33:8daea0279301 772 float L6474_Tmin_Time_to_Par(float ton_min_us);
davide.aliprandi@st.com 33:8daea0279301 773 float L6474_Par_to_Tmin_Time(float Tmin);
Davidroid 22:ed3a6990a6eb 774
davide.aliprandi@st.com 33:8daea0279301 775
davide.aliprandi@st.com 33:8daea0279301 776 /*** Component's I/O Methods ***/
Davidroid 22:ed3a6990a6eb 777
davide.aliprandi@st.com 33:8daea0279301 778 /**
davide.aliprandi@st.com 33:8daea0279301 779 * @brief Utility function to read data from L6474.
davide.aliprandi@st.com 33:8daea0279301 780 * @param[out] pBuffer pointer to the buffer to read data into.
davide.aliprandi@st.com 33:8daea0279301 781 * @param[in] NumBytesToRead number of bytes to read.
davide.aliprandi@st.com 33:8daea0279301 782 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
davide.aliprandi@st.com 33:8daea0279301 783 */
davide.aliprandi@st.com 33:8daea0279301 784 status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
davide.aliprandi@st.com 33:8daea0279301 785 {
davide.aliprandi@st.com 33:8daea0279301 786 if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) {
davide.aliprandi@st.com 33:8daea0279301 787 return COMPONENT_ERROR;
davide.aliprandi@st.com 33:8daea0279301 788 }
davide.aliprandi@st.com 33:8daea0279301 789 return COMPONENT_OK;
davide.aliprandi@st.com 33:8daea0279301 790 }
davide.aliprandi@st.com 33:8daea0279301 791
davide.aliprandi@st.com 33:8daea0279301 792 /**
davide.aliprandi@st.com 33:8daea0279301 793 * @brief Utility function to write data to L6474.
davide.aliprandi@st.com 33:8daea0279301 794 * @param[in] pBuffer pointer to the buffer of data to send.
davide.aliprandi@st.com 33:8daea0279301 795 * @param[in] NumBytesToWrite number of bytes to write.
davide.aliprandi@st.com 33:8daea0279301 796 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
davide.aliprandi@st.com 33:8daea0279301 797 */
davide.aliprandi@st.com 33:8daea0279301 798 status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite)
davide.aliprandi@st.com 33:8daea0279301 799 {
davide.aliprandi@st.com 33:8daea0279301 800 if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) {
davide.aliprandi@st.com 33:8daea0279301 801 return COMPONENT_ERROR;
davide.aliprandi@st.com 33:8daea0279301 802 }
davide.aliprandi@st.com 33:8daea0279301 803 return COMPONENT_OK;
davide.aliprandi@st.com 33:8daea0279301 804 }
davide.aliprandi@st.com 33:8daea0279301 805
davide.aliprandi@st.com 33:8daea0279301 806 /**
davide.aliprandi@st.com 33:8daea0279301 807 * @brief Utility function to read and write data from/to L6474 at the same time.
davide.aliprandi@st.com 33:8daea0279301 808 * @param[out] pBufferToRead pointer to the buffer to read data into.
davide.aliprandi@st.com 33:8daea0279301 809 * @param[in] pBufferToWrite pointer to the buffer of data to send.
davide.aliprandi@st.com 33:8daea0279301 810 * @param[in] NumBytes number of bytes to read and write.
davide.aliprandi@st.com 33:8daea0279301 811 * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
davide.aliprandi@st.com 33:8daea0279301 812 */
davide.aliprandi@st.com 33:8daea0279301 813 status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
davide.aliprandi@st.com 33:8daea0279301 814 {
davide.aliprandi@st.com 33:8daea0279301 815 if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) {
davide.aliprandi@st.com 33:8daea0279301 816 return COMPONENT_ERROR;
davide.aliprandi@st.com 33:8daea0279301 817 }
davide.aliprandi@st.com 33:8daea0279301 818 return COMPONENT_OK;
davide.aliprandi@st.com 33:8daea0279301 819 }
Davidroid 0:2887415a46cd 820
davide.aliprandi@st.com 33:8daea0279301 821 /* ACTION 8 --------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 822 * Implement here other I/O methods beyond those already implemented *
davide.aliprandi@st.com 33:8daea0279301 823 * above, which are declared extern within the component's header file. *
davide.aliprandi@st.com 33:8daea0279301 824 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 825 /**
davide.aliprandi@st.com 33:8daea0279301 826 * @brief Making the CPU wait.
davide.aliprandi@st.com 33:8daea0279301 827 * @param None.
davide.aliprandi@st.com 33:8daea0279301 828 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 829 */
davide.aliprandi@st.com 33:8daea0279301 830 void L6474_Delay(uint32_t delay)
davide.aliprandi@st.com 33:8daea0279301 831 {
davide.aliprandi@st.com 33:8daea0279301 832 wait_ms(delay);
davide.aliprandi@st.com 33:8daea0279301 833 }
davide.aliprandi@st.com 33:8daea0279301 834
davide.aliprandi@st.com 33:8daea0279301 835 /**
davide.aliprandi@st.com 33:8daea0279301 836 * @brief Enabling interrupts.
davide.aliprandi@st.com 33:8daea0279301 837 * @param None.
davide.aliprandi@st.com 33:8daea0279301 838 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 839 */
davide.aliprandi@st.com 33:8daea0279301 840 void L6474_EnableIrq(void)
davide.aliprandi@st.com 33:8daea0279301 841 {
davide.aliprandi@st.com 33:8daea0279301 842 __enable_irq();
davide.aliprandi@st.com 33:8daea0279301 843 }
davide.aliprandi@st.com 33:8daea0279301 844
davide.aliprandi@st.com 33:8daea0279301 845 /**
davide.aliprandi@st.com 33:8daea0279301 846 * @brief Disabling interrupts.
davide.aliprandi@st.com 33:8daea0279301 847 * @param None.
davide.aliprandi@st.com 33:8daea0279301 848 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 849 */
davide.aliprandi@st.com 33:8daea0279301 850 void L6474_DisableIrq(void)
davide.aliprandi@st.com 33:8daea0279301 851 {
davide.aliprandi@st.com 33:8daea0279301 852 __disable_irq();
davide.aliprandi@st.com 33:8daea0279301 853 }
davide.aliprandi@st.com 33:8daea0279301 854
davide.aliprandi@st.com 33:8daea0279301 855 /**
davide.aliprandi@st.com 33:8daea0279301 856 * @brief Initialising the PWM.
davide.aliprandi@st.com 33:8daea0279301 857 * @param None.
davide.aliprandi@st.com 33:8daea0279301 858 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 859 */
davide.aliprandi@st.com 33:8daea0279301 860 void L6474_PwmInit(void) {}
davide.aliprandi@st.com 33:8daea0279301 861
davide.aliprandi@st.com 33:8daea0279301 862 /**
davide.aliprandi@st.com 33:8daea0279301 863 * @brief Setting the frequency of PWM.
davide.aliprandi@st.com 33:8daea0279301 864 * The frequency controls directly the speed of the device.
davide.aliprandi@st.com 33:8daea0279301 865 * @param frequency the frequency of PWM.
davide.aliprandi@st.com 33:8daea0279301 866 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 867 */
davide.aliprandi@st.com 33:8daea0279301 868 void L6474_PwmSetFreq(uint16_t frequency)
davide.aliprandi@st.com 33:8daea0279301 869 {
davide.aliprandi@st.com 33:8daea0279301 870 /* Computing the period of PWM. */
davide.aliprandi@st.com 33:8daea0279301 871 double period = 1.0f / frequency;
davide.aliprandi@st.com 33:8daea0279301 872
davide.aliprandi@st.com 33:8daea0279301 873 /* Setting the period and the duty-cycle of PWM. */
davide.aliprandi@st.com 33:8daea0279301 874 pwm.period(period);
davide.aliprandi@st.com 33:8daea0279301 875 pwm.write(0.5f);
davide.aliprandi@st.com 33:8daea0279301 876
davide.aliprandi@st.com 33:8daea0279301 877 /* Setting a callback with the same period of PWM's, to update the state machine. */
davide.aliprandi@st.com 33:8daea0279301 878 ticker.attach(Callback<void()>(this, &L6474::L6474_StepClockHandler), period);
davide.aliprandi@st.com 33:8daea0279301 879 }
davide.aliprandi@st.com 33:8daea0279301 880
davide.aliprandi@st.com 33:8daea0279301 881 /**
davide.aliprandi@st.com 33:8daea0279301 882 * @brief Stopping the PWM.
davide.aliprandi@st.com 33:8daea0279301 883 * @param None.
davide.aliprandi@st.com 33:8daea0279301 884 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 885 */
davide.aliprandi@st.com 33:8daea0279301 886 void L6474_PwmStop(void)
davide.aliprandi@st.com 33:8daea0279301 887 {
davide.aliprandi@st.com 33:8daea0279301 888 pwm.write(0.0f);
davide.aliprandi@st.com 33:8daea0279301 889 ticker.detach();
davide.aliprandi@st.com 33:8daea0279301 890 }
davide.aliprandi@st.com 33:8daea0279301 891
davide.aliprandi@st.com 33:8daea0279301 892 /**
davide.aliprandi@st.com 33:8daea0279301 893 * @brief Putting the device in standby mode.
davide.aliprandi@st.com 33:8daea0279301 894 * @param None.
davide.aliprandi@st.com 33:8daea0279301 895 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 896 */
davide.aliprandi@st.com 33:8daea0279301 897 void L6474_ReleaseReset(void)
davide.aliprandi@st.com 33:8daea0279301 898 {
davide.aliprandi@st.com 33:8daea0279301 899 standby_reset = 1;
davide.aliprandi@st.com 33:8daea0279301 900 }
davide.aliprandi@st.com 33:8daea0279301 901
davide.aliprandi@st.com 33:8daea0279301 902 /**
davide.aliprandi@st.com 33:8daea0279301 903 * @brief Putting the device in reset mode.
davide.aliprandi@st.com 33:8daea0279301 904 * @param None.
davide.aliprandi@st.com 33:8daea0279301 905 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 906 */
davide.aliprandi@st.com 33:8daea0279301 907 void L6474_Reset(void)
davide.aliprandi@st.com 33:8daea0279301 908 {
davide.aliprandi@st.com 33:8daea0279301 909 standby_reset = 0;
davide.aliprandi@st.com 33:8daea0279301 910 }
Davidroid 0:2887415a46cd 911
davide.aliprandi@st.com 33:8daea0279301 912 /**
davide.aliprandi@st.com 33:8daea0279301 913 * @brief Setting the direction of rotation.
davide.aliprandi@st.com 33:8daea0279301 914 * @param gpioState direction of rotation: "1" for forward, "0" for backward.
davide.aliprandi@st.com 33:8daea0279301 915 * @retval None.
davide.aliprandi@st.com 33:8daea0279301 916 */
davide.aliprandi@st.com 33:8daea0279301 917 void L6474_SetDirectionGpio(uint8_t gpioState)
davide.aliprandi@st.com 33:8daea0279301 918 {
davide.aliprandi@st.com 33:8daea0279301 919 direction = gpioState;
davide.aliprandi@st.com 33:8daea0279301 920 }
davide.aliprandi@st.com 33:8daea0279301 921
davide.aliprandi@st.com 33:8daea0279301 922 /**
davide.aliprandi@st.com 33:8daea0279301 923 * @brief Writing and reading bytes to/from the component through the SPI at the same time.
davide.aliprandi@st.com 33:8daea0279301 924 * @param[in] pByteToTransmit pointer to the buffer of data to send.
davide.aliprandi@st.com 33:8daea0279301 925 * @param[out] pReceivedByte pointer to the buffer to read data into.
davide.aliprandi@st.com 33:8daea0279301 926 * @retval "0" in case of success, "1" otherwise.
davide.aliprandi@st.com 33:8daea0279301 927 */
davide.aliprandi@st.com 33:8daea0279301 928 uint8_t L6474_SpiWriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte)
davide.aliprandi@st.com 33:8daea0279301 929 {
davide.aliprandi@st.com 33:8daea0279301 930 return (uint8_t) (ReadWrite(pReceivedByte, pByteToTransmit, number_of_devices) == COMPONENT_OK ? 0 : 1);
davide.aliprandi@st.com 33:8daea0279301 931 }
davide.aliprandi@st.com 33:8daea0279301 932
davide.aliprandi@st.com 33:8daea0279301 933
davide.aliprandi@st.com 33:8daea0279301 934 /*** Component's Instance Variables ***/
davide.aliprandi@st.com 33:8daea0279301 935
davide.aliprandi@st.com 33:8daea0279301 936 /* ACTION 9 --------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 937 * Declare here interrupt related variables, if needed. *
davide.aliprandi@st.com 33:8daea0279301 938 * Note that interrupt handling is platform dependent, see *
davide.aliprandi@st.com 33:8daea0279301 939 * "Interrupt Related Methods" above. *
davide.aliprandi@st.com 33:8daea0279301 940 * *
davide.aliprandi@st.com 33:8daea0279301 941 * Example: *
davide.aliprandi@st.com 33:8daea0279301 942 * + mbed: *
davide.aliprandi@st.com 33:8daea0279301 943 * InterruptIn feature_irq; *
davide.aliprandi@st.com 33:8daea0279301 944 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 945 /* Flag Interrupt. */
davide.aliprandi@st.com 33:8daea0279301 946 InterruptIn flag_irq;
davide.aliprandi@st.com 33:8daea0279301 947
davide.aliprandi@st.com 33:8daea0279301 948 /* ACTION 10 -------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 949 * Declare here other pin related variables, if needed. *
davide.aliprandi@st.com 33:8daea0279301 950 * *
davide.aliprandi@st.com 33:8daea0279301 951 * Example: *
davide.aliprandi@st.com 33:8daea0279301 952 * + mbed: *
davide.aliprandi@st.com 33:8daea0279301 953 * DigitalOut standby_reset; *
davide.aliprandi@st.com 33:8daea0279301 954 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 955 /* Standby/reset pin. */
davide.aliprandi@st.com 33:8daea0279301 956 DigitalOut standby_reset;
davide.aliprandi@st.com 33:8daea0279301 957
davide.aliprandi@st.com 33:8daea0279301 958 /* Direction of rotation pin. */
davide.aliprandi@st.com 33:8daea0279301 959 DigitalOut direction;
davide.aliprandi@st.com 33:8daea0279301 960
davide.aliprandi@st.com 33:8daea0279301 961 /* Pulse Width Modulation pin. */
davide.aliprandi@st.com 33:8daea0279301 962 PwmOut pwm;
Davidroid 0:2887415a46cd 963
davide.aliprandi@st.com 33:8daea0279301 964 /* Timer to trigger the PWM callback at each PWM pulse. */
davide.aliprandi@st.com 33:8daea0279301 965 Ticker ticker;
davide.aliprandi@st.com 33:8daea0279301 966
davide.aliprandi@st.com 33:8daea0279301 967 /* ACTION 11 -------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 968 * Declare here communication related variables, if needed. *
davide.aliprandi@st.com 33:8daea0279301 969 * *
davide.aliprandi@st.com 33:8daea0279301 970 * Example: *
davide.aliprandi@st.com 33:8daea0279301 971 * + mbed: *
davide.aliprandi@st.com 33:8daea0279301 972 * DigitalOut ssel; *
davide.aliprandi@st.com 33:8daea0279301 973 * DevSPI &dev_spi; *
davide.aliprandi@st.com 33:8daea0279301 974 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 975 /* Configuration. */
davide.aliprandi@st.com 33:8daea0279301 976 DigitalOut ssel;
davide.aliprandi@st.com 33:8daea0279301 977
davide.aliprandi@st.com 33:8daea0279301 978 /* IO Device. */
davide.aliprandi@st.com 33:8daea0279301 979 DevSPI &dev_spi;
davide.aliprandi@st.com 33:8daea0279301 980
davide.aliprandi@st.com 33:8daea0279301 981 /* ACTION 12 -------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 982 * Declare here identity related variables, if needed. *
davide.aliprandi@st.com 33:8daea0279301 983 * Note that there should be only a unique identifier for each component, *
davide.aliprandi@st.com 33:8daea0279301 984 * which should be the "who_am_i" parameter. *
davide.aliprandi@st.com 33:8daea0279301 985 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 986 /* Identity */
davide.aliprandi@st.com 33:8daea0279301 987 uint8_t who_am_i;
Davidroid 0:2887415a46cd 988
davide.aliprandi@st.com 33:8daea0279301 989 /* ACTION 13 -------------------------------------------------------------*
davide.aliprandi@st.com 33:8daea0279301 990 * Declare here the component's static and non-static data, one variable *
davide.aliprandi@st.com 33:8daea0279301 991 * per line. *
davide.aliprandi@st.com 33:8daea0279301 992 * *
davide.aliprandi@st.com 33:8daea0279301 993 * Example: *
davide.aliprandi@st.com 33:8daea0279301 994 * float measure; *
davide.aliprandi@st.com 33:8daea0279301 995 * int instance_id; *
davide.aliprandi@st.com 33:8daea0279301 996 * static int number_of_instances; *
davide.aliprandi@st.com 33:8daea0279301 997 *------------------------------------------------------------------------*/
davide.aliprandi@st.com 33:8daea0279301 998 /* Data. */
davide.aliprandi@st.com 33:8daea0279301 999 void (*error_handler_callback)(uint16_t error);
davide.aliprandi@st.com 33:8daea0279301 1000 deviceParams_t device_prm;
davide.aliprandi@st.com 33:8daea0279301 1001 uint8_t device_instance;
davide.aliprandi@st.com 33:8daea0279301 1002
davide.aliprandi@st.com 33:8daea0279301 1003 /* Static data. */
davide.aliprandi@st.com 33:8daea0279301 1004 static uint8_t number_of_devices;
davide.aliprandi@st.com 33:8daea0279301 1005 static uint8_t spi_tx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
davide.aliprandi@st.com 33:8daea0279301 1006 static uint8_t spi_rx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
davide.aliprandi@st.com 33:8daea0279301 1007
davide.aliprandi@st.com 33:8daea0279301 1008
davide.aliprandi@st.com 33:8daea0279301 1009 public:
davide.aliprandi@st.com 33:8daea0279301 1010
davide.aliprandi@st.com 33:8daea0279301 1011 /* Static data. */
davide.aliprandi@st.com 33:8daea0279301 1012 static bool spi_preemtion_by_isr;
davide.aliprandi@st.com 33:8daea0279301 1013 static bool isr_flag;
davide.aliprandi@st.com 33:8daea0279301 1014 };
davide.aliprandi@st.com 33:8daea0279301 1015
davide.aliprandi@st.com 33:8daea0279301 1016 #endif // __L6474_CLASS_H
davide.aliprandi@st.com 33:8daea0279301 1017
davide.aliprandi@st.com 33:8daea0279301 1018 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/