Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Diff: Components/l6470/l6470.h
- Revision:
- 22:ba7f4131a5e0
- Parent:
- 16:0d5be428b264
diff -r 1b7f3e002688 -r ba7f4131a5e0 Components/l6470/l6470.h
--- a/Components/l6470/l6470.h Wed Mar 01 17:52:33 2017 +0000
+++ b/Components/l6470/l6470.h Fri Mar 10 11:09:21 2017 +0100
@@ -1,9 +1,10 @@
/**
******************************************************************************
- * @file L6470.h
- * @date 01/10/2014 12:00:00
- * @brief This file contains definitions, exported variables and function
- * prototypes related to the L6470.
+ * @file l6470.h
+ * @author Davide Aliprandi, STMicroelectronics
+ * @version V1.0.0
+ * @date November 12th, 2015
+ * @brief This file contains the class of an L6470 Motor Control component.
******************************************************************************
*
* COPYRIGHT(c) 2014 STMicroelectronics
@@ -34,282 +35,1550 @@
*/
+/* Generated with STM32CubeTOO -----------------------------------------------*/
+
+
+/* Revision ------------------------------------------------------------------*/
+/*
+ Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
+ Branch/Trunk/Tag: trunk
+ Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.h
+ Revision: 0
+*/
+
+
/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __L6470_H
-#define __L6470_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
+#ifndef __L6470_CLASS_H
+#define __L6470_CLASS_H
/* Includes ------------------------------------------------------------------*/
-#include "../Common/microstepping_motor.h"
+/* ACTION 1 ------------------------------------------------------------------*
+ * Include here platform specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "mbed.h"
+#include "DevSPI.h"
+/* ACTION 2 ------------------------------------------------------------------*
+ * Include here component specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "l6470_def.h"
+/* ACTION 3 ------------------------------------------------------------------*
+ * Include here interface specific header files. *
+ * *
+ * Example: *
+ * #include "HumiditySensor.h" *
+ * #include "TemperatureSensor.h" *
+ *----------------------------------------------------------------------------*/
+#include "StepperMotor.h"
-/* Definitions ---------------------------------------------------------------*/
-
-/** @addtogroup BSP
- * @{
- */
-
-/** @addtogroup Components
- * @{
- */
-
-/** @addtogroup L6470
- * @{
- */
-
-/** @defgroup L6470_Exported_Defines L6470_Exported_Defines
- * @{
- */
-
-/**
- * @defgroup L6470_Exported_Constants
- * @brief L6470 Exported Constants.
- * @{
- */
-
-/**
- * @defgroup L6470_Register_Max_Values
- * @brief Maximum values for L6470 registers.
- * @{
- */
-
-#define L6470_MAX_POSITION (0x1FFFFF) //!< Max position
-#define L6470_MIN_POSITION (-(0x200000)) //!< Min position
-#define L6470_POSITION_RANGE ((uint32_t)(L6470_MAX_POSITION - L6470_MIN_POSITION)) //!< Position range
-#define L6470_MAX_SPEED (0xFFFFF) //!< max value of SPEED
-#define L6470_MAX_ACC (0xFFF) //!< max value of ACC
-#define L6470_MAX_DEC (0xFFF) //!< max value of DEC
-#define L6470_MAX_MAX_SPEED (0x3FF) //!< max value of MAX_SPEED
-#define L6470_MAX_MIN_SPEED (0xFFF) //!< max value of MIN_SPEED
-#define L6470_MAX_FS_SPD (0x3FF) //!< max value of FS_SPD
-#define L6470_MAX_INT_SPEED (0x3FFF) //!< max value of INT_SPEED
-#define L6470_MAX_ST_SLP (0xFF) //!< max value of ST_SLP
-#define L6470_MAX_FN_SLP_ACC (0xFF) //!< max value of FN_SLP_ACC
-#define L6470_MAX_FN_SLP_DEC (0xFF) //!< max value of FN_SLP_DEC
-#define L6470_MAX_OCD_TH (0xF) //!< max value of OCD_TH
-#define L6470_MAX_STALL_TH (0x7F) //!< max value of STALL_TH
-
-/**
- * @}
- */ /* End of L6470_Register_Max_Values */
-
-#define L6470REGIDSIZE 25 //!< Max number of identifiers of L6470 Registers
-#define L6470APPCMDIDSIZE 19 //!< Max number of identifiers of L6470 Application Commands
-#define L6470DIRIDSIZE 2 //!< Max number of identifiers of L6470 directions
-#define L6470ACTIDSIZE 2 //!< Max number of identifiers of actions to perform about ABS_POS register
-#define L6470MAXSPICMDBYTESIZE 4 //!< Max number of byte to send via SPI to perform an application command
-#define L6470DAISYCHAINSIZE 2 //!< Max number of identifiers of L6470 in daisy chain configuration
-
-#define L6470_MAX_SPEED_VALUE ((float)15610) //!< max value for the speed in step/s
-#define L6470_MAX_ACC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2
-#define L6470_MAX_DEC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2
-#define L6470_MAX_DEC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2
-
-#define OCD_TH_STEP ((float)375) //!< Minimum step for OCD_TH register in mAmpere
-#define STALL_TH_STEP ((float)31.25) //!< Minimum step for STALL_TH register in mAmpere
-
-#define L6470_ACC_CONV ((float)0.068719) //!< Conversion factor for acceleration value from step/s^2 to the right value
-#define L6470_DEC_CONV ((float)0.068719) //!< Conversion factor for deceleration value from step/s^2 to the right value
-#define L6470_MAXSPEED_CONV ((float)0.065536) //!< Conversion factor for max speed value from step/s to the right value
-#define L6470_MINSPEED_CONV ((float)4.194304) //!< Conversion factor for min speed value from step/s to the right value
-#define L6470_SPEED_CONV ((float)67.108864) //!< Conversion factor for speed value from step/s to the right value
-
-
-/* Types ---------------------------------------------------------------------*/
-
-/**
- * @addtogroup BSP
- * @{
- */
-
-/**
- * @addtogroup Components
- * @{
- */
-
-/**
- * @defgroup L6470
- * @brief Tools to manage the L6470 Stepper Motor Driver.
- * @{
- */
-
-/**
- * @defgroup L6470_Exported_Types
- * @brief L6470 Exported Types.
- * @{
- */
-
-/**
- * @brief The structure to store some features of the L6470 Registers.
- */
-typedef struct {
- uint8_t Address; //!< Register Address
- uint8_t Name[12]; //!< Register Name
- uint8_t LengthBit; //!< Register Length in bits
- uint8_t LengthByte; //!< Register Length in bytes
- uint32_t ResetValue; //!< Register Reset Value
-} sL6470_Register_t;
-
-/**
- * @brief The structure to store some features of the L6470 Application Commands.
- */
-typedef struct {
- uint8_t Mnemonic[12]; //!< AppCmd Mnemonic
- uint8_t BinaryCode; //!< AppCmd Binary Code
- uint8_t NrOfParameters; //!< AppCmd number of needed parameters
-} sL6470_ApplicationCommand_t;
-
-/**
- * @brief The structure to store some features about the L6470 Motor Direction.
- */
-typedef struct {
- uint8_t Mnemonic[8]; //!< L6470 Direction Mnemonic
- uint8_t BinaryCode; //!< L6470 Direction Binary Code
-} sL6470_Direction_t;
+/* Classes -------------------------------------------------------------------*/
/**
- * @brief The structure to store some features about the action taken with the L6470 ABS_POS register.
- */
-typedef struct {
- uint8_t Mnemonic[4]; //!< ACT Mnemonic
- uint8_t BinaryCode; //!< ACT Binary Code
-} sL6470_ACT_t;
-
-/**
- * @brief The structure used to store the identifier of the L6470 application
- * command and its the needed parameters.
- * @note The data stored into this structure will be used to fill the matrix
- * used by SPI to send the command to the L6470.
- */
-typedef struct {
- eL6470_AppCmdId_t L6470_AppCmdId; //!< The identifier of the actual L6470 Application Command
- uint32_t p1; //!< The 1st parameter if needed
- uint32_t p2; //!< The 2nd parameter if needed
- uint32_t p3; //!< The 3rd parameter if needed
-} sL6470_AppCmdPkg_t;
-
-/**
- * @}
- */ /* End of L6470_Exported_Types */
-
-/**
- * @brief L6470 driver initialization structure definition.
+ * @brief Class representing a L6470 component.
*/
-/* ACTION --------------------------------------------------------------------*
- * Declare here the component's initialization structure, if any, one *
- * variable per line without initialization. *
- * *
- * Example: *
- * typedef struct *
- * { *
- * int frequency; *
- * int update_mode; *
- * } COMPONENT_Init_t; *
- *----------------------------------------------------------------------------*/
-typedef struct
+class L6470 : public StepperMotor
{
- float motorvoltage; //!< motor supply voltage in V
- float fullstepsperrevolution; //!< min number of steps per revolution for the motor
- float phasecurrent; //!< max motor phase voltage in A
- float phasevoltage; //!< max motor phase voltage in V
- float speed; //!< motor initial speed [step/s]
- float acc; //!< motor acceleration [step/s^2] (comment for infinite acceleration mode)
- float dec; //!< motor deceleration [step/s^2] (comment for infinite deceleration mode)
- float maxspeed; //!< motor maximum speed [step/s]
- float minspeed; //!< motor minimum speed [step/s]
- float fsspd; //!< motor full-step speed threshold [step/s]
- float kvalhold; //!< holding kval [V]
- float kvalrun; //!< constant speed kval [V]
- float kvalacc; //!< acceleration starting kval [V]
- float kvaldec; //!< deceleration starting kval [V]
- float intspeed; //!< intersect speed for bemf compensation curve slope changing [step/s]
- float stslp; //!< start slope [s/step]
- float fnslpacc; //!< acceleration final slope [s/step]
- float fnslpdec; //!< deceleration final slope [s/step]
- uint8_t kterm; //!< thermal compensation factor (range [0, 15])
- float ocdth; //!< ocd threshold [ma] (range [375 ma, 6000 ma])
- float stallth; //!< stall threshold [ma] (range [31.25 ma, 4000 ma])
- uint8_t step_sel; //!< step mode selection
- uint8_t alarmen; //!< alarm conditions enable
- uint16_t config; //!< ic configuration
-} L6470_Init_t;
+public:
+
+ /*** Public Component Related Types ***/
+
+ /**
+ * @brief Prepared Actions.
+ */
+ typedef enum
+ {
+ PREPARED_NO_ACTION = 0,
+ PREPARED_GET_POSITION,
+ PREPARED_GET_MARK,
+ PREPARED_GET_SPEED,
+ PREPARED_GET_MAX_SPEED,
+ PREPARED_GET_MIN_SPEED,
+ PREPARED_GET_ACCELERATION,
+ PREPARED_GET_DECELERATION,
+ PREPARED_GET_DIRECTION,
+ PREPARED_SET_MARK
+ } prepared_action_t;
+
+
+ /*** Constructor and Destructor Methods ***/
-/**
- * @brief L6470 driver data structure definition.
- */
-/* ACTION --------------------------------------------------------------------*
- * Declare here the structure of component's data, if any, one variable per *
- * line without initialization. *
- * *
- * Example: *
- * typedef struct *
- * { *
- * int T0_out; *
- * int T1_out; *
- * float T0_degC; *
- * float T1_degC; *
- * } COMPONENT_Data_t; *
- *----------------------------------------------------------------------------*/
-typedef struct
-{
- uint8_t L6470_Id; //!< The L6470 identifier inside the daisy chain
- sL6470_Register_t *L6470_Register; //[L6470REGIDSIZE]; //!< Array whose elements are a structure in which store information about the L6470 Registers (the address, the names, the length in bits, the reset value)
- sL6470_ApplicationCommand_t *L6470_ApplicationCommand; //[L6470APPCMDIDSIZE]; //!< Array whose elements are a structure in which store information about the L6470 Application Commands (the mnemonic name, the number of needed parameters, the related funtion to call)
- sL6470_Direction_t *L6470_Direction; //[L6470DIRIDSIZE]; //!< The mnemonic names for the L6470 direction
- sL6470_ACT_t *L6470_ACT; //[L6470ACTIDSIZE]; //!< Action taken about ABS_POS register
- sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; //!< To store the identifier of the actual L6470 application command and its the needed parameters
- uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; //!< To store the matrix that contains the command data that are going to be sent by SPI to the L6470 daisy chain
- uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; //!< To store the matrix that contains the received data by SPI from the L6470 daisy chain
- eFlagStatus_t L6470_DaisyChain_HalfPrepared; /* = ZERO_F; */ //!< Boolean variable used when more than one L6470 into the daisy chain is going to be addressed for commanding
- sL6470_StatusRegister_t L6470_StatusRegister; //!< To store the received L6470_StatusRegister
- sL6470_StatusRegister_t *pL6470_StatusRegister; /* = &L6470_StatusRegister; */ //!< Pointer to the L6470_StatusRegister variable
-} L6470_Data_t;
+ /**
+ * @brief Constructor.
+ * @param flag_irq pin name of the FLAG pin of the component.
+ * @param busy_irq pin name of the BUSY pin of the component.
+ * @param standby_reset pin name of the STBY\RST pin of the component.
+ * @param ssel pin name of the SSEL pin of the SPI device to be used for communication.
+ * @param spi SPI device to be used for communication.
+ */
+ 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)
+ {
+ /* ACTION 4 ----------------------------------------------------------*
+ * Initialize here the component's member variables, one variable per *
+ * line. *
+ * *
+ * Example: *
+ * measure = 0; *
+ * instance_id = number_of_instances++; *
+ *--------------------------------------------------------------------*/
+ L6470_Register = &_L6470_Register[0];
+ L6470_ApplicationCommand = &_L6470_ApplicationCommand[0];
+ L6470_Direction = &_L6470_Direction[0];
+ L6470_ACT = &_L6470_ACT[0];
+ pL6470_StatusRegister = &L6470_StatusRegister;
+ prepared_action = PREPARED_NO_ACTION;
+ L6470_Id = number_of_devices++;
+ L6470_DaisyChain_HalfPrepared = ZERO_F;
+ memset(L6470_AppCmdPkg, 0, L6470DAISYCHAINSIZE * sizeof(sL6470_AppCmdPkg_t));
+ memset(L6470_DaisyChainSpiTxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
+ memset(L6470_DaisyChainSpiRxStruct, 0, L6470MAXSPICMDBYTESIZE * L6470DAISYCHAINSIZE * sizeof(uint8_t));
+ }
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~L6470(void) {}
-/* Functions -----------------------------------------------------------------*/
+ /*** Public Component Related Methods ***/
+
+ /* ACTION 5 --------------------------------------------------------------*
+ * Implement here the component's public methods, as wrappers of the C *
+ * component's functions. *
+ * They should be: *
+ * + Methods with the same name of the C component's virtual table's *
+ * functions (1); *
+ * + Methods with the same name of the C component's extended virtual *
+ * table's functions, if any (2). *
+ * *
+ * Example: *
+ * virtual int get_value(float *p_data) //(1) *
+ * { *
+ * return COMPONENT_get_value(float *pf_data); *
+ * } *
+ * *
+ * virtual int enable_feature(void) //(2) *
+ * { *
+ * return COMPONENT_enable_feature(); *
+ * } *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief Initializing the component.
+ * @param init Pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+ virtual int init(void *init)
+ {
+ return (int) L6470_Config((void *) init);
+ }
+
+ /**
+ * @brief Getting the ID of the component.
+ * @param id Pointer to an allocated variable to store the ID into.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+ virtual int read_id(uint8_t *id)
+ {
+ return (int) 0;
+ }
+
+ /**
+ * @brief Getting the status.
+ * @param None.
+ * @retval The status.
+ */
+ virtual unsigned int get_status(void)
+ {
+ return (unsigned int) L6470_GetStatus();
+ }
+
+ /**
+ * @brief Getting a parameter.
+ * @param parameter A parameter's register address.
+ * @retval The parameter's value.
+ * @note The parameter can be one of the following:
+ * + L6470_ABS_POS_ID
+ * + L6470_EL_POS_ID
+ * + L6470_MARK_ID
+ * + L6470_SPEED_ID
+ * + L6470_ACC_ID
+ * + L6470_DEC_ID
+ * + L6470_MAX_SPEED_ID
+ * + L6470_MIN_SPEED_ID
+ * + L6470_FS_SPD_ID
+ * + L6470_KVAL_HOLD_ID
+ * + L6470_KVAL_RUN_ID
+ * + L6470_KVAL_ACC_ID
+ * + L6470_KVAL_DEC_ID
+ * + L6470_INT_SPEED_ID
+ * + L6470_ST_SLP_ID
+ * + L6470_FN_SLP_ACC_ID
+ * + L6470_FN_SLP_DEC_ID
+ * + L6470_K_THERM_ID
+ * + L6470_ADC_OUT_ID
+ * + L6470_OCD_TH_ID
+ * + L6470_STALL_TH_ID
+ * + L6470_STEP_MODE_ID
+ * + L6470_ALARM_EN_ID
+ * + L6470_CONFIG_ID
+ * + L6470_STATUS_ID
+ */
+ virtual unsigned int get_parameter(unsigned int parameter)
+ {
+ return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter);
+ }
+
+ /**
+ * @brief Getting the position.
+ * @param None.
+ * @retval The position.
+ */
+ virtual signed int get_position(void)
+ {
+ return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
+ }
+
+ /**
+ * @brief Getting the marked position.
+ * @param None.
+ * @retval The marked position.
+ */
+ virtual signed int get_mark(void)
+ {
+ return (signed int) L6470_AbsPos_2_Position((uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_MARK_ID));
+ }
+
+ /**
+ * @brief Getting the current speed in pps.
+ * @param None.
+ * @retval The current speed in pps.
+ */
+ virtual unsigned int get_speed(void)
+ {
+ return round(L6470_Speed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_SPEED_ID)));
+ }
+
+ /**
+ * @brief Getting the maximum speed in pps.
+ * @param None.
+ * @retval The maximum speed in pps.
+ */
+ virtual unsigned int get_max_speed(void)
+ {
+ return round(L6470_MaxSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID)));
+ }
+
+ /**
+ * @brief Getting the minimum speed in pps.
+ * @param None.
+ * @retval The minimum speed in pps.
+ */
+ virtual unsigned int get_min_speed(void)
+ {
+ return round(L6470_MinSpeed_2_Step_s((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID)));
+ }
+
+ /**
+ * @brief Getting the acceleration in pps^2.
+ * @param None.
+ * @retval The acceleration in pps^2.
+ */
+ virtual unsigned int get_acceleration(void)
+ {
+ return round(L6470_Acc_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_ACC_ID)));
+ }
+
+ /**
+ * @brief Getting the deceleration in pps^2.
+ * @param None.
+ * @retval The deceleration in pps^2.
+ */
+ virtual unsigned int get_deceleration(void)
+ {
+ return round(L6470_Dec_2_Step_s2((unsigned int) L6470_GetParam((eL6470_RegId_t) L6470_DEC_ID)));
+ }
+
+ /**
+ * @brief Getting the direction of rotation.
+ * @param None.
+ * @retval The direction of rotation.
+ */
+ virtual direction_t get_direction(void)
+ {
+ return (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
+ }
-/** @addtogroup BSP
- * @{
- */
+ /**
+ * @brief Setting a parameter.
+ * @param parameter A parameter's register address.
+ * @param value The parameter's value.
+ * @retval None.
+ * @note The parameter can be one of the following:
+ * + L6470_ABS_POS_ID
+ * + L6470_EL_POS_ID
+ * + L6470_MARK_ID
+ * + L6470_SPEED_ID
+ * + L6470_ACC_ID
+ * + L6470_DEC_ID
+ * + L6470_MAX_SPEED_ID
+ * + L6470_MIN_SPEED_ID
+ * + L6470_FS_SPD_ID
+ * + L6470_KVAL_HOLD_ID
+ * + L6470_KVAL_RUN_ID
+ * + L6470_KVAL_ACC_ID
+ * + L6470_KVAL_DEC_ID
+ * + L6470_INT_SPEED_ID
+ * + L6470_ST_SLP_ID
+ * + L6470_FN_SLP_ACC_ID
+ * + L6470_FN_SLP_DEC_ID
+ * + L6470_K_THERM_ID
+ * + L6470_ADC_OUT_ID
+ * + L6470_OCD_TH_ID
+ * + L6470_STALL_TH_ID
+ * + L6470_STEP_MODE_ID
+ * + L6470_ALARM_EN_ID
+ * + L6470_CONFIG_ID
+ * + L6470_STATUS_ID
+ * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
+ * Any attempt to write one of those registers when the conditions are not satisfied
+ * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
+ * last argument byte. Any attempt to set an inexistent register (wrong address value)
+ * causes the command to be ignored and the WRONG_CMD flag to rise.
+ * For example, setting some parameters requires first to disable the power bridge;
+ * this can be done through the soft_hiz() method.
+ * They are the following:
+ * + L6470_ABS_POS_ID
+ * + L6470_EL_POS_ID
+ * + L6470_SPEED_ID
+ * + L6470_ACC_ID
+ * + L6470_DEC_ID
+ * + L6470_MAX_SPEED_ID
+ * + L6470_MIN_SPEED_ID
+ * + L6470_INT_SPEED_ID
+ * + L6470_ST_SLP_ID
+ * + L6470_FN_SLP_ACC_ID
+ * + L6470_FN_SLP_DEC_ID
+ * + L6470_ADC_OUT_ID
+ * + L6470_STEP_MODE_ID
+ * + L6470_CONFIG_ID
+ * + L6470_STATUS_ID
+ */
+ virtual void set_parameter(unsigned int parameter, unsigned int value)
+ {
+ L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value);
+ }
+
+ /**
+ * @brief Setting the current position to be the home position.
+ * @param None.
+ * @retval None.
+ */
+ virtual void set_home(void)
+ {
+ L6470_ResetPos();
+ }
+
+ /**
+ * @brief Setting the current position to be the marked position.
+ * @param None.
+ * @retval None.
+ */
+ virtual void set_mark(void)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_GetParam((eL6470_RegId_t) L6470_ABS_POS_ID));
+ }
+
+ /**
+ * @brief Setting the current position to be the marked position.
+ * @param position The given position.
+ * @retval None.
+ */
+ virtual void set_mark(signed int position)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
+ }
+
+ /**
+ * @brief Setting the maximum speed in pps.
+ * @param speed The maximum speed in pps.
+ * @retval "true" in case of success, "false" otherwise.
+ */
+ virtual bool set_max_speed(unsigned int speed)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
+ return true;
+ }
+
+ /**
+ * @brief Setting the minimum speed in pps.
+ * @param speed The minimum speed in pps.
+ * @retval "true" in case of success, "false" otherwise.
+ */
+ virtual bool set_min_speed(unsigned int speed)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
+ return true;
+ }
+
+ /**
+ * @brief Setting the acceleration in pps^2.
+ * @param acceleration The acceleration in pps^2.
+ * @retval "true" in case of success, "false" otherwise.
+ */
+ virtual bool set_acceleration(unsigned int acceleration)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
+ return true;
+ }
+
+ /**
+ * @brief Setting the deceleration in pps^2.
+ * @param deceleration The deceleration in pps^2.
+ * @retval "true" in case of success, "false" otherwise.
+ */
+ virtual bool set_deceleration(unsigned int deceleration)
+ {
+ L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
+ return true;
+ }
+
+ /**
+ * @brief Setting the Step Mode.
+ * @param step_mode The Step Mode.
+ * @retval "true" in case of success, "false" otherwise.
+ * @warning Setting the step mode implies first disabling the power bridge through
+ * the soft_hiz() method.
+ * @warning Every time step mode is changed, the values of the home
+ * and mark positions lose meaning and are reset.
+ */
+ virtual bool set_step_mode(step_mode_t step_mode)
+ {
+ if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128) {
+ return false;
+ }
+ soft_hiz();
+ L6470_SetParam((eL6470_RegId_t) L6470_STEP_MODE_ID, (eMotorStepMode_t) step_mode);
+ return true;
+ }
+
+ /**
+ * @brief Going to a specified position through the shortest path.
+ * @param position The desired position.
+ * @retval None.
+ */
+ virtual void go_to(signed int position)
+ {
+ L6470_GoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
+ }
+
+ /**
+ * @brief Going to a specified position imposing the desired direction.
+ * @param position The desired position.
+ * @param direction The direction of rotation.
+ * @retval None.
+ */
+ virtual void go_to(signed int position, direction_t direction)
+ {
+ 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));
+ }
+
+ /**
+ * @brief Going to the home position.
+ * @param None.
+ * @retval None.
+ */
+ virtual void go_home(void)
+ {
+ L6470_GoHome();
+ }
-/** @addtogroup Components
- * @{
- */
+ /**
+ * @brief Going to the marked position.
+ * @param None.
+ * @retval None.
+ */
+ virtual void go_mark(void)
+ {
+ L6470_GoMark();
+ }
+
+ /**
+ * @brief Running at the given speed imposing the desired direction until
+ * an external switch turn-on event occurs.
+ * @param action The identifier of the action about the absolute position.
+ * @param position The desired position.
+ * @param speed The speed value in pps.
+ * @retval None.
+ * @note The identifier of the action about the absolute position can be
+ * one of the following:
+ * + L6470_ACT_RST_ID: the absolute position is reset;
+ * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
+ */
+ virtual void go_until(eL6470_ActId_t action, direction_t direction, unsigned int speed)
+ {
+ 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));
+ }
+
+ /**
+ * @brief Running towards a specified direction.
+ * @param direction The direction of rotation.
+ * @retval None.
+ */
+ virtual void run(direction_t direction)
+ {
+ 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));
+ }
+
+ /**
+ * @brief Running towards a specified direction at the given speed.
+ * @param direction The direction of rotation.
+ * @param speed The speed value in pps.
+ * @retval None.
+ */
+ virtual void run(direction_t direction, unsigned int speed)
+ {
+ 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));
+ }
+
+ /**
+ * @brief Moving towards a specified direction for a certain number of steps.
+ * @param direction The direction of rotation.
+ * @param steps The desired number of steps.
+ * @retval None.
+ */
+ virtual void move(direction_t direction, unsigned int steps)
+ {
+ L6470_Move((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
+ }
+
+ /**
+ * @brief Stopping the motor through an immediate deceleration up to zero speed.
+ * The used deceleration value is the one stored in the "DEC" register.
+ * @param None.
+ * @retval None.
+ */
+ virtual void soft_stop(void)
+ {
+ L6470_SoftStop();
+ }
+
+ /**
+ * @brief Stopping the motor through an immediate infinite deceleration.
+ * @param None.
+ * @retval None.
+ */
+ virtual void hard_stop(void)
+ {
+ L6470_HardStop();
+ }
+
+ /**
+ * @brief Disabling the power bridge after performing a deceleration to zero.
+ * The used deceleration value is the one stored in the "DEC" register.
+ * @param None.
+ * @retval None.
+ */
+ virtual void soft_hiz(void)
+ {
+ L6470_soft_hiz();
+ }
+
+ /**
+ * @brief Disabling the power bridge immediately.
+ * @param None.
+ * @retval None.
+ */
+ virtual void hard_hiz(void)
+ {
+ L6470_HardHiZ();
+ }
+
+ /**
+ * @brief Waiting while the motor is active.
+ * @param None.
+ * @retval None.
+ */
+ virtual void wait_while_active(void)
+ {
+ while (L6470_CheckStatusRegisterFlag(BUSY_ID) == 0);
+ }
+
+ /**
+ * @brief Switching to step-clock mode.
+ * @param direction The direction of rotation.
+ * @retval None.
+ * @warning Setting the step-clock mode implies first disabling the power bridge through
+ * the soft_hiz() method.
+ */
+ virtual void step_clock(direction_t direction)
+ {
+ soft_hiz();
+ L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ }
+
+ /**
+ * @brief Doing a motion at minimum speed imposing a specified direction
+ * until the SW is released.
+ * @param action The identifier of the action about the absolute position.
+ * @param direction The direction of rotation.
+ * @note The identifier of the action about the absolute position can be
+ * one of the following:
+ * + L6470_ACT_RST_ID: the absolute position is reset;
+ * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
+ */
+ virtual void release_sw(eL6470_ActId_t action, direction_t direction)
+ {
+ L6470_ReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ }
+
+ /**
+ * @brief Resetting the device to power-up conditions.
+ * @param None.
+ * @retval None.
+ */
+ virtual void reset_device(void)
+ {
+ L6470_ResetDevice();
+ }
+
+ /**
+ * @brief Preparing the command to get the status.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_status(void)
+ {
+ L6470_PrepareGetStatus();
+ prepared_action = PREPARED_NO_ACTION;
+ }
-/** @addtogroup L6470
- * @{
- */
+ /**
+ * @brief Preparing the command to get a parameter.
+ * @param parameter A parameter's register address.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ * The parameter can be one of the following:
+ * + L6470_ABS_POS_ID
+ * + L6470_EL_POS_ID
+ * + L6470_MARK_ID
+ * + L6470_SPEED_ID
+ * + L6470_ACC_ID
+ * + L6470_DEC_ID
+ * + L6470_MAX_SPEED_ID
+ * + L6470_MIN_SPEED_ID
+ * + L6470_FS_SPD_ID
+ * + L6470_KVAL_HOLD_ID
+ * + L6470_KVAL_RUN_ID
+ * + L6470_KVAL_ACC_ID
+ * + L6470_KVAL_DEC_ID
+ * + L6470_INT_SPEED_ID
+ * + L6470_ST_SLP_ID
+ * + L6470_FN_SLP_ACC_ID
+ * + L6470_FN_SLP_DEC_ID
+ * + L6470_K_THERM_ID
+ * + L6470_ADC_OUT_ID
+ * + L6470_OCD_TH_ID
+ * + L6470_STALL_TH_ID
+ * + L6470_STEP_MODE_ID
+ * + L6470_ALARM_EN_ID
+ * + L6470_CONFIG_ID
+ * + L6470_STATUS_ID
+ */
+ virtual void prepare_get_parameter(unsigned int parameter)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) parameter);
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to get the position.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_position(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_ABS_POS_ID);
+ prepared_action = PREPARED_GET_POSITION;
+ }
+
+ /**
+ * @brief Preparing the command to get the marked position.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_mark(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_MARK_ID);
+ prepared_action = PREPARED_GET_MARK;
+ }
+
+ /**
+ * @brief Preparing the command to get the current speed in pps.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_speed(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_SPEED_ID);
+ prepared_action = PREPARED_GET_SPEED;
+ }
+
+ /**
+ * @brief Preparing the command to get the maximum speed in pps.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_max_speed(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID);
+ prepared_action = PREPARED_GET_MAX_SPEED;
+ }
+
+ /**
+ * @brief Preparing the command to get the minimum speed in pps.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_min_speed(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID);
+ prepared_action = PREPARED_GET_MIN_SPEED;
+ }
-/** @defgroup L6470_Imported_Functions L6470_Imported_Functions
- * @{
- */
+ /**
+ * @brief Preparing the command to get the acceleration in pps^2.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_acceleration(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_ACC_ID);
+ prepared_action = PREPARED_GET_ACCELERATION;
+ }
+
+ /**
+ * @brief Preparing the command to get the deceleration in pps^2.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_deceleration(void)
+ {
+ L6470_PrepareGetParam((eL6470_RegId_t) L6470_DEC_ID);
+ prepared_action = PREPARED_GET_DECELERATION;
+ }
+
+ /**
+ * @brief Preparing the command to get the direction of rotation.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_get_direction(void)
+ {
+ if (!L6470_DaisyChain_HalfPrepared) {
+ /* To avoid deleting the previous entered command. */
+ L6470_DaisyChain_HalfPrepared = ONE_F;
+ /* Resetting commands. */
+ L6470_ResetAppCmdPkg(L6470_AppCmdPkg);
+ }
+ prepared_action = PREPARED_GET_DIRECTION;
+ }
+
+ /**
+ * @brief Preparing the command to set a parameter.
+ * @param parameter A parameter's register address.
+ * @param value The parameter's value.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ * The parameter can be one of the following:
+ * + L6470_ABS_POS_ID
+ * + L6470_EL_POS_ID
+ * + L6470_MARK_ID
+ * + L6470_SPEED_ID
+ * + L6470_ACC_ID
+ * + L6470_DEC_ID
+ * + L6470_MAX_SPEED_ID
+ * + L6470_MIN_SPEED_ID
+ * + L6470_FS_SPD_ID
+ * + L6470_KVAL_HOLD_ID
+ * + L6470_KVAL_RUN_ID
+ * + L6470_KVAL_ACC_ID
+ * + L6470_KVAL_DEC_ID
+ * + L6470_INT_SPEED_ID
+ * + L6470_ST_SLP_ID
+ * + L6470_FN_SLP_ACC_ID
+ * + L6470_FN_SLP_DEC_ID
+ * + L6470_K_THERM_ID
+ * + L6470_ADC_OUT_ID
+ * + L6470_OCD_TH_ID
+ * + L6470_STALL_TH_ID
+ * + L6470_STEP_MODE_ID
+ * + L6470_ALARM_EN_ID
+ * + L6470_CONFIG_ID
+ * + L6470_STATUS_ID
+ * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
+ * Any attempt to write one of those registers when the conditions are not satisfied
+ * causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
+ * last argument byte. Any attempt to set an inexistent register (wrong address value)
+ * causes the command to be ignored and the WRONG_CMD flag to rise.
+ * For example, setting some parameters requires first to disable the power bridge;
+ * this can be done through the soft_hiz() method.
+ * They are the following:
+ * + L6470_ABS_POS_ID
+ * + L6470_EL_POS_ID
+ * + L6470_SPEED_ID
+ * + L6470_ACC_ID
+ * + L6470_DEC_ID
+ * + L6470_MAX_SPEED_ID
+ * + L6470_MIN_SPEED_ID
+ * + L6470_INT_SPEED_ID
+ * + L6470_ST_SLP_ID
+ * + L6470_FN_SLP_ACC_ID
+ * + L6470_FN_SLP_DEC_ID
+ * + L6470_ADC_OUT_ID
+ * + L6470_STEP_MODE_ID
+ * + L6470_CONFIG_ID
+ * + L6470_STATUS_ID
+ */
+ virtual void prepare_set_parameter(unsigned int parameter, unsigned int value)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) parameter, (uint32_t) value);
+ prepared_action = PREPARED_NO_ACTION;
+ }
-/* ACTION --------------------------------------------------------------------*
- * Declare here extern platform-dependent APIs you might need (e.g.: I/O and *
- * interrupt related functions), and implement them in a glue-logic file on *
- * the target environment, for example within the "x_nucleo_board.c" file. *
- * E.g.: *
- * extern Status_t COMPONENT_IO_Init (void *handle); *
- * extern Status_t COMPONENT_IO_Read (handle, buf, regadd, bytes); *
- * extern Status_t COMPONENT_IO_Write(handle, buf, regadd, bytes); *
- * extern void COMPONENT_IO_ITConfig(void); *
- *----------------------------------------------------------------------------*/
-extern void L6470_DISABLE(void);
-extern void L6470_ENABLE(void);
-extern void L6470_nCS_LOW(void);
-extern void L6470_nCS_HIGH(void);
-extern void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
+ /**
+ * @brief Preparing the command to set the current position to be
+ * the home position.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_home(void)
+ {
+ L6470_PrepareResetPos();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to set the current position to be
+ * the marked position.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_mark(void)
+ {
+ /*
+ Set "0" now as marked position. This value will be replaced by the
+ actual position read at the time when the prepared actions will be
+ performed.
+ */
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, 0);
+ prepared_action = PREPARED_SET_MARK;
+ }
+
+ /**
+ * @brief Preparing the command to set the given position to be
+ * the marked position.
+ * @param position The given position.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_mark(signed int position)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_MARK_ID, (uint32_t) L6470_Position_2_AbsPos((int32_t) position));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to set the current speed in pps.
+ * @param speed The current speed in pps.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_speed(unsigned int speed)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_SPEED_ID, (uint32_t) L6470_Step_s_2_Speed((float) speed));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to set the maximum speed in pps.
+ * @param speed The maximum speed in pps.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_max_speed(unsigned int speed)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to set the minimum speed in pps.
+ * @param speed The minimum speed in pps.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_min_speed(unsigned int speed)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to set the acceleration in pps^2.
+ * @param acceleration The acceleration in pps^2.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_acceleration(unsigned int acceleration)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to set the deceleration in pps^2.
+ * @param deceleration The deceleration in pps^2.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_set_deceleration(unsigned int deceleration)
+ {
+ L6470_PrepareSetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to go to a specified position.
+ * @param position The desired position.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_go_to(signed int position)
+ {
+ L6470_PrepareGoTo((uint32_t) L6470_Position_2_AbsPos((int32_t) position));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to go to a specified position
+ * imposing the desired direction.
+ * @param position The desired position.
+ * @param direction The direction of rotation.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_go_to(signed int position, direction_t direction)
+ {
+ 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));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to go to the home position.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_go_home(void)
+ {
+ L6470_PrepareGoHome();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to go to the marked position.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_go_mark(void)
+ {
+ L6470_PrepareGoMark();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to run at the given speed imposing the desired
+ * direction until an external switch turn-on event occurs.
+ * @param action The identifier of the action about the absolute position.
+ * @param position The desired position.
+ * @param speed The speed value in pps.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ * The identifier of the action about the absolute position can be
+ * one of the following:
+ * + L6470_ACT_RST_ID: the absolute position is reset;
+ * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
+ */
+ virtual void prepare_go_until(eL6470_ActId_t L6470_ActId, direction_t direction, unsigned int speed)
+ {
+ 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));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to run towards a specified direction
+ * at the maximum speed.
+ * @param direction The direction of rotation.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_run(direction_t direction)
+ {
+ 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));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to run towards a specified direction
+ * at the given speed.
+ * @param direction The direction of rotation.
+ * @param speed The speed value in pps.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_run(direction_t direction, unsigned int speed)
+ {
+ 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));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to move towards a specified direction
+ * for a certain number of steps.
+ * @param direction The direction of rotation.
+ * @param steps The desired number of steps.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_move(direction_t direction, unsigned int steps)
+ {
+ L6470_PrepareMove((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID), (unsigned int) steps);
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to stop the motor.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_soft_stop(void)
+ {
+ L6470_PrepareSoftStop();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to stop the motor and disabling the power bridge.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_hard_stop(void)
+ {
+ L6470_PrepareHardStop();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to disable the power bridge after performing
+ * a deceleration to zero.
+ * The used deceleration value is the one stored in the "DEC" register.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_soft_hiz(void)
+ {
+ L6470_PrepareSoftHiZ();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to disable the power bridge immediately.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_hard_hiz(void)
+ {
+ L6470_PrepareHardHiZ();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to switch to step-clock mode.
+ * @param direction The direction of rotation.
+ * @retval None.
+ * @warning Setting the step-clock mode requires an explicit action by the user to first
+ * disable the power bridge through the soft_hiz() method.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_step_clock(direction_t direction)
+ {
+ L6470_PrepareStepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to do a motion at minimum speed
+ * imposing a specified direction until the SW is released.
+ * @param action The identifier of the action about the absolute position.
+ * @param direction The direction of rotation.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ * The identifier of the action about the absolute position can be
+ * one of the following:
+ * + L6470_ACT_RST_ID: the absolute position is reset;
+ * + L6470_ACT_CPY_ID: the absolute position is set as the marked position.
+ */
+ virtual void prepare_release_sw(eL6470_ActId_t action, direction_t direction)
+ {
+ L6470_PrepareReleaseSW((eL6470_ActId_t) action, (eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Preparing the command to reset the device to power-up conditions.
+ * @param None.
+ * @retval None.
+ * @note The command will be sent by issuing "perform_action()".
+ */
+ virtual void prepare_reset_device(void)
+ {
+ L6470_PrepareResetDevice();
+ prepared_action = PREPARED_NO_ACTION;
+ }
+
+ /**
+ * @brief Performing all the actions prepared on the components
+ * of the daisy-chain.
+ * @param None.
+ * @retval The raw data returned by the components.
+ */
+ uint8_t* perform_prepared_actions(void)
+ {
+ return L6470_PerformPreparedApplicationCommand();
+ }
+
+ /**
+ * @brief Getting the prepared action.
+ * @param None
+ * @retval The prepared action.
+ */
+ prepared_action_t get_prepared_action(void)
+ {
+ return prepared_action;
+ }
+
+ /**
+ * @brief Converting the raw data received by the component according to
+ * the action performed on it.
+ * @param raw_data The received raw data.
+ * @retval The result of the action performed.
+ */
+ int32_t get_result(uint8_t *raw_data)
+ {
+ switch (prepared_action) {
+ case PREPARED_GET_POSITION:
+ return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ABS_POS_ID].LengthByte));
+
+ case PREPARED_GET_MARK:
+ return L6470_AbsPos_2_Position(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MARK_ID].LengthByte));
+
+ case PREPARED_GET_SPEED:
+ return round(L6470_Speed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_SPEED_ID].LengthByte)));
+
+ case PREPARED_GET_MAX_SPEED:
+ return round(L6470_MaxSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MAX_SPEED_ID].LengthByte)));
+
+ case PREPARED_GET_MIN_SPEED:
+ return round(L6470_MinSpeed_2_Step_s(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_MIN_SPEED_ID].LengthByte)));
+
+ case PREPARED_GET_ACCELERATION:
+ return round(L6470_Acc_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_ACC_ID].LengthByte)));
+
+ case PREPARED_GET_DECELERATION:
+ return round(L6470_Dec_2_Step_s2(L6470_ExtractReturnedData(raw_data, L6470_Register[L6470_DEC_ID].LengthByte)));
+
+ case PREPARED_GET_DIRECTION:
+ return (int32_t) (direction_t) (L6470_CheckStatusRegisterFlag((eL6470_StatusRegisterFlagId_t) DIR_ID) == 1 ? StepperMotor::FWD : StepperMotor::BWD);
-#ifdef __cplusplus
-}
-#endif
+ default:
+ case PREPARED_NO_ACTION:
+ return 0;
+ }
+ }
+
+
+ /*** Public Interrupt Related Methods ***/
+
+ /* ACTION 6 --------------------------------------------------------------*
+ * Implement here interrupt related methods, if any. *
+ * Note that interrupt handling is platform dependent, e.g.: *
+ * + mbed: *
+ * InterruptIn feature_irq(pin); //Interrupt object. *
+ * feature_irq.rise(callback); //Attach a callback. *
+ * feature_irq.mode(PullNone); //Set interrupt mode. *
+ * feature_irq.enable_irq(); //Enable interrupt. *
+ * feature_irq.disable_irq(); //Disable interrupt. *
+ * + Arduino: *
+ * attachInterrupt(pin, callback, RISING); //Attach a callback. *
+ * detachInterrupt(pin); //Detach a callback. *
+ * *
+ * Example (mbed): *
+ * void attach_feature_irq(void (*fptr) (void)) *
+ * { *
+ * feature_irq.rise(fptr); *
+ * } *
+ * *
+ * void enable_feature_irq(void) *
+ * { *
+ * feature_irq.enable_irq(); *
+ * } *
+ * *
+ * void disable_feature_irq(void) *
+ * { *
+ * feature_irq.disable_irq(); *
+ * } *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief Attaching an interrupt handler to the FLAG interrupt.
+ * @param fptr An interrupt handler.
+ * @retval None.
+ */
+ void attach_flag_irq(void (*fptr)(void))
+ {
+ flag_irq.fall(fptr);
+ }
+
+ /**
+ * @brief Enabling the FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void enable_flag_irq(void)
+ {
+ flag_irq.enable_irq();
+ }
+
+ /**
+ * @brief Disabling the FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void disable_flag_irq(void)
+ {
+ flag_irq.disable_irq();
+ }
+
+ /**
+ * @brief Attaching an interrupt handler to the BUSY interrupt.
+ * @param fptr An interrupt handler.
+ * @retval None.
+ */
+ void attach_busy_irq(void (*fptr)(void))
+ {
+ busy_irq.fall(fptr);
+ }
+
+ /**
+ * @brief Enabling the BUSY interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void enable_busy_irq(void)
+ {
+ busy_irq.enable_irq();
+ }
+
+ /**
+ * @brief Disabling the BUSY interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void disable_busy_irq(void)
+ {
+ busy_irq.disable_irq();
+ }
+
+
+protected:
+
+ /*** Protected Component Related Methods ***/
-#endif /* __L6470_H */
+ /* ACTION 7 --------------------------------------------------------------*
+ * Declare here the component's specific methods. *
+ * They should be: *
+ * + Methods with the same name of the C component's virtual table's *
+ * functions (1); *
+ * + Methods with the same name of the C component's extended virtual *
+ * table's functions, if any (2); *
+ * + Helper methods, if any, like functions declared in the component's *
+ * source files but not pointed by the component's virtual table (3). *
+ * *
+ * Example: *
+ * status_t COMPONENT_get_value(float *f); //(1) *
+ * status_t COMPONENT_enable_feature(void); //(2) *
+ * status_t COMPONENT_compute_average(void); //(3) *
+ *------------------------------------------------------------------------*/
+ int32_t L6470_AbsPos_2_Position(uint32_t AbsPos);
+ uint32_t L6470_Position_2_AbsPos(int32_t Position);
+ float L6470_Speed_2_Step_s(uint32_t Speed);
+ uint32_t L6470_Step_s_2_Speed(float Step_s);
+ float L6470_Acc_2_Step_s2(uint16_t Acc);
+ uint16_t L6470_Step_s2_2_Acc(float Step_s2);
+ float L6470_Dec_2_Step_s2(uint16_t Dec);
+ uint16_t L6470_Step_s2_2_Dec(float Step_s2);
+ float L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed);
+ uint16_t L6470_Step_s_2_MaxSpeed(float Step_s);
+ float L6470_MinSpeed_2_Step_s(uint16_t MinSpeed);
+ uint16_t L6470_Step_s_2_MinSpeed(float Step_s);
+ float L6470_FsSpd_2_Step_s(uint16_t FsSpd);
+ uint16_t L6470_Step_s_2_FsSpd(float Step_s);
+ float L6470_IntSpeed_2_Step_s(uint16_t IntSpeed);
+ uint16_t L6470_Step_s_2_IntSpeed(float Step_s);
+ float L6470_StSlp_2_s_Step(uint8_t StSlp);
+ uint8_t L6470_s_Step_2_StSlp(float s_Step);
+ float L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc);
+ uint8_t L6470_s_Step_2_FnSlpAcc(float s_Step);
+ float L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec);
+ uint8_t L6470_s_Step_2_FnSlpDec(float s_Step);
+ float L6470_OcdTh_2_mA(uint8_t OcdTh);
+ uint8_t L6470_mA_2_OcdTh(float mA);
+ float L6470_StallTh_2_mA(uint8_t StallTh);
+ uint8_t L6470_mA_2_StallTh(float mA);
+ status_t L6470_Config(void *init);
+ void L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
+ uint32_t L6470_GetParam(eL6470_RegId_t L6470_RegId);
+ void L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void L6470_StepClock(eL6470_DirId_t L6470_DirId);
+ void L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
+ void L6470_GoTo(uint32_t AbsPos);
+ void L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
+ void L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
+ void L6470_GoHome(void);
+ void L6470_GoMark(void);
+ void L6470_ResetPos(void);
+ void L6470_ResetDevice(void);
+ void L6470_SoftStop(void);
+ void L6470_HardStop(void);
+ void L6470_soft_hiz(void);
+ void L6470_HardHiZ(void);
+ uint16_t L6470_GetStatus(void);
+ void L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value);
+ void L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId);
+ void L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId);
+ void L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step);
+ void L6470_PrepareGoTo(uint32_t AbsPos);
+ void L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
+ void L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
+ void L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
+ void L6470_PrepareGoHome(void);
+ void L6470_PrepareGoMark(void);
+ void L6470_PrepareResetPos(void);
+ void L6470_PrepareResetDevice(void);
+ void L6470_PrepareSoftStop(void);
+ void L6470_PrepareHardStop(void);
+ void L6470_Preparesoft_hiz(void);
+ void L6470_PrepareHardHiZ(void);
+ void L6470_PrepareGetStatus(void);
+ uint8_t* L6470_PerformPreparedApplicationCommand(void);
+ void L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct);
+ uint32_t L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
+ uint8_t L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId);
+ uint8_t* L6470_GetRegisterName(uint8_t id);
+ void L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg);
+ void L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
+ void L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3);
+ void L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct);
+
+ /**
+ * @brief Rounding a floating point number to the nearest unsigned integer number.
+ * @param f The floating point number.
+ * @retval The nearest unsigned integer number.
+ */
+ int round(float f)
+ {
+ if (f >= 0) {
+ return (int) f + (f - (int) f < 0.5f ? 0 : 1);
+ } else {
+ return (int) f - (f - (int) f < -0.5f ? 1 : 0);
+ }
+ }
+
+
+ /*** Component's I/O Methods ***/
+
+ /**
+ * @brief Utility function to read data from L6470.
+ * @param[out] pBuffer pointer to the buffer to read data into.
+ * @param[in] NumBytesToRead number of bytes to read.
+ * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+ */
+ status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
+ {
+ if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) {
+ return COMPONENT_ERROR;
+ }
+ return COMPONENT_OK;
+ }
+
+ /**
+ * @brief Utility function to write data to L6470.
+ * @param[in] pBuffer pointer to the buffer of data to send.
+ * @param[in] NumBytesToWrite number of bytes to write.
+ * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+ */
+ status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite)
+ {
+ if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) {
+ return COMPONENT_ERROR;
+ }
+ return COMPONENT_OK;
+ }
+
+ /**
+ * @brief Utility function to read and write data from/to L6470 at the same time.
+ * @param[out] pBufferToRead pointer to the buffer to read data into.
+ * @param[in] pBufferToWrite pointer to the buffer of data to send.
+ * @param[in] NumBytes number of bytes to read and write.
+ * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+ */
+ status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
+ {
+ if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) {
+ return COMPONENT_ERROR;
+ }
+ return COMPONENT_OK;
+ }
+
+ /* ACTION 8 --------------------------------------------------------------*
+ * Implement here other I/O methods beyond those already implemented *
+ * above, which are declared extern within the component's header file. *
+ *------------------------------------------------------------------------*/
+ /*
+ * Puts the device in standby mode.
+ */
+ void L6470_ENABLE(void)
+ {
+ standby_reset = 1;
+ }
+
+ /*
+ * Puts the device in reset mode.
+ */
+ void L6470_DISABLE(void)
+ {
+ standby_reset = 0;
+ }
+
+ /*
+ * Write and read bytes to/from the component through the SPI at the same time.
+ */
+ void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
+ {
+ ReadWrite(pRxData, pTxData, Size);
+ }
+
+
+ /*** Component's Instance Variables ***/
+
+ /* ACTION 9 --------------------------------------------------------------*
+ * Declare here interrupt related variables, if needed. *
+ * Note that interrupt handling is platform dependent, see *
+ * "Interrupt Related Methods" above. *
+ * *
+ * Example: *
+ * + mbed: *
+ * InterruptIn feature_irq; *
+ *------------------------------------------------------------------------*/
+ /* Flag Interrupt. */
+ InterruptIn flag_irq;
+
+ /* Busy Interrupt. */
+ InterruptIn busy_irq;
+
+ /* ACTION 10 -------------------------------------------------------------*
+ * Declare here other pin related variables, if needed. *
+ * *
+ * Example: *
+ * + mbed: *
+ * DigitalOut standby_reset; *
+ *------------------------------------------------------------------------*/
+ /* Standby/reset pin. */
+ DigitalOut standby_reset;
+
+ /* ACTION 11 -------------------------------------------------------------*
+ * Declare here communication related variables, if needed. *
+ * *
+ * Example: *
+ * + mbed: *
+ * DigitalOut ssel; *
+ * DevSPI &dev_spi; *
+ *------------------------------------------------------------------------*/
+ /* Configuration. */
+ DigitalOut ssel;
+
+ /* IO Device. */
+ DevSPI &dev_spi;
+
+ /* ACTION 12 -------------------------------------------------------------*
+ * Declare here identity related variables, if needed. *
+ * Note that there should be only a unique identifier for each component, *
+ * which should be the "who_am_i" parameter. *
+ *------------------------------------------------------------------------*/
+ /* Identity */
+ uint8_t who_am_i;
+
+ /* ACTION 13 -------------------------------------------------------------*
+ * Declare here the component's static and non-static data, one variable *
+ * per line. *
+ * *
+ * Example: *
+ * float measure; *
+ * int instance_id; *
+ * static int number_of_instances; *
+ *------------------------------------------------------------------------*/
+ /* Data. */
+ uint8_t L6470_Id;
+ const sL6470_Register_t *L6470_Register;
+ const sL6470_ApplicationCommand_t *L6470_ApplicationCommand;
+ const sL6470_Direction_t *L6470_Direction;
+ const sL6470_ACT_t *L6470_ACT;
+ sL6470_StatusRegister_t L6470_StatusRegister;
+ sL6470_StatusRegister_t *pL6470_StatusRegister;
+ StepperMotorRegister_t StepperMotorRegister;
+ prepared_action_t prepared_action;
+
+ /* Static data. */
+ static uint8_t number_of_devices;
+ static const sL6470_Register_t _L6470_Register[L6470REGIDSIZE];
+ static const sL6470_ApplicationCommand_t _L6470_ApplicationCommand[L6470APPCMDIDSIZE];
+ static const sL6470_Direction_t _L6470_Direction[L6470DIRIDSIZE];
+ static const sL6470_ACT_t _L6470_ACT[L6470ACTIDSIZE];
+ static eFlagStatus_t L6470_DaisyChain_HalfPrepared;
+ static sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
+ static uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
+ static uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
+};
+
+#endif /* __L6470_CLASS_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/